diff --git a/ili9341.c b/ili9341.c index 1a99aa4..2c4b7d7 100644 --- a/ili9341.c +++ b/ili9341.c @@ -667,9 +667,9 @@ void ili9341_read_memory(int x, int y, int w, int h, uint16_t *out) // Parse received data to RGB565 format while data receive by DMA uint8_t *rgbbuf = (uint8_t *)out; do { - uint16_t left = dmaStreamGetTransactionSize(dmarx); // Get DMA data left - if (left+3 > len) continue;// Next pixel RGB data not ready - while (left < len){ // Process completed by DMA data + uint16_t left = dmaStreamGetTransactionSize(dmarx) + 3; // Get DMA data left + if (left > len) continue; // Next pixel RGB data not ready + do{ // Process completed by DMA data uint8_t r, g, b; // read data is always 18bit in RGB888 format r = rgbbuf[0]; g = rgbbuf[1]; @@ -677,7 +677,7 @@ void ili9341_read_memory(int x, int y, int w, int h, uint16_t *out) *out++ = RGB565(r, g, b); rgbbuf+= 3; len -= 3; - } + } while (left < len); } while(len); dmaWaitCompletionRxTx(); // Wait DMA completion and stop it #endif diff --git a/main.c b/main.c index 73205f6..1312fbb 100644 --- a/main.c +++ b/main.c @@ -2937,6 +2937,7 @@ int main(void) * by the Reference Manual. */ dacStart(&DACD2, &dac1cfg1); + dacStart(&DACD1, &dac1cfg1); setup_sa(); set_sweep_points(POINTS_COUNT); diff --git a/nanovna.h b/nanovna.h index 1efa6ba..cf667f2 100644 --- a/nanovna.h +++ b/nanovna.h @@ -72,6 +72,7 @@ //#define __LIMITS__ #ifdef TINYSA4 #define __HARMONIC__ +#else #endif #ifdef TINYSA3 @@ -1310,7 +1311,7 @@ enum { }; -extern const int SI4432_RBW_count; +extern const uint8_t SI4432_RBW_count; extern void SI4432_Listen(int s); #ifdef TINYSA4 diff --git a/sa_cmd.c b/sa_cmd.c index 7e509be..59c775e 100644 --- a/sa_cmd.c +++ b/sa_cmd.c @@ -304,21 +304,29 @@ VNA_SHELL_FUNCTION(cmd_leveloffset) return; } int mode = get_str_index(argv[0], cmd_mode_list); + if (mode < 0) goto usage; float v; - if (argc == 2) + if (argc == 2){ v = my_atof(argv[1]); - else if (argc == 3 && get_str_index(argv[1], "output") == 0) + switch (mode){ + case 0: config.low_level_offset = v; break; + case 1: config.high_level_offset = v; break; + case 2: config.switch_offset = v; break; + default: goto usage; + } + dirty = true; + return; + } + if (argc == 3 && get_str_index(argv[1], "output") == 0){ v = my_atof(argv[2]); - else - goto usage; - switch (mode){ - case 0: config.low_level_offset = v; break; - case 1: config.high_level_offset = v; break; - case 2: config.switch_offset = v; break; - default: goto usage; + switch (mode){ + case 0: config.low_level_output_offset = v; break; + case 1: config.high_level_output_offset = v; break; + default: goto usage; + } + dirty = true; + return; } - dirty = true; - return; usage: shell_printf("leveloffset [%s] {output} [-20..+20]\r\n", cmd_mode_list); } diff --git a/sa_core.c b/sa_core.c index 3ef77ca..d329a80 100644 --- a/sa_core.c +++ b/sa_core.c @@ -3920,11 +3920,11 @@ enum { #define W2P(w) (sweep_points * w / 100) // convert width in % to actual sweep points -#ifdef TINYSA4 -#define CAL_LEVEL -30 -#else +//#ifdef TINYSA4 +//#define CAL_LEVEL -30 +//#else #define CAL_LEVEL -25 -#endif +//#endif // TODO made more compact this structure (need use aligned data) typedef struct test_case { @@ -4577,7 +4577,6 @@ void self_test(int test) // setting.step_delay = setting.step_delay * 4 / 5; // goto do_again; // } - // if (peakLevel < -35) { // shell_printf("Peak level too low, abort\n\r"); // return; @@ -4774,6 +4773,9 @@ void calibrate(void) #ifndef TINYSA4 setting.agc = S_ON; setting.lna = S_OFF; + set_RBW(6000); +#else + set_RBW(1000); #endif test_acquire(TEST_POWER); // Acquire test local_test_status = test_validate(TEST_POWER); // Validate test @@ -4790,11 +4792,11 @@ void calibrate(void) ili9341_drawstring_7x13("Calibration failed", 30, 140); goto quit; } else { -#ifdef TINYSA4 - set_actual_power(-30.0); // Should be -23.5dBm (V0.2) OR 25 (V0.3) -#else - set_actual_power(-25.0); // Should be -23.5dBm (V0.2) OR 25 (V0.3) -#endif +//#ifdef TINYSA4 +// set_actual_power(-30.0); // Should be -23.5dBm (V0.2) OR 25 (V0.3) +//#else + set_actual_power(CAL_LEVEL); // Should be -23.5dBm (V0.2) OR 25 (V0.3) +//#endif chThdSleepMilliseconds(1000); } } diff --git a/si4432.c b/si4432.c index dde5962..ef42922 100644 --- a/si4432.c +++ b/si4432.c @@ -447,7 +447,7 @@ static const RBW_t RBW_choices[] = }; -const int SI4432_RBW_count = ((int)(sizeof(RBW_choices)/sizeof(RBW_t))); +const uint8_t SI4432_RBW_count = ARRAY_COUNT(RBW_choices); static pureRSSI_t SI4432_RSSI_correction = float_TO_PURE_RSSI(-120); diff --git a/si4468.c b/si4468.c index 4bb4180..ff2fa5c 100644 --- a/si4468.c +++ b/si4468.c @@ -1914,6 +1914,75 @@ again: } #endif +#ifdef __LISTEN__ +const uint8_t dBm_to_volt [] = +{ + 255, + 225, + 198, + 175, + 154, + 136, + 120, + 106, + 93, + 82, + 72, + 64, + 56, + 50, + 44, + 39, + 34, + 30, + 26, + 23, + 21, + 18, + 16, + 14, + 12, + 11, + 10, + 8, + 7, + 7, + 6, + 5, + 5, +}; + +void SI4432_Listen(int s) +{ + (void) s; + uint8_t max = 0; + uint16_t count = 0; + operation_requested = OP_NONE; + do { + uint8_t v; + uint8_t data[3] = { + SI446X_CMD_GET_MODEM_STATUS, + 0xFF + }; + uint8_t out[3]; + __disable_irq(); + SI4463_do_api(data, 2, out, 3); // TODO no clear of interrupts + __enable_irq(); + v = out[2]; + if (max < v) // Peak + max = v; + if (count > 1000) { // Decay + max -= 1; + count = 0; + } else + count++; + v = max - v; + dacPutChannelX(&DACD1, 0, dBm_to_volt[v] << 4); + } while(operation_requested == OP_NONE); + count = 0; +// dacPutChannelX(&DACD2, 0, 0); +} +#endif int16_t Si446x_RSSI(void) @@ -2298,7 +2367,7 @@ static const RBW_t RBW_choices[] = {SI4463_RBW_850kHz,0,6000}, }; -const int SI4432_RBW_count = ((int)(sizeof(RBW_choices)/sizeof(RBW_t))); +const uint8_t SI4432_RBW_count = ((int)(sizeof(RBW_choices)/sizeof(RBW_t))); static pureRSSI_t SI4463_RSSI_correction = float_TO_PURE_RSSI(-120); static int prev_band = -1;