From ecb9455f470655f8a51039b7b49fad18d7cdf2c2 Mon Sep 17 00:00:00 2001 From: erikkaashoek Date: Tue, 17 Nov 2020 16:27:45 +0100 Subject: [PATCH] Revert "Revert "Broken scan"" This reverts commit 3707c681d809cb6c46be59bdbb575d4d31b719fb. --- nanovna.h | 4 +++- sa_core.c | 38 ++++++++++++++++++++++++++++++++------ si4432.c | 17 +++++++++++++++++ 3 files changed, 52 insertions(+), 7 deletions(-) diff --git a/nanovna.h b/nanovna.h index f84a9cb..1236ab4 100644 --- a/nanovna.h +++ b/nanovna.h @@ -1064,7 +1064,9 @@ enum { // -------------------- Si4432.c --------------- +#ifdef __SI4463__ extern int SI4463_R; void Si4463_set_refer(int ref); - +void SI446x_set_AGC_LNA(uint8_t v); +#endif /*EOF*/ diff --git a/sa_core.c b/sa_core.c index 02a7051..86680d3 100644 --- a/sa_core.c +++ b/sa_core.c @@ -717,9 +717,7 @@ void toggle_AGC(void) dirty = true; } -#ifdef __SI4432__ static unsigned char SI4432_old_v[2]; -#endif void auto_set_AGC_LNA(int auto_set, int agc) // Adapt the AGC setting if needed { @@ -735,6 +733,17 @@ void auto_set_AGC_LNA(int auto_set, int agc) SI4432_old_v[MODE_SELECT(setting.mode)] = v; } #endif +#ifdef __SI4463__ + unsigned char v; + if (auto_set) + v = 0x00; // Enable AGC and disable LNA + else + v = 0x88+agc; // Disable AGC and enable LNA + if (SI4432_old_v[0] != v) { + SI446x_set_AGC_LNA(v); + SI4432_old_v[0] = v; + } +#endif } #ifdef __SI4432__ @@ -747,6 +756,18 @@ void set_AGC_LNA(void) { } #endif +#ifdef __SI4463__ +void set_AGC_LNA(void) { + uint8_t v = 0; + if (!S_STATE(setting.agc)) + v |= 0x80; // Inverse!!!! + if (S_STATE(setting.lna)) + v |= 0x08; // Inverse!!!! + SI446x_set_AGC_LNA(v); + SI4432_old_v[0] = v; +} +#endif + void set_unit(int u) { if (setting.unit == u) @@ -1263,8 +1284,10 @@ case M_ULTRA: } else { set_switch_receive(); } +#endif set_AGC_LNA(); +#ifdef __SI4432__ SI4432_Sel = SI4432_LO ; if (setting.tracking_output) set_switch_transmit(); @@ -1290,8 +1313,8 @@ mute: } else { set_switch_receive(); } - set_AGC_LNA(); #endif + set_AGC_LNA(); break; case M_GENLOW: // Mixed output from 0 @@ -1736,10 +1759,12 @@ pureRSSI_t perform(bool break_on_operation, int i, uint32_t f, int tracking) } } if (setting.mode == M_LOW && S_IS_AUTO(setting.agc) && !check_for_AM && UNIT_IS_LOG(setting.unit)) { // If in low input mode with auto AGC and log unit +#ifdef __SI4432__ if (f < 1500000) auto_set_AGC_LNA(false, f*9/1500000); else auto_set_AGC_LNA(true, 0); +#endif } // Calculate the RSSI correction for later use if (MODE_INPUT(setting.mode)){ // only cases where the value can change on 0 point of sweep @@ -2184,6 +2209,7 @@ sweep_again: // stay in sweep loop when output mo // ----------------------- in loop AGC --------------------------------- +#ifdef __SI4432__ if (!in_selftest && setting.mode == M_HIGH && S_IS_AUTO(setting.agc) && UNIT_IS_LOG(setting.unit)) { #define AGC_RSSI_THRESHOLD (-55+get_attenuation()) @@ -2201,7 +2227,7 @@ sweep_again: // stay in sweep loop when output mo else auto_set_AGC_LNA(TRUE, 0); } - +#endif // Delay between points if needed, (all delays can apply in SI4432 fill) if (setting.measure_sweep_time_us == 0){ // If not already in buffer @@ -2476,6 +2502,7 @@ sweep_again: // stay in sweep loop when output mo if (!in_selftest && MODE_INPUT(setting.mode)) { +#ifdef __SI4432__ if (S_IS_AUTO(setting.agc)) { float actual_max_level = actual_t[max_index[0]] - get_attenuation(); if (UNIT_IS_LINEAR(setting.unit)) { // Auto AGC in linear mode @@ -2499,6 +2526,7 @@ sweep_again: // stay in sweep loop when output mo } } } else +#endif signal_is_AM = false; } @@ -2664,9 +2692,7 @@ sweep_again: // stay in sweep loop when output mo setting.agc = S_AUTO_OFF; setting.lna = S_AUTO_ON; } -#ifdef __SI4432__ set_AGC_LNA(); -#endif } } diff --git a/si4432.c b/si4432.c index fd37ca8..7bc83ec 100644 --- a/si4432.c +++ b/si4432.c @@ -1713,6 +1713,23 @@ int16_t Si446x_RSSI(void) } +void SI446x_set_AGC_LNA(uint8_t v) +{ + + uint8_t data[2] = { + 0xd0, // AGC_OVERRIDE + v + }; + SI4463_do_api(data, sizeof(data), NULL, 0); +#if 0 + if (v == 0) { + data[0] = 0xd1; // Read AGC?????? NO + SI4463_do_api(data, 1, data, 1); + } +#endif +} + + // Do an ADC conversion static uint16_t getADC(uint8_t adc_en, uint8_t adc_cfg, uint8_t part)