From 2d2f52d52f458ddbb839695ca7dc8616c980eadd Mon Sep 17 00:00:00 2001 From: erikkaashoek Date: Wed, 2 Dec 2020 09:25:32 +0100 Subject: [PATCH] Added ultra and extra_lna --- NANOVNA_STM32_F303/board.h | 6 ++--- main.c | 3 +++ nanovna.h | 5 +++- sa_cmd.c | 30 +++++++++++++++++++++++ sa_core.c | 49 +++++++++++++++++++++++++++++++------- si4432.c | 26 +++++++++++++------- si4432.h | 2 +- ui_sa.c | 32 ++++++++++++++++++------- 8 files changed, 122 insertions(+), 31 deletions(-) diff --git a/NANOVNA_STM32_F303/board.h b/NANOVNA_STM32_F303/board.h index 397b676..fd87067 100644 --- a/NANOVNA_STM32_F303/board.h +++ b/NANOVNA_STM32_F303/board.h @@ -55,7 +55,7 @@ /* on-board */ -#if 0 +#if 1 // Set to 1 to build for prototype HW #define TINYSA4_PROTO #define GPIO_LED 0 #define LINE_LED PAL_LINE(GPIOA,GPIO_LED) @@ -92,9 +92,9 @@ #define GPIO_SD_CD 7 #define LINE_SD_CD PAL_LINE(GPIOB, GPIO_SD_CD) #define GPIO_RX_SEL 8 -#define LINE_RX_SEL PAL_LINE(GPIOB, GPIO_RX_SEL) +#define LINE_RX_SEL PAL_LINE(GPIOB, GPIO_RX_SEL) #define GPIO_RX_CTS 9 -#define LINE_RX_CTS PAL_LINE(GPIOB, GPIO_RX_CTS) +#define LINE_RX_CTS PAL_LINE(GPIOB, GPIO_RX_CTS) #define GPIO_LCD_CD 10 #define GPIO_LCD_CD_PORT GPIOB #define GPIO_LCD_CS 11 diff --git a/main.c b/main.c index 7c46374..99279b3 100644 --- a/main.c +++ b/main.c @@ -894,6 +894,7 @@ config_t config = { .cor_am = -14, .cor_wfm = -17, .cor_nfm = -17, + .ultra = true, }; //properties_t current_props; @@ -2399,6 +2400,8 @@ static const VNAShellCommand commands[] = { "rbw", cmd_rbw, 0 }, { "mode", cmd_mode, CMD_WAIT_MUTEX }, { "spur", cmd_spur, 0 }, + { "lna", cmd_lna, 0 }, + { "ultra", cmd_ultra, 0 }, { "load", cmd_load, 0 }, { "offset", cmd_offset, 0}, { "output", cmd_output, 0 }, diff --git a/nanovna.h b/nanovna.h index 674c7cb..f95da99 100644 --- a/nanovna.h +++ b/nanovna.h @@ -160,6 +160,8 @@ int shell_printf(const char *fmt, ...); void set_marker_frequency(int m, uint32_t f); void toggle_sweep(void); void toggle_mute(void); +void toggle_extra_lna(void); +void set_extra_lna(int t); void load_default_properties(void); enum { @@ -507,6 +509,7 @@ typedef struct config { int8_t cor_am; int8_t cor_wfm; int8_t cor_nfm; + int8_t ultra; int8_t dummy; // uint8_t _reserved[22]; uint32_t checksum; @@ -792,7 +795,7 @@ typedef struct setting float normalize_level; // Level to set normalize to, zero if not doing anything int modulation_frequency; uint32_t checksum; - int ultra; + int extra_lna; }setting_t; extern setting_t setting; diff --git a/sa_cmd.c b/sa_cmd.c index 85c7250..0ee1866 100644 --- a/sa_cmd.c +++ b/sa_cmd.c @@ -107,6 +107,36 @@ VNA_SHELL_FUNCTION(cmd_spur) } } +VNA_SHELL_FUNCTION(cmd_lna) +{ +// static const char cmd[] = "off|on"; +// if (argc != 1) { +// usage: +// shell_printf("usage: spur %s\r\n", cmd); +// return; +// } + int m = generic_option_cmd("lna", "off|on", argc, argv[0]); + if (m>=0) { + set_extra_lna(m); + redraw_request |= REDRAW_CAL_STATUS | REDRAW_AREA; + } +} + +VNA_SHELL_FUNCTION(cmd_ultra) +{ +// static const char cmd[] = "off|on"; +// if (argc != 1) { +// usage: +// shell_printf("usage: spur %s\r\n", cmd); +// return; +// } + int m = generic_option_cmd("ultra", "off|on", argc, argv[0]); + if (m>=0) { + config.ultra = m; + update_min_max_freq(); + } +} + VNA_SHELL_FUNCTION(cmd_output) { #if 0 diff --git a/sa_core.c b/sa_core.c index a7f3e76..696d8ce 100644 --- a/sa_core.c +++ b/sa_core.c @@ -66,7 +66,10 @@ void update_min_max_freq(void) switch(setting.mode) { case M_LOW: minFreq = 0; - maxFreq = 3000000000; // DEFAULT_MAX_FREQ; <---------------- TODO + if (config.ultra) + maxFreq = 2900000000; + else + maxFreq = 850000000; break; #ifdef __ULTRA__ case M_ULTRA: @@ -149,7 +152,10 @@ void reset_settings(int m) case M_LOW: set_sweep_frequency(ST_START, minFreq); set_sweep_frequency(ST_STOP, maxFreq); - set_sweep_frequency(ST_STOP, 800000000); // TODO <----------------- temp ---------------------- + if (config.ultra) + set_sweep_frequency(ST_STOP, 2900000000); // TODO <----------------- temp ---------------------- + else + set_sweep_frequency(ST_STOP, 800000000); // TODO <----------------- temp ---------------------- setting.attenuate = 0.0; // <---------------- WARNING ----------------- setting.auto_attenuation = false; // <---------------- WARNING ----------------- setting.sweep_time_us = 0; @@ -330,6 +336,18 @@ void toggle_tracking_output(void) dirty = true; } +void toggle_extra_lna(void) +{ + setting.extra_lna = !setting.extra_lna; + dirty = true; +} + +void set_extra_lna(int t) +{ + setting.extra_lna = t; + dirty = true; +} + void toggle_mirror_masking(void) { setting.mirror_masking = !setting.mirror_masking; @@ -1125,7 +1143,7 @@ void setupSA(void) #endif ADF4351_Setup(); - enable_lna(false); + enable_extra_lna(false); enable_ultra(false); enable_rx_output(false); enable_high(false); @@ -1306,8 +1324,8 @@ case M_ULTRA: #endif enable_rx_output(false); enable_high(false); - enable_lna(setting.lna); - enable_ultra(setting.ultra); + enable_extra_lna(setting.extra_lna); + enable_ultra(false); break; case M_HIGH: // Direct into 1 mute: @@ -1335,7 +1353,7 @@ mute: enable_rx_output(false); enable_high(true); - enable_lna(false); + enable_extra_lna(false); enable_ultra(false); break; @@ -1375,7 +1393,7 @@ case M_GENLOW: // Mixed output from 0 } SI4463_set_output_level(setting.rx_drive); enable_high(false); - enable_lna(false); + enable_extra_lna(false); enable_ultra(false); break; case M_GENHIGH: // Direct output from 1 @@ -1408,7 +1426,7 @@ case M_GENHIGH: // Direct output from 1 ADF4351_aux_drive(setting.lo_drive); enable_rx_output(false); enable_high(true); - enable_lna(false); + enable_extra_lna(false); enable_ultra(false); break; } @@ -1687,6 +1705,7 @@ static void calculate_static_correction(void) // Calculate the + float_TO_PURE_RSSI( + get_level_offset() + get_attenuation() + + (setting.extra_lna ? -20.0 : 0) // TODO <------------------------- set correct value - setting.offset); } @@ -1847,6 +1866,11 @@ modulation_again: my_microsecond_delay(modulation_delay); } } + // -------------- set ultra --------------------------------- + if (setting.mode == M_LOW && config.ultra && f > 850000000U ) { + enable_ultra(true); + } else + enable_ultra(false); // -------------------------------- Acquisition loop for one requested frequency covering spur avoidance and vbwsteps ------------------------ pureRSSI_t RSSI = float_TO_PURE_RSSI(-150); @@ -3093,6 +3117,15 @@ void draw_cal_status(void) ili9341_drawstring(buf, x, y); } #endif + if (setting.extra_lna) { + ili9341_set_foreground(LCD_BRIGHT_COLOR_GREEN); + y += YSTEP + YSTEP/2 ; + ili9341_drawstring("LNA:", x, y); + + y += YSTEP; + plot_printf(buf, BLEN, "ON"); + ili9341_drawstring(buf, x, y); + } if (setting.subtract_stored) { ili9341_set_foreground(LCD_BRIGHT_COLOR_GREEN); diff --git a/si4432.c b/si4432.c index 3d04426..4f4b0ef 100644 --- a/si4432.c +++ b/si4432.c @@ -2302,13 +2302,17 @@ again: prev_band = -1; // 433MHz } -void enable_lna(int s) +void enable_extra_lna(int s) { #ifdef TINYSA4_PROTO - if (s) - palClearLine(LINE_LNA); // Inverted logic!!! - else - palSetLine(LINE_LNA); + static int old_extra_lna = -1; + if (s != old_extra_lna) { + if (s) + palClearLine(LINE_LNA); // Inverted logic!!! + else + palSetLine(LINE_LNA); + old_extra_lna = s; + } #else (void)s; #endif @@ -2317,10 +2321,14 @@ void enable_lna(int s) void enable_ultra(int s) { #ifdef TINYSA4_PROTO - if (s) - palSetLine(LINE_ULTRA); - else - palClearLine(LINE_ULTRA); +static int old_ultra = -1; + if (s != old_ultra) { + if (s) + palSetLine(LINE_ULTRA); + else + palClearLine(LINE_ULTRA); + old_ultra = s; + } #else (void)s; #endif diff --git a/si4432.h b/si4432.h index 1c4c550..668b5c2 100644 --- a/si4432.h +++ b/si4432.h @@ -197,7 +197,7 @@ void SI4463_init(void); #endif #ifdef TINYSA4 -void enable_lna(int s); +void enable_extra_lna(int s); void enable_ultra(int s); void enable_rx_output(int s); void enable_high(int s); diff --git a/ui_sa.c b/ui_sa.c index 7d11a55..ffcc1e2 100644 --- a/ui_sa.c +++ b/ui_sa.c @@ -767,6 +767,19 @@ static UI_FUNCTION_ADV_CALLBACK(menu_spur_acb) } #endif +static UI_FUNCTION_ADV_CALLBACK(menu_extra_lna_acb) +{ + (void)data; + (void)item; + if (b){ + b->icon = setting.extra_lna == 0 ? BUTTON_ICON_NOCHECK : BUTTON_ICON_CHECK; + return; + } + toggle_extra_lna(); + // menu_move_back(); + ui_mode_normal(); +} + static UI_FUNCTION_ADV_CALLBACK(menu_measure_acb) { (void)item; @@ -1868,15 +1881,16 @@ static const menuitem_t menu_trigger[] = { }; static const menuitem_t menu_level[] = { - { MT_SUBMENU, 0, "REF LEVEL", menu_reflevel}, -//{ MT_SUBMENU, 0, "SCALE/DIV", menu_scale_per}, - { MT_KEYPAD, KM_SCALE, "SCALE/DIV", NULL}, - { MT_SUBMENU, 0, "ATTENUATE", menu_atten}, -// { MT_SUBMENU,0, "CALC", menu_average}, - { MT_SUBMENU, 0, "UNIT", menu_unit}, - { MT_KEYPAD, KM_OFFSET, "EXTERNAL\nAMP",NULL}, - { MT_SUBMENU, 0, "TRIGGER", menu_trigger}, - { MT_CANCEL, 0, S_LARROW" BACK", NULL }, + { MT_SUBMENU, 0, "REF LEVEL", menu_reflevel}, +//{ MT_SUBMENU, 0, "SCALE/DIV", menu_scale_per}, + { MT_KEYPAD, KM_SCALE, "SCALE/DIV", NULL}, + { MT_SUBMENU, 0, "ATTENUATE", menu_atten}, +// { MT_SUBMENU,0, "CALC", menu_average}, + { MT_SUBMENU, 0, "UNIT", menu_unit}, + { MT_KEYPAD, KM_OFFSET, "EXTERNAL\nAMP",NULL}, + { MT_ADV_CALLBACK | MT_LOW ,0,"LNA", menu_extra_lna_acb}, + { MT_SUBMENU, 0, "TRIGGER", menu_trigger}, + { MT_CANCEL, 0, S_LARROW" BACK",NULL }, { MT_NONE, 0, NULL, NULL } // sentinel };