diff --git a/app/app.c b/app/app.c index d94c350..3150748 100644 --- a/app/app.c +++ b/app/app.c @@ -480,53 +480,6 @@ void FUN_00007f4c(void) } } -void APP_PlayFM(void) -{ - if (!FM_CheckFrequencyLock(gEeprom.FM_FrequencyPlaying, gEeprom.FM_LowerLimit)) { - if (!gFM_AutoScan) { - gFmPlayCountdown = 0; - g_20000427 = 1; - if (!gEeprom.FM_IsMrMode) { - gEeprom.FM_SelectedFrequency = gEeprom.FM_FrequencyPlaying; - } - GPIO_SetBit(&GPIOC->DATA, GPIOC_PIN_AUDIO_PATH); - gEnableSpeaker = true; - } else { - if (gFM_ChannelPosition < 20) { - gFM_Channels[gFM_ChannelPosition++] = gEeprom.FM_FrequencyPlaying; - if (gEeprom.FM_UpperLimit > gEeprom.FM_FrequencyPlaying) { - FM_Tune(gEeprom.FM_FrequencyPlaying, gFM_Step, false); - } else { - FM_Play(); - } - } else { - FM_Play(); - } - } - } else if (gFM_AutoScan) { - if (gEeprom.FM_UpperLimit > gEeprom.FM_FrequencyPlaying) { - FM_Tune(gEeprom.FM_FrequencyPlaying, gFM_Step, false); - } else { - FM_Play(); - } - } else { - FM_Tune(gEeprom.FM_FrequencyPlaying, gFM_Step, false); - } - - GUI_SelectNextDisplay(DISPLAY_FM); -} - -void APP_StartFM(void) -{ - gFmRadioMode = true; - gFM_Step = 0; - g_2000038E = 0; - BK1080_Init(gEeprom.FM_FrequencyPlaying, true); - GPIO_SetBit(&GPIOC->DATA, GPIOC_PIN_AUDIO_PATH); - gEnableSpeaker = true; - gUpdateStatus = true; -} - void APP_CheckRadioInterrupts(void) { if (gScreenToDisplay == DISPLAY_SCANNER) { @@ -735,7 +688,7 @@ void APP_Update(void) } if (gFM_Step && gScheduleFM && gCurrentFunction != FUNCTION_MONITOR && gCurrentFunction != FUNCTION_RECEIVE && gCurrentFunction != FUNCTION_TRANSMIT) { - APP_PlayFM(); + FM_Play(); gScheduleFM = false; } @@ -948,7 +901,7 @@ void APP_TimeSlice10ms(void) if (gFmRadioMode && g_2000038E) { g_2000038E--; if (g_2000038E == 0) { - APP_StartFM(); + FM_Start(); GUI_SelectNextDisplay(DISPLAY_FM); } } @@ -1153,7 +1106,7 @@ LAB_00004b08: if (g_20000373 == 0) { RADIO_SomethingElse(0); if (gCurrentFunction != FUNCTION_RECEIVE && gCurrentFunction != FUNCTION_TRANSMIT && gCurrentFunction != FUNCTION_MONITOR && gFmRadioMode) { - APP_StartFM(); + FM_Start(); GUI_SelectNextDisplay(DISPLAY_FM); } } @@ -1349,7 +1302,7 @@ void APP_StartScan(bool bFlag) GUI_SelectNextDisplay(DISPLAY_FM); if (gFM_Step) { - FM_Play(); + FM_PlayAndUpdate(); gAnotherVoiceID = VOICE_ID_SCANNING_STOP; return; } @@ -1406,32 +1359,13 @@ void FUN_00005770(void) } RADIO_SetupRegisters(true); if (gFmRadioMode) { - APP_StartFM(); + FM_Start(); gRequestDisplayScreen = DISPLAY_FM; } else { gRequestDisplayScreen = gScreenToDisplay; } } -void APP_SwitchToFM(void) -{ - if (gCurrentFunction != FUNCTION_TRANSMIT && gCurrentFunction != FUNCTION_MONITOR) { - if (gFmRadioMode) { - FM_TurnOff(); - gInputBoxIndex = 0; - g_200003B6 = 0x50; - g_20000398 = 1; - gRequestDisplayScreen = DISPLAY_MAIN; - return; - } - RADIO_ConfigureTX(); - RADIO_SetupRegisters(true); - APP_StartFM(); - gInputBoxIndex = 0; - gRequestDisplayScreen = DISPLAY_FM; - } -} - void FUN_000056a0(bool bFlag) { gInputBoxIndex = 0; @@ -1526,7 +1460,7 @@ void FUN_00004404(KEY_Code_t Key, bool bKeyPressed, bool bKeyHeld) FUN_000056a0(0); break; case 7: - APP_SwitchToFM(); + FM_Switch(); break; case 8: FUN_000056a0(1); diff --git a/app/fm.c b/app/fm.c index 4ee7b29..9cdfb8d 100644 --- a/app/fm.c +++ b/app/fm.c @@ -22,13 +22,13 @@ #include "driver/bk1080.h" #include "driver/eeprom.h" #include "driver/gpio.h" +#include "functions.h" #include "misc.h" #include "settings.h" #include "ui/inputbox.h" #include "ui/ui.h" extern void APP_StartScan(bool bFlag); -extern void APP_SwitchToFM(void); uint16_t gFM_Channels[20]; bool gFmRadioMode; @@ -136,7 +136,7 @@ void FM_Tune(uint16_t Frequency, int8_t Step, bool bFlag) BK1080_SetFrequency(gEeprom.FM_FrequencyPlaying); } -void FM_Play(void) +void FM_PlayAndUpdate(void) { gFM_Step = 0; if (gFM_AutoScan) { @@ -286,7 +286,7 @@ static void FM_Key_DIGITS(KEY_Code_t Key, bool bKeyPressed, bool bKeyHeld) gRequestDisplayScreen = DISPLAY_FM; switch (Key) { case KEY_0: - APP_SwitchToFM(); + FM_Switch(); break; case KEY_1: @@ -326,7 +326,7 @@ static void FM_Key_EXIT(bool bKeyPressed, bool bKeyHeld) if (gFM_Step == 0) { if (gInputBoxIndex == 0) { if (!gAskToSave && !gAskToDelete) { - APP_SwitchToFM(); + FM_Switch(); return; } gAskToSave = false; @@ -348,7 +348,7 @@ static void FM_Key_EXIT(bool bKeyPressed, bool bKeyHeld) } gAnotherVoiceID = VOICE_ID_CANCEL; } else { - FM_Play(); + FM_PlayAndUpdate(); gAnotherVoiceID = VOICE_ID_SCANNING_STOP; } gRequestDisplayScreen = DISPLAY_FM; @@ -492,3 +492,70 @@ void FM_ProcessKeys(KEY_Code_t Key, bool bKeyPressed, bool bKeyHeld) break; } } + +void FM_Play(void) +{ + if (!FM_CheckFrequencyLock(gEeprom.FM_FrequencyPlaying, gEeprom.FM_LowerLimit)) { + if (!gFM_AutoScan) { + gFmPlayCountdown = 0; + g_20000427 = 1; + if (!gEeprom.FM_IsMrMode) { + gEeprom.FM_SelectedFrequency = gEeprom.FM_FrequencyPlaying; + } + GPIO_SetBit(&GPIOC->DATA, GPIOC_PIN_AUDIO_PATH); + gEnableSpeaker = true; + } else { + if (gFM_ChannelPosition < 20) { + gFM_Channels[gFM_ChannelPosition++] = gEeprom.FM_FrequencyPlaying; + if (gEeprom.FM_UpperLimit > gEeprom.FM_FrequencyPlaying) { + FM_Tune(gEeprom.FM_FrequencyPlaying, gFM_Step, false); + } else { + FM_PlayAndUpdate(); + } + } else { + FM_PlayAndUpdate(); + } + } + } else if (gFM_AutoScan) { + if (gEeprom.FM_UpperLimit > gEeprom.FM_FrequencyPlaying) { + FM_Tune(gEeprom.FM_FrequencyPlaying, gFM_Step, false); + } else { + FM_PlayAndUpdate(); + } + } else { + FM_Tune(gEeprom.FM_FrequencyPlaying, gFM_Step, false); + } + + GUI_SelectNextDisplay(DISPLAY_FM); +} + +void FM_Start(void) +{ + gFmRadioMode = true; + gFM_Step = 0; + g_2000038E = 0; + BK1080_Init(gEeprom.FM_FrequencyPlaying, true); + GPIO_SetBit(&GPIOC->DATA, GPIOC_PIN_AUDIO_PATH); + gEnableSpeaker = true; + gUpdateStatus = true; +} + +void FM_Switch(void) +{ + if (gCurrentFunction != FUNCTION_TRANSMIT && gCurrentFunction != FUNCTION_MONITOR) { + if (gFmRadioMode) { + FM_TurnOff(); + gInputBoxIndex = 0; + g_200003B6 = 0x50; + g_20000398 = 1; + gRequestDisplayScreen = DISPLAY_MAIN; + return; + } + RADIO_ConfigureTX(); + RADIO_SetupRegisters(true); + FM_Start(); + gInputBoxIndex = 0; + gRequestDisplayScreen = DISPLAY_FM; + } +} + diff --git a/app/fm.h b/app/fm.h index 4c42d28..dae4df6 100644 --- a/app/fm.h +++ b/app/fm.h @@ -39,10 +39,14 @@ void FM_TurnOff(void); void FM_EraseChannels(void); void FM_Tune(uint16_t Frequency, int8_t Step, bool bFlag); -void FM_Play(void); +void FM_PlayAndUpdate(void); int FM_CheckFrequencyLock(uint16_t Frequency, uint16_t LowerLimit); void FM_ProcessKeys(KEY_Code_t Key, bool bKeyPressed, bool bKeyHeld); +void FM_Play(void); +void FM_Start(void); +void FM_Switch(void); + #endif diff --git a/app/generic.c b/app/generic.c index f85f837..e34ef7f 100644 --- a/app/generic.c +++ b/app/generic.c @@ -164,7 +164,7 @@ void GENERIC_Key_PTT(bool bKeyPressed) gRequestDisplayScreen = DISPLAY_MENU; } } else { - FM_Play(); + FM_PlayAndUpdate(); gRequestDisplayScreen = DISPLAY_FM; } gAnotherVoiceID = VOICE_ID_SCANNING_STOP; diff --git a/app/main.c b/app/main.c index d54b74f..0789596 100644 --- a/app/main.c +++ b/app/main.c @@ -27,7 +27,6 @@ #include "ui/inputbox.h" #include "ui/ui.h" -extern void APP_SwitchToFM(void); extern void FUN_0000773c(void); extern void APP_SetFrequencyByStep(VFO_Info_t *pInfo, int8_t Step); extern void APP_ChangeStepDirectionMaybe(bool bFlag, int8_t Direction); @@ -136,7 +135,7 @@ static void MAIN_Key_DIGITS(KEY_Code_t Key, bool bKeyPressed, bool bKeyHeld) gUpdateStatus = true; switch (Key) { case KEY_0: - APP_SwitchToFM(); + FM_Switch(); break; case KEY_1: @@ -283,7 +282,7 @@ static void MAIN_Key_EXIT(bool bKeyPressed, bool bKeyHeld) gRequestDisplayScreen = DISPLAY_MAIN; return; } - APP_SwitchToFM(); + FM_Switch(); } }