From 6847d5df4d6d5810cedbebc9b12d81edd9d1fdfa Mon Sep 17 00:00:00 2001 From: erikkaashoek Date: Sun, 18 Apr 2021 16:21:19 +0200 Subject: [PATCH] VBW menu added --- ili9341.c | 9 ++- nanovna.h | 8 ++- sa_core.c | 172 +++++++++++++++++++++++++++++------------------------- si4468.c | 4 +- spi.h | 2 +- ui_sa.c | 35 +++++++++++ 6 files changed, 144 insertions(+), 86 deletions(-) diff --git a/ili9341.c b/ili9341.c index 2c4b7d7..7c3ba51 100644 --- a/ili9341.c +++ b/ili9341.c @@ -563,21 +563,26 @@ void ili9341_bulk(int x, int y, int w, int h) // Fill region by some color void ili9341_fill(int x, int y, int w, int h) { +#if 1 ili9341_setWindow(x, y ,w, h); send_command(ILI9341_MEMORY_WRITE, 0, NULL); - dmaStreamSetMemory0(dmatx, &background_color); dmaStreamSetMode(dmatx, txdmamode | STM32_DMA_CR_PSIZE_HWORD | STM32_DMA_CR_MSIZE_HWORD); +#endif #ifdef __REMOTE_DESKTOP__ if (auto_capture) { send_region("fill", x, y, w, h); send_buffer((uint8_t *)&background_color, sizeof(pixel_t)); } #endif +#if 1 dmaStreamFlush(w * h); +#endif +// while (SPI_IN_TX_RX(LCD_SPI)); } static void ili9341_DMA_bulk(uint16_t x, uint16_t y, uint16_t w, uint16_t h, pixel_t *buffer){ +#if 1 ili9341_setWindow(x, y ,w, h); send_command(ILI9341_MEMORY_WRITE, 0, NULL); @@ -585,12 +590,14 @@ static void ili9341_DMA_bulk(uint16_t x, uint16_t y, uint16_t w, uint16_t h, pix dmaStreamSetMode(dmatx, txdmamode | STM32_DMA_CR_PSIZE_HWORD | STM32_DMA_CR_MSIZE_HWORD | STM32_DMA_CR_MINC); dmaStreamSetTransactionSize(dmatx, w * h); dmaStreamEnable(dmatx); +#endif #ifdef __REMOTE_DESKTOP__ if (auto_capture) { send_region("bulk", x, y, w, h); send_buffer((uint8_t *)buffer, w *h * sizeof(pixel_t)); } #endif +// while (SPI_IN_TX_RX(LCD_SPI)); } // Copy spi_buffer to region diff --git a/nanovna.h b/nanovna.h index 86569c9..d792ce1 100644 --- a/nanovna.h +++ b/nanovna.h @@ -18,7 +18,7 @@ */ #include "ch.h" -//#ifdef TINYSA_F303 +#ifdef TINYSA_F303 #include "adc_F303.h" #ifdef TINYSA_F072 #error "Remove comment for #ifdef TINYSA_F303" @@ -27,7 +27,7 @@ #define TINYSA4 #endif #define TINYSA4_PROTO -//#endif +#endif #ifdef TINYSA_F072 #ifdef TINYSA_F303 @@ -73,6 +73,7 @@ #define __LIMITS__ #ifdef TINYSA4 #define __HARMONIC__ +#define __VBW__ #else #endif @@ -327,6 +328,9 @@ int is_paused(void); void set_actual_power(float); void SetGenerate(int); void set_RBW(uint32_t rbw_x10); +#ifdef __VBW__ +void set_VBW(uint32_t vbw_x10); +#endif void set_lo_drive(int d); void set_rx_drive(int d); void set_IF(int f); diff --git a/sa_core.c b/sa_core.c index 9030ba2..6df6c94 100644 --- a/sa_core.c +++ b/sa_core.c @@ -43,6 +43,7 @@ setting_t setting; freq_t frequencies[POINTS_COUNT]; uint16_t actual_rbw_x10 = 0; +freq_t frequency_step_x10 = 0; uint16_t vbwSteps = 1; freq_t minFreq = 0; freq_t maxFreq = 520000000; @@ -216,7 +217,7 @@ void reset_settings(int m) setting.step_delay = 0; setting.offset_delay = 0; setting.step_delay_mode = SD_NORMAL; - setting.vbw_x10 = 0; + setting.vbw_x10 = 0; // Auto mode setting.auto_reflevel = true; // Must be after SetReflevel setting.decay=20; setting.attack=1; @@ -988,6 +989,14 @@ void set_RBW(uint32_t rbw_x10) dirty = true; } +#ifdef __VBW__ +void set_VBW(uint32_t vbw_x10) +{ + setting.vbw_x10 = vbw_x10; + dirty = true; +} +#endif + #ifdef __SPUR__ void set_spur(int v) { @@ -1994,30 +2003,28 @@ void update_rbw(void) // calculate the actual_rbw and the vbwSteps (# return; #endif } + frequency_step_x10 = 3000; // default value for zero span if (setting.frequency_step > 0 && MODE_INPUT(setting.mode)) { - setting.vbw_x10 = (setting.frequency_step)/100; - } else { - setting.vbw_x10 = 3000; // trick to get right default rbw in zero span mode + frequency_step_x10 = (setting.frequency_step)/100; } - freq_t temp_actual_rbw_x10 = setting.rbw_x10; // requested rbw , 32 bit !!!!!! + + freq_t temp_actual_rbw_x10 = setting.rbw_x10; if (temp_actual_rbw_x10 == 0) { // if auto rbw + if (setting.step_delay_mode==SD_FAST) { // if in fast scanning #ifdef __SI4432__ if (setting.fast_speedup > 2) - temp_actual_rbw_x10 = 6*setting.vbw_x10; // rbw is six times the frequency step to ensure no gaps in coverage as there are some weird jumps + temp_actual_rbw_x10 = 6*frequency_step_x10; // rbw is six times the frequency step to ensure no gaps in coverage as there are some weird jumps else - temp_actual_rbw_x10 = 4*setting.vbw_x10; // rbw is four times the frequency step to ensure no gaps in coverage as there are some weird jumps + temp_actual_rbw_x10 = 4*frequency_step_x10; // rbw is four times the frequency step to ensure no gaps in coverage as there are some weird jumps #endif #ifdef __SI4463__ - temp_actual_rbw_x10 = setting.vbw_x10; + temp_actual_rbw_x10 = frequency_step_x10; #endif - } else -#ifdef TINYSA4 - temp_actual_rbw_x10 = 2*setting.vbw_x10; // rbw is NOT twice the frequency step to ensure no gaps in coverage -#else - temp_actual_rbw_x10 = 2*setting.vbw_x10; // rbw is twice the frequency step to ensure no gaps in coverage -#endif - } + } else { + temp_actual_rbw_x10 = 2*frequency_step_x10; // rbw is twice the frequency step to ensure no gaps in coverage + } + } #ifdef __SI4432__ if (temp_actual_rbw_x10 < 26) temp_actual_rbw_x10 = 26; @@ -2044,18 +2051,18 @@ void update_rbw(void) // calculate the actual_rbw and the vbwSteps (# actual_rbw_x10 = set_rbw(actual_rbw_x10); // see what rbw the SI4432 can realize if (setting.frequency_step > 0 && MODE_INPUT(setting.mode)) { // When doing frequency scanning in input mode #ifdef TINYSA4 - if (setting.vbw_x10 > actual_rbw_x10) - vbwSteps = 1+(setting.vbw_x10 / actual_rbw_x10); //((int)(2 * (setting.vbw_x10 + (actual_rbw_x10/8)) / actual_rbw_x10)); // calculate # steps in between each frequency step due to rbw being less than frequency step + if (frequency_step_x10 > actual_rbw_x10) + vbwSteps = 1+(frequency_step_x10 / actual_rbw_x10); //((int)(2 * (frequency_step_x10 + (actual_rbw_x10/8)) / actual_rbw_x10)); // calculate # steps in between each frequency step due to rbw being less than frequency step vbwSteps += vbwSteps; #else - vbwSteps = ((int)(2 * (setting.vbw_x10 + (actual_rbw_x10/2)) / actual_rbw_x10)); // calculate # steps in between each frequency step due to rbw being less than frequency step + vbwSteps = ((int)(2 * (frequency_step_x10 + (actual_rbw_x10/2)) / actual_rbw_x10)); // calculate # steps in between each frequency step due to rbw being less than frequency step #endif if (setting.step_delay_mode==SD_PRECISE) // if in Precise scanning vbwSteps *= 2; // use twice as many steps if (vbwSteps < 1) // at least one step, should never happen vbwSteps = 1; } else { // in all other modes - setting.vbw_x10 = actual_rbw_x10; + frequency_step_x10 = actual_rbw_x10; } #ifdef TINYSA4 done: @@ -2837,7 +2844,7 @@ modulation_again: int offs_div10 = (t - (local_vbw_steps >> 1)) * 100; // steps of x10 * settings. if ((local_vbw_steps & 1) == 0) // Uneven steps, center offs_div10+= 50; // Even, shift half step - int offs = (offs_div10 * (int32_t)setting.vbw_x10 )/ local_vbw_steps; + int offs = (offs_div10 * (int32_t)frequency_step_x10 )/ local_vbw_steps; // if (setting.step_delay_mode == SD_PRECISE) // offs>>=1; // steps of a quarter rbw // if (lf > -offs) // No negative frequencies @@ -3531,16 +3538,16 @@ static bool sweep(bool break_on_operation) #endif #endif -again: // Waiting for a trigger jumps back to here + again: // Waiting for a trigger jumps back to here setting.measure_sweep_time_us = 0; // start measure sweep time -// start_of_sweep_timestamp = chVTGetSystemTimeX(); // Will be set in perform + // start_of_sweep_timestamp = chVTGetSystemTimeX(); // Will be set in perform -sweep_again: // stay in sweep loop when output mode and modulation on. + sweep_again: // stay in sweep loop when output mode and modulation on. // ------------------------- start sweep loop ----------------------------------- for (int i = 0; i < sweep_points; i++) { debug_avoid_second = false; - debug_avoid_label: + debug_avoid_label: debug_avoid_second = debug_avoid_second; // --------------------- measure ------------------------- pureRSSI_t rssi = perform(break_on_operation, i, frequencies[i], setting.tracking); // Measure RSSI for one of the frequencies @@ -3604,30 +3611,56 @@ sweep_again: // stay in sweep loop when output mo } } } - - //if (MODE_INPUT(setting.mode)) - { + if ( #ifdef TINYSA4 - if (show_bar && (i & 0x07) == 0 && (setting.actual_sweep_time_us > ONE_SECOND_TIME || (chVTGetSystemTimeX() - start_of_sweep_timestamp) > ONE_SECOND_TIME / 100)) { // if required + show_bar && (i & 0x07) == 0 && (setting.actual_sweep_time_us > ONE_SECOND_TIME || (chVTGetSystemTimeX() - start_of_sweep_timestamp) > ONE_SECOND_TIME / 100) // if required #else - if ( show_bar && (i & 0x07) == 0 && setting.actual_sweep_time_us > ONE_SECOND_TIME) { // if required -#endif - int pos = i * (WIDTH+1) / sweep_points; - ili9341_set_background(LCD_SWEEP_LINE_COLOR); - ili9341_fill(OFFSETX, CHART_BOTTOM+1, pos, 1); // update sweep progress bar - ili9341_set_background(LCD_BG_COLOR); - ili9341_fill(OFFSETX+pos, CHART_BOTTOM+1, WIDTH-pos, 1); + show_bar && (i & 0x07) == 0 && setting.actual_sweep_time_us > ONE_SECOND_TIME // if required +#endif + ) { + int pos = i * (WIDTH+1) / sweep_points; + ili9341_set_background(LCD_SWEEP_LINE_COLOR); + ili9341_fill(OFFSETX, CHART_BOTTOM+1, pos, 1); // update sweep progress bar + ili9341_set_background(LCD_BG_COLOR); + ili9341_fill(OFFSETX+pos, CHART_BOTTOM+1, WIDTH-pos, 1); + } + // ----------------------- debug avoid -------------------------------- + if (debug_avoid) { + if (!debug_avoid_second) { + temp_t[i] = RSSI; + debug_avoid_second = true; + goto debug_avoid_label; + } else { + debug_avoid_second = false; } - // ----------------------- debug avoid -------------------------------- - if (debug_avoid) { - if (!debug_avoid_second) { - temp_t[i] = RSSI; - debug_avoid_second = true; - goto debug_avoid_label; - } else { - debug_avoid_second = false; - } + } + temp_t[i] = RSSI; + } + + // -------------------------------- Scan finished, do all postprocessing -------------------- + if (MODE_INPUT(setting.mode)) { + +#ifdef __VBW__ + // ------------------------ do VBW processing ------------------------------ + + int vbw_count_div2 = actual_rbw_x10 * 100 / setting.frequency_step / (setting.vbw_x10 == 0 ? 10 : setting.vbw_x10); + while(vbw_count_div2-- > 0){ + pureRSSI_t prev = temp_t[0]; + int j; + // first point smooth + temp_t[0] = (prev + prev + temp_t[1])/3.0f; + for (j=1;j old_RSSI && setting.attack > 1) - old_RSSI += (RSSI - old_RSSI)/setting.attack; - else if (RSSI < old_RSSI && setting.decay > 1) - old_RSSI += (RSSI - old_RSSI)/setting.decay; - else - old_RSSI = RSSI; - actual_t[i] = old_RSSI; - } - break; + { static float old_RSSI = -150.0; + if (i == 0) old_RSSI = actual_t[sweep_points-1]; + if (RSSI > old_RSSI && setting.attack > 1) + old_RSSI += (RSSI - old_RSSI)/setting.attack; + else if (RSSI < old_RSSI && setting.decay > 1) + old_RSSI += (RSSI - old_RSSI)/setting.decay; + else + old_RSSI = RSSI; + actual_t[i] = old_RSSI; + } + break; #endif } } @@ -3756,8 +3787,8 @@ sweep_again: // stay in sweep loop when output mo downslope = true; } } // end of peak finding - } // end of input specific processing - } // ---------------------- end of sweep loop ----------------------------- + } + } // ---------------------- end of postprocessing ----------------------------- if (MODE_OUTPUT(setting.mode) && setting.modulation != MO_NONE) { // if in output mode with modulation if (!in_selftest) @@ -3826,25 +3857,6 @@ sweep_again: // stay in sweep loop when output mo // ---------------------- sweep finished, do all postprocessing --------------------- -#ifdef TINYSA4 - // ------------------------ do VBW processing ------------------------------ - - int vbw_count_div2 = actual_rbw_x10 * 50 / setting.frequency_step; - while(vbw_count_div2-- > 0){ - pureRSSI_t prev = actual_t[0]; - int j; - // first point smooth - actual_t[0] = (prev + prev + actual_t[1])/3.0f; - for (j=1;jparam_1.text = vbwsel_text[data]; + b->icon = setting.vbw_x10 == vbwsel_x10[data] ? BUTTON_ICON_GROUP_CHECKED : BUTTON_ICON_GROUP; + return; + } + set_VBW(vbwsel_x10[data]); + menu_move_back(true); +} + +#endif + static UI_FUNCTION_ADV_CALLBACK(menu_unit_acb) { (void)item; @@ -1839,6 +1858,19 @@ static const menuitem_t menu_rbw[] = { { MT_NONE, 0, NULL, NULL } // sentinel }; +#ifdef __VBW__ +static const menuitem_t menu_vbw[] = { + { MT_ADV_CALLBACK, 0, " AUTO", menu_vbw_acb}, + { MT_ADV_CALLBACK, 1, "%s RBW", menu_vbw_acb}, + { MT_ADV_CALLBACK, 2, "%s RBW", menu_vbw_acb}, + { MT_ADV_CALLBACK, 3, "%s RBW", menu_vbw_acb}, + { MT_ADV_CALLBACK, 4, "%s RBW", menu_vbw_acb}, + { MT_ADV_CALLBACK, 5, "%s RBW", menu_vbw_acb}, + { MT_CANCEL, 0, S_LARROW" BACK", NULL }, + { MT_NONE, 0, NULL, NULL } // sentinel +}; +#endif + #if 0 static const menuitem_t menu_scale_per2[] = { { MT_ADV_CALLBACK, 6, "0.1 /", menu_scale_per_acb}, @@ -2283,6 +2315,9 @@ static const menuitem_t menu_display[] = { // { MT_ADV_CALLBACK,0, "STORE\nTRACE", menu_storage_acb}, // { MT_ADV_CALLBACK,1, "CLEAR\nSTORED", menu_storage_acb}, // { MT_ADV_CALLBACK,2, "SUBTRACT\nSTORED",menu_storage_acb}, +#ifdef __VBW__ + { MT_SUBMENU, 0, "VBW", menu_vbw}, +#endif #ifdef __LIMITS__ { MT_SUBMENU, 0, "LIMITS", menu_limit_select}, #endif