From d817ff7e6a1b4756099655d1315b26afa7d143f0 Mon Sep 17 00:00:00 2001 From: Krzysiek Egzmont Date: Mon, 16 Oct 2023 12:22:56 +0200 Subject: [PATCH] Fixed RSSI calibration --- app/menu.c | 4 ++-- board.c | 10 +++++----- board.h | 2 +- main.c | 2 +- misc.c | 7 +------ misc.h | 7 +------ ui/main.c | 29 +++++++++-------------------- 7 files changed, 20 insertions(+), 41 deletions(-) diff --git a/app/menu.c b/app/menu.c index aea53a6f6..ac38da6cd 100644 --- a/app/menu.c +++ b/app/menu.c @@ -505,7 +505,7 @@ void MENU_AcceptSetting(void) gEeprom.VOX_SWITCH = gSubMenuSelection != 0; if (gEeprom.VOX_SWITCH) gEeprom.VOX_LEVEL = gSubMenuSelection - 1; - BOARD_EEPROM_LoadMoreSettings(); + BOARD_EEPROM_LoadCalibration(); gFlagReconfigureVfos = true; gUpdateStatus = true; break; @@ -579,7 +579,7 @@ void MENU_AcceptSetting(void) case MENU_MIC: gEeprom.MIC_SENSITIVITY = gSubMenuSelection; - BOARD_EEPROM_LoadMoreSettings(); + BOARD_EEPROM_LoadCalibration(); gFlagReconfigureVfos = true; break; diff --git a/board.c b/board.c index a63272637..8bf66154d 100644 --- a/board.c +++ b/board.c @@ -739,14 +739,14 @@ void BOARD_EEPROM_Init(void) } } -void BOARD_EEPROM_LoadMoreSettings(void) +void BOARD_EEPROM_LoadCalibration(void) { // uint8_t Mic; - EEPROM_ReadBuffer(0x1EC0, gEEPROM_1EC0_0, 8); - memmove(gEEPROM_1EC0_1, gEEPROM_1EC0_0, 8); - memmove(gEEPROM_1EC0_2, gEEPROM_1EC0_0, 8); - memmove(gEEPROM_1EC0_3, gEEPROM_1EC0_0, 8); + EEPROM_ReadBuffer(0x1EC0, gEEPROM_RSSI_CALIB[3], 8); + memcpy(gEEPROM_RSSI_CALIB[4], gEEPROM_RSSI_CALIB[3], 8); + memcpy(gEEPROM_RSSI_CALIB[5], gEEPROM_RSSI_CALIB[3], 8); + memcpy(gEEPROM_RSSI_CALIB[6], gEEPROM_RSSI_CALIB[3], 8); // 8 * 16-bit values EEPROM_ReadBuffer(0x1EC0, gEEPROM_RSSI_CALIB[0], 8); diff --git a/board.h b/board.h index a65d1c9ac..4f854aa13 100644 --- a/board.h +++ b/board.h @@ -27,7 +27,7 @@ void BOARD_ADC_Init(void); void BOARD_ADC_GetBatteryInfo(uint16_t *pVoltage, uint16_t *pCurrent); void BOARD_Init(void); void BOARD_EEPROM_Init(void); -void BOARD_EEPROM_LoadMoreSettings(void); +void BOARD_EEPROM_LoadCalibration(void); uint32_t BOARD_fetchChannelFrequency(const int channel); void BOARD_fetchChannelName(char *s, const int channel); void BOARD_FactoryReset(bool bIsAll); diff --git a/main.c b/main.c index a7d82f27c..e77228832 100644 --- a/main.c +++ b/main.c @@ -84,7 +84,7 @@ void Main(void) BOARD_EEPROM_Init(); - BOARD_EEPROM_LoadMoreSettings(); + BOARD_EEPROM_LoadCalibration(); RADIO_ConfigureChannel(0, VFO_CONFIGURE_RELOAD); RADIO_ConfigureChannel(1, VFO_CONFIGURE_RELOAD); diff --git a/misc.c b/misc.c index 0f4d51a70..bb3a5f9cf 100644 --- a/misc.c +++ b/misc.c @@ -110,12 +110,7 @@ bool bHasCustomAesKey; uint32_t gChallenge[4]; uint8_t gTryCount; -uint8_t gEEPROM_1EC0_0[8]; -uint8_t gEEPROM_1EC0_1[8]; -uint8_t gEEPROM_1EC0_2[8]; -uint8_t gEEPROM_1EC0_3[8]; - -uint16_t gEEPROM_RSSI_CALIB[2][4]; +uint16_t gEEPROM_RSSI_CALIB[7][4]; uint16_t gEEPROM_1F8A; uint16_t gEEPROM_1F8C; diff --git a/misc.h b/misc.h index 57e8a07ed..ad1bd6432 100644 --- a/misc.h +++ b/misc.h @@ -184,12 +184,7 @@ extern bool bHasCustomAesKey; extern uint32_t gChallenge[4]; extern uint8_t gTryCount; -extern uint8_t gEEPROM_1EC0_0[8]; -extern uint8_t gEEPROM_1EC0_1[8]; -extern uint8_t gEEPROM_1EC0_2[8]; -extern uint8_t gEEPROM_1EC0_3[8]; - -extern uint16_t gEEPROM_RSSI_CALIB[2][4]; +extern uint16_t gEEPROM_RSSI_CALIB[7][4]; extern uint16_t gEEPROM_1F8A; extern uint16_t gEEPROM_1F8C; diff --git a/ui/main.c b/ui/main.c index 17231326c..1348163e8 100644 --- a/ui/main.c +++ b/ui/main.c @@ -58,8 +58,8 @@ void UI_drawBars(uint8_t *p, const unsigned int level) case 4: memmove(p + 11, BITMAP_AntennaLevel3, sizeof(BITMAP_AntennaLevel3)); case 3: memmove(p + 8, BITMAP_AntennaLevel2, sizeof(BITMAP_AntennaLevel2)); case 2: memmove(p + 5, BITMAP_AntennaLevel1, sizeof(BITMAP_AntennaLevel1)); - case 1: memmove(p + 0, BITMAP_Antenna, sizeof(BITMAP_Antenna)); - case 0: break; + case 1: memmove(p + 0, BITMAP_Antenna, sizeof(BITMAP_Antenna)); break; + case 0: memset( p + 0, 0, sizeof(BITMAP_Antenna)); break; } #pragma GCC diagnostic pop @@ -218,24 +218,13 @@ void UI_UpdateRSSI(const int16_t rssi, const int vfo) const uint8_t Line = (vfo == 0) ? 3 : 7; uint8_t *p_line = gFrameBuffer[Line - 1]; - // TODO: sort out all 8 values from the eeprom - - #if 0 - // dBm -105 -100 -95 -90 -70 -65 -60 -55 - // RSSI 110 120 130 140 180 190 200 210 - // 0000C0 6E 00 78 00 82 00 8C 00 B4 00 BE 00 C8 00 D2 00 - // - const unsigned int band = 1; - const int16_t level0 = gEEPROM_RSSI_CALIB[band][0]; - const int16_t level1 = gEEPROM_RSSI_CALIB[band][1]; - const int16_t level2 = gEEPROM_RSSI_CALIB[band][2]; - const int16_t level3 = gEEPROM_RSSI_CALIB[band][3]; - #else - const int16_t level0 = (-115 + 160) * 2; // dB - const int16_t level1 = ( -89 + 160) * 2; // dB - const int16_t level2 = ( -64 + 160) * 2; // dB - const int16_t level3 = ( -39 + 160) * 2; // dB - #endif + + const unsigned int band = gRxVfo->Band; + const int16_t level0 = gEEPROM_RSSI_CALIB[band][0]; + const int16_t level1 = gEEPROM_RSSI_CALIB[band][1]; + const int16_t level2 = gEEPROM_RSSI_CALIB[band][2]; + const int16_t level3 = gEEPROM_RSSI_CALIB[band][3]; + const int16_t level01 = (level0 + level1) / 2; const int16_t level12 = (level1 + level2) / 2; const int16_t level23 = (level2 + level3) / 2;