diff --git a/NANOVNA_STM32_F303/board.h b/NANOVNA_STM32_F303/board.h index 6d7359c..0a772be 100644 --- a/NANOVNA_STM32_F303/board.h +++ b/NANOVNA_STM32_F303/board.h @@ -1184,8 +1184,10 @@ #endif #ifdef USB_DP_R_VDD -#define usb_lld_connect_bus(usbp) -#define usb_lld_disconnect_bus(usbp) +//#define usb_lld_connect_bus(usbp) +//#define usb_lld_disconnect_bus(usbp) +#define usb_lld_connect_bus(usbp) {palSetPadMode(GPIOA, GPIOA_USB_DP, PAL_MODE_ALTERNATE(14));} +#define usb_lld_disconnect_bus(usbp) {palSetPadMode(GPIOA, GPIOA_USB_DP, PAL_STM32_MODE_OUTPUT); palClearPad(GPIOA, GPIOA_USB_DP);} #else // USB_DP connect to VDD by 1.5K R, and USB_DP short with PA10 #define usb_lld_connect_bus(usbp) palSetPadMode(GPIOA, GPIOA_USB_DISC, PAL_MODE_INPUT) #define usb_lld_disconnect_bus(usbp) palClearPad(GPIOA, GPIOA_USB_DISC) diff --git a/main.c b/main.c index 1a679db..b152f23 100644 --- a/main.c +++ b/main.c @@ -869,13 +869,22 @@ config_t config = { .high_level_offset = 100, // Uncalibrated .correction_frequency = { { 10000, 100000, 200000, 500000, 30000000, 140000000, 200000000, 300000000, 330000000, 350000000 }, { 240000000, 280000000, 300000000, 400000000, 500000000, 600000000, 700000000, 800000000, 900000000, 960000000 }}, +#ifdef __ULTRA__ + .correction_value = { { +6.0, +2.8, +1.6, -0.4, 0.0, -0.4, +0.4, +0.4, +0.4, +0.4 }, + { 0, 0, 0, 0, 0.0, 0, 0, 0, 0, 0 } }, +#else .correction_value = { { +6.0, +2.8, +1.6, -0.4, 0.0, -0.4, +0.4, +3.0, +4.0, +8.1 }, { 0, 0, 0, 0, 0.0, 0, 0, 0, 0, 0 } }, +#endif .setting_frequency_10mhz = 10000000, .cor_am = 0,// -10, .cor_wfm = 0, //-18, .cor_nfm = 0, //-18, .ext_zero_level = 128, +#ifdef __ULTRA + .ultra_threshold = 350000000, + .ultra = false, +#endif #endif #ifdef TINYSA4 ._brightness = DEFAULT_BRIGHTNESS, @@ -964,9 +973,12 @@ void set_sweep_points(uint16_t points){ VNA_SHELL_FUNCTION(cmd_scan) { - freq_t start, stop; + freq_t start = get_sweep_frequency(ST_START); + freq_t stop = get_sweep_frequency(ST_STOP); uint32_t old_points = sweep_points; uint32_t i; + if (argc == 0) + goto do_scan; if (argc < 2 || argc > 4) { shell_printf("usage: scan {start(Hz)} {stop(Hz)} [points] [outmask]\r\n"); return; @@ -987,8 +999,11 @@ VNA_SHELL_FUNCTION(cmd_scan) sweep_points = points; } set_frequencies(start, stop, sweep_points); +do_scan: pause_sweep(); + setting.sweep = true; // prevent abort sweep(false); + setting.sweep = false; // Output data after if set (faster data recive) if (argc == 4) { uint16_t mask = my_atoui(argv[3]); @@ -1296,6 +1311,11 @@ VNA_SHELL_FUNCTION(cmd_sweep) set_sweep_frequency(type, value1); return; } + // Parse sweep {go|abort} + static const char sweep_cmd2[] = "go|abort"; + int type2 = get_str_index(argv[0], sweep_cmd2); + if (type2==0) { setting.sweep = true; return;} + if (type2==1) { setting.sweep = false; return;} // Parse sweep {start(Hz)} [stop(Hz)] set_sweep_frequency(ST_START, value0); if (value1) @@ -1305,7 +1325,8 @@ VNA_SHELL_FUNCTION(cmd_sweep) return; usage: shell_printf("usage: sweep {start(Hz)} [stop(Hz)] [points]\r\n"\ - "\tsweep {%s} {freq(Hz)}\r\n", sweep_cmd); + "\tsweep {%s}\r\n"\ + "\tsweep {%s} {freq(Hz)}\r\n", sweep_cmd2, sweep_cmd); } VNA_SHELL_FUNCTION(cmd_save) @@ -1906,6 +1927,8 @@ static const VNAShellCommand commands[] = #endif #ifdef TINYSA4 { "lna", cmd_lna, CMD_WAIT_MUTEX | CMD_RUN_IN_LOAD }, +#endif +#ifdef __ULTRA__ { "ultra", cmd_ultra, CMD_WAIT_MUTEX | CMD_RUN_IN_LOAD }, { "ultra_start", cmd_ultra_start, CMD_WAIT_MUTEX | CMD_RUN_IN_LOAD }, #endif diff --git a/nanovna.h b/nanovna.h index 2634490..74d265e 100644 --- a/nanovna.h +++ b/nanovna.h @@ -77,6 +77,7 @@ #define __LIMITS__ #define __MCU_CLOCK_SHIFT__ #ifdef TINYSA4 +#define __ULTRA__ #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) @@ -94,6 +95,7 @@ //#define __FFT_VBW__ //#define __FFT_DECONV__ #else +//#define __ULTRA__ //#define __HARMONIC__ #define __USE_FREQ_TABLE__ // Enable use table for frequency list #endif @@ -103,6 +105,10 @@ #define DEFAULT_IF 433800000 #define DEFAULT_SPUR_IF 434000000 #define DEFAULT_MAX_FREQ 350000000 +#define MAX_LO_FREQ 960000000UL +#define MIN_LO_FREQ 240000000UL +#define MIN_BELOW_LO 550000000UL +#define ULTRA_MAX_FREQ 1390000000UL //#define DEFAULT_MAX_FREQ 527000000 #define HIGH_MIN_FREQ_MHZ 240 #define HIGH_MAX_FREQ_MHZ 960 @@ -119,7 +125,7 @@ #define ULTRA_MAX_FREQ 5350000000ULL //#define ULTRA_MAX_FREQ 2900000000ULL #define MAX_LO_FREQ 4350000000ULL -#define LOW_MAX_FREQ 800000000ULL +//#define LOW_MAX_FREQ 800000000ULL #define MIN_BELOW_LO 550000000ULL #endif /* @@ -144,6 +150,7 @@ #define TRACE_TEMP (LCD_TRACE_3_COLOR - LCD_TRACE_1_COLOR) #else #define TRACE_TEMP (LCD_TRACE_4_COLOR - LCD_TRACE_1_COLOR) +#define TRACE_STORED2 (LCD_TRACE_3_COLOR - LCD_TRACE_1_COLOR) #endif #define TRACE_STORED (LCD_TRACE_2_COLOR - LCD_TRACE_1_COLOR) //#define TRACE_AGE 3 @@ -278,10 +285,12 @@ extern float channel_power[3]; extern float channel_power_watt[3]; extern const char * const unit_string[]; extern uint16_t vbwSteps; -#ifdef TINYSA4 -extern float measured_noise_figure; +#ifdef __ULTRA__ extern freq_t ultra_threshold; extern bool ultra; +#endif +#ifdef TINYSA4 +extern float measured_noise_figure; extern float *drive_dBm; extern int test_output; extern int test_output_switch; @@ -376,12 +385,15 @@ void sweep_remote(void); void calculate_step_delay(void); extern int generic_option_cmd( const char *cmd, const char *cmd_list, int argc, char *argv); +#ifdef __ULTRA__ +void toggle_ultra(void); +void enable_ultra(int); +#endif #ifdef TINYSA4 void clear_frequency_cache(void); void toggle_high_out_adf4350(void); extern int high_out_adf4350; void set_30mhz(freq_t); -void toggle_ultra(void); void set_IF2(int f); void set_R(int f); extern void set_modulo(uint32_t f); @@ -398,7 +410,10 @@ void set_10mhz(freq_t); #define LOW_OUT_OFFSET config.low_level_output_offset #define HIGH_OUT_OFFSET config.high_level_output_offset #endif - +#ifdef __ULTRA__ +extern bool debug_spur; +extern void toggle_debug_spur(void); +#endif #ifdef __AUDIO__ /* * dsp.c @@ -665,6 +680,8 @@ typedef struct config { #ifdef TINYSA4 freq_t frequency_IF1; freq_t frequency_IF2; +#endif +#ifdef __ULTRA__ freq_t ultra_threshold; int8_t ultra; #endif @@ -1084,9 +1101,11 @@ typedef struct setting freq_t *correction_frequency; float *correction_value; -#ifdef TINYSA4 - bool extra_lna; +#ifdef __ULTRA__ uint8_t ultra; // enum ?? +#endif + #ifdef TINYSA4 + bool extra_lna; int R; // KM_R int32_t exp_aver; #endif diff --git a/plot.c b/plot.c index 6bab64c..c8f60a8 100644 --- a/plot.c +++ b/plot.c @@ -1806,7 +1806,7 @@ static const uint8_t sd_icon [] = { int16_t vbat = adc_vbat_read(); if (vbat <= 0) return; - uint8_t string_buf[16]; + uint8_t string_buf[24]; // Set battery color ili9341_set_foreground(vbat < BATTERY_WARNING_LEVEL ? LCD_LOW_BAT_COLOR : (vbat < BATTERY_MID_LEVEL ? LCD_TRACE_1_COLOR : LCD_NORMAL_BAT_COLOR)); ili9341_set_background(LCD_BG_COLOR); diff --git a/sa_cmd.c b/sa_cmd.c index ceb3575..7ee5f72 100644 --- a/sa_cmd.c +++ b/sa_cmd.c @@ -149,7 +149,8 @@ VNA_SHELL_FUNCTION(cmd_lna) redraw_request |= REDRAW_CAL_STATUS | REDRAW_AREA; } } - +#endif +#ifdef __ULTRA__ VNA_SHELL_FUNCTION(cmd_ultra) { // static const char cmd[] = "off|on"; @@ -449,7 +450,7 @@ VNA_SHELL_FUNCTION(cmd_zero) } } -#ifdef TINYSA4 +#ifdef __ULTRA__ VNA_SHELL_FUNCTION(cmd_ultra_start) { if (argc != 1) { @@ -461,7 +462,9 @@ VNA_SHELL_FUNCTION(cmd_ultra_start) config_save(); } } +#endif +#ifdef TINYSA4 VNA_SHELL_FUNCTION(cmd_if1) { if (argc != 1) { diff --git a/sa_core.c b/sa_core.c index 9570df7..e3f4154 100644 --- a/sa_core.c +++ b/sa_core.c @@ -51,6 +51,9 @@ float *imag = (float *) &spi_buffer[512]; uint8_t scandirty = true; bool debug_avoid = false; bool debug_avoid_second = false; +#ifdef __ULTRA__ +bool debug_spur = false; +#endif int current_index = -1; setting_t setting; @@ -63,9 +66,11 @@ freq_t maxFreq = 520000000; static float old_a = -150; // cached value to reduce writes to level registers int spur_gate = 100; -#ifdef TINYSA4 +#ifdef __ULTRA__ freq_t ultra_threshold; bool ultra; +#endif +#ifdef TINYSA4 int noise_level; float log_averaging_correction; uint32_t old_CFGR; @@ -154,14 +159,16 @@ void update_min_max_freq(void) switch(setting.mode) { case M_LOW: minFreq = 0; -#ifdef TINYSA4 +#ifdef __ULTRA__ if (ultra) +#ifdef TINYSA4 maxFreq = 12000000000; // ULTRA_MAX_FREQ; // make use of harmonic mode above ULTRA_MAX_FREQ - else - maxFreq = LOW_MAX_FREQ; #else - maxFreq = DEFAULT_MAX_FREQ; + maxFreq = 3000000000; // ULTRA_MAX_FREQ; // make use of harmonic mode above ULTRA_MAX_FREQ +#endif + else #endif + maxFreq = DEFAULT_MAX_FREQ; #ifdef TINYSA4 plot_printf(range_text, sizeof range_text, "%QHz to %QHz", minFreq, maxFreq); #endif @@ -169,7 +176,7 @@ void update_min_max_freq(void) case M_GENLOW: minFreq = 0; #ifdef TINYSA4 - maxFreq = LOW_MAX_FREQ; + maxFreq = DEFAULT_MAX_FREQ; #else maxFreq = DEFAULT_MAX_FREQ; #endif @@ -218,9 +225,11 @@ void reset_settings(int m) // strcpy((char *)spi_buffer, dummy); setting.mode = m; setting.sweep = false; -#ifdef TINYSA4 +#ifdef __ULTRA__ ultra_threshold = config.ultra_threshold; ultra = config.ultra; +#endif +#ifdef TINYSA4 drive_dBm = (float *) (setting.mode == M_GENHIGH && config.high_out_adf4350 ? adf_drive_dBm : si_drive_dBm); setting.exp_aver = 1; #endif @@ -252,11 +261,19 @@ void reset_settings(int m) setting.stored[TRACE_STORED] = true; TRACE_ENABLE(TRACE_STORED_FLAG); } else - TRACE_DISABLE(TRACE_STORED_FLAG|TRACE_TEMP_FLAG); +#ifdef TINYSA4 + TRACE_DISABLE(TRACE_STORED_FLAG|TRACE_TEMP_FLAG|TRACE_STORED2); +#else + TRACE_DISABLE(TRACE_STORED_FLAG|TRACE_TEMP_FLAG); +#endif #ifdef TINYSA4 setting.harmonic = 3; // Automatically used when above ULTRA_MAX_FREQ +#else +#ifdef __ULTRA__ + setting.harmonic = 3; #else setting.harmonic = 0; +#endif #endif setting.show_stored = 0; setting.auto_attenuation = false; @@ -287,8 +304,10 @@ void reset_settings(int m) setting.below_IF = S_AUTO_OFF; setting.tracking_output = false; setting.measurement = M_OFF; -#ifdef TINYSA4 +#ifdef __ULTRA__ setting.ultra = S_AUTO_OFF; +#endif +#ifdef TINYSA4 setting.frequency_IF = config.frequency_IF1 + STATIC_DEFAULT_SPUR_OFFSET/2; ; #else setting.frequency_IF = DEFAULT_IF; @@ -306,7 +325,7 @@ void reset_settings(int m) // setting.refer = -1; // do not reset reffer when switching modes setting.mute = true; #ifdef __SPUR__ -#ifdef TINYSA4 +#ifdef __ULTRA__ if (m == M_LOW) setting.spur_removal = S_AUTO_OFF; else @@ -322,11 +341,8 @@ void reset_settings(int m) case M_LOW: set_sweep_frequency(ST_START, minFreq); set_sweep_frequency(ST_STOP, maxFreq); -// if (ultra) -// set_sweep_frequency(ST_STOP, 2900000000); // TODO <----------------- temp ---------------------- -// else #ifdef TINYSA4 - set_sweep_frequency(ST_STOP, LOW_MAX_FREQ); // TODO <----------------- temp ---------------------- + set_sweep_frequency(ST_STOP, DEFAULT_MAX_FREQ); // TODO <----------------- temp ---------------------- setting.attenuate_x2 = 10; #else setting.attenuate_x2 = 60; @@ -581,14 +597,24 @@ void toggle_debug_avoid(void) { debug_avoid = !debug_avoid; if (debug_avoid) { - setting.show_stored = true; TRACE_ENABLE(TRACE_STORED_FLAG|TRACE_TEMP_FLAG); } else { - setting.show_stored = false; TRACE_DISABLE(TRACE_STORED_FLAG|TRACE_TEMP_FLAG); } dirty = true; } +#ifdef __ULTRA__ +void toggle_debug_spur(void) +{ + debug_spur = !debug_spur; + if (debug_spur) { + TRACE_ENABLE(TRACE_STORED_FLAG|TRACE_TEMP_FLAG); + } else { + TRACE_DISABLE(TRACE_STORED_FLAG|TRACE_TEMP_FLAG); + } + dirty = true; +} +#endif #ifdef TINYSA4 void toggle_high_out_adf4350(void) @@ -624,10 +650,12 @@ void toggle_mirror_masking(void) setting.mirror_masking = !setting.mirror_masking; #ifdef __HARMONIC__ #ifdef TINYSA3 +#ifndef __ULTRA if (setting.harmonic) { setting.spur_removal = setting.mirror_masking; } #endif +#endif #endif dirty = true; } @@ -655,7 +683,7 @@ void toggle_below_IF(void) dirty = true; } -#ifdef TINYSA4 +#ifdef __ULTRA__ void toggle_ultra(void) { if (S_IS_AUTO(setting.ultra )) @@ -1689,19 +1717,14 @@ pureRSSI_t get_frequency_correction(freq_t f) // Frequency dependent RSSI c pureRSSI_t cv = 0; if (setting.mode == M_GENHIGH) return(0.0); -#ifdef TINYSA4 +#ifdef __ULTRA__ if (setting.mode == M_LOW && ultra && f > ultra_threshold) { -#if 0 - freq_t local_IF = config.frequency_IF1 + STATIC_DEFAULT_SPUR_OFFSET/2; - if ( f > local_IF && f < local_IF + MIN_BELOW_LO) { // Jump at local_IF + MIN_BELOW_LO = 978 - 550 = 1527MHz - cv += ( float_TO_PURE_RSSI(1.5) * (f - local_IF) ) / MIN_BELOW_LO; // +2.5dB correction. - } - if ( f > MAX_LO_FREQ - local_IF && f < ULTRA_MAX_FREQ) { // = 4350 - 978 = 3372MHz up to 5350MHz - cv += float_TO_PURE_RSSI(1); // +1dB correction. - } -#endif if ( f > ULTRA_MAX_FREQ) { +#ifdef TINYSA4 cv += float_TO_PURE_RSSI(9); // +9dB correction. +#else + cv += float_TO_PURE_RSSI(13.5); // +dB correction. TODO !!!!!!!!!!!!!!!!! +#endif } } #endif @@ -1796,7 +1819,9 @@ void setup_sa(void) #ifdef TINYSA4 ADF4351_Setup(); enable_extra_lna(false); +#ifdef __ULTRA__ enable_ultra(false); +#endif enable_rx_output(false); enable_high(false); @@ -2014,6 +2039,8 @@ case M_LOW: // Mixed into 0 #ifdef TINYSA4 enable_high(false); enable_extra_lna(setting.extra_lna); +#endif +#ifdef __ULTRA__ enable_ultra(false); #endif break; @@ -2048,6 +2075,8 @@ mute: } enable_high(true); enable_extra_lna(false); +#endif +#ifdef __ULTRA__ enable_ultra(false); #endif break; @@ -2089,6 +2118,8 @@ case M_GENLOW: // Mixed output from 0 SI4463_set_output_level(setting.rx_drive); enable_high(false); enable_extra_lna(false); +#endif +#ifdef __ULTRA__ enable_ultra(false); #endif break; @@ -2098,6 +2129,8 @@ case M_GENHIGH: // Direct output from 1 #ifdef TINYSA4 enable_high(true); // Must be first to protect SAW filters enable_extra_lna(false); +#endif +#ifdef __ULTRA__ enable_ultra(false); #endif #ifdef __SI4432__ @@ -2658,9 +2691,11 @@ static int is_below = false; #ifdef TINYSA4 static int LO_shifted; static int LO_mirrored; -static int LO_harmonic; static int LO_shifting; #endif +#ifdef __ULTRA__ +static int LO_harmonic; +#endif static void calculate_static_correction(void) // Calculate the static part of the RSSI correction { @@ -2721,8 +2756,10 @@ void clock_at_48MHz(void) } } -#ifdef TINYSA4 +#ifdef __ULTRA__ int old_drive = -1; +#endif +#ifdef TINYSA4 int test_output = false; int test_output_switch = false; int test_output_drive = 0; @@ -2850,6 +2887,18 @@ pureRSSI_t perform(bool break_on_operation, int i, freq_t f, int tracking) / } } #endif +#ifdef TINYSA3 +#ifdef __ULTRA__ + int target_drive = setting.lo_drive; + if (f > ULTRA_MAX_FREQ) + target_drive += 1; + if (old_drive != target_drive) { + SI4432_Drive(target_drive); + old_drive = target_drive; + } +#endif +#endif + // ------------------------------------- Set the output level ---------------------------------- if (( setting.frequency_step != 0 || setting.level_sweep != 0.0 || i == 0)) { // Initialize or adapt output levels @@ -3104,7 +3153,7 @@ modulation_again: my_microsecond_delay(modulation_delay); } } -#ifdef TINYSA4 +#ifdef __ULTRA__ // -------------- set ultra --------------------------------- if (setting.mode == M_LOW && ultra && f > ultra_threshold) { enable_ultra(true); @@ -3151,7 +3200,10 @@ modulation_again: int offs = offs_div10 * actual_rbw_x10; if (setting.step_delay_mode == SD_PRECISE) offs>>=1; // steps of a quarter rbw - lf += offs; + if (offs < 0 && ((freq_t)-offs) > lf) + lf = 0; + else + lf += offs; #endif } // -------------- Calculate the IF ----------------------------- @@ -3168,8 +3220,10 @@ again: // Spur redu #ifdef TINYSA4 LO_shifted = false; LO_mirrored = false; - LO_harmonic = false; LO_shifting = false; +#endif +#ifdef __ULTRA__ + LO_harmonic = false; #endif if (MODE_LOW(setting.mode)){ // All low mode if (!setting.auto_IF) @@ -3200,7 +3254,7 @@ again: // Spur redu lf = (setting.refer == -1 ? 0 : reffer_freq[setting.refer]); #endif } else { -#ifdef __SI4468__ +#ifdef __ULTRA__ if (S_IS_AUTO(setting.spur_removal)) { if (ultra && lf >= ultra_threshold) { setting.spur_removal= S_AUTO_ON; @@ -3209,9 +3263,9 @@ again: // Spur redu } } #endif -#ifdef TINYSA4 +#ifdef __ULTRA__ if (S_IS_AUTO(setting.below_IF)) { - if ((uint64_t)lf + (uint64_t)local_IF> MAX_LO_FREQ && lf < ULTRA_MAX_FREQ) + if ((freq_t)lf + (freq_t)local_IF> MAX_LO_FREQ && lf < ULTRA_MAX_FREQ) setting.below_IF = S_AUTO_ON; // Only way to reach this range. else setting.below_IF = S_AUTO_OFF; // default is above IF @@ -3222,7 +3276,11 @@ again: // Spur redu #ifdef TINYSA4 ( lf > ULTRA_MAX_FREQ || lf < local_IF/2 || ( lf + (uint64_t)local_IF< MAX_LO_FREQ && lf > MIN_BELOW_LO + local_IF) ) #else - (lf < local_IF / 2 || lf > local_IF) +#ifdef __ULTRA__ + ( (lf > ULTRA_MAX_FREQ && (lf + local_IF) / setting.harmonic < MAX_LO_FREQ) || lf < local_IF - MIN_LO_FREQ || ( lf + (uint32_t)local_IF< MAX_LO_FREQ && lf > MIN_BELOW_LO + local_IF) ) +#else + (lf < local_IF / 2 || lf > local_IF) +#endif #endif ) { // below/above IF @@ -3337,15 +3395,17 @@ again: // Spur redu int inverted_f = false; #endif if (setting.mode == M_LOW && !setting.tracking && S_STATE(setting.below_IF)) { // if in low input mode and below IF -#ifdef TINYSA4 +#ifdef __ULTRA__ if (lf < local_IF) #endif target_f = local_IF-lf; // set LO SI4432 to below IF frequency -#ifdef TINYSA4 +#ifdef __ULTRA__ else { target_f = lf - local_IF; // set LO SI4432 to below IF frequency +#ifdef TINYSA4 inverted_f = true; LO_mirrored = true; +#endif } #endif } @@ -3365,6 +3425,17 @@ again: // Spur redu target_f /= setting.harmonic; } #endif +#endif +#ifdef __ULTRA__ + if (setting.harmonic && lf > ULTRA_MAX_FREQ) { + target_f /= setting.harmonic; +#ifdef TINYSA3 + if (target_f > MAX_LO_FREQ) { + target_f = (lf - local_IF) / setting.harmonic; + } +#endif + LO_harmonic = true; + } #endif set_freq (SI4432_LO, target_f); // otherwise to above IF #endif @@ -3744,14 +3815,33 @@ again: // Spur redu // volatile int i = 0; // i = i + 1; // } +#ifdef __ULTRA__ + float debug_rssi = PURE_TO_float(pureRSSI+ correct_RSSI + correct_RSSI_freq); +#endif #ifdef __SPUR__ static pureRSSI_t spur_RSSI = -1; // Initialization only to avoid warning. if ((setting.mode == M_LOW || setting.mode == M_HIGH) && S_STATE(setting.spur_removal) && !debug_avoid) { if (!spur_second_pass) { // If first spur pass +#ifdef __ULTRA__ + if (debug_spur) { + if (t == 0) + temp_t[i] = debug_rssi; + else if (temp_t[i] < debug_rssi) + temp_t[i] = debug_rssi; + } +#endif spur_RSSI = pureRSSI; // remember measure RSSI spur_second_pass = true; goto again; // Skip all other processing } else { // If second spur pass +#ifdef __ULTRA__ + if (debug_spur) { + if (t == 0) + stored_t[i] = debug_rssi; + else if (stored_t[i] < debug_rssi) + stored_t[i] = debug_rssi; + } +#endif pureRSSI = ( pureRSSI < spur_RSSI ? pureRSSI : spur_RSSI); // Take minimum of two if (S_IS_AUTO(setting.below_IF)) setting.below_IF = S_AUTO_OFF; // make sure it is off for next pass @@ -4149,9 +4239,14 @@ static volatile int dummy; RSSI = temp_t[i]; #else + if (MODE_INPUT(setting.mode)) { for (int t=0; t0) + continue; +#endif float RSSI_calc = RSSI; float *trace_data = measured[t]; #endif // __DOUBLE_LOOP__ @@ -4302,6 +4397,7 @@ static volatile int dummy; } } // end of peak finding } + } } @@ -4328,7 +4424,7 @@ static volatile int dummy; ili9341_set_background(LCD_BG_COLOR); ili9341_fill(OFFSETX, CHART_BOTTOM+1, WIDTH, 1); #ifdef __SWEEP_RESTART__ - refresh_sweep_menu(-1); + refresh_sweep_menu(sweep_points-1); #endif } // ---------------------- process measured actual sweep time ----------------- @@ -4382,7 +4478,7 @@ static volatile int dummy; redraw_request |= REDRAW_CAL_STATUS; } - if (MODE_OUTPUT(setting.mode) ) // Sweep time is calculated, we can sweep again in output mode + if (MODE_OUTPUT(setting.mode) && (sweep_mode & SWEEP_ENABLE) ) // Sweep time is calculated, we can sweep again in output mode goto again; // Keep repeating sweep loop till user aborts by input #define __MIRROR_MASKING__ @@ -4826,6 +4922,7 @@ void markers_reset() markers[i].enabled = M_DISABLED; markers[i].mtype = M_DELTA; markers[i].ref = 0; + markers[i].trace = 0; } markers[0].mtype = M_TRACKING; markers[0].enabled = M_ENABLED; @@ -5314,11 +5411,13 @@ void test_prepare(int i) setting.atten_step = false; #ifdef TINYSA4 setting.frequency_IF = config.frequency_IF1 + STATIC_DEFAULT_SPUR_OFFSET/2; // Default frequency - ultra = true; - ultra_threshold = 2000000000; setting.extra_lna = false; #else setting.frequency_IF = DEFAULT_IF; // Default frequency +#endif +#ifdef __ULTRA__ + ultra = true; + ultra_threshold = 2000000000; #endif setting.auto_IF = true; setting.auto_attenuation = false; @@ -5602,7 +5701,7 @@ quit: set_attenuation(((float)j)/2.0); if (setting.test_argument) set_sweep_frequency(ST_CENTER, ((freq_t)setting.test_argument)); -#ifdef TINYSA4 +#ifdef __ULTRA__ ultra_threshold = config.ultra_threshold; #endif test_acquire(TEST_LEVEL); // Acquire test diff --git a/si4432.c b/si4432.c index 258c294..9af869b 100644 --- a/si4432.c +++ b/si4432.c @@ -553,6 +553,21 @@ int SI4432_is_fast_mode(void) } #endif +#ifdef __ULTRA__ +void enable_ultra(int s) +{ +static int old_ultra = -1; + if (s != old_ultra) { +#ifdef TINYSA4 + if (s) + palClearLine(LINE_ULTRA); + else + palSetLine(LINE_ULTRA); +#endif + old_ultra = s; + } +} +#endif //--------------------------- Trigger ------------------- // ************** trigger mode if need diff --git a/si4468.c b/si4468.c index 43af3c7..974214d 100644 --- a/si4468.c +++ b/si4468.c @@ -74,7 +74,9 @@ //#define ADF_SPI_SPEED SPI_BR_DIV32 #define ADF_SPI_SPEED SPI_BR_DIV2 -#define PE_SPI_SPEED SPI_BR_DIV16 +#define PE4302_HW_SHIFT true +#define PE_SPI_SPEED SPI_BR_DIV2 +#define PE_SW_DELAY 1 static uint32_t old_spi_settings; #else @@ -155,9 +157,9 @@ static void software_shiftOut(uint8_t val) do { if (val & 0x80) SPI1_SDI_HIGH; - my_microsecond_delay(100); + my_microsecond_delay(PE_SW_DELAY); SPI1_CLK_HIGH; - my_microsecond_delay(100); + my_microsecond_delay(PE_SW_DELAY); SPI1_RESET; val<<=1; }while((++i) & 0x07); @@ -221,7 +223,7 @@ bool PE4302_Write_Byte(unsigned char DATA ) if (old_attenuation == DATA) return false; old_attenuation = DATA; -#if 0 +#if PE4302_HW_SHIFT set_SPI_mode(SPI_MODE_SI); if (SI4432_SPI_SPEED != PE_SPI_SPEED) SPI_BR_SET(SI4432_SPI, PE_SPI_SPEED); @@ -232,10 +234,10 @@ bool PE4302_Write_Byte(unsigned char DATA ) software_shiftOut(DATA); #endif CS_PE_HIGH; - my_microsecond_delay(100); + my_microsecond_delay(PE_SW_DELAY); CS_PE_LOW; - my_microsecond_delay(100); -#if 0 + my_microsecond_delay(PE_SW_DELAY); +#if PE4302_HW_SHIFT if (SI4432_SPI_SPEED != PE_SPI_SPEED) SPI_BR_SET(SI4432_SPI, SI4432_SPI_SPEED); #endif @@ -1825,17 +1827,21 @@ void enable_extra_lna(int s) } } +#ifdef __ULTRA__ void enable_ultra(int s) { static int old_ultra = -1; if (s != old_ultra) { +#ifdef TINYSA4 if (s) palClearLine(LINE_ULTRA); else palSetLine(LINE_ULTRA); +#endif old_ultra = s; } } +#endif void enable_rx_output(int s) { diff --git a/ui.c b/ui.c index 3100c6f..7e2ad6c 100644 --- a/ui.c +++ b/ui.c @@ -1534,9 +1534,9 @@ refresh_sweep_menu(int i) if (new_sweep_time - old_sweep_time > ONE_SECOND_TIME/200 && i >= 0) { old_sweep_time = new_sweep_time; if (menu_stack[menu_current_level] == menu_lowoutputmode) - draw_menu_buttons(menu_stack[menu_current_level], 5); + draw_menu_buttons(menu_stack[menu_current_level], 1 << 5); if (menu_stack[menu_current_level] == menu_highoutputmode) - draw_menu_buttons(menu_stack[menu_current_level], 5); + draw_menu_buttons(menu_stack[menu_current_level], 1 << 5); } } #endif diff --git a/ui_sa.c b/ui_sa.c index 62739e1..c8046d7 100644 --- a/ui_sa.c +++ b/ui_sa.c @@ -421,8 +421,10 @@ enum { KM_R,KM_MOD,KM_CP, #endif KM_ATTACK, -#ifdef TINYSA4 +#ifdef __ULTRA__ KM_LPF, +#endif +#ifdef TINYSA4 KM_EXP_AVER, #endif KM_LEVEL, @@ -483,8 +485,10 @@ static const struct { [KM_CP] = {keypads_positive , "CP"}, // KM_CP #endif [KM_ATTACK] = {keypads_positive , "ATTACK"}, // KM_ATTACK -#ifdef TINYSA4 +#ifdef __ULTRA__ [KM_LPF] = {keypads_freq , "ULTRA\nSTART"}, // KM_LPF +#endif +#ifdef TINYSA4 [KM_EXP_AVER] = {keypads_positive , "EXPONENTIAL\nAVERAGING"}, //KM_EXP_AVER #endif [KM_LEVEL] = {keypads_plusmin , "LEVEL"}, // KM_LEVEL @@ -569,9 +573,12 @@ static UI_FUNCTION_ADV_CALLBACK(menu_restart_acb){ (void)item; (void)data; if(b){ - if (current_index >= 0 && setting.sweep) { - float current_level = setting.level + ((float)current_index)* setting.level_sweep / (float)sweep_points; - plot_printf(b->text, sizeof b->text, "STOP %5.3QHz %+.1fdBm", getFrequency(current_index), current_level); + if (setting.sweep) { + if (current_index >= 0) { + float current_level = setting.level + ((float)current_index)* setting.level_sweep / (float)sweep_points; + plot_printf(b->text, sizeof b->text, "STOP %5.3QHz %+.1fdBm", getFrequency(current_index), current_level); + } else + plot_printf(b->text, sizeof b->text, "STOP SWEEP"); } else plot_printf(b->text, sizeof b->text, "START SWEEP"); @@ -1105,54 +1112,44 @@ static UI_FUNCTION_ADV_CALLBACK(menu_harmonic_spur_acb) #endif #endif -#ifdef TINYSA4 -static UI_FUNCTION_ADV_CALLBACK(menu_extra_lna_acb) +#ifdef __ULTRA__ +static UI_FUNCTION_ADV_CALLBACK(menu_debug_spur_acb) { (void)data; (void)item; if (b){ - b->icon = setting.extra_lna == 0 ? BUTTON_ICON_NOCHECK : BUTTON_ICON_CHECK; + b->icon = debug_spur == 0 ? BUTTON_ICON_NOCHECK : BUTTON_ICON_CHECK; return; } - toggle_extra_lna(); - // menu_move_back(false); + toggle_debug_spur(); + // menu_move_back(); ui_mode_normal(); } +#endif -static UI_FUNCTION_ADV_CALLBACK(menu_adf_out_acb) +#ifdef TINYSA4 +static UI_FUNCTION_ADV_CALLBACK(menu_extra_lna_acb) { (void)data; (void)item; if (b){ - b->icon = config.high_out_adf4350 == 0 ? BUTTON_ICON_NOCHECK : BUTTON_ICON_CHECK; + b->icon = setting.extra_lna == 0 ? BUTTON_ICON_NOCHECK : BUTTON_ICON_CHECK; return; } - toggle_high_out_adf4350(); + toggle_extra_lna(); // menu_move_back(false); ui_mode_normal(); } -static UI_FUNCTION_ADV_CALLBACK(menu_ultra_acb) +static UI_FUNCTION_ADV_CALLBACK(menu_adf_out_acb) { (void)data; (void)item; if (b){ - b->icon = config.ultra == 0 ? BUTTON_ICON_NOCHECK : BUTTON_ICON_CHECK; + b->icon = config.high_out_adf4350 == 0 ? BUTTON_ICON_NOCHECK : BUTTON_ICON_CHECK; return; } - if (!config.ultra) { - kp_help_text = "Ultra unlock code"; - ui_mode_keypad(KM_CENTER); - if (uistat.value != 4321) - return; - } - config.ultra = !config.ultra; - config_save(); - reset_settings(M_LOW); - if (config.ultra){ - set_sweep_frequency(ST_START, 0); - set_sweep_frequency(ST_STOP, 3000000000ULL); - } + toggle_high_out_adf4350(); // menu_move_back(false); ui_mode_normal(); } @@ -1215,6 +1212,33 @@ static UI_FUNCTION_ADV_CALLBACK(menu_linear_averaging_acb) #endif +#ifdef __ULTRA__ +static UI_FUNCTION_ADV_CALLBACK(menu_ultra_acb) +{ + (void)data; + (void)item; + if (b){ + b->icon = config.ultra == 0 ? BUTTON_ICON_NOCHECK : BUTTON_ICON_CHECK; + return; + } + if (!config.ultra) { + kp_help_text = "Ultra unlock code"; + ui_mode_keypad(KM_CENTER); + if (uistat.value != 4321) + return; + } + config.ultra = !config.ultra; + config_save(); + reset_settings(M_LOW); + if (config.ultra){ + set_sweep_frequency(ST_START, 0); + set_sweep_frequency(ST_STOP, 3000000000ULL); + } + // menu_move_back(false); + ui_mode_normal(); +} +#endif + static UI_FUNCTION_CALLBACK(menu_clearconfig_cb) { (void)data; @@ -2659,6 +2683,11 @@ static const menuitem_t menu_settings3[] = #endif { MT_SUBMENU, 0, S_RARROW" MORE", menu_settings4}, #else +#ifdef __ULTRA__ + { MT_ADV_CALLBACK, 0, "ENABLE\nULTRA", menu_ultra_acb}, + { MT_KEYPAD, KM_LPF, "ULTRA\nSTART", "Enter ULTRA mode start freq"}, + { MT_ADV_CALLBACK, 0, "DEBUG\nSPUR", menu_debug_spur_acb}, +#endif { MT_KEYPAD, KM_10MHZ, "CORRECT\nFREQUENCY", "Enter actual l0MHz frequency"}, { MT_KEYPAD, KM_GRIDLINES, "MINIMUM\nGRIDLINES", "Enter minimum horizontal grid divisions"}, { MT_CALLBACK, 0 , "CLEAR\nCONFIG", menu_clearconfig_cb}, @@ -3172,7 +3201,7 @@ static void fetch_numeric_target(uint8_t mode) plot_printf(uistat.text, sizeof uistat.text, "%5d", ((int32_t)uistat.value)); break; #endif -#ifdef TINYSA4 +#ifdef __ULTRA__ case KM_LPF: uistat.freq_value = config.ultra_threshold; plot_printf(uistat.text, sizeof uistat.text, "%3.6fMHz", uistat.freq_value / 1000000.0); @@ -3331,12 +3360,14 @@ set_numeric_value(void) set_attack(uistat.value); break; #endif -#ifdef TINYSA4 +#ifdef __ULTRA__ case KM_LPF: config.ultra_threshold = uistat.value; config_save(); ultra_threshold = config.ultra_threshold; break; +#endif +#ifdef TINYSA4 case KM_EXP_AVER: setting.exp_aver = uistat.value; dirty = true;