From 89650936caadf19d955139e85a82a288376591c4 Mon Sep 17 00:00:00 2001 From: Anton Todorov Date: Wed, 14 Feb 2024 11:21:35 +0200 Subject: [PATCH] ENABLE_ALT_CHANNELS option and changes to enable more than 230 channels rename *FREQ_* to *VFO_* - thinking in VFO context is less confusing --- Makefile | 4 + app/app.c | 2 +- app/chFrScanner.c | 2 +- app/dtmf.c | 2 +- app/main.c | 24 ++-- app/menu.c | 4 +- app/scanner.c | 4 +- driver/eeprom.c | 3 +- helper/boot.c | 2 +- main.c | 2 +- misc.c | 2 +- misc.h | 103 ++++++++++++++++- radio.c | 38 +++---- radio.h | 9 +- settings.c | 278 ++++++++++++++++++++++++++-------------------- settings.h | 19 ++-- ui/helper.c | 6 +- ui/helper.h | 5 +- ui/main.c | 6 +- 19 files changed, 325 insertions(+), 190 deletions(-) diff --git a/Makefile b/Makefile index c2202ce76..eb4699585 100644 --- a/Makefile +++ b/Makefile @@ -40,6 +40,7 @@ ENABLE_REDUCE_LOW_MID_TX_POWER?= 0 ENABLE_BYP_RAW_DEMODULATORS ?= 0 ENABLE_BLMIN_TMP_OFF ?= 0 ENABLE_SCAN_RANGES ?= 1 +ENABLE_ALT_CHANNELS ?= 0 # ---- DEBUGGING ---- ENABLE_AM_FIX_SHOW_DATA ?= 0 @@ -377,6 +378,9 @@ endif ifeq ($(ENABLE_CUSTOM_MENU_LAYOUT),1) CFLAGS += -DENABLE_CUSTOM_MENU_LAYOUT endif +ifeq ($(ENABLE_ALT_CHANNELS),1) + CFLAGS += -DENABLE_ALT_CHANNELS +endif LDFLAGS = LDFLAGS += -z noexecstack -mcpu=cortex-m0 -nostartfiles -Wl,-T,firmware.ld -Wl,--gc-sections diff --git a/app/app.c b/app/app.c index 23e93cb1d..cdb8eb5f9 100644 --- a/app/app.c +++ b/app/app.c @@ -246,7 +246,7 @@ static void HandleReceive(void) goto Skip; } - if (gScanStateDir != SCAN_OFF && IS_FREQ_CHANNEL(gNextMrChannel)) { // we are scanning in the frequency mode + if (gScanStateDir != SCAN_OFF && IS_VFO_CHANNEL(gNextMrChannel)) { // we are scanning in the frequency mode if (g_SquelchLost) return; diff --git a/app/chFrScanner.c b/app/chFrScanner.c index 4d7f8441c..685b1dc0c 100644 --- a/app/chFrScanner.c +++ b/app/chFrScanner.c @@ -69,7 +69,7 @@ void CHFRSCANNER_Start(const bool storeBackupSettings, const int8_t scan_directi void CHFRSCANNER_ContinueScanning(void) { - if (IS_FREQ_CHANNEL(gNextMrChannel)) + if (IS_VFO_CHANNEL(gNextMrChannel)) { if (gCurrentFunction == FUNCTION_INCOMING) APP_StartListening(gMonitor ? FUNCTION_MONITOR : FUNCTION_RECEIVE); diff --git a/app/dtmf.c b/app/dtmf.c index 252721aa8..0488d6969 100644 --- a/app/dtmf.c +++ b/app/dtmf.c @@ -139,7 +139,7 @@ bool DTMF_GetContact(const int Index, char *pContact) return false; } - EEPROM_ReadBuffer(0x1C00 + (Index * 16), pContact, 16); + EEPROM_ReadBuffer(EEPROM_DTMF_CONTACT_OFF + (Index * 16), pContact, 16); // check whether the first character is printable or not return (pContact[0] >= ' ' && pContact[0] < 127); diff --git a/app/main.c b/app/main.c index a0431ccfc..7e380f226 100644 --- a/app/main.c +++ b/app/main.c @@ -90,7 +90,7 @@ static void processFKeyFunction(const KEY_Code_t Key, const bool beep) break; case KEY_1: - if (!IS_FREQ_CHANNEL(gTxVfo->CHANNEL_SAVE)) { + if (!IS_VFO_CHANNEL(gTxVfo->CHANNEL_SAVE)) { gWasFKeyPressed = false; gUpdateStatus = true; gBeepToPlay = BEEP_1KHZ_60MS_OPTIONAL; @@ -115,7 +115,7 @@ static void processFKeyFunction(const KEY_Code_t Key, const bool beep) if (IS_MR_CHANNEL(gEeprom.ScreenChannel[vfo])) { // copy channel to VFO, then swap to the VFO - gEeprom.ScreenChannel[vfo] = FREQ_CHANNEL_FIRST + gEeprom.VfoInfo[vfo].Band; + gEeprom.ScreenChannel[vfo] = VFO_CHANNEL_FIRST + gEeprom.VfoInfo[vfo].Band; gEeprom.VfoInfo[vfo].CHANNEL_SAVE = gEeprom.ScreenChannel[vfo]; RADIO_SelectVfos(); @@ -147,8 +147,8 @@ static void processFKeyFunction(const KEY_Code_t Key, const bool beep) gTxVfo->Band = BAND1_50MHz; } - gEeprom.ScreenChannel[Vfo] = FREQ_CHANNEL_FIRST + gTxVfo->Band; - gEeprom.FreqChannel[Vfo] = FREQ_CHANNEL_FIRST + gTxVfo->Band; + gEeprom.ScreenChannel[Vfo] = VFO_CHANNEL_FIRST + gTxVfo->Band; + gEeprom.FreqChannel[Vfo] = VFO_CHANNEL_FIRST + gTxVfo->Band; gRequestSaveVFO = true; gVfoConfigureMode = VFO_CONFIGURE_RELOAD; @@ -325,7 +325,7 @@ static void MAIN_Key_DIGITS(KEY_Code_t Key, bool bKeyPressed, bool bKeyHeld) // #ifdef ENABLE_NOAA // if (!IS_NOAA_CHANNEL(gTxVfo->CHANNEL_SAVE)) // #endif - if (IS_FREQ_CHANNEL(gTxVfo->CHANNEL_SAVE)) + if (IS_VFO_CHANNEL(gTxVfo->CHANNEL_SAVE)) { // user is entering a frequency #ifdef ENABLE_VOICE @@ -355,8 +355,8 @@ static void MAIN_Key_DIGITS(KEY_Code_t Key, bool bKeyPressed, bool bKeyHeld) if (gTxVfo->Band != band) { gTxVfo->Band = band; - gEeprom.ScreenChannel[Vfo] = band + FREQ_CHANNEL_FIRST; - gEeprom.FreqChannel[Vfo] = band + FREQ_CHANNEL_FIRST; + gEeprom.ScreenChannel[Vfo] = band + VFO_CHANNEL_FIRST; + gEeprom.FreqChannel[Vfo] = band + VFO_CHANNEL_FIRST; SETTINGS_SaveVfoIndices(); @@ -600,14 +600,14 @@ static void MAIN_Key_STAR(bool bKeyPressed, bool bKeyHeld) static void MAIN_Key_UP_DOWN(bool bKeyPressed, bool bKeyHeld, int8_t Direction) { - uint8_t Channel = gEeprom.ScreenChannel[gEeprom.TX_VFO]; + channel_t Channel = gEeprom.ScreenChannel[gEeprom.TX_VFO]; if (bKeyHeld || !bKeyPressed) { // key held or released if (gInputBoxIndex > 0) return; // leave if input box active if (!bKeyPressed) { - if (!bKeyHeld || IS_FREQ_CHANNEL(Channel)) + if (!bKeyHeld || IS_VFO_CHANNEL(Channel)) return; // if released long button press and not in freq mode #ifdef ENABLE_VOICE @@ -630,8 +630,8 @@ static void MAIN_Key_UP_DOWN(bool bKeyPressed, bool bKeyHeld, int8_t Direction) if (!IS_NOAA_CHANNEL(Channel)) #endif { - uint8_t Next; - if (IS_FREQ_CHANNEL(Channel)) { // step/down in frequency + channel_t Next; + if (IS_VFO_CHANNEL(Channel)) { // step/down in frequency const uint32_t frequency = APP_SetFrequencyByStep(gTxVfo, Direction); if (RX_freq_check(frequency) < 0) { // frequency not allowed @@ -646,7 +646,7 @@ static void MAIN_Key_UP_DOWN(bool bKeyPressed, bool bKeyHeld, int8_t Direction) } Next = RADIO_FindNextChannel(Channel + Direction, Direction, false, 0); - if (Next == 0xFF) + if (Next == MAX_CHANNEL) return; if (Channel == Next) return; diff --git a/app/menu.c b/app/menu.c index 8dacadafe..23fb94d7c 100644 --- a/app/menu.c +++ b/app/menu.c @@ -395,7 +395,7 @@ void MENU_AcceptSetting(void) case MENU_STEP: gTxVfo->STEP_SETTING = FREQUENCY_GetStepIdxFromSortedIdx(gSubMenuSelection); - if (IS_FREQ_CHANNEL(gTxVfo->CHANNEL_SAVE)) + if (IS_VFO_CHANNEL(gTxVfo->CHANNEL_SAVE)) { gRequestSaveChannel = 1; return; @@ -1166,7 +1166,7 @@ void MENU_ShowCurrentSetting(void) static void MENU_Key_0_to_9(KEY_Code_t Key, bool bKeyPressed, bool bKeyHeld) { - uint8_t Offset; + channel_t Offset; int32_t Min; int32_t Max; uint16_t Value = 0; diff --git a/app/scanner.c b/app/scanner.c index 1bd0d552e..21c7d1f03 100644 --- a/app/scanner.c +++ b/app/scanner.c @@ -204,7 +204,7 @@ static void SCANNER_Key_MENU(bool bKeyPressed, bool bKeyHeld) gEeprom.MrChannel[gEeprom.TX_VFO] = chan; } else { - chan = gTxVfo->Band + FREQ_CHANNEL_FIRST; + chan = gTxVfo->Band + VFO_CHANNEL_FIRST; gEeprom.FreqChannel[gEeprom.TX_VFO] = chan; } @@ -310,7 +310,7 @@ void SCANNER_Start(bool singleFreq) #ifdef ENABLE_NOAA if (IS_NOAA_CHANNEL(gRxVfo->CHANNEL_SAVE)) - gRxVfo->CHANNEL_SAVE = FREQ_CHANNEL_FIRST + BAND6_400MHz; + gRxVfo->CHANNEL_SAVE = VFO_CHANNEL_FIRST + BAND6_400MHz; #endif uint8_t backupStep = gRxVfo->STEP_SETTING; diff --git a/driver/eeprom.c b/driver/eeprom.c index 07cca2ed1..c0ded4f4f 100644 --- a/driver/eeprom.c +++ b/driver/eeprom.c @@ -20,6 +20,7 @@ #include "driver/eeprom.h" #include "driver/i2c.h" #include "driver/system.h" +#include "misc.h" void EEPROM_ReadBuffer(uint16_t Address, void *pBuffer, uint8_t Size) { @@ -41,7 +42,7 @@ void EEPROM_ReadBuffer(uint16_t Address, void *pBuffer, uint8_t Size) void EEPROM_WriteBuffer(uint16_t Address, const void *pBuffer) { - if (pBuffer == NULL || Address >= 0x2000) + if (pBuffer == NULL || Address >= EEPROM_SIZE) return; diff --git a/helper/boot.c b/helper/boot.c index bb20dab9a..bf07ba020 100644 --- a/helper/boot.c +++ b/helper/boot.c @@ -86,7 +86,7 @@ void BOOT_ProcessMode(BOOT_Mode_t Mode) gEeprom.KEY_2_LONG_PRESS_ACTION = ACTION_OPT_NONE; gEeprom.KEY_M_LONG_PRESS_ACTION = ACTION_OPT_NONE; - RADIO_InitInfo(gRxVfo, FREQ_CHANNEL_LAST - 1, 41002500); + RADIO_InitInfo(gRxVfo, VFO_CHANNEL_LAST - 1, 41002500); gRxVfo->CHANNEL_BANDWIDTH = BANDWIDTH_WIDE; gRxVfo->OUTPUT_POWER = OUTPUT_POWER_LOW; diff --git a/main.c b/main.c index aa0366aa1..afa9598a7 100644 --- a/main.c +++ b/main.c @@ -207,7 +207,7 @@ void Main(void) AUDIO_SetVoiceID(1, VOICE_ID_CHANNEL_MODE); AUDIO_SetDigitVoice(2, Channel + 1); } - else if (IS_FREQ_CHANNEL(Channel)) + else if (IS_VFO_CHANNEL(Channel)) AUDIO_SetVoiceID(1, VOICE_ID_FREQUENCY_MODE); AUDIO_PlaySingleVoice(0); diff --git a/misc.c b/misc.c index 2a23c4b40..4c023cb45 100644 --- a/misc.c +++ b/misc.c @@ -113,7 +113,7 @@ uint16_t gEEPROM_RSSI_CALIB[7][4]; uint16_t gEEPROM_1F8A; uint16_t gEEPROM_1F8C; -ChannelAttributes_t gMR_ChannelAttributes[FREQ_CHANNEL_LAST + 1]; +ChannelAttributes_t gMR_ChannelAttributes[ALL_CHANNELS_COUNT]; volatile uint16_t gBatterySaveCountdown_10ms = battery_save_count_10ms; diff --git a/misc.h b/misc.h index 2ea627deb..01c61fe57 100644 --- a/misc.h +++ b/misc.h @@ -37,19 +37,114 @@ #endif #define IS_MR_CHANNEL(x) ((x) <= MR_CHANNEL_LAST) -#define IS_FREQ_CHANNEL(x) ((x) >= FREQ_CHANNEL_FIRST && (x) <= FREQ_CHANNEL_LAST) +#define IS_VFO_CHANNEL(x) ((x) >= VFO_CHANNEL_FIRST && (x) <= VFO_CHANNEL_LAST) #define IS_VALID_CHANNEL(x) ((x) < LAST_CHANNEL) #define IS_NOAA_CHANNEL(x) ((x) >= NOAA_CHANNEL_FIRST && (x) <= NOAA_CHANNEL_LAST) +#ifdef ENABLE_ALT_CHANNELS + typedef uint16_t channel_t; + + #define EEPROM_SIZE 0xFFFF //Exact size is 0x10000 but the ckecs are "gret or equal" so a bit off to fit in 2 bytes looks like ok + #define VFO_CHANNELS_COUNT 7 // VFO in each freq band is like a "system channel" + #define FM_CHANNELS_COUNT 20 // are these NOAA? no clue, but let's define them in a constant here + #define MR_CHANNELS_COUNT 999 + #define MAX_CHANNEL 0xffff // a mask defining ceil of two bytes + #define ALL_CHANNELS_COUNT (VFO_CHANNELS_COUNT + FM_CHANNELS_COUNT + MR_CHANNELS_COUNT) + + #define EEPROM_MR_FREQ_OFF 0x2000 // Start of the channel relocation + #define EEPROM_MR_FREQ_LEN (MR_CHANNELS_COUNT * 16) + + #define EEPROM_MR_ATTR_OFF (EEPROM_MR_FREQ_OFF + EEPROM_MR_FREQ_LEN) + #define EEPROM_MR_ATTR_LEN (MR_CHANNELS_COUNT) + + #define EEPROM_VFO_ATTR_OFF (EEPROM_MR_ATTR_OFF + EEPROM_MR_ATTR_LEN) + #define EEPROM_VFO_ATTR_LEN (VFO_CHANNELS_COUNT) + + #define EEPROM_MR_SETTINGS_OFF (EEPROM_VFO_ATTR_OFF + EEPROM_VFO_ATTR_LEN) // Screen CH A, MR CH A, Freq CH A, Screen CH B, MR CH B, Freq CH B, NOAA CH A, NOAA CH B + #define EEPROM_MR_SETTINGS_LEN 0x0010 + + #define EEPROM_MR_NAME_OFF (EEPROM_MR_SETTINGS_OFF + EEPROM_MR_SETTINGS_LEN) + #define EEPROM_MR_NAME_LEN (EEPROM_MR_FREQ_LEN) + #define EEPROM_LAST (EEPROM_MR_NAME_OFF + EEPROM_MR_NAME_LEN) + static const uint16_t MR_CHANNEL_FIRST = 0; + static const uint16_t MR_CHANNEL_LAST = (MR_CHANNELS_COUNT - 1); + static const uint16_t VFO_CHANNEL_FIRST = MR_CHANNELS_COUNT; + static const uint16_t VFO_CHANNEL_LAST = (MR_CHANNELS_COUNT + VFO_CHANNELS_COUNT - 1); + static const uint16_t NOAA_CHANNEL_FIRST = (MR_CHANNELS_COUNT + VFO_CHANNELS_COUNT); + static const uint16_t NOAA_CHANNEL_LAST = (MR_CHANNELS_COUNT + VFO_CHANNELS_COUNT + FM_CHANNELS_COUNT -1); + static const uint16_t LAST_CHANNEL = (MR_CHANNELS_COUNT + VFO_CHANNELS_COUNT + FM_CHANNELS_COUNT); +#else + typedef uint8_t channel_t; + + #define EEPROM_SIZE 0x2000 + #define VFO_CHANNELS_COUNT 7 + #define FM_CHANNELS_COUNT 20 + #define MR_CHANNELS_COUNT 200 + #define MAX_CHANNEL 0xff + #define ALL_CHANNELS_COUNT (VFO_CHANNELS_COUNT + FM_CHANNELS_COUNT + MR_CHANNELS_COUNT) + + #define EEPROM_MR_FREQ_OFF 0x0000 + #define EEPROM_MR_FREQ_LEN 0x0C80 + + #define EEPROM_MR_ATTR_OFF 0x0D60 + #define EEPROM_MR_ATTR_LEN 0x00C8 + + #define EEPROM_VFO_ATTR_OFF 0x0E28 + #define EEPROM_VFO_ATTR_LEN 0x0007 + + #define EEPROM_MR_SETTINGS_OFF 0x0E80 + #define EEPROM_MR_SETTINGS_LEN 0x0008 + + #define EEPROM_MR_NAME_OFF 0x0F50 + #define EEPROM_MR_NAME_LEN 0x0C80 +#endif // ENABLE_ALT_CHANNELS + +#define EEPROM_VFO_FREQ_OFF 0x0C80 +#define EEPROM_VFO_FREQ_LEN 0x00E0 + +#define EEPROM_FM_CHANNELS_OFF 0x0E40 +#define EEPROM_FM_CHANNELS_LEN 0x0028 + +#define EEPROM_OPTIONS_0E70_OFF 0x0E70 +#define EEPROM_OPTIONS_0E70_LEN 0x0008 + +#define EEPROM_OPTIONS_0E78_OFF 0x0E78 +#define EEPROM_OPTIONS_0E78_LEN 0x0008 + +#define EEPROM_FM_CH_SETTINGS_OFF 0x0E88 +#define EEPROM_FM_CH_SETTINGS_LEN 0x0003 + +#define EEPROM_WELCOME_STR1_OFF 0x0EB0 +#define EEPROM_WELCOME_STR1_LEN 0x0010 +#define EEPROM_WELCOME_STR2_OFF 0x0EC0 +#define EEPROM_WELCOME_STR2_LEN 0x0010 + +#define EEPROM_CODE_OPTIONS_OFF 0x0ED0 +#define EEPROM_CODE_OPTIONS_LEN 0x000B + +#define EEPROM_DTMF_ANI_ID_OFF 0x0EE0 +#define EEPROM_DTMF_ANI_ID_LEN 0x0038 + +#define EEPROM_SCAN_LIST_OFF 0x0F18 +#define EEPROM_SCAN_LIST_LEN 0x0018 + +#define EEPROM_AES_KEY_OFF 0x0F30 +#define EEPROM_AES_KEY_LEN 0x0010 + +#define EEPROM_DTMF_CONTACT_OFF 0x1C00 +#define EEPROM_DTMF_CONTACT_LEN 0x0100 + +#ifndef ENABLE_ALT_CHANNELS enum { MR_CHANNEL_FIRST = 0, MR_CHANNEL_LAST = 199u, - FREQ_CHANNEL_FIRST = 200u, - FREQ_CHANNEL_LAST = 206u, + VFO_CHANNEL_FIRST = 200u, + VFO_CHANNEL_LAST = 206u, NOAA_CHANNEL_FIRST = 207u, NOAA_CHANNEL_LAST = 216u, LAST_CHANNEL }; +#endif enum { VFO_CONFIGURE_NONE = 0, @@ -186,7 +281,7 @@ typedef union { uint8_t __val; } ChannelAttributes_t; -extern ChannelAttributes_t gMR_ChannelAttributes[207]; +extern ChannelAttributes_t gMR_ChannelAttributes[ALL_CHANNELS_COUNT]; extern volatile uint16_t gBatterySaveCountdown_10ms; diff --git a/radio.c b/radio.c index a7db68d48..8427c2575 100644 --- a/radio.c +++ b/radio.c @@ -56,7 +56,7 @@ const char gModulationStr[MODULATION_UKNOWN][4] = { -bool RADIO_CheckValidChannel(uint16_t channel, bool checkScanList, uint8_t scanList) +bool RADIO_CheckValidChannel(channel_t channel, bool checkScanList, uint8_t scanList) { // return true if the channel appears valid if (!IS_MR_CHANNEL(channel)) @@ -79,10 +79,10 @@ bool RADIO_CheckValidChannel(uint16_t channel, bool checkScanList, uint8_t scanL return PriorityCh1 != channel && PriorityCh2 != channel; } -uint8_t RADIO_FindNextChannel(uint8_t Channel, int8_t Direction, bool bCheckScanList, uint8_t VFO) +channel_t RADIO_FindNextChannel(channel_t Channel, int8_t Direction, bool bCheckScanList, uint8_t VFO) { for (unsigned int i = 0; IS_MR_CHANNEL(i); i++, Channel += Direction) { - if (Channel == 0xFF) { + if (Channel == MAX_CHANNEL) { Channel = MR_CHANNEL_LAST; } else if (!IS_MR_CHANNEL(Channel)) { Channel = MR_CHANNEL_FIRST; @@ -93,10 +93,10 @@ uint8_t RADIO_FindNextChannel(uint8_t Channel, int8_t Direction, bool bCheckScan } } - return 0xFF; + return MAX_CHANNEL; } -void RADIO_InitInfo(VFO_Info_t *pInfo, const uint8_t ChannelSave, const uint32_t Frequency) +void RADIO_InitInfo(VFO_Info_t *pInfo, const channel_t ChannelSave, const uint32_t Frequency) { memset(pInfo, 0, sizeof(*pInfo)); @@ -114,7 +114,7 @@ void RADIO_InitInfo(VFO_Info_t *pInfo, const uint8_t ChannelSave, const uint32_t pInfo->pTX = &pInfo->freq_config_TX; pInfo->Compander = 0; // off - if (ChannelSave == (FREQ_CHANNEL_FIRST + BAND2_108MHz)) + if (ChannelSave == (VFO_CHANNEL_FIRST + BAND2_108MHz)) pInfo->Modulation = MODULATION_AM; else pInfo->Modulation = MODULATION_FM; @@ -127,14 +127,14 @@ void RADIO_ConfigureChannel(const unsigned int VFO, const unsigned int configure VFO_Info_t *pVfo = &gEeprom.VfoInfo[VFO]; if (!gSetting_350EN) { - if (gEeprom.FreqChannel[VFO] == FREQ_CHANNEL_FIRST + BAND5_350MHz) - gEeprom.FreqChannel[VFO] = FREQ_CHANNEL_FIRST + BAND6_400MHz; + if (gEeprom.FreqChannel[VFO] == VFO_CHANNEL_FIRST + BAND5_350MHz) + gEeprom.FreqChannel[VFO] = VFO_CHANNEL_FIRST + BAND6_400MHz; - if (gEeprom.ScreenChannel[VFO] == FREQ_CHANNEL_FIRST + BAND5_350MHz) - gEeprom.ScreenChannel[VFO] = FREQ_CHANNEL_FIRST + BAND6_400MHz; + if (gEeprom.ScreenChannel[VFO] == VFO_CHANNEL_FIRST + BAND5_350MHz) + gEeprom.ScreenChannel[VFO] = VFO_CHANNEL_FIRST + BAND6_400MHz; } - uint8_t channel = gEeprom.ScreenChannel[VFO]; + channel_t channel = gEeprom.ScreenChannel[VFO]; if (IS_VALID_CHANNEL(channel)) { #ifdef ENABLE_NOAA @@ -154,7 +154,7 @@ void RADIO_ConfigureChannel(const unsigned int VFO, const unsigned int configure if (IS_MR_CHANNEL(channel)) { channel = RADIO_FindNextChannel(channel, RADIO_CHANNEL_UP, false, VFO); - if (channel == 0xFF) { + if (channel == MAX_CHANNEL) { channel = gEeprom.FreqChannel[VFO]; gEeprom.ScreenChannel[VFO] = gEeprom.FreqChannel[VFO]; } @@ -165,7 +165,7 @@ void RADIO_ConfigureChannel(const unsigned int VFO, const unsigned int configure } } else - channel = FREQ_CHANNEL_LAST - 1; + channel = VFO_CHANNEL_LAST - 1; ChannelAttributes_t att = gMR_ChannelAttributes[channel]; if (att.__val == 0xFF) { // invalid/unused channel @@ -174,7 +174,7 @@ void RADIO_ConfigureChannel(const unsigned int VFO, const unsigned int configure gEeprom.ScreenChannel[VFO] = channel; } - uint8_t bandIdx = channel - FREQ_CHANNEL_FIRST; + uint8_t bandIdx = channel - VFO_CHANNEL_FIRST; RADIO_InitInfo(pVfo, channel, frequencyBandTable[bandIdx].lower); return; } @@ -191,7 +191,7 @@ void RADIO_ConfigureChannel(const unsigned int VFO, const unsigned int configure bParticipation2 = att.scanlist2; } else { - band = channel - FREQ_CHANNEL_FIRST; + band = channel - VFO_CHANNEL_FIRST; bParticipation1 = true; bParticipation2 = true; } @@ -203,11 +203,11 @@ void RADIO_ConfigureChannel(const unsigned int VFO, const unsigned int configure uint16_t base; if (IS_MR_CHANNEL(channel)) - base = channel * 16; + base = EEPROM_MR_FREQ_OFF + channel * 16; else - base = 0x0C80 + ((channel - FREQ_CHANNEL_FIRST) * 32) + (VFO * 16); + base = EEPROM_VFO_FREQ_OFF + ((channel - VFO_CHANNEL_FIRST) * 32) + (VFO * 16); - if (configure == VFO_CONFIGURE_RELOAD || IS_FREQ_CHANNEL(channel)) + if (configure == VFO_CONFIGURE_RELOAD || IS_VFO_CHANNEL(channel)) { uint8_t tmp; uint8_t data[8]; @@ -344,7 +344,7 @@ void RADIO_ConfigureChannel(const unsigned int VFO, const unsigned int configure frequency = frequencyBandTable[band].lower; else if (frequency > frequencyBandTable[band].upper) frequency = frequencyBandTable[band].upper; - else if (channel >= FREQ_CHANNEL_FIRST) + else if (channel >= VFO_CHANNEL_FIRST) frequency = FREQUENCY_RoundToStep(frequency, pVfo->StepFrequency); pVfo->freq_config_RX.Frequency = frequency; diff --git a/radio.h b/radio.h index 1e1d94e70..6d2c89007 100644 --- a/radio.h +++ b/radio.h @@ -22,6 +22,7 @@ #include "dcs.h" #include "frequencies.h" +#include "misc.h" enum { RADIO_CHANNEL_UP = 0x01u, @@ -95,7 +96,7 @@ typedef struct VFO_Info_t uint32_t TX_OFFSET_FREQUENCY; uint16_t StepFrequency; - uint8_t CHANNEL_SAVE; + channel_t CHANNEL_SAVE; uint8_t TX_OFFSET_FREQUENCY_DIRECTION; @@ -148,9 +149,9 @@ extern DCS_CodeType_t gCurrentCodeType; extern VfoState_t VfoState[2]; -bool RADIO_CheckValidChannel(uint16_t channel, bool checkScanList, uint8_t scanList); -uint8_t RADIO_FindNextChannel(uint8_t ChNum, int8_t Direction, bool bCheckScanList, uint8_t RadioNum); -void RADIO_InitInfo(VFO_Info_t *pInfo, const uint8_t ChannelSave, const uint32_t Frequency); +bool RADIO_CheckValidChannel(channel_t channel, bool checkScanList, uint8_t scanList); +channel_t RADIO_FindNextChannel(channel_t ChNum, int8_t Direction, bool bCheckScanList, uint8_t RadioNum); +void RADIO_InitInfo(VFO_Info_t *pInfo, const channel_t ChannelSave, const uint32_t Frequency); void RADIO_ConfigureChannel(const unsigned int VFO, const unsigned int configure); void RADIO_ConfigureSquelchAndOutputPower(VFO_Info_t *pInfo); void RADIO_ApplyOffset(VFO_Info_t *pInfo); diff --git a/settings.c b/settings.c index 61c9c958c..51b7c199e 100644 --- a/settings.c +++ b/settings.c @@ -40,48 +40,63 @@ EEPROM_Config_t gEeprom = { 0 }; void SETTINGS_InitEEPROM(void) { - uint8_t Data[16] = {0}; + union { + uint8_t _8[16]; + uint16_t _16[8]; + } Data = {0}; // 0E70..0E77 - EEPROM_ReadBuffer(0x0E70, Data, 8); - gEeprom.CHAN_1_CALL = IS_MR_CHANNEL(Data[0]) ? Data[0] : MR_CHANNEL_FIRST; - gEeprom.SQUELCH_LEVEL = (Data[1] < 10) ? Data[1] : 1; - gEeprom.TX_TIMEOUT_TIMER = (Data[2] < 11) ? Data[2] : 1; + EEPROM_ReadBuffer(EEPROM_OPTIONS_0E70_OFF, Data._8, 8); + gEeprom.CHAN_1_CALL = IS_MR_CHANNEL(Data._8[0]) ? Data._8[0] : MR_CHANNEL_FIRST; + gEeprom.SQUELCH_LEVEL = (Data._8[1] < 10) ? Data._8[1] : 1; + gEeprom.TX_TIMEOUT_TIMER = (Data._8[2] < 11) ? Data._8[2] : 1; #ifdef ENABLE_NOAA - gEeprom.NOAA_AUTO_SCAN = (Data[3] < 2) ? Data[3] : false; + gEeprom.NOAA_AUTO_SCAN = (Data._8[3] < 2) ? Data._8[3] : false; #endif - gEeprom.KEY_LOCK = (Data[4] < 2) ? Data[4] : false; + gEeprom.KEY_LOCK = (Data._8[4] < 2) ? Data._8[4] : false; #ifdef ENABLE_VOX - gEeprom.VOX_SWITCH = (Data[5] < 2) ? Data[5] : false; - gEeprom.VOX_LEVEL = (Data[6] < 10) ? Data[6] : 1; + gEeprom.VOX_SWITCH = (Data._8[5] < 2) ? Data._8[5] : false; + gEeprom.VOX_LEVEL = (Data._8[6] < 10) ? Data._8[6] : 1; #endif - gEeprom.MIC_SENSITIVITY = (Data[7] < 5) ? Data[7] : 4; + gEeprom.MIC_SENSITIVITY = (Data._8[7] < 5) ? Data._8[7] : 4; // 0E78..0E7F - EEPROM_ReadBuffer(0x0E78, Data, 8); - gEeprom.BACKLIGHT_MAX = (Data[0] & 0xF) <= 10 ? (Data[0] & 0xF) : 10; - gEeprom.BACKLIGHT_MIN = (Data[0] >> 4) < gEeprom.BACKLIGHT_MAX ? (Data[0] >> 4) : 0; + EEPROM_ReadBuffer(EEPROM_OPTIONS_0E78_OFF, Data._8, 8); + gEeprom.BACKLIGHT_MAX = (Data._8[0] & 0xF) <= 10 ? (Data._8[0] & 0xF) : 10; + gEeprom.BACKLIGHT_MIN = (Data._8[0] >> 4) < gEeprom.BACKLIGHT_MAX ? (Data._8[0] >> 4) : 0; #ifdef ENABLE_BLMIN_TMP_OFF gEeprom.BACKLIGHT_MIN_STAT = BLMIN_STAT_ON; #endif - gEeprom.CHANNEL_DISPLAY_MODE = (Data[1] < 4) ? Data[1] : MDF_FREQUENCY; // 4 instead of 3 - extra display mode - gEeprom.CROSS_BAND_RX_TX = (Data[2] < 3) ? Data[2] : CROSS_BAND_OFF; - gEeprom.BATTERY_SAVE = (Data[3] < 5) ? Data[3] : 4; - gEeprom.DUAL_WATCH = (Data[4] < 3) ? Data[4] : DUAL_WATCH_CHAN_A; - gEeprom.BACKLIGHT_TIME = (Data[5] < ARRAY_SIZE(gSubMenu_BACKLIGHT)) ? Data[5] : 3; - gEeprom.TAIL_TONE_ELIMINATION = (Data[6] < 2) ? Data[6] : false; - gEeprom.VFO_OPEN = (Data[7] < 2) ? Data[7] : true; - + gEeprom.CHANNEL_DISPLAY_MODE = (Data._8[1] < 4) ? Data._8[1] : MDF_FREQUENCY; // 4 instead of 3 - extra display mode + gEeprom.CROSS_BAND_RX_TX = (Data._8[2] < 3) ? Data._8[2] : CROSS_BAND_OFF; + gEeprom.BATTERY_SAVE = (Data._8[3] < 5) ? Data._8[3] : 4; + gEeprom.DUAL_WATCH = (Data._8[4] < 3) ? Data._8[4] : DUAL_WATCH_CHAN_A; + gEeprom.BACKLIGHT_TIME = (Data._8[5] < ARRAY_SIZE(gSubMenu_BACKLIGHT)) ? Data._8[5] : 3; + gEeprom.TAIL_TONE_ELIMINATION = (Data._8[6] < 2) ? Data._8[6] : false; + gEeprom.VFO_OPEN = (Data._8[7] < 2) ? Data._8[7] : true; // 0E80..0E87 - EEPROM_ReadBuffer(0x0E80, Data, 8); - gEeprom.ScreenChannel[0] = IS_VALID_CHANNEL(Data[0]) ? Data[0] : (FREQ_CHANNEL_FIRST + BAND6_400MHz); - gEeprom.ScreenChannel[1] = IS_VALID_CHANNEL(Data[3]) ? Data[3] : (FREQ_CHANNEL_FIRST + BAND6_400MHz); - gEeprom.MrChannel[0] = IS_MR_CHANNEL(Data[1]) ? Data[1] : MR_CHANNEL_FIRST; - gEeprom.MrChannel[1] = IS_MR_CHANNEL(Data[4]) ? Data[4] : MR_CHANNEL_FIRST; - gEeprom.FreqChannel[0] = IS_FREQ_CHANNEL(Data[2]) ? Data[2] : (FREQ_CHANNEL_FIRST + BAND6_400MHz); - gEeprom.FreqChannel[1] = IS_FREQ_CHANNEL(Data[5]) ? Data[5] : (FREQ_CHANNEL_FIRST + BAND6_400MHz); + EEPROM_ReadBuffer(EEPROM_MR_SETTINGS_OFF, Data._8, 16); +#ifdef ENABLE_ALT_CHANNELS + gEeprom.ScreenChannel[0] = IS_VALID_CHANNEL(Data._16[0]) ? Data._16[0] : (VFO_CHANNEL_FIRST + BAND6_400MHz); + gEeprom.ScreenChannel[1] = IS_VALID_CHANNEL(Data._16[3]) ? Data._16[3] : (VFO_CHANNEL_FIRST + BAND6_400MHz); + gEeprom.MrChannel[0] = IS_MR_CHANNEL(Data._16[1]) ? Data._16[1] : MR_CHANNEL_FIRST; + gEeprom.MrChannel[1] = IS_MR_CHANNEL(Data._16[4]) ? Data._16[4] : MR_CHANNEL_FIRST; + gEeprom.FreqChannel[0] = IS_VFO_CHANNEL(Data._16[2]) ? Data._16[2] : (VFO_CHANNEL_FIRST + BAND6_400MHz); + gEeprom.FreqChannel[1] = IS_VFO_CHANNEL(Data._16[5]) ? Data._16[5] : (VFO_CHANNEL_FIRST + BAND6_400MHz); +#ifdef ENABLE_NOAA + gEeprom.NoaaChannel[0] = IS_NOAA_CHANNEL(Data._16[6]) ? Data._16[6] : NOAA_CHANNEL_FIRST; + gEeprom.NoaaChannel[1] = IS_NOAA_CHANNEL(Data._16[7]) ? Data._16[7] : NOAA_CHANNEL_FIRST; +#endif +#else + gEeprom.ScreenChannel[0] = IS_VALID_CHANNEL(Data._8[0]) ? Data._8[0] : (VFO_CHANNEL_FIRST + BAND6_400MHz); + gEeprom.ScreenChannel[1] = IS_VALID_CHANNEL(Data._8[3]) ? Data._8[3] : (VFO_CHANNEL_FIRST + BAND6_400MHz); + gEeprom.MrChannel[0] = IS_MR_CHANNEL(Data._8[1]) ? Data._8[1] : MR_CHANNEL_FIRST; + gEeprom.MrChannel[1] = IS_MR_CHANNEL(Data._8[4]) ? Data._8[4] : MR_CHANNEL_FIRST; + gEeprom.FreqChannel[0] = IS_VFO_CHANNEL(Data._8[2]) ? Data._8[2] : (VFO_CHANNEL_FIRST + BAND6_400MHz); + gEeprom.FreqChannel[1] = IS_VFO_CHANNEL(Data._8[5]) ? Data._8[5] : (VFO_CHANNEL_FIRST + BAND6_400MHz); #ifdef ENABLE_NOAA - gEeprom.NoaaChannel[0] = IS_NOAA_CHANNEL(Data[6]) ? Data[6] : NOAA_CHANNEL_FIRST; - gEeprom.NoaaChannel[1] = IS_NOAA_CHANNEL(Data[7]) ? Data[7] : NOAA_CHANNEL_FIRST; + gEeprom.NoaaChannel[0] = IS_NOAA_CHANNEL(Data._8[6]) ? Data._8[6] : NOAA_CHANNEL_FIRST; + gEeprom.NoaaChannel[1] = IS_NOAA_CHANNEL(Data._8[7]) ? Data._8[7] : NOAA_CHANNEL_FIRST; +#endif #endif #ifdef ENABLE_FMRADIO @@ -94,7 +109,7 @@ void SETTINGS_InitEEPROM(void) uint8_t band:2; //uint8_t space:2; } __attribute__((packed)) fmCfg; - EEPROM_ReadBuffer(0x0E88, &fmCfg, 4); + EEPROM_ReadBuffer(EEPROM_FM_CH_SETTINGS_OFF, &fmCfg, 4); gEeprom.FM_Band = fmCfg.band; //gEeprom.FM_Space = fmCfg.space; @@ -112,30 +127,30 @@ void SETTINGS_InitEEPROM(void) #endif // 0E90..0E97 - EEPROM_ReadBuffer(0x0E90, Data, 8); - gEeprom.BEEP_CONTROL = Data[0] & 1; - gEeprom.KEY_M_LONG_PRESS_ACTION = ((Data[0] >> 1) < ACTION_OPT_LEN) ? (Data[0] >> 1) : ACTION_OPT_NONE; - gEeprom.KEY_1_SHORT_PRESS_ACTION = (Data[1] < ACTION_OPT_LEN) ? Data[1] : ACTION_OPT_MONITOR; - gEeprom.KEY_1_LONG_PRESS_ACTION = (Data[2] < ACTION_OPT_LEN) ? Data[2] : ACTION_OPT_NONE; - gEeprom.KEY_2_SHORT_PRESS_ACTION = (Data[3] < ACTION_OPT_LEN) ? Data[3] : ACTION_OPT_SCAN; - gEeprom.KEY_2_LONG_PRESS_ACTION = (Data[4] < ACTION_OPT_LEN) ? Data[4] : ACTION_OPT_NONE; - gEeprom.SCAN_RESUME_MODE = (Data[5] < 3) ? Data[5] : SCAN_RESUME_CO; - gEeprom.AUTO_KEYPAD_LOCK = (Data[6] < 2) ? Data[6] : false; - gEeprom.POWER_ON_DISPLAY_MODE = (Data[7] < 4) ? Data[7] : POWER_ON_DISPLAY_MODE_VOLTAGE; + EEPROM_ReadBuffer(0x0E90, Data._8, 8); + gEeprom.BEEP_CONTROL = Data._8[0] & 1; + gEeprom.KEY_M_LONG_PRESS_ACTION = ((Data._8[0] >> 1) < ACTION_OPT_LEN) ? (Data._8[0] >> 1) : ACTION_OPT_NONE; + gEeprom.KEY_1_SHORT_PRESS_ACTION = (Data._8[1] < ACTION_OPT_LEN) ? Data._8[1] : ACTION_OPT_MONITOR; + gEeprom.KEY_1_LONG_PRESS_ACTION = (Data._8[2] < ACTION_OPT_LEN) ? Data._8[2] : ACTION_OPT_NONE; + gEeprom.KEY_2_SHORT_PRESS_ACTION = (Data._8[3] < ACTION_OPT_LEN) ? Data._8[3] : ACTION_OPT_SCAN; + gEeprom.KEY_2_LONG_PRESS_ACTION = (Data._8[4] < ACTION_OPT_LEN) ? Data._8[4] : ACTION_OPT_NONE; + gEeprom.SCAN_RESUME_MODE = (Data._8[5] < 3) ? Data._8[5] : SCAN_RESUME_CO; + gEeprom.AUTO_KEYPAD_LOCK = (Data._8[6] < 2) ? Data._8[6] : false; + gEeprom.POWER_ON_DISPLAY_MODE = (Data._8[7] < 4) ? Data._8[7] : POWER_ON_DISPLAY_MODE_VOLTAGE; // 0E98..0E9F - EEPROM_ReadBuffer(0x0E98, Data, 8); - memcpy(&gEeprom.POWER_ON_PASSWORD, Data, 4); + EEPROM_ReadBuffer(0x0E98, Data._8, 8); + memcpy(&gEeprom.POWER_ON_PASSWORD, Data._8, 4); // 0EA0..0EA7 - EEPROM_ReadBuffer(0x0EA0, Data, 8); + EEPROM_ReadBuffer(0x0EA0, Data._8, 8); #ifdef ENABLE_VOICE - gEeprom.VOICE_PROMPT = (Data[0] < 3) ? Data[0] : VOICE_PROMPT_ENGLISH; + gEeprom.VOICE_PROMPT = (Data._8[0] < 3) ? Data._8[0] : VOICE_PROMPT_ENGLISH; #endif #ifdef ENABLE_RSSI_BAR - if((Data[1] < 200 && Data[1] > 90) && (Data[2] < Data[1]-9 && Data[1] < 160 && Data[2] > 50)) { - gEeprom.S0_LEVEL = Data[1]; - gEeprom.S9_LEVEL = Data[2]; + if((Data._8[1] < 200 && Data._8[1] > 90) && (Data._8[2] < Data._8[1]-9 && Data._8[1] < 160 && Data._8[2] > 50)) { + gEeprom.S0_LEVEL = Data._8[1]; + gEeprom.S9_LEVEL = Data._8[2]; } else { gEeprom.S0_LEVEL = 130; @@ -144,111 +159,111 @@ void SETTINGS_InitEEPROM(void) #endif // 0EA8..0EAF - EEPROM_ReadBuffer(0x0EA8, Data, 8); + EEPROM_ReadBuffer(0x0EA8, Data._8, 8); #ifdef ENABLE_ALARM - gEeprom.ALARM_MODE = (Data[0] < 2) ? Data[0] : true; + gEeprom.ALARM_MODE = (Data._8[0] < 2) ? Data._8[0] : true; #endif - gEeprom.ROGER = (Data[1] < 3) ? Data[1] : ROGER_MODE_OFF; - gEeprom.REPEATER_TAIL_TONE_ELIMINATION = (Data[2] < 11) ? Data[2] : 0; - gEeprom.TX_VFO = (Data[3] < 2) ? Data[3] : 0; - gEeprom.BATTERY_TYPE = (Data[4] < BATTERY_TYPE_UNKNOWN) ? Data[4] : BATTERY_TYPE_1600_MAH; + gEeprom.ROGER = (Data._8[1] < 3) ? Data._8[1] : ROGER_MODE_OFF; + gEeprom.REPEATER_TAIL_TONE_ELIMINATION = (Data._8[2] < 11) ? Data._8[2] : 0; + gEeprom.TX_VFO = (Data._8[3] < 2) ? Data._8[3] : 0; + gEeprom.BATTERY_TYPE = (Data._8[4] < BATTERY_TYPE_UNKNOWN) ? Data._8[4] : BATTERY_TYPE_1600_MAH; // 0ED0..0ED7 - EEPROM_ReadBuffer(0x0ED0, Data, 8); - gEeprom.DTMF_SIDE_TONE = (Data[0] < 2) ? Data[0] : true; + EEPROM_ReadBuffer(0x0ED0, Data._8, 8); + gEeprom.DTMF_SIDE_TONE = (Data._8[0] < 2) ? Data._8[0] : true; #ifdef ENABLE_DTMF_CALLING - gEeprom.DTMF_SEPARATE_CODE = DTMF_ValidateCodes((char *)(Data + 1), 1) ? Data[1] : '*'; - gEeprom.DTMF_GROUP_CALL_CODE = DTMF_ValidateCodes((char *)(Data + 2), 1) ? Data[2] : '#'; - gEeprom.DTMF_DECODE_RESPONSE = (Data[3] < 4) ? Data[3] : 0; - gEeprom.DTMF_auto_reset_time = (Data[4] < 61 && Data[4] >= 5) ? Data[4] : 10; + gEeprom.DTMF_SEPARATE_CODE = DTMF_ValidateCodes((char *)(Data._8 + 1), 1) ? Data._8[1] : '*'; + gEeprom.DTMF_GROUP_CALL_CODE = DTMF_ValidateCodes((char *)(Data._8 + 2), 1) ? Data._8[2] : '#'; + gEeprom.DTMF_DECODE_RESPONSE = (Data._8[3] < 4) ? Data._8[3] : 0; + gEeprom.DTMF_auto_reset_time = (Data._8[4] < 61 && Data._8[4] >= 5) ? Data._8[4] : 10; #endif - gEeprom.DTMF_PRELOAD_TIME = (Data[5] < 101) ? Data[5] * 10 : 300; - gEeprom.DTMF_FIRST_CODE_PERSIST_TIME = (Data[6] < 101) ? Data[6] * 10 : 100; - gEeprom.DTMF_HASH_CODE_PERSIST_TIME = (Data[7] < 101) ? Data[7] * 10 : 100; + gEeprom.DTMF_PRELOAD_TIME = (Data._8[5] < 101) ? Data._8[5] * 10 : 300; + gEeprom.DTMF_FIRST_CODE_PERSIST_TIME = (Data._8[6] < 101) ? Data._8[6] * 10 : 100; + gEeprom.DTMF_HASH_CODE_PERSIST_TIME = (Data._8[7] < 101) ? Data._8[7] * 10 : 100; // 0ED8..0EDF - EEPROM_ReadBuffer(0x0ED8, Data, 8); - gEeprom.DTMF_CODE_PERSIST_TIME = (Data[0] < 101) ? Data[0] * 10 : 100; - gEeprom.DTMF_CODE_INTERVAL_TIME = (Data[1] < 101) ? Data[1] * 10 : 100; + EEPROM_ReadBuffer(0x0ED8, Data._8, 8); + gEeprom.DTMF_CODE_PERSIST_TIME = (Data._8[0] < 101) ? Data._8[0] * 10 : 100; + gEeprom.DTMF_CODE_INTERVAL_TIME = (Data._8[1] < 101) ? Data._8[1] * 10 : 100; #ifdef ENABLE_DTMF_CALLING - gEeprom.PERMIT_REMOTE_KILL = (Data[2] < 2) ? Data[2] : true; + gEeprom.PERMIT_REMOTE_KILL = (Data._8[2] < 2) ? Data._8[2] : true; // 0EE0..0EE7 - EEPROM_ReadBuffer(0x0EE0, Data, sizeof(gEeprom.ANI_DTMF_ID)); - if (DTMF_ValidateCodes((char *)Data, sizeof(gEeprom.ANI_DTMF_ID))) { - memcpy(gEeprom.ANI_DTMF_ID, Data, sizeof(gEeprom.ANI_DTMF_ID)); + EEPROM_ReadBuffer(0x0EE0, Data._8, sizeof(gEeprom.ANI_DTMF_ID)); + if (DTMF_ValidateCodes((char *)Data._8, sizeof(gEeprom.ANI_DTMF_ID))) { + memcpy(gEeprom.ANI_DTMF_ID, Data._8, sizeof(gEeprom.ANI_DTMF_ID)); } else { strcpy(gEeprom.ANI_DTMF_ID, "123"); } // 0EE8..0EEF - EEPROM_ReadBuffer(0x0EE8, Data, sizeof(gEeprom.KILL_CODE)); - if (DTMF_ValidateCodes((char *)Data, sizeof(gEeprom.KILL_CODE))) { - memcpy(gEeprom.KILL_CODE, Data, sizeof(gEeprom.KILL_CODE)); + EEPROM_ReadBuffer(0x0EE8, Data._8, sizeof(gEeprom.KILL_CODE)); + if (DTMF_ValidateCodes((char *)Data._8, sizeof(gEeprom.KILL_CODE))) { + memcpy(gEeprom.KILL_CODE, Data._8, sizeof(gEeprom.KILL_CODE)); } else { strcpy(gEeprom.KILL_CODE, "ABCD9"); } // 0EF0..0EF7 - EEPROM_ReadBuffer(0x0EF0, Data, sizeof(gEeprom.REVIVE_CODE)); - if (DTMF_ValidateCodes((char *)Data, sizeof(gEeprom.REVIVE_CODE))) { - memcpy(gEeprom.REVIVE_CODE, Data, sizeof(gEeprom.REVIVE_CODE)); + EEPROM_ReadBuffer(0x0EF0, Data._8, sizeof(gEeprom.REVIVE_CODE)); + if (DTMF_ValidateCodes((char *)Data._8, sizeof(gEeprom.REVIVE_CODE))) { + memcpy(gEeprom.REVIVE_CODE, Data._8, sizeof(gEeprom.REVIVE_CODE)); } else { strcpy(gEeprom.REVIVE_CODE, "9DCBA"); } #endif // 0EF8..0F07 - EEPROM_ReadBuffer(0x0EF8, Data, sizeof(gEeprom.DTMF_UP_CODE)); - if (DTMF_ValidateCodes((char *)Data, sizeof(gEeprom.DTMF_UP_CODE))) { - memcpy(gEeprom.DTMF_UP_CODE, Data, sizeof(gEeprom.DTMF_UP_CODE)); + EEPROM_ReadBuffer(0x0EF8, Data._8, sizeof(gEeprom.DTMF_UP_CODE)); + if (DTMF_ValidateCodes((char *)Data._8, sizeof(gEeprom.DTMF_UP_CODE))) { + memcpy(gEeprom.DTMF_UP_CODE, Data._8, sizeof(gEeprom.DTMF_UP_CODE)); } else { strcpy(gEeprom.DTMF_UP_CODE, "12345"); } // 0F08..0F17 - EEPROM_ReadBuffer(0x0F08, Data, sizeof(gEeprom.DTMF_DOWN_CODE)); - if (DTMF_ValidateCodes((char *)Data, sizeof(gEeprom.DTMF_DOWN_CODE))) { - memcpy(gEeprom.DTMF_DOWN_CODE, Data, sizeof(gEeprom.DTMF_DOWN_CODE)); + EEPROM_ReadBuffer(0x0F08, Data._8, sizeof(gEeprom.DTMF_DOWN_CODE)); + if (DTMF_ValidateCodes((char *)Data._8, sizeof(gEeprom.DTMF_DOWN_CODE))) { + memcpy(gEeprom.DTMF_DOWN_CODE, Data._8, sizeof(gEeprom.DTMF_DOWN_CODE)); } else { strcpy(gEeprom.DTMF_DOWN_CODE, "54321"); } // 0F18..0F1F - EEPROM_ReadBuffer(0x0F18, Data, 8); - gEeprom.SCAN_LIST_DEFAULT = (Data[0] < 3) ? Data[0] : 0; // we now have 'all' channel scan option + EEPROM_ReadBuffer(0x0F18, Data._8, 8); + gEeprom.SCAN_LIST_DEFAULT = (Data._8[0] < 3) ? Data._8[0] : 0; // we now have 'all' channel scan option for (unsigned int i = 0; i < 2; i++) { const unsigned int j = 1 + (i * 3); - gEeprom.SCAN_LIST_ENABLED[i] = (Data[j + 0] < 2) ? Data[j] : false; - gEeprom.SCANLIST_PRIORITY_CH1[i] = Data[j + 1]; - gEeprom.SCANLIST_PRIORITY_CH2[i] = Data[j + 2]; + gEeprom.SCAN_LIST_ENABLED[i] = (Data._8[j + 0] < 2) ? Data._8[j] : false; + gEeprom.SCANLIST_PRIORITY_CH1[i] = Data._8[j + 1]; + gEeprom.SCANLIST_PRIORITY_CH2[i] = Data._8[j + 2]; } // 0F40..0F47 - EEPROM_ReadBuffer(0x0F40, Data, 8); - gSetting_F_LOCK = (Data[0] < F_LOCK_LEN) ? Data[0] : F_LOCK_DEF; - gSetting_350TX = (Data[1] < 2) ? Data[1] : false; // was true + EEPROM_ReadBuffer(0x0F40, Data._8, 8); + gSetting_F_LOCK = (Data._8[0] < F_LOCK_LEN) ? Data._8[0] : F_LOCK_DEF; + gSetting_350TX = (Data._8[1] < 2) ? Data._8[1] : false; // was true #ifdef ENABLE_DTMF_CALLING - gSetting_KILLED = (Data[2] < 2) ? Data[2] : false; -#endif - gSetting_200TX = (Data[3] < 2) ? Data[3] : false; - gSetting_500TX = (Data[4] < 2) ? Data[4] : false; - gSetting_350EN = (Data[5] < 2) ? Data[5] : true; - gSetting_ScrambleEnable = (Data[6] < 2) ? Data[6] : true; - //gSetting_TX_EN = (Data[7] & (1u << 0)) ? true : false; - gSetting_live_DTMF_decoder = !!(Data[7] & (1u << 1)); - gSetting_battery_text = (((Data[7] >> 2) & 3u) <= 2) ? (Data[7] >> 2) & 3 : 2; + gSetting_KILLED = (Data._8[2] < 2) ? Data._8[2] : false; +#endif + gSetting_200TX = (Data._8[3] < 2) ? Data._8[3] : false; + gSetting_500TX = (Data._8[4] < 2) ? Data._8[4] : false; + gSetting_350EN = (Data._8[5] < 2) ? Data._8[5] : true; + gSetting_ScrambleEnable = (Data._8[6] < 2) ? Data._8[6] : true; + //gSetting_TX_EN = (Data._8[7] & (1u << 0)) ? true : false; + gSetting_live_DTMF_decoder = !!(Data._8[7] & (1u << 1)); + gSetting_battery_text = (((Data._8[7] >> 2) & 3u) <= 2) ? (Data._8[7] >> 2) & 3 : 2; #ifdef ENABLE_AUDIO_BAR - gSetting_mic_bar = !!(Data[7] & (1u << 4)); + gSetting_mic_bar = !!(Data._8[7] & (1u << 4)); #endif #ifdef ENABLE_AM_FIX - gSetting_AM_fix = !!(Data[7] & (1u << 5)); + gSetting_AM_fix = !!(Data._8[7] & (1u << 5)); #endif - gSetting_backlight_on_tx_rx = (Data[7] >> 6) & 3u; + gSetting_backlight_on_tx_rx = (Data._8[7] >> 6) & 3u; if (!gEeprom.VFO_OPEN) { @@ -257,7 +272,19 @@ void SETTINGS_InitEEPROM(void) } // 0D60..0E27 - EEPROM_ReadBuffer(0x0D60, gMR_ChannelAttributes, sizeof(gMR_ChannelAttributes)); +#ifndef ENABLE_ALT_CHANNELS + EEPROM_ReadBuffer(0x0D60, gMR_ChannelAttributes, sizeof(gMR_ChannelAttributes)); +#else + #define _CHUNKSIZE 64 + channel_t channel = 0; + for( uint16_t i = 0 ; i < ALL_CHANNELS_COUNT / _CHUNKSIZE; i++) { + EEPROM_ReadBuffer(EEPROM_MR_ATTR_OFF + channel, &gMR_ChannelAttributes[channel], _CHUNKSIZE); + channel += _CHUNKSIZE; + } + if (ALL_CHANNELS_COUNT - channel > 0){ + EEPROM_ReadBuffer(EEPROM_MR_ATTR_OFF + channel, &gMR_ChannelAttributes[channel], ALL_CHANNELS_COUNT - channel); + } +#endif for(uint16_t i = 0; i < sizeof(gMR_ChannelAttributes); i++) { ChannelAttributes_t *att = &gMR_ChannelAttributes[i]; if(att->__val == 0xff){ @@ -265,7 +292,6 @@ void SETTINGS_InitEEPROM(void) att->band = 0xf; } } - // 0F30..0F3F EEPROM_ReadBuffer(0x0F30, gCustomAesKey, sizeof(gCustomAesKey)); bHasCustomAesKey = false; @@ -342,7 +368,7 @@ uint32_t SETTINGS_FetchChannelFrequency(const int channel) uint32_t offset; } __attribute__((packed)) info; - EEPROM_ReadBuffer(channel * 16, &info, sizeof(info)); + EEPROM_ReadBuffer(EEPROM_MR_FREQ_OFF + channel * 16, &info, sizeof(info)); return info.frequency; } @@ -360,7 +386,7 @@ void SETTINGS_FetchChannelName(char *s, const int channel) if (!RADIO_CheckValidChannel(channel, false, 0)) return; - EEPROM_ReadBuffer(0x0F50 + (channel * 16), s, 10); + EEPROM_ReadBuffer(EEPROM_MR_NAME_OFF + channel * 16, s, 10); int i; for (i = 0; i < 10; i++) @@ -402,9 +428,15 @@ void SETTINGS_FactoryReset(bool bIsAll) } } +#ifdef ENABLE_ALT_CHANNELS + for (i = EEPROM_MR_FREQ_OFF; i < EEPROM_LAST; i +=8) + { + EEPROM_WriteBuffer(i, Template); + } +#endif if (bIsAll) { - RADIO_InitInfo(gRxVfo, FREQ_CHANNEL_FIRST + BAND6_400MHz, 43350000); + RADIO_InitInfo(gRxVfo, VFO_CHANNEL_FIRST + BAND6_400MHz, 43350000); // set the first few memory channels for (i = 0; i < ARRAY_SIZE(gDefaultFrequencyTable); i++) @@ -438,19 +470,19 @@ void SETTINGS_SaveFM(void) fmCfg.isMrMode = gEeprom.FM_IsMrMode; fmCfg.band = gEeprom.FM_Band; //fmCfg.space = gEeprom.FM_Space; - EEPROM_WriteBuffer(0x0E88, fmCfg.__raw); + EEPROM_WriteBuffer(EEPROM_FM_CH_SETTINGS_OFF, fmCfg.__raw); for (unsigned i = 0; i < 5; i++) - EEPROM_WriteBuffer(0x0E40 + (i * 8), &gFM_Channels[i * 4]); + EEPROM_WriteBuffer(EEPROM_FM_CHANNELS_OFF + (i * 8), &gFM_Channels[i * 4]); } #endif void SETTINGS_SaveVfoIndices(void) { - uint8_t State[8]; + channel_t State[8]; #ifndef ENABLE_NOAA - EEPROM_ReadBuffer(0x0E80, State, sizeof(State)); + EEPROM_ReadBuffer(EEPROM_MR_SETTINGS_OFF, State, sizeof(State)); #endif State[0] = gEeprom.ScreenChannel[0]; @@ -464,7 +496,7 @@ void SETTINGS_SaveVfoIndices(void) State[7] = gEeprom.NoaaChannel[1]; #endif - EEPROM_WriteBuffer(0x0E80, State); + EEPROM_WriteBuffer(EEPROM_MR_SETTINGS_OFF, State); } void SETTINGS_SaveSettings(void) @@ -489,7 +521,7 @@ void SETTINGS_SaveSettings(void) State[6] = 0; #endif State[7] = gEeprom.MIC_SENSITIVITY; - EEPROM_WriteBuffer(0x0E70, State); + EEPROM_WriteBuffer(EEPROM_OPTIONS_0E70_OFF, State); State[0] = (gEeprom.BACKLIGHT_MIN << 4) + gEeprom.BACKLIGHT_MAX; State[1] = gEeprom.CHANNEL_DISPLAY_MODE; @@ -594,21 +626,21 @@ void SETTINGS_SaveSettings(void) EEPROM_WriteBuffer(0x0F40, State); } -void SETTINGS_SaveChannel(uint8_t Channel, uint8_t VFO, const VFO_Info_t *pVFO, uint8_t Mode) +void SETTINGS_SaveChannel(channel_t Channel, uint8_t VFO, const VFO_Info_t *pVFO, uint8_t Mode) { #ifdef ENABLE_NOAA if (IS_NOAA_CHANNEL(Channel)) return; #endif - uint16_t OffsetVFO = Channel * 16; + uint16_t OffsetVFO = EEPROM_MR_FREQ_OFF + Channel * 16; - if (IS_FREQ_CHANNEL(Channel)) { // it's a VFO, not a channel + if (IS_VFO_CHANNEL(Channel)) { // it's a VFO, not a channel OffsetVFO = (VFO == 0) ? 0x0C80 : 0x0C90; - OffsetVFO += (Channel - FREQ_CHANNEL_FIRST) * 32; + OffsetVFO += (Channel - VFO_CHANNEL_FIRST) * 32; } - if (Mode >= 2 || IS_FREQ_CHANNEL(Channel)) { // copy VFO to a channel + if (Mode >= 2 || IS_VFO_CHANNEL(Channel)) { // copy VFO to a channel union { uint8_t _8[8]; uint32_t _32[2]; @@ -662,16 +694,16 @@ void SETTINGS_SaveBatteryCalibration(const uint16_t * batteryCalibration) EEPROM_WriteBuffer(0x1F48, buf); } -void SETTINGS_SaveChannelName(uint8_t channel, const char * name) +void SETTINGS_SaveChannelName(channel_t channel, const char * name) { uint16_t offset = channel * 16; uint8_t buf[16] = {0}; memcpy(buf, name, MIN(strlen(name), 10u)); - EEPROM_WriteBuffer(0x0F50 + offset, buf); - EEPROM_WriteBuffer(0x0F58 + offset, buf + 8); + EEPROM_WriteBuffer(EEPROM_MR_NAME_OFF + offset, buf); + EEPROM_WriteBuffer(EEPROM_MR_NAME_OFF + 8 + offset, buf + 8); } -void SETTINGS_UpdateChannel(uint8_t channel, const VFO_Info_t *pVFO, bool keep) +void SETTINGS_UpdateChannel(channel_t channel, const VFO_Info_t *pVFO, bool keep) { #ifdef ENABLE_NOAA if (!IS_NOAA_CHANNEL(channel)) @@ -685,7 +717,7 @@ void SETTINGS_UpdateChannel(uint8_t channel, const VFO_Info_t *pVFO, bool keep) .scanlist2 = 0, }; // default attributes - uint16_t offset = 0x0D60 + (channel & ~7u); + uint16_t offset = EEPROM_MR_ATTR_OFF + (channel & ~7u); EEPROM_ReadBuffer(offset, state, sizeof(state)); if (keep) { diff --git a/settings.h b/settings.h index eadf2fe2f..3c035fc87 100644 --- a/settings.h +++ b/settings.h @@ -24,6 +24,7 @@ #include #include "radio.h" #include +#include "misc.h" enum POWER_OnDisplayMode_t { POWER_ON_DISPLAY_MODE_FULL_SCREEN = 0, @@ -125,9 +126,9 @@ enum CHANNEL_DisplayMode_t { typedef enum CHANNEL_DisplayMode_t CHANNEL_DisplayMode_t; typedef struct { - uint8_t ScreenChannel[2]; // current channels set in the radio (memory or frequency channels) - uint8_t FreqChannel[2]; // last frequency channels used - uint8_t MrChannel[2]; // last memory channels used + channel_t ScreenChannel[2]; // current channels set in the radio (memory or frequency channels) + channel_t FreqChannel[2]; // last frequency channels used + channel_t MrChannel[2]; // last memory channels used #ifdef ENABLE_NOAA uint8_t NoaaChannel[2]; #endif @@ -171,8 +172,8 @@ typedef struct { uint8_t SCAN_RESUME_MODE; uint8_t SCAN_LIST_DEFAULT; bool SCAN_LIST_ENABLED[2]; - uint8_t SCANLIST_PRIORITY_CH1[2]; - uint8_t SCANLIST_PRIORITY_CH2[2]; + channel_t SCANLIST_PRIORITY_CH1[2]; + channel_t SCANLIST_PRIORITY_CH2[2]; uint8_t field29_0x26; uint8_t field30_0x27; @@ -193,7 +194,7 @@ typedef struct { uint8_t KEY_2_LONG_PRESS_ACTION; uint8_t MIC_SENSITIVITY; uint8_t MIC_SENSITIVITY_TUNING; - uint8_t CHAN_1_CALL; + channel_t CHAN_1_CALL; #ifdef ENABLE_DTMF_CALLING char ANI_DTMF_ID[8]; char KILL_CODE[8]; @@ -265,10 +266,10 @@ void SETTINGS_FactoryReset(bool bIsAll); #endif void SETTINGS_SaveVfoIndices(void); void SETTINGS_SaveSettings(void); -void SETTINGS_SaveChannelName(uint8_t channel, const char * name); -void SETTINGS_SaveChannel(uint8_t Channel, uint8_t VFO, const VFO_Info_t *pVFO, uint8_t Mode); +void SETTINGS_SaveChannelName(channel_t channel, const char * name); +void SETTINGS_SaveChannel(channel_t Channel, uint8_t VFO, const VFO_Info_t *pVFO, uint8_t Mode); +void SETTINGS_UpdateChannel(channel_t channel, const VFO_Info_t *pVFO, bool keep); void SETTINGS_SaveBatteryCalibration(const uint16_t * batteryCalibration); -void SETTINGS_UpdateChannel(uint8_t channel, const VFO_Info_t *pVFO, bool keep); void SETTINGS_WriteBuildOptions(void); #endif diff --git a/ui/helper.c b/ui/helper.c index 63bf58199..fac930ca6 100644 --- a/ui/helper.c +++ b/ui/helper.c @@ -27,7 +27,7 @@ #define ARRAY_SIZE(arr) (sizeof(arr)/sizeof((arr)[0])) #endif -void UI_GenerateChannelString(char *pString, const uint8_t Channel) +void UI_GenerateChannelString(char *pString, const channel_t Channel) { unsigned int i; @@ -44,7 +44,7 @@ void UI_GenerateChannelString(char *pString, const uint8_t Channel) pString[i + 3] = (gInputBox[i] == 10) ? '-' : gInputBox[i] + '0'; } -void UI_GenerateChannelStringEx(char *pString, const bool bShowPrefix, const uint8_t ChannelNumber) +void UI_GenerateChannelStringEx(char *pString, const bool bShowPrefix, const channel_t ChannelNumber) { if (gInputBoxIndex > 0) { for (unsigned int i = 0; i < 3; i++) { @@ -58,7 +58,7 @@ void UI_GenerateChannelStringEx(char *pString, const bool bShowPrefix, const uin if (bShowPrefix) { // BUG here? Prefixed NULLs are allowed sprintf(pString, "CH-%03u", ChannelNumber + 1); - } else if (ChannelNumber == 0xFF) { + } else if (ChannelNumber == MAX_CHANNEL) { strcpy(pString, "NULL"); } else { sprintf(pString, "%03u", ChannelNumber + 1); diff --git a/ui/helper.h b/ui/helper.h index 8401a9b3e..2b028e7ea 100644 --- a/ui/helper.h +++ b/ui/helper.h @@ -19,9 +19,10 @@ #include #include +#include "misc.h" -void UI_GenerateChannelString(char *pString, const uint8_t Channel); -void UI_GenerateChannelStringEx(char *pString, const bool bShowPrefix, const uint8_t ChannelNumber); +void UI_GenerateChannelString(char *pString, const channel_t Channel); +void UI_GenerateChannelStringEx(char *pString, const bool bShowPrefix, const channel_t ChannelNumber); void UI_PrintString(const char *pString, uint8_t Start, uint8_t End, uint8_t Line, uint8_t Width); void UI_PrintStringSmallNormal(const char *pString, uint8_t Start, uint8_t End, uint8_t Line); void UI_PrintStringSmallBold(const char *pString, uint8_t Start, uint8_t End, uint8_t Line); diff --git a/ui/main.c b/ui/main.c index eb17b1f86..0e6149205 100644 --- a/ui/main.c +++ b/ui/main.c @@ -442,12 +442,12 @@ void UI_DisplayMain(void) sprintf(String, "M%.3s", INPUTBOX_GetAscii()); // show the input text UI_PrintStringSmallNormal(String, x, 0, line + 1); } - else if (IS_FREQ_CHANNEL(gEeprom.ScreenChannel[vfo_num])) + else if (IS_VFO_CHANNEL(gEeprom.ScreenChannel[vfo_num])) { // frequency mode // show the frequency band number const unsigned int x = 2; char * buf = gEeprom.VfoInfo[vfo_num].pRX->Frequency < _1GHz_in_KHz ? "" : "+"; - sprintf(String, "F%u%s", 1 + gEeprom.ScreenChannel[vfo_num] - FREQ_CHANNEL_FIRST, buf); + sprintf(String, "F%u%s", 1 + gEeprom.ScreenChannel[vfo_num] - VFO_CHANNEL_FIRST, buf); UI_PrintStringSmallNormal(String, x, 0, line + 1); } #ifdef ENABLE_NOAA @@ -483,7 +483,7 @@ void UI_DisplayMain(void) if (state < ARRAY_SIZE(VfoStateStr)) UI_PrintString(VfoStateStr[state], 31, 0, line, 8); } - else if (gInputBoxIndex > 0 && IS_FREQ_CHANNEL(gEeprom.ScreenChannel[vfo_num]) && gEeprom.TX_VFO == vfo_num) + else if (gInputBoxIndex > 0 && IS_VFO_CHANNEL(gEeprom.ScreenChannel[vfo_num]) && gEeprom.TX_VFO == vfo_num) { // user entering a frequency const char * ascii = INPUTBOX_GetAscii(); bool isGigaF = frequency>=_1GHz_in_KHz;