From f15433928989d14a6692a18dd3d84366bb733450 Mon Sep 17 00:00:00 2001 From: erikkaashoek Date: Wed, 9 Dec 2020 13:09:45 +0100 Subject: [PATCH] Added CP setting --- sa_core.c | 2 +- si4432.c | 109 +++++++++++++++++++++++++++++++----------------------- ui_sa.c | 16 +++++--- 3 files changed, 74 insertions(+), 53 deletions(-) diff --git a/sa_core.c b/sa_core.c index 2a4b28b..66efe9a 100644 --- a/sa_core.c +++ b/sa_core.c @@ -1956,7 +1956,7 @@ modulation_again: #endif } if (setting.spur_removal){ // If in low input mode and spur reduction is on - if (S_IS_AUTO(setting.below_IF) && lf < local_IF / 2 ) // if below 150MHz and auto_below_IF <-------------------TODO --------------------- + if (false && S_IS_AUTO(setting.below_IF) && lf < local_IF / 2 ) // if below 150MHz and auto_below_IF <-------------------TODO --------------------- { // else low/above IF if (setting.spur_removal == 1) setting.below_IF = S_AUTO_ON; // use below IF in first pass diff --git a/si4432.c b/si4432.c index 849dad3..63b2f9d 100644 --- a/si4432.c +++ b/si4432.c @@ -877,9 +877,9 @@ float Simulated_SI4432_RSSI(uint32_t i, int s) //uint32_t registers[6] = {0x320000, 0x8008011, 0x4E42, 0x4B3,0x8C803C , 0x580005} ; //25 MHz ref #ifdef TINYSA4_PROTO -uint32_t registers[6] = {0xA00000, 0x8000011, 0x4042, 0x4B3,0xDC003C , 0x580005} ; //10 MHz ref +uint32_t registers[6] = {0xA00000, 0x8000011, 0x4042, 0x4B3,0x9F003C , 0x580005} ; //10 MHz ref #else -uint32_t registers[6] = {0xA00000, 0x8000011, 0x4E42, 0x4B3,0xDC003C , 0x580005} ; //10 MHz ref +uint32_t registers[6] = {0xA00000, 0x8000011, 0x4E42, 0x4B3,0x9F003C , 0x580005} ; //10 MHz ref #endif int debug = 0; ioline_t ADF4351_LE[2] = { LINE_LO_SEL, LINE_LO_SEL}; @@ -1094,6 +1094,9 @@ static uint32_t gcd(uint32_t x, uint32_t y) return x; } +#if 0 +#endif + uint64_t ADF4351_prep_frequency(int channel, uint64_t freq) // freq / 10Hz { target_freq = freq; @@ -1139,8 +1142,8 @@ uint64_t ADF4351_prep_frequency(int channel, uint64_t freq) // freq / 10Hz // Serial.println( "MOD/FRAC reduced"); } #endif - uint32_t reduce = gcd(MOD, FRAC); #if 0 + uint32_t reduce = gcd(MOD, FRAC); if (reduce>1) { FRAC /= reduce; MOD /= reduce; @@ -1699,58 +1702,70 @@ void set_RSSI_comp(void) int16_t Si446x_RSSI(void) { - uint8_t data[3] = { - SI446X_CMD_GET_MODEM_STATUS, - 0xFF - }; - if (SI4432_step_delay && (ADF4351_frequency_changed || SI4463_frequency_changed)) { - my_microsecond_delay(SI4432_step_delay); - ADF4351_frequency_changed = false; - SI4463_frequency_changed = false; - } else if (SI4432_offset_delay && SI4463_frequency_changed) { + + int i = setting.repeat; + int32_t RSSI_RAW = 0; + do{ + // if (MODE_INPUT(setting.mode) && RSSI_R + uint8_t data[3] = { + SI446X_CMD_GET_MODEM_STATUS, + 0xFF + }; + if (SI4432_step_delay && (ADF4351_frequency_changed || SI4463_frequency_changed)) { + my_microsecond_delay(SI4432_step_delay); + ADF4351_frequency_changed = false; + SI4463_frequency_changed = false; + } else if (SI4432_offset_delay && SI4463_frequency_changed) { my_microsecond_delay(SI4432_offset_delay); ADF4351_frequency_changed = false; SI4463_frequency_changed = false; - } - - int i = 1; //setting.repeat; - int RSSI_RAW[3]; - do{ - again: - data[0] = SI446X_CMD_GET_MODEM_STATUS; - data[1] = 0xFF; - SI4463_do_api(data, 2, data, 3); - if (data[2] == 255) { - my_microsecond_delay(10); - goto again; } - RSSI_RAW[--i] = data[2] - 120 * 2; - if (i == 0) break; - my_microsecond_delay(100); - }while(1); + + int j = 1; //setting.repeat; + int RSSI_RAW_ARRAY[3]; + do{ + again: + data[0] = SI446X_CMD_GET_MODEM_STATUS; + data[1] = 0xFF; + SI4463_do_api(data, 2, data, 3); + if (data[2] == 255) { + my_microsecond_delay(10); + goto again; + } + RSSI_RAW_ARRAY[--j] = data[2] - 120 * 2; + if (j == 0) break; + my_microsecond_delay(100); + }while(1); #if 0 - int t; - if (RSSI_RAW[0] > RSSI_RAW[1]) { - t = RSSI_RAW[1]; - RSSI_RAW[1] = RSSI_RAW[0]; - RSSI_RAW[0] = t; - } - if (RSSI_RAW[1] > RSSI_RAW[2]) { - t = RSSI_RAW[2]; - RSSI_RAW[2] = RSSI_RAW[1]; - RSSI_RAW[1] = t; - } - if (RSSI_RAW[0] > RSSI_RAW[1]) { - t = RSSI_RAW[1]; - RSSI_RAW[1] = RSSI_RAW[0]; - RSSI_RAW[0] = t; - } + int t; + if (RSSI_RAW_ARRAY[0] > RSSI_RAW_ARRAY[1]) { + t = RSSI_RAW_ARRAY[1]; + RSSI_RAW_ARRAY[1] = RSSI_RAW_ARRAY[0]; + RSSI_RAW_ARRAY[0] = t; + } + if (RSSI_RAW_ARRAY[1] > RSSI_RAW_ARRAY[2]) { + t = RSSI_RAW_ARRAY[2]; + RSSI_RAW_ARRAY[2] = RSSI_RAW_ARRAY[1]; + RSSI_RAW_ARRAY[1] = t; + } + if (RSSI_RAW_ARRAY[0] > RSSI_RAW_ARRAY[1]) { + t = RSSI_RAW_ARRAY[1]; + RSSI_RAW_ARRAY[1] = RSSI_RAW_ARRAY[0]; + RSSI_RAW_ARRAY[0] = t; + } - return DEVICE_TO_PURE_RSSI(RSSI_RAW[1]); + RSSI_RAW += DEVICE_TO_PURE_RSSI(RSSI_RAW_ARRAY[1]); #else - return DEVICE_TO_PURE_RSSI(RSSI_RAW[0]); + RSSI_RAW += DEVICE_TO_PURE_RSSI(RSSI_RAW_ARRAY[0]); #endif + if (--i <= 0) break; + my_microsecond_delay(100); + }while(1); + if (setting.repeat > 1) + RSSI_RAW = RSSI_RAW / setting.repeat; + + return RSSI_RAW; } void SI446x_set_AGC_LNA(uint8_t v) @@ -2143,7 +2158,7 @@ void SI4463_set_freq(uint32_t freq) while(1) my_microsecond_delay(10); } - if (false && (SI4463_band == prev_band)) { + if ((SI4463_band == prev_band)) { uint8_t data[] = { 0x36, (uint8_t) R, // R data[4] diff --git a/ui_sa.c b/ui_sa.c index b987ec1..1dee97b 100644 --- a/ui_sa.c +++ b/ui_sa.c @@ -408,7 +408,7 @@ enum { KM_ACTUALPOWER, KM_IF, KM_SAMPLETIME, KM_DRIVE, KM_LOWOUTLEVEL, KM_DECAY, KM_NOISE, KM_10MHZ, KM_REPEAT, KM_OFFSET, KM_TRIGGER, KM_LEVELSWEEP, KM_SWEEP_TIME, KM_OFFSET_DELAY, KM_FAST_SPEEDUP, KM_GRIDLINES, KM_MARKER, KM_MODULATION,KM_COR_AM,KM_COR_WFM, KM_COR_NFM, KM_IF2, - KM_R,KM_MOD,KM_MUX,KM_ATTACK, + KM_R,KM_MOD,KM_CP,KM_ATTACK, KM_NONE // always at enum end }; @@ -448,7 +448,7 @@ static const struct { {keypads_freq , "IF2"}, // KM_IF2 {keypads_positive , "R"}, // KM_R {keypads_positive , "MODULO"}, // KM_MOD - {keypads_positive , "MUX"}, // KM_MUX + {keypads_positive , "CP"}, // KM_CP {keypads_positive , "ATTACK"}, // KM_ATTACK }; @@ -467,6 +467,10 @@ static const menuitem_t menu_tophigh[]; static const menuitem_t menu_topultra[]; #endif + +#define AUTO_ICON(s) (s >=2 ? BUTTON_ICON_CHECK_AUTO : s) // This assumes the a certin icon order !!!!!! + + static UI_FUNCTION_ADV_CALLBACK(menu_mode_acb) { (void)data; @@ -743,6 +747,8 @@ static UI_FUNCTION_ADV_CALLBACK(menu_sdrive_acb){ menu_push_submenu(menu_drive_wide); } + + #ifdef __SPUR__ static UI_FUNCTION_ADV_CALLBACK(menu_spur_acb) { @@ -1725,7 +1731,7 @@ static const menuitem_t menu_settings3[] = // { MT_KEYPAD | MT_LOW, KM_IF2, "IF2 FREQ", "Set to zero for no IF2"}, { MT_KEYPAD, KM_R, "R", "Set R"}, { MT_KEYPAD, KM_MOD, "MODULO", "Set MODULO"}, - { MT_KEYPAD, KM_MUX, "MUX", "Set MUX"}, + { MT_KEYPAD, KM_CP, "CP", "Set CP"}, { MT_ADV_CALLBACK | MT_LOW, 0, "ULTRA", menu_settings_ultra_acb}, #ifdef __HAM_BAND__ @@ -2210,8 +2216,8 @@ set_numeric_value(void) case KM_MOD: set_modulo(uistat.value); break; - case KM_MUX: - ADF4351_mux((int)uistat.value); + case KM_CP: + ADF4351_CP((int)uistat.value); // config_save(); break; case KM_SAMPLETIME: