From 9159fea8c63a07a42ebf202c65e2f2fa8d455f3f Mon Sep 17 00:00:00 2001 From: Nunu Date: Fri, 19 Jan 2024 11:16:15 +0100 Subject: [PATCH] fix #81 fm radio 10s scan timeout, eeprom frequency validation --- app/fm.c | 5 ++++- app/fm.h | 3 +++ board.c | 4 ++++ driver/bk1080.c | 6 +++++- 4 files changed, 16 insertions(+), 2 deletions(-) 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