From 5b97b35307e991f647b134ea11b99644c12c8a2b Mon Sep 17 00:00:00 2001 From: erikkaashoek Date: Sat, 8 Jan 2022 16:46:27 +0100 Subject: [PATCH] Repair output mode restore --- main.c | 17 +++++++++++------ nanovna.h | 13 +++++++++---- sa_cmd.c | 10 ++++++---- sa_core.c | 23 ++++++++++++++++------- si4432.c | 3 +++ ui.c | 10 ++++++---- ui_sa.c | 3 ++- 7 files changed, 53 insertions(+), 26 deletions(-) diff --git a/main.c b/main.c index b00cfa0..9b57e79 100644 --- a/main.c +++ b/main.c @@ -144,7 +144,11 @@ static THD_FUNCTION(Thread1, arg) if (setting.rbw_x10 == 0) b.RBW = 0; else +#ifdef TINYSA4 b.RBW = SI4463_rbw_selected+1; +#else + b.RBW = SI4432_rbw_selected+1; +#endif b.mode = setting.mode; uint32_t *f = (uint32_t *)&b; uint32_t *t = &backup; @@ -720,12 +724,11 @@ VNA_SHELL_FUNCTION(cmd_refresh) auto_capture = m; } } - VNA_SHELL_FUNCTION(cmd_touch) { if (argc != 2) return; touch_set(my_atoi(argv[0]), my_atoi(argv[1])); - remote_mouse_down = true; + remote_mouse_down = 1; handle_touch_interrupt(); } @@ -733,9 +736,10 @@ VNA_SHELL_FUNCTION(cmd_release) { if (argc == 2) touch_set(my_atoi(argv[0]), my_atoi(argv[1])); - remote_mouse_down = false; + remote_mouse_down = 2; handle_touch_interrupt(); } + #endif VNA_SHELL_FUNCTION(cmd_capture) @@ -2468,18 +2472,19 @@ int main(void) case M_HIGH: break; case M_GENLOW: + menu_push_submenu(menu_mode); menu_push_submenu(menu_lowoutputmode); break; case M_GENHIGH: + menu_push_submenu(menu_mode); menu_push_submenu(menu_highoutputmode); break; } if (b.frequency0 != 0 || b.frequency1 != 0) { if (b.mode <= M_HIGH){ - setting.frequency0 = b.frequency0; - setting.frequency1 = b.frequency1; - update_frequencies(); + set_sweep_frequency(ST_START, b.frequency0); + set_sweep_frequency(ST_STOP, b.frequency1); } else { set_sweep_frequency(ST_CW, (b.frequency0 + b.frequency1)/2); set_sweep_frequency(ST_SPAN, (b.frequency1 - b.frequency0)); diff --git a/nanovna.h b/nanovna.h index e2bbc06..85b65cb 100644 --- a/nanovna.h +++ b/nanovna.h @@ -18,7 +18,7 @@ */ #include "ch.h" -//#ifdef TINYSA_F303 +#ifdef TINYSA_F303 #ifdef TINYSA_F072 #error "Remove comment for #ifdef TINYSA_F303" #endif @@ -26,16 +26,16 @@ #define TINYSA4 #endif #define TINYSA4_PROTO -//#endif +#endif -#ifdef TINYSA_F072 +//#ifdef TINYSA_F072 #ifdef TINYSA_F303 #error "Remove comment for #ifdef TINYSA_F072" #endif #ifndef TINYSA3 #define TINYSA3 #endif -#endif +//#endif // Need enable HAL_USE_SPI in halconf.h #define __USE_DISPLAY_DMA__ @@ -1476,9 +1476,14 @@ void sd_card_load_config(char *filename); #pragma pack(push) #pragma pack(1) +#ifdef TINYSA4 extern uint8_t SI4463_rbw_selected; +#else +extern uint8_t SI4432_rbw_selected; +#endif extern const menuitem_t menu_lowoutputmode[]; extern const menuitem_t menu_highoutputmode[]; +extern const menuitem_t menu_mode[]; extern void menu_push_submenu(const menuitem_t *submenu); typedef struct { diff --git a/sa_cmd.c b/sa_cmd.c index 7ee5f72..896c88a 100644 --- a/sa_cmd.c +++ b/sa_cmd.c @@ -307,7 +307,7 @@ VNA_SHELL_FUNCTION(cmd_leveloffset) { // 0 1 2 #ifdef TINYSA4 - static const char cmd_mode_list[] = "low|high|switch|lna|harmonic|shift"; + static const char cmd_mode_list[] = "low|high|switch|receive_switch|lna|harmonic|shift"; #else static const char cmd_mode_list[] = "low|high|switch"; #endif @@ -319,6 +319,7 @@ VNA_SHELL_FUNCTION(cmd_leveloffset) shell_printf(p, "high output", config.high_level_output_offset); shell_printf(p, "switch", config.switch_offset); #ifdef TINYSA4 + shell_printf(p, "receive_switch",config.receive_switch_offset); shell_printf(p, "lna", config.lna_level_offset); shell_printf(p, "harmonic", config.harmonic_level_offset); shell_printf(p, "shift", config.shift_level_offset); @@ -335,9 +336,10 @@ VNA_SHELL_FUNCTION(cmd_leveloffset) case 1: config.high_level_offset = v; break; case 2: config.switch_offset = v; break; #ifdef TINYSA4 - case 3: config.lna_level_offset = v; break; - case 4: config.harmonic_level_offset = v; break; - case 5: config.shift_level_offset = v; break; + case 3: config.receive_switch_offset = v; break; + case 4: config.lna_level_offset = v; break; + case 5: config.harmonic_level_offset = v; break; + case 6: config.shift_level_offset = v; break; #endif default: goto usage; } diff --git a/sa_core.c b/sa_core.c index c672db3..c91c406 100644 --- a/sa_core.c +++ b/sa_core.c @@ -105,8 +105,8 @@ const int8_t drive_dBm [16] = {-38, -32, -30, -27, -24, -19, -15, -12, -5, -2, 0 #endif #ifdef TINYSA4 -#define SWITCH_ATTENUATION ((setting.mode == M_GENHIGH && config.high_out_adf4350) ? 40 : 35.8 - config.switch_offset) -#define RECEIVE_SWITCH_ATTENUATION (38 - config.receive_switch_offset) +#define SWITCH_ATTENUATION ((setting.mode == M_GENHIGH && config.high_out_adf4350) ? 40 : 23 - config.switch_offset) +#define RECEIVE_SWITCH_ATTENUATION (29 - config.receive_switch_offset) //#define POWER_OFFSET -18 // Max level with all enabled //#define POWER_RANGE 70 #define MAX_DRIVE ((setting.mode == M_GENHIGH && config.high_out_adf4350 ) ? 3 : 18) @@ -125,7 +125,7 @@ const int8_t drive_dBm [16] = {-38, -32, -30, -27, -24, -19, -15, -12, -5, -2, 0 #define SWITCH_ATTENUATION (29 - config.switch_offset) #define RECEIVE_SWITCH_ATTENUATION 24 #define POWER_OFFSET 15 -#define MAX_DRIVE (setting.mode == M_GENHIGH ? 15 : 11) +#define MAX_DRIVE (setting.mode == M_GENHIGH ? 13 : 11) // The value of 13 is linked to the SL_GENHIGH_LEVEL_MAX of 9 #define MIN_DRIVE 8 #define SL_GENHIGH_LEVEL_MIN -38 #define SL_GENHIGH_LEVEL_MAX 9 @@ -1091,9 +1091,11 @@ void set_actual_power(float o) // Set peak level to known value else #endif { - // if (get_attennuation() > 32) - // config.receive_switch_offset = new_offset; - // else +#ifdef TINYSA4 + if (setting.atten_step) + config.receive_switch_offset -= new_offset; + else +#endif config.low_level_offset = new_offset; } } @@ -6237,6 +6239,7 @@ void calibrate(void) reset_calibration(); #ifdef TINYSA4 bool calibrate_lna = false; + bool calibrate_switch = false; again: #endif for (int k = 0; k<2; k++) { @@ -6250,7 +6253,9 @@ again: setting.rbw_x10 = 3000; int test_case = TEST_POWER; #ifdef TINYSA4 - set_extra_lna(calibrate_lna); + setting.atten_step = calibrate_switch; + if (!calibrate_switch) + set_extra_lna(calibrate_lna); #endif set_average(0, AV_100); for (int m=1; m<20; m++) { @@ -6321,6 +6326,10 @@ again: calibrate_lna = true; goto again; } + if (!calibrate_switch) { + calibrate_switch = true; + goto again; + } #endif #if 0 // No high input calibration as CAL OUTPUT is unreliable diff --git a/si4432.c b/si4432.c index be9cbe7..c920c7d 100644 --- a/si4432.c +++ b/si4432.c @@ -180,6 +180,8 @@ static inline void shiftInBuf(uint16_t sel, uint8_t addr, deviceRSSI_t *buf, uin const uint16_t SI_nSEL[MAX_SI4432+1] = { GPIO_RX_SEL, GPIO_LO_SEL, 0}; // #3 is dummy!!!!!! uint16_t SI4432_Sel = GPIO_RX_SEL; // currently selected SI4432 +uint8_t SI4432_rbw_selected = 0; + // volatile int SI4432_guard = 0; #ifdef __SI4432_H__ @@ -456,6 +458,7 @@ uint16_t force_rbw(int i) SI4432_Write_Byte(SI4432_IF_FILTER_BW, RBW_choices[i].reg); // Write RBW settings to Si4432 SI4432_RSSI_correction = float_TO_PURE_RSSI(RBW_choices[i].RSSI_correction_x_10 - 1200)/10; // Set RSSI correction // SI4432_RSSI_correction = float_TO_PURE_RSSI( - 1200)/10; // Set RSSI correction + SI4432_rbw_selected = i; return RBW_choices[i].RBWx10; // RBW achieved by Si4432 in kHz * 10 } diff --git a/ui.c b/ui.c index d7aa2e1..3424666 100644 --- a/ui.c +++ b/ui.c @@ -287,8 +287,10 @@ touch_start_watchdog(void) if (touch_status_flag&TOUCH_INTERRUPT_ENABLED) return; touch_status_flag^=TOUCH_INTERRUPT_ENABLED; adc_start_analog_watchdog(); +#ifdef REMOTE_DESKTOP + remote_mouse_down = 0; +#endif } - static void touch_stop_watchdog(void) { @@ -335,10 +337,10 @@ touch_check(void) last_touch_x = x; last_touch_y = y; } -#ifdef __REMOTE_DESKTOP__ - remote_mouse_down = false; +#ifdef REMOTE_DESKTOP + remote_mouse_down = 0; } else { - stat = remote_mouse_down; + stat = remote_mouse_down == 1; #endif } if (stat != last_touch_status) { diff --git a/ui_sa.c b/ui_sa.c index e596ffe..78a0eac 100644 --- a/ui_sa.c +++ b/ui_sa.c @@ -527,6 +527,7 @@ ui_slider_t ui_sliders [] = // ===[MENU CALLBACKS]========================================================= const menuitem_t menu_lowoutputmode[]; const menuitem_t menu_highoutputmode[]; +const menuitem_t menu_mode[]; static const menuitem_t menu_modulation[]; static const menuitem_t menu_top[]; static const menuitem_t menu_trace[]; @@ -3012,7 +3013,7 @@ static const menuitem_t menu_stimulus[] = { { MT_NONE, 0, NULL, menu_back} // next-> menu_back }; -static const menuitem_t menu_mode[] = { +const menuitem_t menu_mode[] = { // { MT_FORM | MT_TITLE, 0, "tinySA MODE", NULL}, { MT_FORM | MT_ADV_CALLBACK | MT_ICON, I_LOW_INPUT+I_SA, "%s to LOW in", menu_mode_acb}, { MT_FORM | MT_ADV_CALLBACK | MT_ICON, I_HIGH_INPUT+I_SA, "%s to HIGH in", menu_mode_acb},