From 2a2fb32ab4e1154f15865932a18ef780bb307a40 Mon Sep 17 00:00:00 2001 From: DiSlord Date: Sun, 9 May 2021 01:47:32 +0300 Subject: [PATCH 01/24] Remove --- si4468.c | 13 +------------ 1 file changed, 1 insertion(+), 12 deletions(-) diff --git a/si4468.c b/si4468.c index 9664523..883e452 100644 --- a/si4468.c +++ b/si4468.c @@ -1175,19 +1175,8 @@ static char Si446x_readRSSI(void){ while (SPI_RX_IS_NOT_EMPTY(SI4432_SPI)) (void)SPI_READ_8BIT(SI4432_SPI); // Remove lingering bytes -#if 0 SI4463_WAIT_CTS; // Wait for CTS -#else - while (!SI4463_READ_CTS) { - if (sleep) { - __disable_irq(); -// CS_PE_HIGH; - __WFI(); -// CS_PE_LOW; - __enable_irq(); - } - } - #endif + SI_CS_LOW; SPI_WRITE_8BIT(SI4432_SPI, SI446X_CMD_READ_CMD_BUFF); // read answer while (SPI_IS_BUSY(SI4432_SPI)) ; // wait tx From c91c78d4ba5763ab2f9a281c431623decc899e5a Mon Sep 17 00:00:00 2001 From: DiSlord Date: Sun, 9 May 2021 10:20:50 +0300 Subject: [PATCH 02/24] Add option use or not string lib for fatFS --- FatFs/ff.c | 53 +++++++++++++++++++++++++++++++++++++++++++++++++- FatFs/ffconf.h | 6 ++++++ 2 files changed, 58 insertions(+), 1 deletion(-) diff --git a/FatFs/ff.c b/FatFs/ff.c index 3c98aa7..580a916 100644 --- a/FatFs/ff.c +++ b/FatFs/ff.c @@ -19,7 +19,6 @@ /----------------------------------------------------------------------------*/ -#include #include "ff.h" /* Declarations of FatFs API */ #include "diskio.h" /* Declarations of device I/O functions */ @@ -697,6 +696,58 @@ static void st_qword (BYTE* ptr, QWORD val) /* Store an 8-byte word in little-en /*-----------------------------------------------------------------------*/ /* String functions */ /*-----------------------------------------------------------------------*/ +#if FF_USE_STRINGLIB == 1 +#include +#else +// Redefine default tu use self string functions +#define memcpy mem_cpy +#define memset mem_set +#define memcmp mem_cmp +#define strchr chk_chr +/* Copy memory to memory */ +static void mem_cpy (void* dst, const void* src, UINT cnt) +{ + BYTE *d = (BYTE*)dst; + const BYTE *s = (const BYTE*)src; + + if (cnt != 0) { + do { + *d++ = *s++; + } while (--cnt); + } +} + +/* Fill memory block */ +static void mem_set (void* dst, int val, UINT cnt) +{ + BYTE *d = (BYTE*)dst; + + do { + *d++ = (BYTE)val; + } while (--cnt); +} + + +/* Compare memory block */ +static int mem_cmp (const void* dst, const void* src, UINT cnt) /* ZR:same, NZ:different */ +{ + const BYTE *d = (const BYTE *)dst, *s = (const BYTE *)src; + int r = 0; + + do { + r = *d++ - *s++; + } while (--cnt && r == 0); + + return r; +} + +/* Check if chr is contained in the string */ +static int chk_chr (const char* str, int chr) /* NZ:contained, ZR:not contained */ +{ + while (*str && *str != chr) str++; + return *str; +} +#endif /* Test if the byte is DBC 1st byte */ static int dbc_1st (BYTE c) diff --git a/FatFs/ffconf.h b/FatFs/ffconf.h index d1fc937..7c6accc 100644 --- a/FatFs/ffconf.h +++ b/FatFs/ffconf.h @@ -320,4 +320,10 @@ / PIC32 0 H8/300H 0 x86 0/1 */ +#define FF_USE_STRINGLIB 1 /* 0 or 1 */ +/* + * if 1 Use standard string.h for memcpy, memcmp, memset, strchr + * if 0 use own + */ + /*--- End of configuration options ---*/ From c0d5a36eb14eb230ef306fffa0cee87a24625ccc Mon Sep 17 00:00:00 2001 From: DiSlord Date: Tue, 11 May 2021 11:00:17 +0300 Subject: [PATCH 03/24] Add brightness support --- ili9341.c | 30 +++++++++++++++++++++++++++++- main.c | 8 ++++++++ nanovna.h | 8 +++++++- ui_sa.c | 37 ++++++++++++++++++++++++++++++++++++- 4 files changed, 80 insertions(+), 3 deletions(-) diff --git a/ili9341.c b/ili9341.c index 327dd47..3602bcc 100644 --- a/ili9341.c +++ b/ili9341.c @@ -501,9 +501,37 @@ static const uint8_t ili9341_init_seq[] = { #define LCD_INIT ili9341_init_seq #endif +#ifdef __LCD_BRIGHTNESS__ +#if HAL_USE_DAC == FALSE +#error "Need set HAL_USE_DAC in halconf.h for use __LCD_BRIGHTNESS__" +#endif + +static const DACConfig dac1cfg1 = { + init: 0, + datamode: DAC_DHRM_12BIT_RIGHT +}; + +static void lcd_initBrightness(void){ + dacStart(&DACD2, &dac1cfg1); +} + +#define BRIGHTNESS_MIN_LEVEL 0 +#define BRIGHTNESS_MAX_LEVEL 3300 +// Brightness control range 0 - 100 +void lcd_setBrightness(uint16_t b){ + b = BRIGHTNESS_MIN_LEVEL + b*((BRIGHTNESS_MAX_LEVEL-BRIGHTNESS_MIN_LEVEL)/100); + dacPutChannelX(&DACD2, 0, b); +} +#else +#define lcd_initBrightness() +#endif + void ili9341_init(void) { spi_init(); + // Init Brightness if LCD support + lcd_initBrightness(); + LCD_DC_DATA; LCD_RESET_ASSERT; chThdSleepMilliseconds(10); @@ -514,7 +542,7 @@ void ili9341_init(void) p += 2 + p[1]; chThdSleepMilliseconds(5); } -// ili9341_clear_screen(); + ili9341_clear_screen(); LCD_CS_HIGH; } diff --git a/main.c b/main.c index 4d83902..60adc52 100644 --- a/main.c +++ b/main.c @@ -885,6 +885,7 @@ config_t config = { .ext_zero_level = 128, #endif #ifdef TINYSA4 + ._brightness = DEFAULT_BRIGHTNESS, .vbat_offset = 220, .frequency_IF1 = DEFAULT_IF, .frequency_IF2 = 0, @@ -2265,6 +2266,13 @@ int main(void) // ui_mode_menu(); // Show menu when autostarting mode ui_mode_normal(); + /* + * Set LCD display brightness + */ + #ifdef __LCD_BRIGHTNESS__ + lcd_setBrightness(config._brightness); + #endif + chThdCreateStatic(waThread1, sizeof(waThread1), NORMALPRIO-1, Thread1, NULL); diff --git a/nanovna.h b/nanovna.h index 654a8db..9690599 100644 --- a/nanovna.h +++ b/nanovna.h @@ -80,6 +80,7 @@ #ifdef TINYSA4 #define __USE_RTC__ // Enable RTC clock #define __USE_SD_CARD__ // Enable SD card support +#define __LCD_BRIGHTNESS__ // LCD or hardware allow change brightness, add menu item for this #define __HARMONIC__ #define __VBW__ #define __SWEEP_RESTART__ @@ -695,6 +696,7 @@ typedef struct config { int8_t cor_am; int8_t cor_wfm; int8_t cor_nfm; + uint8_t _brightness; uint8_t high_out_adf4350; float sweep_voltage; float switch_offset; @@ -857,6 +859,9 @@ typedef uint16_t pixel_t; #define LCD_HEIGHT 240 #endif +// Default LCD brightness if display support it +#define DEFAULT_BRIGHTNESS 70 + #define LCD_BG_COLOR 0 #define LCD_FG_COLOR 1 #define LCD_GRID_COLOR 2 @@ -966,6 +971,7 @@ void ili9341_drawfont(uint8_t ch, int x, int y); void ili9341_read_memory(int x, int y, int w, int h, uint16_t* out); void ili9341_line(int x0, int y0, int x1, int y1); void show_version(void); +void lcd_setBrightness(uint16_t b); /* * flash.c @@ -1185,7 +1191,7 @@ typedef struct properties { //sizeof(properties_t) == 0x1200 -#define CONFIG_MAGIC 0x434f4e4f /* 'CONF' */ +#define CONFIG_MAGIC 0x434f4e50 /* 'CONF' */ extern int16_t lastsaveid; //extern properties_t *active_props; diff --git a/ui_sa.c b/ui_sa.c index 0a15f56..54f6bc2 100644 --- a/ui_sa.c +++ b/ui_sa.c @@ -1702,6 +1702,39 @@ static UI_FUNCTION_ADV_CALLBACK(menu_settings_bpf_acb){ toggle_tracking(); } +#ifdef __LCD_BRIGHTNESS__ +static UI_FUNCTION_CALLBACK(menu_brightness_cb) +{ + (void)item; + (void)data; + int16_t value = config._brightness; + ili9341_set_foreground(LCD_MENU_TEXT_COLOR); + ili9341_set_background(LCD_MENU_COLOR); + ili9341_fill(LCD_WIDTH/2-80, LCD_HEIGHT/2-20, 160, 40); + ili9341_drawstring_7x13("BRIGHTNESS", LCD_WIDTH/2-35, LCD_HEIGHT/2-13); + ili9341_drawstring_7x13(S_LARROW" USE LEVELER BUTTON "S_RARROW, LCD_WIDTH/2-72, LCD_HEIGHT/2+2); + while (TRUE) { + int status = btn_check(); + if (status & (EVT_UP|EVT_DOWN)) { + do { + if (status & EVT_UP ) value+=5; + if (status & EVT_DOWN) value-=5; + if (value < 0) value = 0; + if (value > 100) value = 100; + lcd_setBrightness(value); + status = btn_wait_release(); + } while (status != 0); + } + if (status == EVT_BUTTON_SINGLE_CLICK) + break; + } + config._brightness = (uint8_t)value; + lcd_setBrightness(value); + redraw_request|= REDRAW_AREA; + ui_mode_normal(); +} +#endif + static UI_FUNCTION_ADV_CALLBACK(menu_settings_pulse_acb){ (void)item; (void)data; @@ -2561,7 +2594,9 @@ static const menuitem_t menu_config[] = { #ifndef TINYSA4 { MT_SUBMENU, 0, S_RARROW" DFU", menu_dfu}, #endif - +#ifdef __LCD_BRIGHTNESS__ + { MT_CALLBACK, 0, "BRIGHTHESS", menu_brightness_cb}, +#endif { MT_CANCEL, 0, S_LARROW" BACK", NULL }, { MT_NONE, 0, NULL, NULL } // sentinel }; From 63ac7fd3c731e1b3dec0d038232e5b9ef3ab7241 Mon Sep 17 00:00:00 2001 From: DiSlord Date: Thu, 13 May 2021 20:35:08 +0300 Subject: [PATCH 04/24] Debug for SA4 --- main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.c b/main.c index ecd22da..9175389 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 cef1d75efcfca5713d8b9ac10058fcf7475bc269 Mon Sep 17 00:00:00 2001 From: DiSlord Date: Thu, 13 May 2021 20:37:24 +0300 Subject: [PATCH 05/24] 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 2a3496e..0d35eb6 100644 --- a/ui_sa.c +++ b/ui_sa.c @@ -1981,7 +1981,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 @@ -1991,8 +1991,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[] = { @@ -2000,7 +2000,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 @@ -2089,6 +2089,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}, @@ -2096,9 +2098,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 235eeb5e90ce9ad1de6269e99ce607dd76481892 Mon Sep 17 00:00:00 2001 From: DiSlord Date: Thu, 13 May 2021 21:08:33 +0300 Subject: [PATCH 06/24] 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 0d35eb6..ae85ce3 100644 --- a/ui_sa.c +++ b/ui_sa.c @@ -2090,7 +2090,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 090f5abf012f016dff4446c45c99900dccbadb2e Mon Sep 17 00:00:00 2001 From: DiSlord Date: Thu, 13 May 2021 21:43:16 +0300 Subject: [PATCH 07/24] 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 e6ebea1269d20e89706e36bdd7d224aac5937691 Mon Sep 17 00:00:00 2001 From: DiSlord Date: Thu, 13 May 2021 22:17:49 +0300 Subject: [PATCH 08/24] 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 ae85ce3..94d0d0c 100644 --- a/ui_sa.c +++ b/ui_sa.c @@ -1911,13 +1911,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(); } @@ -2546,28 +2548,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 fc2704652f0a15081700f79191a257a99c8e42a7 Mon Sep 17 00:00:00 2001 From: DiSlord Date: Thu, 13 May 2021 22:22:33 +0300 Subject: [PATCH 09/24] fix typo --- ui_sa.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ui_sa.c b/ui_sa.c index 94d0d0c..d889c44 100644 --- a/ui_sa.c +++ b/ui_sa.c @@ -1915,7 +1915,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 073430d76963bcbd8b18db883b90ccc91a21e318 Mon Sep 17 00:00:00 2001 From: DiSlord Date: Thu, 13 May 2021 22:30:51 +0300 Subject: [PATCH 10/24] 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 b79e6a0a468aeabf60ef8042667af1e1269ba0a4 Mon Sep 17 00:00:00 2001 From: DiSlord Date: Fri, 14 May 2021 07:12:56 +0300 Subject: [PATCH 11/24] 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(); From 0b86be360e48b7e8e892a76afe62a8f6e18c7d7f Mon Sep 17 00:00:00 2001 From: DiSlord Date: Sat, 15 May 2021 15:56:58 +0300 Subject: [PATCH 12/24] Update marker plate --- plot.c | 170 ++++++++++++++++++++++++++++++++------------------------- 1 file changed, 96 insertions(+), 74 deletions(-) diff --git a/plot.c b/plot.c index 9af3490..80ee7e1 100644 --- a/plot.c +++ b/plot.c @@ -631,8 +631,7 @@ static const uint8_t reference_bitmap[]={ #define X_MARKER_OFFSET 3 #define Y_MARKER_OFFSET 10 #define MARKER_BITMAP(i) (&marker_bitmap[(i)*MARKER_HEIGHT]) -static const uint8_t marker_bitmap[]= -{ +static const uint8_t marker_bitmap[]={ // Marker Back plate _BMP8(0b11111110), _BMP8(0b11111110), @@ -655,6 +654,7 @@ static const uint8_t marker_bitmap[]= _BMP8(0b00000000), _BMP8(0b00000000), _BMP8(0b00000000), +#if MARKERS_MAX >=2 // Marker 2 _BMP8(0b00000000), _BMP8(0b00111000), @@ -666,6 +666,8 @@ static const uint8_t marker_bitmap[]= _BMP8(0b00000000), _BMP8(0b00000000), _BMP8(0b00000000), +#endif +#if MARKERS_MAX >=3 // Marker 3 _BMP8(0b00000000), _BMP8(0b00111000), @@ -677,6 +679,8 @@ static const uint8_t marker_bitmap[]= _BMP8(0b00000000), _BMP8(0b00000000), _BMP8(0b00000000), +#endif +#if MARKERS_MAX >=4 // Marker 4 _BMP8(0b00000000), _BMP8(0b00001000), @@ -688,63 +692,69 @@ static const uint8_t marker_bitmap[]= _BMP8(0b00001000), _BMP8(0b00000000), _BMP8(0b00000000), -#if MARKER_COUNT > 4 +#endif +#if MARKERS_MAX >=5 // Marker 5 _BMP8(0b00000000), - _BMP8(0b11110000), - _BMP8(0b10000000), - _BMP8(0b11100000), - _BMP8(0b00010000), - _BMP8(0b00010000), - _BMP8(0b10010000), - _BMP8(0b01100000), + _BMP8(0b01111100), + _BMP8(0b01000000), + _BMP8(0b01111000), + _BMP8(0b00000100), + _BMP8(0b01000100), + _BMP8(0b00111000), + _BMP8(0b00000000), _BMP8(0b00000000), _BMP8(0b00000000), +#endif +#if MARKERS_MAX >=6 // Marker 6 _BMP8(0b00000000), - _BMP8(0b01100000), - _BMP8(0b10010000), - _BMP8(0b10000000), - _BMP8(0b11100000), - _BMP8(0b10010000), - _BMP8(0b10010000), - _BMP8(0b01100000), + _BMP8(0b00111100), + _BMP8(0b01000000), + _BMP8(0b01111000), + _BMP8(0b01000100), + _BMP8(0b01000100), + _BMP8(0b00111000), + _BMP8(0b00000000), _BMP8(0b00000000), _BMP8(0b00000000), +#endif +#if MARKERS_MAX >=7 // Marker 7 _BMP8(0b00000000), - _BMP8(0b11110000), + _BMP8(0b01111100), + _BMP8(0b01000100), + _BMP8(0b00000100), + _BMP8(0b00001000), + _BMP8(0b00010000), + _BMP8(0b00010000), _BMP8(0b00010000), - _BMP8(0b00100000), - _BMP8(0b00100000), - _BMP8(0b01000000), - _BMP8(0b01000000), - _BMP8(0b01000000), _BMP8(0b00000000), _BMP8(0b00000000), +#endif +#if MARKERS_MAX >=8 // Marker 8 _BMP8(0b00000000), - _BMP8(0b01100000), - _BMP8(0b10010000), - _BMP8(0b10010000), - _BMP8(0b01100000), - _BMP8(0b10010000), - _BMP8(0b10010000), - _BMP8(0b01100000), + _BMP8(0b00111000), + _BMP8(0b01000100), + _BMP8(0b00111000), + _BMP8(0b01000100), + _BMP8(0b01000100), + _BMP8(0b00111000), + _BMP8(0b00000000), _BMP8(0b00000000), _BMP8(0b00000000), - #endif }; + #elif _MARKER_SIZE_ == 1 #define MARKER_WIDTH 10 #define MARKER_HEIGHT 13 #define X_MARKER_OFFSET 4 #define Y_MARKER_OFFSET 13 #define MARKER_BITMAP(i) (&marker_bitmap[(i)*2*MARKER_HEIGHT]) -static const uint8_t marker_bitmap[]= -{ +static const uint8_t marker_bitmap[]={ // Marker Back plate _BMP16(0b1111111110000000), _BMP16(0b1111111110000000), @@ -773,20 +783,23 @@ static const uint8_t marker_bitmap[]= _BMP16(0b0000000000000000), _BMP16(0b0000000000000000), _BMP16(0b0000000000000000), +#if MARKERS_MAX >=2 // Marker 2 _BMP16(0b0000000000000000), _BMP16(0b0001111000000000), _BMP16(0b0011001100000000), _BMP16(0b0011001100000000), + _BMP16(0b0000001100000000), _BMP16(0b0000011000000000), - _BMP16(0b0000110000000000), - _BMP16(0b0001100000000000), + _BMP16(0b0001110000000000), _BMP16(0b0011000000000000), - _BMP16(0b0011111100000000), - _BMP16(0b0000000000000000), + _BMP16(0b0011000000000000), + _BMP16(0b0011111000000000), _BMP16(0b0000000000000000), _BMP16(0b0000000000000000), _BMP16(0b0000000000000000), +#endif +#if MARKERS_MAX >=3 // Marker 3 _BMP16(0b0000000000000000), _BMP16(0b0011111000000000), @@ -801,6 +814,8 @@ static const uint8_t marker_bitmap[]= _BMP16(0b0000000000000000), _BMP16(0b0000000000000000), _BMP16(0b0000000000000000), +#endif +#if MARKERS_MAX >=4 // Marker 4 _BMP16(0b0000000000000000), _BMP16(0b0000011000000000), @@ -815,60 +830,67 @@ static const uint8_t marker_bitmap[]= _BMP16(0b0000000000000000), _BMP16(0b0000000000000000), _BMP16(0b0000000000000000), -#if MARKER_COUNT>4 +#endif +#if MARKERS_MAX >=5 // Marker 5 _BMP16(0b0000000000000000), - _BMP16(0b11111100<<6), - _BMP16(0b11000000<<6), - _BMP16(0b11000000<<6), - _BMP16(0b11111000<<6), - _BMP16(0b11001100<<6), - _BMP16(0b00001100<<6), - _BMP16(0b00001100<<6), - _BMP16(0b11001100<<6), - _BMP16(0b01111000<<6), + _BMP16(0b0111111100000000), + _BMP16(0b0110000000000000), + _BMP16(0b0110000000000000), + _BMP16(0b0111111000000000), + _BMP16(0b0110001100000000), + _BMP16(0b0000001100000000), + _BMP16(0b0000001100000000), + _BMP16(0b0110001100000000), + _BMP16(0b0011111000000000), _BMP16(0b0000000000000000), _BMP16(0b0000000000000000), _BMP16(0b0000000000000000), +#endif +#if MARKERS_MAX >=6 // Marker 6 _BMP16(0b0000000000000000), - _BMP16(0b01111000<<6), - _BMP16(0b11001100<<6), - _BMP16(0b11000000<<6), - _BMP16(0b11000000<<6), - _BMP16(0b11111000<<6), - _BMP16(0b11001100<<6), - _BMP16(0b11001100<<6), - _BMP16(0b11001100<<6), - _BMP16(0b01111000<<6), + _BMP16(0b0011111000000000), + _BMP16(0b0110001100000000), + _BMP16(0b0110000000000000), + _BMP16(0b0110111000000000), + _BMP16(0b0111001100000000), + _BMP16(0b0110001100000000), + _BMP16(0b0110001100000000), + _BMP16(0b0110001100000000), + _BMP16(0b0011111000000000), _BMP16(0b0000000000000000), _BMP16(0b0000000000000000), _BMP16(0b0000000000000000), +#endif +#if MARKERS_MAX >=7 // Marker 7 _BMP16(0b0000000000000000), - _BMP16(0b11111100<<6), - _BMP16(0b00001100<<6), - _BMP16(0b00001100<<6), - _BMP16(0b00011000<<6), - _BMP16(0b00011000<<6), - _BMP16(0b00110000<<6), - _BMP16(0b00110000<<6), - _BMP16(0b01100000<<6), - _BMP16(0b01100000<<6), + _BMP16(0b0111111100000000), + _BMP16(0b0110001100000000), + _BMP16(0b0000001100000000), + _BMP16(0b0000011000000000), + _BMP16(0b0000110000000000), + _BMP16(0b0001100000000000), + _BMP16(0b0001100000000000), + _BMP16(0b0001100000000000), + _BMP16(0b0001100000000000), _BMP16(0b0000000000000000), _BMP16(0b0000000000000000), _BMP16(0b0000000000000000), +#endif +#if MARKERS_MAX >=8 // Marker 8 _BMP16(0b0000000000000000), - _BMP16(0b01111000<<6), - _BMP16(0b11001100<<6), - _BMP16(0b11001100<<6), - _BMP16(0b11001100<<6), - _BMP16(0b01111000<<6), - _BMP16(0b11001100<<6), - _BMP16(0b11001100<<6), - _BMP16(0b11001100<<6), - _BMP16(0b01111000<<6), + _BMP16(0b0011111000000000), + _BMP16(0b0110001100000000), + _BMP16(0b0110001100000000), + _BMP16(0b0011111000000000), + _BMP16(0b0110001100000000), + _BMP16(0b0110001100000000), + _BMP16(0b0110001100000000), + _BMP16(0b0110001100000000), + _BMP16(0b0011111000000000), _BMP16(0b0000000000000000), _BMP16(0b0000000000000000), _BMP16(0b0000000000000000), From 147612d9f7b4c31db89f1fc7f13040725413d302 Mon Sep 17 00:00:00 2001 From: DiSlord Date: Sat, 15 May 2021 16:54:58 +0300 Subject: [PATCH 13/24] Fix typo --- ui_sa.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ui_sa.c b/ui_sa.c index 0415529..45e70ae 100644 --- a/ui_sa.c +++ b/ui_sa.c @@ -2631,7 +2631,7 @@ static const menuitem_t menu_config[] = { { MT_SUBMENU, 0, S_RARROW" DFU", menu_dfu}, #endif #ifdef __LCD_BRIGHTNESS__ - { MT_CALLBACK, 0, "BRIGHTHESS", menu_brightness_cb}, + { MT_CALLBACK, 0, "BRIGHTNESS", menu_brightness_cb}, #endif { MT_CANCEL, 0, S_LARROW" BACK", NULL }, { MT_NONE, 0, NULL, NULL } // sentinel From 045d6f4000268c832a3713c786de2aebb2be9842 Mon Sep 17 00:00:00 2001 From: DiSlord Date: Sat, 15 May 2021 19:03:17 +0300 Subject: [PATCH 14/24] Add custom button label Use adaptive button size depend from count mode --- ui.c | 47 +++++++++++++++++++++++++++++++---------------- ui_sa.c | 41 +++++++++++++++++++---------------------- 2 files changed, 50 insertions(+), 38 deletions(-) diff --git a/ui.c b/ui.c index cad9e3d..e7b710a 100644 --- a/ui.c +++ b/ui.c @@ -64,7 +64,11 @@ 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_N(MENU_BUTTON_MIN); +#define MENU_USE_AUTOHEIGHT +#ifdef MENU_USE_AUTOHEIGHT +static uint16_t menu_button_height = MENU_BUTTON_HEIGHT_N(MENU_BUTTON_MIN); +#endif + volatile uint8_t operation_requested = OP_NONE; int8_t previous_marker = MARKER_INVALID; @@ -641,6 +645,8 @@ enum { //#define MT_LEAVE 0x20 #define MT_MASK(x) (0xF & (x)) +#define MT_CUSTOM_LABEL 0 + // Call back functions for MT_CALLBACK type typedef void (*menuaction_cb_t)(int item, uint16_t data); #define UI_FUNCTION_CALLBACK(ui_function_name) void ui_function_name(int item, uint16_t data) @@ -820,7 +826,9 @@ ensure_selection(void) if (MT_MASK(menu[0].type) == MT_TITLE && selection == 0) selection = 1; 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); +#ifdef MENU_USE_AUTOHEIGHT + menu_button_height = MENU_BUTTON_HEIGHT_N(i); +#endif } static void @@ -1118,9 +1126,10 @@ static int menu_is_multiline(const char *label) { int n = 1; - while (*label) - if (*label++ == '\n') - n++; + if (label) + while (*label) + if (*label++ == '\n') + n++; return n; } @@ -1343,11 +1352,13 @@ static const uint8_t check_box[] = { static const char *step_text[5] = {"-10dB", "-1dB", "set", "+1dB", "+10dB"}; static char step_text_freq[5][10] = { "-100MHz", "-10MHz", "set", "+10MHz", "+100MHz" }; -#ifdef TINYS4 +#ifndef MENU_USE_AUTOHEIGHT +#ifdef TINYSA4 #define menu_button_height ((menu[i].type & MT_FORM) || menu_is_multiline(menu[i].label) == 2 ? LCD_HEIGHT/10 : LCD_HEIGHT/12 ) #else #define menu_button_height ((menu[i].type & MT_FORM) || menu_is_multiline(menu[i].label) == 2 ? LCD_HEIGHT/8 : LCD_HEIGHT/10 ) #endif +#endif static void draw_menu_buttons(const menuitem_t *menu, int only) @@ -1390,22 +1401,26 @@ draw_menu_buttons(const menuitem_t *menu, int only) // Need replace this obsolete bad function on new MT_ADV_CALLBACK variant menu_item_modify_attribute(menu, i, &button); // before plot_printf to create status text - + char *text; // MT_ADV_CALLBACK - allow change button data in callback, more easy and correct if (MT_MASK(menu[i].type) == MT_ADV_CALLBACK){ menuaction_acb_t cb = (menuaction_acb_t)menu[i].reference; if (cb) (*cb)(i, menu[i].data, &button); + // Apply custom text, from button label and + if (menu[i].label != MT_CUSTOM_LABEL) + plot_printf(button.text, sizeof(button.text), menu[i].label, button.param_1.u); + text = button.text; } + else + text = menu[i].label; // Only keypad retrieves value if (menu[i].type & MT_FORM && MT_MASK(menu[i].type) == MT_KEYPAD) { keypad_mode = menu[i].data; fetch_numeric_target(); - button.param_1.text = uistat.text; + plot_printf(button.text, sizeof button.text, menu[i].label, uistat.text); + text = button.text; } - // Prepare button label - plot_printf(button.text, sizeof button.text, menu[i].label, button.param_1.u, button.param_2.u); - 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 @@ -1454,8 +1469,8 @@ draw_menu_buttons(const menuitem_t *menu, int only) goto draw_slider; } } -// ili9341_drawstring_size(button.text, text_offs, y+(button_height-2*FONT_GET_HEIGHT)/2-local_text_shift, 2); - ili9341_drawstring_10x14(button.text, text_offs, y+(button_height-wFONT_GET_HEIGHT)/2-local_text_shift); +// ili9341_drawstring_size(text, text_offs, y+(button_height-2*FONT_GET_HEIGHT)/2-local_text_shift, 2); + ili9341_drawstring_10x14(text, text_offs, y+(button_height-wFONT_GET_HEIGHT)/2-local_text_shift); } else { int button_width = MENU_BUTTON_WIDTH; int button_start = LCD_WIDTH - MENU_BUTTON_WIDTH; @@ -1466,12 +1481,12 @@ draw_menu_buttons(const menuitem_t *menu, int only) 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); + int lines = menu_is_multiline(text); #define BIG_BUTTON_FONT 1 #ifdef BIG_BUTTON_FONT - ili9341_drawstring_7x13(button.text, text_offs, y+(button_height-lines*bFONT_GET_HEIGHT)/2); + ili9341_drawstring_7x13(text, text_offs, y+(button_height-lines*bFONT_GET_HEIGHT)/2); #else - ili9341_drawstring(button.text, text_offs, y+(button_height-linesFONT_GET_HEIGHT)/2); + ili9341_drawstring(text, text_offs, y+(button_height-linesFONT_GET_HEIGHT)/2); #endif } y += menu_button_height; diff --git a/ui_sa.c b/ui_sa.c index 45e70ae..0c480f7 100644 --- a/ui_sa.c +++ b/ui_sa.c @@ -747,12 +747,10 @@ static UI_FUNCTION_ADV_CALLBACK(menu_load_preset_acb) (void)item; if(b){ setting_t *p = caldata_pointer(data); - char *t = (char *)spi_buffer; if (p) - plot_printf(t, 64, "%.6FHz\n%.6FHz", (float)p->frequency0, (float)p->frequency1);//\n%d-drstx8 + plot_printf(b->text, sizeof(b->text), "%.6FHz\n%.6FHz", (float)p->frequency0, (float)p->frequency1); else - plot_printf(t, 64, "EMPTY %d", (int)data); - b->param_1.text = t; + plot_printf(b->text, sizeof(b->text), "EMPTY %d", (int)data); return; } if (caldata_recall(data) == -1) { @@ -923,10 +921,9 @@ static UI_FUNCTION_ADV_CALLBACK(menu_smodulation_acb){ (void)data; if(b){ if (setting.modulation == MO_NONE || setting.modulation == MO_EXTERNAL) - b->param_1.text = menu_modulation_text[setting.modulation]; + plot_printf(b->text, sizeof b->text, "MOD: %s", menu_modulation_text[setting.modulation]); else { - plot_printf(uistat.text, sizeof uistat.text, "%5.3fkHz %s", setting.modulation_frequency / 1000.0, menu_modulation_text[setting.modulation]); - b->param_1.text = uistat.text; + plot_printf(b->text, sizeof b->text, "MOD: %5.3fkHz %s", setting.modulation_frequency / 1000.0, menu_modulation_text[setting.modulation]); } return; } @@ -1970,11 +1967,11 @@ static const menuitem_t menu_store_preset_high[8] = static const menuitem_t menu_load_preset_high[] = { - { MT_ADV_CALLBACK, 0, "LOAD\nSTARTUP",menu_load_preset_acb}, - { MT_ADV_CALLBACK, 5, "LOAD %s", menu_load_preset_acb}, - { MT_ADV_CALLBACK, 6, "LOAD %s", menu_load_preset_acb}, - { MT_ADV_CALLBACK, 7, "LOAD %s", menu_load_preset_acb}, - { MT_ADV_CALLBACK, 8, "LOAD %s", menu_load_preset_acb}, + { MT_ADV_CALLBACK, 0, "LOAD\nSTARTUP", menu_load_preset_acb}, + { MT_ADV_CALLBACK, 5, MT_CUSTOM_LABEL, menu_load_preset_acb}, + { MT_ADV_CALLBACK, 6, MT_CUSTOM_LABEL, menu_load_preset_acb}, + { MT_ADV_CALLBACK, 7, MT_CUSTOM_LABEL, menu_load_preset_acb}, + { MT_ADV_CALLBACK, 8, MT_CUSTOM_LABEL, menu_load_preset_acb}, { MT_SUBMENU, 0, "STORE" , menu_store_preset_high}, { MT_CANCEL, 255, S_LARROW" BACK", NULL }, { MT_NONE, 0, NULL, NULL } // sentinel @@ -1995,11 +1992,11 @@ static const menuitem_t menu_store_preset[] = static const menuitem_t menu_load_preset[] = { - { MT_ADV_CALLBACK, 0, "LOAD\nSTARTUP",menu_load_preset_acb}, - { MT_ADV_CALLBACK, 1, "%s" , menu_load_preset_acb}, - { MT_ADV_CALLBACK, 2, "%s" , menu_load_preset_acb}, - { MT_ADV_CALLBACK, 3, "%s" , menu_load_preset_acb}, - { MT_ADV_CALLBACK, 4, "%s" , menu_load_preset_acb}, + { MT_ADV_CALLBACK, 0, "LOAD\nSTARTUP", menu_load_preset_acb}, + { MT_ADV_CALLBACK, 1, MT_CUSTOM_LABEL, menu_load_preset_acb}, + { MT_ADV_CALLBACK, 2, MT_CUSTOM_LABEL, menu_load_preset_acb}, + { MT_ADV_CALLBACK, 3, MT_CUSTOM_LABEL, menu_load_preset_acb}, + { MT_ADV_CALLBACK, 4, MT_CUSTOM_LABEL, menu_load_preset_acb}, { MT_SUBMENU, 0, "STORE" , menu_store_preset}, { MT_CANCEL, 0, S_LARROW" BACK", NULL }, { MT_NONE, 0, NULL, NULL } // sentinel @@ -2054,7 +2051,7 @@ static const menuitem_t menu_lowoutputmode[] = { // { MT_FORM | MT_ADV_CALLBACK, 0, "MOD: %s", menu_smodulation_acb}, { MT_FORM | MT_KEYPAD, KM_CENTER, center_text, VARIANT("10kHz..350MHz","10kHz..850MHz")}, { MT_FORM | MT_KEYPAD, KM_LOWOUTLEVEL, "LEVEL: %s", low_level_help_text}, - { MT_FORM | MT_ADV_CALLBACK, 0, "MOD: %s", menu_smodulation_acb}, + { MT_FORM | MT_ADV_CALLBACK, 0, MT_CUSTOM_LABEL, menu_smodulation_acb}, { MT_FORM | MT_ADV_CALLBACK, 0, "%s", menu_sweep_acb}, #ifdef __SWEEP_RESTART__ { MT_FORM | MT_ADV_CALLBACK, 0, "%s", menu_restart_acb}, @@ -2071,7 +2068,7 @@ static const menuitem_t menu_highoutputmode[] = { { MT_FORM | MT_ADV_CALLBACK, 0, "HIGH OUTPUT %s", menu_outputmode_acb}, { MT_FORM | MT_KEYPAD, KM_CENTER, center_text, VARIANT("240MHz..960MHz",range_text)}, { MT_FORM | MT_KEYPAD, KM_HIGHOUTLEVEL, "LEVEL: %s", low_level_help_text /* "-76..-6" */}, - { MT_FORM | MT_ADV_CALLBACK, 0, "MOD: %s", menu_smodulation_acb}, + { MT_FORM | MT_ADV_CALLBACK, 0, MT_CUSTOM_LABEL, menu_smodulation_acb}, { MT_FORM | MT_ADV_CALLBACK, 0, "%s", menu_sweep_acb}, #ifdef __SWEEP_RESTART__ { MT_FORM | MT_ADV_CALLBACK, 0, "%s", menu_restart_acb}, @@ -2315,7 +2312,7 @@ static const menuitem_t menu_dfu[] = { #ifdef __HARMONIC__ static const menuitem_t menu_harmonic[] = { - { MT_ADV_CALLBACK, 0, "OFF", menu_harmonic_acb}, + { MT_ADV_CALLBACK, 0, "OFF", menu_harmonic_acb}, { MT_ADV_CALLBACK, 2, "2", menu_harmonic_acb}, { MT_ADV_CALLBACK, 3, "3", menu_harmonic_acb}, { MT_ADV_CALLBACK, 4, "4", menu_harmonic_acb}, @@ -2390,8 +2387,8 @@ static const menuitem_t menu_settings3[] = { #ifdef TINYSA4 // { MT_KEYPAD, KM_GRIDLINES, "MINIMUM\nGRIDLINES", "Enter minimum horizontal grid divisions"}, - { MT_ADV_CALLBACK, 0, "ADF OUT", menu_adf_out_acb}, - { MT_ADV_CALLBACK, 0, "ENABLE\nULTRA", menu_ultra_acb}, + { MT_ADV_CALLBACK, 0, "ADF OUT", menu_adf_out_acb}, + { MT_ADV_CALLBACK, 0, "ENABLE\nULTRA", menu_ultra_acb}, { MT_KEYPAD, KM_LPF, "ULTRA\nSTART", "Enter ULTRA mode start freq"}, // { MT_KEYPAD | MT_LOW, KM_IF2, "IF2 FREQ", "Set to zero for no IF2"}, { MT_KEYPAD, KM_R, "R", "Set R"}, From 58356d82a58b2b01646c0e0caac5de8d9acc1ca2 Mon Sep 17 00:00:00 2001 From: DiSlord Date: Sat, 15 May 2021 21:01:38 +0300 Subject: [PATCH 15/24] Change custom labels create --- ui_sa.c | 63 +++++++++++++++++++++++++++------------------------------ 1 file changed, 30 insertions(+), 33 deletions(-) diff --git a/ui_sa.c b/ui_sa.c index 0c480f7..c7ff5d9 100644 --- a/ui_sa.c +++ b/ui_sa.c @@ -527,14 +527,13 @@ static UI_FUNCTION_ADV_CALLBACK(menu_sweep_acb) (void)item; if (b){ if (setting.level_sweep != 0 || get_sweep_frequency(ST_SPAN) != 0) { - plot_printf(uistat.text, sizeof uistat.text, "SW:%3.2fMHz %+ddB %.3Fs", + plot_printf(b->text, sizeof b->text, "SW:%3.2fMHz %+ddB %.3Fs", get_sweep_frequency(ST_SPAN) / 1000000.0, (int)setting.level_sweep, setting.sweep_time_us/(float)ONE_SECOND_TIME); - b->param_1.text = uistat.text; } else - b->param_1.text = "SWEEP: OFF"; + plot_printf(b->text, sizeof b->text, "SWEEP: OFF"); return; } menu_push_submenu(menu_sweep); @@ -547,11 +546,10 @@ static UI_FUNCTION_ADV_CALLBACK(menu_restart_acb){ if(b){ if (current_index >= 0 && setting.sweep) { float current_level = setting.level + ((float)current_index)* setting.level_sweep / (float)sweep_points; - plot_printf(uistat.text, sizeof uistat.text, "STOP %5.3QHz %+.1fdBm", frequencies[current_index], current_level); - b->param_1.text = uistat.text; - } else { - b->param_1.text = "START SWEEP"; + plot_printf(b->text, sizeof b->text, "STOP %5.3QHz %+.1fdBm", frequencies[current_index], current_level); } + else + plot_printf(b->text, sizeof b->text, "START SWEEP"); return; } setting.sweep = !setting.sweep; @@ -570,10 +568,9 @@ static UI_FUNCTION_ADV_CALLBACK(menu_curve_acb) (void)item; int old_m; if (b){ - plot_printf(uistat.text, sizeof uistat.text, "%8.3QHz %+4.1fdB", + plot_printf(b->text, sizeof b->text, "%8.3QHz %+4.1fdB", config.correction_frequency[current_curve][data], config.correction_value[current_curve][data]); - b->param_1.text = uistat.text; return; } switch(current_curve) { @@ -2052,9 +2049,9 @@ static const menuitem_t menu_lowoutputmode[] = { { MT_FORM | MT_KEYPAD, KM_CENTER, center_text, VARIANT("10kHz..350MHz","10kHz..850MHz")}, { MT_FORM | MT_KEYPAD, KM_LOWOUTLEVEL, "LEVEL: %s", low_level_help_text}, { MT_FORM | MT_ADV_CALLBACK, 0, MT_CUSTOM_LABEL, menu_smodulation_acb}, - { MT_FORM | MT_ADV_CALLBACK, 0, "%s", menu_sweep_acb}, + { MT_FORM | MT_ADV_CALLBACK, 0, MT_CUSTOM_LABEL, menu_sweep_acb}, #ifdef __SWEEP_RESTART__ - { MT_FORM | MT_ADV_CALLBACK, 0, "%s", menu_restart_acb}, + { MT_FORM | MT_ADV_CALLBACK, 0, MT_CUSTOM_LABEL, menu_restart_acb}, #endif { MT_FORM | MT_KEYPAD, KM_EXT_GAIN, "EXTERNAL GAIN: %s", "-100..+100"}, #ifdef TINYSA4 @@ -2069,9 +2066,9 @@ static const menuitem_t menu_highoutputmode[] = { { MT_FORM | MT_KEYPAD, KM_CENTER, center_text, VARIANT("240MHz..960MHz",range_text)}, { MT_FORM | MT_KEYPAD, KM_HIGHOUTLEVEL, "LEVEL: %s", low_level_help_text /* "-76..-6" */}, { MT_FORM | MT_ADV_CALLBACK, 0, MT_CUSTOM_LABEL, menu_smodulation_acb}, - { MT_FORM | MT_ADV_CALLBACK, 0, "%s", menu_sweep_acb}, + { MT_FORM | MT_ADV_CALLBACK, 0, MT_CUSTOM_LABEL, menu_sweep_acb}, #ifdef __SWEEP_RESTART__ - { MT_FORM | MT_ADV_CALLBACK, 0, "%s", menu_restart_acb}, + { MT_FORM | MT_ADV_CALLBACK, 0, MT_CUSTOM_LABEL, menu_restart_acb}, #endif { MT_FORM | MT_KEYPAD, KM_EXT_GAIN, "EXTERNAL GAIN: %s", "-100..+100"}, #ifdef TINYSA4 @@ -2457,37 +2454,37 @@ static const menuitem_t menu_settings2[] = #ifdef TINYSA4 static const menuitem_t menu_curve3[] = { - { MT_FORM | MT_ADV_CALLBACK, 14, "%s", menu_curve_acb }, - { MT_FORM | MT_ADV_CALLBACK, 15, "%s", menu_curve_acb }, - { MT_FORM | MT_ADV_CALLBACK, 16, "%s", menu_curve_acb }, - { MT_FORM | MT_ADV_CALLBACK, 17, "%s", menu_curve_acb }, - { MT_FORM | MT_ADV_CALLBACK, 18, "%s", menu_curve_acb }, - { MT_FORM | MT_ADV_CALLBACK, 19, "%s", menu_curve_acb }, + { MT_FORM | MT_ADV_CALLBACK, 14, MT_CUSTOM_LABEL, menu_curve_acb }, + { MT_FORM | MT_ADV_CALLBACK, 15, MT_CUSTOM_LABEL, menu_curve_acb }, + { MT_FORM | MT_ADV_CALLBACK, 16, MT_CUSTOM_LABEL, menu_curve_acb }, + { MT_FORM | MT_ADV_CALLBACK, 17, MT_CUSTOM_LABEL, menu_curve_acb }, + { MT_FORM | MT_ADV_CALLBACK, 18, MT_CUSTOM_LABEL, menu_curve_acb }, + { MT_FORM | MT_ADV_CALLBACK, 19, MT_CUSTOM_LABEL, menu_curve_acb }, { MT_FORM | MT_CANCEL, 0, S_LARROW" BACK", NULL }, { MT_NONE, 0, NULL, NULL } // sentinel }; static const menuitem_t menu_curve2[] = { - { MT_FORM | MT_ADV_CALLBACK, 7, "%s", menu_curve_acb }, - { MT_FORM | MT_ADV_CALLBACK, 8, "%s", menu_curve_acb }, - { MT_FORM | MT_ADV_CALLBACK, 9, "%s", menu_curve_acb }, - { MT_FORM | MT_ADV_CALLBACK, 10, "%s", menu_curve_acb }, - { MT_FORM | MT_ADV_CALLBACK, 11, "%s", menu_curve_acb }, - { MT_FORM | MT_ADV_CALLBACK, 12, "%s", menu_curve_acb }, - { MT_FORM | MT_ADV_CALLBACK, 13, "%s", menu_curve_acb }, + { MT_FORM | MT_ADV_CALLBACK, 7, MT_CUSTOM_LABEL, menu_curve_acb }, + { MT_FORM | MT_ADV_CALLBACK, 8, MT_CUSTOM_LABEL, menu_curve_acb }, + { MT_FORM | MT_ADV_CALLBACK, 9, MT_CUSTOM_LABEL, menu_curve_acb }, + { MT_FORM | MT_ADV_CALLBACK, 10, MT_CUSTOM_LABEL, menu_curve_acb }, + { MT_FORM | MT_ADV_CALLBACK, 11, MT_CUSTOM_LABEL, menu_curve_acb }, + { MT_FORM | MT_ADV_CALLBACK, 12, MT_CUSTOM_LABEL, menu_curve_acb }, + { MT_FORM | MT_ADV_CALLBACK, 13, MT_CUSTOM_LABEL, menu_curve_acb }, { MT_FORM | MT_SUBMENU, 0, S_RARROW" MORE", menu_curve3}, { MT_FORM | MT_CANCEL, 0, S_LARROW" BACK", NULL }, { MT_NONE, 0, NULL, NULL } // sentinel }; static const menuitem_t menu_curve[] = { - { MT_FORM | MT_ADV_CALLBACK, 0, "%s", menu_curve_acb }, - { MT_FORM | MT_ADV_CALLBACK, 1, "%s", menu_curve_acb }, - { MT_FORM | MT_ADV_CALLBACK, 2, "%s", menu_curve_acb }, - { MT_FORM | MT_ADV_CALLBACK, 3, "%s", menu_curve_acb }, - { MT_FORM | MT_ADV_CALLBACK, 4, "%s", menu_curve_acb }, - { MT_FORM | MT_ADV_CALLBACK, 5, "%s", menu_curve_acb }, - { MT_FORM | MT_ADV_CALLBACK, 6, "%s", menu_curve_acb }, + { MT_FORM | MT_ADV_CALLBACK, 0, MT_CUSTOM_LABEL, menu_curve_acb }, + { MT_FORM | MT_ADV_CALLBACK, 1, MT_CUSTOM_LABEL, menu_curve_acb }, + { MT_FORM | MT_ADV_CALLBACK, 2, MT_CUSTOM_LABEL, menu_curve_acb }, + { MT_FORM | MT_ADV_CALLBACK, 3, MT_CUSTOM_LABEL, menu_curve_acb }, + { MT_FORM | MT_ADV_CALLBACK, 4, MT_CUSTOM_LABEL, menu_curve_acb }, + { MT_FORM | MT_ADV_CALLBACK, 5, MT_CUSTOM_LABEL, menu_curve_acb }, + { MT_FORM | MT_ADV_CALLBACK, 6, MT_CUSTOM_LABEL, menu_curve_acb }, { MT_FORM | MT_SUBMENU, 0, S_RARROW" MORE", menu_curve2}, { MT_FORM | MT_CANCEL, 0, S_LARROW" BACK", NULL }, { MT_NONE, 0, NULL, NULL } // sentinel From aec175ee28b007e827bce15eee9ac4e0b7a524c2 Mon Sep 17 00:00:00 2001 From: DiSlord Date: Sat, 15 May 2021 23:18:06 +0300 Subject: [PATCH 16/24] Fix battery icon --- plot.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plot.c b/plot.c index 80ee7e1..fe27cc2 100644 --- a/plot.c +++ b/plot.c @@ -1776,7 +1776,7 @@ draw_frequencies(void) // Draw battery level #define BATTERY_TOP_LEVEL 4200 -#define BATTERY_BOTTOM_LEVEL 3200 +#define BATTERY_BOTTOM_LEVEL 3300 #define BATTERY_WARNING_LEVEL 3300 #define BATTERY_MID_LEVEL 3600 From 78f6c3218a89d581a16347069173b4a18cdb792f Mon Sep 17 00:00:00 2001 From: DiSlord Date: Sat, 15 May 2021 23:42:28 +0300 Subject: [PATCH 17/24] Disable unused ChibiOS systems --- NANOVNA_STM32_F072/mcuconf.h | 4 ++-- NANOVNA_STM32_F303/mcuconf.h | 2 +- halconf.h | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/NANOVNA_STM32_F072/mcuconf.h b/NANOVNA_STM32_F072/mcuconf.h index 1d4b073..99f4609 100644 --- a/NANOVNA_STM32_F072/mcuconf.h +++ b/NANOVNA_STM32_F072/mcuconf.h @@ -175,7 +175,7 @@ * I2S driver system settings. */ #define STM32_I2S_USE_SPI1 FALSE -#define STM32_I2S_USE_SPI2 TRUE +#define STM32_I2S_USE_SPI2 FALSE #define STM32_I2S_SPI1_MODE (STM32_I2S_MODE_MASTER | \ STM32_I2S_MODE_RX) #define STM32_I2S_SPI2_MODE (STM32_I2S_MODE_SLAVE | \ @@ -222,7 +222,7 @@ /* * SPI driver system settings. */ -#define STM32_SPI_USE_SPI1 TRUE +#define STM32_SPI_USE_SPI1 FALSE #define STM32_SPI_USE_SPI2 FALSE #define STM32_SPI_USE_SPI3 FALSE #define STM32_SPI_SPI1_RX_DMA_STREAM STM32_DMA_STREAM_ID(1, 2) diff --git a/NANOVNA_STM32_F303/mcuconf.h b/NANOVNA_STM32_F303/mcuconf.h index c0d4001..391e522 100644 --- a/NANOVNA_STM32_F303/mcuconf.h +++ b/NANOVNA_STM32_F303/mcuconf.h @@ -226,7 +226,7 @@ /* * SPI driver system settings. */ -#define STM32_SPI_USE_SPI1 TRUE +#define STM32_SPI_USE_SPI1 FALSE #define STM32_SPI_USE_SPI2 FALSE #define STM32_SPI_USE_SPI3 FALSE #define STM32_SPI_SPI1_RX_DMA_STREAM STM32_DMA_STREAM_ID(1, 2) diff --git a/halconf.h b/halconf.h index b3767eb..7077bb3 100644 --- a/halconf.h +++ b/halconf.h @@ -150,7 +150,7 @@ * @brief Enables the SPI subsystem. */ #if !defined(HAL_USE_SPI) || defined(__DOXYGEN__) -#define HAL_USE_SPI TRUE +#define HAL_USE_SPI FALSE #endif /** From 2aed400a477ebd8edb81396546ef341df7a55b96 Mon Sep 17 00:00:00 2001 From: DiSlord Date: Sat, 15 May 2021 23:43:07 +0300 Subject: [PATCH 18/24] Restore tinySA3 compilation --- nanovna.h | 4 ++-- sa_core.c | 2 ++ 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/nanovna.h b/nanovna.h index 6b3ea05..6bafbc7 100644 --- a/nanovna.h +++ b/nanovna.h @@ -18,7 +18,7 @@ */ #include "ch.h" -//#ifdef TINYSA_F303 +#ifdef TINYSA_F303 #include "adc_F303.h" #ifdef TINYSA_F072 #error "Remove comment for #ifdef TINYSA_F303" @@ -27,7 +27,7 @@ #define TINYSA4 #endif #define TINYSA4_PROTO -//#endif +#endif #ifdef TINYSA_F072 #ifdef TINYSA_F303 diff --git a/sa_core.c b/sa_core.c index 5f79b10..cee5538 100644 --- a/sa_core.c +++ b/sa_core.c @@ -3963,11 +3963,13 @@ static bool sweep(bool break_on_operation) } } // end of peak finding } +#ifdef TINYSA4 if (setting.average == AV_DECONV && setting.frequency_step != 0) { for (int i = sweep_points - 1 - d_half_width*2; i>0; i--) { actual_t[i+d_half_width] = actual_t[i]; } } +#endif } From f50d7e7f474c21cd5a0bb36730f049ee997fd764 Mon Sep 17 00:00:00 2001 From: DiSlord Date: Sun, 16 May 2021 08:12:52 +0300 Subject: [PATCH 19/24] Cleanup, reduce size --- plot.c | 99 ++++++++-------------------------------------------------- 1 file changed, 13 insertions(+), 86 deletions(-) diff --git a/plot.c b/plot.c index fe27cc2..e5ca346 100644 --- a/plot.c +++ b/plot.c @@ -1316,77 +1316,8 @@ cell_drawchar_size(uint8_t ch, int x, int y, int size) } #endif -/* -void -cell_drawstring(char *str, int x, int y) -{ - if ((uint32_t)(y+FONT_GET_HEIGHT) >= CELLHEIGHT + FONT_GET_HEIGHT) - return; - while (*str) { - if (x >= CELLWIDTH) - return; - uint16_t ch = *str++; - uint16_t w = FONT_GET_WIDTH(ch); - cell_blit_bitmap(x, y, w, FONT_GET_HEIGHT, FONT_GET_DATA(ch)); - x += w; - } -} - -static void -cell_drawstring_7x13(char *str, int x, int y) -{ - if ((uint32_t)(y+bFONT_GET_HEIGHT) >= CELLHEIGHT + bFONT_GET_HEIGHT) - return; - while (*str) { - if (x >= CELLWIDTH) - return; - uint8_t ch = *str++; - uint16_t w = bFONT_GET_WIDTH(ch); - cell_blit_bitmap(x, y, w, bFONT_GET_HEIGHT, bFONT_GET_DATA(ch)); - x += w; - } -} - -#ifndef wFONT_GET_DATA -void -cell_drawstring_size(char *str, int x, int y, int size) -{ - if (y <= -FONT_GET_HEIGHT*2 || y >= CELLHEIGHT) - return; - while (*str) { - if (x >= CELLWIDTH) - return; - x += cell_drawchar_size(*str++, x, y, size); - } -} -#endif - -void -cell_drawstring_10x14(char *str, int x, int y) -{ -#ifdef wFONT_GET_DATA - if ((uint32_t)(y+wFONT_GET_HEIGHT) >= CELLHEIGHT + wFONT_GET_HEIGHT) - return; - while (*str) { - if (x >= CELLWIDTH) - return; - uint8_t ch = *str++; - uint16_t w = wFONT_GET_WIDTH(ch); - cell_blit_bitmap(x, y, w <=8 ? 9 : w, wFONT_GET_HEIGHT, wFONT_GET_DATA(ch)); - x+=w; - } -#else - cell_drawstring_size(str, x, y, 2); -#endif -} -*/ - -struct cellprintStreamVMT { - _base_sequential_stream_methods -}; - typedef struct { - const struct cellprintStreamVMT *vmt; + const void *vmt; int16_t x; int16_t y; } screenPrintStream; @@ -1400,7 +1331,6 @@ static msg_t cellPut(void *ip, uint8_t ch) { } return MSG_OK; } -static const struct cellprintStreamVMT cell_vmt_s = {NULL, NULL, cellPut, NULL}; static msg_t cellPut7x13(void *ip, uint8_t ch) { screenPrintStream *ps = ip; @@ -1411,10 +1341,8 @@ static msg_t cellPut7x13(void *ip, uint8_t ch) { } return MSG_OK; } -static const struct cellprintStreamVMT cell_vmt_b = {NULL, NULL, cellPut7x13, NULL}; //#define ENABLE_WIDE_FONT_ON_CELL - #ifdef ENABLE_WIDE_FONT_ON_CELL static msg_t cellPut10x14(void *ip, uint8_t ch) { screenPrintStream *ps = ip; @@ -1429,25 +1357,27 @@ static msg_t cellPut10x14(void *ip, uint8_t ch) { } return MSG_OK; } -static const struct cellprintStreamVMT cell_vmt_w = {NULL, NULL, cellPut10x14, NULL}; #endif // Simple print in buffer function int cell_printf(int16_t x, int16_t y, const char *fmt, ...) { // skip always if right if (x>=CELLWIDTH) return 0; - uint8_t font_type = *fmt++; - screenPrintStream ps; + // Init small cell print stream + struct cellprintStreamVMT { + _base_sequential_stream_methods + } cell_vmt = {NULL, NULL, NULL, NULL}; + screenPrintStream ps = {&cell_vmt, x, y}; // Select font and skip print if not on cell (at top/bottom) - switch (font_type){ + switch (*fmt++){ case _FONT_s: if ((uint32_t)(y+FONT_GET_HEIGHT) >= CELLHEIGHT + FONT_GET_HEIGHT) return 0; - ps.vmt = &cell_vmt_s; + cell_vmt.put = cellPut; break; #ifdef ENABLE_WIDE_FONT_ON_CELL case _FONT_w: if ((uint32_t)(y+FONT_GET_HEIGHT) >= CELLHEIGHT + FONT_GET_HEIGHT) return 0; - ps.vmt = &cell_vmt_w; + cell_vmt.put = cellPut10x14; break; #endif default: @@ -1455,14 +1385,11 @@ int cell_printf(int16_t x, int16_t y, const char *fmt, ...) { __attribute__ ((fallthrough)); // prevent warning case _FONT_b: if ((uint32_t)(y+bFONT_GET_HEIGHT) >= CELLHEIGHT + bFONT_GET_HEIGHT) return 0; - ps.vmt = &cell_vmt_b; + cell_vmt.put = cellPut7x13; break; } - va_list ap; - // Init small cell print stream - ps.x = x; - ps.y = y; // Performing the print operation using the common code. + va_list ap; va_start(ap, fmt); int retval = chvprintf((BaseSequentialStream *)(void *)&ps, fmt, ap); va_end(ap); @@ -1491,8 +1418,8 @@ static void trace_print_value_string( // Only used at one place int xpos, int ypos, bool bold, int mi, // Marker number - int ri, // reference Marker number - float coeff[POINTS_COUNT]) + int ri, // reference Marker number + float coeff[POINTS_COUNT]) { (void) bold; int mtype = markers[mi].mtype; From 753d397f61424a3ec9b689e6a0cd5ec4c3b6af01 Mon Sep 17 00:00:00 2001 From: DiSlord Date: Sun, 16 May 2021 08:14:10 +0300 Subject: [PATCH 20/24] Add lcd_printf function (allow use printf for lcd output) --- ili9341.c | 46 +++++++++++++++++++++++++++++++++++++++++++++- nanovna.h | 1 + 2 files changed, 46 insertions(+), 1 deletion(-) diff --git a/ili9341.c b/ili9341.c index 0c78c00..78d7257 100644 --- a/ili9341.c +++ b/ili9341.c @@ -23,7 +23,7 @@ #ifdef TINYSA4 #include "si4432.h" #endif - +#include "chprintf.h" #include "spi.h" // Pin macros for LCD @@ -841,6 +841,50 @@ void ili9341_drawstring_10x14(const char *str, int x, int y) #endif } +typedef struct { + const void *vmt; + int16_t start_x; + int16_t start_y; + int16_t x; + int16_t y; +} lcdPrintStream; + +static msg_t lcd_put(void *ip, uint8_t ch) { + lcdPrintStream *ps = ip; + if (ch == '\n') {ps->x = ps->start_x; ps->y+=FONT_STR_HEIGHT; return MSG_OK;} + uint16_t w = FONT_GET_WIDTH(ch); + ili9341_blitBitmap(ps->x, ps->y, w, FONT_GET_HEIGHT, FONT_GET_DATA(ch)); + ps->x+= w; + return MSG_OK; +} + +#if 0 +static msg_t lcd_put_7x13(void *ip, uint8_t ch) { + lcdPrintStream *ps = ip; + if (ch == '\n') {ps->x = ps->start_x; ps->y+=FONT_STR_HEIGHT; return MSG_OK;} + uint16_t w = FONT_GET_WIDTH(ch); + ili9341_blitBitmap(ps->x, ps->y, w, FONT_GET_HEIGHT, FONT_GET_DATA(ch)); + ps->x+= w; + return MSG_OK; +} +#endif + +// Simple print in buffer function +int lcd_printf(int16_t x, int16_t y, const char *fmt, ...) { + // Init small lcd print stream + struct lcd_printStreamVMT { + _base_sequential_stream_methods + } lcd_vmt = {NULL, NULL, lcd_put, NULL}; + lcdPrintStream ps = {&lcd_vmt, x, y, x, y}; + // Performing the print operation using the common code. + va_list ap; + va_start(ap, fmt); + int retval = chvprintf((BaseSequentialStream *)(void *)&ps, fmt, ap); + va_end(ap); + // Return number of bytes that would have been written. + return retval; +} + void ili9341_drawstringV(const char *str, int x, int y) { ili9341_set_rotation(DISPLAY_ROTATION_270); diff --git a/nanovna.h b/nanovna.h index 6bafbc7..f04bfc0 100644 --- a/nanovna.h +++ b/nanovna.h @@ -961,6 +961,7 @@ void ili9341_drawchar(uint8_t ch, int x, int y); void ili9341_drawstring(const char *str, int x, int y); void ili9341_drawstring_7x13(const char *str, int x, int y); void ili9341_drawstring_10x14(const char *str, int x, int y); +int lcd_printf(int16_t x, int16_t y, const char *fmt, ...); void ili9341_drawstringV(const char *str, int x, int y); int ili9341_drawchar_size(uint8_t ch, int x, int y, uint8_t size); void ili9341_drawstring_size(const char *str, int x, int y, uint8_t size); From 8d805be0e6a67ea0441a7ea0d90bf4b85ec4e68c Mon Sep 17 00:00:00 2001 From: DiSlord Date: Sun, 16 May 2021 08:15:08 +0300 Subject: [PATCH 21/24] Use lcd_printf for debug screen log --- main.c | 38 ++++++++++++++++++-------------------- 1 file changed, 18 insertions(+), 20 deletions(-) diff --git a/main.c b/main.c index a6cf428..c68d48f 100644 --- a/main.c +++ b/main.c @@ -2354,24 +2354,23 @@ void hard_fault_handler_c(uint32_t *sp) static char buf[96]; ili9341_set_background(LCD_BG_COLOR); ili9341_set_foreground(LCD_FG_COLOR); - - plot_printf(buf, sizeof(buf), "SP 0x%08x", (uint32_t)sp);ili9341_drawstring(buf, x, y+=FONT_STR_HEIGHT); - plot_printf(buf, sizeof(buf), "R0 0x%08x", r0);ili9341_drawstring(buf, x, y+=FONT_STR_HEIGHT); - plot_printf(buf, sizeof(buf), "R1 0x%08x", r1);ili9341_drawstring(buf, x, y+=FONT_STR_HEIGHT); - plot_printf(buf, sizeof(buf), "R2 0x%08x", r2);ili9341_drawstring(buf, x, y+=FONT_STR_HEIGHT); - plot_printf(buf, sizeof(buf), "R3 0x%08x", r3);ili9341_drawstring(buf, x, y+=FONT_STR_HEIGHT); - plot_printf(buf, sizeof(buf), "R4 0x%08x", r4);ili9341_drawstring(buf, x, y+=FONT_STR_HEIGHT); - plot_printf(buf, sizeof(buf), "R5 0x%08x", r5);ili9341_drawstring(buf, x, y+=FONT_STR_HEIGHT); - plot_printf(buf, sizeof(buf), "R6 0x%08x", r6);ili9341_drawstring(buf, x, y+=FONT_STR_HEIGHT); - plot_printf(buf, sizeof(buf), "R7 0x%08x", r7);ili9341_drawstring(buf, x, y+=FONT_STR_HEIGHT); - plot_printf(buf, sizeof(buf), "R8 0x%08x", r8);ili9341_drawstring(buf, x, y+=FONT_STR_HEIGHT); - plot_printf(buf, sizeof(buf), "R9 0x%08x", r9);ili9341_drawstring(buf, x, y+=FONT_STR_HEIGHT); - plot_printf(buf, sizeof(buf), "R10 0x%08x", r10);ili9341_drawstring(buf, x, y+=FONT_STR_HEIGHT); - plot_printf(buf, sizeof(buf), "R11 0x%08x", r11);ili9341_drawstring(buf, x, y+=FONT_STR_HEIGHT); - plot_printf(buf, sizeof(buf), "R12 0x%08x", r12);ili9341_drawstring(buf, x, y+=FONT_STR_HEIGHT); - plot_printf(buf, sizeof(buf), "LR 0x%08x", lr);ili9341_drawstring(buf, x, y+=FONT_STR_HEIGHT); - plot_printf(buf, sizeof(buf), "PC 0x%08x", pc);ili9341_drawstring(buf, x, y+=FONT_STR_HEIGHT); - plot_printf(buf, sizeof(buf), "PSR 0x%08x", psr);ili9341_drawstring(buf, x, y+=FONT_STR_HEIGHT); + lcd_printf(x, y+=FONT_STR_HEIGHT, "SP 0x%08x", (uint32_t)sp); + lcd_printf(x, y+=FONT_STR_HEIGHT, "R0 0x%08x", r0); + lcd_printf(x, y+=FONT_STR_HEIGHT, "R1 0x%08x", r1); + lcd_printf(x, y+=FONT_STR_HEIGHT, "R2 0x%08x", r2); + lcd_printf(x, y+=FONT_STR_HEIGHT, "R3 0x%08x", r3); + lcd_printf(x, y+=FONT_STR_HEIGHT, "R4 0x%08x", r4); + lcd_printf(x, y+=FONT_STR_HEIGHT, "R5 0x%08x", r5); + lcd_printf(x, y+=FONT_STR_HEIGHT, "R6 0x%08x", r6); + lcd_printf(x, y+=FONT_STR_HEIGHT, "R7 0x%08x", r7); + lcd_printf(x, y+=FONT_STR_HEIGHT, "R8 0x%08x", r8); + lcd_printf(x, y+=FONT_STR_HEIGHT, "R9 0x%08x", r9); + lcd_printf(x, y+=FONT_STR_HEIGHT, "R10 0x%08x", r10); + lcd_printf(x, y+=FONT_STR_HEIGHT, "R11 0x%08x", r11); + lcd_printf(x, y+=FONT_STR_HEIGHT, "R12 0x%08x", r12); + lcd_printf(x, y+=FONT_STR_HEIGHT, "LR 0x%08x", lr); + lcd_printf(x, y+=FONT_STR_HEIGHT, "PC 0x%08x", pc); + lcd_printf(x, y+=FONT_STR_HEIGHT, "PSR 0x%08x", psr); #ifdef ENABLE_THREADS_COMMAND thread_t *tp; tp = chRegFirstThread(); @@ -2385,11 +2384,10 @@ void hard_fault_handler_c(uint32_t *sp) #else uint32_t stklimit = 0U; #endif - plot_printf(buf, sizeof(buf), "%08x|%08x|%08x|%08x|%4u|%4u|%9s|%12s", + lcd_printf(buf, x, y+=FONT_STR_HEIGHT, "%08x|%08x|%08x|%08x|%4u|%4u|%9s|%12s", stklimit, (uint32_t)tp->ctx.sp, max_stack_use, (uint32_t)tp, (uint32_t)tp->refs - 1, (uint32_t)tp->prio, states[tp->state], tp->name == NULL ? "" : tp->name); - ili9341_drawstring(buf, x, y+=FONT_STR_HEIGHT); tp = chRegNextThread(tp); } while (tp != NULL); #endif From 164f4a64878495861bdce157b9763f8bef8b3ad2 Mon Sep 17 00:00:00 2001 From: DiSlord Date: Sun, 16 May 2021 08:28:13 +0300 Subject: [PATCH 22/24] Fix typo Not init DAC2 if enabled brightness control --- main.c | 26 +++++++++----------------- 1 file changed, 9 insertions(+), 17 deletions(-) diff --git a/main.c b/main.c index c68d48f..43bf6b1 100644 --- a/main.c +++ b/main.c @@ -2046,9 +2046,8 @@ static const I2CConfig i2ccfg = { }; #endif -static DACConfig dac1cfg1 = { - //init: 2047U, - init: 1922U, +static const DACConfig dac1cfg1 = { + init: 0, datamode: DAC_DHRM_12BIT_RIGHT }; @@ -2224,18 +2223,7 @@ int main(void) shell_init_connection(); -#ifdef TINYSA4 - dac1cfg1.init = config.dac_value; -#else - dac1cfg1.init = 0; -#endif -/* - * Starting DAC1 driver, setting up the output pin as analog as suggested - * by the Reference Manual. - */ - dacStart(&DACD2, &dac1cfg1); - dacStart(&DACD1, &dac1cfg1); set_sweep_points(POINTS_COUNT); @@ -2279,11 +2267,16 @@ int main(void) ui_mode_normal(); /* - * Set LCD display brightness + * Set LCD display brightness (use DAC2 for control) + * Starting DAC1 driver, setting up the output pin as analog as suggested by the Reference Manual. */ #ifdef __LCD_BRIGHTNESS__ lcd_setBrightness(config._brightness); + #else + dacStart(&DACD2, &dac1cfg1); + dacPutChannelX(&DACD2, 0, config.dac_value); #endif + dacStart(&DACD1, &dac1cfg1); chThdCreateStatic(waThread1, sizeof(waThread1), NORMALPRIO-1, Thread1, NULL); @@ -2351,7 +2344,6 @@ void hard_fault_handler_c(uint32_t *sp) uint32_t psr = sp[7]; int y = 0; int x = OFFSETX + 1; - static char buf[96]; ili9341_set_background(LCD_BG_COLOR); ili9341_set_foreground(LCD_FG_COLOR); lcd_printf(x, y+=FONT_STR_HEIGHT, "SP 0x%08x", (uint32_t)sp); @@ -2384,7 +2376,7 @@ void hard_fault_handler_c(uint32_t *sp) #else uint32_t stklimit = 0U; #endif - lcd_printf(buf, x, y+=FONT_STR_HEIGHT, "%08x|%08x|%08x|%08x|%4u|%4u|%9s|%12s", + lcd_printf(x, y+=FONT_STR_HEIGHT, "%08x|%08x|%08x|%08x|%4u|%4u|%9s|%12s", stklimit, (uint32_t)tp->ctx.sp, max_stack_use, (uint32_t)tp, (uint32_t)tp->refs - 1, (uint32_t)tp->prio, states[tp->state], tp->name == NULL ? "" : tp->name); From b2878e5a9edc5be6a89adbd64bdf8c2fa7ecdfb3 Mon Sep 17 00:00:00 2001 From: DiSlord Date: Sun, 16 May 2021 08:48:21 +0300 Subject: [PATCH 23/24] use cell_printf on selftest --- sa_core.c | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/sa_core.c b/sa_core.c index cee5538..ef05dd2 100644 --- a/sa_core.c +++ b/sa_core.c @@ -4714,7 +4714,6 @@ static void test_acquire(int i) } int cell_printf(int16_t x, int16_t y, const char *fmt, ...); -static char self_test_status_buf[35]; void cell_draw_test_info(int x0, int y0) { #define INFO_SPACING 13 @@ -4726,27 +4725,28 @@ void cell_draw_test_info(int x0, int y0) i++; int xpos = 25 - x0; int ypos = 50+i*INFO_SPACING - y0; - unsigned int color = LCD_FG_COLOR; + pixel_t color; + if (i < 0) + color = LCD_FG_COLOR; + else if (test_status[i] == TS_PASS) + color = LCD_BRIGHT_COLOR_GREEN; + else if (test_status[i] == TS_CRITICAL) + color = LCD_TRACE_3_COLOR; // Yellow + else if (test_status[i] == TS_FAIL) + color = LCD_BRIGHT_COLOR_RED; + else + color = LCD_BRIGHT_COLOR_BLUE; + ili9341_set_foreground(color); if (i == -1) { - plot_printf(self_test_status_buf, sizeof self_test_status_buf, FONT_s"Self test status:"); + cell_printf(xpos, ypos, FONT_s"Self test status:"); } else if (test_case[i].kind == TC_END) { if (test_wait) - plot_printf(self_test_status_buf, sizeof self_test_status_buf, FONT_s"Touch screen to continue"); - else - self_test_status_buf[0] = 0; + cell_printf(xpos, ypos, FONT_s"Touch screen to continue"); + continue; } else { - plot_printf(self_test_status_buf, sizeof self_test_status_buf, FONT_s"Test %d: %s%s", i+1, test_fail_cause[i], test_text[test_status[i]] ); - if (test_status[i] == TS_PASS) - color = LCD_BRIGHT_COLOR_GREEN; - else if (test_status[i] == TS_CRITICAL) - color = LCD_TRACE_3_COLOR; // Yellow - else if (test_status[i] == TS_FAIL) - color = LCD_BRIGHT_COLOR_RED; - else - color = LCD_BRIGHT_COLOR_BLUE; + cell_printf(xpos, ypos, FONT_s"Test %d: %s%s", i+1, test_fail_cause[i], test_text[test_status[i]] ); + continue; } - ili9341_set_foreground(color); - cell_printf(xpos, ypos, self_test_status_buf); } while (test_case[i].kind != TC_END); } From 41eac5bce709e5ecfaa88d2f910c590b3e9f6035 Mon Sep 17 00:00:00 2001 From: DiSlord Date: Sun, 16 May 2021 10:58:47 +0300 Subject: [PATCH 24/24] Use timer macros --- adc.c | 2 +- adc_F303.c | 2 +- nanovna.h | 2 ++ sa_core.c | 8 ++++---- si4432.c | 4 ++-- si4468.c | 2 +- 6 files changed, 11 insertions(+), 9 deletions(-) diff --git a/adc.c b/adc.c index a55b4a8..d61068f 100644 --- a/adc.c +++ b/adc.c @@ -80,7 +80,7 @@ int16_t adc_vbat_read(void) // Vbat measure averange count = 2^VBAT_AVERAGE #define VBAT_AVERAGE 4 // Measure vbat every 5 second -#define VBAT_MEASURE_INTERVAL 50000 +#define VBAT_MEASURE_INTERVAL S2ST(5) static int16_t vbat_raw = 0; static systime_t vbat_time = -VBAT_MEASURE_INTERVAL-1; diff --git a/adc_F303.c b/adc_F303.c index 8cbfdc7..9691b80 100644 --- a/adc_F303.c +++ b/adc_F303.c @@ -96,7 +96,7 @@ int16_t adc_vbat_read(void) // Vbat measure averange count = 2^VBAT_AVERAGE #define VBAT_AVERAGE 4 // Measure vbat every 5 second -#define VBAT_MEASURE_INTERVAL 50000 +#define VBAT_MEASURE_INTERVAL S2ST(5) static int16_t vbat_raw = 0; static systime_t vbat_time = -VBAT_MEASURE_INTERVAL-1; diff --git a/nanovna.h b/nanovna.h index f04bfc0..75a0832 100644 --- a/nanovna.h +++ b/nanovna.h @@ -1444,6 +1444,8 @@ enum { T_AUTO, T_NORMAL, T_SINGLE, T_DONE, T_UP, T_DOWN, T_MODE, T_PRE, T_POST, T_MID }; +//!!! Warning can show not correct results on CH_CFG_ST_FREQUENCY not round by 1000 or > 1000000UL +#define sa_ST2US(n) ((n)*(1000000UL/(CH_CFG_ST_FREQUENCY))) extern const uint8_t SI4432_RBW_count; extern void SI4432_Listen(int s); diff --git a/sa_core.c b/sa_core.c index ef05dd2..92b174a 100644 --- a/sa_core.c +++ b/sa_core.c @@ -3427,7 +3427,7 @@ again: // Spur redu // i = 1; // Everything set so skip LO setting #define MODULATION_CYCLES_TEST 10000 if (in_selftest && modulation_count_iter++ >= 10000) { - start_of_sweep_timestamp = (chVTGetSystemTimeX() - start_of_sweep_timestamp)*MODULATION_STEPS*100/MODULATION_CYCLES_TEST; // uS per cycle + start_of_sweep_timestamp = sa_ST2US(chVTGetSystemTimeX() - start_of_sweep_timestamp)*MODULATION_STEPS/MODULATION_CYCLES_TEST; // uS per cycle return 0; } goto modulation_again; // Keep repeating sweep loop till user aborts by input @@ -3761,7 +3761,7 @@ static bool sweep(bool break_on_operation) } } } - systime_t local_sweep_time = (chVTGetSystemTimeX() - start_of_sweep_timestamp)*100 ; + systime_t local_sweep_time = sa_ST2US(chVTGetSystemTimeX() - start_of_sweep_timestamp); if (setting.actual_sweep_time_us > ONE_SECOND_TIME) local_sweep_time = setting.actual_sweep_time_us; if (show_bar && (( local_sweep_time > ONE_SECOND_TIME && (i & 0x07) == 0) || ( local_sweep_time > ONE_SECOND_TIME*10)) ) @@ -4002,7 +4002,7 @@ static bool sweep(bool break_on_operation) // ---------------------- process measured actual sweep time ----------------- // For CW mode value calculated in SI4432_Fill if (setting.measure_sweep_time_us == 0) - setting.measure_sweep_time_us = (chVTGetSystemTimeX() - start_of_sweep_timestamp) * 100; + setting.measure_sweep_time_us = sa_ST2US(chVTGetSystemTimeX() - start_of_sweep_timestamp); // Update actual time on change on status panel uint32_t delta = abs((int)(setting.actual_sweep_time_us - setting.measure_sweep_time_us)); @@ -4104,7 +4104,7 @@ static bool sweep(bool break_on_operation) } else if (actual_max_level > target_level && setting.attenuate_x2 < 60) { delta = actual_max_level - target_level; } - if ((chVTGetSystemTimeX() - sweep_elapsed > 10000 && ( delta < -5 || delta > +5)) || delta > 10 ) { + if ((chVTGetSystemTimeX() - sweep_elapsed > MS2ST(1000) && ( delta < -5 || delta > +5)) || delta > 10 ) { setting.attenuate_x2 += delta + delta; if (setting.attenuate_x2 < 0) setting.attenuate_x2= 0; diff --git a/si4432.c b/si4432.c index 6fd8c27..88b07d0 100644 --- a/si4432.c +++ b/si4432.c @@ -593,7 +593,7 @@ void SI4432_trigger_fill(int s, uint8_t trigger_lvl, int up_direction, int trigg case ST_ARMING: if (i == sweep_points-1) { waiting = ST_WAITING; - setting.measure_sweep_time_us = (chVTGetSystemTimeX() - measure)*100; + setting.measure_sweep_time_us = sa_ST2US(chVTGetSystemTimeX() - measure); } break; case ST_WAITING: @@ -674,7 +674,7 @@ void SI4432_Fill(int s, int start) shiftInBuf(sel, SI4432_REG_RSSI, &age[start], sweep_points - start, t); #endif // __enable_irq(); - setting.measure_sweep_time_us = (chVTGetSystemTimeX() - measure)*100; + setting.measure_sweep_time_us = sa_ST2US(chVTGetSystemTimeX() - measure); buf_index = start; // Is used to skip 1st entry during level triggering buf_end = sweep_points - 1; buf_read = true; diff --git a/si4468.c b/si4468.c index dd3ff32..7f589f7 100644 --- a/si4468.c +++ b/si4468.c @@ -1276,7 +1276,7 @@ void SI446x_Fill(int s, int start) } while(1); __enable_irq(); - setting.measure_sweep_time_us = (chVTGetSystemTimeX() - measure)*100; + setting.measure_sweep_time_us = sa_ST2US(chVTGetSystemTimeX() - measure); buf_index = (start<=0 ? 0 : start); // Is used to skip 1st entry during level triggering buf_read = true; }