From 6aa31c51ea127d72bb9d16253f71314dcc355b3a Mon Sep 17 00:00:00 2001 From: erikkaashoek Date: Fri, 14 May 2021 13:30:36 +0200 Subject: [PATCH 1/9] Improved measurements --- plot.c | 18 ++++++++++--- sa_core.c | 75 ++++++++++++++++++++++++++++++++++++++++++++++--------- ui_sa.c | 10 +++++++- 3 files changed, 87 insertions(+), 16 deletions(-) diff --git a/plot.c b/plot.c index d9dfa8e..05844b4 100644 --- a/plot.c +++ b/plot.c @@ -1498,16 +1498,28 @@ static void cell_draw_marker_info(int x0, int y0) int xpos = 1 + (j%2)*(WIDTH/2) + CELLOFFSETX - x0; int ypos = 1 + (j/2)*(16) - y0; cell_printf(xpos, ypos, FONT_b"DEVIATION:%6.1QHz", dev); - } else if (setting.measurement == M_THD && markers[0].enabled && (markers[0].index << 5) > sweep_points ) { +#ifdef TINYSA4 +#define THD_SHIFT 7 +#else +#define THD_SHIFT 6 +#endif + } else if (setting.measurement == M_THD && markers[0].enabled && (markers[0].index << THD_SHIFT) > sweep_points ) { int old_unit = setting.unit; setting.unit = U_WATT; float p = marker_to_value(0); int h_i = 2; freq_t f = markers[0].frequency; float h = 0.0; + int h_count = 0; + int search_gate = 10; + if (markers[0].index < search_gate) + search_gate = markers[0].index * 2 / 3; while (f * h_i < frequencies[sweep_points-1]) { - if (search_maximum(1, f*h_i, 4*h_i) ) // use marker 1 for searching harmonics + if (search_maximum(1, f*h_i, search_gate) ) { // use marker 1 for searching harmonics + h_count++; + f = (f * 3 + markers[1].frequency / h_i) >> 2; h += marker_to_value(1); + } h_i++; } float thd = 100.0 * sa_sqrtf(h/p); @@ -1516,7 +1528,7 @@ static void cell_draw_marker_info(int x0, int y0) // j = 1; int xpos = 1 + (j%2)*(WIDTH/2) + CELLOFFSETX - x0; int ypos = 1 + (j/2)*(16) - y0; - cell_printf(xpos, ypos, FONT_b"THD: %4.1f%%", thd); + cell_printf(xpos, ypos, FONT_b"#%d THD: %4.1f%%", h_count, thd); break; } } else diff --git a/sa_core.c b/sa_core.c index 3f53df5..06da112 100644 --- a/sa_core.c +++ b/sa_core.c @@ -2105,18 +2105,24 @@ done: #endif } -#ifdef TINYSA4 -#define frequency_seatch_gate 60 // 120% of the RBW -#else -#define frequency_seatch_gate 100 // 200% of the RBW -#endif +//#ifdef TINYSA4 +//#define frequency_seatch_gate 60 // 120% of the RBW +//#else +//#define frequency_seatch_gate 100 // 200% of the RBW +//#endif int binary_search_frequency(freq_t f) // Search which index in the frequency tabled matches with frequency f using actual_rbw { int L = 0; - int R = (sizeof frequencies)/sizeof(int) - 1; - freq_t fmin = f - actual_rbw_x10 * frequency_seatch_gate; - freq_t fplus = f + actual_rbw_x10 * frequency_seatch_gate; + int frequency_seatch_gate = (frequencies[1] - frequencies[0]) >> 1; + if (f < frequencies[0]) + return -1; + if (f > frequencies[sweep_points-1]) + return -1; +// int R = (sizeof frequencies)/sizeof(int) - 1; + int R = sweep_points - 1; + freq_t fmin = f - frequency_seatch_gate; // actual_rbw_x10 * frequency_seatch_gate; + freq_t fplus = f + frequency_seatch_gate; // actual_rbw_x10 * frequency_seatch_gate; while (L <= R) { int m = (L + R) / 2; if (frequencies[m] < fmin) @@ -2129,6 +2135,37 @@ int binary_search_frequency(freq_t f) // Search which index in the frequenc return -1; } +int index_of_frequency(freq_t f) // Search which index in the frequency tabled matches with frequency f using actual_rbw +{ + freq_t f_step = frequencies[1] - frequencies[0]; + if (f_step == 0) + return 0; + if (f < frequencies[0]) + return -1; + if (f > frequencies[sweep_points-1]) + return -1; + int i = (f + (f_step >> 1))* sweep_points / (frequencies[sweep_points-1] - frequencies[0]); + return i; +#if 0 + // int R = (sizeof frequencies)/sizeof(int) - 1; + int L = 0; + int R = sweep_points - 1; + freq_t fmin = f - frequency_seatch_gate; // actual_rbw_x10 * frequency_seatch_gate; + freq_t fplus = f + frequency_seatch_gate; // actual_rbw_x10 * frequency_seatch_gate; + while (L <= R) { + int m = (L + R) / 2; + if (frequencies[m] < fmin) + L = m + 1; + else if (frequencies[m] > fplus) + R = m - 1; + else + return m; // index is m + } +#endif +} + + + void interpolate_maximum(int m) { const int idx = markers[m].index; @@ -2154,7 +2191,7 @@ void interpolate_maximum(int m) int search_maximum(int m, freq_t center, int span) { - int center_index = binary_search_frequency(center); + int center_index = index_of_frequency(center); if (center_index < 0) return false; int from = center_index - span/2; @@ -2212,6 +2249,15 @@ search_maximum(int m, freq_t center, int span) } } } + if (false && !found) { + temppeakIndex = from; + temppeakLevel = actual_t[from]; + for (int i = from+1; i <= to; i++) { + if (temppeakLevel 10) { // ----- IMD measurement - markers[1].enabled = search_maximum(1, frequencies[markers[0].index]*2, 8); - markers[2].enabled = search_maximum(2, frequencies[markers[0].index]*3, 12); - markers[3].enabled = search_maximum(3, frequencies[markers[0].index]*4, 16); +#ifdef TINYSA4 +#define H_SPACING 7 +#else +#define H_SPACING 4 +#endif + markers[1].enabled = search_maximum(1, frequencies[markers[0].index]*2, 2*H_SPACING); + markers[2].enabled = search_maximum(2, frequencies[markers[0].index]*3, 3*H_SPACING); + markers[3].enabled = search_maximum(3, frequencies[markers[0].index]*4, 4*H_SPACING); #ifdef TINYSA4 } else if (setting.measurement == M_AM && markers[0].index > 10) { // ----------AM measurement int l = markers[1].index; diff --git a/ui_sa.c b/ui_sa.c index 2a3496e..f5a9786 100644 --- a/ui_sa.c +++ b/ui_sa.c @@ -1156,7 +1156,13 @@ static UI_FUNCTION_ADV_CALLBACK(menu_measure_acb) kp_help_text = "Frequency of fundamental"; ui_mode_keypad(KM_CENTER); set_sweep_frequency(ST_START, 0); - set_sweep_frequency(ST_STOP, uistat.value*5); +#ifdef TINYSA4 +#define IMD_RANGE 10 +#else +#define IMD_RANGE 5 +#endif + set_sweep_frequency(ST_STOP, uistat.value*IMD_RANGE); + set_average(AV_4); // set_measurement(M_IMD); break; case M_OIP3: // OIP3 @@ -1175,6 +1181,7 @@ static UI_FUNCTION_ADV_CALLBACK(menu_measure_acb) int right = uistat.value; set_sweep_frequency(ST_CENTER, (left+right)/2); set_sweep_frequency(ST_SPAN, (right - left)*5); + set_average(AV_4); // set_measurement(M_OIP3); break; case M_PHASE_NOISE: // Phase noise @@ -1305,6 +1312,7 @@ static UI_FUNCTION_ADV_CALLBACK(menu_measure_acb) // set_measurement(M_FM); break; case M_THD: + set_average(AV_4); // set_measurement(M_THD); break; #ifdef __CHANNEL_POWER__ From e5110b4cba6c2ceb1ee12039b8d60d458f40eac9 Mon Sep 17 00:00:00 2001 From: DiSlord Date: Thu, 13 May 2021 20:35:08 +0300 Subject: [PATCH 2/9] Debug for SA4 --- main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.c b/main.c index 008b692..75c1cd8 100644 --- a/main.c +++ b/main.c @@ -2320,7 +2320,7 @@ void HardFault_Handler(void) void hard_fault_handler_c(uint32_t *sp) { -#ifndef TINYSA4 +#ifdef TINYSA4 uint32_t r0 = sp[0]; uint32_t r1 = sp[1]; uint32_t r2 = sp[2]; From 21a8798d2602ea27d3d046dc76a54ef8a22837b3 Mon Sep 17 00:00:00 2001 From: DiSlord Date: Thu, 13 May 2021 20:37:24 +0300 Subject: [PATCH 3/9] Add variable height buttons --- nanovna.h | 13 +- ui.c | 585 +++--------------------------------------------------- ui_sa.c | 15 +- 3 files changed, 52 insertions(+), 561 deletions(-) diff --git a/nanovna.h b/nanovna.h index a1b0728..48cfda2 100644 --- a/nanovna.h +++ b/nanovna.h @@ -517,12 +517,19 @@ extern uint16_t graph_bottom; // Menu Button // Maximum menu buttons count #ifdef TINYSA4 -#define MENU_BUTTON_MAX 9 +#define MENU_BUTTON_MAX 12 +#define MENU_BUTTON_HEIGHT (LCD_HEIGHT/ 9-1) +#define MENU_BUTTON_HEIGHT_10 (LCD_HEIGHT/10-1) +#define MENU_BUTTON_HEIGHT_11 (LCD_HEIGHT/11-1) +#define MENU_BUTTON_HEIGHT_12 (LCD_HEIGHT/12-1) #else -#define MENU_BUTTON_MAX 8 +#define MENU_BUTTON_MAX 12 +#define MENU_BUTTON_HEIGHT (LCD_HEIGHT/ 8-1) +#define MENU_BUTTON_HEIGHT_10 (LCD_HEIGHT/10-1) +#define MENU_BUTTON_HEIGHT_11 (LCD_HEIGHT/11-1) +#define MENU_BUTTON_HEIGHT_12 (LCD_HEIGHT/12-1) #endif #define MENU_BUTTON_WIDTH 80 -#define MENU_BUTTON_HEIGHT (LCD_HEIGHT/MENU_BUTTON_MAX-1) #define MENU_BUTTON_BORDER 1 #define KEYBOARD_BUTTON_BORDER 2 #define FORM_BUTTON_BORDER 2 diff --git a/ui.c b/ui.c index 07833dd..68a2e26 100644 --- a/ui.c +++ b/ui.c @@ -47,10 +47,10 @@ uistat_t uistat = { #define EVT_DOWN 0x20 #define EVT_REPEAT 0x40 -#define BUTTON_DOWN_LONG_TICKS 5000 /* 500ms */ -#define BUTTON_DOUBLE_TICKS 2500 /* 250ms */ -#define BUTTON_REPEAT_TICKS 400 /* 40ms */ -#define BUTTON_DEBOUNCE_TICKS 200 +#define BUTTON_DOWN_LONG_TICKS MS2ST(500) // 500ms +#define BUTTON_DOUBLE_TICKS MS2ST(250) // 250ms +#define BUTTON_REPEAT_TICKS MS2ST( 40) // 40ms +#define BUTTON_DEBOUNCE_TICKS MS2ST( 2) // 2ms /* lever switch assignment */ #define BIT_UP1 3 @@ -64,6 +64,7 @@ static uint16_t last_button = 0b0000; static uint32_t last_button_down_ticks; static uint32_t last_button_repeat_ticks; +static uint16_t menu_button_height = MENU_BUTTON_HEIGHT; volatile uint8_t operation_requested = OP_NONE; int8_t previous_marker = MARKER_INVALID; @@ -647,265 +648,6 @@ typedef void (*menuaction_cb_t)(int item, uint16_t data); typedef void (*menuaction_acb_t)(int item, uint16_t data, ui_button_t *b); #define UI_FUNCTION_ADV_CALLBACK(ui_function_name) void ui_function_name(int item, uint16_t data, ui_button_t *b) -#ifdef __VNA__ -static void -menu_calop_cb(int item, uint8_t data) -{ - cal_collect(data); - selection = item+1; - draw_cal_status(); - draw_menu(); -} - -static void -menu_caldone_cb(int item, uint8_t data) -{ - extern const menuitem_t menu_save[]; - //extern const menuitem_t menu_cal[]; - (void)item; - (void)data; - cal_done(); - draw_cal_status(); - menu_move_back(false); - menu_push_submenu(menu_save); -} - -static void -menu_cal2_cb(int item, uint8_t data) -{ - (void)data; - switch (item) { - case 2: // RESET - cal_status = 0; - break; - case 3: // CORRECTION - // toggle applying correction - cal_status ^= CALSTAT_APPLY; - break; - } - draw_menu(); - draw_cal_status(); - //menu_move_back(false); -} - -static void -menu_recall_cb(int item, uint8_t data) -{ - (void)item; - caldata_recall(data); - menu_move_back(false); - ui_mode_normal(); - update_grid(); - draw_cal_status(); -} - -static void -menu_config_cb(int item, uint8_t data) -{ - (void)data; - switch (item) { - case 0: - touch_cal_exec(); - break; - case 1: - touch_draw_test(); - break; - case 3: - show_version(); - break; - } - redraw_frame(); - request_to_redraw_grid(); - draw_menu(); -} - -static void -menu_config_save_cb(int item, uint8_t data) -{ - (void)item; - (void)data; - config_save(); - menu_move_back(false); - ui_mode_normal(); -} - -static void -menu_dfu_cb(int item, uint8_t data) -{ - (void)item; - (void)data; - enter_dfu(); -} - -static void -menu_save_cb(int item, uint8_t data) -{ - (void)item; - if (caldata_save(data) == 0) { - menu_move_back(false); - ui_mode_normal(); - draw_cal_status(); - } -} - -static void -choose_active_trace(void) -{ - int i; - if (trace[uistat.current_trace].enabled) - // do nothing - return; - for (i = 0; i < TRACES_MAX; i++) - if (trace[i].enabled) { - uistat.current_trace = i; - return; - } -} - -static void -menu_trace_cb(int item, uint8_t data) -{ - (void)item; - if (trace[data].enabled) { - if (data == uistat.current_trace) { - // disable if active trace is selected - trace[data].enabled = FALSE; - choose_active_trace(); - } else { - // make active selected trace - uistat.current_trace = data; - } - } else { - trace[data].enabled = TRUE; - uistat.current_trace = data; - } - request_to_redraw_grid(); - draw_menu(); -} - -static void -menu_format_cb(int item, uint8_t data) -{ - (void)item; - set_trace_type(uistat.current_trace, data); - request_to_redraw_grid(); - ui_mode_normal(); - //redraw_all(); -} - -static void -menu_channel_cb(int item, uint8_t data) -{ - (void)item; - set_trace_channel(uistat.current_trace, data); - menu_move_back(false); - ui_mode_normal(); -} - -static void -menu_transform_window_cb(int item, uint8_t data) -{ - (void)item; - // TODO - domain_mode = (domain_mode & ~TD_WINDOW) | data; - ui_mode_normal(); -} - -static void -menu_transform_cb(int item, uint8_t data) -{ - (void)item; - (void)data; - domain_mode ^= DOMAIN_TIME; - select_lever_mode(LM_MARKER); - draw_frequencies(); - ui_mode_normal(); -} - -static void -menu_velocity_cb(int item, uint8_t data) -{ - (void)item; - (void)data; - if (btn_wait_release() & EVT_BUTTON_DOWN_LONG) { - ui_mode_numeric(KM_VELOCITY_FACTOR); - ui_process_numeric(); - } else { - ui_mode_keypad(KM_VELOCITY_FACTOR); - } -} - -static void -menu_transform_filter_cb(int item, uint8_t data) -{ - (void)item; - domain_mode = (domain_mode & ~TD_FUNC) | data; - ui_mode_normal(); -} - -static void -menu_bandwidth_cb(int item) -{ - bandwidth = item; - draw_menu(); -} - -static void -choose_active_marker(void) -{ - int i; - for (i = 0; i < MARKERS_MAX; i++) - if (markers[i].enabled) { - active_marker = i; - return; - } - active_marker = -1; -} - -static void -menu_scale_cb(int item, uint8_t data) -{ - (void)item; -#ifdef __VNA__ - if (data == KM_SCALE && trace[uistat.current_trace].type == TRC_DELAY) { - data = KM_SCALEDELAY; - } -#endif - if (btn_wait_release() & EVT_BUTTON_DOWN_LONG) { - ui_mode_numeric(data); - ui_process_numeric(); - } else { - ui_mode_keypad(data); - } -} - -static void -menu_stimulus_cb(int item, uint8_t data) -{ - (void)data; - switch (item) { - case 0: /* START */ - case 1: /* STOP */ - case 2: /* CENTER */ - case 3: /* SPAN */ - case 4: /* CW */ - if (btn_wait_release() & EVT_BUTTON_DOWN_LONG) { - ui_mode_numeric(item); - ui_process_numeric(); - } else { - ui_mode_keypad(item); - } - break; - case 5: /* PAUSE */ - toggle_sweep(); - //menu_move_back(false); - //ui_mode_normal(); - draw_menu(); - break; - } -} -#endif - static freq_t get_marker_frequency(int marker) { @@ -1058,267 +800,6 @@ active_marker_select(int item) // used only to select an active marker from the } } } -#ifdef __VNA__ -static void -menu_marker_sel_cb(int item, uint8_t data) -{ - (void)data; -// int t; - if (item >= 0 && item < MARKERS_MAX) { - if (markers[item].enabled) { - if (item == active_marker) { - // disable if active trace is selected - markers[item].enabled = M_DISABLED; - active_marker_select(-1); - } else { - active_marker_select(item); - } - } else { - markers[item].enabled = M_ENABLED; - active_marker_select(item); - markers[item].mtype = M_NORMAL; - markers[item].mtype |= (uistat.marker_delta ? M_DELTA : 0); - markers[item].mtype |= (uistat.marker_noise ? M_NOISE : 0); - markers[item].mtype |= (uistat.marker_tracking ? M_TRACKING : 0); - } - // if (markers[item].enabled) - // menu_push_submenu(menu_marker_type); -#if 0 - } else if (item == 4) { /* all off */ - for (t = 0; t < MARKERS_MAX; t++) - markers[t].enabled = M_DISABLED; - previous_marker = -1; - active_marker = -1; -#endif - } else if (item == 4) { /* marker delta */ - uistat.marker_delta = !uistat.marker_delta; - } else if (item == 5) { /* marker noise */ - uistat.marker_noise = !uistat.marker_noise; - // if (uistat.marker_noise) uistat.marker_delta = true; //Default behavior - } else if (item == 6) { /* marker tracking */ - uistat.marker_tracking = !uistat.marker_tracking; - // if (uistat.marker_tracking) uistat.marker_noise = false; //Default behavior - } - redraw_marker(active_marker); - draw_menu(); -} - -static const menuitem_t menu_calop[] = { - { MT_CALLBACK, CAL_OPEN, "OPEN", menu_calop_cb }, - { MT_CALLBACK, CAL_SHORT, "SHORT", menu_calop_cb }, - { MT_CALLBACK, CAL_LOAD, "LOAD", menu_calop_cb }, - { MT_CALLBACK, CAL_ISOLN, "ISOLN", menu_calop_cb }, - { MT_CALLBACK, CAL_THRU, "THRU", menu_calop_cb }, - { MT_CALLBACK, 0, "DONE", menu_caldone_cb }, - { MT_CANCEL, 0, S_LARROW" BACK", NULL }, - { MT_NONE, 0, NULL, NULL } // sentinel -}; - -const menuitem_t menu_save[] = { - { MT_CALLBACK, 0, "SAVE 0", menu_save_cb }, - { MT_CALLBACK, 1, "SAVE 1", menu_save_cb }, - { MT_CALLBACK, 2, "SAVE 2", menu_save_cb }, - { MT_CALLBACK, 3, "SAVE 3", menu_save_cb }, - { MT_CALLBACK, 4, "SAVE 4", menu_save_cb }, - { MT_CANCEL, 0, S_LARROW" BACK", NULL }, - { MT_NONE, 0, NULL, NULL } // sentinel -}; - -const menuitem_t menu_cal[] = { - { MT_SUBMENU, 0, "CALIBRATE", menu_calop }, - { MT_SUBMENU, 0, "SAVE", menu_save }, - { MT_CALLBACK, 0, "RESET", menu_cal2_cb }, - { MT_CALLBACK, 0, "CORRECTION", menu_cal2_cb }, - { MT_CANCEL, 0, S_LARROW" BACK", NULL }, - { MT_NONE, 0, NULL, NULL } // sentinel -}; - -const menuitem_t menu_trace[] = { - { MT_CALLBACK, 0, "TRACE 0", menu_trace_cb }, - { MT_CALLBACK, 1, "TRACE 1", menu_trace_cb }, - { MT_CALLBACK, 2, "TRACE 2", menu_trace_cb }, - { MT_CALLBACK, 3, "TRACE 3", menu_trace_cb }, - { MT_CANCEL, 0, S_LARROW" BACK", NULL }, - { MT_NONE, 0, NULL, NULL } // sentinel -}; - -const menuitem_t menu_format2[] = { - { MT_CALLBACK, TRC_POLAR, "POLAR", menu_format_cb }, - { MT_CALLBACK, TRC_LINEAR, "LINEAR", menu_format_cb }, - { MT_CALLBACK, TRC_REAL, "REAL", menu_format_cb }, - { MT_CALLBACK, TRC_IMAG, "IMAG", menu_format_cb }, - { MT_CALLBACK, TRC_R, "RESISTANCE", menu_format_cb }, - { MT_CALLBACK, TRC_X, "REACTANCE", menu_format_cb }, - { MT_CANCEL, 0, S_LARROW" BACK", NULL }, - { MT_NONE, 0, NULL, NULL } // sentinel -}; - -const menuitem_t menu_format[] = { - { MT_CALLBACK, TRC_LOGMAG, "LOGMAG", menu_format_cb }, - { MT_CALLBACK, TRC_PHASE, "PHASE", menu_format_cb }, - { MT_CALLBACK, TRC_DELAY, "DELAY", menu_format_cb }, - { MT_CALLBACK, TRC_SMITH, "SMITH", menu_format_cb }, - { MT_CALLBACK, TRC_SWR, "SWR", menu_format_cb }, - { MT_SUBMENU, 0, S_RARROW" MORE", menu_format2 }, - //{ MT_CALLBACK, TRC_LINEAR, "LINEAR", menu_format_cb }, - //{ MT_CALLBACK, TRC_SWR, "SWR", menu_format_cb }, - { MT_CANCEL, 0, S_LARROW" BACK", NULL }, - { MT_NONE, 0, NULL, NULL } // sentinel -}; - -const menuitem_t menu_scale[] = { - { MT_CALLBACK, KM_SCALE, "SCALE/DIV", menu_scale_cb }, - { MT_CALLBACK, KM_REFPOS, "\2REFERENCE\0POSITION", menu_scale_cb }, - { MT_CALLBACK, KM_EDELAY, "\2ELECTRICAL\0DELAY", menu_scale_cb }, - { MT_CANCEL, 0, S_LARROW" BACK", NULL }, - { MT_NONE, 0, NULL, NULL } // sentinel -}; - -const menuitem_t menu_channel[] = { - { MT_CALLBACK, 0, "\2CH0\0REFLECT", menu_channel_cb }, - { MT_CALLBACK, 1, "\2CH1\0THROUGH", menu_channel_cb }, - { MT_CANCEL, 0, S_LARROW" BACK", NULL }, - { MT_NONE, 0, NULL, NULL } // sentinel -}; - -const menuitem_t menu_transform_window[] = { - { MT_CALLBACK, TD_WINDOW_MINIMUM, "MINIMUM", menu_transform_window_cb }, - { MT_CALLBACK, TD_WINDOW_NORMAL, "NORMAL", menu_transform_window_cb }, - { MT_CALLBACK, TD_WINDOW_MAXIMUM, "MAXIMUM", menu_transform_window_cb }, - { MT_CANCEL, 0, S_LARROW" BACK", NULL }, - { MT_NONE, 0, NULL, NULL } // sentinel -}; - -const menuitem_t menu_transform[] = { - { MT_CALLBACK, 0, "\2TRANSFORM\0ON", menu_transform_cb }, - { MT_CALLBACK, TD_FUNC_LOWPASS_IMPULSE, "\2LOW PASS\0IMPULSE", menu_transform_filter_cb }, - { MT_CALLBACK, TD_FUNC_LOWPASS_STEP, "\2LOW PASS\0STEP", menu_transform_filter_cb }, - { MT_CALLBACK, TD_FUNC_BANDPASS, "BANDPASS", menu_transform_filter_cb }, - { MT_SUBMENU, 0, "WINDOW", menu_transform_window }, - { MT_CALLBACK, 0, "\2VELOCITY\0FACTOR", menu_velocity_cb }, - { MT_CANCEL, 0, S_LARROW" BACK", NULL }, - { 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 -}; - -const menuitem_t menu_stimulus[] = { - { MT_CALLBACK, 0, "START", menu_stimulus_cb }, - { MT_CALLBACK, 0, "STOP", menu_stimulus_cb }, - { MT_CALLBACK, 0, "CENTER", menu_stimulus_cb }, - { MT_CALLBACK, 0, "SPAN", menu_stimulus_cb }, - { MT_CALLBACK, 0, "CW FREQ", menu_stimulus_cb }, - { MT_CALLBACK, 0, "\2PAUSE\0SWEEP", menu_stimulus_cb }, - { MT_CANCEL, 0, S_LARROW" BACK", NULL }, - { MT_NONE, 0, NULL, NULL } // sentinel -}; - -const menuitem_t menu_marker_sel[] = { - { MT_CALLBACK, 1, "MARKER 1", menu_marker_sel_cb }, - { MT_CALLBACK, 2, "MARKER 2", menu_marker_sel_cb }, - { MT_CALLBACK, 3, "MARKER 3", menu_marker_sel_cb }, - { MT_CALLBACK, 4, "MARKER 4", menu_marker_sel_cb }, - { MT_CALLBACK, 0, "ALL OFF", menu_marker_sel_cb }, - { MT_CALLBACK, 0, "DELTA", menu_marker_sel_cb }, - { MT_CANCEL, 0, S_LARROW" BACK", NULL }, - { MT_NONE, 0, NULL, NULL } // sentinel -}; - -const menuitem_t menu_marker_ops[] = { - { MT_CALLBACK, ST_START, S_RARROW"START", menu_marker_op_cb }, - { MT_CALLBACK, ST_STOP, S_RARROW"STOP", menu_marker_op_cb }, - { MT_CALLBACK, ST_CENTER, S_RARROW"CENTER", menu_marker_op_cb }, - { MT_CALLBACK, ST_SPAN, S_RARROW"SPAN", menu_marker_op_cb }, - { MT_CALLBACK, 0, S_RARROW"EDELAY", menu_marker_op_cb }, - { MT_CANCEL, 0, S_LARROW" BACK", NULL }, - { 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 -}; - -const menuitem_t menu_marker_smith[] = { - { MT_CALLBACK, MS_LIN, "LIN", menu_marker_smith_cb }, - { MT_CALLBACK, MS_LOG, "LOG", menu_marker_smith_cb }, - { MT_CALLBACK, MS_REIM,"Re+Im", menu_marker_smith_cb }, - { MT_CALLBACK, MS_RX, "R+Xj", menu_marker_smith_cb }, - { MT_CALLBACK, MS_RLC, "R+L/C", menu_marker_smith_cb }, - { MT_CANCEL, 0, S_LARROW" BACK", NULL }, - { MT_NONE, 0, NULL, NULL } // sentinel -}; - -const menuitem_t menu_marker[] = { - { MT_SUBMENU, 0, "\2SELECT\0MARKER", menu_marker_sel }, - { MT_SUBMENU, 0, "SEARCH", menu_marker_search }, - { MT_SUBMENU, 0, "OPERATIONS", menu_marker_ops }, - { MT_SUBMENU, 0, "\2SMITH\0VALUE", menu_marker_smith }, - { MT_CANCEL, 0, S_LARROW" BACK", NULL }, - { MT_NONE, 0, NULL, NULL } // sentinel -}; - -const menuitem_t menu_recall[] = { - { MT_CALLBACK, 0, "RECALL 0", menu_recall_cb }, - { MT_CALLBACK, 1, "RECALL 1", menu_recall_cb }, - { MT_CALLBACK, 2, "RECALL 2", menu_recall_cb }, - { MT_CALLBACK, 3, "RECALL 3", menu_recall_cb }, - { MT_CALLBACK, 4, "RECALL 4", menu_recall_cb }, - { MT_CANCEL, 0, S_LARROW" BACK", NULL }, - { MT_NONE, 0, NULL, NULL } // sentinel -}; - -const menuitem_t menu_dfu[] = { - { MT_CALLBACK, 0, "\2RESET AND\0ENTER DFU", menu_dfu_cb }, - { MT_CANCEL, 0, S_LARROW"CANCEL", NULL }, - { MT_NONE, 0, NULL, NULL } // sentinel -}; - -const menuitem_t menu_config[] = { - { MT_CALLBACK, 0, "TOUCH CAL", menu_config_cb }, - { MT_CALLBACK, 0, "TOUCH TEST", menu_config_cb }, - { MT_CALLBACK, 0, "SAVE", menu_config_save_cb }, - { MT_CALLBACK, 0, "VERSION", menu_config_cb }, - { MT_SUBMENU, 0, S_RARROW"DFU", menu_dfu }, - { MT_CANCEL, 0, S_LARROW" BACK", NULL }, - { MT_NONE, 0, NULL, NULL } // sentinel -}; - -const menuitem_t menu_top[] = { - { MT_SUBMENU, 0, "DISPLAY", menu_display }, - { MT_SUBMENU, 0, "MARKER", menu_marker }, - { MT_SUBMENU, 0, "STIMULUS", menu_stimulus }, - { MT_SUBMENU, 0, "CAL", menu_cal }, - { MT_SUBMENU, 0, "RECALL", menu_recall }, - { MT_SUBMENU, 0, "CONFIG", menu_config }, - { MT_NONE, 0, NULL, NULL } // sentinel -}; -#endif #include "ui_sa.c" @@ -1331,16 +812,15 @@ static void ensure_selection(void) { const menuitem_t *menu = menu_stack[menu_current_level]; - if (selection < 0) {selection = -1; return;} int i; - if (MT_MASK(menu[0].type) == MT_TITLE && selection == 0) { - selection = 1; - return; - } for (i = 0; MT_MASK(menu[i].type) != MT_NONE; i++) ; - if (selection >= i) - selection = i-1; + if (selection < 0) selection = -1; + if (selection >= i) selection = i-1; + if (MT_MASK(menu[0].type) == MT_TITLE && selection == 0) selection = 1; + + static const uint8_t button_h[] = {MENU_BUTTON_HEIGHT, MENU_BUTTON_HEIGHT_10, MENU_BUTTON_HEIGHT_11, MENU_BUTTON_HEIGHT_12}; + menu_button_height = button_h[menu[i].data&3]; } static void @@ -1870,13 +1350,13 @@ draw_menu_buttons(const menuitem_t *menu, int only) int y = 0; ui_button_t button; for (i = 0; i < MENU_BUTTON_MAX; i++) { - if (menuDisabled(menu[i].type)) //not applicable to mode - continue; if (MT_MASK(menu[i].type) == MT_NONE) break; + if (menuDisabled(menu[i].type)) //not applicable to mode + continue; #ifdef __SWEEP_RESTART__ if (only != -1 && only != i) { - y += MENU_BUTTON_HEIGHT; + y += menu_button_height; continue; } #else @@ -1923,11 +1403,11 @@ draw_menu_buttons(const menuitem_t *menu, int only) if (menu[i].type & MT_FORM) { int button_width = MENU_FORM_WIDTH; int button_start = (LCD_WIDTH - MENU_FORM_WIDTH)/2; // At center of screen - int button_height = MENU_BUTTON_HEIGHT; + int button_height = menu_button_height; draw_button(button_start, y, button_width, button_height, &button); uint16_t text_offs = button_start + 6; if (button.icon >=0){ - ili9341_blitBitmap(button_start+3, y+(MENU_BUTTON_HEIGHT-ICON_HEIGHT)/2, ICON_WIDTH, ICON_HEIGHT, &check_box[button.icon*2*ICON_HEIGHT]); + ili9341_blitBitmap(button_start+3, y+(button_height-ICON_HEIGHT)/2, ICON_WIDTH, ICON_HEIGHT, &check_box[button.icon*2*ICON_HEIGHT]); text_offs = button_start+6+ICON_WIDTH+1; } #ifdef __ICONS__ @@ -1973,11 +1453,11 @@ draw_menu_buttons(const menuitem_t *menu, int only) } else { int button_width = MENU_BUTTON_WIDTH; int button_start = LCD_WIDTH - MENU_BUTTON_WIDTH; - int button_height = MENU_BUTTON_HEIGHT; + int button_height = menu_button_height; draw_button(button_start, y, button_width, button_height, &button); uint16_t text_offs = button_start + 7; if (button.icon >=0){ - ili9341_blitBitmap(button_start+2, y+(MENU_BUTTON_HEIGHT-ICON_HEIGHT)/2, ICON_WIDTH, ICON_HEIGHT, &check_box[button.icon*2*ICON_HEIGHT]); + ili9341_blitBitmap(button_start+2, y+(button_height-ICON_HEIGHT)/2, ICON_WIDTH, ICON_HEIGHT, &check_box[button.icon*2*ICON_HEIGHT]); text_offs = button_start+2+ICON_WIDTH; } int lines = menu_is_multiline(button.text); @@ -1988,12 +1468,14 @@ draw_menu_buttons(const menuitem_t *menu, int only) ili9341_drawstring(button.text, text_offs, y+(button_height-linesFONT_GET_HEIGHT)/2); #endif } - y += MENU_BUTTON_HEIGHT; + y += menu_button_height; } // Cleanup other buttons (less flicker) - ili9341_set_background(LCD_BG_COLOR); - for (; y < MENU_BUTTON_MAX*MENU_BUTTON_HEIGHT; y+=MENU_BUTTON_HEIGHT) - ili9341_fill(LCD_WIDTH-MENU_BUTTON_WIDTH, y, MENU_BUTTON_WIDTH, MENU_BUTTON_HEIGHT); + // Erase empty buttons + if (AREA_HEIGHT_NORMAL + OFFSETY - y > 0){ + ili9341_set_background(LCD_BG_COLOR); + ili9341_fill(LCD_WIDTH-MENU_BUTTON_WIDTH, y, MENU_BUTTON_WIDTH, AREA_HEIGHT_NORMAL + OFFSETY - y); + } // if (menu[i].type & MT_FORM) // draw_battery_status(); } @@ -2221,15 +1703,14 @@ menu_apply_touch(int touch_x, int touch_y) int i; int y = 0; for (i = 0; i < MENU_BUTTON_MAX; i++) { + if (MT_MASK(menu[i].type) == MT_NONE) + break; if (menuDisabled(menu[i].type)) //not applicable to mode continue; if (MT_MASK(menu[i].type) == MT_TITLE) { - y += MENU_BUTTON_HEIGHT; + y += menu_button_height; continue; } - if (MT_MASK(menu[i].type) == MT_NONE) { - break; - } int active_button_start; if (menu[i].type & MT_FORM) { active_button_start = (LCD_WIDTH - MENU_FORM_WIDTH)/2; @@ -2238,13 +1719,13 @@ menu_apply_touch(int touch_x, int touch_y) active_button_start = LCD_WIDTH - MENU_BUTTON_WIDTH; // active_button_stop = LCD_WIDTH; } - if (y < touch_y && touch_y < y+MENU_BUTTON_HEIGHT) { + if (y < touch_y && touch_y < y+menu_button_height) { if (touch_x > active_button_start) { menu_select_touch(i, (( touch_x - active_button_start) * 5 ) / MENU_FORM_WIDTH); return; } } - y += MENU_BUTTON_HEIGHT; + y += menu_button_height; } if (menu_is_form(menu)) return; @@ -2282,9 +1763,9 @@ erase_menu_buttons(void) // Not need, screen redraw in all cases // ili9341_fill(area_width, 0, LCD_WIDTH - area_width, area_height, LCD_BG_COLOR); // if (current_menu_is_form()) - // ili9341_fill(OFFSETX, 0,LCD_WIDTH-OFFSETX, MENU_BUTTON_HEIGHT*MENU_BUTTON_MAX, LCD_BG_COLOR); + // ili9341_fill(OFFSETX, 0,LCD_WIDTH-OFFSETX, menu_button_height*MENU_BUTTON_MAX, LCD_BG_COLOR); // else - // ili9341_fill(LCD_WIDTH-MENU_BUTTON_WIDTH, 0, MENU_BUTTON_WIDTH, MENU_BUTTON_HEIGHT*MENU_BUTTON_MAX, LCD_BG_COLOR); + // ili9341_fill(LCD_WIDTH-MENU_BUTTON_WIDTH, 0, MENU_BUTTON_WIDTH, menu_button_height*MENU_BUTTON_MAX, LCD_BG_COLOR); draw_frequencies(); } @@ -2306,8 +1787,8 @@ leave_ui_mode() // } ili9341_set_background(LCD_BG_COLOR); // Erase bottom area (not redraw on area update) - if (MENU_BUTTON_HEIGHT*MENU_BUTTON_MAX - area_height > 0) - ili9341_fill(LCD_WIDTH-MENU_BUTTON_WIDTH, area_height, MENU_BUTTON_WIDTH, MENU_BUTTON_HEIGHT*MENU_BUTTON_MAX - area_height); +// if (menu_button_height*MENU_BUTTON_MAX - area_height > 0) +// ili9341_fill(LCD_WIDTH-MENU_BUTTON_WIDTH, area_height, MENU_BUTTON_WIDTH, menu_button_height*MENU_BUTTON_MAX - area_height); if (setting.waterfall) toggle_waterfall(); redraw_request|=REDRAW_AREA | REDRAW_FREQUENCY | REDRAW_CAL_STATUS | REDRAW_BATTERY; diff --git a/ui_sa.c b/ui_sa.c index f5a9786..cd3515a 100644 --- a/ui_sa.c +++ b/ui_sa.c @@ -1989,7 +1989,7 @@ static const menuitem_t menu_load_preset[] = { MT_ADV_CALLBACK, 3, "LOAD %d" , menu_load_preset_acb}, { MT_ADV_CALLBACK, 4, "LOAD %d" , menu_load_preset_acb}, { MT_SUBMENU, 0, "STORE" , menu_store_preset}, - { MT_CANCEL, 255, S_LARROW" BACK", NULL }, + { MT_CANCEL, 0, S_LARROW" BACK", NULL }, { MT_NONE, 0, NULL, NULL } // sentinel }; #ifdef TINYSA4 @@ -1999,8 +1999,8 @@ static const menuitem_t menu_mixer_drive[] = { { MT_ADV_CALLBACK, 2, "%+ddBm", menu_mixer_drive_acb}, { MT_ADV_CALLBACK, 1, "%+ddBm", menu_mixer_drive_acb}, { MT_ADV_CALLBACK, 0, "%+ddBm", menu_mixer_drive_acb}, - { MT_CANCEL, 255, S_LARROW" BACK", NULL }, - { MT_NONE, 0, NULL, NULL } // sentinel + { MT_CANCEL, 0, S_LARROW" BACK", NULL }, + { MT_NONE, 0, NULL, NULL } // sentinel }; #else static const menuitem_t menu_lo_drive[] = { @@ -2008,7 +2008,7 @@ static const menuitem_t menu_lo_drive[] = { { MT_ADV_CALLBACK, 14, "%+ddBm", menu_lo_drive_acb}, { MT_ADV_CALLBACK, 13, "%+ddBm", menu_lo_drive_acb}, { MT_ADV_CALLBACK, 12, "%+ddBm", menu_lo_drive_acb}, - { MT_CANCEL, 255, S_LARROW" BACK", NULL }, + { MT_CANCEL, 0, S_LARROW" BACK", NULL }, { MT_NONE, 0, NULL, NULL } // sentinel }; #endif @@ -2097,6 +2097,8 @@ static const menuitem_t menu_rbw[] = { { MT_ADV_CALLBACK, 6, "%sHz", menu_rbw_acb}, { MT_ADV_CALLBACK, 7, "%sHz", menu_rbw_acb}, { MT_ADV_CALLBACK, 8, "%sHz", menu_rbw_acb}, + { MT_CANCEL, 0, S_LARROW" BACK", NULL }, + { MT_NONE, MENU_BUTTON_HEIGHT_10, NULL, NULL } // sentinel #else { MT_ADV_CALLBACK, 1, "%4dkHz", menu_rbw_acb}, { MT_ADV_CALLBACK, 2, "%4dkHz", menu_rbw_acb}, @@ -2104,9 +2106,10 @@ static const menuitem_t menu_rbw[] = { { MT_ADV_CALLBACK, 4, "%4dkHz", menu_rbw_acb}, { MT_ADV_CALLBACK, 5, "%4dkHz", menu_rbw_acb}, { MT_ADV_CALLBACK, 6, "%4dkHz", menu_rbw_acb}, -#endif { MT_CANCEL, 0, S_LARROW" BACK", NULL }, - { MT_NONE, 0, NULL, NULL } // sentinel + { MT_NONE, 0, NULL, NULL } // sentinel +#endif + }; #ifdef __VBW__ From 401d0aab86e39143e2aa3a351ad245c58a1f5a7c Mon Sep 17 00:00:00 2001 From: DiSlord Date: Thu, 13 May 2021 21:08:33 +0300 Subject: [PATCH 4/9] Add button height auto adaptation --- nanovna.h | 16 ++++++---------- ui.c | 8 ++++---- ui_sa.c | 2 +- 3 files changed, 11 insertions(+), 15 deletions(-) diff --git a/nanovna.h b/nanovna.h index 48cfda2..9e291cd 100644 --- a/nanovna.h +++ b/nanovna.h @@ -517,23 +517,19 @@ extern uint16_t graph_bottom; // Menu Button // Maximum menu buttons count #ifdef TINYSA4 -#define MENU_BUTTON_MAX 12 -#define MENU_BUTTON_HEIGHT (LCD_HEIGHT/ 9-1) -#define MENU_BUTTON_HEIGHT_10 (LCD_HEIGHT/10-1) -#define MENU_BUTTON_HEIGHT_11 (LCD_HEIGHT/11-1) -#define MENU_BUTTON_HEIGHT_12 (LCD_HEIGHT/12-1) +#define MENU_BUTTON_MAX 16 +#define MENU_BUTTON_MIN 9 #else -#define MENU_BUTTON_MAX 12 -#define MENU_BUTTON_HEIGHT (LCD_HEIGHT/ 8-1) -#define MENU_BUTTON_HEIGHT_10 (LCD_HEIGHT/10-1) -#define MENU_BUTTON_HEIGHT_11 (LCD_HEIGHT/11-1) -#define MENU_BUTTON_HEIGHT_12 (LCD_HEIGHT/12-1) +#define MENU_BUTTON_MAX 16 +#define MENU_BUTTON_MIN 8 #endif #define MENU_BUTTON_WIDTH 80 #define MENU_BUTTON_BORDER 1 #define KEYBOARD_BUTTON_BORDER 2 #define FORM_BUTTON_BORDER 2 +#define MENU_BUTTON_HEIGHT_N(n) (LCD_HEIGHT/(n)-1) + // Define message box width #define MESSAGE_BOX_WIDTH 180 diff --git a/ui.c b/ui.c index 68a2e26..be043ba 100644 --- a/ui.c +++ b/ui.c @@ -64,7 +64,7 @@ static uint16_t last_button = 0b0000; static uint32_t last_button_down_ticks; static uint32_t last_button_repeat_ticks; -static uint16_t menu_button_height = MENU_BUTTON_HEIGHT; +static uint16_t menu_button_height = MENU_BUTTON_HEIGHT_N(MENU_BUTTON_MIN); volatile uint8_t operation_requested = OP_NONE; int8_t previous_marker = MARKER_INVALID; @@ -818,9 +818,9 @@ ensure_selection(void) if (selection < 0) selection = -1; if (selection >= i) selection = i-1; if (MT_MASK(menu[0].type) == MT_TITLE && selection == 0) selection = 1; - - static const uint8_t button_h[] = {MENU_BUTTON_HEIGHT, MENU_BUTTON_HEIGHT_10, MENU_BUTTON_HEIGHT_11, MENU_BUTTON_HEIGHT_12}; - menu_button_height = button_h[menu[i].data&3]; + if (i < MENU_BUTTON_MIN) i = MENU_BUTTON_MIN; + if (i >= MENU_BUTTON_MAX) i = MENU_BUTTON_MAX; + menu_button_height = MENU_BUTTON_HEIGHT_N(i); } static void diff --git a/ui_sa.c b/ui_sa.c index cd3515a..e99e26d 100644 --- a/ui_sa.c +++ b/ui_sa.c @@ -2098,7 +2098,7 @@ static const menuitem_t menu_rbw[] = { { MT_ADV_CALLBACK, 7, "%sHz", menu_rbw_acb}, { MT_ADV_CALLBACK, 8, "%sHz", menu_rbw_acb}, { MT_CANCEL, 0, S_LARROW" BACK", NULL }, - { MT_NONE, MENU_BUTTON_HEIGHT_10, NULL, NULL } // sentinel + { MT_NONE, 0, NULL, NULL } // sentinel #else { MT_ADV_CALLBACK, 1, "%4dkHz", menu_rbw_acb}, { MT_ADV_CALLBACK, 2, "%4dkHz", menu_rbw_acb}, From 5f07a2a355386c89e2bb5072189d2f1089f53137 Mon Sep 17 00:00:00 2001 From: DiSlord Date: Thu, 13 May 2021 21:43:16 +0300 Subject: [PATCH 5/9] Use macros for timing (now not depend from selected timer freq) --- ili9341.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/ili9341.c b/ili9341.c index 3602bcc..0c78c00 100644 --- a/ili9341.c +++ b/ili9341.c @@ -1264,7 +1264,7 @@ static inline uint8_t SD_ReadR1(uint32_t cnt) { return r1; } -// Wait SD ready token answer (wait time in systick, 10 systick = 1ms) +// Wait SD ready token answer (wait time in systick) static inline bool SD_WaitDataToken(uint8_t token, uint32_t wait_time) { uint8_t res; uint32_t time = chVTGetSystemTimeX(); @@ -1288,7 +1288,7 @@ static inline uint8_t SD_WaitDataAccept(uint32_t cnt) { return res&0x1F; } -// Wait no Busy answer from SD (wait time in systick, 10 systick = 1ms) +// Wait no Busy answer from SD (wait time in systick) static uint8_t SD_WaitNotBusy(uint32_t wait_time) { uint8_t res; uint32_t time = chVTGetSystemTimeX(); @@ -1308,7 +1308,7 @@ static uint8_t SD_WaitNotBusy(uint32_t wait_time) { // Receive data block from SD static bool SD_RxDataBlock(uint8_t *buff, uint16_t len, uint8_t token) { // loop until receive read response token or timeout ~50ms - if (!SD_WaitDataToken(token, 500)) { + if (!SD_WaitDataToken(token, MS2ST(50))) { DEBUG_PRINT(" rx SD_WaitDataToken err\r\n"); return FALSE; } @@ -1360,7 +1360,7 @@ static bool SD_TxDataBlock(const uint8_t *buff, uint8_t token) { } #if 0 // Wait busy (recommended timeout is 250ms (500ms for SDXC) set 250ms - resp = SD_WaitNotBusy(2500); + resp = SD_WaitNotBusy(MS2ST(250)); if (resp == 0xFF) return TRUE; #else @@ -1379,7 +1379,7 @@ static uint8_t SD_SendCmd(uint8_t cmd, uint32_t arg) { uint8_t buf[6]; uint8_t r1; // wait SD ready after last Tx (recommended timeout is 250ms (500ms for SDXC) set 250ms - if ((r1 = SD_WaitNotBusy(2500)) != 0xFF) { + if ((r1 = SD_WaitNotBusy(MS2ST(250))) != 0xFF) { DEBUG_PRINT(" SD_WaitNotBusy CMD%d err, %02x\r\n", cmd-0x40, (uint32_t)r1); return 0xFF; } @@ -1649,7 +1649,7 @@ DRESULT disk_ioctl(BYTE pdrv, BYTE cmd, void* buff) { // Nothing to do for this command if each write operation to the media is completed // within the disk_write function. case CTRL_SYNC: - if (SD_WaitNotBusy(2000) == 0xFF) res = RES_OK; + if (SD_WaitNotBusy(MS2ST(200)) == 0xFF) res = RES_OK; break; #if FF_USE_TRIM == 1 // Informs the device the data on the block of sectors is no longer needed and it can be erased. From 9faa54c36eec73f77a3a4394db0efa90b9402db9 Mon Sep 17 00:00:00 2001 From: DiSlord Date: Thu, 13 May 2021 22:17:49 +0300 Subject: [PATCH 6/9] Add more serial speed settings Use direct store serial speed Add usart_cfg command --- main.c | 16 ++++++++++++++-- nanovna.h | 14 +------------- ui_sa.c | 37 ++++++++++++++----------------------- 3 files changed, 29 insertions(+), 38 deletions(-) diff --git a/main.c b/main.c index 75c1cd8..a6cf428 100644 --- a/main.c +++ b/main.c @@ -866,7 +866,7 @@ config_t config = { .touch_cal = { 278, 513, 115, 154 }, // 4 inch panel #endif ._mode = _MODE_USB, - ._serial_speed = USART_SPEED_SETTING(SERIAL_DEFAULT_BITRATE), + ._serial_speed = SERIAL_DEFAULT_BITRATE, .lcd_palette = LCD_DEFAULT_PALETTE, #ifdef TINYSA4 #endif @@ -1617,6 +1617,17 @@ VNA_SHELL_FUNCTION(cmd_threads) #endif #ifdef ENABLE_USART_COMMAND +VNA_SHELL_FUNCTION(cmd_usart_cfg) +{ + if (argc != 1) goto result; + uint32_t speed = my_atoui(argv[0]); + if (speed < 300) speed = 300; + config._serial_speed = speed; + shell_update_speed(); +result: + shell_printf("Serial: %u baud\r\n", config._serial_speed); +} + VNA_SHELL_FUNCTION(cmd_usart) { uint32_t time = 2000; // 200ms wait answer by default @@ -1680,6 +1691,7 @@ static const VNAShellCommand commands[] = {"marker" , cmd_marker , 0}, #ifdef ENABLE_USART_COMMAND {"usart" , cmd_usart , CMD_WAIT_MUTEX}, + {"usart_cfg" , cmd_usart_cfg , CMD_WAIT_MUTEX}, #endif {"capture" , cmd_capture , CMD_WAIT_MUTEX}, #ifdef __REMOTE_DESKTOP__ @@ -1817,7 +1829,7 @@ static bool shell_check_connect(void){ // Update Serial connection speed and settings void shell_update_speed(void){ // Update Serial speed settings - SerialConfig s_config = {USART_GET_SPEED(config._serial_speed), 0, USART_CR2_STOP1_BITS, 0 }; + SerialConfig s_config = {config._serial_speed, 0, USART_CR2_STOP1_BITS, 0 }; sdStop(&SD1); sdStart(&SD1, &s_config); // USART config } diff --git a/nanovna.h b/nanovna.h index 9e291cd..3993157 100644 --- a/nanovna.h +++ b/nanovna.h @@ -722,22 +722,10 @@ extern int display_test(void); // // Shell config functions and macros // Serial connect definitions not used if Serial mode disabled -// Minimum speed - USART_SPEED_MULTIPLIER -// Maximum speed - USART_SPEED_MULTIPLIER * 256 -// Can be: 19200, 38400, 57600, 76800, 115200, 230400, 460800, 921600, 1843200, 3686400 -#define USART_SPEED_MULTIPLIER 19200 -#define USART_SPEED_SETTING(speed) ((speed)/USART_SPEED_MULTIPLIER - 1) -#define USART_GET_SPEED(idx) (((idx) + 1) * USART_SPEED_MULTIPLIER) void shell_update_speed(void); void shell_reset_console(void); int shell_serial_printf(const char *fmt, ...); - -#ifdef __VNA -void set_electrical_delay(float picoseconds); -float get_electrical_delay(void); -float groupdelay_from_array(int i, float array[POINTS_COUNT][2]); -#endif // marker enum { M_NORMAL=0,M_REFERENCE=1, M_DELTA=2, M_NOISE=4, M_STORED=8, M_TRACKING=16, M_DELETE=32 // Tracking must be last. @@ -1192,7 +1180,7 @@ typedef struct properties { //sizeof(properties_t) == 0x1200 -#define CONFIG_MAGIC 0x434f4e50 /* 'CONF' */ +#define CONFIG_MAGIC 0x434f4e51 /* 'CONF' */ extern int16_t lastsaveid; //extern properties_t *active_props; diff --git a/ui_sa.c b/ui_sa.c index e99e26d..cc9f1e4 100644 --- a/ui_sa.c +++ b/ui_sa.c @@ -1919,13 +1919,15 @@ static UI_FUNCTION_ADV_CALLBACK(menu_points_acb){ #ifdef __USE_SERIAL_CONSOLE__ static UI_FUNCTION_ADV_CALLBACK(menu_serial_speed_acb) { + static const uint32_t usart_speed[] = {19200, 38400, 57600, 115200, 230400, 460800, 921600, 1843200, 2000000, 3000000}; (void)item; + uint32_t speed = usart_speed[data]; if (b){ b->icon = config._serial_speed == data ? BUTTON_ICON_GROUP_CHECKED : BUTTON_ICON_GROUP; - b->param_1.u = USART_GET_SPEED(data); + b->param_1.u = speed; return; } - config._serial_speed = data; + config._serial_speed = speed; shell_update_speed(); } @@ -2554,28 +2556,17 @@ static const menuitem_t menu_calibrate[] = #endif #ifdef __USE_SERIAL_CONSOLE__ -//19200, 38400, 57600, 74800, 115200, 230400, 460800, 921600, 1843200, 3686400 -#if 0 -const menuitem_t menu_serial_speed2[] = { - { MT_ADV_CALLBACK, USART_SPEED_SETTING( 460800), "%u", menu_serial_speed_acb }, - { MT_ADV_CALLBACK, USART_SPEED_SETTING( 921600), "%u", menu_serial_speed_acb }, - { MT_ADV_CALLBACK, USART_SPEED_SETTING(1843200), "%u", menu_serial_speed_acb }, - { MT_ADV_CALLBACK, USART_SPEED_SETTING(3686400), "%u", menu_serial_speed_acb }, - { MT_CANCEL, 0, S_LARROW" BACK", NULL }, - { MT_NONE, 0, NULL, NULL } // sentinel -}; -#endif - const menuitem_t menu_serial_speed[] = { - { MT_ADV_CALLBACK, USART_SPEED_SETTING( 19200), "%u", menu_serial_speed_acb }, - { MT_ADV_CALLBACK, USART_SPEED_SETTING( 38400), "%u", menu_serial_speed_acb }, - { MT_ADV_CALLBACK, USART_SPEED_SETTING( 57600), "%u", menu_serial_speed_acb }, -// { MT_ADV_CALLBACK, USART_SPEED_SETTING( 76800), "%u", menu_serial_speed_acb }, - { MT_ADV_CALLBACK, USART_SPEED_SETTING(115200), "%u", menu_serial_speed_acb }, - { MT_ADV_CALLBACK, USART_SPEED_SETTING(230400), "%u", menu_serial_speed_acb }, -// { MT_SUBMENU, 0, S_RARROW" MORE", menu_serial_speed2 }, - { MT_ADV_CALLBACK, USART_SPEED_SETTING( 460800), "%u", menu_serial_speed_acb }, - { MT_ADV_CALLBACK, USART_SPEED_SETTING( 921600), "%u", menu_serial_speed_acb }, + { MT_ADV_CALLBACK, 0, "%u", menu_serial_speed_acb }, + { MT_ADV_CALLBACK, 1, "%u", menu_serial_speed_acb }, + { MT_ADV_CALLBACK, 2, "%u", menu_serial_speed_acb }, + { MT_ADV_CALLBACK, 3, "%u", menu_serial_speed_acb }, + { MT_ADV_CALLBACK, 4, "%u", menu_serial_speed_acb }, + { MT_ADV_CALLBACK, 5, "%u", menu_serial_speed_acb }, + { MT_ADV_CALLBACK, 6, "%u", menu_serial_speed_acb }, + { MT_ADV_CALLBACK, 7, "%u", menu_serial_speed_acb }, + { MT_ADV_CALLBACK, 8, "%u", menu_serial_speed_acb }, + { MT_ADV_CALLBACK, 9, "%u", menu_serial_speed_acb }, { MT_CANCEL, 0, S_LARROW" BACK", NULL }, { MT_NONE, 0, NULL, NULL } // sentinel }; From f255525528229495883719ff51fb4ab37f3d4314 Mon Sep 17 00:00:00 2001 From: DiSlord Date: Thu, 13 May 2021 22:22:33 +0300 Subject: [PATCH 7/9] fix typo --- ui_sa.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ui_sa.c b/ui_sa.c index cc9f1e4..3da5e21 100644 --- a/ui_sa.c +++ b/ui_sa.c @@ -1923,7 +1923,7 @@ static UI_FUNCTION_ADV_CALLBACK(menu_serial_speed_acb) (void)item; uint32_t speed = usart_speed[data]; if (b){ - b->icon = config._serial_speed == data ? BUTTON_ICON_GROUP_CHECKED : BUTTON_ICON_GROUP; + b->icon = config._serial_speed == speed ? BUTTON_ICON_GROUP_CHECKED : BUTTON_ICON_GROUP; b->param_1.u = speed; return; } From adf55acd72d49f94d0bf15d8b7fd9afa8355be54 Mon Sep 17 00:00:00 2001 From: DiSlord Date: Thu, 13 May 2021 22:30:51 +0300 Subject: [PATCH 8/9] align config to 4 bytes size --- nanovna.h | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/nanovna.h b/nanovna.h index 3993157..6e95f46 100644 --- a/nanovna.h +++ b/nanovna.h @@ -661,15 +661,13 @@ float marker_to_value(const int i); #define _MODE_SERIAL 0x04 #define _MODE_USB 0x00 +#pragma pack(push, 4) typedef struct config { int32_t magic; uint32_t deviceid; uint16_t lcd_palette[MAX_PALETTE]; int16_t touch_cal[4]; uint32_t _serial_speed; -#ifdef __VNA__ - freq_t harmonic_freq_threshold; -#endif uint16_t dac_value; uint16_t vbat_offset; float low_level_offset; @@ -711,6 +709,7 @@ typedef struct config { // uint8_t _reserved[22]; freq_t checksum; } config_t; +#pragma pack(pop) extern config_t config; //#define settingLevelOffset config.level_offset @@ -1180,7 +1179,7 @@ typedef struct properties { //sizeof(properties_t) == 0x1200 -#define CONFIG_MAGIC 0x434f4e51 /* 'CONF' */ +#define CONFIG_MAGIC 0x434f4e52 /* 'CONF' */ extern int16_t lastsaveid; //extern properties_t *active_props; From dd5ca921ea603eb609d6eb12c95c95652c345979 Mon Sep 17 00:00:00 2001 From: DiSlord Date: Fri, 14 May 2021 07:12:56 +0300 Subject: [PATCH 9/9] Fix erase button on waterfall --- ui.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ui.c b/ui.c index be043ba..83b02b9 100644 --- a/ui.c +++ b/ui.c @@ -1472,9 +1472,9 @@ draw_menu_buttons(const menuitem_t *menu, int only) } // Cleanup other buttons (less flicker) // Erase empty buttons - if (AREA_HEIGHT_NORMAL + OFFSETY - y > 0){ + if (NO_WATERFALL - y > 0){ ili9341_set_background(LCD_BG_COLOR); - ili9341_fill(LCD_WIDTH-MENU_BUTTON_WIDTH, y, MENU_BUTTON_WIDTH, AREA_HEIGHT_NORMAL + OFFSETY - y); + ili9341_fill(LCD_WIDTH-MENU_BUTTON_WIDTH, y, MENU_BUTTON_WIDTH, NO_WATERFALL - y); } // if (menu[i].type & MT_FORM) // draw_battery_status();