From 4d6a6ae7dfcf18fa9ab54e8b4741b464632433a6 Mon Sep 17 00:00:00 2001 From: DiSlord Date: Sun, 16 May 2021 15:30:16 +0300 Subject: [PATCH 01/18] Skip %c char if input zero --- chprintf.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/chprintf.c b/chprintf.c index a149a86..0b24e38 100644 --- a/chprintf.c +++ b/chprintf.c @@ -350,7 +350,8 @@ int chvprintf(BaseSequentialStream *chp, const char *fmt, va_list ap) { switch (c) { case 'c': state&=~PAD_ZERO; - *p++ = va_arg(ap, int); + c = va_arg(ap, int); + if (c) *p++ = c; break; case 's': state&=~PAD_ZERO; From 80e4c06ef42e1cc42de7d4fd73dfb2824b7ed88b Mon Sep 17 00:00:00 2001 From: DiSlord Date: Sun, 16 May 2021 16:32:20 +0300 Subject: [PATCH 02/18] Cleanup draw_cal_status code, use lcd_printf --- ui_sa.c | 189 +++++++++++++++++++------------------------------------- 1 file changed, 62 insertions(+), 127 deletions(-) diff --git a/ui_sa.c b/ui_sa.c index c7ff5d9..527ef23 100644 --- a/ui_sa.c +++ b/ui_sa.c @@ -3195,9 +3195,8 @@ int invoke_quick_menu(int y) } #define YSTEP 8 -int add_quick_menu(char *buf, int x, int y, menuitem_t *menu) +int add_quick_menu(int y, menuitem_t *menu) { - ili9341_drawstring(buf, x, y); y += YSTEP*item_space/2 + YSTEP; if (max_quick_menu 0.9 && t < 1.1){ - plot_printf(buf, BLEN, "%s%c/",scale_vtext[i],unit_scale_text[setting.unit_scale_index]); + lcd_printf(x, y, "%s%c/",scale_vtext[i],unit_scale_text[setting.unit_scale_index]); break; } i++; } #else - plot_printf(buf, BLEN, "%.2F/",setting.scale); + lcd_printf(x, y, "%.2F/",setting.scale); #endif - y = add_quick_menu(buf, x, y, (menuitem_t *)KM_SCALE); + y = add_quick_menu(y, (menuitem_t *)KM_SCALE); // Trigger status if (is_paused()) { - color = LCD_BRIGHT_COLOR_GREEN; - ili9341_set_foreground(color); + ili9341_set_foreground(LCD_BRIGHT_COLOR_GREEN); ili9341_drawstring("PAUSED", x, y); y += YSTEP + YSTEP/2 ; } if (setting.trigger == T_SINGLE || setting.trigger == T_NORMAL ) { - color = LCD_BRIGHT_COLOR_GREEN; - ili9341_set_foreground(color); + ili9341_set_foreground(LCD_BRIGHT_COLOR_GREEN); ili9341_drawstring("ARMED", x, y); y += YSTEP + YSTEP/2 ; } // AM warning if (signal_is_AM) { - color = LCD_BRIGHT_COLOR_RED; - ili9341_set_foreground(color); + ili9341_set_foreground(LCD_BRIGHT_COLOR_RED); ili9341_drawstring("AM", x, y); y += YSTEP + YSTEP/2 ; } @@ -3309,66 +3302,42 @@ redraw_cal_status: // if (setting.mode == M_LOW) { // Attenuation - if (setting.auto_attenuation) - color = LCD_FG_COLOR; - else - color = LCD_BRIGHT_COLOR_GREEN; - ili9341_set_foreground(color); - ili9341_drawstring("Atten:", x, y); - y += YSTEP; - plot_printf(buf, BLEN, "%.2FdB", get_attenuation()); - y = add_quick_menu(buf, x, y, (menuitem_t *)menu_atten); + ili9341_set_foreground(setting.auto_attenuation ? LCD_BRIGHT_COLOR_GREEN : LCD_FG_COLOR); + lcd_printf(x, y, "Atten:\n%4.2FdB", get_attenuation()); + y = add_quick_menu(y+= YSTEP, (menuitem_t *)menu_atten); // } // Calc if (setting.average>0) { ili9341_set_foreground(LCD_BRIGHT_COLOR_GREEN); - ili9341_drawstring("Calc:", x, y); - y += YSTEP; - plot_printf(buf, BLEN, "%s",averageText[setting.average]); - y = add_quick_menu(buf, x, y, (menuitem_t *)menu_average); + lcd_printf(x, y, "Calc:\n%s", averageText[setting.average]); + y = add_quick_menu(y+= YSTEP, (menuitem_t *)menu_average); } // Spur #ifdef __SPUR__ if (setting.spur_removal != S_OFF) { - if (setting.spur_removal == S_ON) - color = LCD_BRIGHT_COLOR_GREEN; - else - color = LCD_FG_COLOR; - ili9341_set_foreground(color); - - ili9341_drawstring("Spur:", x, y); - y += YSTEP; - if (S_IS_AUTO(setting.spur_removal)) - y = add_quick_menu("AUTO", x, y, (menuitem_t *)menu_stimulus); - else - y = add_quick_menu("ON", x, y, (menuitem_t *)menu_stimulus); + ili9341_set_foreground(setting.spur_removal == S_ON ? LCD_BRIGHT_COLOR_GREEN : LCD_FG_COLOR); + lcd_printf(x, y, "Spur:\n%s", S_IS_AUTO(setting.spur_removal) ? "AUTO" : "ON"); + y = add_quick_menu(y += YSTEP, (menuitem_t *)menu_stimulus); } if (setting.mirror_masking) { ili9341_set_foreground(LCD_BRIGHT_COLOR_GREEN); - ili9341_drawstring("Mask:", x, y); - - y += YSTEP; - y = add_quick_menu("ON", x, y, (menuitem_t *)menu_stimulus); + ili9341_drawstring("Mask:\nON", x, y); + y = add_quick_menu(y+=YSTEP, (menuitem_t *)menu_stimulus); } #endif if (setting.subtract_stored) { ili9341_set_foreground(LCD_BRIGHT_COLOR_GREEN); - y = add_quick_menu("Norm.", x, y, (menuitem_t *)menu_storage); + ili9341_drawstring("Norm.", x, y); + y = add_quick_menu(y, (menuitem_t *)menu_storage); } // RBW - if (setting.rbw_x10) - color = LCD_BRIGHT_COLOR_GREEN; - else - color = LCD_FG_COLOR; - ili9341_set_foreground(color); + ili9341_set_foreground(setting.rbw_x10 ? LCD_BRIGHT_COLOR_GREEN : LCD_FG_COLOR); if (dirty) update_rbw(); - ili9341_drawstring("RBW:", x, y); - y += YSTEP; - plot_printf(buf, BLEN, "%.1FHz", actual_rbw_x10*100.0); - y = add_quick_menu(buf, x, y,(menuitem_t *)menu_rbw); + lcd_printf(x, y, "RBW:\n%.1FHz", actual_rbw_x10*100.0); + y = add_quick_menu(y+=YSTEP, (menuitem_t *)menu_rbw); #ifdef __VBW__ // VBW @@ -3381,41 +3350,22 @@ redraw_cal_status: vbw = 10; } ili9341_set_foreground(color); - ili9341_drawstring("VBW:", x, y); - y += YSTEP; - plot_printf(buf, BLEN, "%.1FHz", actual_rbw_x10*100.0 *vbw/10.0); - y = add_quick_menu(buf, x, y,(menuitem_t *)menu_vbw); + lcd_printf(x, y, "VBW:\n%.1FHz", actual_rbw_x10*100.0 *vbw/10.0); + y = add_quick_menu(y+=YSTEP, (menuitem_t *)menu_vbw); } #endif - // Sweep time - if (setting.step_delay != 0) - color = LCD_BRIGHT_COLOR_GREEN; - else - color = LCD_FG_COLOR; - ili9341_set_foreground(color); - buf[0] = ' '; - strcpy(&buf[1],"Scan:"); - if (setting.step_delay_mode == SD_PRECISE) - buf[0] = 'P'; - else if (setting.step_delay_mode == SD_FAST) - buf[0] = 'F'; - else - strcpy(&buf[0],"Scan:"); - ili9341_drawstring(buf, x, y); - + // Sweep time: SD_NORMAL, SD_PRECISE, SD_FAST, SD_MANUAL + static const char fscan[]={0, 'P', 'F', 'M'}; if (dirty) { calculate_step_delay(); setting.actual_sweep_time_us = calc_min_sweep_time_us(); } - + ili9341_set_foreground(setting.step_delay ? LCD_BRIGHT_COLOR_GREEN : LCD_FG_COLOR); #if 0 // Activate for sweep time debugging - y += YSTEP; - plot_printf(buf, BLEN, "%5.3Fs", (float)setting.sweep_time_us/ONE_SECOND_TIME); - ili9341_drawstring(buf, x, y); + lcd_printf(x, y, "%cScan:\n%5.3Fs", fscan[setting.step_delay_mode&3], (float)setting.sweep_time_us/ONE_SECOND_TIME); #endif - y += YSTEP; - plot_printf(buf, BLEN, "%5.3Fs", (float)setting.actual_sweep_time_us/ONE_SECOND_TIME); - y = add_quick_menu(buf, x, y, (menuitem_t *)menu_sweep_speed); + lcd_printf(x, y, "%cScan:\n%5.3Fs", fscan[setting.step_delay_mode&3], (float)setting.actual_sweep_time_us/ONE_SECOND_TIME); + y = add_quick_menu(y+=YSTEP, (menuitem_t *)menu_sweep_speed); #if 0 // Activate for sweep time debugging @@ -3423,47 +3373,38 @@ redraw_cal_status: update_rbw(); // To ensure the calc_min_sweep time shown takes the latest delay into account calculate_step_delay(); uint32_t t = calc_min_sweep_time_us(); - plot_printf(buf, BLEN, "%5.3Fs", (float)t/ONE_SECOND_TIME); - ili9341_drawstring(buf, x, y); + lcd_printf(x, y, "%5.3Fs", (float)t/ONE_SECOND_TIME); y += YSTEP; - plot_printf(buf, BLEN, "%5.3Fs", (float)setting.additional_step_delay_us/ONE_SECOND_TIME); - ili9341_drawstring(buf, x, y); + lcd_printf(x, y, "%5.3Fs", (float)setting.additional_step_delay_us/ONE_SECOND_TIME); y += YSTEP + YSTEP/2 ; #endif #ifdef TINYSA4 if (setting.extra_lna){ ili9341_set_foreground(LCD_BRIGHT_COLOR_GREEN); - y = add_quick_menu("LNA:ON", x, y, (menuitem_t *)menu_level); + lcd_printf(x, y, "LNA:ON"); + y = add_quick_menu(y, (menuitem_t *)menu_level); y += YSTEP; } #endif // Cal output if (setting.refer >= 0) { ili9341_set_foreground(LCD_BRIGHT_COLOR_GREEN); - ili9341_drawstring("Ref:", x, y); - y += YSTEP; - plot_printf(buf, BLEN, "%dMHz",reffer_freq[setting.refer]/1000000); - buf[6]=0; - y = add_quick_menu(buf, x, y,(menuitem_t *)menu_reffer); + lcd_printf(x, y, "Ref:\n%dMHz",reffer_freq[setting.refer]/1000000); + y = add_quick_menu(y+=YSTEP, (menuitem_t *)menu_reffer); } // Offset if (setting.external_gain != 0.0) { ili9341_set_foreground(LCD_BRIGHT_COLOR_GREEN); - ili9341_drawstring("Amp:", x, y); - y += YSTEP; - plot_printf(buf, BLEN, "%.1fdB",setting.external_gain); - y = add_quick_menu(buf, x, y,(menuitem_t *)KM_EXT_GAIN); + lcd_printf(x, y, "Amp:\n%4.1fdB",setting.external_gain); + y = add_quick_menu(y+=YSTEP, (menuitem_t *)KM_EXT_GAIN); } // Repeat if (setting.repeat != 1) { ili9341_set_foreground(LCD_BRIGHT_COLOR_GREEN); - ili9341_drawstring("Repeat:", x, y); - y += YSTEP; - plot_printf(buf, BLEN, "%d",setting.repeat); - buf[6]=0; - y = add_quick_menu(buf, x, y,(menuitem_t *)KM_REPEAT); + lcd_printf(x, y, "Repeat\n x%d", setting.repeat); + y = add_quick_menu(y+=YSTEP,( menuitem_t *)KM_REPEAT); } // Trigger @@ -3477,19 +3418,15 @@ redraw_cal_status: y += YSTEP; if (rounding) - plot_printf(buf, BLEN, "%4f", value(setting.trigger_level)); + lcd_printf(x, y, "%6.3f", value(setting.trigger_level)); else - plot_printf(buf, BLEN, "%.4F", value(setting.trigger_level)); -// plot_printf(buf, BLEN, "%4f", value(setting.trigger_level)/setting.unit_scale); - y = add_quick_menu(buf, x, y,(menuitem_t *)menu_trigger); + lcd_printf(x, y, "%6.4F", value(setting.trigger_level)); +// lcd_printf(x, y, "%4f", value(setting.trigger_level)/setting.unit_scale); + y = add_quick_menu(y,(menuitem_t *)menu_trigger); } // Mode - if (level_is_calibrated()) - color = LCD_BRIGHT_COLOR_GREEN; - else - color = LCD_BRIGHT_COLOR_RED; - ili9341_set_foreground(color); + ili9341_set_foreground(level_is_calibrated() ? LCD_BRIGHT_COLOR_GREEN : LCD_BRIGHT_COLOR_RED); ili9341_drawstring_7x13(MODE_LOW(setting.mode) ? "LOW" : "HIGH", x, y); // Compact status string @@ -3551,11 +3488,6 @@ redraw_cal_status: if (!setting.waterfall) { // Do not draw bottom level if in waterfall mode // Bottom level y = area_height + OFFSETY; - if (rounding) - plot_printf(buf, BLEN, "%4d", (int)(yMax - setting.scale * NGRIDY)); - else - plot_printf(buf, BLEN, "%+4.3F", ((yMax - setting.scale * NGRIDY)/setting.unit_scale)); - // buf[5]=0; if (level_is_calibrated()) if (setting.auto_reflevel) color = LCD_FG_COLOR; @@ -3564,8 +3496,11 @@ redraw_cal_status: else color = LCD_BRIGHT_COLOR_RED; ili9341_set_foreground(color); - y = add_quick_menu(buf, x, y,(menuitem_t *)menu_average); -// ili9341_drawstring(buf, x, y); + if (rounding) + lcd_printf(x, y, "%4d", (int)(yMax - setting.scale * NGRIDY)); + else + lcd_printf(x, y, "%+4.3F", ((yMax - setting.scale * NGRIDY)/setting.unit_scale)); + y = add_quick_menu(y,(menuitem_t *)menu_average); } } From f76ef7a6b0b36ed1603043ac492281aae4f50caa Mon Sep 17 00:00:00 2001 From: DiSlord Date: Sun, 16 May 2021 17:58:39 +0300 Subject: [PATCH 03/18] Cleanup --- ui.c | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/ui.c b/ui.c index 2f3b054..3669a2d 100644 --- a/ui.c +++ b/ui.c @@ -1349,8 +1349,6 @@ static const uint8_t check_box[] = { _BMP16(0b0000100001000000), _BMP16(0b0000011110000000), }; -static const char *step_text[5] = {"-10dB", "-1dB", "set", "+1dB", "+10dB"}; -static char step_text_freq[5][10] = { "-100MHz", "-10MHz", "set", "+10MHz", "+100MHz" }; #ifndef MENU_USE_AUTOHEIGHT #ifdef TINYSA4 @@ -1443,19 +1441,19 @@ draw_menu_buttons(const menuitem_t *menu, int only) local_text_shift = 2; if (menu[i].data == KM_CENTER) { local_slider_positions = LCD_WIDTH/2+setting.slider_position; - plot_printf(step_text_freq[0], sizeof step_text_freq[0], "-%3.0FHz", (float)setting.slider_span); - plot_printf(step_text_freq[1], sizeof step_text_freq[1], "-%3.0FHz", (float)setting.slider_span/10); - plot_printf(step_text_freq[3], sizeof step_text_freq[3], "+%3.0FHz", (float)setting.slider_span/10); - plot_printf(step_text_freq[4], sizeof step_text_freq[4], "+%3.0FHz", (float)setting.slider_span); - for (int i=0; i <= 4; i++) { - ili9341_drawstring(step_text_freq[i], button_start+12 + i * MENU_FORM_WIDTH/5, y+button_height-9); - } + lcd_printf(button_start+12 + 0 * MENU_FORM_WIDTH/5, y+button_height-9, "%+3.0FHz", -(float)setting.slider_span); + lcd_printf(button_start+12 + 1 * MENU_FORM_WIDTH/5, y+button_height-9, "%+3.0FHz", -(float)setting.slider_span/10); + lcd_printf(button_start+12 + 2 * MENU_FORM_WIDTH/5, y+button_height-9, "Set"); + lcd_printf(button_start+12 + 3 * MENU_FORM_WIDTH/5, y+button_height-9, "%+3.0FHz", (float)setting.slider_span/10); + lcd_printf(button_start+12 + 4 * MENU_FORM_WIDTH/5, y+button_height-9, "%+3.0FHz", (float)setting.slider_span); goto draw_divider; } else if (menu[i].data == KM_LOWOUTLEVEL) { local_slider_positions = ((get_level() - level_min()) * (MENU_FORM_WIDTH-8)) / level_range() + OFFSETX+4; - for (int i=0; i <= 4; i++) { - ili9341_drawstring(step_text[i], button_start+12 + i * MENU_FORM_WIDTH/5, y+button_height-9); - } + lcd_printf(button_start+12 + 0 * MENU_FORM_WIDTH/5, y+button_height-9, "%+ddB", -10); + lcd_printf(button_start+12 + 1 * MENU_FORM_WIDTH/5, y+button_height-9, "%+ddB", -1); + lcd_printf(button_start+12 + 2 * MENU_FORM_WIDTH/5, y+button_height-9, "Set"); + lcd_printf(button_start+12 + 3 * MENU_FORM_WIDTH/5, y+button_height-9, "%+ddB", 1); + lcd_printf(button_start+12 + 4 * MENU_FORM_WIDTH/5, y+button_height-9, "%+ddB", 10); draw_divider: for (int i = 1; i <= 4; i++) { ili9341_line(button_start + i * MENU_FORM_WIDTH/5, y+button_height-9, button_start + i * MENU_FORM_WIDTH/5, y+button_height); From 7c0f8366f640c92034a58ffd6fd26f1f69f2f1c4 Mon Sep 17 00:00:00 2001 From: DiSlord Date: Sun, 16 May 2021 19:06:30 +0300 Subject: [PATCH 04/18] Remove --- NANOVNA_STM32_F072/mcuconf.h | 250 ----------------------------------- 1 file changed, 250 deletions(-) diff --git a/NANOVNA_STM32_F072/mcuconf.h b/NANOVNA_STM32_F072/mcuconf.h index 99f4609..241b42d 100644 --- a/NANOVNA_STM32_F072/mcuconf.h +++ b/NANOVNA_STM32_F072/mcuconf.h @@ -17,254 +17,6 @@ #ifndef MCUCONF_H #define MCUCONF_H -#ifdef TINYSA_F303 - -/* - * STM32F3xx drivers configuration. - * The following settings override the default settings present in - * the various device driver implementation headers. - * Note that the settings for each driver only have effect if the whole - * driver is enabled in halconf.h. - * - * IRQ priorities: - * 15...0 Lowest...Highest. - * - * DMA priorities: - * 0...3 Lowest...Highest. - */ - -#define STM32F3xx_MCUCONF - -/* - * HAL driver system settings. - */ -#define STM32_NO_INIT FALSE -#define STM32_PVD_ENABLE FALSE -#define STM32_PLS STM32_PLS_LEV0 -#if 0 // 72MHz -#define STM32_HSI_ENABLED FALSE -#define STM32_HSE_ENABLED TRUE -#define STM32_SW STM32_SW_PLL -#define STM32_PLLSRC STM32_PLLSRC_HSE -#define STM32_PREDIV_VALUE 1 -#define STM32_PLLMUL_VALUE 9 -#define STM32_USBPRE STM32_USBPRE_DIV1P5 -#else -#define STM32_HSI_ENABLED TRUE // 48MHz -#define STM32_HSE_ENABLED FALSE -#define STM32_SW STM32_SW_PLL -#define STM32_PLLSRC STM32_PLLSRC_HSI -#define STM32_PREDIV_VALUE 1 -#define STM32_PLLMUL_VALUE 12 // prediv HSI always 2 -#define STM32_USBPRE STM32_USBPRE_DIV1 -#endif -#define STM32_HPRE STM32_HPRE_DIV1 -#define STM32_PPRE1 STM32_PPRE1_DIV2 -// Set SPI1 more faster use PPRE2 max speed -#define STM32_PPRE2 STM32_PPRE2_DIV1 -#define STM32_MCOSEL STM32_MCOSEL_PLLDIV2 -#define STM32_ADC12PRES STM32_ADC12PRES_DIV2 -//#define STM32_ADC34PRES STM32_ADC34PRES_DIV1 -#define STM32_USART1SW STM32_USART1SW_PCLK -//#define STM32_USART2SW STM32_USART2SW_PCLK -//#define STM32_USART3SW STM32_USART3SW_PCLK -#define STM32_I2C1SW STM32_I2C1SW_SYSCLK -//#define STM32_I2C2SW STM32_I2C2SW_SYSCLK -#define STM32_TIM1SW STM32_TIM1SW_PCLK2 -#define STM32_TIM8SW STM32_TIM8SW_PCLK2 -#define STM32_USB_CLOCK_REQUIRED TRUE - -/* - * RTC driver system settings for stm32f303 - */ - -#ifndef VNA_USE_LSE -// Use 40kHz LSI -#define STM32_LSE_ENABLED FALSE -#define STM32_LSI_ENABLED TRUE -#define STM32_RTCSEL STM32_RTCSEL_LSI -#define STM32_RTC_PRESA_VALUE 40 -#define STM32_RTC_PRESS_VALUE 1000 -#else -// Use 32768Hz LSE -#define STM32_LSE_ENABLED TRUE -#define STM32_LSI_ENABLED FALSE -#define STM32_RTCSEL STM32_RTCSEL_LSE -#define STM32_RTC_PRESA_VALUE 32 -#define STM32_RTC_PRESS_VALUE 1024 -#define STM32_LSEDRV (3 << 3) -#endif - -/* - * ADC driver system settings. - */ -#define STM32_ADC_USE_ADC1 TRUE -#define STM32_ADC_USE_ADC2 TRUE -#define STM32_ADC_USE_ADC3 FALSE -#define STM32_ADC_ADC1_DMA_STREAM STM32_DMA_STREAM_ID(1, 1) -#define STM32_ADC_ADC2_DMA_STREAM STM32_DMA_STREAM_ID(2, 1) -//#define STM32_ADC_ADC3_DMA_STREAM STM32_DMA_STREAM_ID(2, 5) -//#define STM32_ADC_ADC4_DMA_STREAM STM32_DMA_STREAM_ID(2, 2) -#define STM32_ADC_ADC12_DMA_PRIORITY 2 -//#define STM32_ADC_ADC34_DMA_PRIORITY 2 -#define STM32_ADC_ADC12_IRQ_PRIORITY 2 -//#define STM32_ADC_ADC34_IRQ_PRIORITY 5 -#define STM32_ADC_ADC12_DMA_IRQ_PRIORITY 2 -//#define STM32_ADC_ADC34_DMA_IRQ_PRIORITY 5 -//#define STM32_ADC_ADC12_CLOCK_MODE ADC_CCR_CKMODE_ADCCK -//#define STM32_ADC_ADC12_CLOCK_MODE ADC_CCR_CKMODE_AHB_DIV2 -#define STM32_ADC_ADC12_CLOCK_MODE ADC_CCR_CKMODE_AHB_DIV1 -//#define STM32_ADC_ADC34_CLOCK_MODE ADC_CCR_CKMODE_AHB_DIV1 -#define STM32_ADC_DUAL_MODE FALSE - -/* - * CAN driver system settings. - */ -#define STM32_CAN_USE_CAN1 FALSE -#define STM32_CAN_CAN1_IRQ_PRIORITY 11 - -/* - * DAC driver system settings. - */ -#define STM32_DAC_DUAL_MODE FALSE -#define STM32_DAC_USE_DAC1_CH1 TRUE -#define STM32_DAC_USE_DAC1_CH2 TRUE -#define STM32_DAC_DAC1_CH1_IRQ_PRIORITY 10 -#define STM32_DAC_DAC1_CH2_IRQ_PRIORITY 10 -#define STM32_DAC_DAC1_CH1_DMA_PRIORITY 2 -#define STM32_DAC_DAC1_CH2_DMA_PRIORITY 2 - -/* - * EXT driver system settings. - */ -#define STM32_EXT_EXTI0_1_IRQ_PRIORITY 3 -#define STM32_EXT_EXTI2_3_IRQ_PRIORITY 3 -#define STM32_EXT_EXTI4_15_IRQ_PRIORITY 3 -#define STM32_EXT_EXTI16_IRQ_PRIORITY 3 -#define STM32_EXT_EXTI17_IRQ_PRIORITY 3 -#define STM32_EXT_EXTI21_22_IRQ_PRIORITY 3 - -#define STM32_DISABLE_EXTI2122_HANDLER TRUE - -/* - * GPT driver system settings. - */ -#define STM32_GPT_USE_TIM1 FALSE -#define STM32_GPT_USE_TIM2 FALSE -#define STM32_GPT_USE_TIM3 TRUE -#define STM32_GPT_USE_TIM4 TRUE -#define STM32_GPT_TIM1_IRQ_PRIORITY 2 -#define STM32_GPT_TIM2_IRQ_PRIORITY 2 -#define STM32_GPT_TIM3_IRQ_PRIORITY 2 -#define STM32_GPT_TIM4_IRQ_PRIORITY 2 - -/* - * I2C driver system settings. - */ -#define STM32_I2C_USE_I2C1 TRUE -#define STM32_I2C_USE_I2C2 FALSE -#define STM32_I2C_BUSY_TIMEOUT 50 -#define STM32_I2C_I2C1_IRQ_PRIORITY 3 -#define STM32_I2C_I2C2_IRQ_PRIORITY 3 -#define STM32_I2C_USE_DMA TRUE -#define STM32_I2C_I2C1_DMA_PRIORITY 1 -#define STM32_I2C_I2C2_DMA_PRIORITY 1 -#define STM32_I2C_DMA_ERROR_HOOK(i2cp) osalSysHalt("DMA failure") - -/* - * I2S driver system settings. - */ -#define STM32_I2S_USE_SPI1 FALSE -#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 | \ - STM32_I2S_MODE_RX ) -#define STM32_I2S_SPI1_IRQ_PRIORITY 2 -#define STM32_I2S_SPI2_IRQ_PRIORITY 2 -#define STM32_I2S_SPI1_DMA_PRIORITY 1 -#define STM32_I2S_SPI2_DMA_PRIORITY 1 -#define STM32_I2S_SPI1_RX_DMA_STREAM STM32_DMA_STREAM_ID(1, 2) -#define STM32_I2S_SPI1_TX_DMA_STREAM STM32_DMA_STREAM_ID(1, 3) -#define STM32_I2S_SPI2_RX_DMA_STREAM STM32_DMA_STREAM_ID(1, 4) -#define STM32_I2S_SPI2_TX_DMA_STREAM STM32_DMA_STREAM_ID(1, 5) -#define STM32_I2S_DMA_ERROR_HOOK(i2sp) osalSysHalt("DMA failure") - -/* - * ICU driver system settings. - */ -#define STM32_ICU_USE_TIM1 FALSE -#define STM32_ICU_USE_TIM2 FALSE -#define STM32_ICU_USE_TIM3 FALSE -#define STM32_ICU_TIM1_IRQ_PRIORITY 3 -#define STM32_ICU_TIM2_IRQ_PRIORITY 3 -#define STM32_ICU_TIM3_IRQ_PRIORITY 3 - -/* - * PWM driver system settings. - */ -#define STM32_PWM_USE_ADVANCED FALSE -#define STM32_PWM_USE_TIM1 FALSE -#define STM32_PWM_USE_TIM2 FALSE -#define STM32_PWM_USE_TIM3 FALSE -#define STM32_PWM_TIM1_IRQ_PRIORITY 3 -#define STM32_PWM_TIM2_IRQ_PRIORITY 3 -#define STM32_PWM_TIM3_IRQ_PRIORITY 3 - -/* - * SERIAL driver system settings. - */ -#define STM32_SERIAL_USE_USART1 TRUE -#define STM32_SERIAL_USE_USART2 FALSE -#define STM32_SERIAL_USART1_PRIORITY 3 -#define STM32_SERIAL_USART2_PRIORITY 3 - -/* - * SPI driver system settings. - */ -#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) -#define STM32_SPI_SPI1_TX_DMA_STREAM STM32_DMA_STREAM_ID(1, 3) -#define STM32_SPI_SPI1_DMA_PRIORITY 1 -#define STM32_SPI_SPI2_DMA_PRIORITY 1 -#define STM32_SPI_SPI1_IRQ_PRIORITY 2 -#define STM32_SPI_SPI2_IRQ_PRIORITY 2 -#define STM32_SPI_DMA_ERROR_HOOK(spip) osalSysHalt("DMA failure") - -/* - * ST driver system settings. - */ -#define STM32_ST_IRQ_PRIORITY 2 -#define STM32_ST_USE_TIMER 2 - -/* - * UART driver system settings. - */ -#define STM32_UART_USE_USART1 FALSE -#define STM32_UART_USE_USART2 FALSE -#define STM32_UART_USART1_IRQ_PRIORITY 3 -#define STM32_UART_USART2_IRQ_PRIORITY 3 -#define STM32_UART_USART1_DMA_PRIORITY 0 -#define STM32_UART_USART2_DMA_PRIORITY 0 -#define STM32_UART_USART3_DMA_PRIORITY 0 -#define STM32_UART_DMA_ERROR_HOOK(uartp) osalSysHalt("DMA failure") - -/* - * USB driver system settings. - */ -#define STM32_USB_USE_USB1 TRUE -#define STM32_USB_LOW_POWER_ON_SUSPEND FALSE -#define STM32_USB_USB1_LP_IRQ_PRIORITY 3 - -/* - * WDG driver system settings. - */ -#define STM32_WDG_USE_IWDG FALSE - -#else - /* * STM32F0xx drivers configuration. * The following settings override the default settings present in @@ -473,6 +225,4 @@ */ #define STM32_WDG_USE_IWDG FALSE -#endif - #endif /* MCUCONF_H */ From 4896804c6829c2a6aae71788bde76774e21d23d4 Mon Sep 17 00:00:00 2001 From: DiSlord Date: Sun, 16 May 2021 19:23:04 +0300 Subject: [PATCH 05/18] Revert --- sa_core.c | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/sa_core.c b/sa_core.c index 2263d96..f0caeb1 100644 --- a/sa_core.c +++ b/sa_core.c @@ -4105,17 +4105,6 @@ static volatile int dummy; } } // end of peak finding } - -#ifdef __NOFFT_DECONV__ - for (int i = sweep_points - 1 - d_width; i>0; i--) { - actual_t[i+d_width/2] = actual_t[i] + temp_t[0]; - } - for (int i = 0; i < d_width/2+2; i++) { - actual_t[i] = temp_t[0]; - actual_t[sweep_points - 1 - i] = temp_t[0]; - } -#endif - } From 0b30b84c454ae32da9dc03cb8fcc38f6f6bf079a Mon Sep 17 00:00:00 2001 From: DiSlord Date: Sun, 23 May 2021 16:02:28 +0300 Subject: [PATCH 06/18] Pin names --- NANOVNA_STM32_F303/board.h | 56 +++++++++++++++++++------------------- 1 file changed, 28 insertions(+), 28 deletions(-) diff --git a/NANOVNA_STM32_F303/board.h b/NANOVNA_STM32_F303/board.h index 84461c1..4c3cb8b 100644 --- a/NANOVNA_STM32_F303/board.h +++ b/NANOVNA_STM32_F303/board.h @@ -260,7 +260,7 @@ */ #define VAL_GPIOB_MODER (PIN_MODE_ANALOG(GPIOB_XN) | \ PIN_MODE_ANALOG(GPIOB_YN) | \ - PIN_MODE_OUTPUT(2) | \ + PIN_MODE_OUTPUT(GPIO_LCD_RESET) | \ PIN_MODE_ALTERNATE(GPIOB_SPI_SCLK) | \ PIN_MODE_ALTERNATE(GPIOB_SPI_MISO) | \ PIN_MODE_ALTERNATE(GPIOB_SPI_MOSI) | \ @@ -274,12 +274,12 @@ PIN_MODE_OUTPUT(13) | \ PIN_MODE_OUTPUT(14) | \ PIN_MODE_OUTPUT(15)) -#define VAL_GPIOB_OTYPER (PIN_OTYPE_PUSHPULL(0) | \ - PIN_OTYPE_PUSHPULL(1) | \ - PIN_OTYPE_PUSHPULL(2) | \ - PIN_OTYPE_PUSHPULL(3) | \ - PIN_OTYPE_PUSHPULL(4) | \ - PIN_OTYPE_PUSHPULL(5) | \ +#define VAL_GPIOB_OTYPER (PIN_OTYPE_PUSHPULL(GPIOB_XN) | \ + PIN_OTYPE_PUSHPULL(GPIOB_YN) | \ + PIN_OTYPE_PUSHPULL(GPIO_LCD_RESET) | \ + PIN_OTYPE_PUSHPULL(GPIOB_SPI_SCLK) | \ + PIN_OTYPE_PUSHPULL(GPIOB_SPI_MISO) | \ + PIN_OTYPE_PUSHPULL(GPIOB_SPI_MOSI) | \ PIN_OTYPE_PUSHPULL(6) | \ PIN_OTYPE_PUSHPULL(GPIO_SD_CD) | \ PIN_OTYPE_PUSHPULL(8) | \ @@ -292,12 +292,12 @@ PIN_OTYPE_PUSHPULL(15)) #define VAL_GPIOB_OSPEEDR (PIN_PUPDR_FLOATING(GPIOB_XN) | \ PIN_PUPDR_FLOATING(GPIOB_YN) | \ - PIN_OSPEED_100M(2) | \ - PIN_OSPEED_100M(3) | \ - PIN_OSPEED_100M(4) | \ - PIN_OSPEED_100M(5) | \ + PIN_OSPEED_100M(GPIO_LCD_RESET) | \ + PIN_OSPEED_100M(GPIOB_SPI_SCLK) | \ + PIN_OSPEED_100M(GPIOB_SPI_MISO) | \ + PIN_OSPEED_100M(GPIOB_SPI_MOSI) | \ PIN_OSPEED_100M(6) | \ - PIN_OSPEED_2M(GPIO_SD_CD) | \ + PIN_OSPEED_100M(GPIO_SD_CD) | \ PIN_OSPEED_100M(8) | \ PIN_OSPEED_100M(9) | \ PIN_OSPEED_100M(10) | \ @@ -306,12 +306,12 @@ PIN_OSPEED_100M(13) | \ PIN_OSPEED_100M(14) | \ PIN_OSPEED_2M(15)) -#define VAL_GPIOB_PUPDR (PIN_PUPDR_PULLUP(0) | \ - PIN_PUPDR_PULLUP(1) | \ - PIN_PUPDR_PULLUP(2) | \ - PIN_PUPDR_PULLUP(3) | \ - PIN_PUPDR_PULLUP(4) | \ - PIN_PUPDR_PULLUP(5) | \ +#define VAL_GPIOB_PUPDR (PIN_PUPDR_PULLUP(GPIOB_XN) | \ + PIN_PUPDR_PULLUP(GPIOB_YN) | \ + PIN_PUPDR_PULLUP(GPIO_LCD_RESET) | \ + PIN_PUPDR_PULLUP(GPIOB_SPI_SCLK) | \ + PIN_PUPDR_PULLUP(GPIOB_SPI_MISO) | \ + PIN_PUPDR_PULLUP(GPIOB_SPI_MOSI) | \ PIN_PUPDR_PULLUP(6) | \ PIN_PUPDR_PULLUP(GPIO_SD_CD) | \ PIN_PUPDR_PULLUP(8) | \ @@ -322,12 +322,12 @@ PIN_PUPDR_PULLUP(13) | \ PIN_PUPDR_PULLUP(14) | \ PIN_PUPDR_PULLUP(15)) -#define VAL_GPIOB_ODR (PIN_ODR_HIGH(0) | \ - PIN_ODR_HIGH(1) | \ - PIN_ODR_HIGH(2) | \ - PIN_ODR_HIGH(3) | \ - PIN_ODR_HIGH(4) | \ - PIN_ODR_HIGH(5) | \ +#define VAL_GPIOB_ODR (PIN_ODR_HIGH(GPIOB_XN) | \ + PIN_ODR_HIGH(GPIOB_YN) | \ + PIN_ODR_HIGH(GPIO_LCD_RESET) | \ + PIN_ODR_HIGH(GPIOB_SPI_SCLK) | \ + PIN_ODR_HIGH(GPIOB_SPI_MISO) | \ + PIN_ODR_HIGH(GPIOB_SPI_MOSI) | \ PIN_ODR_HIGH(6) | \ PIN_ODR_HIGH(GPIO_SD_CD) | \ PIN_ODR_HIGH(8) | \ @@ -338,12 +338,12 @@ PIN_ODR_HIGH(13) | \ PIN_ODR_HIGH(14) | \ PIN_ODR_HIGH(15)) -#define VAL_GPIOB_AFRL (PIN_AFIO_AF(0, 0) | \ - PIN_AFIO_AF(1, 0) | \ - PIN_AFIO_AF(2, 0) | \ +#define VAL_GPIOB_AFRL (PIN_AFIO_AF(GPIOB_XN, 0) | \ + PIN_AFIO_AF(GPIOB_YN, 0) | \ + PIN_AFIO_AF(GPIO_LCD_RESET, 0) | \ PIN_AFIO_AF(GPIOB_SPI_SCLK, 5) | \ - PIN_AFIO_AF(GPIOB_SPI_MOSI, 5) | \ PIN_AFIO_AF(GPIOB_SPI_MISO, 5) | \ + PIN_AFIO_AF(GPIOB_SPI_MOSI, 5) | \ PIN_AFIO_AF(6, 0) | \ PIN_AFIO_AF(GPIO_SD_CD, 0)) #define VAL_GPIOB_AFRH (PIN_AFIO_AF(8, 0) | \ From 8a3179a0e410c6f70565b870e67a4556bd4356a4 Mon Sep 17 00:00:00 2001 From: DiSlord Date: Sun, 23 May 2021 16:04:03 +0300 Subject: [PATCH 07/18] Code style Code cleanup Implement custom jog step feature --- main.c | 10 +- nanovna.h | 87 +++---------- sa_core.c | 1 + ui.c | 382 +++++------------------------------------------------- ui_sa.c | 102 ++++++++------- 5 files changed, 112 insertions(+), 470 deletions(-) diff --git a/main.c b/main.c index d228c74..5ee8256 100644 --- a/main.c +++ b/main.c @@ -28,13 +28,10 @@ #include #include -extern freq_t minFreq; -extern freq_t maxFreq; freq_t frequencyStart; freq_t frequencyStop; int32_t frequencyExtra; -#define START_MIN minFreq -#define STOP_MAX maxFreq + /* * Shell settings */ @@ -936,10 +933,7 @@ static const marker_t def_markers[MARKERS_MAX] = { void load_LCD_properties(void) { //Magic add on caldata_save -//current_props.magic = CONFIG_MAGIC; -// current_props._setting.frequency0 = 0; // start = 0Hz -// current_props._setting.frequency1 = 350000000; // end = 350MHz -// current_props._setting.frequency_IF= 433800000, +//setting.magic = CONFIG_MAGIC; setting._sweep_points = POINTS_COUNT; setting.trace_scale = 10.0; setting.trace_refpos = 0; diff --git a/nanovna.h b/nanovna.h index 328cb8a..aea920d 100644 --- a/nanovna.h +++ b/nanovna.h @@ -148,27 +148,30 @@ typedef uint32_t freq_t; typedef int32_t long_t; extern bool has_esd; -#define CORRECTION_POINTS 10 // Frequency dependent level correction table entries -#define CORRECTION_LOW 0 -#define CORRECTION_HIGH 1 -#define CORRECTION_SIZE 2 + #define CORRECTION_POINTS 10 // Frequency dependent level correction table entries + #define CORRECTION_LOW 0 + #define CORRECTION_HIGH 1 + #define CORRECTION_SIZE 2 #endif #ifdef TINYSA4 typedef uint64_t freq_t; typedef int64_t long_t; -#define CORRECTION_POINTS 20 // Frequency dependent level correction table entries -#define CORRECTION_LOW 0 -#define CORRECTION_LNA 1 -#define CORRECTION_LOW_OUT 2 -#define CORRECTION_HIGH 3 -#define CORRECTION_SIZE 4 - #endif - - + #define CORRECTION_POINTS 20 // Frequency dependent level correction table entries + #define CORRECTION_LOW 0 + #define CORRECTION_LNA 1 + #define CORRECTION_LOW_OUT 2 + #define CORRECTION_HIGH 3 + #define CORRECTION_SIZE 4 +#endif typedef float measurement_t[TRACES_MAX][POINTS_COUNT]; extern measurement_t measured; #endif +extern freq_t minFreq; +extern freq_t maxFreq; +#define START_MIN minFreq +#define STOP_MAX maxFreq + extern const char TINYSA_VERSION[]; #ifdef __REMOTE_DESKTOP__ @@ -178,63 +181,6 @@ extern int16_t mouse_y; extern uint8_t mouse_down; #endif -#ifdef __VNA__ -// Minimum frequency set -#define START_MIN 50000 -// Maximum frequency set -#define STOP_MAX 2700000000U -// Frequency offset (sin_cos table in dsp.c generated for this offset, if change need create new table) -#define FREQUENCY_OFFSET 5000 -// Speed of light const -#define SPEED_OF_LIGHT 299792458 -// pi const -#define VNA_PI 3.14159265358979323846 - -#define POINTS_COUNT 101 -extern float measured[2][POINTS_COUNT][2]; - -#define CAL_LOAD 0 -#define CAL_OPEN 1 -#define CAL_SHORT 2 -#define CAL_THRU 3 -#define CAL_ISOLN 4 - -#define CALSTAT_LOAD (1<<0) -#define CALSTAT_OPEN (1<<1) -#define CALSTAT_SHORT (1<<2) -#define CALSTAT_THRU (1<<3) -#define CALSTAT_ISOLN (1<<4) -#define CALSTAT_ES (1<<5) -#define CALSTAT_ER (1<<6) -#define CALSTAT_ET (1<<7) -#define CALSTAT_ED CALSTAT_LOAD -#define CALSTAT_EX CALSTAT_ISOLN -#define CALSTAT_APPLY (1<<8) -#define CALSTAT_INTERPOLATED (1<<9) - -#define ETERM_ED 0 /* error term directivity */ -#define ETERM_ES 1 /* error term source match */ -#define ETERM_ER 2 /* error term refrection tracking */ -#define ETERM_ET 3 /* error term transmission tracking */ -#define ETERM_EX 4 /* error term isolation */ - -#define DOMAIN_MODE (1<<0) -#define DOMAIN_FREQ (0<<0) -#define DOMAIN_TIME (1<<0) -#define TD_FUNC (0b11<<1) -#define TD_FUNC_BANDPASS (0b00<<1) -#define TD_FUNC_LOWPASS_IMPULSE (0b01<<1) -#define TD_FUNC_LOWPASS_STEP (0b10<<1) -#define TD_WINDOW (0b11<<3) -#define TD_WINDOW_NORMAL (0b00<<3) -#define TD_WINDOW_MINIMUM (0b01<<3) -#define TD_WINDOW_MAXIMUM (0b10<<3) - -#define FFT_SIZE 256 - -void cal_collect(int type); -void cal_done(void); -#endif #define MAX_FREQ_TYPE 5 enum stimulus_type { ST_START=0, ST_STOP, ST_CENTER, ST_SPAN, ST_CW, ST_DUMMY // Last is used in marker ops @@ -1053,6 +999,7 @@ typedef struct setting freq_t frequency_step; freq_t frequency0; freq_t frequency1; + freq_t frequency_var; freq_t frequency_IF; freq_t frequency_offset; #define FREQUENCY_SHIFT 100000000 // 100MHz upconversion maximum diff --git a/sa_core.c b/sa_core.c index 452cfc0..514b949 100644 --- a/sa_core.c +++ b/sa_core.c @@ -203,6 +203,7 @@ void reset_settings(int m) drive_dBm = (float *) (setting.mode == M_GENHIGH && config.high_out_adf4350 ? adf_drive_dBm : si_drive_dBm); #endif update_min_max_freq(); + setting.frequency_var = 0; sweep_mode |= SWEEP_ENABLE; setting.unit_scale_index = 0; setting.unit_scale = 1; diff --git a/ui.c b/ui.c index bd16950..0b11ad3 100644 --- a/ui.c +++ b/ui.c @@ -21,7 +21,6 @@ #include "hal.h" #include "chprintf.h" #include "nanovna.h" -//#include #include #include @@ -90,12 +89,6 @@ enum { UI_NORMAL, UI_MENU, UI_KEYPAD }; -#ifdef __VNA__ -enum { - KM_START, KM_STOP, KM_CENTER, KM_SPAN, KM_CW, KM_SCALE, KM_REFPOS, KM_EDELAY, KM_VELOCITY_FACTOR, KM_SCALEDELAY -}; -#endif - #define NUMINPUT_LEN 12 static uint8_t ui_mode = UI_NORMAL; static uint8_t keypad_mode; @@ -729,6 +722,7 @@ static UI_FUNCTION_CALLBACK(menu_marker_op_cb) static UI_FUNCTION_CALLBACK(menu_markers_reset_cb) { (void)item; + (void)data; markers_reset(); } @@ -953,114 +947,6 @@ menu_invoke(int item) draw_menu(); } -#ifdef __VNA__ -// Key names -#define KP_0 0 -#define KP_1 1 -#define KP_2 2 -#define KP_3 3 -#define KP_4 4 -#define KP_5 5 -#define KP_6 6 -#define KP_7 7 -#define KP_8 8 -#define KP_9 9 -#define KP_PERIOD 10 -#define KP_MINUS 11 -#define KP_X1 12 -#define KP_K 13 -#define KP_M 14 -#define KP_G 15 -#define KP_BS 16 -#define KP_INF 17 -#define KP_DB 18 -#define KP_PLUSMINUS 19 -#define KP_KEYPAD 20 -#define KP_N 21 -#define KP_P 22 - -typedef struct { - uint8_t x:4; - uint8_t y:4; - int8_t c; -} keypads_t; - -static const keypads_t *keypads; - -static const keypads_t keypads_freq[] = { - { 1, 3, KP_PERIOD }, - { 0, 3, KP_0 }, - { 0, 2, KP_1 }, - { 1, 2, KP_2 }, - { 2, 2, KP_3 }, - { 0, 1, KP_4 }, - { 1, 1, KP_5 }, - { 2, 1, KP_6 }, - { 0, 0, KP_7 }, - { 1, 0, KP_8 }, - { 2, 0, KP_9 }, - { 3, 0, KP_G }, - { 3, 1, KP_M }, - { 3, 2, KP_K }, - { 3, 3, KP_X1 }, - { 2, 3, KP_BS }, - { 0, 0, -1 } -}; - -static const keypads_t keypads_scale[] = { - { 1, 3, KP_PERIOD }, - { 0, 3, KP_0 }, - { 0, 2, KP_1 }, - { 1, 2, KP_2 }, - { 2, 2, KP_3 }, - { 0, 1, KP_4 }, - { 1, 1, KP_5 }, - { 2, 1, KP_6 }, - { 0, 0, KP_7 }, - { 1, 0, KP_8 }, - { 2, 0, KP_9 }, - { 3, 3, KP_X1 }, - { 2, 3, KP_BS }, - { 0, 0, -1 } -}; - -static const keypads_t keypads_time[] = { - { 1, 3, KP_PERIOD }, - { 0, 3, KP_0 }, - { 0, 2, KP_1 }, - { 1, 2, KP_2 }, - { 2, 2, KP_3 }, - { 0, 1, KP_4 }, - { 1, 1, KP_5 }, - { 2, 1, KP_6 }, - { 0, 0, KP_7 }, - { 1, 0, KP_8 }, - { 2, 0, KP_9 }, - { 3, 1, KP_N }, - { 3, 2, KP_P }, - { 3, 3, KP_MINUS }, - { 2, 3, KP_BS }, - { 0, 0, -1 } -}; - -static const keypads_t * const keypads_mode_tbl[] = { - keypads_freq, // start - keypads_freq, // stop - keypads_freq, // center - keypads_freq, // span - keypads_freq, // cw freq - keypads_scale, // scale - keypads_scale, // refpos - keypads_time, // electrical delay - keypads_scale, // velocity factor - keypads_time // scale of delay -}; - -static const char * const keypad_mode_label[] = { - "START", "STOP", "CENTER", "SPAN", "CW FREQ", "SCALE", "REFPOS", "EDELAY", "VELOCITY%", "DELAY" -}; -#endif - static const char * const keypad_scale_text[] = {"0", "1", "2", "5", "10", "20" , "50", "100", "200", "500"}; //static const int keypad_scale_value[] = { 1, 2, 5, 10, 20 , 50, 100, 200, 500}; @@ -1187,83 +1073,6 @@ draw_numeric_area_frame(void) draw_numeric_input(""); } -#ifdef __VNA__ -static void -menu_item_modify_attribute(const menuitem_t *menu, int item, - uint16_t *fg, uint16_t *bg) -{ - if (menu == menu_trace && item < TRACES_MAX) { - if (trace[item].enabled) - *bg = config.trace_color[item]; - } else if (menu == menu_marker_sel) { - if (item < 4) { - if (markers[item].enabled) { - *bg = LCD_MENU_TEXT_COLOR; - *fg = config.menu_normal_color; - } - } else if (item == 5) { - if (uistat.marker_delta) { - *bg = LCD_MENU_TEXT_COLOR; - *fg = config.menu_normal_color; - } - } - } else if (menu == menu_marker_search) { - if (item == 4 && uistat.marker_tracking) { - *bg = LCD_MENU_TEXT_COLOR; - *fg = config.menu_normal_color; - } - } else if (menu == menu_marker_smith) { - - if (marker_smith_format == item) { - *bg = LCD_MENU_TEXT_COLOR; - *fg = config.menu_normal_color; - } - } else if (menu == menu_calop) { - if ((item == 0 && (cal_status & CALSTAT_OPEN)) - || (item == 1 && (cal_status & CALSTAT_SHORT)) - || (item == 2 && (cal_status & CALSTAT_LOAD)) - || (item == 3 && (cal_status & CALSTAT_ISOLN)) - || (item == 4 && (cal_status & CALSTAT_THRU))) { - domain_mode = (domain_mode & ~DOMAIN_MODE) | DOMAIN_FREQ; - *bg = LCD_MENU_TEXT_COLOR; - *fg = config.menu_normal_color; - } - } else if (menu == menu_stimulus) { - if (item == 5 /* PAUSE */ && !(sweep_mode&SWEEP_ENABLE)) { - *bg = LCD_MENU_TEXT_COLOR; - *fg = config.menu_normal_color; - } - } else if (menu == menu_cal) { - if (item == 3 /* CORRECTION */ && (cal_status & CALSTAT_APPLY)) { - *bg = LCD_MENU_TEXT_COLOR; - *fg = config.menu_normal_color; - } - } else if (menu == menu_bandwidth) { - if (item == bandwidth) { - *bg = 0x0000; - *fg = 0xffff; - } - } else if (menu == menu_transform) { - if ((item == 0 && (domain_mode & DOMAIN_MODE) == DOMAIN_TIME) - || (item == 1 && (domain_mode & TD_FUNC) == TD_FUNC_LOWPASS_IMPULSE) - || (item == 2 && (domain_mode & TD_FUNC) == TD_FUNC_LOWPASS_STEP) - || (item == 3 && (domain_mode & TD_FUNC) == TD_FUNC_BANDPASS) - ) { - *bg = LCD_MENU_TEXT_COLOR; - *fg = config.menu_normal_color; - } - } else if (menu == menu_transform_window) { - if ((item == 0 && (domain_mode & TD_WINDOW) == TD_WINDOW_MINIMUM) - || (item == 1 && (domain_mode & TD_WINDOW) == TD_WINDOW_NORMAL) - || (item == 2 && (domain_mode & TD_WINDOW) == TD_WINDOW_MAXIMUM) - ) { - *bg = LCD_MENU_TEXT_COLOR; - *fg = config.menu_normal_color; - } - } -} -#endif - #ifndef __VNA__ extern void menu_item_modify_attribute( const menuitem_t *menu, int item, ui_button_t *button); @@ -1418,9 +1227,8 @@ draw_menu_buttons(const menuitem_t *menu, int only) 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(); + if (MT_MASK(menu[i].type) == MT_KEYPAD) { + fetch_numeric_target(menu[i].data); plot_printf(button.text, sizeof button.text, menu[i].label, uistat.text); text = button.text; } @@ -1556,8 +1364,7 @@ menu_select_touch(int i, int pos) if (dt > BUTTON_DOWN_LONG_TICKS) { touch_position(&touch_x, &touch_y); if (touch_x != prev_touch_x /* - 1 || prev_touch_x + 1 < touch_x */ ) { - keypad_mode = keypad; - fetch_numeric_target(); + fetch_numeric_target(keypad); int new_slider = touch_x - LCD_WIDTH/2; // Can have negative outcome if (new_slider < - (MENU_FORM_WIDTH-8)/2 - 1) new_slider = -(MENU_FORM_WIDTH-8)/2 - 1; @@ -1818,89 +1625,6 @@ leave_ui_mode() redraw_request|=REDRAW_AREA | REDRAW_FREQUENCY | REDRAW_CAL_STATUS | REDRAW_BATTERY; } -#ifdef __VNA__ -static void -fetch_numeric_target(void) -{ - switch (keypad_mode) { - case KM_START: - uistat.value = get_sweep_frequency(ST_START); - break; - case KM_STOP: - uistat.value = get_sweep_frequency(ST_STOP); - break; - case KM_CENTER: - uistat.value = get_sweep_frequency(ST_CENTER); - break; - case KM_SPAN: - uistat.value = get_sweep_frequency(ST_SPAN); - break; - case KM_CW: - uistat.value = get_sweep_frequency(ST_CW); - break; - case KM_SCALE: - uistat.value = get_trace_scale(uistat.current_trace) * 1000; - break; - case KM_REFPOS: - uistat.value = get_trace_refpos(uistat.current_trace) * 1000; - break; - case KM_EDELAY: - uistat.value = get_electrical_delay(); - break; - case KM_VELOCITY_FACTOR: - uistat.value = velocity_factor * 100; - break; - case KM_SCALEDELAY: - uistat.value = get_trace_scale(uistat.current_trace) * 1e12; - break; - } - - { - uint32_t x = uistat.value; - int n = 0; - for (; x >= 10 && n < 9; n++) - x /= 10; - uistat.digit = n; - } -// uistat.previous_value = uistat.value; -} - - -static void -set_numeric_value(void) -{ - switch (keypad_mode) { - case KM_START: - set_sweep_frequency(ST_START, uistat.value); - break; - case KM_STOP: - set_sweep_frequency(ST_STOP, uistat.value); - break; - case KM_CENTER: - set_sweep_frequency(ST_CENTER, uistat.value); - break; - case KM_SPAN: - set_sweep_frequency(ST_SPAN, uistat.value); - break; - case KM_CW: - set_sweep_frequency(ST_CW, uistat.value); - break; - case KM_SCALE: - set_trace_scale(uistat.current_trace, uistat.value / 1000.0); - break; - case KM_REFPOS: - set_trace_refpos(uistat.current_trace, uistat.value / 1000.0); - break; - case KM_EDELAY: - set_electrical_delay(uistat.value); - break; - case KM_VELOCITY_FACTOR: - velocity_factor = uistat.value/100.0; - break; - } -} -#endif - void ui_mode_menu(void) { @@ -2014,25 +1738,6 @@ step_round(freq_t v) return x * 5; } -static void -lever_zoom_span(int status) -{ - freq_t span = get_sweep_frequency(ST_SPAN); - if (uistat.auto_center_marker) { - freq_t freq = get_marker_frequency(active_marker); - search_maximum(active_marker, freq, 10 ); - if (freq != 0) - set_sweep_frequency(ST_CENTER, freq); - } - if (status & EVT_UP) { - span = step_round(span - 1); - } else if (status & EVT_DOWN) { - span = step_round(span + 1); - span = step_round(span * 3); - } - set_sweep_frequency(ST_SPAN, span); -} - static void lever_zoom_time(int status) { @@ -2051,35 +1756,30 @@ lever_zoom_time(int status) static void lever_move(int status, int mode) { - freq_t center = get_sweep_frequency(mode); - freq_t span = get_sweep_frequency(ST_SPAN); - span = step_round(span / 3); - if (status & EVT_UP) { - set_sweep_frequency(mode, center + span); - } else if (status & EVT_DOWN) { - set_sweep_frequency(mode, center - span); + freq_t freq = get_sweep_frequency(mode); + if (mode == ST_SPAN){ + if (uistat.auto_center_marker) { + freq = get_marker_frequency(active_marker); + search_maximum(active_marker, freq, 10 ); + if (freq == 0) return; + set_sweep_frequency(ST_CENTER, freq); + return; + } + if (status & EVT_UP ) freq = setting.frequency_var ? (freq + setting.frequency_var) : step_round(freq*4 + 1); + if (status & EVT_DOWN) freq = setting.frequency_var ? (freq - setting.frequency_var) : step_round(freq - 1); } + else { + freq_t span = setting.frequency_var ? setting.frequency_var : step_round(get_sweep_frequency(ST_SPAN) / 4); + if (status & EVT_UP ) freq+= span; + if (status & EVT_DOWN) freq-= span; + } + if (freq > STOP_MAX || freq < START_MIN) return; + set_sweep_frequency(mode, freq); } #define STEPRATIO 0.2 -#ifdef __VNA__ static void -lever_edelay(int status) -{ - float value = get_electrical_delay(); - float ratio = STEPRATIO; - if (value < 0) - ratio = -ratio; - if (status & EVT_UP) { - value = (1 - ratio) * value; - } else if (status & EVT_DOWN) { - value = (1 + ratio) * value; - } - set_electrical_delay(value); -} -#endif -static void -ui_process_normal(void) +ui_process_normal_lever(void) { int status = btn_check(); if (status != 0) { @@ -2089,24 +1789,13 @@ ui_process_normal(void) switch (uistat.lever_mode) { case LM_MARKER: lever_move_marker(status); break; case LM_SEARCH: lever_search_marker(status); break; - case LM_CENTER: - lever_move(status, FREQ_IS_STARTSTOP() ? ST_START : ST_CENTER); - break; + case LM_CENTER: lever_move(status, FREQ_IS_STARTSTOP() ? ST_START : ST_CENTER); break; case LM_SPAN: - if (FREQ_IS_STARTSTOP()) - lever_move(status, ST_STOP); - else { - if (FREQ_IS_CW()) - lever_zoom_time(status); - else - lever_zoom_span(status); - } - break; -#ifdef __VNA__ - case LM_EDELAY: - lever_edelay(status); + if (FREQ_IS_CW()) + lever_zoom_time(status); + else + lever_move(status, FREQ_IS_STARTSTOP() ? ST_STOP : ST_SPAN); break; -#endif } } } @@ -2129,7 +1818,7 @@ ui_process_listen_lever(void) #endif static void -ui_process_menu(void) +ui_process_menu_lever(void) { // Flag show, can close menu if user come out from it // if false user must select some thing @@ -2164,8 +1853,7 @@ ui_process_menu(void) ensure_selection(); draw_menu(); chThdSleepMilliseconds(50); // Add delay for not move so fast in menu - status = btn_wait_release(); - } while (status != 0); + } while ((status = btn_wait_release()) != 0); } } return; @@ -2318,14 +2006,14 @@ ui_process_lever(void) { switch (ui_mode) { case UI_NORMAL: - ui_process_normal(); + ui_process_normal_lever(); break; case UI_MENU: - ui_process_menu(); - break; - case UI_KEYPAD: - ui_process_keypad(); + ui_process_menu_lever(); break; +// case UI_KEYPAD: +// ui_process_keypad(); +// break; } } diff --git a/ui_sa.c b/ui_sa.c index 3de8cb1..ecbc0f9 100644 --- a/ui_sa.c +++ b/ui_sa.c @@ -430,6 +430,7 @@ enum { #endif KM_MARKER_TIME, // #35 + KM_VAR, KM_NONE // always at enum end }; @@ -437,56 +438,60 @@ static const struct { const keypads_t *keypad_type; char * name; } keypads_mode_tbl[KM_NONE] = { - {keypads_freq , "START"}, // start - {keypads_freq , "STOP"}, // stop - {keypads_freq , "CENTER"}, // center - {keypads_freq , "SPAN"}, // span - {keypads_freq , "FREQ"}, // cw freq - {keypads_plusmin_unit, "REF\nLEVEL"}, // reflevel #5 - {keypads_pos_unit , "SCALE"}, // scale - {keypads_positive , "ATTENUATE"}, // attenuation - {keypads_plusmin_unit, "ACTUAL\nPOWER"}, // actual power - {keypads_freq , "IF"}, // IF - {keypads_positive , "SAMPLE\nDELAY"}, // sample delay #10 - {keypads_plusmin , "OUTPUT\nLEVEL"}, // KM_LOWOUTLEVEL - {keypads_positive , "DECAY"}, // KM_DECAY - {keypads_positive , "NOISE\nLEVEL"}, // KM_NOISE - {keypads_freq , "FREQ"}, // KM_30MHz | KM_10MHz - {keypads_positive , "SAMPLE\nREPEAT"}, // KM_REPEA #15 - {keypads_plusmin , "EXT\nGAIN"}, // KM_EXT_GAIN - {keypads_plusmin_unit, "TRIGGER\nLEVEL"}, // KM_TRIGGER - {keypads_plusmin , "LEVEL\nSWEEP"}, // KM_LEVELSWEEP - {keypads_time , "SWEEP\nSECONDS"}, // KM_SWEEP_TIME - {keypads_positive , "OFFSET\nDELAY"}, // KM_OFFSET_DELAY #20 - {keypads_positive , "FAST\nSPEEDUP"}, // KM_FAST_SPEEDUP - {keypads_positive , "MINIMUM\nGRIDLINES"}, // KM_GRIDLINES - {keypads_freq , "MARKER\nFREQ"}, // KM_MARKER - {keypads_freq , "MODULATION\nFREQ"}, // KM_MODULATION - {keypads_plusmin , "OUTPUT\nLEVEL"}, // KM_HIGHOUTLEVEL #25 +[KM_START] = {keypads_freq , "START"}, // start +[KM_STOP] = {keypads_freq , "STOP"}, // stop +[KM_CENTER] = {keypads_freq , "CENTER"}, // center +[KM_SPAN] = {keypads_freq , "SPAN"}, // span +[KM_CW] = {keypads_freq , "FREQ"}, // cw freq +[KM_REFLEVEL] = {keypads_plusmin_unit, "REF\nLEVEL"}, // reflevel #5 +[KM_SCALE] = {keypads_pos_unit , "SCALE"}, // scale +[KM_ATTENUATION] = {keypads_positive , "ATTENUATE"}, // attenuation +[KM_ACTUALPOWER] = {keypads_plusmin_unit, "ACTUAL\nPOWER"}, // actual power +[KM_IF] = {keypads_freq , "IF"}, // IF +[KM_SAMPLETIME] = {keypads_positive , "SAMPLE\nDELAY"}, // sample delay #10 +[KM_LOWOUTLEVEL] = {keypads_plusmin , "OUTPUT\nLEVEL"}, // KM_LOWOUTLEVEL +[KM_DECAY] = {keypads_positive , "DECAY"}, // KM_DECAY +[KM_NOISE] = {keypads_positive , "NOISE\nLEVEL"}, // KM_NOISE #ifdef TINYSA4 - {keypads_plusmin , "COR\nAM"}, // KM_COR_AM - {keypads_plusmin , "COR\nWFM"}, // KM_COR_WFM - {keypads_plusmin , "COR\nNFM"}, // KM_COR_NFM - {keypads_freq , "IF2"}, // KM_IF2 - {keypads_positive , "R"}, // KM_R #30 - {keypads_positive , "MODULO"}, // KM_MOD - {keypads_positive , "CP"}, // KM_CP -#endif - {keypads_positive , "ATTACK"}, // KM_ATTACK +[KM_30MHZ] = {keypads_freq , "FREQ"}, // KM_30MHz +#else +[KM_10MHZ] = {keypads_freq , "FREQ"}, // KM_10MHz +#endif +[KM_REPEAT] = {keypads_positive , "SAMPLE\nREPEAT"}, // KM_REPEA #15 +[KM_EXT_GAIN] = {keypads_plusmin , "EXT\nGAIN"}, // KM_EXT_GAIN +[KM_TRIGGER] = {keypads_plusmin_unit, "TRIGGER\nLEVEL"}, // KM_TRIGGER +[KM_LEVELSWEEP] = {keypads_plusmin , "LEVEL\nSWEEP"}, // KM_LEVELSWEEP +[KM_SWEEP_TIME] = {keypads_time , "SWEEP\nSECONDS"}, // KM_SWEEP_TIME +[KM_OFFSET_DELAY] = {keypads_positive , "OFFSET\nDELAY"}, // KM_OFFSET_DELAY #20 +[KM_FAST_SPEEDUP] = {keypads_positive , "FAST\nSPEEDUP"}, // KM_FAST_SPEEDUP +[KM_GRIDLINES] = {keypads_positive , "MINIMUM\nGRIDLINES"}, // KM_GRIDLINES +[KM_MARKER] = {keypads_freq , "MARKER\nFREQ"}, // KM_MARKER +[KM_MODULATION] = {keypads_freq , "MODULATION\nFREQ"}, // KM_MODULATION +[KM_HIGHOUTLEVEL] = {keypads_plusmin , "OUTPUT\nLEVEL"}, // KM_HIGHOUTLEVEL #25 +#ifdef TINYSA4 +[KM_COR_AM] = {keypads_plusmin , "COR\nAM"}, // KM_COR_AM +[KM_COR_WFM] = {keypads_plusmin , "COR\nWFM"}, // KM_COR_WFM +[KM_COR_NFM] = {keypads_plusmin , "COR\nNFM"}, // KM_COR_NFM +[KM_IF2] = {keypads_freq , "IF2"}, // KM_IF2 +[KM_R] = {keypads_positive , "R"}, // KM_R #30 +[KM_MOD] = {keypads_positive , "MODULO"}, // KM_MOD +[KM_CP] = {keypads_positive , "CP"}, // KM_CP +#endif +[KM_ATTACK] = {keypads_positive , "ATTACK"}, // KM_ATTACK #ifdef TINYSA4 - {keypads_freq , "ULTRA\nSTART"}, // KM_LPF +[KM_LPF] = {keypads_freq , "ULTRA\nSTART"}, // KM_LPF #endif - {keypads_plusmin , "LEVEL"}, // KM_LEVEL +[KM_LEVEL] = {keypads_plusmin , "LEVEL"}, // KM_LEVEL #ifdef __LIMITS__ - {keypads_freq , "END\nFREQ"}, // KM_LIMIT_FREQ - {keypads_plusmin_unit , "LEVEL"}, // KM_LIMIT_LEVEL +[KM_LIMIT_FREQ] = {keypads_freq , "END\nFREQ"}, // KM_LIMIT_FREQ +[KM_LIMIT_LEVEL] = {keypads_plusmin_unit , "LEVEL"}, // KM_LIMIT_LEVEL #endif - {keypads_time , "MARKER\nTIME"}, // KM_MARKER_TIME +[KM_MARKER_TIME] = {keypads_time , "MARKER\nTIME"}, // KM_MARKER_TIME +[KM_VAR] = {keypads_freq , "JOG\nSTEP"}, // jog step }; -#if 0 // Not used +#if 0 // Not used enum { SL_GENLOW_FREQ, SL_GENHIGH_FREQ, SL_GENLOW_LEVEL, SL_GENHIGH_LEVEL }; - ui_slider_t ui_sliders [] = { { KM_CENTER, true, 0, 1000000, 0, 350000000, M_GENLOW}, @@ -2752,6 +2757,7 @@ static const menuitem_t menu_stimulus[] = { { MT_KEYPAD, KM_CENTER, "CENTER", NULL}, { MT_KEYPAD, KM_SPAN, "SPAN", NULL}, { MT_KEYPAD, KM_CW, "ZERO SPAN", NULL}, + { MT_KEYPAD, KM_VAR, "JOG STEP\n%s","0 - AUTO"}, { MT_SUBMENU,0, "RBW", menu_rbw}, { MT_ADV_CALLBACK,0, "SHIFT\nFREQ", menu_shift_acb}, { MT_CANCEL, 0, S_LARROW" BACK", NULL }, @@ -2827,9 +2833,9 @@ static void menu_item_modify_attribute( } } -static void fetch_numeric_target(void) +static void fetch_numeric_target(uint8_t mode) { - switch (keypad_mode) { + switch (mode) { case KM_START: uistat.freq_value = get_sweep_frequency(ST_START) + (setting.frequency_offset - FREQUENCY_SHIFT); plot_printf(uistat.text, sizeof uistat.text, "%3.3fMHz", uistat.freq_value / 1000000.0); @@ -2984,6 +2990,10 @@ static void fetch_numeric_target(void) plot_printf(uistat.text, sizeof uistat.text, "%7.0fHz", uistat.value); } break; + case KM_VAR: + uistat.freq_value = setting.frequency_var; + plot_printf(uistat.text, sizeof uistat.text, setting.frequency_var ? "%QHz" : " AUTO", setting.frequency_var); + break; } { @@ -2993,7 +3003,6 @@ static void fetch_numeric_target(void) x /= 10; uistat.digit = n; } -// uistat.previous_value = uistat.value; } static void @@ -3156,6 +3165,9 @@ set_numeric_value(void) dirty = true; break; #endif + case KM_VAR: + setting.frequency_var = uistat.freq_value; + break; } } From 153a4c2fdf9c6175f25ef1fc9d0ff5b962dc3fb1 Mon Sep 17 00:00:00 2001 From: DiSlord Date: Sun, 23 May 2021 16:10:56 +0300 Subject: [PATCH 08/18] More cleanup --- nanovna.h | 5 +---- ui.c | 1 - ui_sa.c | 8 -------- 3 files changed, 1 insertion(+), 13 deletions(-) diff --git a/nanovna.h b/nanovna.h index aea920d..d9384a4 100644 --- a/nanovna.h +++ b/nanovna.h @@ -1216,12 +1216,9 @@ enum marker_smithvalue { }; typedef struct uistat { - float value; // for editing at numeric input area + float value; // for editing at numeric input area freq_t freq_value; // for editing frequencies that do not fit in float; - int8_t digit; /* 0~5 */ - int8_t digit_mode; int8_t current_trace; /* 0..3 */ -// uint32_t previous_value; uint8_t lever_mode; uint8_t marker_delta; uint8_t marker_noise; diff --git a/ui.c b/ui.c index 0b11ad3..92f2b81 100644 --- a/ui.c +++ b/ui.c @@ -28,7 +28,6 @@ #pragma GCC optimize ("Os") uistat_t uistat = { - digit: 6, current_trace: 0, lever_mode: LM_MARKER, marker_delta: FALSE, diff --git a/ui_sa.c b/ui_sa.c index ecbc0f9..fc0528a 100644 --- a/ui_sa.c +++ b/ui_sa.c @@ -2995,14 +2995,6 @@ static void fetch_numeric_target(uint8_t mode) plot_printf(uistat.text, sizeof uistat.text, setting.frequency_var ? "%QHz" : " AUTO", setting.frequency_var); break; } - - { - freq_t x = uistat.value; - int n = 0; - for (; x >= 10 && n < 9; n++) - x /= 10; - uistat.digit = n; - } } static void From b278a06fd4eee2b9fcfdb17f606b495e4081cee0 Mon Sep 17 00:00:00 2001 From: DiSlord Date: Sun, 23 May 2021 18:56:03 +0300 Subject: [PATCH 09/18] Use defines in header for SD card buffers --- main.c | 4 ---- nanovna.h | 11 +++++++++++ ui.c | 13 ------------- 3 files changed, 11 insertions(+), 17 deletions(-) diff --git a/main.c b/main.c index 5ee8256..df21572 100644 --- a/main.c +++ b/main.c @@ -762,10 +762,6 @@ void send_buffer(uint8_t * buf, int s) #ifndef __USE_SD_CARD__ #error "Need enable SD card support __USE_SD_CARD__ in nanovna.h, for use ENABLE_SD_CARD_CMD" #endif -// Fat file system work area (at the end of spi_buffer) -static FATFS *fs_volume = (FATFS *)(((uint8_t*)(&spi_buffer[SPI_BUFFER_SIZE])) - sizeof(FATFS)); -// FatFS file object (at the end of spi_buffer) -static FIL *fs_file = ( FIL*)(((uint8_t*)(&spi_buffer[SPI_BUFFER_SIZE])) - sizeof(FATFS) - sizeof(FIL)); static FRESULT cmd_sd_card_mount(void){ const FRESULT res = f_mount(fs_volume, "", 1); diff --git a/nanovna.h b/nanovna.h index d9384a4..d182f17 100644 --- a/nanovna.h +++ b/nanovna.h @@ -1322,6 +1322,17 @@ void rtc_set_time(uint32_t dr, uint32_t tr); #include "../FatFs/ff.h" #include "../FatFs/diskio.h" bool SD_Inserted(void); +// Buffers for SD card use spi_buffer +#if SPI_BUFFER_SIZE < 2048 +#error "SPI_BUFFER_SIZE for SD card support need size >= 2048" +#else +// Fat file system work area (at the end of spi_buffer) +#define fs_volume (FATFS *)(((uint8_t*)(&spi_buffer[SPI_BUFFER_SIZE])) - sizeof(FATFS)) +// FatFS file object (at the end of spi_buffer) +#define fs_file ( FIL*)(((uint8_t*)(&spi_buffer[SPI_BUFFER_SIZE])) - sizeof(FATFS) - sizeof(FIL)) +// Filename object (at the end of spi_buffer) +#define fs_filename ( char*)(((uint8_t*)(&spi_buffer[SPI_BUFFER_SIZE])) - sizeof(FATFS) - sizeof(FIL) - FF_LFN_BUF - 4) +#endif void testLog(void); // debug log #endif diff --git a/ui.c b/ui.c index 92f2b81..1a71816 100644 --- a/ui.c +++ b/ui.c @@ -71,19 +71,6 @@ volatile uint8_t operation_requested = OP_NONE; int8_t previous_marker = MARKER_INVALID; -#ifdef __USE_SD_CARD__ -#if SPI_BUFFER_SIZE < 2048 -#error "SPI_BUFFER_SIZE for SD card support need size >= 2048" -#else -// Fat file system work area (at the end of spi_buffer) -static FATFS *fs_volume = (FATFS *)(((uint8_t*)(&spi_buffer[SPI_BUFFER_SIZE])) - sizeof(FATFS)); -// FatFS file object (at the end of spi_buffer) -static FIL *fs_file = ( FIL*)(((uint8_t*)(&spi_buffer[SPI_BUFFER_SIZE])) - sizeof(FATFS) - sizeof(FIL)); -// Filename object (at the end of spi_buffer) -static char *fs_filename = ( char*)(((uint8_t*)(&spi_buffer[SPI_BUFFER_SIZE])) - sizeof(FATFS) - sizeof(FIL) - FF_LFN_BUF - 4); -#endif -#endif - enum { UI_NORMAL, UI_MENU, UI_KEYPAD }; From a647621233626bce571d06e03b0151de13fa3a76 Mon Sep 17 00:00:00 2001 From: DiSlord Date: Sun, 16 May 2021 16:32:20 +0300 Subject: [PATCH 10/18] Cleanup draw_cal_status code, use lcd_printf --- ui_sa.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ui_sa.c b/ui_sa.c index 7c0ff97..995da9b 100644 --- a/ui_sa.c +++ b/ui_sa.c @@ -3355,7 +3355,7 @@ redraw_cal_status: // if (setting.mode == M_LOW) { // Attenuation - ili9341_set_foreground(setting.auto_attenuation ? LCD_FG_COLOR : LCD_BRIGHT_COLOR_GREEN); + ili9341_set_foreground(setting.auto_attenuation ? LCD_BRIGHT_COLOR_GREEN : LCD_FG_COLOR); lcd_printf(x, y, "Atten:\n%4.2FdB", get_attenuation()); y = add_quick_menu(y+= YSTEP, (menuitem_t *)menu_atten); // } From 3abd42e62c4972c18661bef48f13b11dd9baf8eb Mon Sep 17 00:00:00 2001 From: DiSlord Date: Sun, 23 May 2021 18:56:03 +0300 Subject: [PATCH 11/18] Use defines in header for SD card buffers --- main.c | 4 ---- nanovna.h | 11 +++++++++++ ui.c | 13 ------------- 3 files changed, 11 insertions(+), 17 deletions(-) diff --git a/main.c b/main.c index 6f54a3f..53c4df0 100644 --- a/main.c +++ b/main.c @@ -762,10 +762,6 @@ void send_buffer(uint8_t * buf, int s) #ifndef __USE_SD_CARD__ #error "Need enable SD card support __USE_SD_CARD__ in nanovna.h, for use ENABLE_SD_CARD_CMD" #endif -// Fat file system work area (at the end of spi_buffer) -static FATFS *fs_volume = (FATFS *)(((uint8_t*)(&spi_buffer[SPI_BUFFER_SIZE])) - sizeof(FATFS)); -// FatFS file object (at the end of spi_buffer) -static FIL *fs_file = ( FIL*)(((uint8_t*)(&spi_buffer[SPI_BUFFER_SIZE])) - sizeof(FATFS) - sizeof(FIL)); static FRESULT cmd_sd_card_mount(void){ const FRESULT res = f_mount(fs_volume, "", 1); diff --git a/nanovna.h b/nanovna.h index d9384a4..d182f17 100644 --- a/nanovna.h +++ b/nanovna.h @@ -1322,6 +1322,17 @@ void rtc_set_time(uint32_t dr, uint32_t tr); #include "../FatFs/ff.h" #include "../FatFs/diskio.h" bool SD_Inserted(void); +// Buffers for SD card use spi_buffer +#if SPI_BUFFER_SIZE < 2048 +#error "SPI_BUFFER_SIZE for SD card support need size >= 2048" +#else +// Fat file system work area (at the end of spi_buffer) +#define fs_volume (FATFS *)(((uint8_t*)(&spi_buffer[SPI_BUFFER_SIZE])) - sizeof(FATFS)) +// FatFS file object (at the end of spi_buffer) +#define fs_file ( FIL*)(((uint8_t*)(&spi_buffer[SPI_BUFFER_SIZE])) - sizeof(FATFS) - sizeof(FIL)) +// Filename object (at the end of spi_buffer) +#define fs_filename ( char*)(((uint8_t*)(&spi_buffer[SPI_BUFFER_SIZE])) - sizeof(FATFS) - sizeof(FIL) - FF_LFN_BUF - 4) +#endif void testLog(void); // debug log #endif diff --git a/ui.c b/ui.c index 92f2b81..1a71816 100644 --- a/ui.c +++ b/ui.c @@ -71,19 +71,6 @@ volatile uint8_t operation_requested = OP_NONE; int8_t previous_marker = MARKER_INVALID; -#ifdef __USE_SD_CARD__ -#if SPI_BUFFER_SIZE < 2048 -#error "SPI_BUFFER_SIZE for SD card support need size >= 2048" -#else -// Fat file system work area (at the end of spi_buffer) -static FATFS *fs_volume = (FATFS *)(((uint8_t*)(&spi_buffer[SPI_BUFFER_SIZE])) - sizeof(FATFS)); -// FatFS file object (at the end of spi_buffer) -static FIL *fs_file = ( FIL*)(((uint8_t*)(&spi_buffer[SPI_BUFFER_SIZE])) - sizeof(FATFS) - sizeof(FIL)); -// Filename object (at the end of spi_buffer) -static char *fs_filename = ( char*)(((uint8_t*)(&spi_buffer[SPI_BUFFER_SIZE])) - sizeof(FATFS) - sizeof(FIL) - FF_LFN_BUF - 4); -#endif -#endif - enum { UI_NORMAL, UI_MENU, UI_KEYPAD }; From e4deb9f04e3a739bf8b0a30b8d32df9e683fbbde Mon Sep 17 00:00:00 2001 From: erikkaashoek Date: Wed, 26 May 2021 15:53:53 +0200 Subject: [PATCH 12/18] Revert "Cleanup draw_cal_status code, use lcd_printf" This reverts commit a647621233626bce571d06e03b0151de13fa3a76. --- ui_sa.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ui_sa.c b/ui_sa.c index 995da9b..7c0ff97 100644 --- a/ui_sa.c +++ b/ui_sa.c @@ -3355,7 +3355,7 @@ redraw_cal_status: // if (setting.mode == M_LOW) { // Attenuation - ili9341_set_foreground(setting.auto_attenuation ? LCD_BRIGHT_COLOR_GREEN : LCD_FG_COLOR); + ili9341_set_foreground(setting.auto_attenuation ? LCD_FG_COLOR : LCD_BRIGHT_COLOR_GREEN); lcd_printf(x, y, "Atten:\n%4.2FdB", get_attenuation()); y = add_quick_menu(y+= YSTEP, (menuitem_t *)menu_atten); // } From e0b951e286fc17b66b9c90bff15c45041379a0fc Mon Sep 17 00:00:00 2001 From: DiSlord Date: Wed, 26 May 2021 22:05:17 +0300 Subject: [PATCH 13/18] Add load config.ini script from sd card --- main.c | 263 +++++++++++++++++++++++------------------------------- nanovna.h | 2 + ui_sa.c | 13 +++ 3 files changed, 128 insertions(+), 150 deletions(-) diff --git a/main.c b/main.c index df21572..cacab00 100644 --- a/main.c +++ b/main.c @@ -798,7 +798,6 @@ VNA_SHELL_FUNCTION(cmd_sd_list) VNA_SHELL_FUNCTION(cmd_sd_read) { - FRESULT res; char *buf = (char *)spi_buffer; if (argc != 1) { @@ -814,21 +813,15 @@ VNA_SHELL_FUNCTION(cmd_sd_read) return; } // shell_printf("sd_read: %s\r\n", filename); - // number of bytes to follow (file size) - const uint32_t filesize = f_size(fs_file); + uint32_t filesize = f_size(fs_file); streamWrite(shell_stream, (void *)&filesize, 4); - + UINT size = 0; // file data (send all data from file) - while (1) - { - UINT size = 0; - res = f_read(fs_file, buf, 512, &size); - if (res != FR_OK || size == 0) - break; + while (f_read(fs_file, buf, 512, &size) == FR_OK && size > 0) streamWrite(shell_stream, (void *)buf, size); - } - res = f_close(fs_file); + + f_close(fs_file); return; } @@ -1902,43 +1895,67 @@ static void shell_init_connection(void){ } #endif +static const VNAShellCommand *VNAShell_parceLine(char *line){ + // Parse and execute line + char *lp = line, *ep; + shell_nargs = 0; + +// DEBUG_LOG(0, lp); // debug console log + while (*lp != 0) { + // Skipping white space and tabs at string begin. + while (*lp == ' ' || *lp == '\t') lp++; + // If an argument starts with a double quote then its delimiter is another quote, else + // delimiter is white space. + ep = (*lp == '"') ? strpbrk(++lp, "\"") : strpbrk(lp, " \t"); + // Store in args string + shell_args[shell_nargs++] = lp; + // Stop, end of input string + if ((lp = ep) == NULL) break; + // Argument limits check + if (shell_nargs > VNA_SHELL_MAX_ARGUMENTS) { + shell_printf("too many arguments, max " define_to_STR(VNA_SHELL_MAX_ARGUMENTS) "" VNA_SHELL_NEWLINE_STR); + return NULL; + } + // Set zero at the end of string and continue check + *lp++ = 0; + } + if (shell_nargs){ + const VNAShellCommand *scp; + for (scp = commands; scp->sc_name != NULL; scp++) + if (get_str_index(scp->sc_name, shell_args[0]) == 0) + return scp; + } + return NULL; +} + // // Read command line from shell_stream // static int VNAShell_readLine(char *line, int max_size) { - // Read line from input stream + // send backspace, space for erase, backspace again + char backspace[] = {0x08, 0x20, 0x08, 0x00}; uint8_t c; - char *ptr = line; // Prepare I/O for shell_stream PREPARE_STREAM; - while (1) { - // Return 0 only if stream not active - if (streamRead(shell_stream, &c, 1) == 0) - return 0; + uint16_t j = 0; + // Return 0 only if stream not active + while (streamRead(shell_stream, &c, 1)) { // Backspace or Delete - if (c == 8 || c == 0x7f) { - if (ptr != line) { - static const char backspace[] = {0x08, 0x20, 0x08, 0x00}; - shell_printf(backspace); - ptr--; - } + if (c == 0x08 || c == 0x7f) { + if (j > 0) {shell_printf(backspace); j--;} continue; } // New line (Enter) if (c == '\r') { shell_printf(VNA_SHELL_NEWLINE_STR); - *ptr = 0; + line[j] = 0; return 1; } - // Others (skip) - if (c < 0x20) - continue; - // Store - if (ptr < line + max_size - 1) { - streamPut(shell_stream, c); // Echo - *ptr++ = (char)c; - } + // Others (skip) or too long - skip + if (c < ' ' || j >= max_size - 1) continue; + streamPut(shell_stream, c); // Echo + line[j++] = (char)c; } return 0; } @@ -1948,57 +1965,76 @@ static int VNAShell_readLine(char *line, int max_size) // static void VNAShell_executeLine(char *line) { - // Parse and execute line - char *lp = line, *ep; - shell_nargs = 0; - while (*lp != 0) { - // Skipping white space and tabs at string begin. - while (*lp == ' ' || *lp == '\t') lp++; - // If an argument starts with a double quote then its delimiter is another quote, else - // delimiter is white space. - ep = (*lp == '"') ? strpbrk(++lp, "\"") : strpbrk(lp, " \t"); - // Store in args string - shell_args[shell_nargs++] = lp; - // Stop, end of input string - if ((lp = ep) == NULL) break; - // Argument limits check - if (shell_nargs > VNA_SHELL_MAX_ARGUMENTS) { - shell_printf("too many arguments, max " define_to_STR( - VNA_SHELL_MAX_ARGUMENTS) "" VNA_SHELL_NEWLINE_STR); - return; - } - // Set zero at the end of string and continue check - *lp++ = 0; - } - if (shell_nargs == 0) return; // Execute line - const VNAShellCommand *scp; - for (scp = commands; scp->sc_name != NULL; scp++) { - if (get_str_index(scp->sc_name, shell_args[0]) == 0) { - if (scp->flags & CMD_WAIT_MUTEX) { - shell_function = scp->sc_function; - operation_requested|=OP_CONSOLE; - // Wait execute command in sweep thread - do { - osalThreadSleepMilliseconds(100); - } while (shell_function); - } else { - operation_requested = false; // otherwise commands will be aborted - scp->sc_function(shell_nargs - 1, &shell_args[1]); - if (dirty) { - operation_requested = true; // ensure output is updated - if (MODE_OUTPUT(setting.mode)) - draw_menu(); // update screen if in output mode and dirty - else - redraw_request |= REDRAW_CAL_STATUS | REDRAW_AREA | REDRAW_FREQUENCY; - } + const VNAShellCommand *scp = VNAShell_parceLine(line); + if (scp) { + if (scp->flags & CMD_WAIT_MUTEX) { + shell_function = scp->sc_function; + operation_requested|=OP_CONSOLE; + // Wait execute command in sweep thread + do { + osalThreadSleepMilliseconds(10); + } while (shell_function); + } else { + operation_requested = false; // otherwise commands will be aborted + scp->sc_function(shell_nargs - 1, &shell_args[1]); + if (dirty) { + operation_requested = true; // ensure output is updated + if (MODE_OUTPUT(setting.mode)) + draw_menu(); // update screen if in output mode and dirty + else + redraw_request |= REDRAW_CAL_STATUS | REDRAW_AREA | REDRAW_FREQUENCY; } - return; } + return; } shell_printf("%s?" VNA_SHELL_NEWLINE_STR, shell_args[0]); } +#ifdef __SD_CARD_LOAD__ +#ifndef __USE_SD_CARD__ +#error "Need enable SD card support __USE_SD_CARD__ in nanovna.h, for use ENABLE_SD_CARD_CMD" +#endif +void sd_card_load_config(void){ + // Mount card + if (f_mount(fs_volume, "", 1) != FR_OK) + return; + + if (f_open(fs_file, "config.ini", FA_OPEN_EXISTING | FA_READ) != FR_OK) + return; + + char *buf = (char *)spi_buffer; + UINT size = 0; + + uint16_t j = 0, i; + while (f_read(fs_file, buf, 512, &size) == FR_OK && size > 0){ + i = 0; + while (i < size) { + uint8_t c = buf[i++]; + // New line (Enter) + if (c == '\r') { +// shell_line[j ] = '\r'; +// shell_line[j+1] = '\n'; +// shell_line[j+2] = 0; +// shell_printf(shell_line); + shell_line[j] = 0; j = 0; + const VNAShellCommand *scp = VNAShell_parceLine(shell_line); +// if (scp && (scp->flags&CMD_RUN_IN_LOAD)) !!! FIX me, add this flag to commands + scp->sc_function(shell_nargs - 1, &shell_args[1]); + continue; + } + // Others (skip) + if (c < 0x20) continue; + // Store + if (j < VNA_SHELL_MAX_LENGTH - 1) + shell_line[j++] = (char)c; + } + } + f_close(fs_file); + return; +} +#endif + #ifdef VNA_SHELL_THREAD static THD_WORKING_AREA(waThread2, /* cmd_* max stack size + alpha */442); THD_FUNCTION(myshellThread, p) @@ -2016,26 +2052,6 @@ THD_FUNCTION(myshellThread, p) } #endif -#ifdef __VNA__ -// I2C clock bus setting: depend from STM32_I2C1SW in mcuconf.h -static const I2CConfig i2ccfg = { - .timingr = STM32_TIMINGR_PRESC(0U) | /* 72MHz I2CCLK. ~ 600kHz i2c */ -// STM32_TIMINGR_SCLDEL(10U) | STM32_TIMINGR_SDADEL(4U) | -// STM32_TIMINGR_SCLH(31U) | STM32_TIMINGR_SCLL(79U), - - STM32_TIMINGR_SCLDEL(15U) | STM32_TIMINGR_SDADEL(15U) | - STM32_TIMINGR_SCLH(35U) | STM32_TIMINGR_SCLL(85U), - -// STM32_TIMINGR_SCLDEL(15U) | STM32_TIMINGR_SDADEL(15U) | -// STM32_TIMINGR_SCLH(35U) | STM32_TIMINGR_SCLL(55U), - -// STM32_TIMINGR_SCLDEL(10U) | STM32_TIMINGR_SDADEL(4U) | -// STM32_TIMINGR_SCLH(48U) | STM32_TIMINGR_SCLL(90U), - .cr1 = 0, - .cr2 = 0 -}; -#endif - static const DACConfig dac1cfg1 = { init: 0, datamode: DAC_DHRM_12BIT_RIGHT @@ -2057,59 +2073,6 @@ void my_microsecond_delay(int t) if (t>1) gptPolledDelay(&GPTD14, t); // t us delay #endif } -#if 0 -/* - * UART driver configuration structure. - */ -static UARTConfig uart_cfg_1 = { - NULL, //txend1, - NULL, //txend2, - NULL, //rxend, - NULL, //rxchar, - NULL, //rxerr, - 800000, - 0, - 0, //USART_CR2_LINEN, - 0 -}; -#endif - -#if 0 -static const SerialConfig LCD_config = -{ - 9600, - 0, - USART_CR2_STOP2_BITS, - 0 -}; - - -void myWrite(char *buf) -{ - int len = strlen(buf); - while(len-- > 0) { - sdPut(&SD1,*buf++); - osalThreadSleepMicroseconds(1000); - } -} - -static int serial_count = 0; -int mySerialReadline(unsigned char *buf, int len) -{ - int i; - do { - i = sdReadTimeout(&SD1,&buf[serial_count], 20-serial_count,TIME_IMMEDIATE); - serial_count += i; - if (i > 0) - osalThreadSleepMicroseconds(1000); - } while (serial_count < len && i > 0); - if (buf[serial_count-1] == '\n') { - serial_count = 0; - return(i); - } else - return 0; -} -#endif /* Main thread stack size defined in makefile USE_PROCESS_STACKSIZE = 0x200 * Profile stack usage (enable threads command by def ENABLE_THREADS_COMMAND) show: diff --git a/nanovna.h b/nanovna.h index d182f17..bf351d2 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 __SD_CARD_LOAD__ // Allow run commands from SD card (config.ini in root) #define __LCD_BRIGHTNESS__ // LCD or hardware allow change brightness, add menu item for this #define __HARMONIC__ #define __VBW__ @@ -1334,6 +1335,7 @@ bool SD_Inserted(void); #define fs_filename ( char*)(((uint8_t*)(&spi_buffer[SPI_BUFFER_SIZE])) - sizeof(FATFS) - sizeof(FIL) - FF_LFN_BUF - 4) #endif void testLog(void); // debug log +void sd_card_load_config(void); #endif /* diff --git a/ui_sa.c b/ui_sa.c index 8ec0ccc..967b21b 100644 --- a/ui_sa.c +++ b/ui_sa.c @@ -780,6 +780,16 @@ static UI_FUNCTION_ADV_CALLBACK(menu_store_preset_acb) menu_move_back(true); } +#ifdef __SD_CARD_LOAD__ +UI_FUNCTION_CALLBACK(menu_load_config_cb) +{ + (void)item; + (void)data; + sd_card_load_config(); + ui_mode_normal(); +} +#endif + UI_FUNCTION_CALLBACK(menu_autosettings_cb) { (void)item; @@ -2476,6 +2486,9 @@ static const menuitem_t menu_settings4[] = { MT_KEYPAD, KM_COR_AM, "COR\nAM", "Enter AM modulation correction"}, { MT_KEYPAD, KM_COR_WFM, "COR\nWFM", "Enter WFM modulation correction"}, { MT_KEYPAD, KM_COR_NFM, "COR\nNFM", "Enter NFM modulation correction"}, +#endif +#ifdef __SD_CARD_LOAD__ + { MT_CALLBACK, 0 , "LOAD\nCONFIG", menu_load_config_cb}, #endif { MT_CALLBACK, 0 , "CLEAR\nCONFIG", menu_clearconfig_cb}, #ifdef __HARMONIC__ From cfa225ce2855e7a68377b631e9371d2f05ac90f9 Mon Sep 17 00:00:00 2001 From: DiSlord Date: Wed, 26 May 2021 22:09:19 +0300 Subject: [PATCH 14/18] Add CMD_RUN_IN_LOAD define --- main.c | 1 + 1 file changed, 1 insertion(+) diff --git a/main.c b/main.c index a05ab64..3627d1e 100644 --- a/main.c +++ b/main.c @@ -1639,6 +1639,7 @@ typedef struct { // Some commands can executed only in sweep thread, not in main cycle #define CMD_WAIT_MUTEX 1 +#define CMD_RUN_IN_LOAD 2 static const VNAShellCommand commands[] = { {"version" , cmd_version , 0}, From 6e52e279869bbff2f365ccdce7942b81c360812e Mon Sep 17 00:00:00 2001 From: DiSlord Date: Thu, 27 May 2021 21:46:29 +0300 Subject: [PATCH 15/18] Better keyboard input formatting --- ui.c | 34 +++++++++++++++++++--------------- 1 file changed, 19 insertions(+), 15 deletions(-) diff --git a/ui.c b/ui.c index 1a71816..0f9bb14 100644 --- a/ui.c +++ b/ui.c @@ -1011,33 +1011,37 @@ menu_is_multiline(const char *label) return n; } +static int period_pos(void) {int j; for (j = 0; j < kp_index && kp_buf[j] != '.'; j++); return j;} + static void draw_numeric_input(const char *buf) { - int i; - int x; - uint16_t xsim = 0b0010010000000000; - + uint16_t i; + uint16_t x = 10 + 10 * FONT_WIDTH + 4; + uint16_t xsim = 0b00100100100100100 >>(2-(period_pos()%3)); + xsim&=~1; ili9341_set_foreground(LCD_INPUT_TEXT_COLOR); ili9341_set_background(LCD_INPUT_BG_COLOR); - for (i = 0, x = 64; i < NUMINPUT_LEN && buf[i]; i++, xsim<<=1) { + for (i = 0; buf[i]; i++) { int c = buf[i]; - if (c == '.') - c = KP_PERIOD; - else if (c == '-') - c = KP_MINUS; + if (c == '.'){c = KP_PERIOD;xsim<<=4;} + else if (c == '-'){c = KP_MINUS; xsim&=~1;} else// if (c >= '0' && c <= '9') c = c - '0'; - + if (c < 0) c = 0; + // Add space before char + int16_t space = xsim&1 ? 2 + 10 : 2; + xsim>>=1; + ili9341_fill(x, LCD_HEIGHT-NUM_INPUT_HEIGHT+4, space, NUM_INPUT_HEIGHT); + x+=space; if (c >= 0) // c is number ili9341_drawfont(c, x, LCD_HEIGHT-NUM_INPUT_HEIGHT+4); - else // erase + else break; - - x += xsim&0x8000 ? NUM_FONT_GET_WIDTH+2+8 : NUM_FONT_GET_WIDTH+2; + x+=NUM_FONT_GET_WIDTH; } - // erase last - ili9341_fill(x, LCD_HEIGHT-NUM_INPUT_HEIGHT+4, LCD_WIDTH-x-1, NUM_FONT_GET_WIDTH+2+8); + + ili9341_fill(x, LCD_HEIGHT-NUM_INPUT_HEIGHT+4, LCD_WIDTH - 1 - x, NUM_INPUT_HEIGHT); if (buf[0] == 0 && kp_help_text != NULL) { int lines = menu_is_multiline(kp_help_text); ili9341_set_foreground(LCD_INPUT_TEXT_COLOR); From 596b9645eb013c0e1408ed7eb6f61d54025eaf72 Mon Sep 17 00:00:00 2001 From: DiSlord Date: Thu, 27 May 2021 22:02:35 +0300 Subject: [PATCH 16/18] Small fix --- ui.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ui.c b/ui.c index 0f9bb14..681a8c5 100644 --- a/ui.c +++ b/ui.c @@ -1025,7 +1025,7 @@ draw_numeric_input(const char *buf) for (i = 0; buf[i]; i++) { int c = buf[i]; if (c == '.'){c = KP_PERIOD;xsim<<=4;} - else if (c == '-'){c = KP_MINUS; xsim&=~1;} + else if (c == '-'){c = KP_MINUS; xsim&=~2;} else// if (c >= '0' && c <= '9') c = c - '0'; if (c < 0) c = 0; From 9d4489abe145c16e55a5d72ff1a0bc6c3997e443 Mon Sep 17 00:00:00 2001 From: DiSlord Date: Thu, 27 May 2021 22:31:58 +0300 Subject: [PATCH 17/18] Small optimization --- ui.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/ui.c b/ui.c index 681a8c5..97b2b5c 100644 --- a/ui.c +++ b/ui.c @@ -1019,13 +1019,12 @@ draw_numeric_input(const char *buf) uint16_t i; uint16_t x = 10 + 10 * FONT_WIDTH + 4; uint16_t xsim = 0b00100100100100100 >>(2-(period_pos()%3)); - xsim&=~1; ili9341_set_foreground(LCD_INPUT_TEXT_COLOR); ili9341_set_background(LCD_INPUT_BG_COLOR); for (i = 0; buf[i]; i++) { int c = buf[i]; if (c == '.'){c = KP_PERIOD;xsim<<=4;} - else if (c == '-'){c = KP_MINUS; xsim&=~2;} + else if (c == '-'){c = KP_MINUS; xsim&=~3;} else// if (c >= '0' && c <= '9') c = c - '0'; if (c < 0) c = 0; From 0caf199850359a6364792e61f14ec5929d6be9e0 Mon Sep 17 00:00:00 2001 From: DiSlord Date: Thu, 27 May 2021 22:35:14 +0300 Subject: [PATCH 18/18] fix --- ui.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ui.c b/ui.c index 97b2b5c..85529d6 100644 --- a/ui.c +++ b/ui.c @@ -1018,7 +1018,7 @@ draw_numeric_input(const char *buf) { uint16_t i; uint16_t x = 10 + 10 * FONT_WIDTH + 4; - uint16_t xsim = 0b00100100100100100 >>(2-(period_pos()%3)); + uint16_t xsim = (0b00100100100100100 >>(2-(period_pos()%3)))&(~1); ili9341_set_foreground(LCD_INPUT_TEXT_COLOR); ili9341_set_background(LCD_INPUT_BG_COLOR); for (i = 0; buf[i]; i++) {