diff --git a/Makefile b/Makefile index b8cc111..8fff338 100644 --- a/Makefile +++ b/Makefile @@ -15,7 +15,6 @@ OBJS += external/printf/printf.o OBJS += driver/adc.o OBJS += driver/aes.o OBJS += driver/backlight.o -OBJS += driver/bk1080.o OBJS += driver/bk4819.o OBJS += driver/crc.o OBJS += driver/eeprom.o @@ -33,7 +32,6 @@ OBJS += driver/uart.o OBJS += app/action.o OBJS += app/app.o OBJS += app/dtmf.o -OBJS += app/fm.o OBJS += app/generic.o OBJS += app/main.o OBJS += app/menu.o @@ -53,7 +51,6 @@ OBJS += radio.o OBJS += scheduler.o OBJS += settings.o OBJS += ui/battery.o -OBJS += ui/fmradio.o OBJS += ui/helper.o OBJS += ui/inputbox.o OBJS += ui/lock.o diff --git a/app/app.c b/app/app.c index 14c3448..638fe11 100644 --- a/app/app.c +++ b/app/app.c @@ -21,7 +21,6 @@ #include "ARMCM0.h" #include "app/action.h" #include "app/dtmf.h" -#include "app/fm.h" #include "app/generic.h" #include "app/main.h" #include "app/menu.h" @@ -31,7 +30,6 @@ #include "board.h" #include "bsp/dp32g030/gpio.h" #include "driver/backlight.h" -#include "driver/bk1080.h" #include "driver/bk4819.h" #include "driver/gpio.h" #include "driver/keyboard.h" @@ -279,9 +277,7 @@ static void APP_HandleFunction(void) { } void APP_StartListening(FUNCTION_Type_t Function) { - if (gFmRadioMode) { - BK1080_Init(0, false); - } + gVFO_RSSI_Level[gEeprom.RX_CHANNEL == 0] = 0; GPIO_SetBit(&GPIOC->DATA, GPIOC_PIN_AUDIO_PATH); gEnableSpeaker = true; @@ -328,7 +324,7 @@ void APP_StartListening(FUNCTION_Type_t Function) { } } FUNCTION_Select(Function); - if (Function == FUNCTION_MONITOR || gFmRadioMode) { + if (Function == FUNCTION_MONITOR) { GUI_SelectNextDisplay(DISPLAY_MAIN); return; } @@ -387,7 +383,7 @@ static void MR_NextChannel(void) { if (gCurrentScanList == 2) { gNextMrChannel = gPreviousMrChannel; } else { - goto Skip; + goto Skip; //ебать бы вас в задницу } } @@ -513,7 +509,7 @@ static void APP_HandleVox(void) { } if (gCurrentFunction != FUNCTION_RECEIVE && gCurrentFunction != FUNCTION_MONITOR && gScanState == SCAN_OFF && - gCssScanMode == CSS_SCAN_MODE_OFF && !gFmRadioMode) { + gCssScanMode == CSS_SCAN_MODE_OFF) { if (gVOX_NoiseDetected) { if (g_VOX_Lost) { gVoxStopCountdown = 100; @@ -572,9 +568,7 @@ void APP_Update(void) { if (gCurrentFunction != FUNCTION_TRANSMIT) { APP_HandleFunction(); } - if (gFmRadioCountdown) { - return; - } + if (gScreenToDisplay != DISPLAY_SCANNER && gScanState != SCAN_OFF && gScheduleScanListen && !gPttIsPressed && gVoiceWriteIndex == 0) { @@ -607,7 +601,7 @@ void APP_Update(void) { gEeprom.DUAL_WATCH != DUAL_WATCH_OFF) { if (gScheduleDualWatch && gVoiceWriteIndex == 0) { if (gScanState == SCAN_OFF && gCssScanMode == CSS_SCAN_MODE_OFF) { - if (!gPttIsPressed && !gFmRadioMode && + if (!gPttIsPressed && gDTMF_CallState == DTMF_CALL_STATE_NONE && gCurrentFunction != FUNCTION_POWER_SAVE) { DUALWATCH_Alternate(); @@ -623,13 +617,7 @@ void APP_Update(void) { } } - if (gFM_ScanState != FM_SCAN_OFF && gScheduleFM && - gCurrentFunction != FUNCTION_MONITOR && - gCurrentFunction != FUNCTION_RECEIVE && - gCurrentFunction != FUNCTION_TRANSMIT) { - FM_Play(); - gScheduleFM = false; - } + if (gEeprom.VOX_SWITCH) { APP_HandleVox(); @@ -637,7 +625,7 @@ void APP_Update(void) { if (gSchedulePowerSave) { if (gEeprom.BATTERY_SAVE == 0 || gScanState != SCAN_OFF || - gCssScanMode != CSS_SCAN_MODE_OFF || gFmRadioMode || + gCssScanMode != CSS_SCAN_MODE_OFF || gPttIsPressed || gScreenToDisplay != DISPLAY_MAIN || gKeyBeingHeld || gDTMF_CallState != DTMF_CALL_STATE_NONE) { gBatterySaveCountdown = 1000; @@ -779,9 +767,7 @@ void APP_TimeSlice10ms(void) { // Skipping authentic device checks - if (gFmRadioCountdown) { - return; - } + if (gFlashLightState == FLASHLIGHT_BLINK && (gFlashLightBlinkCounter & 15U) == 0) { @@ -839,13 +825,7 @@ void APP_TimeSlice10ms(void) { } } } - if (gFmRadioMode && gFM_RestoreCountdown) { - gFM_RestoreCountdown--; - if (gFM_RestoreCountdown == 0) { - FM_Start(); - GUI_SelectNextDisplay(DISPLAY_FM); - } - } + if (gScreenToDisplay == DISPLAY_SCANNER) { uint32_t Result; int32_t Delta; @@ -954,12 +934,7 @@ void APP_TimeSlice500ms(void) { } } - // Skipped authentic device check - if (gFmRadioCountdown) { - gFmRadioCountdown--; - return; - } if (gReducedService) { BOARD_ADC_GetBatteryInfo(&gBatteryCurrentVoltage, &gBatteryCurrent); if (gBatteryCurrent > 500 || @@ -987,7 +962,7 @@ void APP_TimeSlice500ms(void) { gCurrentRSSI = BK4819_GetRSSI(); UI_UpdateRSSI(gCurrentRSSI); } - if ((gFM_ScanState == FM_SCAN_OFF || gAskToSave) && + if (/*(gFM_ScanState == FM_SCAN_OFF || gAskToSave) &&*/ gScanState == SCAN_OFF && gCssScanMode == CSS_SCAN_MODE_OFF) { if (gBacklightCountdown) { gBacklightCountdown--; @@ -1026,32 +1001,15 @@ void APP_TimeSlice500ms(void) { gDTMF_InputIndex = 0; gAskToSave = false; gAskToDelete = false; - if (gFmRadioMode && - gCurrentFunction != FUNCTION_RECEIVE && - gCurrentFunction != FUNCTION_MONITOR && - gCurrentFunction != FUNCTION_TRANSMIT) { - GUI_SelectNextDisplay(DISPLAY_FM); - } else { - GUI_SelectNextDisplay(DISPLAY_MAIN); - } + GUI_SelectNextDisplay(DISPLAY_MAIN); + } } } } } - if (!gPttIsPressed && gFM_ResumeCountdown) { - gFM_ResumeCountdown--; - if (gFM_ResumeCountdown == 0) { - RADIO_SetVfoState(VFO_STATE_NORMAL); - if (gCurrentFunction != FUNCTION_RECEIVE && - gCurrentFunction != FUNCTION_TRANSMIT && - gCurrentFunction != FUNCTION_MONITOR && gFmRadioMode) { - FM_Start(); - GUI_SelectNextDisplay(DISPLAY_FM); - } - } - } + if (gLowBattery) { gLowBatteryBlink = ++gLowBatteryCountdown & 1; @@ -1186,10 +1144,6 @@ static void APP_ProcessKey(KEY_Code_t Key, bool bKeyPressed, bool bKeyHeld) { SETTINGS_SaveSettings(); gFlagSaveSettings = false; } - if (gFlagSaveFM) { - SETTINGS_SaveFM(); - gFlagSaveFM = false; - } if (gFlagSaveChannel) { SETTINGS_SaveChannel(gTxVfo->CHANNEL_SAVE, gEeprom.TX_CHANNEL, gTxVfo, gFlagSaveChannel); @@ -1357,7 +1311,7 @@ static void APP_ProcessKey(KEY_Code_t Key, bool bKeyPressed, bool bKeyHeld) { MAIN_ProcessKeys(Key, bKeyPressed, bKeyHeld); break; case DISPLAY_FM: - FM_ProcessKeys(Key, bKeyPressed, bKeyHeld); + // FM_ProcessKeys(Key, bKeyPressed, bKeyHeld); break; case DISPLAY_MENU: MENU_ProcessKeys(Key, bKeyPressed, bKeyHeld); @@ -1399,14 +1353,7 @@ static void APP_ProcessKey(KEY_Code_t Key, bool bKeyPressed, bool bKeyHeld) { gRequestSaveSettings = false; gUpdateStatus = true; } - if (gRequestSaveFM) { - if (!bKeyHeld) { - SETTINGS_SaveFM(); - } else { - gFlagSaveFM = true; - } - gRequestSaveFM = false; - } + if (gRequestSaveVFO) { if (!bKeyHeld) { SETTINGS_SaveVfoIndices(); diff --git a/app/fm.c b/app/fm.c deleted file mode 100644 index c6e24b0..0000000 --- a/app/fm.c +++ /dev/null @@ -1,252 +0,0 @@ -/* Copyright 2023 Dual Tachyon - * https://github.com/DualTachyon - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include "app/action.h" -#include "app/fm.h" -#include "app/generic.h" -#include "audio.h" -#include "bsp/dp32g030/gpio.h" -#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" - -uint16_t gFM_Channels[20]; -bool gFmRadioMode; -uint8_t gFmRadioCountdown; -volatile uint16_t gFmPlayCountdown; -volatile int8_t gFM_ScanState; -bool gFM_AutoScan; -uint8_t gFM_ChannelPosition; -bool gFM_FoundFrequency; -bool gFM_AutoScan; -uint8_t gFM_ResumeCountdown; -uint16_t gFM_RestoreCountdown; - -bool FM_CheckValidChannel(uint8_t Channel) -{ - if (Channel < 20 && (gFM_Channels[Channel] >= 760 && gFM_Channels[Channel] < 1080)) { - return true; - } - - return false; -} - -uint8_t FM_FindNextChannel(uint8_t Channel, uint8_t Direction) -{ - uint8_t i; - - for (i = 0; i < 20; i++) { - Channel %= 20; - if (FM_CheckValidChannel(Channel)) { - return Channel; - } - Channel += Direction; - } - - return 0xFF; -} - -int FM_ConfigureChannelState(void) -{ - uint8_t Channel; - - gEeprom.FM_FrequencyPlaying = gEeprom.FM_SelectedFrequency; - if (gEeprom.FM_IsMrMode) { - Channel = FM_FindNextChannel(gEeprom.FM_SelectedChannel, FM_CHANNEL_UP); - if (Channel == 0xFF) { - gEeprom.FM_IsMrMode = false; - return -1; - } - gEeprom.FM_SelectedChannel = Channel; - gEeprom.FM_FrequencyPlaying = gFM_Channels[Channel]; - } - - return 0; -} - -void FM_TurnOff(void) -{ - gFmRadioMode = false; - gFM_ScanState = FM_SCAN_OFF; - gFM_RestoreCountdown = 0; - GPIO_ClearBit(&GPIOC->DATA, GPIOC_PIN_AUDIO_PATH); - gEnableSpeaker = false; - BK1080_Init(0, false); - gUpdateStatus = true; -} - -void FM_EraseChannels(void) -{ - uint8_t i; - uint8_t Template[8]; - - memset(Template, 0xFF, sizeof(Template)); - for (i = 0; i < 5; i++) { - EEPROM_WriteBuffer(0x0E40 + (i * 8), Template); - } - - memset(gFM_Channels, 0xFF, sizeof(gFM_Channels)); -} - -void FM_Tune(uint16_t Frequency, int8_t Step, bool bFlag) -{ - GPIO_ClearBit(&GPIOC->DATA, GPIOC_PIN_AUDIO_PATH); - gEnableSpeaker = false; - if (gFM_ScanState == FM_SCAN_OFF) { - gFmPlayCountdown = 120; - } else { - gFmPlayCountdown = 10; - } - gScheduleFM = false; - gFM_FoundFrequency = false; - gAskToSave = false; - gAskToDelete = false; - gEeprom.FM_FrequencyPlaying = Frequency; - if (!bFlag) { - Frequency += Step; - if (Frequency < gEeprom.FM_LowerLimit) { - Frequency = gEeprom.FM_UpperLimit; - } else if (Frequency > gEeprom.FM_UpperLimit) { - Frequency = gEeprom.FM_LowerLimit; - } - gEeprom.FM_FrequencyPlaying = Frequency; - } - - gFM_ScanState = Step; - BK1080_SetFrequency(gEeprom.FM_FrequencyPlaying); -} - -void FM_PlayAndUpdate(void) -{ - gFM_ScanState = FM_SCAN_OFF; - if (gFM_AutoScan) { - gEeprom.FM_IsMrMode = true; - gEeprom.FM_SelectedChannel = 0; - } - FM_ConfigureChannelState(); - BK1080_SetFrequency(gEeprom.FM_FrequencyPlaying); - SETTINGS_SaveFM(); - gFmPlayCountdown = 0; - gScheduleFM = false; - gAskToSave = false; - GPIO_SetBit(&GPIOC->DATA, GPIOC_PIN_AUDIO_PATH); - gEnableSpeaker = true; -} - -int FM_CheckFrequencyLock(uint16_t Frequency, uint16_t LowerLimit) -{ - uint16_t Test2; - uint16_t Deviation; - int ret = -1; - - Test2 = BK1080_ReadRegister(BK1080_REG_07); - // This is supposed to be a signed value, but above function is unsigned - Deviation = BK1080_REG_07_GET_FREQD(Test2); - - if (BK1080_REG_07_GET_SNR(Test2) >= 2) { - uint16_t Status; - - Status = BK1080_ReadRegister(BK1080_REG_10); - if ((Status & BK1080_REG_10_MASK_AFCRL) == BK1080_REG_10_AFCRL_NOT_RAILED && BK1080_REG_10_GET_RSSI(Status) >= 10) { - // if (Deviation > -281 && Deviation < 280) - if (Deviation < 280 || Deviation > 3815) { - // not BLE(less than or equal) - if (Frequency > LowerLimit && (Frequency - BK1080_BaseFrequency) == 1) { - if (BK1080_FrequencyDeviation & 0x800) { - goto Bail; - } - if (BK1080_FrequencyDeviation < 20) { - goto Bail; - } - } - // not BLT(less than) - if (Frequency >= LowerLimit && (BK1080_BaseFrequency - Frequency) == 1) { - if ((BK1080_FrequencyDeviation & 0x800) == 0) { - goto Bail; - } - // if (BK1080_FrequencyDeviation > -21) { - if (BK1080_FrequencyDeviation > 4075) { - goto Bail; - } - } - ret = 0; - } - } - } - -Bail: - BK1080_FrequencyDeviation = Deviation; - BK1080_BaseFrequency = Frequency; - - return ret; -} - - -void FM_ProcessKeys(KEY_Code_t Key, bool bKeyPressed, bool bKeyHeld) -{ - -} - -void FM_Play(void) -{ - if (!FM_CheckFrequencyLock(gEeprom.FM_FrequencyPlaying, gEeprom.FM_LowerLimit)) { - if (!gFM_AutoScan) { - gFmPlayCountdown = 0; - gFM_FoundFrequency = true; - if (!gEeprom.FM_IsMrMode) { - gEeprom.FM_SelectedFrequency = gEeprom.FM_FrequencyPlaying; - } - GPIO_SetBit(&GPIOC->DATA, GPIOC_PIN_AUDIO_PATH); - gEnableSpeaker = true; - GUI_SelectNextDisplay(DISPLAY_FM); - return; - } - if (gFM_ChannelPosition < 20) { - gFM_Channels[gFM_ChannelPosition++] = gEeprom.FM_FrequencyPlaying; - } - if (gFM_ChannelPosition >= 20) { - FM_PlayAndUpdate(); - GUI_SelectNextDisplay(DISPLAY_FM); - return; - } - } - - if (gFM_AutoScan && gEeprom.FM_FrequencyPlaying >= gEeprom.FM_UpperLimit) { - FM_PlayAndUpdate(); - } else { - FM_Tune(gEeprom.FM_FrequencyPlaying, gFM_ScanState, false); - } - - GUI_SelectNextDisplay(DISPLAY_FM); -} - -void FM_Start(void) -{ - gFmRadioMode = true; - gFM_ScanState = FM_SCAN_OFF; - gFM_RestoreCountdown = 0; - BK1080_Init(gEeprom.FM_FrequencyPlaying, true); - GPIO_SetBit(&GPIOC->DATA, GPIOC_PIN_AUDIO_PATH); - gEnableSpeaker = true; - gUpdateStatus = true; -} - diff --git a/app/fm.h b/app/fm.h deleted file mode 100644 index 1c0b9e8..0000000 --- a/app/fm.h +++ /dev/null @@ -1,59 +0,0 @@ -/* Copyright 2023 Dual Tachyon - * https://github.com/DualTachyon - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef APP_FM_H -#define APP_FM_H - -#include "driver/keyboard.h" - -#define FM_CHANNEL_UP 0x01 -#define FM_CHANNEL_DOWN 0xFF - -enum { - FM_SCAN_OFF = 0U, -}; - -extern uint16_t gFM_Channels[20]; -extern bool gFmRadioMode; -extern uint8_t gFmRadioCountdown; -extern volatile uint16_t gFmPlayCountdown; -extern volatile int8_t gFM_ScanState; -extern bool gFM_AutoScan; -extern uint8_t gFM_ChannelPosition; -// Doubts about whether this should be signed or not. -extern uint16_t gFM_FrequencyDeviation; -extern bool gFM_FoundFrequency; -extern bool gFM_AutoScan; -extern uint8_t gFM_ResumeCountdown; -extern uint16_t gFM_RestoreCountdown; - -bool FM_CheckValidChannel(uint8_t Channel); -uint8_t FM_FindNextChannel(uint8_t Channel, uint8_t Direction); -int FM_ConfigureChannelState(void); -void FM_TurnOff(void); -void FM_EraseChannels(void); - -void FM_Tune(uint16_t Frequency, int8_t Step, bool bFlag); -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); - -#endif - diff --git a/app/uart.c b/app/uart.c index 705ca02..6ffaac0 100644 --- a/app/uart.c +++ b/app/uart.c @@ -15,7 +15,6 @@ */ #include -#include "app/fm.h" #include "app/uart.h" #include "board.h" #include "bsp/dp32g030/dma.h" @@ -214,7 +213,7 @@ static void CMD_0514(const uint8_t *pBuffer) const CMD_0514_t *pCmd = (const CMD_0514_t *)pBuffer; Timestamp = pCmd->Timestamp; - gFmRadioCountdown = 4; + //gFmRadioCountdown = 4; GPIO_ClearBit(&GPIOB->DATA, GPIOB_PIN_BACKLIGHT); SendVersion(); } @@ -229,7 +228,7 @@ static void CMD_051B(const uint8_t *pBuffer) return; } - gFmRadioCountdown = 4; + //gFmRadioCountdown = 4; memset(&Reply, 0, sizeof(Reply)); Reply.Header.ID = 0x051C; Reply.Header.Size = pCmd->Size + 4; @@ -260,7 +259,7 @@ static void CMD_051D(const uint8_t *pBuffer) bReloadEeprom = false; - gFmRadioCountdown = 4; + //gFmRadioCountdown = 4; Reply.Header.ID = 0x051E; Reply.Header.Size = sizeof(Reply.Data); Reply.Data.Offset = pCmd->Offset; @@ -325,7 +324,7 @@ static void CMD_052D(const uint8_t *pBuffer) REPLY_052D_t Reply; bool bIsLocked; - gFmRadioCountdown = 4; + //gFmRadioCountdown = 4; Reply.Header.ID = 0x052E; Reply.Header.Size = sizeof(Reply.Data); diff --git a/audio.c b/audio.c index c0c7404..cc36b2c 100644 --- a/audio.c +++ b/audio.c @@ -14,10 +14,9 @@ * limitations under the License. */ -#include "app/fm.h" + #include "audio.h" #include "bsp/dp32g030/gpio.h" -#include "driver/bk1080.h" #include "driver/bk4819.h" #include "driver/gpio.h" #include "driver/system.h" @@ -84,9 +83,6 @@ void AUDIO_PlayBeep(BEEP_Type_t Beep) BK4819_RX_TurnOn(); } - if (gFmRadioMode) { - BK1080_Mute(true); - } SYSTEM_DelayMs(20); switch (Beep) { case BEEP_1KHZ_60MS_OPTIONAL: @@ -138,9 +134,6 @@ void AUDIO_PlayBeep(BEEP_Type_t Beep) if (gEnableSpeaker) { GPIO_SetBit(&GPIOC->DATA, GPIOC_PIN_AUDIO_PATH); } - if (gFmRadioMode) { - BK1080_Mute(false); - } if (gCurrentFunction == FUNCTION_POWER_SAVE && gRxIdleMode) { BK4819_Sleep(); } @@ -193,9 +186,6 @@ void AUDIO_PlaySingleVoice(bool bFlag) if (gCurrentFunction == FUNCTION_RECEIVE || gCurrentFunction == FUNCTION_MONITOR) { BK4819_SetAF(BK4819_AF_MUTE); } - if (gFmRadioMode) { - BK1080_Mute(true); - } GPIO_SetBit(&GPIOC->DATA, GPIOC_PIN_AUDIO_PATH); gVoxResumeCountdown = 2000; SYSTEM_DelayMs(5); @@ -212,9 +202,6 @@ void AUDIO_PlaySingleVoice(bool bFlag) BK4819_SetAF(BK4819_AF_OPEN); } } - if (gFmRadioMode) { - BK1080_Mute(false); - } if (!gEnableSpeaker) { GPIO_ClearBit(&GPIOC->DATA, GPIOC_PIN_AUDIO_PATH); } @@ -327,9 +314,6 @@ void AUDIO_PlayQueuedVoice(void) BK4819_SetAF(BK4819_AF_OPEN); } } - if (gFmRadioMode) { - BK1080_Mute(false); - } if (!gEnableSpeaker) { GPIO_ClearBit(&GPIOC->DATA, GPIOC_PIN_AUDIO_PATH); } diff --git a/board.c b/board.c index 622c191..a43a07b 100644 --- a/board.c +++ b/board.c @@ -17,14 +17,12 @@ #include #include "app/dtmf.h" -#include "app/fm.h" #include "board.h" #include "bsp/dp32g030/gpio.h" #include "bsp/dp32g030/portcon.h" #include "bsp/dp32g030/saradc.h" #include "bsp/dp32g030/syscon.h" #include "driver/adc.h" -#include "driver/bk1080.h" #include "driver/bk4819.h" #include "driver/crc.h" #include "driver/eeprom.h" @@ -335,7 +333,6 @@ void BOARD_Init(void) BOARD_GPIO_Init(); BOARD_ADC_Init(); ST7565_Init(); - BK1080_Init(0, false); CRC_Init(); } @@ -396,8 +393,8 @@ void BOARD_EEPROM_Init(void) gEeprom.FM_IsMrMode = (FM.IsMrMode < 2) ? FM.IsMrMode : false; // 0E40..0E67 - EEPROM_ReadBuffer(0x0E40, gFM_Channels, sizeof(gFM_Channels)); - FM_ConfigureChannelState(); + //EEPROM_ReadBuffer(0x0E40, gFM_Channels, sizeof(gFM_Channels)); + //FM_ConfigureChannelState(); // 0E90..0E97 EEPROM_ReadBuffer(0x0E90, Data, 8); diff --git a/driver/bk1080-regs.h b/driver/bk1080-regs.h deleted file mode 100644 index 49dfdfc..0000000 --- a/driver/bk1080-regs.h +++ /dev/null @@ -1,57 +0,0 @@ -/* Copyright 2023 Dual Tachyon - * https://github.com/DualTachyon - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef BK1080_REGS_H -#define BK1080_REGS_H - -enum BK1080_Register_t { - BK1080_REG_00 = 0x00U, - BK1080_REG_02_POWER_CONFIGURATION = 0x02U, - BK1080_REG_03_CHANNEL = 0x03U, - BK1080_REG_05_SYSTEM_CONFIGURATION2 = 0x05U, - BK1080_REG_07 = 0x07U, - BK1080_REG_10 = 0x0AU, - BK1080_REG_25_INTERNAL = 0x19U, -}; - -typedef enum BK1080_Register_t BK1080_Register_t; - -// REG 07 - -#define BK1080_REG_07_SHIFT_FREQD 4 -#define BK1080_REG_07_SHIFT_SNR 0 - -#define BK1080_REG_07_MASK_FREQD (0xFFFU << BK1080_REG_07_SHIFT_FREQD) -#define BK1080_REG_07_MASK_SNR (0x00FU << BK1080_REG_07_SHIFT_SNR) - -#define BK1080_REG_07_GET_FREQD(x) (((x) & BK1080_REG_07_MASK_FREQD) >> BK1080_REG_07_SHIFT_FREQD) -#define BK1080_REG_07_GET_SNR(x) (((x) & BK1080_REG_07_MASK_SNR) >> BK1080_REG_07_SHIFT_SNR) - -// REG 10 - -#define BK1080_REG_10_SHIFT_AFCRL 12 -#define BK1080_REG_10_SHIFT_RSSI 0 - -#define BK1080_REG_10_MASK_AFCRL (0x01U << BK1080_REG_10_SHIFT_AFCRL) -#define BK1080_REG_10_MASK_RSSI (0xFFU << BK1080_REG_10_SHIFT_RSSI) - -#define BK1080_REG_10_AFCRL_NOT_RAILED (0U << BK1080_REG_10_SHIFT_AFCRL) -#define BK1080_REG_10_AFCRL_RAILED (1U << BK1080_REG_10_SHIFT_AFCRL) - -#define BK1080_REG_10_GET_RSSI(x) (((x) & BK1080_REG_10_MASK_RSSI) >> BK1080_REG_10_SHIFT_RSSI) - -#endif - diff --git a/driver/bk1080.c b/driver/bk1080.c deleted file mode 100644 index 7c9d6bb..0000000 --- a/driver/bk1080.c +++ /dev/null @@ -1,115 +0,0 @@ -/* Copyright 2023 Dual Tachyon - * https://github.com/DualTachyon - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "bsp/dp32g030/gpio.h" -#include "bk1080.h" -#include "driver/gpio.h" -#include "driver/i2c.h" -#include "driver/system.h" -#include "misc.h" - -#define ARRAY_SIZE(a) (sizeof(a) / sizeof(a[0])) - -static const uint16_t BK1080_RegisterTable[] = { - 0x0008, 0x1080, 0x0201, 0x0000, - 0x40C0, 0x0A1F, 0x002E, 0x02FF, - 0x5B11, 0x0000, 0x411E, 0x0000, - 0xCE00, 0x0000, 0x0000, 0x1000, - 0x3197, 0x0000, 0x13FF, 0x9852, - 0x0000, 0x0000, 0x0008, 0x0000, - 0x51E1, 0xA8BC, 0x2645, 0x00E4, - 0x1CD8, 0x3A50, 0xEAE0, 0x3000, - 0x0200, 0x0000, -}; - -static bool gIsInitBK1080; - -uint16_t BK1080_BaseFrequency; -uint16_t BK1080_FrequencyDeviation; - -void BK1080_Init(uint16_t Frequency, bool bDoScan) -{ - uint8_t i; - - if (bDoScan) { - GPIO_ClearBit(&GPIOB->DATA, GPIOB_PIN_BK1080); - - if (!gIsInitBK1080) { - for (i = 0; i < ARRAY_SIZE(BK1080_RegisterTable); i++) { - BK1080_WriteRegister(i, BK1080_RegisterTable[i]); - } - SYSTEM_DelayMs(250); - BK1080_WriteRegister(BK1080_REG_25_INTERNAL, 0xA83C); - BK1080_WriteRegister(BK1080_REG_25_INTERNAL, 0xA8BC); - SYSTEM_DelayMs(60); - gIsInitBK1080 = true; - } else { - BK1080_WriteRegister(BK1080_REG_02_POWER_CONFIGURATION, 0x0201); - } - BK1080_WriteRegister(BK1080_REG_05_SYSTEM_CONFIGURATION2, 0x0A5F); - BK1080_WriteRegister(BK1080_REG_03_CHANNEL, Frequency - 760); - SYSTEM_DelayMs(10); - BK1080_WriteRegister(BK1080_REG_03_CHANNEL, (Frequency - 760) | 0x8000); - } else { - BK1080_WriteRegister(BK1080_REG_02_POWER_CONFIGURATION, 0x0241); - GPIO_SetBit(&GPIOB->DATA, GPIOB_PIN_BK1080); - } -} - -uint16_t BK1080_ReadRegister(BK1080_Register_t Register) -{ - uint8_t Value[2]; - - I2C_Start(); - I2C_Write(0x80); - I2C_Write((Register << 1) | I2C_READ); - I2C_ReadBuffer(Value, sizeof(Value)); - I2C_Stop(); - return (Value[0] << 8) | Value[1]; -} - -void BK1080_WriteRegister(BK1080_Register_t Register, uint16_t Value) -{ - I2C_Start(); - I2C_Write(0x80); - I2C_Write((Register << 1) | I2C_WRITE); - Value = ((Value >> 8) & 0xFF) | ((Value & 0xFF) << 8); - I2C_WriteBuffer(&Value, sizeof(Value)); - I2C_Stop(); -} - -void BK1080_Mute(bool Mute) -{ - if (Mute) { - BK1080_WriteRegister(BK1080_REG_02_POWER_CONFIGURATION, 0x4201); - } else { - BK1080_WriteRegister(BK1080_REG_02_POWER_CONFIGURATION, 0x0201); - } -} - -void BK1080_SetFrequency(uint16_t Frequency) -{ - BK1080_WriteRegister(BK1080_REG_03_CHANNEL, Frequency - 760); - SYSTEM_DelayMs(10); - BK1080_WriteRegister(BK1080_REG_03_CHANNEL, (Frequency - 760) | 0x8000); -} - -void BK1080_GetFrequencyDeviation(uint16_t Frequency) -{ - BK1080_BaseFrequency = Frequency; - BK1080_FrequencyDeviation = BK1080_ReadRegister(BK1080_REG_07) / 16; -} - diff --git a/driver/bk1080.h b/driver/bk1080.h deleted file mode 100644 index ed1f9c1..0000000 --- a/driver/bk1080.h +++ /dev/null @@ -1,35 +0,0 @@ -/* Copyright 2023 Dual Tachyon - * https://github.com/DualTachyon - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef DRIVER_BK1080_H -#define DRIVER_BK1080_H - -#include -#include -#include "driver/bk1080-regs.h" - -extern uint16_t BK1080_BaseFrequency; -extern uint16_t BK1080_FrequencyDeviation; - -void BK1080_Init(uint16_t Frequency, bool bDoScan); -uint16_t BK1080_ReadRegister(BK1080_Register_t Register); -void BK1080_WriteRegister(BK1080_Register_t Register, uint16_t Value); -void BK1080_Mute(bool Mute); -void BK1080_SetFrequency(uint16_t Frequency); -void BK1080_GetFrequencyDeviation(uint16_t Frequency); - -#endif - diff --git a/firmware.packed.bin b/firmware.packed.bin index 30b7294..ffa14f5 100644 Binary files a/firmware.packed.bin and b/firmware.packed.bin differ diff --git a/functions.c b/functions.c index a2f3e62..458bdfa 100644 --- a/functions.c +++ b/functions.c @@ -19,10 +19,8 @@ #include #include "app/dtmf.h" -#include "app/fm.h" #include "bsp/dp32g030/gpio.h" #include "dcs.h" -#include "driver/bk1080.h" #include "driver/bk4819.h" #include "driver/gpio.h" #include "driver/system.h" @@ -65,7 +63,7 @@ void FUNCTION_Init(void) { void FUNCTION_Select(FUNCTION_Type_t Function) { FUNCTION_Type_t PreviousFunction; bool bWasPowerSave; - uint16_t Countdown = 0; + PreviousFunction = gCurrentFunction; bWasPowerSave = (PreviousFunction == FUNCTION_POWER_SAVE); @@ -88,9 +86,7 @@ void FUNCTION_Select(FUNCTION_Type_t Function) { gVFO_RSSI_Level[0] = 0; gVFO_RSSI_Level[1] = 0; } else if (PreviousFunction == FUNCTION_RECEIVE) { - if (gFmRadioMode) { - Countdown = 500; - } + if (gDTMF_CallState == DTMF_CALL_STATE_CALL_OUT || gDTMF_CallState == DTMF_CALL_STATE_RECEIVED) { gDTMF_AUTO_RESET_TIME = @@ -116,9 +112,7 @@ void FUNCTION_Select(FUNCTION_Type_t Function) { return; case FUNCTION_TRANSMIT: - if (gFmRadioMode) { - BK1080_Init(0, false); - } + if (gAlarmState == ALARM_STATE_TXALARM && gEeprom.ALARM_MODE != ALARM_MODE_TONE) { @@ -163,5 +157,5 @@ void FUNCTION_Select(FUNCTION_Type_t Function) { } gBatterySaveCountdown = 1000; gSchedulePowerSave = false; - gFM_RestoreCountdown = Countdown; + } diff --git a/radio.c b/radio.c index 6ff5662..144568f 100644 --- a/radio.c +++ b/radio.c @@ -19,7 +19,6 @@ #include #include "app/dtmf.h" -#include "app/fm.h" #include "audio.h" #include "bsp/dp32g030/gpio.h" #include "dcs.h" @@ -553,7 +552,7 @@ void RADIO_SetupRegisters(bool bSwitchToFunction0) { } } - if (gEeprom.VOX_SWITCH && !gFmRadioMode && !gCurrentVfo->IsAM) { + if (gEeprom.VOX_SWITCH && !gCurrentVfo->IsAM) { BK4819_EnableVox(gEeprom.VOX1_THRESHOLD, gEeprom.VOX0_THRESHOLD); InterruptMask |= 0 | BK4819_REG_3F_VOX_FOUND | BK4819_REG_3F_VOX_LOST; } else { @@ -619,7 +618,6 @@ void RADIO_SetVfoState(VfoState_t State) { if (State == VFO_STATE_NORMAL) { VfoState[0] = VFO_STATE_NORMAL; VfoState[1] = VFO_STATE_NORMAL; - gFM_ResumeCountdown = 0; } else { if (State == VFO_STATE_VOL_HIGH) { VfoState[0] = VFO_STATE_VOL_HIGH; @@ -634,7 +632,6 @@ void RADIO_SetVfoState(VfoState_t State) { } VfoState[Channel] = State; } - gFM_ResumeCountdown = 5; } gUpdateDisplay = true; } diff --git a/scheduler.c b/scheduler.c index cbe8ab7..6f615c6 100644 --- a/scheduler.c +++ b/scheduler.c @@ -14,7 +14,7 @@ * limitations under the License. */ -#include "app/fm.h" + #include "app/scanner.h" #include "audio.h" #include "functions.h" @@ -80,11 +80,7 @@ void SystickHandler(void) DECREMENT_AND_TRIGGER(gCountdownToPlayNextVoice, gFlagPlayQueuedVoice); - if (gFM_ScanState != FM_SCAN_OFF && gCurrentFunction != FUNCTION_MONITOR) { - if (gCurrentFunction != FUNCTION_TRANSMIT && gCurrentFunction != FUNCTION_RECEIVE) { - DECREMENT_AND_TRIGGER(gFmPlayCountdown, gScheduleFM); - } - } + if (gVoxStopCountdown) { gVoxStopCountdown--; } diff --git a/settings.c b/settings.c index d8d5279..8dde1d6 100644 --- a/settings.c +++ b/settings.c @@ -18,34 +18,14 @@ #include -#include "app/fm.h" + #include "driver/eeprom.h" #include "driver/uart.h" #include "misc.h" EEPROM_Config_t gEeprom; -void SETTINGS_SaveFM(void) { - uint8_t i; - struct { - uint16_t Frequency; - uint8_t Channel; - bool IsChannelSelected; - uint8_t Padding[4]; - } State; - - UART_LogSend("sFm\r\n", 5); - - memset(&State, 0xFF, sizeof(State)); - State.Channel = gEeprom.FM_SelectedChannel; - State.Frequency = gEeprom.FM_SelectedFrequency; - State.IsChannelSelected = gEeprom.FM_IsMrMode; - - EEPROM_WriteBuffer(0x0E88, &State); - for (i = 0; i < 5; i++) { - EEPROM_WriteBuffer(0x0E40 + (i * 8), &gFM_Channels[i * 4]); - } -} + void SETTINGS_SaveVfoIndices(void) { uint8_t State[8]; diff --git a/ui/fmradio.c b/ui/fmradio.c deleted file mode 100644 index 851a010..0000000 --- a/ui/fmradio.c +++ /dev/null @@ -1,90 +0,0 @@ -/* Copyright 2023 Dual Tachyon - * https://github.com/DualTachyon - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include "app/fm.h" -#include "driver/st7565.h" -#include "external/printf/printf.h" -#include "misc.h" -#include "settings.h" -#include "ui/fmradio.h" -#include "ui/helper.h" -#include "ui/inputbox.h" -#include "ui/ui.h" - -void UI_DisplayFM(void) -{ - uint8_t i; - char String[16]; - - memset(gFrameBuffer, 0, sizeof(gFrameBuffer)); - - memset(String, 0, sizeof(String)); - strcpy(String, "FM"); - - UI_PrintString(String, 0, 127, 0, 12, true); - memset(String, 0, sizeof(String)); - - if (gAskToSave) { - strcpy(String, "SAVE?"); - } else if (gAskToDelete) { - strcpy(String, "DEL?"); - } else { - if (gFM_ScanState == FM_SCAN_OFF) { - if (!gEeprom.FM_IsMrMode) { - for (i = 0; i < 20; i++) { - if (gEeprom.FM_FrequencyPlaying == gFM_Channels[i]) { - sprintf(String, "VFO(CH%02d)", i + 1); - break; - } - } - if (i == 20) { - strcpy(String, "VFO"); - } - } else { - sprintf(String, "MR(CH%02d)", gEeprom.FM_SelectedChannel + 1); - } - } else { - if (!gFM_AutoScan) { - strcpy(String, "M-SCAN"); - } else { - sprintf(String, "A-SCAN(%d)", gFM_ChannelPosition + 1); - } - } - } - - UI_PrintString(String, 0, 127, 2, 10, true); - memset(String, 0, sizeof(String)); - - if (gAskToSave || (gEeprom.FM_IsMrMode && gInputBoxIndex)) { - UI_GenerateChannelString(String, gFM_ChannelPosition); - } else if (!gAskToDelete) { - if (gInputBoxIndex == 0) { - NUMBER_ToDigits(gEeprom.FM_FrequencyPlaying * 10000, String); - UI_DisplayFrequency(String, 23, 4, false, true); - } else { - UI_DisplayFrequency(gInputBox, 23, 4, true, false); - } - ST7565_BlitFullScreen(); - return; - } else { - sprintf(String, "CH-%02d", gEeprom.FM_SelectedChannel + 1); - } - - UI_PrintString(String, 0, 127, 4, 10, true); - ST7565_BlitFullScreen(); -} - diff --git a/ui/fmradio.h b/ui/fmradio.h deleted file mode 100644 index 8309e9e..0000000 --- a/ui/fmradio.h +++ /dev/null @@ -1,23 +0,0 @@ -/* Copyright 2023 Dual Tachyon - * https://github.com/DualTachyon - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef UI_FM_H -#define UI_FM_H - -void UI_DisplayFM(void); - -#endif - diff --git a/ui/status.c b/ui/status.c index 5555025..e2566d2 100644 --- a/ui/status.c +++ b/ui/status.c @@ -15,7 +15,7 @@ */ #include -#include "app/fm.h" + #include "bitmaps.h" #include "driver/keyboard.h" #include "driver/st7565.h" @@ -67,9 +67,7 @@ void UI_DisplayStatus(void) if (gEeprom.VOICE_PROMPT != VOICE_PROMPT_OFF) { memcpy(gStatusLine + 34, BITMAP_VoicePrompt, sizeof(BITMAP_VoicePrompt)); } - if (gFmRadioMode) { - memcpy(gStatusLine + 21, BITMAP_FM, sizeof(BITMAP_FM)); - } + ST7565_BlitStatusLine(); } diff --git a/ui/ui.c b/ui/ui.c index 09c22f2..8704c13 100644 --- a/ui/ui.c +++ b/ui/ui.c @@ -16,11 +16,9 @@ #include #include "app/dtmf.h" -#include "app/fm.h" #include "app/scanner.h" #include "driver/keyboard.h" #include "misc.h" -#include "ui/fmradio.h" #include "ui/inputbox.h" #include "ui/main.h" #include "ui/menu.h" @@ -41,7 +39,6 @@ void GUI_DisplayScreen(void) UI_DisplayMain(); break; case DISPLAY_FM: - UI_DisplayFM(); break; case DISPLAY_MENU: UI_DisplayMenu(); @@ -62,7 +59,6 @@ void GUI_SelectNextDisplay(GUI_DisplayType_t Display) gIsInSubMenu = false; gCssScanMode = CSS_SCAN_MODE_OFF; gScanState = SCAN_OFF; - gFM_ScanState = FM_SCAN_OFF; gAskForConfirmation = 0; gDTMF_InputMode = false; gDTMF_InputIndex = 0;