diff --git a/.settings/language.settings.xml b/.settings/language.settings.xml index 25405c1..abc65ba 100644 --- a/.settings/language.settings.xml +++ b/.settings/language.settings.xml @@ -5,7 +5,7 @@ - + @@ -17,7 +17,7 @@ - + diff --git a/Font10x14.c b/Font10x14.c index 43a6a4b..55c26c7 100644 --- a/Font10x14.c +++ b/Font10x14.c @@ -471,12 +471,12 @@ const uint8_t x10x14_bits[(127-wFONT_START_CHAR)*wFONT_GET_HEIGHT*2] = _BMP16(0b0111111110000000), // | ******** | _BMP16(0b1111001111000000), // |**** **** | _BMP16(0b1110000111000000), // |*** *** | - _BMP16(0b1110001111000000), // |*** **** | - _BMP16(0b1110011111000000), // |*** ***** | - _BMP16(0b1110110111000000), // |*** ** *** | - _BMP16(0b1110110111000000), // |*** ** *** | - _BMP16(0b1111100111000000), // |***** *** | - _BMP16(0b1111000111000000), // |**** *** | + _BMP16(0b1110000111000000), // |*** **** | + _BMP16(0b1110000111000000), // |*** **** | + _BMP16(0b1110000111000000), // |*** *** | + _BMP16(0b1110000111000000), // |*** *** | + _BMP16(0b1110000111000000), // |*** *** | + _BMP16(0b1110000111000000), // |*** *** | _BMP16(0b1110000111000000), // |*** *** | _BMP16(0b1111001111000000), // |**** **** | _BMP16(0b0111111110000000), // | ******** | diff --git a/Font7x13b.c b/Font7x13b.c index cd0ef57..ec776dd 100644 --- a/Font7x13b.c +++ b/Font7x13b.c @@ -679,8 +679,8 @@ const uint8_t x7x11b_bits[] = 0b01111000, // | **** | 0b11001100, // |** ** | 0b11001100, // |** ** | - 0b11011100, // |** *** | - 0b11101100, // |*** ** | + 0b11001100, // |** ** | + 0b11001100, // |** ** | 0b11001100, // |** ** | 0b11001100, // |** ** | 0b11001100, // |** ** | diff --git a/flash.c b/flash.c index 63a61be..cbacf5c 100644 --- a/flash.c +++ b/flash.c @@ -237,6 +237,7 @@ caldata_recall(uint16_t id) set_reflevel(setting.reflevel); set_waterfall(); set_level_meter(); + sweep_mode = SWEEP_ENABLE; #ifdef __ULTRA__ ultra_start = (config.ultra_start == ULTRA_AUTO ? DEFAULT_ULTRA_THRESHOLD : config.ultra_start); #endif diff --git a/main.c b/main.c index f0896e5..a5f369a 100644 --- a/main.c +++ b/main.c @@ -109,6 +109,14 @@ int32_t scan_after_dirty = 0; uint8_t completed = false; uint8_t enable_after_complete = 0; +void clear_backup(void) { + uint32_t *f = &backup; // Clear backup when no valid config data + int i = USED_BACKUP_SIZE; + while (i--) + *f++ = 0; +} + + #ifdef TINYSA4 static THD_WORKING_AREA(waThread1, 1224); #else @@ -162,11 +170,19 @@ static THD_FUNCTION(Thread1, arg) while (i--) *t++ = *f++; - completed = sweep(true); - if (sweep_once_count>1) { - sweep_once_count--; +#ifdef __LISTEN__ + if (setting.listen && markers[active_marker].enabled == M_ENABLED) { + perform(false, 0, getFrequency(markers[active_marker].index), false); + SI4432_Listen(MODE_SELECT(setting.mode)); } else - sweep_mode&=~SWEEP_ONCE; +#endif + { + completed = sweep(true); + if (sweep_once_count>1) { + sweep_once_count--; + } else + sweep_mode&=~SWEEP_ONCE; + } } else if (sweep_mode & SWEEP_SELFTEST) { // call from lowest level to save stack space self_test(setting.test); @@ -176,13 +192,6 @@ static THD_FUNCTION(Thread1, arg) } else if (sweep_mode & SWEEP_REMOTE) { sweep_remote(); #endif -#ifdef __LISTEN__ - } else if (sweep_mode & SWEEP_LISTEN) { - if (markers[active_marker].enabled == M_ENABLED) { - perform(false, 0, getFrequency(markers[active_marker].index), false); - SI4432_Listen(MODE_SELECT(setting.mode)); - } -#endif #ifdef __CALIBRATE__ } else if (sweep_mode & SWEEP_CALIBRATE) { // call from lowest level to save stack space @@ -2671,10 +2680,7 @@ int main(void) config.switch_offset = -5.0; #endif if(config_recall()) { - uint32_t *f = &backup; // Clear backup when no valid config data - int i = USED_BACKUP_SIZE; - while (i--) - *f++ = 0; + clear_backup(); } config.cor_am = 0; // Should be removed from config config.cor_nfm = 0; @@ -2729,7 +2735,7 @@ int main(void) load_LCD_properties(); } ui_mode_normal(); - { + if (!(config._mode & _MODE_DONT_SAVE_STATE)) { backup_t b; uint32_t *f = &backup; uint32_t *t = (uint32_t *)&b; diff --git a/nanovna.h b/nanovna.h index 4b11c4d..6851b05 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,7 +26,7 @@ #define TINYSA4 #endif #define TINYSA4_PROTO -//#endif +#endif #ifdef TINYSA_F072 #ifdef TINYSA_F303 @@ -250,6 +250,7 @@ float my_atof(const char *p); freq_t my_atoui(const char *p); int shell_printf(const char *fmt, ...); int usage_printf(const char *fmt, ...); +void clear_backup(void); #ifdef __REMOTE_DESKTOP__ extern uint8_t remote_mouse_down; @@ -319,10 +320,10 @@ enum { #define SWEEP_SELFTEST 0x08 #define SWEEP_REMOTE 0x10 #ifdef __LISTEN__ -#define SWEEP_LISTEN 0x20 -#define SWEEP_CALIBRATE_HARMONIC 0x40 +//#define SWEEP_LISTEN 0x20 //#define SWEEP_FACTORY 0x20 #endif +#define SWEEP_CALIBRATE_HARMONIC 0x40 #define SWEEP_UI_MODE 0x80 extern uint8_t sweep_mode; @@ -731,9 +732,10 @@ float marker_to_value(const int i); #define _MODE_CONNECTION_MASK 0x04 #define _MODE_SERIAL 0x04 #define _MODE_USB 0x00 - +// don't save state +#define _MODE_DONT_SAVE_STATE 0x08 // auto name -#define _MODE_AUTO_FILENAME 0x08 +#define _MODE_AUTO_FILENAME 0x10 #pragma pack(push, 4) typedef struct config { @@ -1164,6 +1166,7 @@ typedef struct setting uint8_t spur_removal; // enum uint8_t disable_correction; int8_t normalized_trace; + uint8_t listen; int8_t tracking; // -1...1 Can NOT convert to bool!!!!!! uint8_t atten_step; // 0...1 !!! need convert to bool @@ -1381,7 +1384,7 @@ typedef struct properties { //sizeof(properties_t) == 0x1200 -#define CONFIG_MAGIC 0x434f4e5B /* 'CONF' */ +#define CONFIG_MAGIC 0x434f4e5C /* 'CONF' */ extern int16_t lastsaveid; //extern properties_t *active_props; diff --git a/sa_cmd.c b/sa_cmd.c index 2da7f5e..7645e36 100644 --- a/sa_cmd.c +++ b/sa_cmd.c @@ -978,7 +978,7 @@ VNA_SHELL_FUNCTION(cmd_z) return; } if (argc == 1) { - setting.step_delay = atoi(argv[0]); + setting.step_delay = my_atoi(argv[0]); dirty = true; } } @@ -990,7 +990,7 @@ VNA_SHELL_FUNCTION(cmd_n) return; } if (argc == 1) { - setting.offset_delay = atoi(argv[0]); + setting.offset_delay = my_atoi(argv[0]); dirty = true; } } @@ -1321,8 +1321,8 @@ again: switch (m) { default: goto usage; case 's': test_output_switch = *a - '0'; break; - case 'd': test_output_drive = atoi(a); break; - case 'a': test_output_attenuate = atoi(a); break; + case 'd': test_output_drive = my_atoi(a); break; + case 'a': test_output_attenuate = my_atoi(a); break; #ifdef TINYSA4 case 'p': test_path = *a - '0'; break; #endif diff --git a/sa_core.c b/sa_core.c index 5ecb87f..641deba 100644 --- a/sa_core.c +++ b/sa_core.c @@ -18,6 +18,7 @@ #include "si4432.h" // comment out for simulation //#endif #include "stdlib.h" +//#define TINYSA4 #pragma GCC push_options #ifdef TINYSA4 @@ -2795,7 +2796,7 @@ void interpolate_maximum(int m) const INTER_TYPE y1 = ref_marker_levels[idx - 1]; const INTER_TYPE y2 = ref_marker_levels[idx + 0]; const INTER_TYPE y3 = ref_marker_levels[idx + 1]; - const INTER_TYPE d = abs(delta_Hz) * 0.5 * (y1 - y3) / ((y1 - (2 * y2) + y3) + 1e-12); + const INTER_TYPE d = fabs(delta_Hz) * 0.5 * (y1 - y3) / ((y1 - (2 * y2) + y3) + 1e-12); //const float bin = (float)idx + d; markers[m].frequency += d; } @@ -7450,7 +7451,6 @@ void calibrate(void) { int local_test_status; int old_sweep_points = setting._sweep_points; - reset_calibration(); #ifdef TINYSA4 int old_ultra = config.ultra; config.ultra = true; @@ -7516,6 +7516,7 @@ void calibrate(void) #endif #endif + reset_calibration(); in_calibration = true; for (calibration_stage = CS_NORMAL; calibration_stage < CS_MAX ; calibration_stage++) { for (int k = 0; k<3; k++) { @@ -7594,7 +7595,7 @@ void calibrate(void) local_test_status = test_validate(test_case); calibration_busy(); } - local_test_status = TS_PASS; + local_test_status = TS_PASS; // Must be forced because test_validate calculates pass band wrong #else // set_RBW(power_rbw[j]); // set_sweep_points(21); @@ -7634,7 +7635,13 @@ void calibrate(void) local_test_status = test_validate(test_case); // Validate test also sets attenuation if zero span #endif #endif - if (calibration_stage == CS_NORMAL && peakLevel < -40) { + if ((calibration_stage == CS_NORMAL && peakLevel < -40) +#ifdef TINYSA4 + || (calibration_stage == CS_LNA && peakLevel < -40) + || (calibration_stage == CS_ULTRA && peakLevel < -40) + || (calibration_stage == CS_DIRECT && peakLevel < direct_level - 10) +#endif + ) { #ifdef TINYSA4 low_level: #endif diff --git a/ui.c b/ui.c index 94a682e..cfdb14f 100644 --- a/ui.c +++ b/ui.c @@ -542,7 +542,7 @@ show_version(void) ili9341_drawstring_7x13(info_about[i++], x, y+=bFONT_STR_HEIGHT+2-5); } lcd_set_font(FONT_NORMAL); - lcd_printf(x, y+=bFONT_STR_HEIGHT, "HW Version:%s", get_hw_version_text()); + lcd_printf(x, y+=bFONT_STR_HEIGHT, "HW Version:%s (%d)", get_hw_version_text(), adc1_single_read(0)); extern const char *states[]; #define ENABLE_THREADS_COMMAND @@ -1523,10 +1523,12 @@ static UI_FUNCTION_ADV_CALLBACK(menu_curve_acb) reset_settings(old_m); break; case CORRECTION_LNA: + case CORRECTION_LNA_ULTRA: reset_settings(M_LOW); setting.extra_lna = true; goto common; case CORRECTION_LOW: + case CORRECTION_LOW_ULTRA: reset_settings(M_LOW); common: set_sweep_frequency(ST_SPAN, 1000000); @@ -1820,10 +1822,11 @@ static UI_FUNCTION_ADV_CALLBACK(menu_store_preset_acb) b->param_1.u = data; return; } - if (data == 100) { + if (data >= 100) { reset_settings(M_LOW); // Restore all defaults in Low mode set_refer_output(-1); // setting.mode = -1; + if (data == 101) clear_backup(); data = 0; } caldata_save(data); @@ -1956,26 +1959,13 @@ static UI_FUNCTION_ADV_CALLBACK(menu_listen_acb) (void)data; (void)item; if (b){ - b->icon = (sweep_mode & SWEEP_LISTEN) ? BUTTON_ICON_CHECK : BUTTON_ICON_NOCHECK; + b->icon = (setting.listen) ? BUTTON_ICON_CHECK : BUTTON_ICON_NOCHECK; return; } - if (sweep_mode & SWEEP_LISTEN) { - sweep_mode = SWEEP_ENABLE; - } else { - sweep_mode = SWEEP_LISTEN; - } + setting.listen = !setting.listen; ui_mode_normal(); redraw_frame(); request_to_redraw_grid(); - -#if 0 - if (markers[active_marker].enabled == M_ENABLED) { - do { - perform(false,0,frequencies[markers[active_marker].index], false); - SI4432_Listen(MODE_SELECT(setting.mode)); - } while (ui_process_listen_lever()); - } -#endif } #endif #ifdef TINYSA4 @@ -3210,6 +3200,7 @@ static UI_FUNCTION_ADV_CALLBACK(menu_harmonic_acb) return; } set_harmonic(data); + config_save(); } #endif @@ -3290,6 +3281,17 @@ static UI_FUNCTION_ADV_CALLBACK(menu_settings_pulse_acb){ toggle_pulse(); } +static UI_FUNCTION_ADV_CALLBACK(menu_save_state_acb){ + (void)item; + (void)data; + if(b){ + b->icon = (config._mode & _MODE_DONT_SAVE_STATE) ? BUTTON_ICON_NOCHECK : BUTTON_ICON_CHECK; + return; + } + config._mode ^= _MODE_DONT_SAVE_STATE; + config_save(); +} + #ifdef __DRAW_LINE__ static UI_FUNCTION_ADV_CALLBACK(menu_settings_draw_line_acb){ (void)item; @@ -3628,10 +3630,11 @@ static const menuitem_t menu_load_preset[] = { { MT_ADV_CALLBACK, 0, "LOAD\nSTARTUP", menu_load_preset_acb}, { MT_ADV_CALLBACK|MT_REPEATS, DATA_STARTS_REPEATS(1,4), MT_CUSTOM_LABEL, menu_load_preset_acb}, + { MT_ADV_CALLBACK, 101, "LOAD\nDEFAULTS",menu_store_preset_acb}, + { MT_ADV_CALLBACK, _MODE_DONT_SAVE_STATE, "SAVE\nSTATE", menu_save_state_acb}, #ifdef __SD_FILE_BROWSER__ { MT_CALLBACK, FMT_PRS_FILE, "LOAD FROM\n SD", menu_sdcard_browse_cb }, #endif - { MT_SUBMENU, 0, "STORE" , menu_store_preset}, { MT_NONE, 0, NULL, menu_back} // next-> menu_back }; @@ -4088,6 +4091,9 @@ static const menuitem_t menu_settings[] = { MT_ADV_CALLBACK,0, "PROGRESS\nBAR", menu_progress_bar_acb}, { MT_ADV_CALLBACK, 0, "DIRECT\nMODE", menu_direct_acb}, { MT_ADV_CALLBACK, 0, "LINEAR\nAVERAGING", menu_linear_averaging_acb}, +#ifdef __HARMONIC__ + { MT_SUBMENU ,0, "HARMONIC", menu_harmonic}, +#endif { MT_KEYPAD, KM_FREQ_CORR, "FREQ CORR\n\b%s", "Enter ppb correction"}, // { MT_SUBMENU, 0, "CALIBRATE\nHARMONIC", menu_calibrate_harmonic}, #ifdef __NOISE_FIGURE__