diff --git a/app/fm.c b/app/fm.c index 922eb92..2ea52af 100644 --- a/app/fm.c +++ b/app/fm.c @@ -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; diff --git a/app/fm.h b/app/fm.h index e838af4..7bad1f9 100644 --- a/app/fm.h +++ b/app/fm.h @@ -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, }; diff --git a/board.c b/board.c index e48f9e7..7f249ed 100644 --- a/board.c +++ b/board.c @@ -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 diff --git a/driver/bk1080.c b/driver/bk1080.c index a950a13..8ce9a83 100644 --- a/driver/bk1080.c +++ b/driver/bk1080.c @@ -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