Skip to content

Commit

Permalink
Fixed RSSI calibration
Browse files Browse the repository at this point in the history
  • Loading branch information
egzumer committed Oct 16, 2023
1 parent ec4bec5 commit d817ff7
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 41 deletions.
4 changes: 2 additions & 2 deletions app/menu.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -579,7 +579,7 @@ void MENU_AcceptSetting(void)

case MENU_MIC:
gEeprom.MIC_SENSITIVITY = gSubMenuSelection;
BOARD_EEPROM_LoadMoreSettings();
BOARD_EEPROM_LoadCalibration();
gFlagReconfigureVfos = true;
break;

Expand Down
10 changes: 5 additions & 5 deletions board.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion board.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
7 changes: 1 addition & 6 deletions misc.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
7 changes: 1 addition & 6 deletions misc.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
29 changes: 9 additions & 20 deletions ui/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit d817ff7

Please sign in to comment.