fix #81 fm radio 10s scan timeout, eeprom frequency validation

This commit is contained in:
Nunu 2024-01-19 11:16:15 +01:00
parent ef98c1e9f8
commit 9159fea8c6
4 changed files with 16 additions and 2 deletions

View File

@ -30,6 +30,9 @@
#include "settings.h"
#include "ui/ui.h"
const uint16_t FM_RADIO_MAX_FREQ = 1080; // 108 Mhz
const uint16_t FM_RADIO_MIN_FREQ = 875; // 87.5 Mhz
bool gFmRadioMode;
uint8_t gFmRadioCountdown_500ms;
volatile uint16_t gFmPlayCountdown_10ms;
@ -59,7 +62,7 @@ static void Key_EXIT()
static void Key_UP_DOWN(bool direction)
{
BK1080_TuneNext(direction);
BK1080_TuneNext(direction);
gEeprom.FM_FrequencyPlaying = BK1080_GetFrequency();
// save
gRequestSaveSettings = true;

View File

@ -22,6 +22,9 @@
#include "driver/keyboard.h"
extern const uint16_t FM_RADIO_MAX_FREQ;
extern const uint16_t FM_RADIO_MIN_FREQ;
enum {
FM_SCAN_OFF = 0U,
};

View File

@ -564,6 +564,10 @@ void BOARD_EEPROM_Init(void)
#ifdef ENABLE_FMRADIO
EEPROM_ReadBuffer(0x0E88, Data, 8);
memmove(&gEeprom.FM_FrequencyPlaying, Data, 2);
// validate that its within the supported range
if(gEeprom.FM_FrequencyPlaying < FM_RADIO_MIN_FREQ || gEeprom.FM_FrequencyPlaying > FM_RADIO_MAX_FREQ)
gEeprom.FM_FrequencyPlaying = FM_RADIO_MIN_FREQ;
#endif
// 0E90..0E97

View File

@ -114,6 +114,7 @@ void BK1080_TuneNext(bool direction)
{
uint16_t reg_11;
uint16_t reg_02;
uint8_t scanCounter_100ms = 100; // timeouts after 10s
reg_02 = BK1080_ReadRegister(BK1080_REG_02_POWER_CONFIGURATION);
reg_11 = BK1080_ReadRegister(BK1080_REG_11);
@ -128,7 +129,10 @@ void BK1080_TuneNext(bool direction)
// wait until we find the channel
while((BK1080_ReadRegister(BK1080_REG_10) >> 14) == 0){
SYSTEM_DelayMs(5);
if(scanCounter_100ms-- == 0)
break;
SYSTEM_DelayMs(100);
}
//read found freq