Revert "Revert "Broken scan""

This reverts commit 3707c681d8.
Removed_REF_marker
erikkaashoek 5 years ago
parent ba2fcb197e
commit ecb9455f47

@ -1064,7 +1064,9 @@ enum {
// -------------------- Si4432.c --------------- // -------------------- Si4432.c ---------------
#ifdef __SI4463__
extern int SI4463_R; extern int SI4463_R;
void Si4463_set_refer(int ref); void Si4463_set_refer(int ref);
void SI446x_set_AGC_LNA(uint8_t v);
#endif
/*EOF*/ /*EOF*/

@ -717,9 +717,7 @@ void toggle_AGC(void)
dirty = true; dirty = true;
} }
#ifdef __SI4432__
static unsigned char SI4432_old_v[2]; static unsigned char SI4432_old_v[2];
#endif
void auto_set_AGC_LNA(int auto_set, int agc) // Adapt the AGC setting if needed 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; SI4432_old_v[MODE_SELECT(setting.mode)] = v;
} }
#endif #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__ #ifdef __SI4432__
@ -747,6 +756,18 @@ void set_AGC_LNA(void) {
} }
#endif #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) void set_unit(int u)
{ {
if (setting.unit == u) if (setting.unit == u)
@ -1263,8 +1284,10 @@ case M_ULTRA:
} else { } else {
set_switch_receive(); set_switch_receive();
} }
#endif
set_AGC_LNA(); set_AGC_LNA();
#ifdef __SI4432__
SI4432_Sel = SI4432_LO ; SI4432_Sel = SI4432_LO ;
if (setting.tracking_output) if (setting.tracking_output)
set_switch_transmit(); set_switch_transmit();
@ -1290,8 +1313,8 @@ mute:
} else { } else {
set_switch_receive(); set_switch_receive();
} }
set_AGC_LNA();
#endif #endif
set_AGC_LNA();
break; break;
case M_GENLOW: // Mixed output from 0 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 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) if (f < 1500000)
auto_set_AGC_LNA(false, f*9/1500000); auto_set_AGC_LNA(false, f*9/1500000);
else else
auto_set_AGC_LNA(true, 0); auto_set_AGC_LNA(true, 0);
#endif
} }
// Calculate the RSSI correction for later use // Calculate the RSSI correction for later use
if (MODE_INPUT(setting.mode)){ // only cases where the value can change on 0 point of sweep 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 --------------------------------- // ----------------------- in loop AGC ---------------------------------
#ifdef __SI4432__
if (!in_selftest && setting.mode == M_HIGH && S_IS_AUTO(setting.agc) && UNIT_IS_LOG(setting.unit)) { if (!in_selftest && setting.mode == M_HIGH && S_IS_AUTO(setting.agc) && UNIT_IS_LOG(setting.unit)) {
#define AGC_RSSI_THRESHOLD (-55+get_attenuation()) #define AGC_RSSI_THRESHOLD (-55+get_attenuation())
@ -2201,7 +2227,7 @@ sweep_again: // stay in sweep loop when output mo
else else
auto_set_AGC_LNA(TRUE, 0); auto_set_AGC_LNA(TRUE, 0);
} }
#endif
// Delay between points if needed, (all delays can apply in SI4432 fill) // Delay between points if needed, (all delays can apply in SI4432 fill)
if (setting.measure_sweep_time_us == 0){ // If not already in buffer 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)) { if (!in_selftest && MODE_INPUT(setting.mode)) {
#ifdef __SI4432__
if (S_IS_AUTO(setting.agc)) { if (S_IS_AUTO(setting.agc)) {
float actual_max_level = actual_t[max_index[0]] - get_attenuation(); float actual_max_level = actual_t[max_index[0]] - get_attenuation();
if (UNIT_IS_LINEAR(setting.unit)) { // Auto AGC in linear mode 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 } else
#endif
signal_is_AM = false; signal_is_AM = false;
} }
@ -2664,9 +2692,7 @@ sweep_again: // stay in sweep loop when output mo
setting.agc = S_AUTO_OFF; setting.agc = S_AUTO_OFF;
setting.lna = S_AUTO_ON; setting.lna = S_AUTO_ON;
} }
#ifdef __SI4432__
set_AGC_LNA(); set_AGC_LNA();
#endif
} }
} }

@ -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 // Do an ADC conversion
static uint16_t getADC(uint8_t adc_en, uint8_t adc_cfg, uint8_t part) static uint16_t getADC(uint8_t adc_en, uint8_t adc_cfg, uint8_t part)

Loading…
Cancel
Save

Powered by TurnKey Linux.