From 1656342eeb60141e26c678b81480c127ffa7fc87 Mon Sep 17 00:00:00 2001 From: TT Date: Wed, 15 Jan 2020 01:07:40 +0900 Subject: [PATCH 01/23] feat: add bandwidth setting of detector --- dsp.c | 16 ++++++++-------- main.c | 48 ++++++++++++++++++++++++++++++++++++------------ nanovna.h | 2 ++ ui.c | 23 +++++++++++++++++++++++ 4 files changed, 69 insertions(+), 20 deletions(-) diff --git a/dsp.c b/dsp.c index 6e9f607..4b616dc 100644 --- a/dsp.c +++ b/dsp.c @@ -41,10 +41,10 @@ const int16_t sincos_tbl[48][2] = { {-24636, -21605 }, {-32698, -2143 }, {-27246, 18205 }, {-10533, 31029 } }; -int32_t acc_samp_s; -int32_t acc_samp_c; -int32_t acc_ref_s; -int32_t acc_ref_c; +float acc_samp_s; +float acc_samp_c; +float acc_ref_s; +float acc_ref_c; void dsp_process(int16_t *capture, size_t length) @@ -79,10 +79,10 @@ dsp_process(int16_t *capture, size_t length) ref_c = __SMLATT(sr, sc, ref_c); #endif } - acc_samp_s = samp_s; - acc_samp_c = samp_c; - acc_ref_s = ref_s; - acc_ref_c = ref_c; + acc_samp_s += samp_s; + acc_samp_c += samp_c; + acc_ref_s += ref_s; + acc_ref_c += ref_c; } void diff --git a/main.c b/main.c index fff210d..91f475c 100644 --- a/main.c +++ b/main.c @@ -584,10 +584,34 @@ int16_t dump_buffer[AUDIO_BUFFER_LEN]; int16_t dump_selection = 0; #endif -volatile int16_t wait_count = 0; +volatile uint8_t wait_count = 0; +volatile uint8_t accumerate_count = 0; + +const int8_t bandwidth_accumerate_count[] = { + 1, // 1kHz + 3, // 300Hz + 10, // 100Hz + 33, // 30Hz + 100 // 10Hz +}; float measured[2][POINTS_COUNT][2]; +static inline void +dsp_start(int count) +{ + wait_count = count; + accumerate_count = bandwidth_accumerate_count[bandwidth]; + reset_dsp_accumerator(); +} + +static inline void +dsp_wait(void) +{ + while (accumerate_count > 0) + __WFI(); +} + #ifdef ENABLED_DUMP static void duplicate_buffer_to_dump(int16_t *p) @@ -610,13 +634,16 @@ void i2s_end_callback(I2SDriver *i2sp, size_t offset, size_t n) (void)i2sp; (void)n; - if (wait_count > 0) { - if (wait_count == 1) + if (wait_count > 1) { + --wait_count; + } else if (wait_count > 0) { + if (accumerate_count > 0) { dsp_process(p, n); + accumerate_count--; + } #ifdef ENABLED_DUMP - duplicate_buffer_to_dump(p); + duplicate_buffer_to_dump(p); #endif - --wait_count; } #if PORT_SUPPORTS_RT @@ -808,9 +835,6 @@ ensure_edit_config(void) cal_status = 0; } -#define DSP_START(delay) wait_count = delay; -#define DSP_WAIT_READY while (wait_count) __WFI(); - #define DELAY_CHANNEL_CHANGE 2 // main loop for measurement @@ -824,20 +848,20 @@ bool sweep(bool break_on_operation) if (frequencies[i] == 0) break; delay = set_frequency(frequencies[i]); // 700 tlv320aic3204_select(0); // 60 CH0:REFLECT, reset and begin measure - DSP_START(delay + ((i == 0) ? 1 : 0)); // 1900 + dsp_start(delay + ((i == 0) ? 1 : 0)); // 1900 //================================================ // Place some code thats need execute while delay //================================================ - DSP_WAIT_READY; + dsp_wait(); // calculate reflection coefficient (*sample_func)(measured[0][i]); // 60 tlv320aic3204_select(1); // 60 CH1:TRANSMISSION, reset and begin measure - DSP_START(DELAY_CHANNEL_CHANGE); // 1700 + dsp_start(DELAY_CHANNEL_CHANGE); // 1700 //================================================ // Place some code thats need execute while delay //================================================ - DSP_WAIT_READY; + dsp_wait(); // calculate transmission coefficient (*sample_func)(measured[1][i]); // 60 // ======== 170 =========== diff --git a/nanovna.h b/nanovna.h index d553f38..ec03e18 100644 --- a/nanovna.h +++ b/nanovna.h @@ -379,6 +379,7 @@ typedef struct properties { int8_t _active_marker; uint8_t _domain_mode; /* 0bxxxxxffm : where ff: TD_FUNC m: DOMAIN_MODE */ uint8_t _marker_smith_format; + uint8_t _bandwidth; uint8_t _reserved[50]; uint32_t checksum; } properties_t; @@ -405,6 +406,7 @@ extern properties_t current_props; #define domain_mode current_props._domain_mode #define velocity_factor current_props._velocity_factor #define marker_smith_format current_props._marker_smith_format +#define bandwidth current_props._bandwidth #define FREQ_IS_STARTSTOP() (!(config.freq_mode&FREQ_MODE_CENTER_SPAN)) #define FREQ_IS_CENTERSPAN() (config.freq_mode&FREQ_MODE_CENTER_SPAN) diff --git a/ui.c b/ui.c index 391af98..3e10a58 100644 --- a/ui.c +++ b/ui.c @@ -631,6 +631,13 @@ menu_transform_filter_cb(int item, uint8_t data) ui_mode_normal(); } +static void +menu_bandwidth_cb(int item) +{ + bandwidth = item; + draw_menu(); +} + static void choose_active_marker(void) { @@ -928,12 +935,23 @@ const menuitem_t menu_transform[] = { { MT_NONE, 0, NULL, NULL } // sentinel }; +const menuitem_t menu_bandwidth[] = { + { MT_CALLBACK, 0, "1 kHz", menu_bandwidth_cb }, + { MT_CALLBACK, 0, "300 Hz", menu_bandwidth_cb }, + { MT_CALLBACK, 0, "100 Hz", menu_bandwidth_cb }, + { MT_CALLBACK, 0, "30 Hz", menu_bandwidth_cb }, + { MT_CALLBACK, 0, "10 Hz", menu_bandwidth_cb }, + { MT_CANCEL, 0, S_LARROW" BACK", NULL }, + { MT_NONE, 0, NULL, NULL } // sentinel +}; + const menuitem_t menu_display[] = { { MT_SUBMENU, 0, "TRACE", menu_trace }, { MT_SUBMENU, 0, "FORMAT", menu_format }, { MT_SUBMENU, 0, "SCALE", menu_scale }, { MT_SUBMENU, 0, "CHANNEL", menu_channel }, { MT_SUBMENU, 0, "TRANSFORM", menu_transform }, + { MT_SUBMENU, 0, "BANDWIDTH", menu_bandwidth }, { MT_CANCEL, 0, S_LARROW" BACK", NULL }, { MT_NONE, 0, NULL, NULL } // sentinel }; @@ -1365,6 +1383,11 @@ menu_item_modify_attribute(const menuitem_t *menu, int item, *bg = DEFAULT_MENU_TEXT_COLOR; *fg = config.menu_normal_color; } + } else if (menu == menu_bandwidth) { + if (item == bandwidth) { + *bg = 0x0000; + *fg = 0xffff; + } } else if (menu == menu_transform) { if ((item == 0 && (domain_mode & DOMAIN_MODE) == DOMAIN_TIME) || (item == 1 && (domain_mode & TD_FUNC) == TD_FUNC_LOWPASS_IMPULSE) From 11052640896b130aa0aa78b3a5db42eb37a3b891 Mon Sep 17 00:00:00 2001 From: erikkaashoek Date: Mon, 23 Mar 2020 19:54:28 +0100 Subject: [PATCH 02/23] Input forms working --- plot.c | 4 +- sa_core.c | 3 +- ui.c | 26 ++++++--- ui_sa.c | 157 ++++++++++++++++++++++++++++++++++++++++++++++++++++-- 4 files changed, 175 insertions(+), 15 deletions(-) diff --git a/plot.c b/plot.c index 31a7771..481c45e 100644 --- a/plot.c +++ b/plot.c @@ -33,7 +33,7 @@ int fullscreen = true; static void cell_draw_marker_info(int x0, int y0); static void draw_battery_status(void); void cell_draw_test_info(int x0, int y0); -static void frequency_string(char *buf, size_t len, int32_t freq); +void frequency_string(char *buf, size_t len, int32_t freq); static int16_t grid_offset; static int16_t grid_width; @@ -1841,7 +1841,7 @@ static void cell_draw_marker_info(int x0, int y0) } } } -static void frequency_string(char *buf, size_t len, int32_t freq) +void frequency_string(char *buf, size_t len, int32_t freq) { if (freq < 0) { freq = -freq; diff --git a/sa_core.c b/sa_core.c index d870670..18c3da8 100644 --- a/sa_core.c +++ b/sa_core.c @@ -593,7 +593,8 @@ float perform(bool break_on_operation, int i, int32_t f, int extraV) SetRX(settingMode); SI4432_SetReference(settingRefer); temppeakLevel = -150; - setFreq (0, local_IF); + if (local_IF) + setFreq (0, local_IF); if (dirty) { scandirty = true; dirty = false; diff --git a/ui.c b/ui.c index 5460ebe..da79dc3 100644 --- a/ui.c +++ b/ui.c @@ -1046,6 +1046,11 @@ const menuitem_t menu_top[] = { }; #endif + +#define MENU_BUTTON_WIDTH 60 +#define MENU_BUTTON_HEIGHT 30 +#define NUM_INPUT_HEIGHT 30 + #include "ui_sa.c" #define MENU_STACK_DEPTH_MAX 4 @@ -1083,6 +1088,10 @@ menu_push_submenu(const menuitem_t *submenu) menu_stack[menu_current_level] = submenu; ensure_selection(); erase_menu_buttons(); + if (menu_is_form(submenu)) { + redraw_frame(); + area_width = 0; + } draw_menu(); } @@ -1105,7 +1114,7 @@ menu_invoke(int item) const menuitem_t *menu = menu_stack[menu_current_level]; menu = &menu[item]; - switch (menu->type) { + switch (menu->type & 0x0f) { case MT_NONE: case MT_BLANK: case MT_CLOSE: @@ -1130,10 +1139,6 @@ menu_invoke(int item) } } -#define MENU_BUTTON_WIDTH 60 -#define MENU_BUTTON_HEIGHT 30 -#define NUM_INPUT_HEIGHT 30 - #define KP_WIDTH 48 #define KP_HEIGHT 48 // Key x, y position (0 - 15) on screen @@ -1466,7 +1471,8 @@ menu_apply_touch(void) return; } } - + if (menu_is_form(menu)) + return; touch_wait_release(); ui_mode_normal(); } @@ -2064,8 +2070,12 @@ ui_process_keypad(void) } redraw_frame(); - request_to_redraw_grid(); - ui_mode_normal(); + if (menu_is_form(menu_stack[menu_current_level])) + ui_mode_menu(); //Reactivate menu after keypad + else { + ui_mode_normal(); + request_to_redraw_grid(); + } //redraw_all(); touch_start_watchdog(); } diff --git a/ui_sa.c b/ui_sa.c index 00e5aef..8721954 100644 --- a/ui_sa.c +++ b/ui_sa.c @@ -14,10 +14,12 @@ void SetAttenuation(int); void SetPowerLevel(int); void SetGenerate(int); void SetRBW(int); +extern int settingBandwidth; void SetSpur(int); int GetSpur(void); void SetAverage(int); int GetAverage(void); +extern int settingAverage; void SetStorage(void); void SetClearStorage(void); void SetSubtractStorage(void); @@ -159,17 +161,26 @@ static const char * const keypad_mode_label[] = { int generator_enabled = false; +extern const menuitem_t menu_lowoutputmode[]; +extern const menuitem_t menu_highoutputmode[]; + static void menu_mode_cb(int item, uint8_t data) { (void)data; switch (item) { - case 4: // Change reference output + case 4: // Change reference output, should not happen!!! break; default: SetMode(item); - menu_move_back(); - ui_mode_normal(); draw_cal_status(); + if (item == 2) { // Activate menu_lowoutputmode as input form + set_sweep_frequency(ST_SPAN, 0); + menu_push_submenu(menu_lowoutputmode); + } else if (item == 3) { // Activate menu_highoutputmode as input form + set_sweep_frequency(ST_SPAN, 0); + menu_push_submenu(menu_highoutputmode); + } else + ui_mode_normal(); // Exit menu after setting the mode break; } @@ -399,6 +410,47 @@ static void menu_scale_cb(int item, uint8_t data) draw_cal_status(); } +static void menu_lowoutputmode_cb(int item, uint8_t data) +{ + int status; + int km = data; +// if (km == KM_SCALE && trace[uistat.current_trace].type == TRC_DELAY) { +// km = KM_SCALEDELAY; +// } + status = btn_wait_release(); + if (status & EVT_BUTTON_DOWN_LONG) { + ui_mode_numeric(km); +// ui_process_numeric(); + } else { + area_width = AREA_WIDTH_NORMAL - MENU_BUTTON_WIDTH; + redraw_frame(); // Remove form numbers + ui_mode_keypad(km); + ui_process_keypad(); + } + draw_cal_status(); +} + +static void menu_highoutputmode_cb(int item, uint8_t data) +{ + int status; + int km = data; +// if (km == KM_SCALE && trace[uistat.current_trace].type == TRC_DELAY) { +// km = KM_SCALEDELAY; +// } + status = btn_wait_release(); + if (status & EVT_BUTTON_DOWN_LONG) { + ui_mode_numeric(km); +// ui_process_numeric(); + } else { + area_width = AREA_WIDTH_NORMAL - MENU_BUTTON_WIDTH; + redraw_frame(); // Remove form numbers + ui_mode_keypad(km); + ui_process_keypad(); + } + draw_cal_status(); +} + + static void menu_settings_cb(int item, uint8_t data) { (void)data; @@ -465,8 +517,56 @@ static void menu_stimulus_cb(int item, uint8_t data) //static void menu_marker_sel_cb(int); //static void menu_marker_op_cb(int); +#if 0 + +#pragma pack(push, 2) +typedef struct { + uint8_t type; + int *data; + char *format; +} menuvalue_t; +#pragma pack(pop) + +enum { + MVT_INT, MVT_FLOAT, MVT_STRINGARRAY +}; +enum { +MV_AVERAGE, MV_RBW, MV_DBPER, MV_REFER, MV_POWER, MVSAMPLETIME, MV_IFFREQ +}; + +static const char *average_text[] = +{ + "OFF", "MIN HOLD", "MAX HOLD", "2", "4", "8" +}; + +static const menuvalue_t menu_value[] = { + { MVT_STRINGARRAY,&settingAverage, (char *)average_text }, + { MVT_INT, &settingBandwidth, "%dkHz" }, + { MVT_INT, &settingScale, "%ddB/" }, + { MVT_INT, &settingRefer, "%dB" }, + { MVT_INT, &settingPower, "%dB" }, + { MVT_INT, &settingSampleTime, "%dmS" }, + { MVT_INT, %setting_IF, "%dHz" }, + } +}; +#endif + // ===[MENU DEFINITION]========================================================= +const menuitem_t menu_lowoutputmode[] = { + { MT_CALLBACK, KM_CENTER, "FREQUENCY", menu_lowoutputmode_cb}, + { MT_CALLBACK, KM_ATTENUATION,"LEVEL", menu_lowoutputmode_cb}, + { MT_CANCEL, 0, S_LARROW" BACK",NULL }, + { MT_NONE, 0, NULL, NULL } // sentinel +}; + +const menuitem_t menu_highoutputmode[] = { + { MT_CALLBACK, KM_CENTER, "FREQUENCY", menu_highoutputmode_cb}, + { MT_CALLBACK, KM_DRIVE, "LEVEL", menu_highoutputmode_cb}, + { MT_CANCEL, 0, S_LARROW" BACK",NULL }, + { MT_NONE, 0, NULL, NULL } // sentinel +}; + static const menuitem_t menu_average[] = { { MT_CALLBACK, 0, "OFF", menu_average_cb}, { MT_CALLBACK, 0, "MIN", menu_average_cb}, @@ -651,6 +751,14 @@ static const menuitem_t menu_top[] = { #define ACTIVE_COLOR RGBHEX(0x007FFF) +void frequency_string(char *buf, size_t len, int32_t freq); + +int menu_is_form(const menuitem_t *menu) +{ + return(menu == menu_lowoutputmode || + menu == menu_highoutputmode); +} + static void menu_item_modify_attribute( const menuitem_t *menu, int item, uint16_t *fg, uint16_t *bg) { @@ -722,6 +830,48 @@ static void menu_item_modify_attribute( *fg = config.menu_normal_color; } } + if (ui_mode == UI_MENU && menu_is_form(menu)) { +// if (item == 0) +// redraw_frame(); + if (item <= 1) { + + area_width = 0; +// area_height = HEIGHT - 32; + int y = MENU_BUTTON_HEIGHT*item; + uint16_t bg = config.menu_normal_color; + uint16_t fg = DEFAULT_MENU_TEXT_COLOR; + // ili9341_fill(320-MENU_BUTTON_WIDTH, y, MENU_BUTTON_WIDTH, MENU_BUTTON_HEIGHT-2, bg); + ili9341_set_foreground(fg); + ili9341_set_background(bg); + char buf[10]; + ili9341_fill(50+25, y, 170, MENU_BUTTON_HEIGHT-2, bg); + if (menu == menu_lowoutputmode) { + switch (item) { + case 0: + set_sweep_frequency(ST_SPAN, 0); // For CW sweep mode + frequency_string(buf, sizeof buf, frequency0); + break; + case 1: + plot_printf(buf, sizeof buf, "%ddB", -10 - settingAttenuate); + break; + } + } + if (menu == menu_highoutputmode) { + switch (item) { + case 0: + set_sweep_frequency(ST_SPAN, 0); // For CW sweep mode + frequency_string(buf, sizeof buf, frequency0); + break; + case 1: + plot_printf(buf, sizeof buf, "%ddB", -10 - settingDrive); + break; + } + } + ili9341_drawstring_size(buf, 130, y+6, 2); + } + }else{ + area_width = AREA_WIDTH_NORMAL - MENU_BUTTON_WIDTH; + } } static void fetch_numeric_target(void) @@ -776,7 +926,6 @@ static void fetch_numeric_target(void) // uistat.previous_value = uistat.value; } - static void set_numeric_value(void) { From 44eb6027a952d2b4f410fa50ff15ee5387615ab5 Mon Sep 17 00:00:00 2001 From: erikkaashoek Date: Tue, 24 Mar 2020 09:55:25 +0100 Subject: [PATCH 03/23] No stepping during output mode --- nanovna.h | 4 +-- sa_core.c | 94 +++++++++++++++++++++++-------------------------------- si4432.c | 6 ++-- ui_sa.c | 22 ++++++++----- 4 files changed, 59 insertions(+), 67 deletions(-) diff --git a/nanovna.h b/nanovna.h index 93398a9..0984dc7 100644 --- a/nanovna.h +++ b/nanovna.h @@ -572,8 +572,8 @@ int plot_printf(char *str, int, const char *fmt, ...); #define PULSE do { palClearPad(GPIOC, GPIOC_LED); palSetPad(GPIOC, GPIOC_LED);} while(0) extern int settingAttenuate; extern int settingPowerCal; -extern int stepDelay; -extern int settingSpeed; +extern int settingStepDelay; +extern int actualStepDelay; extern int settingMode; void update_rbw(uint32_t delta_f); diff --git a/sa_core.c b/sa_core.c index 18c3da8..b218a64 100644 --- a/sa_core.c +++ b/sa_core.c @@ -80,6 +80,7 @@ int settingDrive=0; // 0-3 , 3=+20dBm int settingAGC = true; int settingLNA = false; int extraVFO = false; +int settingStepDelay = 0; uint32_t minFreq = 0; uint32_t maxFreq = 520000000; @@ -101,9 +102,22 @@ void SetGenerate(int g) dirty = true; } +void SetDrive(int d) +{ + settingDrive = d; + dirty = true; +} + +void SetIF(int f) +{ + frequency_IF = f; + dirty = true; +} + int GetMode(void) { return(settingMode); + dirty = true; } void SetMode(int m) @@ -141,6 +155,7 @@ void SetStorage(void) stored_t[i] = actual_t[i]; settingShowStorage = true; trace[TRACE_STORED].enabled = true; + dirty = true; } int GetStorage(void) @@ -193,6 +208,7 @@ int settingLevelOffset(void) { if (settingMode & 1) return(config.high_level_offset); + dirty = true; return(config.low_level_offset); } @@ -214,6 +230,12 @@ void SetSpur(int v) dirty = true; } +void SetStepDelay(int d) +{ + settingStepDelay = d; + dirty = true; +} + int GetSpur(void) { return(settingSpur); @@ -234,6 +256,7 @@ int GetAverage(void) void ToggleLNA(void) { settingLNA = !settingLNA; + dirty = true; } int GetLNA(void) @@ -244,6 +267,7 @@ int GetLNA(void) void ToggleAGC(void) { settingAGC = !settingAGC; + dirty = true; } int GetAGC(void) @@ -570,21 +594,23 @@ void update_rbw(uint32_t delta_f) dirty = true; } +static int old_lf = -1; + float perform(bool break_on_operation, int i, int32_t f, int extraV) { long local_IF = ((settingMode & 1) == 0?frequency_IF + (int)(rbw < 300.0?settingSpur * 1000 * rbw :0):0); - if (i == 0) { - if (settingSpeed == 0){ + if (i == 0 && dirty) { + if (settingStepDelay == 0){ if (rbw < 10.0) - stepDelay = 2500; + actualStepDelay = 2500; else if (rbw <30.0) - stepDelay = 2000; + actualStepDelay = 2000; else if (rbw <100.0) - stepDelay = 1000; + actualStepDelay = 1000; else - stepDelay = 500; + actualStepDelay = 500; } else - stepDelay = settingSpeed; + actualStepDelay = settingStepDelay; // setupSA(); @@ -595,10 +621,10 @@ float perform(bool break_on_operation, int i, int32_t f, int extraV) temppeakLevel = -150; if (local_IF) setFreq (0, local_IF); - if (dirty) { +// if (dirty) { scandirty = true; dirty = false; - } +// } } volatile int subSteps = ((int)(2 * vbw / rbw)); float RSSI = -150.0; @@ -607,57 +633,17 @@ float perform(bool break_on_operation, int i, int32_t f, int extraV) int lf = (uint32_t)(f + (int)(t * 500 * rbw)); if (extraV) setFreq (0, local_IF + lf - refferFreq[settingRefer]); // Offset so fundamental of reffer is visible - setFreq (1, local_IF + lf); + if (lf != old_lf) // only set on change + setFreq (1, local_IF + lf); + old_lf = lf; float subRSSI = SI4432_RSSI(lf, (settingMode & 1))+settingLevelOffset()+settingAttenuate; if (RSSI < subRSSI) RSSI = subRSSI; t++; - if (operation_requested && break_on_operation) + if ((operation_requested && break_on_operation ) || (settingMode & 2 )) // output modes do not step. subSteps = 0; // abort } while (subSteps-- > 0); return(RSSI); -#if 0 - temp_t[i] = RSSI; - if (settingSubtractStorage) { - RSSI = RSSI - stored_t[i] ; - } - if (scandirty || settingAverage == AV_OFF) - actual_t[i] = RSSI; - else { - switch(settingAverage) { - case AV_MIN: if (actual_t[i] > RSSI) actual_t[i] = RSSI; break; - case AV_MAX: if (actual_t[i] < RSSI) actual_t[i] = RSSI; break; - case AV_2: actual_t[i] = (actual_t[i] + RSSI) / 2.0; break; - case AV_4: actual_t[i] = (actual_t[i]*3 + RSSI) / 4.0; break; - case AV_8: actual_t[i] = (actual_t[i]*7 + RSSI) / 8.0; break; - } - } - if (frequencies[i] > 1000000) { - if (temppeakLevel < actual_t[i]) { - temppeakIndex = i; - temppeakLevel = actual_t[i]; - } - } - if (temp_t[i] == 0) { - SI4432_Init(); - } - if (i == POINTS_COUNT -1) { - if (scandirty) { - scandirty = false; - } - peakIndex = temppeakIndex; - peakLevel = actual_t[peakIndex]; - peakFreq = frequencies[peakIndex]; - settingSpur = -settingSpur; - int peak_marker = 0; - markers[peak_marker].enabled = true; - markers[peak_marker].index = peakIndex; - markers[peak_marker].frequency = frequencies[markers[peak_marker].index]; -// redraw_marker(peak_marker, FALSE); - - - } -#endif } // main loop for measurement @@ -881,7 +867,7 @@ void draw_cal_status(void) ili9341_drawstring("Scan:", x, y); y += YSTEP; - int32_t t = (int)((2* vbwSteps * sweep_points * ( stepDelay / 100) )) /10 * (settingSpur ? 2 : 1); // in mS + int32_t t = (int)((2* vbwSteps * sweep_points * ( actualStepDelay / 100) )) /10 * (settingSpur ? 2 : 1); // in mS if (t>1000) plot_printf(buf, BLEN, "%dS",(t+500)/1000); else diff --git a/si4432.c b/si4432.c index 6efbd8f..f4115a6 100644 --- a/si4432.c +++ b/si4432.c @@ -226,8 +226,8 @@ void SI4432_Set_Frequency ( long Freq ) { #endif } -int stepDelay = 1500; -int settingSpeed = 0; +int actualStepDelay = 1500; + float SI4432_RSSI(uint32_t i, int s) { @@ -239,7 +239,7 @@ float SI4432_RSSI(uint32_t i, int s) } else #endif SI4432_Sel = s; - chThdSleepMicroseconds(stepDelay); + chThdSleepMicroseconds(actualStepDelay); RSSI_RAW = (unsigned char)SI4432_Read_Byte( 0x26 ) ; if (settingMode < 2 && RSSI_RAW == 0) SI4432_Init(); diff --git a/ui_sa.c b/ui_sa.c index 8721954..a009015 100644 --- a/ui_sa.c +++ b/ui_sa.c @@ -14,6 +14,9 @@ void SetAttenuation(int); void SetPowerLevel(int); void SetGenerate(int); void SetRBW(int); +void SetDrive(int d); +void SetIF(int f); +void SetStepDelay(int t); extern int settingBandwidth; void SetSpur(int); int GetSpur(void); @@ -35,8 +38,8 @@ extern int extraVFO; extern int settingDrive; extern int settingLNA; extern int settingAGC; -extern int settingSpeed; -extern int stepDelay; +// extern int settingSpeed; +extern int settingStepDelay; enum { KM_START, KM_STOP, KM_CENTER, KM_SPAN, KM_CW, KM_REFPOS, KM_SCALE, KM_ATTENUATION, KM_ACTUALPOWER, KM_IF, KM_SAMPLETIME, KM_DRIVE @@ -414,6 +417,7 @@ static void menu_lowoutputmode_cb(int item, uint8_t data) { int status; int km = data; + (void) item; // if (km == KM_SCALE && trace[uistat.current_trace].type == TRC_DELAY) { // km = KM_SCALEDELAY; // } @@ -434,6 +438,8 @@ static void menu_highoutputmode_cb(int item, uint8_t data) { int status; int km = data; + (void) item; + // if (km == KM_SCALE && trace[uistat.current_trace].type == TRC_DELAY) { // km = KM_SCALEDELAY; // } @@ -843,13 +849,13 @@ static void menu_item_modify_attribute( // ili9341_fill(320-MENU_BUTTON_WIDTH, y, MENU_BUTTON_WIDTH, MENU_BUTTON_HEIGHT-2, bg); ili9341_set_foreground(fg); ili9341_set_background(bg); - char buf[10]; + char buf[15]; ili9341_fill(50+25, y, 170, MENU_BUTTON_HEIGHT-2, bg); if (menu == menu_lowoutputmode) { switch (item) { case 0: set_sweep_frequency(ST_SPAN, 0); // For CW sweep mode - frequency_string(buf, sizeof buf, frequency0); + plot_printf(buf, sizeof buf, "%3.3fMHz", frequency0 / 1000000.0); break; case 1: plot_printf(buf, sizeof buf, "%ddB", -10 - settingAttenuate); @@ -908,7 +914,7 @@ static void fetch_numeric_target(void) uistat.value = frequency_IF; break; case KM_SAMPLETIME: - uistat.value = settingSpeed; + uistat.value = settingStepDelay; break; case KM_DRIVE: uistat.value = settingDrive; @@ -963,14 +969,14 @@ set_numeric_value(void) config_save(); break; case KM_IF: - frequency_IF = uistat.value; + SetIF(uistat.value); config_save(); break; case KM_SAMPLETIME: - settingSpeed = uistat.value; + SetStepDelay(uistat.value); break; case KM_DRIVE: - settingDrive = uistat.value; + SetDrive(uistat.value); break; } } From 9fb0638deffa3a3b98ef41c7a857b053da23efd9 Mon Sep 17 00:00:00 2001 From: erikkaashoek Date: Wed, 25 Mar 2020 09:48:55 +0100 Subject: [PATCH 04/23] Full screen mode menu --- nanovna.h | 9 +++ plot.c | 35 ++++++--- sa_core.c | 56 ++++++++----- ui.c | 84 ++++++++++++++------ ui_sa.c | 229 +++++++++++++++++++++++++++++++----------------------- 5 files changed, 260 insertions(+), 153 deletions(-) diff --git a/nanovna.h b/nanovna.h index 0984dc7..3074186 100644 --- a/nanovna.h +++ b/nanovna.h @@ -122,6 +122,13 @@ enum { enum { M_LOW, M_HIGH, M_GENLOW, M_GENHIGH, }; + +#define MODE_OUTPUT(x) ((x) == M_GENLOW || (x) == M_GENHIGH ) +#define MODE_INPUT(x) ((x) == M_LOW || (x) == M_HIGH ) +#define MODE_HIGH(x) ((x) == M_HIGH || (x) == M_GENHIGH ) +#define MODE_LOW(x) ((x) == M_LOW || (x) == M_GENLOW ) +#define MODE_SELECT(x) (MODE_HIGH(x) ? 1 : 0) + #define SWEEP_ENABLE 0x01 #define SWEEP_ONCE 0x02 extern int8_t sweep_mode; @@ -537,6 +544,7 @@ typedef struct uistat { uint8_t lever_mode; uint8_t marker_delta; uint8_t marker_tracking; + char text[20]; } uistat_t; extern uistat_t uistat; @@ -576,6 +584,7 @@ extern int settingStepDelay; extern int actualStepDelay; extern int settingMode; void update_rbw(uint32_t delta_f); +int GetActualRBW(void); #define byte uint8_t extern volatile int SI4432_Sel; // currently selected SI4432 diff --git a/plot.c b/plot.c index 481c45e..81f628a 100644 --- a/plot.c +++ b/plot.c @@ -1,5 +1,4 @@ -/* - * Copyright (c) 2014-2015, TAKAHASHI Tomohiro (TTRFTECH) edy555@gmail.com +/* Copyright (c) 2014-2015, TAKAHASHI Tomohiro (TTRFTECH) edy555@gmail.com * All rights reserved. * * This is free software; you can redistribute it and/or modify @@ -796,12 +795,19 @@ static void trace_get_value_string( } else { dfreq = frequencies[i]; } - frequency_string(&buf2[1], sizeof(buf2) -1, dfreq); + if (GetActualRBW() < 10) + plot_printf(&buf2[1], sizeof(buf2) -1, "%3.3f" , (dfreq + 500) / 1000000.0); + else if (GetActualRBW() < 100) + plot_printf(&buf2[1], sizeof(buf2) -1, "%3.2f" , (dfreq + 5000) / 1000000.0); + else + plot_printf(&buf2[1], sizeof(buf2) -1, "%3.1f" , (dfreq + 50000) / 1000000.0); + +// frequency_string(&buf2[1], sizeof(buf2) -1, dfreq); v = logmag(&coeff[i]); if (v == -INFINITY) plot_printf(buf, len, "-INF"); else - plot_printf(buf, len, " %s %.2f", buf2, v - rlevel); + plot_printf(buf, len, "%s %.1f", buf2, v - rlevel); } #ifdef __VNA__ static int @@ -1817,26 +1823,35 @@ static void cell_draw_marker_info(int x0, int y0) continue; #if 1 int xpos = 1 + (j%2)*(WIDTH/2) + CELLOFFSETX - x0; - int ypos = 1 + (j/2)*(13) - y0; +// int ypos = 1 + (j/2)*(13) - y0; + int ypos = 1 + (j/2)*(16) - y0; #else int xpos = 1 + CELLOFFSETX - x0; int ypos = 1 + j*(FONT_GET_HEIGHT*2+1) - y0; #endif int k = 0; - if (i == active_marker) + if (i == active_marker) { +// ili9341_set_foreground(DEFAULT_BG_COLOR); +// ili9341_set_background(marker_color[markers[i].mtype]); buf[k++] = '\033'; // Right arrow (?) - else + } else { +// ili9341_set_background(DEFAULT_BG_COLOR); +// ili9341_set_foreground(marker_color[markers[i].mtype]); buf[k++] = ' '; +// buf[k++] = ' '; + } buf[k++] = i+'1'; - buf[k++] = marker_letter[markers[i].mtype]; +// buf[k++] = marker_letter[markers[i].mtype]; buf[k++] = 0; + ili9341_set_background(DEFAULT_BG_COLOR); ili9341_set_foreground(marker_color[markers[i].mtype]); cell_drawstring_7x13(buf, xpos, ypos); +// cell_drawstring_size(buf, xpos, ypos, 2); trace_get_value_string( t, buf, sizeof buf, idx, measured[trace[t].channel], frequencies, sweep_points, ridx, markers[i].mtype); -// cell_drawstring_7x13(w, h, buf, xpos+2*7, ypos, config.trace_color[t]); - cell_drawstring_7x13(buf, xpos+4*7, ypos); + cell_drawstring_7x13(buf, xpos+3*7, ypos); +// cell_drawstring_size(buf, xpos+3*7, ypos, 2); j++; } } diff --git a/sa_core.c b/sa_core.c index b218a64..0b8d107 100644 --- a/sa_core.c +++ b/sa_core.c @@ -75,12 +75,14 @@ int settingSpur = 0; int settingAverage = 0; int settingShowStorage = 0; int settingSubtractStorage = 0; -int settingMode = 0; +int settingMode = M_LOW; int settingDrive=0; // 0-3 , 3=+20dBm int settingAGC = true; int settingLNA = false; int extraVFO = false; int settingStepDelay = 0; +float rbw = 0; +float vbw = 0; uint32_t minFreq = 0; uint32_t maxFreq = 520000000; @@ -122,21 +124,31 @@ int GetMode(void) void SetMode(int m) { + if (settingMode == m) + return; settingMode = m; switch(m) { case M_LOW: + set_sweep_frequency(ST_START, (int32_t) 0); + set_sweep_frequency(ST_STOP, (int32_t) 300000000); + goto min_max_low; case M_GENLOW: + set_sweep_frequency(ST_CENTER, (int32_t) 10000000); + set_sweep_frequency(ST_SPAN, 0); + min_max_low: minFreq = 0; maxFreq = 520000000; - set_sweep_frequency(ST_START, (int32_t) 0); - set_sweep_frequency(ST_STOP, (int32_t) 300000000); break; case M_HIGH: - case M_GENHIGH: - minFreq = 260000000; - maxFreq = 960000000; set_sweep_frequency(ST_START, (int32_t) 300000000); set_sweep_frequency(ST_STOP, (int32_t) 960000000); + goto min_max_high; + case M_GENHIGH: + set_sweep_frequency(ST_CENTER, (int32_t) 300000000); + set_sweep_frequency(ST_SPAN, 0); + min_max_high: + minFreq = 240000000; + maxFreq = 960000000; break; } dirty = true; @@ -192,9 +204,9 @@ extern float peakLevel; void SetPowerLevel(int o) { if (o != 100) { - if (settingMode & 1) + if (settingMode == M_HIGH) config.high_level_offset = o - peakLevel - settingAttenuate + settingLevelOffset(); - else + else if (settingMode == M_LOW) config.low_level_offset = o - peakLevel - settingAttenuate + settingLevelOffset(); } else { @@ -206,10 +218,11 @@ void SetPowerLevel(int o) int settingLevelOffset(void) { - if (settingMode & 1) + if (settingMode == M_HIGH) return(config.high_level_offset); - dirty = true; - return(config.low_level_offset); + if (settingMode == M_LOW) + return(config.high_level_offset); + return(0); } void SetRBW(int v) @@ -224,6 +237,10 @@ int GetRBW(void) return(settingBandwidth); } +int GetActualRBW(void) +{ + return((int) rbw); +} void SetSpur(int v) { settingSpur = v; @@ -287,8 +304,6 @@ int temppeakIndex; #define BARSTART 24 -float rbw = 0; -float vbw = 0; int vbwSteps = 1; #if 0 @@ -586,7 +601,7 @@ void update_rbw(uint32_t delta_f) rbw = 2.6; if (rbw > 600) rbw = 600; - SI4432_Sel = (settingMode & 1); + SI4432_Sel = MODE_SELECT(settingMode); rbw = SI4432_SET_RBW(rbw); vbwSteps = ((int)(2 * vbw / rbw)); if (vbwSteps < 1) @@ -598,7 +613,7 @@ static int old_lf = -1; float perform(bool break_on_operation, int i, int32_t f, int extraV) { - long local_IF = ((settingMode & 1) == 0?frequency_IF + (int)(rbw < 300.0?settingSpur * 1000 * rbw :0):0); + long local_IF = (MODE_LOW(settingMode)?frequency_IF + (int)(rbw < 300.0?settingSpur * 1000 * rbw :0):0); if (i == 0 && dirty) { if (settingStepDelay == 0){ if (rbw < 10.0) @@ -636,11 +651,11 @@ float perform(bool break_on_operation, int i, int32_t f, int extraV) if (lf != old_lf) // only set on change setFreq (1, local_IF + lf); old_lf = lf; - float subRSSI = SI4432_RSSI(lf, (settingMode & 1))+settingLevelOffset()+settingAttenuate; + float subRSSI = SI4432_RSSI(lf, MODE_SELECT(settingMode))+settingLevelOffset()+settingAttenuate; if (RSSI < subRSSI) RSSI = subRSSI; t++; - if ((operation_requested && break_on_operation ) || (settingMode & 2 )) // output modes do not step. + if ((operation_requested && break_on_operation ) || (MODE_OUTPUT(settingMode))) // output modes do not step. subSteps = 0; // abort } while (subSteps-- > 0); return(RSSI); @@ -944,10 +959,9 @@ static void test_acquire(int i) { pause_sweep(); if (test_case[i].center < 300) - settingMode = 0; + settingMode = M_LOW; else - settingMode = 1; - + settingMode = M_HIGH; set_sweep_frequency(ST_CENTER, (int32_t)test_case[i].center * 1000000); set_sweep_frequency(ST_SPAN, (int32_t)test_case[i].span * 1000000); sweep(false); @@ -1174,7 +1188,7 @@ void self_test(void) set_trace_refpos(1, NGRIDY - (-10) / get_trace_scale(0)); set_trace_refpos(2, NGRIDY - (-10) / get_trace_scale(0)); set_refer_output(0); - settingMode = 0; + settingMode = M_LOW; draw_cal_status(); menu_autosettings_cb(0); diff --git a/ui.c b/ui.c index da79dc3..615e017 100644 --- a/ui.c +++ b/ui.c @@ -1,5 +1,4 @@ -/* - * Copyright (c) 2014-2015, TAKAHASHI Tomohiro (TTRFTECH) edy555@gmail.com +/* Copyright (c) 2014-2015, TAKAHASHI Tomohiro (TTRFTECH) edy555@gmail.com * All rights reserved. * * This is free software; you can redistribute it and/or modify @@ -31,6 +30,7 @@ uistat_t uistat = { lever_mode: LM_MARKER, marker_delta: FALSE, marker_tracking : FALSE, + text : "", }; #define NO_EVENT 0 @@ -433,8 +433,11 @@ enum { MT_SUBMENU, MT_CALLBACK, MT_CANCEL, + MT_TITLE, MT_CLOSE }; +#define MT_FORM 0x80 // Or with menu type to get large button with current value +#define MT_MASK(x) (0x7F & (x)) typedef void (*menuaction_cb_t)(int item, uint8_t data); @@ -1048,6 +1051,7 @@ const menuitem_t menu_top[] = { #define MENU_BUTTON_WIDTH 60 +#define MENU_FORM_WIDTH 290 #define MENU_BUTTON_HEIGHT 30 #define NUM_INPUT_HEIGHT 30 @@ -1055,7 +1059,7 @@ const menuitem_t menu_top[] = { #define MENU_STACK_DEPTH_MAX 4 const menuitem_t *menu_stack[MENU_STACK_DEPTH_MAX] = { - menu_top, NULL, NULL, NULL + menu_mode, NULL, NULL, NULL }; static void @@ -1063,7 +1067,7 @@ ensure_selection(void) { const menuitem_t *menu = menu_stack[menu_current_level]; int i; - for (i = 0; menu[i].type != MT_NONE; i++) + for (i = 0; MT_MASK(menu[i].type) != MT_NONE; i++) ; if (selection >= i) selection = i-1; @@ -1074,20 +1078,20 @@ menu_move_back(void) { if (menu_current_level == 0) return; + erase_menu_buttons(); menu_current_level--; ensure_selection(); - erase_menu_buttons(); draw_menu(); } static void menu_push_submenu(const menuitem_t *submenu) { + erase_menu_buttons(); if (menu_current_level < MENU_STACK_DEPTH_MAX-1) menu_current_level++; menu_stack[menu_current_level] = submenu; ensure_selection(); - erase_menu_buttons(); if (menu_is_form(submenu)) { redraw_frame(); area_width = 0; @@ -1264,6 +1268,7 @@ draw_keypad(void) ili9341_set_background(bg); int x = KP_GET_X(keypads[i].x); int y = KP_GET_Y(keypads[i].y); +// ili9341_fill(x, y, KP_WIDTH, KP_HEIGHT, DEFAULT_MENU_TEXT_COLOR); // black area around button, causes flicker.... ili9341_fill(x+2, y+2, KP_WIDTH-4, KP_HEIGHT-4, bg); ili9341_drawfont(keypads[i].c, x + (KP_WIDTH - NUM_FONT_GET_WIDTH) / 2, @@ -1414,30 +1419,55 @@ static void draw_menu_buttons(const menuitem_t *menu) { int i = 0; + char text[30]; for (i = 0; i < 7; i++) { const char *l1, *l2; - if (menu[i].type == MT_NONE) + if (MT_MASK(menu[i].type) == MT_NONE) break; - if (menu[i].type == MT_BLANK) + if (MT_MASK(menu[i].type) == MT_BLANK) continue; int y = MENU_BUTTON_HEIGHT*i; - uint16_t bg = config.menu_normal_color; - uint16_t fg = DEFAULT_MENU_TEXT_COLOR; + uint16_t bg; + uint16_t fg; + if (MT_MASK(menu[i].type) == MT_TITLE) { + fg = config.menu_normal_color; + bg = DEFAULT_MENU_TEXT_COLOR; + } else { + bg = config.menu_normal_color; + fg = DEFAULT_MENU_TEXT_COLOR; + } // focus only in MENU mode but not in KEYPAD mode if (ui_mode == UI_MENU && i == selection) bg = config.menu_active_color; - ili9341_fill(320-MENU_BUTTON_WIDTH, y, MENU_BUTTON_WIDTH, MENU_BUTTON_HEIGHT-2, bg); - - menu_item_modify_attribute(menu, i, &fg, &bg); + + uint16_t old_bg = bg; + int active_button_width; + menu_item_modify_attribute(menu, i, &fg, &bg); // before plot_printf to create status text + if (menu[i].type & MT_FORM) { + active_button_width = MENU_FORM_WIDTH; + if (MT_MASK(menu[i].type) == MT_CALLBACK) { // Only callback can have value + keypad_mode = menu[i].data; + fetch_numeric_target(); + } + plot_printf(text, sizeof text, menu[i].label, uistat.text); + } + else + active_button_width = MENU_BUTTON_WIDTH; + ili9341_fill(320-active_button_width, y, active_button_width, MENU_BUTTON_HEIGHT-2, old_bg); // Set button to unmodified background color ili9341_set_foreground(fg); ili9341_set_background(bg); + if (menu[i].type & MT_FORM) { + ili9341_fill(320-active_button_width+3, y+8, active_button_width-6, 2+FONT_GET_HEIGHT*2+2, bg); + ili9341_drawstring_size(text, 320-active_button_width+5, y+10, 2); + } else { if (menu_is_multiline(menu[i].label, &l1, &l2)) { - ili9341_fill(320-MENU_BUTTON_WIDTH+3, y+5, MENU_BUTTON_WIDTH-6, 2+FONT_GET_HEIGHT+1+FONT_GET_HEIGHT+2, bg); - ili9341_drawstring(l1, 320-MENU_BUTTON_WIDTH+5, y+7); - ili9341_drawstring(l2, 320-MENU_BUTTON_WIDTH+5, y+7+FONT_GET_HEIGHT+1); + ili9341_fill(320-active_button_width+3, y+5, active_button_width-6, 2+FONT_GET_HEIGHT+1+FONT_GET_HEIGHT+2, bg); + ili9341_drawstring(l1, 320-active_button_width+5, y+7); + ili9341_drawstring(l2, 320-active_button_width+5, y+7+FONT_GET_HEIGHT+1); } else { - ili9341_fill(320-MENU_BUTTON_WIDTH+3, y+8, MENU_BUTTON_WIDTH-6, 2+FONT_GET_HEIGHT+2, bg); - ili9341_drawstring(menu[i].label, 320-MENU_BUTTON_WIDTH+5, y+10); + ili9341_fill(320-active_button_width+3, y+8, active_button_width-6, 2+FONT_GET_HEIGHT+2, bg); + ili9341_drawstring(menu[i].label, 320-active_button_width+5, y+10); + } } } } @@ -1461,12 +1491,18 @@ menu_apply_touch(void) touch_position(&touch_x, &touch_y); for (i = 0; i < 7; i++) { - if (menu[i].type == MT_NONE) + if (MT_MASK(menu[i].type) == MT_NONE) break; - if (menu[i].type == MT_BLANK) + if (MT_MASK(menu[i].type == MT_BLANK) || MT_MASK(menu[i].type) == MT_TITLE) continue; int y = MENU_BUTTON_HEIGHT*i; - if (y < touch_y && touch_y < y+MENU_BUTTON_HEIGHT && 320-MENU_BUTTON_WIDTH < touch_x) { + int active_button_width; + if (menu[i].type & MT_FORM) + active_button_width = MENU_FORM_WIDTH; + else + active_button_width = MENU_BUTTON_WIDTH; + + if (y < touch_y && touch_y < y+MENU_BUTTON_HEIGHT && 320-active_button_width < touch_x) { menu_select_touch(i); return; } @@ -1486,7 +1522,8 @@ draw_menu(void) static void erase_menu_buttons(void) { - ili9341_fill(320-MENU_BUTTON_WIDTH, 0, MENU_BUTTON_WIDTH, MENU_BUTTON_HEIGHT*7, DEFAULT_BG_COLOR); + ili9341_fill(area_width, 0, 320 - area_width, area_height, DEFAULT_BG_COLOR); +// ili9341_fill(320-MENU_BUTTON_WIDTH, 0, MENU_BUTTON_WIDTH, MENU_BUTTON_HEIGHT*7, DEFAULT_BG_COLOR); } static void @@ -1649,7 +1686,8 @@ ui_mode_keypad(int _keypad_mode) ui_mode = UI_KEYPAD; area_width = AREA_WIDTH_NORMAL - MENU_BUTTON_WIDTH; area_height = HEIGHT - 32; - draw_menu(); + if (!menu_is_form(menu_stack[menu_current_level])) + draw_menu(); draw_keypad(); draw_numeric_area_frame(); draw_numeric_input(""); diff --git a/ui_sa.c b/ui_sa.c index a009015..db92473 100644 --- a/ui_sa.c +++ b/ui_sa.c @@ -41,11 +41,14 @@ extern int settingAGC; // extern int settingSpeed; extern int settingStepDelay; + + enum { - KM_START, KM_STOP, KM_CENTER, KM_SPAN, KM_CW, KM_REFPOS, KM_SCALE, KM_ATTENUATION, KM_ACTUALPOWER, KM_IF, KM_SAMPLETIME, KM_DRIVE + KM_START=1, KM_STOP, KM_CENTER, KM_SPAN, KM_CW, KM_REFPOS, KM_SCALE, KM_ATTENUATION, KM_ACTUALPOWER, KM_IF, KM_SAMPLETIME, KM_DRIVE }; + #define KP_X(x) (48*(x) + 2 + (320-BUTTON_WIDTH-192)) #define KP_Y(y) (48*(y) + 2) @@ -166,27 +169,28 @@ int generator_enabled = false; extern const menuitem_t menu_lowoutputmode[]; extern const menuitem_t menu_highoutputmode[]; +extern const menuitem_t menu_top[]; static void menu_mode_cb(int item, uint8_t data) { (void)data; + SetMode(item-1); + draw_cal_status(); switch (item) { - case 4: // Change reference output, should not happen!!! - break; - default: - SetMode(item); - draw_cal_status(); - if (item == 2) { // Activate menu_lowoutputmode as input form - set_sweep_frequency(ST_SPAN, 0); - menu_push_submenu(menu_lowoutputmode); - } else if (item == 3) { // Activate menu_highoutputmode as input form - set_sweep_frequency(ST_SPAN, 0); - menu_push_submenu(menu_highoutputmode); - } else - ui_mode_normal(); // Exit menu after setting the mode + case 1: + menu_push_submenu(menu_top); + break; + case 2: + menu_push_submenu(menu_top); + break; + case 3: + menu_push_submenu(menu_lowoutputmode); + break; + case 4: + menu_push_submenu(menu_highoutputmode); break; } - + draw_cal_status(); } extern int dirty; @@ -260,24 +264,25 @@ static void menu_dfu_cb(int item, uint8_t data) } } -int menu_refer_value[]={-1,0,1,2,3,4,5,6}; -static void menu_refer_cb(int item, uint8_t data) +int menu_reffer_value[]={-1,0,1,2,3,4,5,6}; +char *menu_reffer_text[]={"OFF","30MHz","15MHz","10MHz","4MHz","3MHz","2MHz","1MHz"}; +static void menu_reffer_cb(int item, uint8_t data) { (void)data; //Serial.println(item); - set_refer_output(menu_refer_value[item]); + set_refer_output(menu_reffer_value[item]); menu_move_back(); - ui_mode_normal(); +// ui_mode_normal(); // Stay in menu mode draw_cal_status(); } -static void menu_refer_cb2(int item, uint8_t data) +static void menu_reffer_cb2(int item, uint8_t data) { (void)data; //Serial.println(item); - set_refer_output(menu_refer_value[item+5]); + set_refer_output(menu_reffer_value[item+5]); menu_move_back(); - ui_mode_normal(); + // ui_mode_normal(); // Stay in menu mode draw_cal_status(); } @@ -560,16 +565,18 @@ static const menuvalue_t menu_value[] = { // ===[MENU DEFINITION]========================================================= const menuitem_t menu_lowoutputmode[] = { - { MT_CALLBACK, KM_CENTER, "FREQUENCY", menu_lowoutputmode_cb}, - { MT_CALLBACK, KM_ATTENUATION,"LEVEL", menu_lowoutputmode_cb}, - { MT_CANCEL, 0, S_LARROW" BACK",NULL }, + { MT_FORM | MT_TITLE, 0, "LOW OUTPUT", NULL}, + { MT_FORM | MT_CALLBACK, KM_CENTER, "FREQ: %s", menu_lowoutputmode_cb}, + { MT_FORM | MT_CALLBACK, KM_ATTENUATION,"LEVEL: %s", menu_lowoutputmode_cb}, + { MT_FORM | MT_CANCEL, 0, S_LARROW" BACK",NULL }, { MT_NONE, 0, NULL, NULL } // sentinel }; const menuitem_t menu_highoutputmode[] = { - { MT_CALLBACK, KM_CENTER, "FREQUENCY", menu_highoutputmode_cb}, - { MT_CALLBACK, KM_DRIVE, "LEVEL", menu_highoutputmode_cb}, - { MT_CANCEL, 0, S_LARROW" BACK",NULL }, + { MT_FORM | MT_TITLE, 0, "HIGH OUTPUT", NULL}, + { MT_FORM | MT_CALLBACK, KM_CENTER, "FREQ: %s", menu_highoutputmode_cb}, + { MT_FORM | MT_CALLBACK, KM_DRIVE, "LEVEL", menu_highoutputmode_cb}, + { MT_FORM | MT_CANCEL, 0, S_LARROW" BACK",NULL }, { MT_NONE, 0, NULL, NULL } // sentinel }; @@ -615,22 +622,22 @@ static const menuitem_t menu_dBper[] = { { MT_NONE, 0, NULL, NULL } // sentinel }; -static const menuitem_t menu_refer2[] = { - { MT_CALLBACK, 0, "3MHz" , menu_refer_cb2}, - { MT_CALLBACK, 0, "2MHz" , menu_refer_cb2}, - { MT_CALLBACK, 0, "1MHz" , menu_refer_cb2}, - { MT_CANCEL, 0, S_LARROW" BACK", NULL }, +static const menuitem_t menu_reffer2[] = { + { MT_FORM | MT_CALLBACK, 0, "3MHz" , menu_reffer_cb2}, + { MT_FORM | MT_CALLBACK, 0, "2MHz" , menu_reffer_cb2}, + { MT_FORM | MT_CALLBACK, 0, "1MHz" , menu_reffer_cb2}, + { MT_FORM | MT_CANCEL, 0, S_LARROW" BACK", NULL }, { MT_NONE, 0, NULL, NULL } // sentinel }; -static const menuitem_t menu_refer[] = { - { MT_CALLBACK, 0, "OFF" , menu_refer_cb}, - { MT_CALLBACK, 0, "30MHz", menu_refer_cb}, - { MT_CALLBACK, 0, "15MHz", menu_refer_cb}, - { MT_CALLBACK, 0, "10MHz", menu_refer_cb}, - { MT_CALLBACK, 0, "4MHz" , menu_refer_cb}, - { MT_SUBMENU, 0, S_RARROW" MORE", menu_refer2}, - { MT_CANCEL, 0, S_LARROW" BACK", NULL }, +static const menuitem_t menu_reffer[] = { + { MT_FORM | MT_CALLBACK, 0, "OFF" , menu_reffer_cb}, + { MT_FORM | MT_CALLBACK, 0, "30MHz", menu_reffer_cb}, + { MT_FORM | MT_CALLBACK, 0, "15MHz", menu_reffer_cb}, + { MT_FORM | MT_CALLBACK, 0, "10MHz", menu_reffer_cb}, + { MT_FORM | MT_CALLBACK, 0, "4MHz" , menu_reffer_cb}, + { MT_FORM | MT_SUBMENU, 0, S_RARROW" MORE", menu_reffer2}, + { MT_FORM | MT_CANCEL, 0, S_LARROW" BACK", NULL }, { MT_NONE, 0, NULL, NULL } // sentinel }; @@ -693,16 +700,6 @@ static const menuitem_t menu_dfu[] = { { MT_NONE, 0, NULL, NULL } // sentinel }; -static const menuitem_t menu_mode[] = { - { MT_CALLBACK, 0, "\2LOW\0INPUT", menu_mode_cb}, - { MT_CALLBACK, 0, "\2HIGH\0INPUT",menu_mode_cb}, - { MT_CALLBACK, 0, "\2LOW\0OUTPUT", menu_mode_cb}, - { MT_CALLBACK, 0, "\2HIGH\0OUTPUT",menu_mode_cb}, - { MT_SUBMENU, 0, "\2REFER\0OUTPUT",menu_refer}, - { MT_CANCEL, 0, S_LARROW" BACK", NULL }, - { MT_NONE, 0, NULL, NULL } // sentinel -}; - static const menuitem_t menu_settings2[] = { // { MT_CALLBACK, 0, "TRACK", menu_settings2_cb}, @@ -738,14 +735,25 @@ static const menuitem_t menu_config[] = { { MT_NONE, 0, NULL, NULL } // sentinel }; -static const menuitem_t menu_top[] = { - { MT_CALLBACK, 0, "AUTO", menu_autosettings_cb}, - { MT_SUBMENU, 0, "SCAN", menu_stimulus}, - { MT_SUBMENU, 0, "MARKER", menu_marker}, - { MT_SUBMENU, 0, "DISPLAY", menu_scale}, - { MT_SUBMENU, 0, "STORAGE", menu_storage}, - { MT_SUBMENU, 0, "MODE", menu_mode}, - { MT_SUBMENU, 0, "CONFIG", menu_config}, +static const menuitem_t menu_mode[] = { + { MT_FORM | MT_TITLE, 0, "MODE", NULL}, + { MT_FORM | MT_CALLBACK, 0, "LOW INPUT", menu_mode_cb}, + { MT_FORM | MT_CALLBACK, 0, "HIGH INPUT",menu_mode_cb}, + { MT_FORM | MT_CALLBACK, 0, "LOW OUTPUT", menu_mode_cb}, + { MT_FORM | MT_CALLBACK, 0, "HIGH OUTPUT",menu_mode_cb}, + { MT_FORM | MT_SUBMENU, 0, "CAL OUTPUT: %s",menu_reffer}, +// { MT_CANCEL, 0, S_LARROW" BACK", NULL }, + { MT_NONE, 0, NULL, NULL } // sentinel +}; + +const menuitem_t menu_top[] = { + { MT_CALLBACK, 0, "AUTO", menu_autosettings_cb}, + { MT_SUBMENU, 0, "SCAN", menu_stimulus}, + { MT_SUBMENU, 0, "MARKER", menu_marker}, + { MT_SUBMENU, 0, "DISPLAY", menu_scale}, + { MT_SUBMENU, 0, "STORAGE", menu_storage}, + { MT_SUBMENU, 0, "CONFIG", menu_config}, + { MT_CANCEL, 0, S_LARROW" MODE",NULL}, { MT_NONE, 0, NULL, NULL } // sentinel, // MENUITEM_CLOSE, }; @@ -761,24 +769,29 @@ void frequency_string(char *buf, size_t len, int32_t freq); int menu_is_form(const menuitem_t *menu) { - return(menu == menu_lowoutputmode || - menu == menu_highoutputmode); + int i; + for (i = 0; MT_MASK(menu[i].type) != MT_NONE; i++) + if (menu[i].type & MT_FORM) + return (true); + return(false); } static void menu_item_modify_attribute( const menuitem_t *menu, int item, uint16_t *fg, uint16_t *bg) { if (menu == menu_mode) { - if (item == GetMode()){ + if (item == GetMode()+1) { *bg = DEFAULT_MENU_TEXT_COLOR; *fg = config.menu_normal_color; + } else if (item == 5) { + plot_printf(uistat.text, sizeof uistat.text, menu_reffer_text[get_refer_output()+1]); } - } else if (menu == menu_refer) { + } else if (menu == menu_reffer) { if (item < 5 && item == get_refer_output() + 1){ *bg = DEFAULT_MENU_TEXT_COLOR; *fg = config.menu_normal_color; } - } else if (menu == menu_refer2) { + } else if (menu == menu_reffer2) { if (item == get_refer_output() - 4){ *bg = DEFAULT_MENU_TEXT_COLOR; *fg = config.menu_normal_color; @@ -837,44 +850,46 @@ static void menu_item_modify_attribute( } } if (ui_mode == UI_MENU && menu_is_form(menu)) { -// if (item == 0) -// redraw_frame(); + // if (item == 0) + // redraw_frame(); if (item <= 1) { - area_width = 0; -// area_height = HEIGHT - 32; - int y = MENU_BUTTON_HEIGHT*item; - uint16_t bg = config.menu_normal_color; - uint16_t fg = DEFAULT_MENU_TEXT_COLOR; - // ili9341_fill(320-MENU_BUTTON_WIDTH, y, MENU_BUTTON_WIDTH, MENU_BUTTON_HEIGHT-2, bg); - ili9341_set_foreground(fg); - ili9341_set_background(bg); - char buf[15]; - ili9341_fill(50+25, y, 170, MENU_BUTTON_HEIGHT-2, bg); - if (menu == menu_lowoutputmode) { - switch (item) { - case 0: - set_sweep_frequency(ST_SPAN, 0); // For CW sweep mode - plot_printf(buf, sizeof buf, "%3.3fMHz", frequency0 / 1000000.0); - break; - case 1: - plot_printf(buf, sizeof buf, "%ddB", -10 - settingAttenuate); - break; - } - } - if (menu == menu_highoutputmode) { - switch (item) { - case 0: - set_sweep_frequency(ST_SPAN, 0); // For CW sweep mode - frequency_string(buf, sizeof buf, frequency0); - break; - case 1: - plot_printf(buf, sizeof buf, "%ddB", -10 - settingDrive); - break; - } + area_width = 0; +#if 0 + // area_height = HEIGHT - 32; + int y = MENU_BUTTON_HEIGHT*item; + uint16_t bg = config.menu_normal_color; + uint16_t fg = DEFAULT_MENU_TEXT_COLOR; + // ili9341_fill(320-MENU_BUTTON_WIDTH, y, MENU_BUTTON_WIDTH, MENU_BUTTON_HEIGHT-2, bg); + ili9341_set_foreground(fg); + ili9341_set_background(bg); + char buf[15]; + ili9341_fill(50+25, y, 170, MENU_BUTTON_HEIGHT-2, bg); + if (menu == menu_lowoutputmode) { + switch (item) { + case 0: + set_sweep_frequency(ST_SPAN, 0); // For CW sweep mode + plot_printf(buf, sizeof buf, "%3.3fMHz", frequency0 / 1000000.0); + break; + case 1: + plot_printf(buf, sizeof buf, "%ddB", -10 - settingAttenuate); + break; + } + } + if (menu == menu_highoutputmode) { + switch (item) { + case 0: + set_sweep_frequency(ST_SPAN, 0); // For CW sweep mode + plot_printf(buf, sizeof buf, "%3.3fMHz", frequency0 / 1000000.0); + break; + case 1: + plot_printf(buf, sizeof buf, "%ddB", -10 - settingDrive); + break; + } + } + ili9341_drawstring_size(buf, 130, y+6, 2); +#endif } - ili9341_drawstring_size(buf, 130, y+6, 2); - } }else{ area_width = AREA_WIDTH_NORMAL - MENU_BUTTON_WIDTH; } @@ -885,39 +900,53 @@ static void fetch_numeric_target(void) switch (keypad_mode) { case KM_START: uistat.value = get_sweep_frequency(ST_START); + plot_printf(uistat.text, sizeof uistat.text, "%3.3fMHz", uistat.value / 1000000.0); break; case KM_STOP: uistat.value = get_sweep_frequency(ST_STOP); + plot_printf(uistat.text, sizeof uistat.text, "%3.3fMHz", uistat.value / 1000000.0); break; case KM_CENTER: uistat.value = get_sweep_frequency(ST_CENTER); + plot_printf(uistat.text, sizeof uistat.text, "%3.3fMHz", uistat.value / 1000000.0); break; case KM_SPAN: uistat.value = get_sweep_frequency(ST_SPAN); + plot_printf(uistat.text, sizeof uistat.text, "%3.3fMHz", uistat.value / 1000000.0); break; case KM_CW: uistat.value = get_sweep_frequency(ST_CW); + plot_printf(uistat.text, sizeof uistat.text, "%3.3fMHz", uistat.value / 1000000.0); break; case KM_SCALE: uistat.value = get_trace_scale(uistat.current_trace) * 1000; + plot_printf(uistat.text, sizeof uistat.text, "%ddB/", uistat.value / 1000); break; case KM_REFPOS: uistat.value = get_trace_refpos(uistat.current_trace) * 1000; + plot_printf(uistat.text, sizeof uistat.text, "%ddB", uistat.value / 1000); break; case KM_ATTENUATION: uistat.value = settingAttenuate; + if (GetMode() == M_GENLOW) + uistat.value += 10; // compensation for dB offset during low output mode + plot_printf(uistat.text, sizeof uistat.text, "%ddB", uistat.value); break; case KM_ACTUALPOWER: uistat.value = settingLevelOffset(); + plot_printf(uistat.text, sizeof uistat.text, "%ddB", uistat.value); break; case KM_IF: uistat.value = frequency_IF; + plot_printf(uistat.text, sizeof uistat.text, "%3.3fMHz", uistat.value / 1000000.0); break; case KM_SAMPLETIME: uistat.value = settingStepDelay; + plot_printf(uistat.text, sizeof uistat.text, "%3duS", uistat.value); break; case KM_DRIVE: uistat.value = settingDrive; + plot_printf(uistat.text, sizeof uistat.text, "%3ddB", uistat.value); break; } @@ -962,6 +991,8 @@ set_numeric_value(void) set_trace_refpos(2, NGRIDY - uistat.value / get_trace_scale(0)); break; case KM_ATTENUATION: + if (GetMode() == M_GENLOW) + uistat.value -= 10; // compensation for dB offset during low output mode SetAttenuation(uistat.value); break; case KM_ACTUALPOWER: From 9c129b1310ba2bb3012d013814e9ca36604533b9 Mon Sep 17 00:00:00 2001 From: erikkaashoek Date: Wed, 25 Mar 2020 14:53:12 +0100 Subject: [PATCH 05/23] Output modulation added --- nanovna.h | 4 ++ plot.c | 2 +- sa_core.c | 46 ++++++++++++++++++- ui.c | 4 ++ ui_sa.c | 129 ++++++++++++++++++++++++++++++++++++++++-------------- 5 files changed, 149 insertions(+), 36 deletions(-) diff --git a/nanovna.h b/nanovna.h index 3074186..85e05bc 100644 --- a/nanovna.h +++ b/nanovna.h @@ -123,6 +123,10 @@ enum { M_LOW, M_HIGH, M_GENLOW, M_GENHIGH, }; +enum { + MO_NONE, MO_AM, MO_NFM, MO_WFM, +}; + #define MODE_OUTPUT(x) ((x) == M_GENLOW || (x) == M_GENHIGH ) #define MODE_INPUT(x) ((x) == M_LOW || (x) == M_HIGH ) #define MODE_HIGH(x) ((x) == M_HIGH || (x) == M_GENHIGH ) diff --git a/plot.c b/plot.c index 81f628a..f8ee6e2 100644 --- a/plot.c +++ b/plot.c @@ -1503,7 +1503,7 @@ draw_all_cells(bool flush_markmap) #endif spi_buffer[i] = RGB565(r,g,b); } - ili9341_bulk(5*5,HEIGHT+3, 290,1); + ili9341_bulk(5*5,HEIGHT+3, area_width,1); } #endif } diff --git a/sa_core.c b/sa_core.c index 0b8d107..d9813f5 100644 --- a/sa_core.c +++ b/sa_core.c @@ -64,7 +64,7 @@ int scandirty = true; //---------------- menu system ----------------------- int settingAttenuate = 0; -int settingGenerate = 0; +// int settingGenerate = 0; int settingBandwidth = 0; //int settingLevelOffset = 0; @@ -80,6 +80,7 @@ int settingDrive=0; // 0-3 , 3=+20dBm int settingAGC = true; int settingLNA = false; int extraVFO = false; +int settingModulation = MO_NONE; int settingStepDelay = 0; float rbw = 0; float vbw = 0; @@ -98,11 +99,13 @@ int get_refer_output(void) return(settingRefer); } +#if 0 void SetGenerate(int g) { settingGenerate = g; dirty = true; } +#endif void SetDrive(int d) { @@ -110,6 +113,11 @@ void SetDrive(int d) dirty = true; } +void SetModulation(int m) +{ + settingModulation = m; + dirty = true; +} void SetIF(int f) { frequency_IF = f; @@ -157,6 +165,12 @@ void SetMode(int m) void SetAttenuation(int a) { + if (a<0) + a = 0; + if (a> 31) + a=31; + if (settingAttenuate == a) + return; settingAttenuate = a; dirty = true; } @@ -610,6 +624,7 @@ void update_rbw(uint32_t delta_f) } static int old_lf = -1; +static int modulation_counter = 0; float perform(bool break_on_operation, int i, int32_t f, int extraV) { @@ -631,6 +646,16 @@ float perform(bool break_on_operation, int i, int32_t f, int extraV) int p = settingAttenuate * 2; PE4302_Write_Byte(p); + if (settingModulation == MO_NFM ) { + SI4432_Sel = 1; + SI4432_Write_Byte(0x7A, 1); // Use frequency hopping channel width for FM modulation + } else if (settingModulation == MO_WFM ) { + SI4432_Sel = 1; + SI4432_Write_Byte(0x7A, 10); // Use frequency hopping channel width for FM modulation + } else { + SI4432_Sel = 1; + SI4432_Write_Byte(0x79, 0); // IF no FM back to channel 0 + } SetRX(settingMode); SI4432_SetReference(settingRefer); temppeakLevel = -150; @@ -641,6 +666,23 @@ float perform(bool break_on_operation, int i, int32_t f, int extraV) dirty = false; // } } + if (settingModulation == MO_AM) { + int p = settingAttenuate * 2 + modulation_counter; + PE4302_Write_Byte(p); + if (modulation_counter == 3) + modulation_counter = 0; + else + modulation_counter++; + chThdSleepMicroseconds(250); + } else if (settingModulation == MO_NFM || settingModulation == MO_WFM ) { + SI4432_Sel = 1; + SI4432_Write_Byte(0x79, modulation_counter); // Use frequency hopping channel for FM modulation + if (modulation_counter == 3) + modulation_counter = 0; + else + modulation_counter++; + chThdSleepMicroseconds(250); + } volatile int subSteps = ((int)(2 * vbw / rbw)); float RSSI = -150.0; int t = 0; @@ -651,6 +693,8 @@ float perform(bool break_on_operation, int i, int32_t f, int extraV) if (lf != old_lf) // only set on change setFreq (1, local_IF + lf); old_lf = lf; + if (MODE_OUTPUT(settingMode)) + return(0); float subRSSI = SI4432_RSSI(lf, MODE_SELECT(settingMode))+settingLevelOffset()+settingAttenuate; if (RSSI < subRSSI) RSSI = subRSSI; diff --git a/ui.c b/ui.c index 615e017..73f4a48 100644 --- a/ui.c +++ b/ui.c @@ -1095,6 +1095,10 @@ menu_push_submenu(const menuitem_t *submenu) if (menu_is_form(submenu)) { redraw_frame(); area_width = 0; + } else { + redraw_frame(); + request_to_redraw_grid(); + area_width = AREA_WIDTH_NORMAL - MENU_BUTTON_WIDTH; } draw_menu(); } diff --git a/ui_sa.c b/ui_sa.c index db92473..2735799 100644 --- a/ui_sa.c +++ b/ui_sa.c @@ -38,13 +38,16 @@ extern int extraVFO; extern int settingDrive; extern int settingLNA; extern int settingAGC; +void SetModulation(int); +extern int settingModulation; // extern int settingSpeed; extern int settingStepDelay; enum { - KM_START=1, KM_STOP, KM_CENTER, KM_SPAN, KM_CW, KM_REFPOS, KM_SCALE, KM_ATTENUATION, KM_ACTUALPOWER, KM_IF, KM_SAMPLETIME, KM_DRIVE + KM_START=1, KM_STOP, KM_CENTER, KM_SPAN, KM_CW, KM_REFPOS, KM_SCALE, KM_ATTENUATION, + KM_ACTUALPOWER, KM_IF, KM_SAMPLETIME, KM_DRIVE, KM_LOWOUTLEVEL, KM_HIGHOUTLEVEL }; @@ -136,6 +139,7 @@ static const keypads_t keypads_level[] = { static const keypads_t * const keypads_mode_tbl[] = { + NULL, // never used keypads_freq, // start keypads_freq, // stop keypads_freq, // center @@ -148,6 +152,8 @@ static const keypads_t * const keypads_mode_tbl[] = { keypads_freq, // IF keypads_level, // sample time keypads_scale, // drive + keypads_level, // KM_LOWOUTLEVEL + keypads_level, // KM_HIGHOUTLEVEL }; #ifdef __VNA__ @@ -157,7 +163,7 @@ static const char * const keypad_mode_label[] = { #endif #ifdef __SA__ static const char * const keypad_mode_label[] = { - "START", "STOP", "CENTER", "SPAN", "CW FREQ", "REFPOS", "SCALE", "ATTENUATION", "ACTUALPOWER", "IF", "SAMPLE TIME", "DRIVE" + "error", "START", "STOP", "CENTER", "SPAN", "CW FREQ", "REFPOS", "SCALE", "ATTENUATION", "ACTUALPOWER", "IF", "SAMPLE TIME", "DRIVE", "LEVEL", "LEVEL" }; #endif @@ -169,6 +175,7 @@ int generator_enabled = false; extern const menuitem_t menu_lowoutputmode[]; extern const menuitem_t menu_highoutputmode[]; +extern const menuitem_t menu_modulation[]; extern const menuitem_t menu_top[]; static void menu_mode_cb(int item, uint8_t data) @@ -213,15 +220,20 @@ void menu_autosettings_cb(int item, uint8_t data) set_trace_refpos(2, - value / get_trace_scale(0) + NGRIDY); active_marker = 0; - menu_marker_type_cb(M_REFERENCE,M_REFERENCE); - set_refer_output(1); + for (int i = 0; i Date: Wed, 25 Mar 2020 18:36:42 +0100 Subject: [PATCH 06/23] Capture working with DMA, waterfall still hangs --- ili9341.c | 70 ++++++++++++++++++++++++++++--------------------------- ui.c | 4 ++-- 2 files changed, 38 insertions(+), 36 deletions(-) diff --git a/ili9341.c b/ili9341.c index a1942ab..0c44bf9 100644 --- a/ili9341.c +++ b/ili9341.c @@ -384,39 +384,6 @@ void ili9341_bulk(int x, int y, int w, int h) } } #else -static uint8_t ssp_sendrecvdata(void) -{ - // Start RX clock (by sending data) - SPI_WRITE_8BIT(0); - while (SPI_RX_IS_EMPTY && SPI_IS_BUSY) - ; - return SPI_READ_DATA; -} - -void ili9341_read_memory(int x, int y, int w, int h, int len, uint16_t *out) -{ - // uint8_t xx[4] = { x >> 8, x, (x+w-1) >> 8, (x+w-1) }; - // uint8_t yy[4] = { y >> 8, y, (y+h-1) >> 8, (y+h-1) }; - uint32_t xx = __REV16(x | ((x + w - 1) << 16)); - uint32_t yy = __REV16(y | ((y + h - 1) << 16)); - send_command(ILI9341_COLUMN_ADDRESS_SET, 4, (uint8_t *)&xx); - send_command(ILI9341_PAGE_ADDRESS_SET, 4, (uint8_t*)&yy); - send_command(ILI9341_MEMORY_READ, 0, NULL); - - // Skip data from rx buffer - while (SPI_RX_IS_NOT_EMPTY) - (void) SPI_READ_DATA; - // require 8bit dummy clock - ssp_sendrecvdata(); - while (len-- > 0) { - // read data is always 18bit - uint8_t r = ssp_sendrecvdata(); - uint8_t g = ssp_sendrecvdata(); - uint8_t b = ssp_sendrecvdata(); - *out++ = RGB565(r, g, b); - } - CS_HIGH; -} // // Use DMA for send data @@ -469,7 +436,7 @@ void ili9341_bulk(int x, int y, int w, int h) STM32_DMA_CR_MSIZE_HWORD | STM32_DMA_CR_MINC); dmaStreamFlush(w * h); } -#if 0 // Read DMA hangs +#if 1 // Read DMA hangs // Copy screen data to buffer // Warning!!! buffer size must be greater then 3*len + 1 bytes void ili9341_read_memory(int x, int y, int w, int h, int len, uint16_t *out) @@ -515,6 +482,41 @@ void ili9341_read_memory(int x, int y, int w, int h, int len, uint16_t *out) rgbbuf += 3; } } +#else +static uint8_t ssp_sendrecvdata(void) +{ + // Start RX clock (by sending data) + SPI_WRITE_8BIT(0); + while (SPI_RX_IS_EMPTY && SPI_IS_BUSY) + ; + return SPI_READ_DATA; +} + +void ili9341_read_memory(int x, int y, int w, int h, int len, uint16_t *out) +{ + // uint8_t xx[4] = { x >> 8, x, (x+w-1) >> 8, (x+w-1) }; + // uint8_t yy[4] = { y >> 8, y, (y+h-1) >> 8, (y+h-1) }; + uint32_t xx = __REV16(x | ((x + w - 1) << 16)); + uint32_t yy = __REV16(y | ((y + h - 1) << 16)); + send_command(ILI9341_COLUMN_ADDRESS_SET, 4, (uint8_t *)&xx); + send_command(ILI9341_PAGE_ADDRESS_SET, 4, (uint8_t*)&yy); + send_command(ILI9341_MEMORY_READ, 0, NULL); + + // Skip data from rx buffer + while (SPI_RX_IS_NOT_EMPTY) + (void) SPI_READ_DATA; + // require 8bit dummy clock + ssp_sendrecvdata(); + while (len-- > 0) { + // read data is always 18bit + uint8_t r = ssp_sendrecvdata(); + uint8_t g = ssp_sendrecvdata(); + uint8_t b = ssp_sendrecvdata(); + *out++ = RGB565(r, g, b); + } + CS_HIGH; +} + #endif #endif diff --git a/ui.c b/ui.c index 73f4a48..a9f7185 100644 --- a/ui.c +++ b/ui.c @@ -1461,8 +1461,8 @@ draw_menu_buttons(const menuitem_t *menu) ili9341_set_foreground(fg); ili9341_set_background(bg); if (menu[i].type & MT_FORM) { - ili9341_fill(320-active_button_width+3, y+8, active_button_width-6, 2+FONT_GET_HEIGHT*2+2, bg); - ili9341_drawstring_size(text, 320-active_button_width+5, y+10, 2); + ili9341_fill(320-active_button_width+3, y+6, active_button_width-6, 2+FONT_GET_HEIGHT*2+2, bg); + ili9341_drawstring_size(text, 320-active_button_width+5, y+8, 2); } else { if (menu_is_multiline(menu[i].label, &l1, &l2)) { ili9341_fill(320-active_button_width+3, y+5, active_button_width-6, 2+FONT_GET_HEIGHT+1+FONT_GET_HEIGHT+2, bg); From e0a100af56a8062f5af26c49e29acfe8561d8446 Mon Sep 17 00:00:00 2001 From: erikkaashoek Date: Wed, 25 Mar 2020 19:09:09 +0100 Subject: [PATCH 07/23] Clean up code --- nanovna.h | 12 +++++++----- si4432.c | 8 +++----- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/nanovna.h b/nanovna.h index 85e05bc..58a6a6b 100644 --- a/nanovna.h +++ b/nanovna.h @@ -33,14 +33,18 @@ #define POINTS_COUNT 290 #define MARKER_COUNT 4 -#define TRACE_COUNT 3 +#define TRACES_MAX 3 +#define TRACE_AGE 3 #define TRACE_ACTUAL 2 #define TRACE_STORED 1 #define TRACE_TEMP 0 +// #define age_t measured[TRACE_AGE] #define stored_t measured[TRACE_STORED] #define actual_t measured[TRACE_ACTUAL] #define temp_t measured[TRACE_TEMP] -typedef float measurement_t[3][POINTS_COUNT]; + + +typedef float measurement_t[TRACES_MAX][POINTS_COUNT]; extern measurement_t measured; #endif @@ -243,8 +247,6 @@ extern const uint16_t numfont16x22[]; #define S_OHM "\036" // trace -#define TRACES_MAX 3 - #define MAX_TRACE_TYPE 12 enum trace_type { TRC_LOGMAG=0, TRC_PHASE, TRC_DELAY, TRC_SMITH, TRC_POLAR, TRC_LINEAR, TRC_SWR, TRC_REAL, TRC_IMAG, TRC_R, TRC_X, TRC_OFF @@ -418,7 +420,7 @@ void show_logo(void); * flash.c */ -#if 0 +#if 1 #define SAVEAREA_MAX 5 // Begin addr 0x08018000 #define SAVE_CONFIG_AREA_SIZE 0x00008000 diff --git a/si4432.c b/si4432.c index f4115a6..96a45a5 100644 --- a/si4432.c +++ b/si4432.c @@ -132,7 +132,6 @@ void SI4432_Reset(void) { int count = 0; // always perform a system reset (don't send 0x87) -again: SI4432_Write_Byte( 0x07, 0x80); chThdSleepMilliseconds(25); // wait for chiprdy bit @@ -147,7 +146,6 @@ void SI4432_Transmit(int d) SI4432_Write_Byte(0x6D, (byte) (0x1C+d)); if (( SI4432_Read_Byte ( 0x02 ) & 0x03 ) == 2) return; // Already in transmit mode -again: chThdSleepMilliseconds(20); SI4432_Write_Byte( 0x07, 0x0b); chThdSleepMilliseconds(20); @@ -161,7 +159,6 @@ void SI4432_Receive(void) int count = 0; if (( SI4432_Read_Byte ( 0x02 ) & 0x03 ) == 1) return; // Already in receive mode -again: SI4432_Write_Byte( 0x07, 0x07); chThdSleepMilliseconds(10); while (count++ < 100 && ( SI4432_Read_Byte ( 0x02 ) & 0x03 ) != 1) { @@ -188,7 +185,7 @@ static short RBW_choices[] = { // Each triple is: ndec, fils, WISH*10 float SI4432_SET_RBW(float w) { uint8_t dwn3=0; - uint32_t WISH = (uint32_t)(w * 10.0); + int32_t WISH = (uint32_t)(w * 10.0); uint8_t ndec, fils, i; if (WISH > 6207) WISH=6207; // Final value in RBW_choices[] if (WISH > 1379) dwn3 = 1 ; @@ -232,6 +229,7 @@ int actualStepDelay = 1500; float SI4432_RSSI(uint32_t i, int s) { int RSSI_RAW; + (void) i; // SEE DATASHEET PAGE 61 #ifdef USE_SI4463 if (SI4432_Sel == 2) { @@ -252,7 +250,7 @@ float SI4432_RSSI(uint32_t i, int s) } -void SI4432_Sub_Init() +void SI4432_Sub_Init(void) { SI4432_Reset(); SI4432_Write_Byte(0x05, 0x0); From b56af01ba2d14607517d4f2198c228d2accf73d8 Mon Sep 17 00:00:00 2001 From: erikkaashoek Date: Thu, 26 Mar 2020 10:09:08 +0100 Subject: [PATCH 08/23] Cleaning up the high input menu system --- main.c | 4 +- plot.c | 3 + sa_core.c | 312 ++++++++++++++---------------------------------------- ui_sa.c | 128 ++++++++++++++-------- 4 files changed, 167 insertions(+), 280 deletions(-) diff --git a/main.c b/main.c index 8a4007f..02d8b92 100644 --- a/main.c +++ b/main.c @@ -786,8 +786,8 @@ config_t config = { .harmonic_freq_threshold = 300000000, #endif .vbat_offset = 500, - .low_level_offset = 0, - .high_level_offset = 0, + .low_level_offset = 100, // Uncalibrated + .high_level_offset = 100, // Uncalibrated }; properties_t current_props; diff --git a/plot.c b/plot.c index f8ee6e2..7cb98a6 100644 --- a/plot.c +++ b/plot.c @@ -1900,6 +1900,9 @@ draw_frequencies(void) { char buf1[32]; char buf2[32]; buf2[0] = 0; + if (MODE_OUTPUT(settingMode)) // No frequencies during output + return; + #ifdef __VNA__ if ((domain_mode & DOMAIN_MODE) == DOMAIN_FREQ) { #endif diff --git a/sa_core.c b/sa_core.c index d9813f5..cbf5e67 100644 --- a/sa_core.c +++ b/sa_core.c @@ -69,7 +69,7 @@ int settingBandwidth = 0; //int settingLevelOffset = 0; -int settingRefer = 1; +int settingRefer = -1; // Off by default int refferFreq[] = {30000000, 15000000, 10000000, 4000000, 3000000, 2000000, 1000000}; int settingSpur = 0; int settingAverage = 0; @@ -139,10 +139,13 @@ void SetMode(int m) case M_LOW: set_sweep_frequency(ST_START, (int32_t) 0); set_sweep_frequency(ST_STOP, (int32_t) 300000000); + SetRefpos(-10); goto min_max_low; case M_GENLOW: set_sweep_frequency(ST_CENTER, (int32_t) 10000000); set_sweep_frequency(ST_SPAN, 0); + settingSpur = 0; // Not for output mode + settingRefer = -1; // No refer output in output mode min_max_low: minFreq = 0; maxFreq = 520000000; @@ -150,15 +153,20 @@ void SetMode(int m) case M_HIGH: set_sweep_frequency(ST_START, (int32_t) 300000000); set_sweep_frequency(ST_STOP, (int32_t) 960000000); + SetRefpos(-30); goto min_max_high; case M_GENHIGH: set_sweep_frequency(ST_CENTER, (int32_t) 300000000); set_sweep_frequency(ST_SPAN, 0); + settingRefer = -1; // No refer output in output mode min_max_high: minFreq = 240000000; maxFreq = 960000000; + extraVFO = false; // Not possible in high mode + settingSpur = 0; // Not possible in high mode break; } + settingAttenuate = 0; dirty = true; } @@ -224,18 +232,33 @@ void SetPowerLevel(int o) config.low_level_offset = o - peakLevel - settingAttenuate + settingLevelOffset(); } else { - config.low_level_offset = 0; - config.high_level_offset = 0; + config.low_level_offset = 100; + config.high_level_offset = 100; } dirty = true; } int settingLevelOffset(void) { - if (settingMode == M_HIGH) - return(config.high_level_offset); - if (settingMode == M_LOW) + if (settingMode == M_HIGH) { + if (config.high_level_offset == 100) + return 0; return(config.high_level_offset); + } + if (settingMode == M_LOW) { + if (config.low_level_offset == 100) + return 0; + return(config.low_level_offset); + } + return(0); +} + +int level_is_calibrated(void) +{ + if (settingMode == M_HIGH && config.high_level_offset != 100) + return 1; + if (settingMode == M_LOW && config.low_level_offset != 100) + return 1; return(0); } @@ -306,6 +329,13 @@ int GetAGC(void) return(settingAGC); } +void SetRefpos(int level) +{ + set_trace_refpos(0, NGRIDY - level / get_trace_scale(0)); + set_trace_refpos(1, NGRIDY - level / get_trace_scale(0)); + set_trace_refpos(2, NGRIDY - level / get_trace_scale(0)); + dirty = true; +} //------------------------------------------ @@ -320,197 +350,6 @@ int temppeakIndex; int vbwSteps = 1; -#if 0 -int inData = 0; -unsigned long startFreq = 250000000; -unsigned long stopFreq = 300000000; -unsigned long lastFreq[6] = { 300000000, 300000000,0,0,0,0}; -int lastParameter[10]; -int parameter; -unsigned long reg = 0; -long offset=0; -long offset2=0; -static unsigned int spacing = 10000; -double delta=0.0; -int phase=0; -int deltaPhase; -int delaytime = 50; -#endif - - -#if 0 -void displayHisto () -{ - // clearDisplay(); - //int settingMax = 0; - //int settingMin = -120; - - if (old_settingMax != settingMax || old_settingMin != settingMin) { - // Display levels at left of screen - tft.fillRect(0, 0, oX-2, tft.height(), DISPLAY_BLACK); - textWhite(); - tft.setCursor(0,oY); // Start at top-left corner - tft.println(settingMax); - tft.setCursor(0,tft.height() - 16); - tft.println(settingMin); - // tft.setCursor(0,tft.height()/2); - // tft.println("dB"); - old_settingMax = settingMax; - old_settingMin = settingMin; - } - - if (old_startFreq != startFreq || old_stopFreq != stopFreq) { - // Dsiplay frequencies - // Bottom of screen - tft.fillRect(0, tft.height()-8, tft.width(), tft.height()-1, DISPLAY_BLACK); - tft.setTextColor(DISPLAY_WHITE); // Draw white text - tft.setCursor(oX+2,tft.height()-8); // Start at top-left corner - double f = (((double)(startFreq - lastFreq[0]))/ 1000000.0); - tft.print(f); - tft.print("MHz"); - tft.setCursor(tft.width() - 58,tft.height()-8); - f = (((double)(stopFreq - lastFreq[0]))/ 1000000.0); - tft.print(f); - tft.print("MHz"); - - tft.setCursor(tft.width()/2 - 80 + oX,tft.height()-8); - tft.print("center:"); - f = (double)((stopFreq/2 + startFreq/2 - lastFreq[0]) / 1000000.0); - tft.print(f); - tft.print("MHz"); - old_startFreq = startFreq; - old_stopFreq = stopFreq; - } - - // Top of screen - - if (old_settingAttenuate != settingAttenuate || old_settingPowerGrid != settingPowerGrid) { - tft.fillRect(0, 0, 8*6, oY-2, DISPLAY_BLACK); - tft.setCursor(0,0); // Start at top-left corner - tft.setTextColor(DISPLAY_WHITE); // Draw white text - tft.print("Atten:"); - tft.print(settingAttenuate); - tft.setCursor(0,8); // Start at top-left corner - tft.print(settingPowerGrid); - tft.print("dB/"); - old_settingAttenuate = settingAttenuate; - old_settingPowerGrid = settingPowerGrid; - old_rbw = -1; - } - - if (old_rbw != rbw || old_vbw != vbw) { - tft.fillRect(56, 0, 99, oY-2, DISPLAY_BLACK); - tft.setCursor(56,0); // Start at top-left corner - tft.setTextColor(DISPLAY_WHITE); // Draw white text - tft.print("RBW:"); - tft.print(rbw); - tft.print("kHz"); - tft.setCursor(56,8); // Start at top-left corner - tft.print("VBW:"); - tft.print(vbw); - tft.print("kHz"); - old_rbw = rbw; - old_vbw = vbw; - } - - if (peakLevel > -150) { - tft.fillRect(oX+100, 0, 100, 8-1, DISPLAY_BLACK); - tft.setCursor(oX + 100,0); // Start at top-left corner - tft.setTextColor(DISPLAY_WHITE); // Draw white text - tft.print("Max="); - tft.print((int)((peakLevel/ 2.0 - settingAttenuate) - 120.0)+settingLevelOffset); - tft.print("dB, "); - tft.print(peakFreq/ 1000000.0); - tft.print("MHz"); - } - - if (old_settingAverage != settingAverage || abs(old_settingSpur) != abs(settingSpur)) { - int x = tft.width() - 60; - tft.fillRect( x, 0, 60, oY-2, DISPLAY_BLACK); - tft.setTextColor(DISPLAY_WHITE); // Draw white text - if (settingAverage) { - tft.setCursor( x,0); // Start at top-left corner - tft.print("AVR:"); - tft.print(averageText[settingAverage]); - } - if (settingSpur) { - tft.setCursor(x,8); // Start at top-left corner - tft.print("SPUR:"); - tft.print("ON"); - } - old_settingAverage = settingAverage; - old_settingSpur = settingSpur; - } - - - - /* - for (int i=0; i= Y_GRID * dY) f = Y_GRID * dY-1; - if (f < 0) f = 0; - double f2 = ((actual_t[i+1] / 2.0 - settingAttenuate) - 120.0) + settingLevelOffset; - f2 = (f2 - settingMin) * Y_GRID * dY / delta; - if (f2 >= Y_GRID * dY) f2 = Y_GRID * dY-1; - if (f2 < 0) f2 = 0; - int x = i; - int Y1 = Y_GRID * dY - 1 - (int)f; - int Y2 = Y_GRID * dY - 1 - (int)f2; - tft.drawLine(x+oX, oY+Y1, x+oX+1, oY+Y2, DISPLAY_YELLOW); -// tft.drawLine(x+oX, oY+Y1+1, x+oX+1, oY+Y2, DISPLAY_YELLOW); - } - - - */ - sendDisplay(); -} - -void DisplayPoint(unsigned char *data, int i, int color) -{ - if (i == 0) - return; - int x = i-1; - int delta=settingMax - settingMin; - double f = ((data[x] / 2.0 - settingAttenuate) - 120.0) + settingLevelOffset; - f = (f - settingMin) * Y_GRID * dY / delta; - if (f >= Y_GRID * dY) f = Y_GRID * dY-1; - if (f < 0) f = 0; - double f2 = ((data[x+1] / 2.0 - settingAttenuate) - 120.0) + settingLevelOffset; - f2 = (f2 - settingMin) * Y_GRID * dY / delta; - if (f2 >= Y_GRID * dY) f2 = Y_GRID * dY-1; - if (f2 < 0) f2 = 0; - int Y1 = Y_GRID * dY - 1 - (int)f; - int Y2 = Y_GRID * dY - 1 - (int)f2; - DrawDirty(x,min(Y2,Y1)); - DrawDirty(x+1,min(Y2,Y1)); - tft.drawLine(x+oX, oY+Y1, x+oX+1, oY+Y2, color); - // tft.drawLine(x+oX, oY+Y1+1, x+oX+1, oY+Y2, DISPLAY_YELLOW); - sendDisplay(); -} - -void DisplayPeakData(void) -{ - double f = ((((float)actual_t[peakIndex]) / 2.0 - settingAttenuate) - 120.0) + settingLevelOffset; - int delta=settingMax - settingMin; - f = (f - settingMin) * Y_GRID * dY / delta; - if (f >= Y_GRID * dY) f = Y_GRID * dY-1; - if (f < 0) f = 0; - int Y1 = Y_GRID * dY - 1 - (int)f; - tft.setCursor(oX+peakIndex+5,oY+Y1); // Start at top-left corner - tft.setTextColor(DISPLAY_WHITE); // Draw white text - tft.print(peakFreq/ 1000000.0); - tft.setCursor(oX+peakIndex+5,oY+Y1+8); // Start at top-left corner - tft.print((int)((peakLevel/ 2.0 - settingAttenuate) - 120.0)+settingLevelOffset); - tft.print("dB"); - for (int x=peakIndex+5;x RSSI) actual_t[i] = RSSI; break; - case AV_MAX: if (actual_t[i] < RSSI) actual_t[i] = RSSI; break; - case AV_2: actual_t[i] = (actual_t[i] + RSSI) / 2.0; break; - case AV_4: actual_t[i] = (actual_t[i]*3 + RSSI) / 4.0; break; - case AV_8: actual_t[i] = (actual_t[i]*7 + RSSI) / 8.0; break; - } + continue; // Skip all other processing + } + if (settingSpur == -1) // Second pass + RSSI = ( RSSI < temp_t[i] ? RSSI : temp_t[i]); // Minimum of two passes + temp_t[i] = RSSI; + if (settingSubtractStorage) { + RSSI = RSSI - stored_t[i] ; + } + // stored_t[i] = (SI4432_Read_Byte(0x69) & 0x0f) * 3.0 - 90.0; // Display the AGC value in thestored trace + if (scandirty || settingAverage == AV_OFF) + actual_t[i] = RSSI; + else { + switch(settingAverage) { + case AV_MIN: if (actual_t[i] > RSSI) actual_t[i] = RSSI; break; + case AV_MAX: if (actual_t[i] < RSSI) actual_t[i] = RSSI; break; + case AV_2: actual_t[i] = (actual_t[i] + RSSI) / 2.0; break; + case AV_4: actual_t[i] = (actual_t[i]*3 + RSSI) / 4.0; break; + case AV_8: actual_t[i] = (actual_t[i]*7 + RSSI) / 8.0; break; } - if (frequencies[i] > 1000000) { - if (temppeakLevel < actual_t[i]) { - temppeakIndex = i; - temppeakLevel = actual_t[i]; - } + } + if (frequencies[i] > 1000000) { + if (temppeakLevel < actual_t[i]) { + temppeakIndex = i; + temppeakLevel = actual_t[i]; } } if (i == sweep_points -1) { - if (settingSpur == 1) { - settingSpur = -1; - i = 0; - goto again; - } if (scandirty) { scandirty = false; } @@ -767,6 +600,10 @@ again: if (operation_requested && break_on_operation) return false; } + if (settingSpur == 1) { + settingSpur = -1; + goto again; + } palSetPad(GPIOC, GPIOC_LED); return true; } @@ -854,13 +691,22 @@ void draw_cal_status(void) // if (!sweep_enabled) // perform(true, 0, frequencies[0], false); + ili9341_fill(x, y, OFFSETX, HEIGHT, 0x0000); + + if (MODE_OUTPUT(settingMode)) // No cal status during output + return; + ili9341_set_background(DEFAULT_BG_COLOR); int yMax = (NGRIDY - get_trace_refpos(0)) * get_trace_scale(0); plot_printf(buf, BLEN, "%ddB", yMax); buf[5]=0; - ili9341_set_foreground(DEFAULT_FG_COLOR); + if (level_is_calibrated()) + color = DEFAULT_FG_COLOR; + else + color = BRIGHT_COLOR_RED; + ili9341_set_foreground(color); ili9341_drawstring(buf, x, y); y += YSTEP*2; @@ -950,7 +796,11 @@ void draw_cal_status(void) y = HEIGHT-7 + OFFSETY; plot_printf(buf, BLEN, "%ddB", (int)(yMax - get_trace_scale(0) * NGRIDY)); buf[5]=0; - ili9341_set_foreground(DEFAULT_FG_COLOR); + if (level_is_calibrated()) + color = DEFAULT_FG_COLOR; + else + color = BRIGHT_COLOR_RED; + ili9341_set_foreground(color); ili9341_drawstring(buf, x, y); } diff --git a/ui_sa.c b/ui_sa.c index 2735799..a000baa 100644 --- a/ui_sa.c +++ b/ui_sa.c @@ -29,6 +29,7 @@ void SetSubtractStorage(void); void toggle_waterfall(void); void SetMode(int); int GetMode(void); +void SetRefpos(int); void AllDirty(void); void MenuDirty(void); void redrawHisto(void); @@ -177,6 +178,7 @@ extern const menuitem_t menu_lowoutputmode[]; extern const menuitem_t menu_highoutputmode[]; extern const menuitem_t menu_modulation[]; extern const menuitem_t menu_top[]; +extern const menuitem_t menu_tophigh[]; static void menu_mode_cb(int item, uint8_t data) { @@ -188,7 +190,7 @@ static void menu_mode_cb(int item, uint8_t data) menu_push_submenu(menu_top); break; case 2: - menu_push_submenu(menu_top); + menu_push_submenu(menu_tophigh); break; case 3: menu_push_submenu(menu_lowoutputmode); @@ -205,7 +207,7 @@ void menu_autosettings_cb(int item, uint8_t data) { (void)item; (void)data; - SetMode(M_LOW); + SetMode(GetMode()); // set_sweep_frequency(ST_START, (int32_t) 0); // set_sweep_frequency(ST_STOP, (int32_t) 300000000); @@ -428,16 +430,12 @@ static void menu_scale_cb(int item, uint8_t data) { (void)data; int status; - int km = KM_REFPOS + item; -// if (km == KM_SCALE && trace[uistat.current_trace].type == TRC_DELAY) { -// km = KM_SCALEDELAY; -// } status = btn_wait_release(); if (status & EVT_BUTTON_DOWN_LONG) { - ui_mode_numeric(km); + ui_mode_numeric(data); // ui_process_numeric(); } else { - ui_mode_keypad(km); + ui_mode_keypad(data); ui_process_keypad(); } draw_cal_status(); @@ -498,13 +496,12 @@ static void menu_settings_cb(int item, uint8_t data) { (void)data; int status; - int km = KM_ACTUALPOWER+item; status = btn_wait_release(); if (status & EVT_BUTTON_DOWN_LONG) { - ui_mode_numeric(km); + ui_mode_numeric(data); // ui_process_numeric(); } else { - ui_mode_keypad(km); + ui_mode_keypad(data); ui_process_keypad(); } draw_cal_status(); @@ -515,10 +512,10 @@ static void menu_settings2_cb(int item, uint8_t data) (void)data; switch(item) { case 0: - settingAGC = !settingAGC; + ToggleAGC(); break; case 1: - settingLNA = !settingLNA; + ToggleLNA();; break; case 2: extraVFO = !extraVFO; @@ -687,16 +684,27 @@ static const menuitem_t menu_reffer[] = { }; static const menuitem_t menu_scale[] = { - { MT_CALLBACK, 0, "\2REF\0LEVEL", menu_scale_cb}, - { MT_SUBMENU, 0, "\2SCALE/\0DIV", menu_dBper}, - { MT_CALLBACK, 0, "ATTEN", menu_scale_cb}, - { MT_SUBMENU, 0, "AVERAGE", menu_average}, - { MT_CALLBACK, 0, "\2SPUR\0REDUCT.",menu_spur_cb}, - { MT_SUBMENU, 0, "RBW", menu_rbw}, + { MT_CALLBACK, KM_REFPOS, "\2REF\0LEVEL", menu_scale_cb}, + { MT_SUBMENU, 0, "\2SCALE/\0DIV", menu_dBper}, + { MT_CALLBACK, KM_ATTENUATION, "ATTEN", menu_scale_cb}, + { MT_SUBMENU, 0, "AVERAGE", menu_average}, + { MT_CALLBACK, 0, "\2SPUR\0REDUCT.",menu_spur_cb}, + { MT_SUBMENU, 0, "RBW", menu_rbw}, + { MT_CANCEL, 0, S_LARROW" BACK", NULL }, + { MT_NONE, 0, NULL, NULL } // sentinel +}; + +static const menuitem_t menu_scalehigh[] = { + { MT_CALLBACK, KM_REFPOS, "\2REF\0LEVEL", menu_scale_cb}, + { MT_SUBMENU, 0, "\2SCALE/\0DIV", menu_dBper}, + { MT_SUBMENU, 0, "AVERAGE", menu_average}, + { MT_SUBMENU, 0, "RBW", menu_rbw}, { MT_CANCEL, 0, S_LARROW" BACK", NULL }, { MT_NONE, 0, NULL, NULL } // sentinel }; + + static const menuitem_t menu_stimulus[] = { { MT_CALLBACK, 0, "START", menu_stimulus_cb}, { MT_CALLBACK, 0, "STOP", menu_stimulus_cb}, @@ -740,14 +748,13 @@ static const menuitem_t menu_marker[] = { }; static const menuitem_t menu_dfu[] = { - { MT_CALLBACK, 0, "ENTER DFU", menu_dfu_cb}, - { MT_CANCEL, 0, S_LARROW" BACK", NULL }, + { MT_FORM | MT_CALLBACK, 0, "ENTER DFU", menu_dfu_cb}, + { MT_FORM | MT_CANCEL, 0, S_LARROW" BACK", NULL }, { MT_NONE, 0, NULL, NULL } // sentinel }; static const menuitem_t menu_settings2[] = { -// { MT_CALLBACK, 0, "TRACK", menu_settings2_cb}, { MT_CALLBACK, 0, "AGC", menu_settings2_cb}, { MT_CALLBACK, 0, "LNA", menu_settings2_cb}, { MT_CALLBACK, 0, "BPF", menu_settings2_cb}, @@ -757,36 +764,53 @@ static const menuitem_t menu_settings2[] = static const menuitem_t menu_settings[] = { - { MT_CALLBACK, 0, "\2ACTUAL\0POWER", menu_settings_cb}, - { MT_CALLBACK, 0, "\2IF\0FREQ", menu_settings_cb}, - { MT_CALLBACK, 0, "\2SAMPLE\0TIME", menu_settings_cb}, - { MT_CALLBACK, 0, "\2LO\0DRIVE", menu_settings_cb}, - { MT_SUBMENU, 0, S_RARROW" MORE", menu_settings2}, + { MT_CALLBACK, KM_ACTUALPOWER, "\2ACTUAL\0POWER", menu_settings_cb}, + { MT_CALLBACK, KM_IF, "\2IF\0FREQ", menu_settings_cb}, + { MT_CALLBACK, KM_SAMPLETIME, "\2SAMPLE\0TIME", menu_settings_cb}, + { MT_CALLBACK, KM_DRIVE, "\2LO\0DRIVE", menu_settings_cb}, + { MT_SUBMENU, 0, S_RARROW" MORE", menu_settings2}, + { MT_CANCEL, 0, S_LARROW" BACK", NULL }, + { MT_NONE, 0, NULL, NULL } // sentinel +}; -// { MT_SUBMENU, 0, "RBW", menu_rbw}, + +static const menuitem_t menu_settingshigh2[] = +{ + { MT_CALLBACK, 0, "AGC", menu_settings2_cb}, + { MT_CALLBACK, 0, "LNA", menu_settings2_cb}, { MT_CANCEL, 0, S_LARROW" BACK", NULL }, { MT_NONE, 0, NULL, NULL } // sentinel }; +static const menuitem_t menu_settingshigh[] = +{ + { MT_CALLBACK, KM_ACTUALPOWER, "\2ACTUAL\0POWER", menu_settings_cb}, + { MT_CALLBACK, KM_SAMPLETIME, "\2SAMPLE\0TIME", menu_settings_cb}, + { MT_SUBMENU, 0, S_RARROW" MORE", menu_settingshigh2}, + { MT_CANCEL, 0, S_LARROW" BACK", NULL }, + { MT_NONE, 0, NULL, NULL } // sentinel +}; + static const menuitem_t menu_config[] = { - { MT_CALLBACK, 0, "\2TOUCH\0CAL", menu_config_cb}, - { MT_CALLBACK, 0, "\2TOUCH\0TEST", menu_config_cb}, - { MT_CALLBACK, 0, "\2SELF\0TEST", menu_config_cb}, - { MT_CALLBACK, 0, "VERSION", menu_config_cb}, - { MT_SUBMENU, 0, "SETTINGS", menu_settings}, + { MT_FORM | MT_CALLBACK, 0, "TOUCH CAL", menu_config_cb}, + { MT_FORM | MT_CALLBACK, 0, "TOUCH TEST", menu_config_cb}, + { MT_FORM | MT_CALLBACK, 0, "SELF TEST", menu_config_cb}, + { MT_FORM | MT_CALLBACK, 0, "VERSION", menu_config_cb}, +// { MT_SUBMENU, 0, "SETTINGS", menu_settings}, // { MT_SUBMENU, 0, "RBW", menu_rbw}, - { MT_SUBMENU, 0, S_RARROW"DFU", menu_dfu}, - { MT_CANCEL, 0, S_LARROW" BACK", NULL }, + { MT_FORM | MT_SUBMENU, 0, S_RARROW"DFU", menu_dfu}, + { MT_FORM | MT_CANCEL, 0, S_LARROW" BACK", NULL }, { MT_NONE, 0, NULL, NULL } // sentinel }; static const menuitem_t menu_mode[] = { - { MT_FORM | MT_TITLE, 0, "MODE", NULL}, - { MT_FORM | MT_CALLBACK, 0, "LOW INPUT", menu_mode_cb}, - { MT_FORM | MT_CALLBACK, 0, "HIGH INPUT",menu_mode_cb}, - { MT_FORM | MT_CALLBACK, 0, "LOW OUTPUT", menu_mode_cb}, - { MT_FORM | MT_CALLBACK, 0, "HIGH OUTPUT",menu_mode_cb}, - { MT_FORM | MT_SUBMENU, 0, "CAL OUTPUT: %s",menu_reffer}, + { MT_FORM | MT_TITLE, 0, "MODE", NULL}, + { MT_FORM | MT_CALLBACK, 0, "LOW INPUT", menu_mode_cb}, + { MT_FORM | MT_CALLBACK, 0, "HIGH INPUT", menu_mode_cb}, + { MT_FORM | MT_CALLBACK, 0, "LOW OUTPUT", menu_mode_cb}, + { MT_FORM | MT_CALLBACK, 0, "HIGH OUTPUT", menu_mode_cb}, + { MT_FORM | MT_SUBMENU, 0, "CAL OUTPUT: %s", menu_reffer}, + { MT_FORM | MT_SUBMENU, 0, "CONFIG", menu_config}, // { MT_CANCEL, 0, S_LARROW" BACK", NULL }, { MT_NONE, 0, NULL, NULL } // sentinel }; @@ -797,7 +821,19 @@ const menuitem_t menu_top[] = { { MT_SUBMENU, 0, "MARKER", menu_marker}, { MT_SUBMENU, 0, "DISPLAY", menu_scale}, { MT_SUBMENU, 0, "STORAGE", menu_storage}, - { MT_SUBMENU, 0, "CONFIG", menu_config}, + { MT_SUBMENU, 0, "SETTINGS", menu_settings}, + { MT_CANCEL, 0, S_LARROW" MODE",NULL}, + { MT_NONE, 0, NULL, NULL } // sentinel, + // MENUITEM_CLOSE, +}; + +const menuitem_t menu_tophigh[] = { + { MT_CALLBACK, 0, "AUTO", menu_autosettings_cb}, + { MT_SUBMENU, 0, "SCAN", menu_stimulus}, + { MT_SUBMENU, 0, "MARKER", menu_marker}, + { MT_SUBMENU, 0, "DISPLAY", menu_scalehigh}, + { MT_SUBMENU, 0, "STORAGE", menu_storage}, + { MT_SUBMENU, 0, "SETTINGS", menu_settingshigh}, { MT_CANCEL, 0, S_LARROW" MODE",NULL}, { MT_NONE, 0, NULL, NULL } // sentinel, // MENUITEM_CLOSE, @@ -884,7 +920,7 @@ static void menu_item_modify_attribute( *bg = DEFAULT_MENU_TEXT_COLOR; *fg = config.menu_normal_color; } - } else if (menu == menu_settings2) { + } else if (menu == menu_settings2 || menu == menu_settingshigh2) { if (item ==0 && settingAGC){ *bg = DEFAULT_MENU_TEXT_COLOR; *fg = config.menu_normal_color; @@ -893,7 +929,7 @@ static void menu_item_modify_attribute( *bg = DEFAULT_MENU_TEXT_COLOR; *fg = config.menu_normal_color; } - if (item == 2 && extraVFO){ + if (item == 2 && extraVFO){ // should not happen in high mode *bg = DEFAULT_MENU_TEXT_COLOR; *fg = config.menu_normal_color; } @@ -1041,9 +1077,7 @@ set_numeric_value(void) set_trace_scale(2, uistat.value / 1000.0); break; case KM_REFPOS: - set_trace_refpos(0, NGRIDY - uistat.value / get_trace_scale(0)); - set_trace_refpos(1, NGRIDY - uistat.value / get_trace_scale(0)); - set_trace_refpos(2, NGRIDY - uistat.value / get_trace_scale(0)); + SetRefpos(uistat.value); break; case KM_ATTENUATION: SetAttenuation(uistat.value); From f2b9a38e219502ec8bc0512d629764afb15c596d Mon Sep 17 00:00:00 2001 From: erikkaashoek Date: Thu, 26 Mar 2020 10:36:27 +0100 Subject: [PATCH 09/23] Mode switching improved --- sa_core.c | 91 ++++++++++++++++++++++++++++++------------------------- ui_sa.c | 35 ++++++++------------- 2 files changed, 62 insertions(+), 64 deletions(-) diff --git a/sa_core.c b/sa_core.c index cbf5e67..2349e11 100644 --- a/sa_core.c +++ b/sa_core.c @@ -130,47 +130,6 @@ int GetMode(void) dirty = true; } -void SetMode(int m) -{ - if (settingMode == m) - return; - settingMode = m; - switch(m) { - case M_LOW: - set_sweep_frequency(ST_START, (int32_t) 0); - set_sweep_frequency(ST_STOP, (int32_t) 300000000); - SetRefpos(-10); - goto min_max_low; - case M_GENLOW: - set_sweep_frequency(ST_CENTER, (int32_t) 10000000); - set_sweep_frequency(ST_SPAN, 0); - settingSpur = 0; // Not for output mode - settingRefer = -1; // No refer output in output mode - min_max_low: - minFreq = 0; - maxFreq = 520000000; - break; - case M_HIGH: - set_sweep_frequency(ST_START, (int32_t) 300000000); - set_sweep_frequency(ST_STOP, (int32_t) 960000000); - SetRefpos(-30); - goto min_max_high; - case M_GENHIGH: - set_sweep_frequency(ST_CENTER, (int32_t) 300000000); - set_sweep_frequency(ST_SPAN, 0); - settingRefer = -1; // No refer output in output mode - min_max_high: - minFreq = 240000000; - maxFreq = 960000000; - extraVFO = false; // Not possible in high mode - settingSpur = 0; // Not possible in high mode - break; - } - settingAttenuate = 0; - dirty = true; -} - - void SetAttenuation(int a) { if (a<0) @@ -336,6 +295,56 @@ void SetRefpos(int level) set_trace_refpos(2, NGRIDY - level / get_trace_scale(0)); dirty = true; } + +void SetScale(int s) { + set_trace_scale(0, s); + set_trace_scale(1, s); + set_trace_scale(2, s); +} + +void SetMode(int m) +{ + if (settingMode == m) + return; + settingMode = m; + switch(m) { + case M_LOW: + set_sweep_frequency(ST_START, (int32_t) 0); + set_sweep_frequency(ST_STOP, (int32_t) 300000000); + SetRefpos(-10); + goto min_max_low; + case M_GENLOW: + set_sweep_frequency(ST_CENTER, (int32_t) 10000000); + set_sweep_frequency(ST_SPAN, 0); + settingSpur = 0; // Not for output mode + settingRefer = -1; // No refer output in output mode + min_max_low: + minFreq = 0; + maxFreq = 520000000; + break; + case M_HIGH: + set_sweep_frequency(ST_START, (int32_t) 300000000); + set_sweep_frequency(ST_STOP, (int32_t) 960000000); + SetRefpos(-30); + goto min_max_high; + case M_GENHIGH: + set_sweep_frequency(ST_CENTER, (int32_t) 300000000); + set_sweep_frequency(ST_SPAN, 0); + settingRefer = -1; // No refer output in output mode + min_max_high: + minFreq = 240000000; + maxFreq = 960000000; + extraVFO = false; // Not possible in high mode + settingSpur = 0; // Not possible in high mode + break; + } + settingAttenuate = 0; + SetRBW(0); + SetScale(10); + dirty = true; +} + + //------------------------------------------ diff --git a/ui_sa.c b/ui_sa.c index a000baa..5850067 100644 --- a/ui_sa.c +++ b/ui_sa.c @@ -30,8 +30,11 @@ void toggle_waterfall(void); void SetMode(int); int GetMode(void); void SetRefpos(int); +void SetScale(int); void AllDirty(void); void MenuDirty(void); +void ToggleLNA(void); +void ToggleAGC(void); void redrawHisto(void); void self_test(void); extern int32_t frequencyExtra; @@ -207,33 +210,21 @@ void menu_autosettings_cb(int item, uint8_t data) { (void)item; (void)data; - SetMode(GetMode()); -// set_sweep_frequency(ST_START, (int32_t) 0); -// set_sweep_frequency(ST_STOP, (int32_t) 300000000); - - int value = 10; // 10dB/ - set_trace_scale(0, value); - set_trace_scale(1, value); - set_trace_scale(2, value); - - value = -10; // Top at -10dB - set_trace_refpos(0, - value / get_trace_scale(0) + NGRIDY); - set_trace_refpos(1, - value / get_trace_scale(0) + NGRIDY); - set_trace_refpos(2, - value / get_trace_scale(0) + NGRIDY); + int current_mode = GetMode(); + SetMode(-1); // Force setmode to do something + SetMode(current_mode); active_marker = 0; - - for (int i = 0; i Date: Thu, 26 Mar 2020 13:37:54 +0100 Subject: [PATCH 10/23] 3D buttons --- nanovna.h | 2 ++ ui.c | 30 ++++++++++++++++++++++-------- 2 files changed, 24 insertions(+), 8 deletions(-) diff --git a/nanovna.h b/nanovna.h index 58a6a6b..36a7d06 100644 --- a/nanovna.h +++ b/nanovna.h @@ -377,6 +377,8 @@ extern volatile uint8_t redraw_request; #define DEFAULT_FG_COLOR RGB565(255,255,255) #define DEFAULT_BG_COLOR RGB565( 0, 0, 0) +#define DARK_GREY RGB565(140,140,140) +#define LIGHT_GREY RGB565(220,220,220) #define DEFAULT_GRID_COLOR RGB565(128,128,128) #define DEFAULT_MENU_COLOR RGB565(255,255,255) #define DEFAULT_MENU_TEXT_COLOR RGB565( 0, 0, 0) diff --git a/ui.c b/ui.c index a9f7185..1d13e0d 100644 --- a/ui.c +++ b/ui.c @@ -1051,7 +1051,9 @@ const menuitem_t menu_top[] = { #define MENU_BUTTON_WIDTH 60 +#define MENU_BUTTON_START (320-MENU_BUTTON_WIDTH) #define MENU_FORM_WIDTH 290 +#define MENU_FORM_START (320 - MENU_FORM_WIDTH) #define MENU_BUTTON_HEIGHT 30 #define NUM_INPUT_HEIGHT 30 @@ -1423,6 +1425,7 @@ static void draw_menu_buttons(const menuitem_t *menu) { int i = 0; + int bw = 320; char text[30]; for (i = 0; i < 7; i++) { const char *l1, *l2; @@ -1457,20 +1460,31 @@ draw_menu_buttons(const menuitem_t *menu) } else active_button_width = MENU_BUTTON_WIDTH; - ili9341_fill(320-active_button_width, y, active_button_width, MENU_BUTTON_HEIGHT-2, old_bg); // Set button to unmodified background color + ili9341_fill(bw-active_button_width, y, active_button_width, MENU_BUTTON_HEIGHT-4, old_bg); // Set button to unmodified background color + + // 3D button accent + + if (MT_MASK(menu[i].type) != MT_TITLE) { + ili9341_fill(bw-active_button_width, y, 2, MENU_BUTTON_HEIGHT-4, LIGHT_GREY); // Set button to unmodified background color + ili9341_fill(bw-active_button_width, y, active_button_width, 2, LIGHT_GREY); // Set button to unmodified background color + ili9341_fill(bw-2, y, 2, MENU_BUTTON_HEIGHT-4, DARK_GREY); // Set button to unmodified background color + ili9341_fill(bw-active_button_width, y+MENU_BUTTON_HEIGHT-4, active_button_width, 2, DARK_GREY); // Set button to unmodified background color + } + + ili9341_set_foreground(fg); ili9341_set_background(bg); if (menu[i].type & MT_FORM) { - ili9341_fill(320-active_button_width+3, y+6, active_button_width-6, 2+FONT_GET_HEIGHT*2+2, bg); - ili9341_drawstring_size(text, 320-active_button_width+5, y+8, 2); + ili9341_fill(bw-active_button_width+3, y+6, active_button_width-6, 2+FONT_GET_HEIGHT*2+2, bg); + ili9341_drawstring_size(text, bw-active_button_width+5, y+8, 2); } else { if (menu_is_multiline(menu[i].label, &l1, &l2)) { - ili9341_fill(320-active_button_width+3, y+5, active_button_width-6, 2+FONT_GET_HEIGHT+1+FONT_GET_HEIGHT+2, bg); - ili9341_drawstring(l1, 320-active_button_width+5, y+7); - ili9341_drawstring(l2, 320-active_button_width+5, y+7+FONT_GET_HEIGHT+1); + ili9341_fill(bw-active_button_width+3, y+5, active_button_width-6, 2+FONT_GET_HEIGHT+1+FONT_GET_HEIGHT+2, bg); + ili9341_drawstring(l1, bw-active_button_width+5, y+7); + ili9341_drawstring(l2, bw-active_button_width+5, y+7+FONT_GET_HEIGHT+1); } else { - ili9341_fill(320-active_button_width+3, y+8, active_button_width-6, 2+FONT_GET_HEIGHT+2, bg); - ili9341_drawstring(menu[i].label, 320-active_button_width+5, y+10); + ili9341_fill(bw-active_button_width+3, y+8, active_button_width-6, 2+FONT_GET_HEIGHT+2, bg); + ili9341_drawstring(menu[i].label, bw-active_button_width+5, y+10); } } } From 8dcf6a6b59a72c4ab032e4b3d882621dfa9c6e1a Mon Sep 17 00:00:00 2001 From: erikkaashoek Date: Fri, 27 Mar 2020 13:08:13 +0100 Subject: [PATCH 11/23] Force top level menu on screen --- nanovna.h | 1 + plot.c | 2 ++ sa_core.c | 4 +++- ui.c | 39 ++++++++++++++++++++++++++------------- ui_sa.c | 1 + 5 files changed, 33 insertions(+), 14 deletions(-) diff --git a/nanovna.h b/nanovna.h index 36a7d06..0638ad0 100644 --- a/nanovna.h +++ b/nanovna.h @@ -525,6 +525,7 @@ void clear_all_config_prop_data(void); */ extern void ui_init(void); extern void ui_process(void); +int current_menu_is_form(void); // Irq operation process set #define OP_NONE 0x00 diff --git a/plot.c b/plot.c index 7cb98a6..719a443 100644 --- a/plot.c +++ b/plot.c @@ -1902,6 +1902,8 @@ draw_frequencies(void) char buf2[32]; buf2[0] = 0; if (MODE_OUTPUT(settingMode)) // No frequencies during output return; + if (current_menu_is_form()) + return; #ifdef __VNA__ if ((domain_mode & DOMAIN_MODE) == DOMAIN_FREQ) { diff --git a/sa_core.c b/sa_core.c index 2349e11..0731ae9 100644 --- a/sa_core.c +++ b/sa_core.c @@ -75,7 +75,7 @@ int settingSpur = 0; int settingAverage = 0; int settingShowStorage = 0; int settingSubtractStorage = 0; -int settingMode = M_LOW; +int settingMode = -1; // Initialize to unknown state int settingDrive=0; // 0-3 , 3=+20dBm int settingAGC = true; int settingLNA = false; @@ -705,6 +705,8 @@ void draw_cal_status(void) if (MODE_OUTPUT(settingMode)) // No cal status during output return; + if (current_menu_is_form()) + return; ili9341_set_background(DEFAULT_BG_COLOR); diff --git a/ui.c b/ui.c index 1d13e0d..b29cf4a 100644 --- a/ui.c +++ b/ui.c @@ -1105,6 +1105,11 @@ menu_push_submenu(const menuitem_t *submenu) draw_menu(); } +int current_menu_is_form(void) +{ + return menu_is_form(menu_stack[menu_current_level]); +} + /* static void menu_move_top(void) @@ -1425,7 +1430,6 @@ static void draw_menu_buttons(const menuitem_t *menu) { int i = 0; - int bw = 320; char text[30]; for (i = 0; i < 7; i++) { const char *l1, *l2; @@ -1449,20 +1453,25 @@ draw_menu_buttons(const menuitem_t *menu) uint16_t old_bg = bg; int active_button_width; + int active_button_start; menu_item_modify_attribute(menu, i, &fg, &bg); // before plot_printf to create status text if (menu[i].type & MT_FORM) { - active_button_width = MENU_FORM_WIDTH; + active_button_start = 320 - MENU_FORM_WIDTH; + active_button_width = MENU_FORM_WIDTH - 30; // Shorten at the right if (MT_MASK(menu[i].type) == MT_CALLBACK) { // Only callback can have value keypad_mode = menu[i].data; fetch_numeric_target(); } plot_printf(text, sizeof text, menu[i].label, uistat.text); } - else + else { active_button_width = MENU_BUTTON_WIDTH; - ili9341_fill(bw-active_button_width, y, active_button_width, MENU_BUTTON_HEIGHT-4, old_bg); // Set button to unmodified background color - + active_button_start = 320 - MENU_BUTTON_WIDTH; + } + ili9341_fill(active_button_start, y, active_button_width, MENU_BUTTON_HEIGHT-4, old_bg); // Set button to unmodified background color +#if 0 // 3D button accent + int bw = 320; if (MT_MASK(menu[i].type) != MT_TITLE) { ili9341_fill(bw-active_button_width, y, 2, MENU_BUTTON_HEIGHT-4, LIGHT_GREY); // Set button to unmodified background color @@ -1470,21 +1479,21 @@ draw_menu_buttons(const menuitem_t *menu) ili9341_fill(bw-2, y, 2, MENU_BUTTON_HEIGHT-4, DARK_GREY); // Set button to unmodified background color ili9341_fill(bw-active_button_width, y+MENU_BUTTON_HEIGHT-4, active_button_width, 2, DARK_GREY); // Set button to unmodified background color } - +#endif ili9341_set_foreground(fg); ili9341_set_background(bg); if (menu[i].type & MT_FORM) { - ili9341_fill(bw-active_button_width+3, y+6, active_button_width-6, 2+FONT_GET_HEIGHT*2+2, bg); - ili9341_drawstring_size(text, bw-active_button_width+5, y+8, 2); + ili9341_fill(active_button_start+3, y+6, active_button_width-6, 2+FONT_GET_HEIGHT*2+2, bg); + ili9341_drawstring_size(text, active_button_start+5, y+8, 2); } else { if (menu_is_multiline(menu[i].label, &l1, &l2)) { - ili9341_fill(bw-active_button_width+3, y+5, active_button_width-6, 2+FONT_GET_HEIGHT+1+FONT_GET_HEIGHT+2, bg); - ili9341_drawstring(l1, bw-active_button_width+5, y+7); - ili9341_drawstring(l2, bw-active_button_width+5, y+7+FONT_GET_HEIGHT+1); + ili9341_fill(active_button_start+3, y+5, active_button_width-6, 2+FONT_GET_HEIGHT+1+FONT_GET_HEIGHT+2, bg); + ili9341_drawstring(l1, active_button_start+5, y+7); + ili9341_drawstring(l2, active_button_start+5, y+7+FONT_GET_HEIGHT+1); } else { - ili9341_fill(bw-active_button_width+3, y+8, active_button_width-6, 2+FONT_GET_HEIGHT+2, bg); - ili9341_drawstring(menu[i].label, bw-active_button_width+5, y+10); + ili9341_fill(active_button_start+3, y+8, active_button_width-6, 2+FONT_GET_HEIGHT+2, bg); + ili9341_drawstring(menu[i].label, active_button_start+5, y+10); } } } @@ -2280,6 +2289,10 @@ void ui_process(void) { int button_state = READ_PORT() & BUTTON_MASK; + if (ui_mode == UI_NORMAL && current_menu_is_form()) { // Force into menu mode + selection = -1; // hide keyboard mode selection + ui_mode_menu(); + } if (operation_requested&OP_LEVER || previous_button_state != button_state) { ui_process_lever(); previous_button_state = button_state; diff --git a/ui_sa.c b/ui_sa.c index 5850067..b5c3f18 100644 --- a/ui_sa.c +++ b/ui_sa.c @@ -846,6 +846,7 @@ int menu_is_form(const menuitem_t *menu) return(false); } + static void menu_item_modify_attribute( const menuitem_t *menu, int item, uint16_t *fg, uint16_t *bg) { From bab77014585e19e13be061d1804c3999dbb298f6 Mon Sep 17 00:00:00 2001 From: erikkaashoek Date: Fri, 27 Mar 2020 15:02:40 +0100 Subject: [PATCH 12/23] Large buttons and mode switching improvements --- ili9341.c | 10 ++++++++++ sa_core.c | 59 +++++++++++++++++++++++++++++++------------------------ ui.c | 14 +++++++++++++ 3 files changed, 57 insertions(+), 26 deletions(-) diff --git a/ili9341.c b/ili9341.c index 0c44bf9..0cd5ad2 100644 --- a/ili9341.c +++ b/ili9341.c @@ -592,6 +592,16 @@ void ili9341_drawstring(const char *str, int x, int y) } } +void ili9341_drawstring_7x13(const char *str, int x, int y) +{ + while (*str) { + uint8_t ch = *str++; + const uint16_t *char_buf = &x7x13b_bits[(ch * 13)]; + blit16BitWidthBitmap(x, y, 7, 11, char_buf); + x += 7; + } +} + void ili9341_drawstringV(const char *str, int x, int y) { ili9341_set_rotation(DISPLAY_ROTATION_270); diff --git a/sa_core.c b/sa_core.c index 0731ae9..b7b057a 100644 --- a/sa_core.c +++ b/sa_core.c @@ -75,7 +75,7 @@ int settingSpur = 0; int settingAverage = 0; int settingShowStorage = 0; int settingSubtractStorage = 0; -int settingMode = -1; // Initialize to unknown state +int settingMode = M_LOW; int settingDrive=0; // 0-3 , 3=+20dBm int settingAGC = true; int settingLNA = false; @@ -309,31 +309,35 @@ void SetMode(int m) settingMode = m; switch(m) { case M_LOW: + minFreq = 0; + maxFreq = 520000000; set_sweep_frequency(ST_START, (int32_t) 0); set_sweep_frequency(ST_STOP, (int32_t) 300000000); SetRefpos(-10); - goto min_max_low; + settingSpur = 0; // Not for output mode + break; case M_GENLOW: + minFreq = 0; + maxFreq = 520000000; set_sweep_frequency(ST_CENTER, (int32_t) 10000000); set_sweep_frequency(ST_SPAN, 0); settingSpur = 0; // Not for output mode settingRefer = -1; // No refer output in output mode - min_max_low: - minFreq = 0; - maxFreq = 520000000; break; case M_HIGH: + minFreq = 240000000; + maxFreq = 960000000; set_sweep_frequency(ST_START, (int32_t) 300000000); set_sweep_frequency(ST_STOP, (int32_t) 960000000); SetRefpos(-30); - goto min_max_high; + goto common_high; case M_GENHIGH: + minFreq = 240000000; + maxFreq = 960000000; set_sweep_frequency(ST_CENTER, (int32_t) 300000000); set_sweep_frequency(ST_SPAN, 0); settingRefer = -1; // No refer output in output mode - min_max_high: - minFreq = 240000000; - maxFreq = 960000000; + common_high: extraVFO = false; // Not possible in high mode settingSpur = 0; // Not possible in high mode break; @@ -506,13 +510,14 @@ float perform(bool break_on_operation, int i, int32_t f, int extraV) } SetRX(settingMode); SI4432_SetReference(settingRefer); - if (local_IF) - setFreq (0, local_IF); + // if (dirty) { scandirty = true; dirty = false; // } } + if (i == 0 && ( scandirty || settingSpur) && local_IF) + setFreq (0, local_IF); if (settingModulation == MO_AM) { int p = settingAttenuate * 2 + modulation_counter; PE4302_Write_Byte(p); @@ -561,6 +566,10 @@ static bool sweep(bool break_on_operation) again: for (int i = 0; i < sweep_points; i++) { RSSI = perform(break_on_operation, i, frequencies[i], extraVFO); + // back to toplevel to handle ui operation + if (operation_requested && break_on_operation) + return false; + if (settingSpur == 1) { // First pass temp_t[i] = RSSI; continue; // Skip all other processing @@ -590,29 +599,27 @@ again: } } if (i == sweep_points -1) { - if (scandirty) { - scandirty = false; - } - peakIndex = temppeakIndex; - peakLevel = actual_t[peakIndex]; - peakFreq = frequencies[peakIndex]; - settingSpur = -settingSpur; - int peak_marker = 0; - markers[peak_marker].enabled = true; - markers[peak_marker].index = peakIndex; - markers[peak_marker].frequency = frequencies[markers[peak_marker].index]; - // redraw_marker(peak_marker, FALSE); } - // back to toplevel to handle ui operation - if (operation_requested && break_on_operation) - return false; } if (settingSpur == 1) { settingSpur = -1; goto again; + } else if (settingSpur == -1) + settingSpur = 1; + + if (scandirty) { + scandirty = false; } + peakIndex = temppeakIndex; + peakLevel = actual_t[peakIndex]; + peakFreq = frequencies[peakIndex]; + int peak_marker = 0; + markers[peak_marker].enabled = true; + markers[peak_marker].index = peakIndex; + markers[peak_marker].frequency = frequencies[markers[peak_marker].index]; + // redraw_marker(peak_marker, FALSE); palSetPad(GPIOC, GPIOC_LED); return true; } diff --git a/ui.c b/ui.c index b29cf4a..21ce6fe 100644 --- a/ui.c +++ b/ui.c @@ -1488,12 +1488,26 @@ draw_menu_buttons(const menuitem_t *menu) ili9341_drawstring_size(text, active_button_start+5, y+8, 2); } else { if (menu_is_multiline(menu[i].label, &l1, &l2)) { +#define BIG_BUTTON_FONT 1 +#ifdef BIG_BUTTON_FONT +#undef FONT_HEIGHT +#define FONT_HEIGHT 13 + ili9341_fill(active_button_start+1, y+1, active_button_width-2, 13+13 -2, bg); + ili9341_drawstring_7x13(l1, active_button_start+2, y+1); + ili9341_drawstring_7x13(l2, active_button_start+2, y+1+13-1); +#else ili9341_fill(active_button_start+3, y+5, active_button_width-6, 2+FONT_GET_HEIGHT+1+FONT_GET_HEIGHT+2, bg); ili9341_drawstring(l1, active_button_start+5, y+7); ili9341_drawstring(l2, active_button_start+5, y+7+FONT_GET_HEIGHT+1); +#endif } else { +#ifdef BIG_BUTTON_FONT + ili9341_fill(active_button_start+1, y+1, active_button_width-2, 13+13 -2, bg); + ili9341_drawstring_7x13(menu[i].label, active_button_start+2, y+6); +#else ili9341_fill(active_button_start+3, y+8, active_button_width-6, 2+FONT_GET_HEIGHT+2, bg); ili9341_drawstring(menu[i].label, active_button_start+5, y+10); +#endif } } } From 37befeb9478aae6d01bb78a790a0ba9558ac4573 Mon Sep 17 00:00:00 2001 From: erikkaashoek Date: Fri, 27 Mar 2020 19:34:57 +0100 Subject: [PATCH 13/23] Self test extended --- nanovna.h | 1 + plot.c | 25 +++++++------ sa_core.c | 102 +++++++++++++++++++++++++++++++++++++----------------- ui_sa.c | 12 +++++++ 4 files changed, 95 insertions(+), 45 deletions(-) diff --git a/nanovna.h b/nanovna.h index 0638ad0..09d2ec9 100644 --- a/nanovna.h +++ b/nanovna.h @@ -307,6 +307,7 @@ void set_trace_refpos(int t, float refpos); float get_trace_scale(int t); float get_trace_refpos(int t); const char *get_trace_typename(int t); +extern int in_selftest; #ifdef __VNA void set_electrical_delay(float picoseconds); diff --git a/plot.c b/plot.c index 719a443..f31d193 100644 --- a/plot.c +++ b/plot.c @@ -1144,9 +1144,9 @@ marker_search(void) if (uistat.current_trace == -1) return -1; - int value = CELL_Y(trace_index[uistat.current_trace][0]); + int value = CELL_Y(trace_index[TRACE_ACTUAL][0]); for (i = 0; i < sweep_points; i++) { - index_t index = trace_index[uistat.current_trace][i]; + index_t index = trace_index[TRACE_ACTUAL][i]; if ((*compare)(value, CELL_Y(index))) { value = CELL_Y(index); found = i; @@ -1167,21 +1167,21 @@ marker_search_left(int from) { int i; int found = -1; - +#define MINMAX_DELTA -10 if (uistat.current_trace == -1) return -1; - int value = CELL_Y(trace_index[uistat.current_trace][from]); + int value = CELL_Y(trace_index[TRACE_ACTUAL][from]); for (i = from - 1; i >= 0; i--) { - index_t index = trace_index[uistat.current_trace][i]; - if ((*compare)(value, CELL_Y(index))) + index_t index = trace_index[TRACE_ACTUAL][i]; + if ((*compare)(value - MINMAX_DELTA, CELL_Y(index))) break; value = CELL_Y(index); } for (; i >= 0; i--) { - index_t index = trace_index[uistat.current_trace][i]; - if ((*compare)(CELL_Y(index), value)) { + index_t index = trace_index[TRACE_ACTUAL][i]; + if ((*compare)(CELL_Y(index), value + MINMAX_DELTA)) { break; } found = i; @@ -1198,17 +1198,16 @@ marker_search_right(int from) if (uistat.current_trace == -1) return -1; - - int value = CELL_Y(trace_index[uistat.current_trace][from]); + int value = CELL_Y(trace_index[TRACE_ACTUAL][from]); for (i = from + 1; i < sweep_points; i++) { - index_t index = trace_index[uistat.current_trace][i]; + index_t index = trace_index[TRACE_ACTUAL][i]; if ((*compare)(value, CELL_Y(index))) break; value = CELL_Y(index); } for (; i < sweep_points; i++) { - index_t index = trace_index[uistat.current_trace][i]; + index_t index = trace_index[TRACE_ACTUAL][i]; if ((*compare)(CELL_Y(index), value)) { break; } @@ -1902,7 +1901,7 @@ draw_frequencies(void) char buf2[32]; buf2[0] = 0; if (MODE_OUTPUT(settingMode)) // No frequencies during output return; - if (current_menu_is_form()) + if (current_menu_is_form() && !in_selftest) return; #ifdef __VNA__ diff --git a/sa_core.c b/sa_core.c index b7b057a..43a06fd 100644 --- a/sa_core.c +++ b/sa_core.c @@ -84,6 +84,7 @@ int settingModulation = MO_NONE; int settingStepDelay = 0; float rbw = 0; float vbw = 0; +int in_selftest = false; uint32_t minFreq = 0; uint32_t maxFreq = 520000000; @@ -712,7 +713,7 @@ void draw_cal_status(void) if (MODE_OUTPUT(settingMode)) // No cal status during output return; - if (current_menu_is_form()) + if (current_menu_is_form() && !in_selftest) return; ili9341_set_background(DEFAULT_BG_COLOR); @@ -826,32 +827,38 @@ void draw_cal_status(void) // -------------------- Self testing ------------------------------------------------- enum { - TC_SIGNAL, TC_BELOW, TC_ABOVE, TC_FLAT + TC_SIGNAL, TC_BELOW, TC_ABOVE, TC_FLAT, TC_MEASURE, TC_SET, }; enum { - TP_SILENT, TP_10MHZ, TP_10MHZEXTRA, TP_30MHZ + TP_SILENT, TPH_SILENT, TP_10MHZ, TP_10MHZEXTRA, TP_30MHZ, TPH_30MHZ }; -#define TEST_COUNT 7 +#define TEST_COUNT 13 static const struct { int kind; int setup; - uint32_t center; // In MHz - int span; // In MHz + float center; // In MHz + float span; // In MHz float pass; int width; float stop; } test_case [TEST_COUNT] = {// Condition Preparation Center Span Pass Width Stop - {TC_SIGNAL, TP_10MHZ, 10, 7, -30, 30, -85 }, - {TC_SIGNAL, TP_10MHZ, 20, 7, -50, 30, -90 }, - {TC_SIGNAL, TP_10MHZ, 30, 7, -40, 30, -90 }, - {TC_BELOW, TP_SILENT, 200, 100, -80, 0, 0}, - {TC_SIGNAL, TP_10MHZEXTRA, 10, 8, -30, 50, -80 }, - {TC_FLAT, TP_10MHZEXTRA, 10, 4, -35, 20, -80}, - {TC_SIGNAL, TP_30MHZ, 360, 18, -70, 20, -100 }, + {TC_BELOW, TP_SILENT, 0.001, 0.0005, -10,0, 0}, // 1 Zero Hz leakage + {TC_BELOW, TP_SILENT, 0.01, 0.01, -40, 0, 0}, // 2 Phase noise of zero Hz + {TC_MEASURE, TP_30MHZ, 30, 7, -25, 30, -85 }, // 3 Measure power level and noise + {TC_SET, TP_30MHZ, 30, 7, -25, 0, 0 }, // 4 Calibrate power low mode + {TC_MEASURE, TP_30MHZ, 270, 4, -50, 30, -85 }, // 5 Measure powerlevel and noise + {TC_SET, TPH_30MHZ, 270, 4, -50, 0, 0 }, // 6 Calibrate power high mode + {TC_SIGNAL, TP_10MHZ, 20, 7, -40, 30, -90 }, // 7 + {TC_SIGNAL, TP_10MHZ, 30, 7, -30, 30, -90 }, // 8 + {TC_BELOW, TP_SILENT, 200, 100, -75, 0, 0}, // 9 Wide band noise floor low mode + {TC_BELOW, TPH_SILENT, 600, 720, -75, 0, 0}, // 10 Wide band noise floor high mode + {TC_SIGNAL, TP_10MHZEXTRA, 10, 8, -20, 50, -70 }, // 11 BPF loss and stop band + {TC_FLAT, TP_10MHZEXTRA, 10, 4, -25, 20, -70}, // 12 BPF pass band flatness + {TC_BELOW, TP_30MHZ, 430, 60, -75, 0, -85}, // 13 LPF cutoff }; enum { @@ -866,16 +873,19 @@ static const char *(test_fail_cause [TEST_COUNT]); static int test_status[TEST_COUNT]; static int show_test_info = FALSE; static volatile int test_wait = false; +static float test_value; static void test_acquire(int i) { pause_sweep(); +#if 0 if (test_case[i].center < 300) settingMode = M_LOW; else settingMode = M_HIGH; - set_sweep_frequency(ST_CENTER, (int32_t)test_case[i].center * 1000000); - set_sweep_frequency(ST_SPAN, (int32_t)test_case[i].span * 1000000); +#endif + set_sweep_frequency(ST_CENTER, (int32_t)(test_case[i].center * 1000000)); + set_sweep_frequency(ST_SPAN, (int32_t)(test_case[i].span * 1000000)); sweep(false); plot_into_index(measured); redraw_request |= REDRAW_CELLS | REDRAW_FREQUENCY; @@ -978,7 +988,17 @@ int validate_above(void) { void test_validate(int i) { - if (test_case[i].kind == TC_SIGNAL) { // Validate signal +// draw_all(TRUE); + SetRefpos(test_case[i].pass+10); + switch (test_case[i].kind) { + case TC_SET: + if (test_case[i].pass == 0) { + if (test_value != 0) + SetPowerLevel(test_value); + } else + SetPowerLevel(test_case[i].pass); + case TC_MEASURE: + case TC_SIGNAL: // Validate signal if (validate_peak_within(i, 5.0)) // Validate Peak test_status[i] = TS_PASS; else if (validate_peak_within(i, 10.0)) @@ -1007,8 +1027,12 @@ void test_validate(int i) if (test_status[i] != TS_PASS) test_fail_cause[i] = "Stopband "; } - - } else if (test_case[i].kind == TC_ABOVE) { // Validate signal above curve + if (test_status[i] == TS_PASS && test_case[i].kind == TC_MEASURE) + test_value = peakLevel; + else + test_value = 0; // Not valid + break; + case TC_ABOVE: // Validate signal above curve for (int j = 0; j < POINTS_COUNT; j++) { if (actual_t[j] < test_case[i].pass + 5) test_status[i] = TS_CRITICAL; @@ -1019,26 +1043,26 @@ void test_validate(int i) } if (test_status[i] != TS_PASS) test_fail_cause[i] = "Above "; - - } else if (test_case[i].kind == TC_BELOW) { // Validate signal below curve - if (validate_peak_below(i, 10.0)) - test_status[i] = TS_PASS; - else if (validate_peak_below(i, 5.0)) - test_status[i] = TS_CRITICAL; - else - test_status[i] = TS_FAIL; + break; + case TC_BELOW: // Validate signal below curve + test_status[i] = validate_below(); if (test_status[i] != TS_PASS) test_fail_cause[i] = "Above "; - } else if (test_case[i].kind == TC_FLAT) { // Validate passband flatness + break; + case TC_FLAT: // Validate passband flatness test_status[i] = validate_flatness(i); if (test_status[i] != TS_PASS) test_fail_cause[i] = "Passband "; + break; + } // Report status if (test_status[i] != TS_PASS || i == TEST_COUNT - 1) test_wait = true; +// draw_frequencies(); +// draw_cal_status(); draw_all(TRUE); resume_sweep(); } @@ -1048,6 +1072,7 @@ extern void touch_wait_release(void); void self_test(void) { + in_selftest = true; menu_autosettings_cb(0); for (int i=0; i < TEST_COUNT; i++) { // All test cases waiting test_status[i] = TS_WAITING; @@ -1057,26 +1082,38 @@ void self_test(void) for (int i=0; i < TEST_COUNT; i++) { extraVFO = false; //Default test setup switch(test_case[i].setup) { // Prepare test conditions + case TPH_SILENT: // No input signal + SetMode(M_HIGH); case TP_SILENT: // No input signal + SetMode(M_LOW); +common_silent: set_refer_output(-1); for (int j = 0; j < POINTS_COUNT; j++) stored_t[j] = test_case[i].pass; break; case TP_10MHZEXTRA: // Swept receiver + SetMode(M_LOW); extraVFO = true; //Sweep BPF + set_refer_output(2); goto common; case TP_10MHZ: // 10MHz input - common: + SetMode(M_LOW); set_refer_output(2); - int j; - for (j = 0; j < POINTS_COUNT/2 - test_case[i].width; j++) + common: + + for (int j = 0; j < POINTS_COUNT/2 - test_case[i].width; j++) stored_t[j] = test_case[i].stop; - for (j = POINTS_COUNT/2 + test_case[i].width; j < POINTS_COUNT; j++) + for (int j = POINTS_COUNT/2 + test_case[i].width; j < POINTS_COUNT; j++) stored_t[j] = test_case[i].stop; - for (j = POINTS_COUNT/2 - test_case[i].width; j < POINTS_COUNT/2 + test_case[i].width; j++) + for (int j = POINTS_COUNT/2 - test_case[i].width; j < POINTS_COUNT/2 + test_case[i].width; j++) stored_t[j] = test_case[i].pass; break; case TP_30MHZ: + SetMode(M_LOW); + set_refer_output(0); + goto common; + case TPH_30MHZ: + SetMode(M_HIGH); set_refer_output(0); goto common; } @@ -1103,5 +1140,6 @@ void self_test(void) settingMode = M_LOW; draw_cal_status(); + in_selftest = false; menu_autosettings_cb(0); } diff --git a/ui_sa.c b/ui_sa.c index b5c3f18..1e5f44f 100644 --- a/ui_sa.c +++ b/ui_sa.c @@ -715,12 +715,24 @@ static const menuitem_t menu_marker_type[] = { { MT_NONE, 0, NULL, NULL } // sentinel }; +const menuitem_t menu_marker_search[] = { + //{ MT_CALLBACK, "OFF", menu_marker_search_cb }, + { MT_CALLBACK, 0, "MAXIMUM", menu_marker_search_cb }, + { MT_CALLBACK, 0, "MINIMUM", menu_marker_search_cb }, + { MT_CALLBACK, 0, "\2SEARCH\0" S_LARROW" LEFT", menu_marker_search_cb }, + { MT_CALLBACK, 0, "\2SEARCH\0" S_RARROW" RIGHT", menu_marker_search_cb }, + { MT_CALLBACK, 0, "TRACKING", menu_marker_search_cb }, + { MT_CANCEL, 0, S_LARROW" BACK", NULL }, + { MT_NONE, 0, NULL, NULL } // sentinel +}; + static const menuitem_t menu_marker_sel[] = { { MT_CALLBACK, 0, "MARKER 1", menu_marker_sel_cb}, { MT_CALLBACK, 0, "MARKER 2", menu_marker_sel_cb}, { MT_CALLBACK, 0, "MARKER 3", menu_marker_sel_cb}, { MT_CALLBACK, 0, "MARKER 4", menu_marker_sel_cb}, { MT_CALLBACK, 0, "ALL OFF", menu_marker_sel_cb}, + { MT_SUBMENU, 0, "\2SEARCH\0MARKER", menu_marker_search}, { MT_CANCEL, 0, S_LARROW" BACK", NULL }, { MT_NONE, 0, NULL, NULL } // sentinel }; From 39da5289b4cf113de434fc4c31a4a67a3d9ef6ba Mon Sep 17 00:00:00 2001 From: erikkaashoek Date: Sat, 28 Mar 2020 13:11:20 +0100 Subject: [PATCH 14/23] Spur avoidance table added --- main.c | 5 ++- plot.c | 2 +- sa_core.c | 93 ++++++++++++++++++++++++++++++++++++++++++++++++------- 3 files changed, 87 insertions(+), 13 deletions(-) diff --git a/main.c b/main.c index 02d8b92..fb246a5 100644 --- a/main.c +++ b/main.c @@ -801,7 +801,10 @@ static const trace_t def_trace[TRACES_MAX] = {//enable, type, channel, reserved, }; static const marker_t def_markers[MARKERS_MAX] = { - { 1, M_REFERENCE, 30, 0 }, { 0, M_DELTA, 40, 0 }, { 0, M_DELTA, 60, 0 }, { 0, M_DELTA, 80, 0 } + { 1, M_REFERENCE, 30, 0 }, + { 0, M_NORMAL, 40, 0 }, + { 0, M_NORMAL, 60, 0 }, + { 0, M_NORMAL, 80, 0 } }; // Load propeties default settings diff --git a/plot.c b/plot.c index f31d193..d65a34e 100644 --- a/plot.c +++ b/plot.c @@ -67,7 +67,7 @@ typedef uint32_t map_t; uint16_t marker_color[3] = { RGBHEX(0xFFFFFF), - RGBHEX(0x0000FF), + RGBHEX(0xFFFF00), RGBHEX(0x00FF00) }; diff --git a/sa_core.c b/sa_core.c index 43a06fd..28c2cec 100644 --- a/sa_core.c +++ b/sa_core.c @@ -476,12 +476,75 @@ void update_rbw(uint32_t delta_f) dirty = true; } +//static int spur_old_stepdelay = 0; +static int spur_IF = 433900000; +static int spur_alternate_IF = 433700000; +static const int spur_table[] = +{ + 470000, + 780000, + 830000, + 880000, + 949000, + 1468000, + 1830000, + 1900000, + 2840000, + 2880000, + 4780000, + 4800000, + 4880000, + 6510000 + 6860000, + 7340000, + 8100000, + 8200000, + 8880000, +// 9970000, 10MHz!!!!!! + 10870000, + 11420000, + 14880000, + 16820000, +}; + +int avoid_spur(int f) +{ + int window = ((int)rbw ) * 1000*2; + if (window < 50000) + window = 50000; + if (! settingMode == M_LOW) + return false ; + if (frequency_IF != spur_IF) + return false; + if (rbw > 300.0) + return(false); +// if (spur_old_stepdelay != 0 && actualStepDelay != spur_old_stepdelay) // restore stepdelay +// actualStepDelay = spur_old_stepdelay; + for (int i = 0; i < (sizeof spur_table)/sizeof(int); i++) { + if (f/window == spur_table[i]/window) { +// spur_old_stepdelay = actualStepDelay; +// actualStepDelay += 4000; + return true; + } + } + return false; +} + static int old_lf = -1; static int modulation_counter = 0; +static int old_local_IF = -1; float perform(bool break_on_operation, int i, int32_t f, int extraV) { - long local_IF = (MODE_LOW(settingMode)?frequency_IF + (int)(rbw < 300.0?settingSpur * 1000 * rbw :0):0); +// long local_IF = (MODE_LOW(settingMode)?frequency_IF + (int)(rbw < 300.0?settingSpur * 1000 * rbw :0):0); + long local_IF; + if (MODE_HIGH(settingMode)) + local_IF = 0; + else if (avoid_spur(f)) + local_IF = spur_alternate_IF; + else + local_IF = frequency_IF; + if (i == 0 && dirty) { if (settingStepDelay == 0){ if (rbw < 10.0) @@ -517,8 +580,11 @@ float perform(bool break_on_operation, int i, int32_t f, int extraV) dirty = false; // } } - if (i == 0 && ( scandirty || settingSpur) && local_IF) +// if (i == 0 && ( scandirty || settingSpur) && local_IF) + if (local_IF && old_local_IF != local_IF) { setFreq (0, local_IF); + old_local_IF = local_IF; + } if (settingModulation == MO_AM) { int p = settingAttenuate * 2 + modulation_counter; PE4302_Write_Byte(p); @@ -564,6 +630,7 @@ static bool sweep(bool break_on_operation) float RSSI; palClearPad(GPIOC, GPIOC_LED); temppeakLevel = -150; +// spur_old_stepdelay = 0; again: for (int i = 0; i < sweep_points; i++) { RSSI = perform(break_on_operation, i, frequencies[i], extraVFO); @@ -612,6 +679,7 @@ again: if (scandirty) { scandirty = false; + draw_cal_status(); } peakIndex = temppeakIndex; peakLevel = actual_t[peakIndex]; @@ -705,10 +773,6 @@ void draw_cal_status(void) #define XSTEP 40 -// if (!sweep_enabled) -// perform(true, 0, frequencies[0], false); - - ili9341_fill(x, y, OFFSETX, HEIGHT, 0x0000); if (MODE_OUTPUT(settingMode)) // No cal status during output @@ -787,6 +851,9 @@ void draw_cal_status(void) buf[5]=0; ili9341_drawstring(buf, x, y); + if (dirty) + ili9341_set_foreground(BRIGHT_COLOR_RED); + y += YSTEP*2; ili9341_drawstring("Scan:", x, y); @@ -886,6 +953,10 @@ static void test_acquire(int i) #endif set_sweep_frequency(ST_CENTER, (int32_t)(test_case[i].center * 1000000)); set_sweep_frequency(ST_SPAN, (int32_t)(test_case[i].span * 1000000)); + SetAverage(4); + sweep(false); + sweep(false); + sweep(false); sweep(false); plot_into_index(measured); redraw_request |= REDRAW_CELLS | REDRAW_FREQUENCY; @@ -989,7 +1060,6 @@ int validate_above(void) { void test_validate(int i) { // draw_all(TRUE); - SetRefpos(test_case[i].pass+10); switch (test_case[i].kind) { case TC_SET: if (test_case[i].pass == 0) { @@ -997,8 +1067,10 @@ void test_validate(int i) SetPowerLevel(test_value); } else SetPowerLevel(test_case[i].pass); - case TC_MEASURE: + goto common; + case TC_MEASURE: case TC_SIGNAL: // Validate signal + common: if (validate_peak_within(i, 5.0)) // Validate Peak test_status[i] = TS_PASS; else if (validate_peak_within(i, 10.0)) @@ -1084,6 +1156,7 @@ void self_test(void) switch(test_case[i].setup) { // Prepare test conditions case TPH_SILENT: // No input signal SetMode(M_HIGH); + goto common_silent; case TP_SILENT: // No input signal SetMode(M_LOW); common_silent: @@ -1118,9 +1191,7 @@ common_silent: goto common; } trace[TRACE_STORED].enabled = true; - set_trace_refpos(0, NGRIDY - (test_case[i].pass + 30) / get_trace_scale(0)); - set_trace_refpos(1, NGRIDY - (test_case[i].pass + 30) / get_trace_scale(0)); - set_trace_refpos(2, NGRIDY - (test_case[i].pass + 30) / get_trace_scale(0)); + SetRefpos(test_case[i].pass+10); draw_cal_status(); test_acquire(i); // Acquire test test_validate(i); // Validate test From 8631ac14f15434c65cc6c5c0abad6f218f26cfd5 Mon Sep 17 00:00:00 2001 From: erikkaashoek Date: Sat, 28 Mar 2020 19:52:49 +0100 Subject: [PATCH 15/23] Atampt to auto scaling and other UI improvements --- sa_core.c | 31 +++++++++++++++++++++++++------ ui.c | 6 +++--- ui_sa.c | 4 ++-- 3 files changed, 30 insertions(+), 11 deletions(-) diff --git a/sa_core.c b/sa_core.c index 28c2cec..d839429 100644 --- a/sa_core.c +++ b/sa_core.c @@ -354,6 +354,7 @@ void SetMode(int m) float peakLevel; +float min_level; uint32_t peakFreq; int peakIndex; float temppeakLevel; @@ -486,15 +487,20 @@ static const int spur_table[] = 830000, 880000, 949000, + 1390000, 1468000, 1830000, 1900000, + 2770000, 2840000, 2880000, + 4710000, 4780000, 4800000, 4880000, - 6510000 + 6510000, + 6750000, + 6790000, 6860000, 7340000, 8100000, @@ -630,7 +636,8 @@ static bool sweep(bool break_on_operation) float RSSI; palClearPad(GPIOC, GPIOC_LED); temppeakLevel = -150; -// spur_old_stepdelay = 0; + float temp_min_level = 100; + // spur_old_stepdelay = 0; again: for (int i = 0; i < sweep_points; i++) { RSSI = perform(break_on_operation, i, frequencies[i], extraVFO); @@ -666,10 +673,8 @@ again: temppeakLevel = actual_t[i]; } } - if (i == sweep_points -1) { - - - } + if (temp_min_level > actual_t[i]) + temp_min_level = actual_t[i]; } if (settingSpur == 1) { settingSpur = -1; @@ -684,6 +689,20 @@ again: peakIndex = temppeakIndex; peakLevel = actual_t[peakIndex]; peakFreq = frequencies[peakIndex]; + min_level = temp_min_level; +#if 0 // Auto ref level setting + int scale = get_trace_scale(2); + int rp = (NGRIDY - get_trace_refpos(2)) * scale; + if (scale > 0 && peakLevel > rp && peakLevel - min_level < 8 * scale ) { + SetRefpos((((int)(peakLevel/scale)) + 1) * scale); + } + if (scale > 0 && min_level < rp - 9*scale && peakLevel - min_level < 8 * scale ) { + int new_rp = (((int)((min_level + 9*scale)/scale)) - 1) * scale; + if (new_rp < rp) + SetRefpos(new_rp); + } + +#endif int peak_marker = 0; markers[peak_marker].enabled = true; markers[peak_marker].index = peakIndex; diff --git a/ui.c b/ui.c index 21ce6fe..f89aca6 100644 --- a/ui.c +++ b/ui.c @@ -1052,7 +1052,7 @@ const menuitem_t menu_top[] = { #define MENU_BUTTON_WIDTH 60 #define MENU_BUTTON_START (320-MENU_BUTTON_WIDTH) -#define MENU_FORM_WIDTH 290 +#define MENU_FORM_WIDTH 295 #define MENU_FORM_START (320 - MENU_FORM_WIDTH) #define MENU_BUTTON_HEIGHT 30 #define NUM_INPUT_HEIGHT 30 @@ -1484,8 +1484,8 @@ draw_menu_buttons(const menuitem_t *menu) ili9341_set_foreground(fg); ili9341_set_background(bg); if (menu[i].type & MT_FORM) { - ili9341_fill(active_button_start+3, y+6, active_button_width-6, 2+FONT_GET_HEIGHT*2+2, bg); - ili9341_drawstring_size(text, active_button_start+5, y+8, 2); + ili9341_fill(active_button_start+2, y+2, active_button_width-4, FONT_GET_HEIGHT*2+8, bg); + ili9341_drawstring_size(text, active_button_start+6, y+6, 2); } else { if (menu_is_multiline(menu[i].label, &l1, &l2)) { #define BIG_BUTTON_FONT 1 diff --git a/ui_sa.c b/ui_sa.c index 1e5f44f..ec10d26 100644 --- a/ui_sa.c +++ b/ui_sa.c @@ -1035,7 +1035,7 @@ static void fetch_numeric_target(void) break; case KM_LOWOUTLEVEL: uistat.value = settingAttenuate; - uistat.value = -10 - uistat.value; // compensation for dB offset during low output mode + uistat.value = -5 - uistat.value; // compensation for dB offset during low output mode plot_printf(uistat.text, sizeof uistat.text, "%ddB", uistat.value); break; case KM_HIGHOUTLEVEL: @@ -1099,7 +1099,7 @@ set_numeric_value(void) SetDrive(uistat.value); break; case KM_LOWOUTLEVEL: - uistat.value = -10 - uistat.value ; // compensation for dB offset during low output mode + uistat.value = -5 - uistat.value ; // compensation for dB offset during low output mode SetAttenuation(uistat.value); break; case KM_HIGHOUTLEVEL: From 6a627149d64b849dc1a68e29e66a43e48ccafc70 Mon Sep 17 00:00:00 2001 From: erikkaashoek Date: Sun, 29 Mar 2020 15:51:15 +0200 Subject: [PATCH 16/23] Test and calibrate updated --- nanovna.h | 2 + plot.c | 11 +-- sa_core.c | 263 ++++++++++++++++++++++++++++++++++-------------------- si4432.c | 9 +- ui_sa.c | 109 ++++++++++------------ 5 files changed, 226 insertions(+), 168 deletions(-) diff --git a/nanovna.h b/nanovna.h index 09d2ec9..0a96e9c 100644 --- a/nanovna.h +++ b/nanovna.h @@ -620,5 +620,7 @@ int GetStorage(void); int GetSubtractStorage(void); int get_waterfall(void); +void calibrate(void); +void reset_calibration(void); /*EOF*/ diff --git a/plot.c b/plot.c index d65a34e..23dfe61 100644 --- a/plot.c +++ b/plot.c @@ -1100,7 +1100,7 @@ markmap_marker(int marker) int t; if (!markers[marker].enabled) return; - for (t = 0; t < TRACES_MAX; t++) { + for (t = TRACE_ACTUAL; t < TRACE_ACTUAL; t++) { if (!trace[t].enabled) continue; index_t index = trace_index[t][markers[marker].index]; @@ -1390,9 +1390,10 @@ draw_cell(int m, int n) for (i = 0; i < MARKERS_MAX; i++) { if (!markers[i].enabled) continue; - for (t = 0; t < TRACES_MAX; t++) { - if (!trace[t].enabled) - continue; +// for (t = 0; t < TRACES_MAX; t++) { +// if (!trace[t].enabled) +// continue; + t = TRACE_ACTUAL; index_t index = trace_index[t][markers[i].index]; int x = CELL_X(index) - x0 - X_MARKER_OFFSET; int y = CELL_Y(index) - y0 - Y_MARKER_OFFSET; @@ -1401,7 +1402,7 @@ draw_cell(int m, int n) y + MARKER_HEIGHT >= 0 && y - MARKER_HEIGHT < CELLHEIGHT) draw_marker(x, y, marker_color[markers[i].mtype], i); // draw_marker(x, y, config.trace_color[t], i); - } +// } } #endif // Draw trace and marker info on the top (50 system ticks for all screen calls) diff --git a/sa_core.c b/sa_core.c index d839429..f091dbe 100644 --- a/sa_core.c +++ b/sa_core.c @@ -372,22 +372,14 @@ void setupSA(void) PE4302_Write_Byte(0); } +static unsigned long old_freq[2] = { 0, 0 }; void setFreq(int V, unsigned long freq) { - if (V>=0) { - SI4432_Sel = V; -#ifdef USE_SI4463 - if (SI4432_Sel == 2) { - freq = freq - 433000000; - freq = freq / 10000; //convert to 10kHz channel starting with 433MHz - // Serial.print("Set frequency Si4463 = "); - // Serial.println(freq); - Si446x_RX ((uint8_t)freq); - } - else -#endif - SI4432_Set_Frequency(freq); + SI4432_Sel = V; + if (old_freq[V] != freq) { + SI4432_Set_Frequency(freq); + old_freq[V] = freq; } } @@ -586,10 +578,8 @@ float perform(bool break_on_operation, int i, int32_t f, int extraV) dirty = false; // } } -// if (i == 0 && ( scandirty || settingSpur) && local_IF) - if (local_IF && old_local_IF != local_IF) { + if (local_IF) { setFreq (0, local_IF); - old_local_IF = local_IF; } if (settingModulation == MO_AM) { int p = settingAttenuate * 2 + modulation_counter; @@ -615,8 +605,7 @@ float perform(bool break_on_operation, int i, int32_t f, int extraV) int lf = (uint32_t)(f + (int)(t * 500 * rbw)); if (extraV) setFreq (0, local_IF + lf - refferFreq[settingRefer]); // Offset so fundamental of reffer is visible - if (lf != old_lf) // only set on change - setFreq (1, local_IF + lf); + setFreq (1, local_IF + lf); old_lf = lf; if (MODE_OUTPUT(settingMode)) return(0); @@ -913,14 +902,14 @@ void draw_cal_status(void) // -------------------- Self testing ------------------------------------------------- enum { - TC_SIGNAL, TC_BELOW, TC_ABOVE, TC_FLAT, TC_MEASURE, TC_SET, + TC_SIGNAL, TC_BELOW, TC_ABOVE, TC_FLAT, TC_MEASURE, TC_SET, TC_END, }; enum { TP_SILENT, TPH_SILENT, TP_10MHZ, TP_10MHZEXTRA, TP_30MHZ, TPH_30MHZ }; -#define TEST_COUNT 13 +#define TEST_COUNT 14 static const struct { int kind; @@ -934,17 +923,18 @@ static const struct { {// Condition Preparation Center Span Pass Width Stop {TC_BELOW, TP_SILENT, 0.001, 0.0005, -10,0, 0}, // 1 Zero Hz leakage {TC_BELOW, TP_SILENT, 0.01, 0.01, -40, 0, 0}, // 2 Phase noise of zero Hz - {TC_MEASURE, TP_30MHZ, 30, 7, -25, 30, -85 }, // 3 Measure power level and noise - {TC_SET, TP_30MHZ, 30, 7, -25, 0, 0 }, // 4 Calibrate power low mode - {TC_MEASURE, TP_30MHZ, 270, 4, -50, 30, -85 }, // 5 Measure powerlevel and noise - {TC_SET, TPH_30MHZ, 270, 4, -50, 0, 0 }, // 6 Calibrate power high mode - {TC_SIGNAL, TP_10MHZ, 20, 7, -40, 30, -90 }, // 7 - {TC_SIGNAL, TP_10MHZ, 30, 7, -30, 30, -90 }, // 8 - {TC_BELOW, TP_SILENT, 200, 100, -75, 0, 0}, // 9 Wide band noise floor low mode - {TC_BELOW, TPH_SILENT, 600, 720, -75, 0, 0}, // 10 Wide band noise floor high mode - {TC_SIGNAL, TP_10MHZEXTRA, 10, 8, -20, 50, -70 }, // 11 BPF loss and stop band - {TC_FLAT, TP_10MHZEXTRA, 10, 4, -25, 20, -70}, // 12 BPF pass band flatness - {TC_BELOW, TP_30MHZ, 430, 60, -75, 0, -85}, // 13 LPF cutoff + {TC_SIGNAL, TP_10MHZ, 20, 7, -40, 30, -90 }, // 3 + {TC_SIGNAL, TP_10MHZ, 30, 7, -30, 30, -90 }, // 4 + {TC_BELOW, TP_SILENT, 200, 100, -75, 0, 0}, // 5 Wide band noise floor low mode + {TC_BELOW, TPH_SILENT, 600, 720, -75, 0, 0}, // 6 Wide band noise floor high mode + {TC_SIGNAL, TP_10MHZEXTRA, 10, 8, -20, 50, -70 }, // 7 BPF loss and stop band + {TC_FLAT, TP_10MHZEXTRA, 10, 4, -25, 20, -70}, // 8 BPF pass band flatness + {TC_BELOW, TP_30MHZ, 430, 60, -75, 0, -85}, // 9 LPF cutoff + {TC_END, 0, 0, 0, 0, 0, 0}, + {TC_MEASURE, TP_30MHZ, 30, 7, -25, 30, -85 }, // 11 Measure power level and noise + {TC_MEASURE, TP_30MHZ, 270, 4, -50, 30, -85 }, // 13 Measure powerlevel and noise + {TC_MEASURE, TPH_30MHZ, 270, 4, -50, 30, -85 }, // 14 Calibrate power high mode + {TC_END, 0, 0, 0, 0, 0, 0}, }; enum { @@ -992,13 +982,15 @@ void cell_draw_test_info(int x0, int y0) // char self_test_status_buf[35]; if (!show_test_info) return; - for (int i = -1; i < TEST_COUNT+1; i++) { + int i = -2; + do { + i++; int xpos = 25 - x0; int ypos = 40+i*INFO_SPACING - y0; unsigned int color = RGBHEX(0xFFFFFF); if (i == -1) { plot_printf(self_test_status_buf, sizeof self_test_status_buf, "Self test status:"); - } else if (i == TEST_COUNT) { + } else if (test_case[i].kind == TC_END) { if (test_wait) plot_printf(self_test_status_buf, sizeof self_test_status_buf, "Touch screen to continue"); else @@ -1016,7 +1008,7 @@ void cell_draw_test_info(int x0, int y0) } ili9341_set_foreground(color); cell_drawstring(self_test_status_buf, xpos, ypos); - } + } while (test_case[i].kind != TC_END); } #define fabs(X) ((X)<0?-(X):(X)) @@ -1076,9 +1068,10 @@ int validate_above(void) { } -void test_validate(int i) +int test_validate(int i) { // draw_all(TRUE); + int current_test_status = TS_PASS; switch (test_case[i].kind) { case TC_SET: if (test_case[i].pass == 0) { @@ -1091,34 +1084,34 @@ void test_validate(int i) case TC_SIGNAL: // Validate signal common: if (validate_peak_within(i, 5.0)) // Validate Peak - test_status[i] = TS_PASS; + current_test_status = TS_PASS; else if (validate_peak_within(i, 10.0)) - test_status[i] = TS_CRITICAL; + current_test_status = TS_CRITICAL; else - test_status[i] = TS_FAIL; - if (test_status[i] != TS_PASS) + current_test_status = TS_FAIL; + if (current_test_status != TS_PASS) test_fail_cause[i] = "Peak "; - if (test_status[i] == TS_PASS) { // Validate noise floor + if (current_test_status == TS_PASS) { // Validate noise floor for (int j = 0; j < POINTS_COUNT/2 - test_case[i].width; j++) { if (actual_t[j] > test_case[i].stop - 5) - test_status[i] = TS_CRITICAL; + current_test_status = TS_CRITICAL; else if (actual_t[j] > test_case[i].stop) { - test_status[i] = TS_FAIL; + current_test_status = TS_FAIL; break; } } for (int j = POINTS_COUNT/2 + test_case[i].width; j < POINTS_COUNT; j++) { if (actual_t[j] > test_case[i].stop - 5) - test_status[i] = TS_CRITICAL; + current_test_status = TS_CRITICAL; else if (actual_t[j] > test_case[i].stop) { - test_status[i] = TS_FAIL; + current_test_status = TS_FAIL; break; } } - if (test_status[i] != TS_PASS) + if (current_test_status != TS_PASS) test_fail_cause[i] = "Stopband "; } - if (test_status[i] == TS_PASS && test_case[i].kind == TC_MEASURE) + if (current_test_status == TS_PASS && test_case[i].kind == TC_MEASURE) test_value = peakLevel; else test_value = 0; // Not valid @@ -1126,23 +1119,23 @@ void test_validate(int i) case TC_ABOVE: // Validate signal above curve for (int j = 0; j < POINTS_COUNT; j++) { if (actual_t[j] < test_case[i].pass + 5) - test_status[i] = TS_CRITICAL; + current_test_status = TS_CRITICAL; else if (actual_t[j] < test_case[i].pass) { - test_status[i] = TS_FAIL; + current_test_status = TS_FAIL; break; } } - if (test_status[i] != TS_PASS) + if (current_test_status != TS_PASS) test_fail_cause[i] = "Above "; break; case TC_BELOW: // Validate signal below curve - test_status[i] = validate_below(); - if (test_status[i] != TS_PASS) + current_test_status = validate_below(); + if (current_test_status != TS_PASS) test_fail_cause[i] = "Above "; break; case TC_FLAT: // Validate passband flatness - test_status[i] = validate_flatness(i); - if (test_status[i] != TS_PASS) + current_test_status = validate_flatness(i); + if (current_test_status != TS_PASS) test_fail_cause[i] = "Passband "; break; @@ -1150,12 +1143,58 @@ void test_validate(int i) // Report status - if (test_status[i] != TS_PASS || i == TEST_COUNT - 1) + if (current_test_status != TS_PASS || test_case[i+1].kind == TC_END) test_wait = true; // draw_frequencies(); // draw_cal_status(); draw_all(TRUE); resume_sweep(); + return current_test_status; +} + +void test_prepare(int i) +{ + extraVFO = false; //Default test setup + switch(test_case[i].setup) { // Prepare test conditions + case TPH_SILENT: // No input signal + SetMode(M_HIGH); + goto common_silent; + case TP_SILENT: // No input signal + SetMode(M_LOW); +common_silent: + set_refer_output(-1); + for (int j = 0; j < POINTS_COUNT; j++) + stored_t[j] = test_case[i].pass; + break; + case TP_10MHZEXTRA: // Swept receiver + SetMode(M_LOW); + extraVFO = true; //Sweep BPF + set_refer_output(2); + goto common; + case TP_10MHZ: // 10MHz input + SetMode(M_LOW); + set_refer_output(2); + common: + + for (int j = 0; j < POINTS_COUNT/2 - test_case[i].width; j++) + stored_t[j] = test_case[i].stop; + for (int j = POINTS_COUNT/2 + test_case[i].width; j < POINTS_COUNT; j++) + stored_t[j] = test_case[i].stop; + for (int j = POINTS_COUNT/2 - test_case[i].width; j < POINTS_COUNT/2 + test_case[i].width; j++) + stored_t[j] = test_case[i].pass; + break; + case TP_30MHZ: + SetMode(M_LOW); + set_refer_output(0); + goto common; + case TPH_30MHZ: + SetMode(M_HIGH); + set_refer_output(0); + goto common; + } + trace[TRACE_STORED].enabled = true; + SetRefpos(test_case[i].pass+10); + draw_cal_status(); } extern void menu_autosettings_cb(int item); @@ -1166,58 +1205,22 @@ void self_test(void) in_selftest = true; menu_autosettings_cb(0); for (int i=0; i < TEST_COUNT; i++) { // All test cases waiting + if (test_case[i].kind == TC_END) + break; test_status[i] = TS_WAITING; test_fail_cause[i] = ""; } show_test_info = TRUE; - for (int i=0; i < TEST_COUNT; i++) { - extraVFO = false; //Default test setup - switch(test_case[i].setup) { // Prepare test conditions - case TPH_SILENT: // No input signal - SetMode(M_HIGH); - goto common_silent; - case TP_SILENT: // No input signal - SetMode(M_LOW); -common_silent: - set_refer_output(-1); - for (int j = 0; j < POINTS_COUNT; j++) - stored_t[j] = test_case[i].pass; - break; - case TP_10MHZEXTRA: // Swept receiver - SetMode(M_LOW); - extraVFO = true; //Sweep BPF - set_refer_output(2); - goto common; - case TP_10MHZ: // 10MHz input - SetMode(M_LOW); - set_refer_output(2); - common: - - for (int j = 0; j < POINTS_COUNT/2 - test_case[i].width; j++) - stored_t[j] = test_case[i].stop; - for (int j = POINTS_COUNT/2 + test_case[i].width; j < POINTS_COUNT; j++) - stored_t[j] = test_case[i].stop; - for (int j = POINTS_COUNT/2 - test_case[i].width; j < POINTS_COUNT/2 + test_case[i].width; j++) - stored_t[j] = test_case[i].pass; - break; - case TP_30MHZ: - SetMode(M_LOW); - set_refer_output(0); - goto common; - case TPH_30MHZ: - SetMode(M_HIGH); - set_refer_output(0); - goto common; - } - trace[TRACE_STORED].enabled = true; - SetRefpos(test_case[i].pass+10); - draw_cal_status(); + int i=0; + while (test_case[i].kind != TC_END) { + test_prepare(i); test_acquire(i); // Acquire test - test_validate(i); // Validate test - chThdSleepMilliseconds(2000); + test_status[i] = test_validate(i); // Validate test + chThdSleepMilliseconds(1000); if (test_status[i] != TS_PASS) { touch_wait_release(); } + i++; } touch_wait_release(); // chThdSleepMilliseconds(2000); @@ -1227,9 +1230,71 @@ common_silent: set_trace_refpos(1, NGRIDY - (-10) / get_trace_scale(0)); set_trace_refpos(2, NGRIDY - (-10) / get_trace_scale(0)); set_refer_output(0); - settingMode = M_LOW; + SetMode(M_LOW); + SetAverage(0); draw_cal_status(); + in_selftest = false; + menu_autosettings_cb(0); +} + +void reset_calibration(void) +{ + SetPowerLevel(100); +} +#define CALIBRATE_RBWS 5 +const int power_rbw [5] = { 100, 300, 30, 10, 3 }; + +void calibrate(void) +{ + int local_test_status; + float last_peak_level; + in_selftest = true; + SetPowerLevel(100); + menu_autosettings_cb(0); + int i = 10; // calibrate low mode power on 30 MHz; + for (int j= 0; j < CALIBRATE_RBWS; j++ ) { + SetRBW(power_rbw[j]); + test_prepare(i); + test_acquire(i); // Acquire test + local_test_status = test_validate(i); // Validate test + chThdSleepMilliseconds(1000); + if (local_test_status != TS_PASS) { + // touch_wait_release(); + } else + SetPowerLevel(-25); + } + i = 11; // Measure 270MHz in low mode + SetRBW(100); + test_prepare(i); + test_acquire(i); // Acquire test + last_peak_level = peakLevel; + local_test_status = test_validate(i); // Validate test + chThdSleepMilliseconds(1000); + + config.high_level_offset = -20; /// Preliminary setting + + i = 12; // Calibrate 270MHz in high mode + for (int j = 0; j < CALIBRATE_RBWS-1; j++) { + SetRBW(power_rbw[j]); + test_prepare(i); + test_acquire(i); // Acquire test + local_test_status = test_validate(i); // Validate test + chThdSleepMilliseconds(1000); + if (local_test_status != TS_PASS) { + touch_wait_release(); + } else + SetPowerLevel(last_peak_level); + } + touch_wait_release(); + trace[TRACE_STORED].enabled = false; + set_trace_refpos(0, NGRIDY - (-10) / get_trace_scale(0)); + set_trace_refpos(1, NGRIDY - (-10) / get_trace_scale(0)); + set_trace_refpos(2, NGRIDY - (-10) / get_trace_scale(0)); + set_refer_output(0); + SetMode(M_LOW); + SetAverage(0); + draw_cal_status(); in_selftest = false; menu_autosettings_cb(0); } diff --git a/si4432.c b/si4432.c index 96a45a5..cd42d04 100644 --- a/si4432.c +++ b/si4432.c @@ -133,7 +133,7 @@ void SI4432_Reset(void) int count = 0; // always perform a system reset (don't send 0x87) SI4432_Write_Byte( 0x07, 0x80); - chThdSleepMilliseconds(25); + chThdSleepMilliseconds(50); // wait for chiprdy bit while (count++ < 100 && ( SI4432_Read_Byte ( 0x04 ) & 0x02 ) == 0) { chThdSleepMilliseconds(10); @@ -146,11 +146,11 @@ void SI4432_Transmit(int d) SI4432_Write_Byte(0x6D, (byte) (0x1C+d)); if (( SI4432_Read_Byte ( 0x02 ) & 0x03 ) == 2) return; // Already in transmit mode - chThdSleepMilliseconds(20); + chThdSleepMilliseconds(10); SI4432_Write_Byte( 0x07, 0x0b); chThdSleepMilliseconds(20); while (count++ < 100 && ( SI4432_Read_Byte ( 0x02 ) & 0x03 ) != 2) { - chThdSleepMilliseconds(1); + chThdSleepMilliseconds(10); } } @@ -159,8 +159,9 @@ void SI4432_Receive(void) int count = 0; if (( SI4432_Read_Byte ( 0x02 ) & 0x03 ) == 1) return; // Already in receive mode - SI4432_Write_Byte( 0x07, 0x07); chThdSleepMilliseconds(10); + SI4432_Write_Byte( 0x07, 0x07); + chThdSleepMilliseconds(20); while (count++ < 100 && ( SI4432_Read_Byte ( 0x02 ) & 0x03 ) != 1) { chThdSleepMilliseconds(5); } diff --git a/ui_sa.c b/ui_sa.c index ec10d26..a985769 100644 --- a/ui_sa.c +++ b/ui_sa.c @@ -216,47 +216,63 @@ void menu_autosettings_cb(int item, uint8_t data) active_marker = 0; for (int i = 1; i Date: Sun, 29 Mar 2020 19:05:43 +0200 Subject: [PATCH 17/23] Updated stepdelay's --- sa_core.c | 33 ++++++++++++++++++++------------- si4432.c | 2 +- ui_sa.c | 6 +++--- 3 files changed, 24 insertions(+), 17 deletions(-) diff --git a/sa_core.c b/sa_core.c index f091dbe..d1fa976 100644 --- a/sa_core.c +++ b/sa_core.c @@ -470,8 +470,8 @@ void update_rbw(uint32_t delta_f) } //static int spur_old_stepdelay = 0; -static int spur_IF = 433900000; -static int spur_alternate_IF = 433700000; +static const int spur_IF = 433900000; +static const int spur_alternate_IF = 433700000; static const int spur_table[] = { 470000, @@ -545,14 +545,21 @@ float perform(bool break_on_operation, int i, int32_t f, int extraV) if (i == 0 && dirty) { if (settingStepDelay == 0){ - if (rbw < 10.0) - actualStepDelay = 2500; - else if (rbw <30.0) - actualStepDelay = 2000; - else if (rbw <100.0) - actualStepDelay = 1000; - else - actualStepDelay = 500; + if (MODE_LOW(settingMode)) { + if (rbw >300.0) actualStepDelay = 400; + else if (rbw >100.0) actualStepDelay = 500; + else if (rbw > 30.0) actualStepDelay = 900; + else if (rbw > 10.0) actualStepDelay = 900; + else if (rbw > 3.0) actualStepDelay = 1000; + else actualStepDelay = 1500; + } else { + if (rbw >300.0) actualStepDelay = 900; + else if (rbw >100.0) actualStepDelay = 900; + else if (rbw > 30.0) actualStepDelay = 900; + else if (rbw > 10.0) actualStepDelay = 1800; + else if (rbw > 3.0) actualStepDelay = 6000; + else actualStepDelay = 8000; + } } else actualStepDelay = settingStepDelay; @@ -766,9 +773,9 @@ void PeakSearch() } #endif -char *averageText[] = { "OFF", "MIN", "MAX", "2", "4", "8"}; -char *dBText[] = { "1dB/", "2dB/", "5dB/", "10dB/", "20dB/"}; -int refMHz[] = { 30, 15, 10, 4, 3, 2, 1 }; +const char *averageText[] = { "OFF", "MIN", "MAX", "2", "4", "8"}; +const char *dBText[] = { "1dB/", "2dB/", "5dB/", "10dB/", "20dB/"}; +const int refMHz[] = { 30, 15, 10, 4, 3, 2, 1 }; void draw_cal_status(void) { diff --git a/si4432.c b/si4432.c index cd42d04..89c0f3a 100644 --- a/si4432.c +++ b/si4432.c @@ -172,7 +172,7 @@ void SI4432_Receive(void) // User asks for an RBW of WISH, go through table finding the last triple // for which WISH is greater than the first entry, use those values, // Return the first entry of the following triple for the RBW actually achieved -static short RBW_choices[] = { // Each triple is: ndec, fils, WISH*10 +static const short RBW_choices[] = { // Each triple is: ndec, fils, WISH*10 0, 5,1,26, 5,2,28, 5,3,31, 5,4,32, 5,5,37, 5,6,42, 5,7, 45,4,1, 49,4,2, 54,4,3, 59,4,4, 61,4,5, 72,4,6, 82,4,7, 88,3,1, 95,3,2, 106,3,3, 115,3,4, 121,3,5, 142,3,6, 162,3,7, diff --git a/ui_sa.c b/ui_sa.c index a985769..52eccee 100644 --- a/ui_sa.c +++ b/ui_sa.c @@ -298,8 +298,8 @@ static void menu_modulation_cb(int item, uint8_t data) } -int menu_reffer_value[]={-1,0,1,2,3,4,5,6}; -char *menu_reffer_text[]={"OFF","30MHz","15MHz","10MHz","4MHz","3MHz","2MHz","1MHz"}; +const int menu_reffer_value[]={-1,0,1,2,3,4,5,6}; +const char *menu_reffer_text[]={"OFF","30MHz","15MHz","10MHz","4MHz","3MHz","2MHz","1MHz"}; static void menu_reffer_cb(int item, uint8_t data) { (void)data; @@ -384,7 +384,7 @@ static void menu_marker_type_cb(int item, uint8_t data) } -int rbwsel[]={0,3,10,30,100,300}; +const int rbwsel[]={0,3,10,30,100,300}; static void menu_rbw_cb(int item, uint8_t data) { From 6c74a28458fc561776cb690052ed1839f70b1421 Mon Sep 17 00:00:00 2001 From: erikkaashoek Date: Sun, 29 Mar 2020 19:27:56 +0200 Subject: [PATCH 18/23] Code cleaning --- main.c | 10 ++-- sa_core.c | 175 ++++++++++++++++++++---------------------------------- si4432.c | 57 ++++++++++++++++++ ui_sa.c | 8 +-- 4 files changed, 129 insertions(+), 121 deletions(-) diff --git a/main.c b/main.c index fb246a5..6133260 100644 --- a/main.c +++ b/main.c @@ -2256,11 +2256,11 @@ VNA_SHELL_FUNCTION(cmd_t) VNA_SHELL_FUNCTION(cmd_e) { (void)argc; - extraVFO = my_atoi(argv[0]); - if (extraVFO == -1) - extraVFO = false; + trackingVFO = my_atoi(argv[0]); + if (trackingVFO == -1) + trackingVFO = false; else - extraVFO = true; + trackingVFO = true; if (argc >1) frequencyExtra = my_atoi(argv[1]); @@ -2283,7 +2283,7 @@ VNA_SHELL_FUNCTION(cmd_m) chThdSleepMilliseconds(10); streamPut(shell_stream, '{'); for (int i = 0; i 600.0?600: (WISH<3.0?3:WISH));} -void SI4432_SetReference(int p) {} -void SI4432_Set_Frequency(long f) {} -void PE4302_Write_Byte(unsigned char DATA ) {} -void PE4302_init(void) {} -#endif - -#ifdef __SIMULATION__ -unsigned long seed = 123456789; -extern float rbw; -float myfrand(void) -{ - seed = (unsigned int) (1103515245 * seed + 12345) ; - return ((float) seed) / 1000000000.0; -} -#define NOISE ((myfrand()-2) * 2) // +/- 4 dBm noise -extern int settingAttenuate; - -//#define LEVEL(i, f, v) (v * (1-(fabs(f - frequencies[i])/rbw/1000))) - -float LEVEL(uint32_t i, uint32_t f, int v) -{ - float dv; - float df = fabs((float)f - (float)i); - if (df < rbw*1000) - dv = df/(rbw*1000); - else - dv = 1 + 50*(df - rbw*1000)/(rbw*1000); - return (v - dv - settingAttenuate); -} - -float Simulated_SI4432_RSSI(uint32_t i, int s) -{ - SI4432_Sel = s; - float v = -100 + log10(rbw)*10 + NOISE; - if(s == 0) { - v = fmax(LEVEL(i,10000000,-20),v); - v = fmax(LEVEL(i,20000000,-40),v); - v = fmax(LEVEL(i,30000000,-30),v); - v = fmax(LEVEL(i,40000000,-90),v); - } else { - v = fmax(LEVEL(i,320000000,-20),v); - v = fmax(LEVEL(i,340000000,-40),v); - v = fmax(LEVEL(i,360000000,-30),v); - v = fmax(LEVEL(i,380000000,-90),v); - } - return(v); -} +int settingMode = M_LOW; -#endif -//--------------------- Frequency control ----------------------- int dirty = true; int scandirty = true; - -//---------------- menu system ----------------------- - int settingAttenuate = 0; -// int settingGenerate = 0; -int settingBandwidth = 0; - -//int settingLevelOffset = 0; - -int settingRefer = -1; // Off by default -int refferFreq[] = {30000000, 15000000, 10000000, 4000000, 3000000, 2000000, 1000000}; -int settingSpur = 0; +int settingRBW = 0; int settingAverage = 0; int settingShowStorage = 0; int settingSubtractStorage = 0; -int settingMode = M_LOW; int settingDrive=0; // 0-3 , 3=+20dBm int settingAGC = true; int settingLNA = false; -int extraVFO = false; +int trackingVFO = false; int settingModulation = MO_NONE; int settingStepDelay = 0; -float rbw = 0; -float vbw = 0; -int in_selftest = false; +float actual_rbw = 0; +float setting_vbw = 0; +int settingSpur = 0; uint32_t minFreq = 0; uint32_t maxFreq = 520000000; +int settingRefer = -1; // Off by default +const int refferFreq[] = {30000000, 15000000, 10000000, 4000000, 3000000, 2000000, 1000000}; + +int in_selftest = false; + void set_refer_output(int v) { settingRefer = v; @@ -224,19 +165,19 @@ int level_is_calibrated(void) void SetRBW(int v) { - settingBandwidth = v; + settingRBW = v; update_rbw(frequencies[1] - frequencies[0]); dirty = true; } int GetRBW(void) { - return(settingBandwidth); + return(settingRBW); } int GetActualRBW(void) { - return((int) rbw); + return((int) actual_rbw); } void SetSpur(int v) { @@ -273,6 +214,17 @@ void ToggleLNA(void) dirty = true; } +void ToggleVFO(void) +{ + trackingVFO = !trackingVFO; + dirty = true; +} + +int GetExtraVFO(void) +{ + return(trackingVFO); +} + int GetLNA(void) { return(settingLNA); @@ -339,7 +291,7 @@ void SetMode(int m) set_sweep_frequency(ST_SPAN, 0); settingRefer = -1; // No refer output in output mode common_high: - extraVFO = false; // Not possible in high mode + trackingVFO = false; // Not possible in high mode settingSpur = 0; // Not possible in high mode break; } @@ -452,26 +404,26 @@ case M_GENHIGH: // Direct output from 1 void update_rbw(uint32_t delta_f) { - vbw = (delta_f)/1000.0; - rbw = settingBandwidth; -// float old_rbw = rbw; - if (rbw == 0) - rbw = 2*vbw; - if (rbw < 2.6) - rbw = 2.6; - if (rbw > 600) - rbw = 600; + setting_vbw = (delta_f)/1000.0; + actual_rbw = settingRBW; +// float old_rbw = actual_rbw; + if (actual_rbw == 0) + actual_rbw = 2*setting_vbw; + if (actual_rbw < 2.6) + actual_rbw = 2.6; + if (actual_rbw > 600) + actual_rbw = 600; SI4432_Sel = MODE_SELECT(settingMode); - rbw = SI4432_SET_RBW(rbw); - vbwSteps = ((int)(2 * vbw / rbw)); + actual_rbw = SI4432_SET_RBW(actual_rbw); + vbwSteps = ((int)(2 * setting_vbw / actual_rbw)); if (vbwSteps < 1) vbwSteps = 1; dirty = true; } //static int spur_old_stepdelay = 0; -static const int spur_IF = 433900000; -static const int spur_alternate_IF = 433700000; +static const unsigned int spur_IF = 433900000; +static const unsigned int spur_alternate_IF = 433700000; static const int spur_table[] = { 470000, @@ -507,18 +459,18 @@ static const int spur_table[] = int avoid_spur(int f) { - int window = ((int)rbw ) * 1000*2; + int window = ((int)actual_rbw ) * 1000*2; if (window < 50000) window = 50000; if (! settingMode == M_LOW) return false ; if (frequency_IF != spur_IF) return false; - if (rbw > 300.0) + if (actual_rbw > 300.0) return(false); // if (spur_old_stepdelay != 0 && actualStepDelay != spur_old_stepdelay) // restore stepdelay // actualStepDelay = spur_old_stepdelay; - for (int i = 0; i < (sizeof spur_table)/sizeof(int); i++) { + for (unsigned int i = 0; i < (sizeof spur_table)/sizeof(int); i++) { if (f/window == spur_table[i]/window) { // spur_old_stepdelay = actualStepDelay; // actualStepDelay += 4000; @@ -528,13 +480,11 @@ int avoid_spur(int f) return false; } -static int old_lf = -1; static int modulation_counter = 0; -static int old_local_IF = -1; float perform(bool break_on_operation, int i, int32_t f, int extraV) { -// long local_IF = (MODE_LOW(settingMode)?frequency_IF + (int)(rbw < 300.0?settingSpur * 1000 * rbw :0):0); +// long local_IF = (MODE_LOW(settingMode)?frequency_IF + (int)(actual_rbw < 300.0?settingSpur * 1000 * actual_rbw :0):0); long local_IF; if (MODE_HIGH(settingMode)) local_IF = 0; @@ -546,18 +496,18 @@ float perform(bool break_on_operation, int i, int32_t f, int extraV) if (i == 0 && dirty) { if (settingStepDelay == 0){ if (MODE_LOW(settingMode)) { - if (rbw >300.0) actualStepDelay = 400; - else if (rbw >100.0) actualStepDelay = 500; - else if (rbw > 30.0) actualStepDelay = 900; - else if (rbw > 10.0) actualStepDelay = 900; - else if (rbw > 3.0) actualStepDelay = 1000; + if (actual_rbw >300.0) actualStepDelay = 400; + else if (actual_rbw >100.0) actualStepDelay = 500; + else if (actual_rbw > 30.0) actualStepDelay = 900; + else if (actual_rbw > 10.0) actualStepDelay = 900; + else if (actual_rbw > 3.0) actualStepDelay = 1000; else actualStepDelay = 1500; } else { - if (rbw >300.0) actualStepDelay = 900; - else if (rbw >100.0) actualStepDelay = 900; - else if (rbw > 30.0) actualStepDelay = 900; - else if (rbw > 10.0) actualStepDelay = 1800; - else if (rbw > 3.0) actualStepDelay = 6000; + if (actual_rbw >300.0) actualStepDelay = 900; + else if (actual_rbw >100.0) actualStepDelay = 900; + else if (actual_rbw > 30.0) actualStepDelay = 900; + else if (actual_rbw > 10.0) actualStepDelay = 1800; + else if (actual_rbw > 3.0) actualStepDelay = 6000; else actualStepDelay = 8000; } } else @@ -605,15 +555,14 @@ float perform(bool break_on_operation, int i, int32_t f, int extraV) modulation_counter++; chThdSleepMicroseconds(250); } - volatile int subSteps = ((int)(2 * vbw / rbw)); + volatile int subSteps = ((int)(2 * setting_vbw / actual_rbw)); float RSSI = -150.0; int t = 0; do { - int lf = (uint32_t)(f + (int)(t * 500 * rbw)); + int lf = (uint32_t)(f + (int)(t * 500 * actual_rbw)); if (extraV) setFreq (0, local_IF + lf - refferFreq[settingRefer]); // Offset so fundamental of reffer is visible setFreq (1, local_IF + lf); - old_lf = lf; if (MODE_OUTPUT(settingMode)) return(0); float subRSSI = SI4432_RSSI(lf, MODE_SELECT(settingMode))+settingLevelOffset()+settingAttenuate; @@ -636,7 +585,7 @@ static bool sweep(bool break_on_operation) // spur_old_stepdelay = 0; again: for (int i = 0; i < sweep_points; i++) { - RSSI = perform(break_on_operation, i, frequencies[i], extraVFO); + RSSI = perform(break_on_operation, i, frequencies[i], trackingVFO); // back to toplevel to handle ui operation if (operation_requested && break_on_operation) return false; @@ -843,7 +792,7 @@ void draw_cal_status(void) ili9341_drawstring(buf, x, y); } - if (settingBandwidth) + if (settingRBW) color = BRIGHT_COLOR_GREEN; else color = DEFAULT_FG_COLOR; @@ -853,7 +802,7 @@ void draw_cal_status(void) ili9341_drawstring("RBW:", x, y); y += YSTEP; - plot_printf(buf, BLEN, "%dkHz", (int)rbw); + plot_printf(buf, BLEN, "%dkHz", (int)actual_rbw); buf[5]=0; ili9341_drawstring(buf, x, y); @@ -862,7 +811,7 @@ void draw_cal_status(void) ili9341_drawstring("VBW:", x, y); y += YSTEP; - plot_printf(buf, BLEN, "%dkHz",(int)vbw); + plot_printf(buf, BLEN, "%dkHz",(int)setting_vbw); buf[5]=0; ili9341_drawstring(buf, x, y); @@ -1161,7 +1110,7 @@ int test_validate(int i) void test_prepare(int i) { - extraVFO = false; //Default test setup + trackingVFO = false; //Default test setup switch(test_case[i].setup) { // Prepare test conditions case TPH_SILENT: // No input signal SetMode(M_HIGH); @@ -1175,7 +1124,7 @@ common_silent: break; case TP_10MHZEXTRA: // Swept receiver SetMode(M_LOW); - extraVFO = true; //Sweep BPF + trackingVFO = true; //Sweep BPF set_refer_output(2); goto common; case TP_10MHZ: // 10MHz input @@ -1305,3 +1254,5 @@ void calibrate(void) in_selftest = false; menu_autosettings_cb(0); } + + diff --git a/si4432.c b/si4432.c index 89c0f3a..284c267 100644 --- a/si4432.c +++ b/si4432.c @@ -368,3 +368,60 @@ void PE4302_Write_Byte(unsigned char DATA ) } #endif + + + +#if 0 +//-----------------SI4432 dummy------------------ +void SI4432_Write_Byte(unsigned char ADR, unsigned char DATA ) {} +unsigned char SI4432_Read_Byte(unsigned char ADR) {return ADR;} +float SI4432_SET_RBW(float WISH) {return (WISH > 600.0?600: (WISH<3.0?3:WISH));} +void SI4432_SetReference(int p) {} +void SI4432_Set_Frequency(long f) {} +void PE4302_Write_Byte(unsigned char DATA ) {} +void PE4302_init(void) {} +#endif + +#ifdef __SIMULATION__ +unsigned long seed = 123456789; +extern float actual_rbw; +float myfrand(void) +{ + seed = (unsigned int) (1103515245 * seed + 12345) ; + return ((float) seed) / 1000000000.0; +} +#define NOISE ((myfrand()-2) * 2) // +/- 4 dBm noise +extern int settingAttenuate; + +//#define LEVEL(i, f, v) (v * (1-(fabs(f - frequencies[i])/actual_rbw/1000))) + +float LEVEL(uint32_t i, uint32_t f, int v) +{ + float dv; + float df = fabs((float)f - (float)i); + if (df < actual_rbw*1000) + dv = df/(actual_rbw*1000); + else + dv = 1 + 50*(df - actual_rbw*1000)/(actual_rbw*1000); + return (v - dv - settingAttenuate); +} + +float Simulated_SI4432_RSSI(uint32_t i, int s) +{ + SI4432_Sel = s; + float v = -100 + log10(actual_rbw)*10 + NOISE; + if(s == 0) { + v = fmax(LEVEL(i,10000000,-20),v); + v = fmax(LEVEL(i,20000000,-40),v); + v = fmax(LEVEL(i,30000000,-30),v); + v = fmax(LEVEL(i,40000000,-90),v); + } else { + v = fmax(LEVEL(i,320000000,-20),v); + v = fmax(LEVEL(i,340000000,-40),v); + v = fmax(LEVEL(i,360000000,-30),v); + v = fmax(LEVEL(i,380000000,-90),v); + } + return(v); +} + +#endif diff --git a/ui_sa.c b/ui_sa.c index 52eccee..0658067 100644 --- a/ui_sa.c +++ b/ui_sa.c @@ -17,7 +17,7 @@ void SetRBW(int); void SetDrive(int d); void SetIF(int f); void SetStepDelay(int t); -extern int settingBandwidth; +extern int settingRBW; void SetSpur(int); int GetSpur(void); void SetAverage(int); @@ -38,7 +38,7 @@ void ToggleAGC(void); void redrawHisto(void); void self_test(void); extern int32_t frequencyExtra; -extern int extraVFO; +extern int trackingVFO; extern int settingDrive; extern int settingLNA; extern int settingAGC; @@ -523,7 +523,7 @@ static void menu_settings2_cb(int item, uint8_t data) ToggleLNA();; break; case 2: - extraVFO = !extraVFO; + ToggleVFO(); break; } draw_cal_status(); @@ -920,7 +920,7 @@ static void menu_item_modify_attribute( *bg = DEFAULT_MENU_TEXT_COLOR; *fg = config.menu_normal_color; } - if (item == 2 && extraVFO){ // should not happen in high mode + if (item == 2 && trackingVFO){ // should not happen in high mode *bg = DEFAULT_MENU_TEXT_COLOR; *fg = config.menu_normal_color; } From 393d5680506344dcd106f180fe598748fb1ec304 Mon Sep 17 00:00:00 2001 From: erikkaashoek Date: Sun, 29 Mar 2020 19:43:24 +0200 Subject: [PATCH 19/23] Update sa_core.c --- sa_core.c | 1 - 1 file changed, 1 deletion(-) diff --git a/sa_core.c b/sa_core.c index 7bd5413..33231c4 100644 --- a/sa_core.c +++ b/sa_core.c @@ -21,7 +21,6 @@ int settingStepDelay = 0; float actual_rbw = 0; float setting_vbw = 0; int settingSpur = 0; - uint32_t minFreq = 0; uint32_t maxFreq = 520000000; From dea4d02631183d956ee3eed4bd3111ad4886b83a Mon Sep 17 00:00:00 2001 From: erikkaashoek Date: Mon, 30 Mar 2020 12:27:16 +0200 Subject: [PATCH 20/23] Cleanup settings --- main.c | 18 +-- nanovna.h | 16 ++- plot.c | 2 +- sa_core.c | 423 +++++++++++++++++++++++++++--------------------------- si4432.c | 4 +- ui_sa.c | 44 +++--- 6 files changed, 255 insertions(+), 252 deletions(-) diff --git a/main.c b/main.c index 6133260..07821cb 100644 --- a/main.c +++ b/main.c @@ -998,7 +998,8 @@ set_frequencies(uint32_t start, uint32_t stop, uint16_t points) // disable at out of sweep range for (; i < POINTS_COUNT; i++) frequencies[i] = 0; - update_rbw(frequencies[1] - frequencies[0]); + setting_frequency_step = delta; + update_rbw(); } static void @@ -2229,7 +2230,7 @@ VNA_SHELL_FUNCTION(cmd_d) { (void) argc; int32_t a = my_atoi(argv[0]); - settingDrive = a; + setting_drive = a; } @@ -2256,11 +2257,11 @@ VNA_SHELL_FUNCTION(cmd_t) VNA_SHELL_FUNCTION(cmd_e) { (void)argc; - trackingVFO = my_atoi(argv[0]); - if (trackingVFO == -1) - trackingVFO = false; + setting_tracking = my_atoi(argv[0]); + if (setting_tracking == -1) + setting_tracking = false; else - trackingVFO = true; + setting_tracking = true; if (argc >1) frequencyExtra = my_atoi(argv[1]); @@ -2279,11 +2280,12 @@ VNA_SHELL_FUNCTION(cmd_m) pause_sweep(); int32_t f_step = (frequencyStop-frequencyStart)/ points; palClearPad(GPIOC, GPIOC_LED); // disable led and wait for voltage stabilization - update_rbw(f_step); + setting_frequency_step = f_step; + update_rbw(); chThdSleepMilliseconds(10); streamPut(shell_stream, '{'); for (int i = 0; i 31) a=31; - if (settingAttenuate == a) + if (setting_attenuate == a) return; - settingAttenuate = a; + setting_attenuate = a; dirty = true; } @@ -87,49 +131,50 @@ void SetStorage(void) { for (int i=0; i300.0) actualStepDelay = 400; + else if (actual_rbw >100.0) actualStepDelay = 500; + else if (actual_rbw > 30.0) actualStepDelay = 900; + else if (actual_rbw > 10.0) actualStepDelay = 900; + else if (actual_rbw > 3.0) actualStepDelay = 1000; + else actualStepDelay = 1500; + } else { + if (actual_rbw >300.0) actualStepDelay = 900; + else if (actual_rbw >100.0) actualStepDelay = 900; + else if (actual_rbw > 30.0) actualStepDelay = 900; + else if (actual_rbw > 10.0) actualStepDelay = 1800; + else if (actual_rbw > 3.0) actualStepDelay = 6000; + else actualStepDelay = 8000; + } + } else + actualStepDelay = setting_step_delay; + PE4302_Write_Byte(setting_attenuate * 2); + if (setting_modulation == MO_NFM ) { + SI4432_Sel = 1; + SI4432_Write_Byte(0x7A, 1); // Use frequency hopping channel width for FM modulation + } else if (setting_modulation == MO_WFM ) { + SI4432_Sel = 1; + SI4432_Write_Byte(0x7A, 10); // Use frequency hopping channel width for FM modulation + } else { + SI4432_Sel = 1; + SI4432_Write_Byte(0x79, 0); // IF no FM back to channel 0 + } + SetRX(setting_mode); + SI4432_SetReference(setting_refer); + update_rbw(); +} //------------------------------------------ @@ -311,11 +349,6 @@ int peakIndex; float temppeakLevel; int temppeakIndex; -#define BARSTART 24 - - -int vbwSteps = 1; - void setupSA(void) { SI4432_Init(); @@ -346,8 +379,8 @@ void SetSwitchReceive(void) { void SetAGCLNA(void) { unsigned char v = 0x40; - if (settingAGC) v |= 0x20; - if (settingLNA) v |= 0x10; + if (setting_agc) v |= 0x20; + if (setting_lna) v |= 0x10; SI4432_Write_Byte(0x69, v); } @@ -363,8 +396,8 @@ case M_LOW: // Mixed into 0 SI4432_Sel = 1; SetSwitchReceive(); // SI4432_Receive(); For noise testing only - SI4432_Transmit(settingDrive); - // SI4432_SetReference(settingRefer); + SI4432_Transmit(setting_drive); + // SI4432_SetReference(setting_refer); break; case M_HIGH: // Direct into 1 // SI4432_SetReference(-1); // Stop reference output @@ -381,11 +414,11 @@ case M_HIGH: // Direct into 1 case M_GENLOW: // Mixed output from 0 SI4432_Sel = 0; SetSwitchTransmit(); - SI4432_Transmit(settingDrive); + SI4432_Transmit(setting_drive); SI4432_Sel = 1; SetSwitchReceive(); - SI4432_Transmit(settingDrive); + SI4432_Transmit(setting_drive); break; case M_GENHIGH: // Direct output from 1 @@ -395,16 +428,16 @@ case M_GENHIGH: // Direct output from 1 SI4432_Sel = 1; SetSwitchTransmit(); - SI4432_Transmit(settingDrive); + SI4432_Transmit(setting_drive); break; } } -void update_rbw(uint32_t delta_f) +void update_rbw(void) { - setting_vbw = (delta_f)/1000.0; - actual_rbw = settingRBW; + setting_vbw = (setting_frequency_step)/1000.0; + actual_rbw = setting_rbw; // float old_rbw = actual_rbw; if (actual_rbw == 0) actual_rbw = 2*setting_vbw; @@ -412,9 +445,12 @@ void update_rbw(uint32_t delta_f) actual_rbw = 2.6; if (actual_rbw > 600) actual_rbw = 600; - SI4432_Sel = MODE_SELECT(settingMode); + + SI4432_Sel = MODE_SELECT(setting_mode); actual_rbw = SI4432_SET_RBW(actual_rbw); + vbwSteps = ((int)(2 * setting_vbw / actual_rbw)); + if (vbwSteps < 1) vbwSteps = 1; dirty = true; @@ -461,14 +497,8 @@ int avoid_spur(int f) int window = ((int)actual_rbw ) * 1000*2; if (window < 50000) window = 50000; - if (! settingMode == M_LOW) - return false ; - if (frequency_IF != spur_IF) - return false; - if (actual_rbw > 300.0) + if (! setting_mode == M_LOW || frequency_IF != spur_IF || actual_rbw > 300.0) return(false); -// if (spur_old_stepdelay != 0 && actualStepDelay != spur_old_stepdelay) // restore stepdelay -// actualStepDelay = spur_old_stepdelay; for (unsigned int i = 0; i < (sizeof spur_table)/sizeof(int); i++) { if (f/window == spur_table[i]/window) { // spur_old_stepdelay = actualStepDelay; @@ -481,11 +511,11 @@ int avoid_spur(int f) static int modulation_counter = 0; -float perform(bool break_on_operation, int i, int32_t f, int extraV) +float perform(bool break_on_operation, int i, int32_t f, int tracking) { -// long local_IF = (MODE_LOW(settingMode)?frequency_IF + (int)(actual_rbw < 300.0?settingSpur * 1000 * actual_rbw :0):0); +// long local_IF = (MODE_LOW(setting_mode)?frequency_IF + (int)(actual_rbw < 300.0?setting_spur * 1000 * actual_rbw :0):0); long local_IF; - if (MODE_HIGH(settingMode)) + if (MODE_HIGH(setting_mode)) local_IF = 0; else if (avoid_spur(f)) local_IF = spur_alternate_IF; @@ -493,59 +523,22 @@ float perform(bool break_on_operation, int i, int32_t f, int extraV) local_IF = frequency_IF; if (i == 0 && dirty) { - if (settingStepDelay == 0){ - if (MODE_LOW(settingMode)) { - if (actual_rbw >300.0) actualStepDelay = 400; - else if (actual_rbw >100.0) actualStepDelay = 500; - else if (actual_rbw > 30.0) actualStepDelay = 900; - else if (actual_rbw > 10.0) actualStepDelay = 900; - else if (actual_rbw > 3.0) actualStepDelay = 1000; - else actualStepDelay = 1500; - } else { - if (actual_rbw >300.0) actualStepDelay = 900; - else if (actual_rbw >100.0) actualStepDelay = 900; - else if (actual_rbw > 30.0) actualStepDelay = 900; - else if (actual_rbw > 10.0) actualStepDelay = 1800; - else if (actual_rbw > 3.0) actualStepDelay = 6000; - else actualStepDelay = 8000; - } - } else - actualStepDelay = settingStepDelay; - -// setupSA(); - - int p = settingAttenuate * 2; - PE4302_Write_Byte(p); - if (settingModulation == MO_NFM ) { - SI4432_Sel = 1; - SI4432_Write_Byte(0x7A, 1); // Use frequency hopping channel width for FM modulation - } else if (settingModulation == MO_WFM ) { - SI4432_Sel = 1; - SI4432_Write_Byte(0x7A, 10); // Use frequency hopping channel width for FM modulation - } else { - SI4432_Sel = 1; - SI4432_Write_Byte(0x79, 0); // IF no FM back to channel 0 - } - SetRX(settingMode); - SI4432_SetReference(settingRefer); - -// if (dirty) { - scandirty = true; - dirty = false; -// } + apply_settings(); + scandirty = true; + dirty = false; } if (local_IF) { setFreq (0, local_IF); } - if (settingModulation == MO_AM) { - int p = settingAttenuate * 2 + modulation_counter; + if (setting_modulation == MO_AM) { + int p = setting_attenuate * 2 + modulation_counter; PE4302_Write_Byte(p); if (modulation_counter == 3) modulation_counter = 0; else modulation_counter++; chThdSleepMicroseconds(250); - } else if (settingModulation == MO_NFM || settingModulation == MO_WFM ) { + } else if (setting_modulation == MO_NFM || setting_modulation == MO_WFM ) { SI4432_Sel = 1; SI4432_Write_Byte(0x79, modulation_counter); // Use frequency hopping channel for FM modulation if (modulation_counter == 3) @@ -554,23 +547,22 @@ float perform(bool break_on_operation, int i, int32_t f, int extraV) modulation_counter++; chThdSleepMicroseconds(250); } - volatile int subSteps = ((int)(2 * setting_vbw / actual_rbw)); float RSSI = -150.0; int t = 0; do { int lf = (uint32_t)(f + (int)(t * 500 * actual_rbw)); - if (extraV) - setFreq (0, local_IF + lf - refferFreq[settingRefer]); // Offset so fundamental of reffer is visible + if (tracking) + setFreq (0, local_IF + lf - reffer_freq[setting_refer]); // Offset so fundamental of reffer is visible setFreq (1, local_IF + lf); - if (MODE_OUTPUT(settingMode)) + if (MODE_OUTPUT(setting_mode)) return(0); - float subRSSI = SI4432_RSSI(lf, MODE_SELECT(settingMode))+settingLevelOffset()+settingAttenuate; + float subRSSI = SI4432_RSSI(lf, MODE_SELECT(setting_mode))+settingLevelOffset()+setting_attenuate; if (RSSI < subRSSI) RSSI = subRSSI; t++; - if ((operation_requested && break_on_operation ) || (MODE_OUTPUT(settingMode))) // output modes do not step. - subSteps = 0; // abort - } while (subSteps-- > 0); + if ((operation_requested && break_on_operation ) || (MODE_OUTPUT(setting_mode))) // output modes do not step. + break; // abort + } while (t < vbwSteps); return(RSSI); } @@ -582,28 +574,28 @@ static bool sweep(bool break_on_operation) temppeakLevel = -150; float temp_min_level = 100; // spur_old_stepdelay = 0; -again: +//again: for (int i = 0; i < sweep_points; i++) { - RSSI = perform(break_on_operation, i, frequencies[i], trackingVFO); + RSSI = perform(break_on_operation, i, frequencies[i], setting_tracking); // back to toplevel to handle ui operation if (operation_requested && break_on_operation) return false; - if (settingSpur == 1) { // First pass - temp_t[i] = RSSI; - continue; // Skip all other processing - } - if (settingSpur == -1) // Second pass - RSSI = ( RSSI < temp_t[i] ? RSSI : temp_t[i]); // Minimum of two passes +// if (setting_spur == 1) { // First pass +// temp_t[i] = RSSI; +// continue; // Skip all other processing +// } +// if (setting_spur == -1) // Second pass +// RSSI = ( RSSI < temp_t[i] ? RSSI : temp_t[i]); // Minimum of two passes temp_t[i] = RSSI; - if (settingSubtractStorage) { + if (setting_subtract_stored) { RSSI = RSSI - stored_t[i] ; } // stored_t[i] = (SI4432_Read_Byte(0x69) & 0x0f) * 3.0 - 90.0; // Display the AGC value in thestored trace - if (scandirty || settingAverage == AV_OFF) + if (scandirty || setting_average == AV_OFF) actual_t[i] = RSSI; else { - switch(settingAverage) { + switch(setting_average) { case AV_MIN: if (actual_t[i] > RSSI) actual_t[i] = RSSI; break; case AV_MAX: if (actual_t[i] < RSSI) actual_t[i] = RSSI; break; case AV_2: actual_t[i] = (actual_t[i] + RSSI) / 2.0; break; @@ -620,11 +612,11 @@ again: if (temp_min_level > actual_t[i]) temp_min_level = actual_t[i]; } - if (settingSpur == 1) { - settingSpur = -1; - goto again; - } else if (settingSpur == -1) - settingSpur = 1; +// if (setting_spur == 1) { +// setting_spur = -1; +// goto again; +// } else if (setting_spur == -1) +// setting_spur = 1; if (scandirty) { scandirty = false; @@ -708,7 +700,7 @@ void PeakSearch() peakIndex = temppeakIndex; peakLevel = actual_t[peakIndex]; peakFreq = frequencies[peakIndex]; - settingSpur = -settingSpur; + setting_spur = -setting_spur; int peak_marker = 0; markers[peak_marker].enabled = true; markers[peak_marker].index = peakIndex; @@ -738,7 +730,7 @@ void draw_cal_status(void) ili9341_fill(x, y, OFFSETX, HEIGHT, 0x0000); - if (MODE_OUTPUT(settingMode)) // No cal status during output + if (MODE_OUTPUT(setting_mode)) // No cal status during output return; if (current_menu_is_form() && !in_selftest) return; @@ -759,29 +751,29 @@ void draw_cal_status(void) plot_printf(buf, BLEN, "%ddB/",(int)get_trace_scale(0)); ili9341_drawstring(buf, x, y); - if (settingAttenuate) { + if (setting_attenuate) { ili9341_set_foreground(BRIGHT_COLOR_GREEN); y += YSTEP*2; ili9341_drawstring("Attn:", x, y); y += YSTEP; - plot_printf(buf, BLEN, "-%ddB", settingAttenuate); + plot_printf(buf, BLEN, "-%ddB", setting_attenuate); buf[5]=0; ili9341_drawstring(buf, x, y); } - if (settingAverage>0) { + if (setting_average>0) { ili9341_set_foreground(BRIGHT_COLOR_BLUE); y += YSTEP*2; ili9341_drawstring("Aver:", x, y); y += YSTEP; - plot_printf(buf, BLEN, "%s",averageText[settingAverage]); + plot_printf(buf, BLEN, "%s",averageText[setting_average]); buf[5]=0; ili9341_drawstring(buf, x, y); } - - if (settingSpur) { +#if 0 + if (setting_spur) { ili9341_set_foreground(BRIGHT_COLOR_BLUE); y += YSTEP*2; ili9341_drawstring("Spur:", x, y); @@ -790,8 +782,9 @@ void draw_cal_status(void) plot_printf(buf, BLEN, "ON"); ili9341_drawstring(buf, x, y); } +#endif - if (settingRBW) + if (setting_rbw) color = BRIGHT_COLOR_GREEN; else color = DEFAULT_FG_COLOR; @@ -821,7 +814,7 @@ void draw_cal_status(void) ili9341_drawstring("Scan:", x, y); y += YSTEP; - int32_t t = (int)((2* vbwSteps * sweep_points * ( actualStepDelay / 100) )) /10 * (settingSpur ? 2 : 1); // in mS + int32_t t = (int)((2* vbwSteps * sweep_points * ( actualStepDelay / 100) )) /10 /* * (setting_spur ? 2 : 1) */; // in mS if (t>1000) plot_printf(buf, BLEN, "%dS",(t+500)/1000); else @@ -831,13 +824,13 @@ void draw_cal_status(void) ili9341_drawstring(buf, x, y); - if (settingRefer >= 0) { + if (setting_refer >= 0) { ili9341_set_foreground(BRIGHT_COLOR_RED); y += YSTEP*2; ili9341_drawstring("Ref:", x, y); y += YSTEP; - plot_printf(buf, BLEN, "%dMHz",refMHz[settingRefer]); + plot_printf(buf, BLEN, "%dMHz",reffer_freq[setting_refer]/1000000); buf[5]=0; ili9341_drawstring(buf, x, y); } @@ -911,9 +904,9 @@ static void test_acquire(int i) pause_sweep(); #if 0 if (test_case[i].center < 300) - settingMode = M_LOW; + setting_mode = M_LOW; else - settingMode = M_HIGH; + setting_mode = M_HIGH; #endif set_sweep_frequency(ST_CENTER, (int32_t)(test_case[i].center * 1000000)); set_sweep_frequency(ST_SPAN, (int32_t)(test_case[i].span * 1000000)); @@ -1109,7 +1102,7 @@ int test_validate(int i) void test_prepare(int i) { - trackingVFO = false; //Default test setup + setting_tracking = false; //Default test setup switch(test_case[i].setup) { // Prepare test conditions case TPH_SILENT: // No input signal SetMode(M_HIGH); @@ -1123,7 +1116,7 @@ common_silent: break; case TP_10MHZEXTRA: // Swept receiver SetMode(M_LOW); - trackingVFO = true; //Sweep BPF + setting_tracking = true; //Sweep BPF set_refer_output(2); goto common; case TP_10MHZ: // 10MHz input diff --git a/si4432.c b/si4432.c index 284c267..0f56863 100644 --- a/si4432.c +++ b/si4432.c @@ -240,8 +240,8 @@ float SI4432_RSSI(uint32_t i, int s) SI4432_Sel = s; chThdSleepMicroseconds(actualStepDelay); RSSI_RAW = (unsigned char)SI4432_Read_Byte( 0x26 ) ; - if (settingMode < 2 && RSSI_RAW == 0) - SI4432_Init(); + // if (MODE_INPUT(setting_mode) && RSSI_RAW == 0) + // SI4432_Init(); float dBm = 0.5 * RSSI_RAW - 120.0 ; #ifdef __SIMULATION__ dBm = Simulated_SI4432_RSSI(i,s); diff --git a/ui_sa.c b/ui_sa.c index 0658067..e7b3c0d 100644 --- a/ui_sa.c +++ b/ui_sa.c @@ -17,12 +17,12 @@ void SetRBW(int); void SetDrive(int d); void SetIF(int f); void SetStepDelay(int t); -extern int settingRBW; +extern int setting_rbw; void SetSpur(int); int GetSpur(void); void SetAverage(int); int GetAverage(void); -extern int settingAverage; +extern int setting_average; void SetStorage(void); void SetClearStorage(void); void SetSubtractStorage(void); @@ -38,14 +38,14 @@ void ToggleAGC(void); void redrawHisto(void); void self_test(void); extern int32_t frequencyExtra; -extern int trackingVFO; -extern int settingDrive; -extern int settingLNA; -extern int settingAGC; +extern int setting_tracking; +extern int setting_drive; +extern int setting_lna; +extern int setting_agc; void SetModulation(int); -extern int settingModulation; +extern int setting_modulation; // extern int settingSpeed; -extern int settingStepDelay; +extern int setting_step_delay; @@ -324,6 +324,7 @@ static void menu_spur_cb(int item, uint8_t data) { (void)data; (void)item; +#if 0 if (GetSpur()) SetSpur(0); else @@ -331,6 +332,7 @@ static void menu_spur_cb(int item, uint8_t data) // menu_move_back(); ui_mode_normal(); draw_cal_status(); +#endif } static void menu_storage_cb(int item, uint8_t data) @@ -523,7 +525,7 @@ static void menu_settings2_cb(int item, uint8_t data) ToggleLNA();; break; case 2: - ToggleVFO(); + toggle_tracking(); break; } draw_cal_status(); @@ -860,7 +862,7 @@ static void menu_item_modify_attribute( } } else if (menu == menu_lowoutputmode || menu == menu_highoutputmode) { if (item == 3) { - plot_printf(uistat.text, sizeof uistat.text, menu_modulation_text[settingModulation]); + plot_printf(uistat.text, sizeof uistat.text, menu_modulation_text[setting_modulation]); } } else if (menu == menu_reffer) { if (item < 5 && item == get_refer_output() + 1){ @@ -878,10 +880,12 @@ static void menu_item_modify_attribute( *fg = config.menu_normal_color; } } else if (menu == menu_scale) { +#if 0 if (item == 4 /* Spur reduction */ && GetSpur()) { *bg = DEFAULT_MENU_TEXT_COLOR; *fg = config.menu_normal_color; } +#endif } else if (menu == menu_average) { if (item == GetAverage()){ *bg = DEFAULT_MENU_TEXT_COLOR; @@ -912,15 +916,15 @@ static void menu_item_modify_attribute( *fg = config.menu_normal_color; } } else if (menu == menu_settings2 || menu == menu_settingshigh2) { - if (item ==0 && settingAGC){ + if (item ==0 && setting_agc){ *bg = DEFAULT_MENU_TEXT_COLOR; *fg = config.menu_normal_color; } - if (item == 1 && settingLNA){ + if (item == 1 && setting_lna){ *bg = DEFAULT_MENU_TEXT_COLOR; *fg = config.menu_normal_color; } - if (item == 2 && trackingVFO){ // should not happen in high mode + if (item == 2 && setting_tracking){ // should not happen in high mode *bg = DEFAULT_MENU_TEXT_COLOR; *fg = config.menu_normal_color; } @@ -948,7 +952,7 @@ static void menu_item_modify_attribute( plot_printf(buf, sizeof buf, "%3.3fMHz", frequency0 / 1000000.0); break; case 1: - plot_printf(buf, sizeof buf, "%ddB", -10 - settingAttenuate); + plot_printf(buf, sizeof buf, "%ddB", -10 - setting_attenuate); break; } } @@ -959,7 +963,7 @@ static void menu_item_modify_attribute( plot_printf(buf, sizeof buf, "%3.3fMHz", frequency0 / 1000000.0); break; case 1: - plot_printf(buf, sizeof buf, "%ddB", -10 - settingDrive); + plot_printf(buf, sizeof buf, "%ddB", -10 - setting_drive); break; } } @@ -1003,7 +1007,7 @@ static void fetch_numeric_target(void) plot_printf(uistat.text, sizeof uistat.text, "%ddB", uistat.value / 1000); break; case KM_ATTENUATION: - uistat.value = settingAttenuate; + uistat.value = setting_attenuate; plot_printf(uistat.text, sizeof uistat.text, "%ddB", uistat.value); break; case KM_ACTUALPOWER: @@ -1015,20 +1019,20 @@ static void fetch_numeric_target(void) plot_printf(uistat.text, sizeof uistat.text, "%3.3fMHz", uistat.value / 1000000.0); break; case KM_SAMPLETIME: - uistat.value = settingStepDelay; + uistat.value = setting_step_delay; plot_printf(uistat.text, sizeof uistat.text, "%3duS", uistat.value); break; case KM_DRIVE: - uistat.value = settingDrive; + uistat.value = setting_drive; plot_printf(uistat.text, sizeof uistat.text, "%3ddB", uistat.value); break; case KM_LOWOUTLEVEL: - uistat.value = settingAttenuate; + uistat.value = setting_attenuate; uistat.value = -5 - uistat.value; // compensation for dB offset during low output mode plot_printf(uistat.text, sizeof uistat.text, "%ddB", uistat.value); break; case KM_HIGHOUTLEVEL: - uistat.value = settingDrive*5 + 5; + uistat.value = setting_drive*5 + 5; plot_printf(uistat.text, sizeof uistat.text, "%3ddB", uistat.value); break; } From 0d3152c984bf60cc01567fbe4af7e75e7060fb64 Mon Sep 17 00:00:00 2001 From: erikkaashoek Date: Mon, 30 Mar 2020 13:05:51 +0200 Subject: [PATCH 21/23] Show active mode --- sa_core.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/sa_core.c b/sa_core.c index 2370045..b279e35 100644 --- a/sa_core.c +++ b/sa_core.c @@ -835,6 +835,14 @@ void draw_cal_status(void) ili9341_drawstring(buf, x, y); } + ili9341_set_foreground(BRIGHT_COLOR_GREEN); + y += YSTEP*2; + if (MODE_LOW(setting_mode)) + ili9341_drawstring_7x13("M:L", x, y); + else + ili9341_drawstring_7x13("M:H", x, y); + + y = HEIGHT-7 + OFFSETY; plot_printf(buf, BLEN, "%ddB", (int)(yMax - get_trace_scale(0) * NGRIDY)); buf[5]=0; From 4b5e4dffdfe0d5f81b1b4de44022e4c9cf926569 Mon Sep 17 00:00:00 2001 From: erikkaashoek Date: Mon, 30 Mar 2020 15:11:32 +0200 Subject: [PATCH 22/23] Small speed improvements --- Makefile | 4 ++-- nanovna.h | 2 +- sa_core.c | 3 +++ si4432.c | 6 ++++-- ui_sa.c | 4 ++-- 5 files changed, 12 insertions(+), 7 deletions(-) diff --git a/Makefile b/Makefile index e16ea2e..341524d 100644 --- a/Makefile +++ b/Makefile @@ -5,8 +5,8 @@ # Compiler options here. ifeq ($(USE_OPT),) -# USE_OPT = -O2 -fno-inline-small-functions -ggdb -fomit-frame-pointer -falign-functions=16 --specs=nano.specs -fstack-usage - USE_OPT = -fno-inline-small-functions -ggdb -fomit-frame-pointer -falign-functions=16 --specs=nano.specs -fstack-usage + USE_OPT = -O2 -fno-inline-small-functions -ggdb -fomit-frame-pointer -falign-functions=16 --specs=nano.specs -fstack-usage +# USE_OPT = -fno-inline-small-functions -ggdb -fomit-frame-pointer -falign-functions=16 --specs=nano.specs -fstack-usage endif # C specific options here (added to USE_OPT). diff --git a/nanovna.h b/nanovna.h index 2c342fc..8dbdef0 100644 --- a/nanovna.h +++ b/nanovna.h @@ -610,7 +610,7 @@ void SI4432_SetReference(int freq); // Speed profile definition #define START_PROFILE systime_t time = chVTGetSystemTimeX(); -#define STOP_PROFILE {char string_buf[12];plot_printf(string_buf, sizeof string_buf, "T:%06d", chVTGetSystemTimeX() - time);ili9341_drawstringV(string_buf, 1, 60);} +#define STOP_PROFILE {char string_buf[12];plot_printf(string_buf, sizeof string_buf, "T:%06d", chVTGetSystemTimeX() - time);ili9341_drawstringV(string_buf, 1, 180);} // Macros for convert define value to string #define STR1(x) #x #define define_to_STR(x) STR1(x) diff --git a/sa_core.c b/sa_core.c index b279e35..a4720aa 100644 --- a/sa_core.c +++ b/sa_core.c @@ -577,6 +577,8 @@ static bool sweep(bool break_on_operation) //again: for (int i = 0; i < sweep_points; i++) { RSSI = perform(break_on_operation, i, frequencies[i], setting_tracking); + +//START_PROFILE // back to toplevel to handle ui operation if (operation_requested && break_on_operation) return false; @@ -611,6 +613,7 @@ static bool sweep(bool break_on_operation) } if (temp_min_level > actual_t[i]) temp_min_level = actual_t[i]; +//STOP_PROFILE } // if (setting_spur == 1) { // setting_spur = -1; diff --git a/si4432.c b/si4432.c index 0f56863..a9ae215 100644 --- a/si4432.c +++ b/si4432.c @@ -215,7 +215,7 @@ void SI4432_Set_Frequency ( long Freq ) { int N = Freq / 10000000; Carrier = ( 4 * ( Freq - N * 10000000 )) / 625; int Freq_Band = ( N - 24 ) | ( hbsel << 5 ) | ( sbsel << 6 ); -#if 1 +#if 0 SI4432_Write_Byte ( 0x75, Freq_Band ); SI4432_Write_Byte ( 0x76, (Carrier>>8) & 0xFF ); SI4432_Write_Byte ( 0x77, Carrier & 0xFF ); @@ -237,15 +237,17 @@ float SI4432_RSSI(uint32_t i, int s) RSSI_RAW = Si446x_getRSSI(); } else #endif +//START_PROFILE SI4432_Sel = s; chThdSleepMicroseconds(actualStepDelay); RSSI_RAW = (unsigned char)SI4432_Read_Byte( 0x26 ) ; // if (MODE_INPUT(setting_mode) && RSSI_RAW == 0) // SI4432_Init(); - float dBm = 0.5 * RSSI_RAW - 120.0 ; + float dBm = (RSSI_RAW-240)/2.0; #ifdef __SIMULATION__ dBm = Simulated_SI4432_RSSI(i,s); #endif +//STOP_PROFILE // Serial.println(dBm,2); return dBm ; } diff --git a/ui_sa.c b/ui_sa.c index e7b3c0d..d9d5eb6 100644 --- a/ui_sa.c +++ b/ui_sa.c @@ -187,7 +187,7 @@ static void menu_mode_cb(int item, uint8_t data) { (void)data; SetMode(item-1); - draw_cal_status(); +// draw_cal_status(); switch (item) { case 1: menu_push_submenu(menu_top); @@ -202,7 +202,7 @@ static void menu_mode_cb(int item, uint8_t data) menu_push_submenu(menu_highoutputmode); break; } - draw_cal_status(); +// draw_cal_status(); } extern int dirty; From f0f6004bac4378b8aa61dc0bc651f8e1a2e3adb5 Mon Sep 17 00:00:00 2001 From: erikkaashoek Date: Mon, 30 Mar 2020 16:38:57 +0200 Subject: [PATCH 23/23] Added MAX_DECAY average --- Makefile | 4 ++-- nanovna.h | 2 +- sa_core.c | 27 ++++++++++++++++++++------- ui_sa.c | 10 +++++----- 4 files changed, 28 insertions(+), 15 deletions(-) diff --git a/Makefile b/Makefile index 341524d..e16ea2e 100644 --- a/Makefile +++ b/Makefile @@ -5,8 +5,8 @@ # Compiler options here. ifeq ($(USE_OPT),) - USE_OPT = -O2 -fno-inline-small-functions -ggdb -fomit-frame-pointer -falign-functions=16 --specs=nano.specs -fstack-usage -# USE_OPT = -fno-inline-small-functions -ggdb -fomit-frame-pointer -falign-functions=16 --specs=nano.specs -fstack-usage +# USE_OPT = -O2 -fno-inline-small-functions -ggdb -fomit-frame-pointer -falign-functions=16 --specs=nano.specs -fstack-usage + USE_OPT = -fno-inline-small-functions -ggdb -fomit-frame-pointer -falign-functions=16 --specs=nano.specs -fstack-usage endif # C specific options here (added to USE_OPT). diff --git a/nanovna.h b/nanovna.h index 8dbdef0..fd0eefc 100644 --- a/nanovna.h +++ b/nanovna.h @@ -121,7 +121,7 @@ void load_default_properties(void); extern float perform(bool b, int i, int32_t f, int e); enum { - AV_OFF, AV_MIN, AV_MAX, AV_2, AV_4, AV_8 + AV_OFF, AV_MIN, AV_MAX_HOLD, AV_MAX_DECAY, AV_4, AV_16 }; enum { M_LOW, M_HIGH, M_GENLOW, M_GENHIGH, diff --git a/sa_core.c b/sa_core.c index a4720aa..646bf2e 100644 --- a/sa_core.c +++ b/sa_core.c @@ -511,6 +511,8 @@ int avoid_spur(int f) static int modulation_counter = 0; +char age[POINTS_COUNT]; + float perform(bool break_on_operation, int i, int32_t f, int tracking) { // long local_IF = (MODE_LOW(setting_mode)?frequency_IF + (int)(actual_rbw < 300.0?setting_spur * 1000 * actual_rbw :0):0); @@ -594,15 +596,26 @@ static bool sweep(bool break_on_operation) RSSI = RSSI - stored_t[i] ; } // stored_t[i] = (SI4432_Read_Byte(0x69) & 0x0f) * 3.0 - 90.0; // Display the AGC value in thestored trace - if (scandirty || setting_average == AV_OFF) + if (scandirty || setting_average == AV_OFF) { actual_t[i] = RSSI; - else { + age[i] = 0; + } else { switch(setting_average) { - case AV_MIN: if (actual_t[i] > RSSI) actual_t[i] = RSSI; break; - case AV_MAX: if (actual_t[i] < RSSI) actual_t[i] = RSSI; break; - case AV_2: actual_t[i] = (actual_t[i] + RSSI) / 2.0; break; - case AV_4: actual_t[i] = (actual_t[i]*3 + RSSI) / 4.0; break; - case AV_8: actual_t[i] = (actual_t[i]*7 + RSSI) / 8.0; break; + case AV_MIN: if (actual_t[i] > RSSI) actual_t[i] = RSSI; break; + case AV_MAX_HOLD: if (actual_t[i] < RSSI) actual_t[i] = RSSI; break; + case AV_MAX_DECAY: + if (actual_t[i] < RSSI) { + actual_t[i] = RSSI; + age[i] = 0; + } else { + if (age[i] > 20) + actual_t[i] -= 0.5; + else + age[i] += 1; + } + break; + case AV_4: actual_t[i] = (actual_t[i] + RSSI) / 4.0; break; + case AV_16: actual_t[i] = (actual_t[i]*3 + RSSI) / 16.0; break; } } if (frequencies[i] > 1000000) { diff --git a/ui_sa.c b/ui_sa.c index d9d5eb6..d997f30 100644 --- a/ui_sa.c +++ b/ui_sa.c @@ -593,12 +593,12 @@ const menuitem_t menu_highoutputmode[] = { }; static const menuitem_t menu_average[] = { - { MT_CALLBACK, 0, "OFF", menu_average_cb}, - { MT_CALLBACK, 0, "MIN", menu_average_cb}, - { MT_CALLBACK, 0, "MAX", menu_average_cb}, - { MT_CALLBACK, 0, " 2 ", menu_average_cb}, + { MT_CALLBACK, 0, " OFF", menu_average_cb}, + { MT_CALLBACK, 0, "\2 MIN\0 HOLD", menu_average_cb}, + { MT_CALLBACK, 0, "\2 MAX\0 HOLD", menu_average_cb}, + { MT_CALLBACK, 0, "\2 MAX\0 DECAY", menu_average_cb}, { MT_CALLBACK, 0, " 4 ", menu_average_cb}, - { MT_CALLBACK, 0, " 8 ", menu_average_cb}, + { MT_CALLBACK, 0, " 16 ", menu_average_cb}, { MT_CANCEL, 0, S_LARROW" BACK", NULL }, { MT_NONE, 0, NULL, NULL } // sentinel };