From fb30ec8c86e9118f5b6a2f094f5f09c79b092e9e Mon Sep 17 00:00:00 2001 From: Krzysiek Egzmont Date: Wed, 22 Nov 2023 21:30:54 +0100 Subject: [PATCH] Refactor --- misc.c | 2 +- misc.h | 13 ++- radio.c | 321 +++++++++++++++++++++++++---------------------------- radio.h | 7 -- settings.c | 70 +++++------- settings.h | 8 +- ui/main.c | 12 +- 7 files changed, 202 insertions(+), 231 deletions(-) diff --git a/misc.c b/misc.c index 556169f..3ae0cf4 100644 --- a/misc.c +++ b/misc.c @@ -111,7 +111,7 @@ uint16_t gEEPROM_RSSI_CALIB[7][4]; uint16_t gEEPROM_1F8A; uint16_t gEEPROM_1F8C; -uint8_t gMR_ChannelAttributes[FREQ_CHANNEL_LAST + 1]; +ChannelAttributes_t gMR_ChannelAttributes[FREQ_CHANNEL_LAST + 1]; volatile uint16_t gBatterySaveCountdown_10ms = battery_save_count_10ms; diff --git a/misc.h b/misc.h index a13bd38..4b3ea71 100644 --- a/misc.h +++ b/misc.h @@ -176,7 +176,18 @@ extern uint16_t gEEPROM_RSSI_CALIB[7][4]; extern uint16_t gEEPROM_1F8A; extern uint16_t gEEPROM_1F8C; -extern uint8_t gMR_ChannelAttributes[207]; +typedef union { + struct { + uint8_t + band : 4, + compander : 2, + scanlist2 : 1, + scanlist1 : 1; + }; + uint8_t __val; +} ChannelAttributes_t; + +extern ChannelAttributes_t gMR_ChannelAttributes[207]; extern volatile uint16_t gBatterySaveCountdown_10ms; diff --git a/radio.c b/radio.c index 2c8b0c8..c70655e 100644 --- a/radio.c +++ b/radio.c @@ -56,24 +56,22 @@ const char gModulationStr[][4] = bool RADIO_CheckValidChannel(uint16_t Channel, bool bCheckScanList, uint8_t VFO) { // return true if the channel appears valid - uint8_t Attributes; + ChannelAttributes_t att; uint8_t PriorityCh1; uint8_t PriorityCh2; if (!IS_MR_CHANNEL(Channel)) return false; - Attributes = gMR_ChannelAttributes[Channel]; + att = gMR_ChannelAttributes[Channel]; - if ((Attributes & MR_CH_BAND_MASK) > BAND7_470MHz) + if (att.band > BAND7_470MHz) return false; - if (bCheckScanList) - { - switch (VFO) - { + if (bCheckScanList) { + switch (VFO) { case 0: - if ((Attributes & MR_CH_SCANLIST1) == 0) + if (!att.scanlist1) return false; PriorityCh1 = gEeprom.SCANLIST_PRIORITY_CH1[0]; @@ -81,7 +79,7 @@ bool RADIO_CheckValidChannel(uint16_t Channel, bool bCheckScanList, uint8_t VFO) break; case 1: - if ((Attributes & MR_CH_SCANLIST2) == 0) + if (!att.scanlist2) return false; PriorityCh1 = gEeprom.SCANLIST_PRIORITY_CH1[1]; @@ -128,8 +126,8 @@ void RADIO_InitInfo(VFO_Info_t *pInfo, const uint8_t ChannelSave, const uint32_t memset(pInfo, 0, sizeof(*pInfo)); pInfo->Band = FREQUENCY_GetBand(Frequency); - pInfo->SCANLIST1_PARTICIPATION = true; - pInfo->SCANLIST2_PARTICIPATION = true; + pInfo->SCANLIST1_PARTICIPATION = false; + pInfo->SCANLIST2_PARTICIPATION = false; pInfo->STEP_SETTING = STEP_12_5kHz; pInfo->StepFrequency = gStepFrequencyTable[pInfo->STEP_SETTING]; pInfo->CHANNEL_SAVE = ChannelSave; @@ -149,31 +147,23 @@ void RADIO_InitInfo(VFO_Info_t *pInfo, const uint8_t ChannelSave, const uint32_t void RADIO_ConfigureChannel(const unsigned int VFO, const unsigned int configure) { - uint8_t Channel; - uint8_t Attributes; - uint8_t Band; - bool bParticipation2; - uint16_t Base; - uint32_t Frequency; - VFO_Info_t *pRadio = &gEeprom.VfoInfo[VFO]; + VFO_Info_t *pVfo = &gEeprom.VfoInfo[VFO]; - if (!gSetting_350EN) - { - if (gEeprom.FreqChannel[VFO] == (FREQ_CHANNEL_LAST - 2)) - gEeprom.FreqChannel[VFO] = FREQ_CHANNEL_LAST - 1; + if (!gSetting_350EN) { + if (gEeprom.FreqChannel[VFO] == FREQ_CHANNEL_FIRST + BAND5_350MHz) + gEeprom.FreqChannel[VFO] = FREQ_CHANNEL_FIRST + BAND6_400MHz; - if (gEeprom.ScreenChannel[VFO] == (FREQ_CHANNEL_LAST - 2)) - gEeprom.ScreenChannel[VFO] = FREQ_CHANNEL_LAST - 1; + if (gEeprom.ScreenChannel[VFO] == FREQ_CHANNEL_FIRST + BAND5_350MHz) + gEeprom.ScreenChannel[VFO] = FREQ_CHANNEL_FIRST + BAND6_400MHz; } - Channel = gEeprom.ScreenChannel[VFO]; + uint8_t channel = gEeprom.ScreenChannel[VFO]; - if (IS_VALID_CHANNEL(Channel)) - { + if (IS_VALID_CHANNEL(channel)) { #ifdef ENABLE_NOAA - if (Channel >= NOAA_CHANNEL_FIRST) + if (channel >= NOAA_CHANNEL_FIRST) { - RADIO_InitInfo(pRadio, gEeprom.ScreenChannel[VFO], NoaaFrequencyTable[Channel - NOAA_CHANNEL_FIRST]); + RADIO_InitInfo(pVfo, gEeprom.ScreenChannel[VFO], NoaaFrequencyTable[channel - NOAA_CHANNEL_FIRST]); if (gEeprom.CROSS_BAND_RX_TX == CROSS_BAND_OFF) return; @@ -185,248 +175,235 @@ void RADIO_ConfigureChannel(const unsigned int VFO, const unsigned int configure } #endif - if (IS_MR_CHANNEL(Channel)) - { - Channel = RADIO_FindNextChannel(Channel, RADIO_CHANNEL_UP, false, VFO); - if (Channel == 0xFF) - { - Channel = gEeprom.FreqChannel[VFO]; + if (IS_MR_CHANNEL(channel)) { + channel = RADIO_FindNextChannel(channel, RADIO_CHANNEL_UP, false, VFO); + if (channel == 0xFF) { + channel = gEeprom.FreqChannel[VFO]; gEeprom.ScreenChannel[VFO] = gEeprom.FreqChannel[VFO]; } - else - { - gEeprom.ScreenChannel[VFO] = Channel; - gEeprom.MrChannel[VFO] = Channel; + else { + gEeprom.ScreenChannel[VFO] = channel; + gEeprom.MrChannel[VFO] = channel; } } } else - Channel = FREQ_CHANNEL_LAST - 1; + channel = FREQ_CHANNEL_LAST - 1; - Attributes = gMR_ChannelAttributes[Channel]; - if (Attributes == 0xFF) - { // invalid/unused channel - - uint8_t Index; - - if (IS_MR_CHANNEL(Channel)) - { - Channel = gEeprom.FreqChannel[VFO]; - gEeprom.ScreenChannel[VFO] = gEeprom.FreqChannel[VFO]; + ChannelAttributes_t att = gMR_ChannelAttributes[channel]; + if (att.__val == 0xFF) { // invalid/unused channel + if (IS_MR_CHANNEL(channel)) { + channel = gEeprom.FreqChannel[VFO]; + gEeprom.ScreenChannel[VFO] = channel; } - Index = Channel - FREQ_CHANNEL_FIRST; - - RADIO_InitInfo(pRadio, Channel, frequencyBandTable[Index].lower); + uint8_t bandIdx = channel - FREQ_CHANNEL_FIRST; + RADIO_InitInfo(pVfo, channel, frequencyBandTable[bandIdx].lower); return; } - Band = Attributes & MR_CH_BAND_MASK; - if (Band > BAND7_470MHz) - { - Band = BAND6_400MHz; + uint8_t band = att.band; + if (band > BAND7_470MHz) { + band = BAND6_400MHz; } - if (IS_MR_CHANNEL(Channel)) - { - gEeprom.VfoInfo[VFO].Band = Band; - gEeprom.VfoInfo[VFO].SCANLIST1_PARTICIPATION = !!(Attributes & MR_CH_SCANLIST1); - bParticipation2 = !!(Attributes & MR_CH_SCANLIST2); + bool bParticipation1; + bool bParticipation2; + if (IS_MR_CHANNEL(channel)) { + bParticipation1 = att.scanlist1; + bParticipation2 = att.scanlist2; } + else { + band = channel - FREQ_CHANNEL_FIRST; + bParticipation1 = true; + bParticipation2 = true; + } + + pVfo->Band = band; + pVfo->SCANLIST1_PARTICIPATION = bParticipation1; + pVfo->SCANLIST2_PARTICIPATION = bParticipation2; + pVfo->CHANNEL_SAVE = channel; + + uint16_t base; + if (IS_MR_CHANNEL(channel)) + base = channel * 16; else + base = 0x0C80 + ((channel - FREQ_CHANNEL_FIRST) * 32) + (VFO * 16); + + if (configure == VFO_CONFIGURE_RELOAD || IS_FREQ_CHANNEL(channel)) { - Band = Channel - FREQ_CHANNEL_FIRST; - gEeprom.VfoInfo[VFO].Band = Band; - bParticipation2 = true; - gEeprom.VfoInfo[VFO].SCANLIST1_PARTICIPATION = true; - } - - gEeprom.VfoInfo[VFO].SCANLIST2_PARTICIPATION = bParticipation2; - gEeprom.VfoInfo[VFO].CHANNEL_SAVE = Channel; - - if (IS_MR_CHANNEL(Channel)) - Base = Channel * 16; - else - Base = 0x0C80 + ((Channel - FREQ_CHANNEL_FIRST) * 32) + (VFO * 16); - - if (configure == VFO_CONFIGURE_RELOAD || Channel >= FREQ_CHANNEL_FIRST) - { - uint8_t Tmp; - uint8_t Data[8]; + uint8_t tmp; + uint8_t data[8]; // *************** - EEPROM_ReadBuffer(Base + 8, Data, sizeof(Data)); + EEPROM_ReadBuffer(base + 8, data, sizeof(data)); - Tmp = Data[3] & 0x0F; - if (Tmp > TX_OFFSET_FREQUENCY_DIRECTION_SUB) - Tmp = 0; - gEeprom.VfoInfo[VFO].TX_OFFSET_FREQUENCY_DIRECTION = Tmp; - gEeprom.VfoInfo[VFO].Modulation = (Data[3] >> 4); + tmp = data[3] & 0x0F; + if (tmp > TX_OFFSET_FREQUENCY_DIRECTION_SUB) + tmp = 0; + pVfo->TX_OFFSET_FREQUENCY_DIRECTION = tmp; + pVfo->Modulation = (data[3] >> 4); - Tmp = Data[6]; - if (Tmp >= ARRAY_SIZE(gStepFrequencyTable)) - Tmp = STEP_12_5kHz; - gEeprom.VfoInfo[VFO].STEP_SETTING = Tmp; - gEeprom.VfoInfo[VFO].StepFrequency = gStepFrequencyTable[Tmp]; + tmp = data[6]; + if (tmp >= ARRAY_SIZE(gStepFrequencyTable)) + tmp = STEP_12_5kHz; + pVfo->STEP_SETTING = tmp; + pVfo->StepFrequency = gStepFrequencyTable[tmp]; - Tmp = Data[7]; - if (Tmp > (ARRAY_SIZE(gSubMenu_SCRAMBLER) - 1)) - Tmp = 0; - gEeprom.VfoInfo[VFO].SCRAMBLING_TYPE = Tmp; + tmp = data[7]; + if (tmp > (ARRAY_SIZE(gSubMenu_SCRAMBLER) - 1)) + tmp = 0; + pVfo->SCRAMBLING_TYPE = tmp; - gEeprom.VfoInfo[VFO].freq_config_RX.CodeType = (Data[2] >> 0) & 0x0F; - gEeprom.VfoInfo[VFO].freq_config_TX.CodeType = (Data[2] >> 4) & 0x0F; + pVfo->freq_config_RX.CodeType = (data[2] >> 0) & 0x0F; + pVfo->freq_config_TX.CodeType = (data[2] >> 4) & 0x0F; - Tmp = Data[0]; - switch (gEeprom.VfoInfo[VFO].freq_config_RX.CodeType) + tmp = data[0]; + switch (pVfo->freq_config_RX.CodeType) { default: case CODE_TYPE_OFF: - gEeprom.VfoInfo[VFO].freq_config_RX.CodeType = CODE_TYPE_OFF; - Tmp = 0; + pVfo->freq_config_RX.CodeType = CODE_TYPE_OFF; + tmp = 0; break; case CODE_TYPE_CONTINUOUS_TONE: - if (Tmp > (ARRAY_SIZE(CTCSS_Options) - 1)) - Tmp = 0; + if (tmp > (ARRAY_SIZE(CTCSS_Options) - 1)) + tmp = 0; break; case CODE_TYPE_DIGITAL: case CODE_TYPE_REVERSE_DIGITAL: - if (Tmp > (ARRAY_SIZE(DCS_Options) - 1)) - Tmp = 0; + if (tmp > (ARRAY_SIZE(DCS_Options) - 1)) + tmp = 0; break; } - gEeprom.VfoInfo[VFO].freq_config_RX.Code = Tmp; + pVfo->freq_config_RX.Code = tmp; - Tmp = Data[1]; - switch (gEeprom.VfoInfo[VFO].freq_config_TX.CodeType) + tmp = data[1]; + switch (pVfo->freq_config_TX.CodeType) { default: case CODE_TYPE_OFF: - gEeprom.VfoInfo[VFO].freq_config_TX.CodeType = CODE_TYPE_OFF; - Tmp = 0; + pVfo->freq_config_TX.CodeType = CODE_TYPE_OFF; + tmp = 0; break; case CODE_TYPE_CONTINUOUS_TONE: - if (Tmp > (ARRAY_SIZE(CTCSS_Options) - 1)) - Tmp = 0; + if (tmp > (ARRAY_SIZE(CTCSS_Options) - 1)) + tmp = 0; break; case CODE_TYPE_DIGITAL: case CODE_TYPE_REVERSE_DIGITAL: - if (Tmp > (ARRAY_SIZE(DCS_Options) - 1)) - Tmp = 0; + if (tmp > (ARRAY_SIZE(DCS_Options) - 1)) + tmp = 0; break; } - gEeprom.VfoInfo[VFO].freq_config_TX.Code = Tmp; + pVfo->freq_config_TX.Code = tmp; - if (Data[4] == 0xFF) + if (data[4] == 0xFF) { - gEeprom.VfoInfo[VFO].FrequencyReverse = false; - gEeprom.VfoInfo[VFO].CHANNEL_BANDWIDTH = BK4819_FILTER_BW_WIDE; - gEeprom.VfoInfo[VFO].OUTPUT_POWER = OUTPUT_POWER_LOW; - gEeprom.VfoInfo[VFO].BUSY_CHANNEL_LOCK = false; + pVfo->FrequencyReverse = false; + pVfo->CHANNEL_BANDWIDTH = BK4819_FILTER_BW_WIDE; + pVfo->OUTPUT_POWER = OUTPUT_POWER_LOW; + pVfo->BUSY_CHANNEL_LOCK = false; } else { - const uint8_t d4 = Data[4]; - gEeprom.VfoInfo[VFO].FrequencyReverse = !!((d4 >> 0) & 1u); - gEeprom.VfoInfo[VFO].CHANNEL_BANDWIDTH = !!((d4 >> 1) & 1u); - gEeprom.VfoInfo[VFO].OUTPUT_POWER = ((d4 >> 2) & 3u); - gEeprom.VfoInfo[VFO].BUSY_CHANNEL_LOCK = !!((d4 >> 4) & 1u); + const uint8_t d4 = data[4]; + pVfo->FrequencyReverse = !!((d4 >> 0) & 1u); + pVfo->CHANNEL_BANDWIDTH = !!((d4 >> 1) & 1u); + pVfo->OUTPUT_POWER = ((d4 >> 2) & 3u); + pVfo->BUSY_CHANNEL_LOCK = !!((d4 >> 4) & 1u); } - if (Data[5] == 0xFF) + if (data[5] == 0xFF) { - gEeprom.VfoInfo[VFO].DTMF_DECODING_ENABLE = false; - gEeprom.VfoInfo[VFO].DTMF_PTT_ID_TX_MODE = PTT_ID_OFF; + pVfo->DTMF_DECODING_ENABLE = false; + pVfo->DTMF_PTT_ID_TX_MODE = PTT_ID_OFF; } else { - gEeprom.VfoInfo[VFO].DTMF_DECODING_ENABLE = ((Data[5] >> 0) & 1u) ? true : false; - gEeprom.VfoInfo[VFO].DTMF_PTT_ID_TX_MODE = ((Data[5] >> 1) & 7u); + pVfo->DTMF_DECODING_ENABLE = ((data[5] >> 0) & 1u) ? true : false; + pVfo->DTMF_PTT_ID_TX_MODE = ((data[5] >> 1) & 7u); } // *************** - struct - { + struct { uint32_t Frequency; uint32_t Offset; - } __attribute__((packed)) Info; + } __attribute__((packed)) info; + EEPROM_ReadBuffer(base, &info, sizeof(info)); - EEPROM_ReadBuffer(Base, &Info, sizeof(Info)); + pVfo->freq_config_RX.Frequency = info.Frequency; - pRadio->freq_config_RX.Frequency = Info.Frequency; - - if (Info.Offset >= 100000000) - Info.Offset = 1000000; - gEeprom.VfoInfo[VFO].TX_OFFSET_FREQUENCY = Info.Offset; + if (info.Offset >= 100000000) + info.Offset = 1000000; + pVfo->TX_OFFSET_FREQUENCY = info.Offset; // *************** } - Frequency = pRadio->freq_config_RX.Frequency; + uint32_t frequency = pVfo->freq_config_RX.Frequency; // fix previously set incorrect band - Band = FREQUENCY_GetBand(Frequency); + band = FREQUENCY_GetBand(frequency); - if (Frequency < frequencyBandTable[Band].lower) - Frequency = frequencyBandTable[Band].lower; - else - if (Frequency > frequencyBandTable[Band].upper) - Frequency = frequencyBandTable[Band].upper; - else - if (Channel >= FREQ_CHANNEL_FIRST) - Frequency = FREQUENCY_RoundToStep(Frequency, gEeprom.VfoInfo[VFO].StepFrequency); + if (frequency < frequencyBandTable[band].lower) + frequency = frequencyBandTable[band].lower; + else if (frequency > frequencyBandTable[band].upper) + frequency = frequencyBandTable[band].upper; + else if (channel >= FREQ_CHANNEL_FIRST) + frequency = FREQUENCY_RoundToStep(frequency, pVfo->StepFrequency); - pRadio->freq_config_RX.Frequency = Frequency; + pVfo->freq_config_RX.Frequency = frequency; - if (Frequency >= frequencyBandTable[BAND2_108MHz].upper && Frequency < frequencyBandTable[BAND2_108MHz].upper) - gEeprom.VfoInfo[VFO].TX_OFFSET_FREQUENCY_DIRECTION = TX_OFFSET_FREQUENCY_DIRECTION_OFF; - else if (!IS_MR_CHANNEL(Channel)) - gEeprom.VfoInfo[VFO].TX_OFFSET_FREQUENCY = FREQUENCY_RoundToStep(gEeprom.VfoInfo[VFO].TX_OFFSET_FREQUENCY, gEeprom.VfoInfo[VFO].StepFrequency); + if (frequency >= frequencyBandTable[BAND2_108MHz].upper && frequency < frequencyBandTable[BAND2_108MHz].upper) + pVfo->TX_OFFSET_FREQUENCY_DIRECTION = TX_OFFSET_FREQUENCY_DIRECTION_OFF; + else if (!IS_MR_CHANNEL(channel)) + pVfo->TX_OFFSET_FREQUENCY = FREQUENCY_RoundToStep(pVfo->TX_OFFSET_FREQUENCY, pVfo->StepFrequency); - RADIO_ApplyOffset(pRadio); + RADIO_ApplyOffset(pVfo); - memset(gEeprom.VfoInfo[VFO].Name, 0, sizeof(gEeprom.VfoInfo[VFO].Name)); - if (IS_MR_CHANNEL(Channel)) + memset(pVfo->Name, 0, sizeof(pVfo->Name)); + if (IS_MR_CHANNEL(channel)) { // 16 bytes allocated to the channel name but only 10 used, the rest are 0's - EEPROM_ReadBuffer(0x0F50 + (Channel * 16), gEeprom.VfoInfo[VFO].Name + 0, 8); - EEPROM_ReadBuffer(0x0F58 + (Channel * 16), gEeprom.VfoInfo[VFO].Name + 8, 2); + EEPROM_ReadBuffer(0x0F50 + (channel * 16), pVfo->Name + 0, 8); + EEPROM_ReadBuffer(0x0F58 + (channel * 16), pVfo->Name + 8, 2); } - if (!gEeprom.VfoInfo[VFO].FrequencyReverse) + if (!pVfo->FrequencyReverse) { - gEeprom.VfoInfo[VFO].pRX = &gEeprom.VfoInfo[VFO].freq_config_RX; - gEeprom.VfoInfo[VFO].pTX = &gEeprom.VfoInfo[VFO].freq_config_TX; + pVfo->pRX = &pVfo->freq_config_RX; + pVfo->pTX = &pVfo->freq_config_TX; } else { - gEeprom.VfoInfo[VFO].pRX = &gEeprom.VfoInfo[VFO].freq_config_TX; - gEeprom.VfoInfo[VFO].pTX = &gEeprom.VfoInfo[VFO].freq_config_RX; + pVfo->pRX = &pVfo->freq_config_TX; + pVfo->pTX = &pVfo->freq_config_RX; } if (!gSetting_350EN) { - FREQ_Config_t *pConfig = gEeprom.VfoInfo[VFO].pRX; + FREQ_Config_t *pConfig = pVfo->pRX; if (pConfig->Frequency >= 35000000 && pConfig->Frequency < 40000000) pConfig->Frequency = 43300000; } - if (gEeprom.VfoInfo[VFO].Modulation != MODULATION_FM) + if (pVfo->Modulation != MODULATION_FM) { // freq/chan is in AM mode - gEeprom.VfoInfo[VFO].SCRAMBLING_TYPE = 0; -// gEeprom.VfoInfo[VFO].DTMF_DECODING_ENABLE = false; // no reason to disable DTMF decoding, aircraft use it on SSB - gEeprom.VfoInfo[VFO].freq_config_RX.CodeType = CODE_TYPE_OFF; - gEeprom.VfoInfo[VFO].freq_config_TX.CodeType = CODE_TYPE_OFF; + pVfo->SCRAMBLING_TYPE = 0; +// pVfo->DTMF_DECODING_ENABLE = false; // no reason to disable DTMF decoding, aircraft use it on SSB + pVfo->freq_config_RX.CodeType = CODE_TYPE_OFF; + pVfo->freq_config_TX.CodeType = CODE_TYPE_OFF; } - gEeprom.VfoInfo[VFO].Compander = (Attributes & MR_CH_COMPAND) >> 4; + pVfo->Compander = att.compander; - RADIO_ConfigureSquelchAndOutputPower(pRadio); + RADIO_ConfigureSquelchAndOutputPower(pVfo); } void RADIO_ConfigureSquelchAndOutputPower(VFO_Info_t *pInfo) diff --git a/radio.h b/radio.h index a4a5400..c86bdd6 100644 --- a/radio.h +++ b/radio.h @@ -23,13 +23,6 @@ #include "dcs.h" #include "frequencies.h" -enum { - MR_CH_BAND_MASK = 0x0F << 0, - MR_CH_COMPAND = 3u << 4, // new - MR_CH_SCANLIST2 = 1u << 6, - MR_CH_SCANLIST1 = 1u << 7 -}; - enum { RADIO_CHANNEL_UP = 0x01u, RADIO_CHANNEL_DOWN = 0xFFu, diff --git a/settings.c b/settings.c index 82c8da9..1a1f22a 100644 --- a/settings.c +++ b/settings.c @@ -263,55 +263,45 @@ void SETTINGS_SaveBatteryCalibration(const uint16_t * batteryCalibration) EEPROM_WriteBuffer(0x1F48, buf); } -void SETTINGS_UpdateChannel(uint8_t Channel, const VFO_Info_t *pVFO, bool keep) +void SETTINGS_UpdateChannel(uint8_t channel, const VFO_Info_t *pVFO, bool keep) { - #ifdef ENABLE_NOAA - if (!IS_NOAA_CHANNEL(Channel)) - #endif +#ifdef ENABLE_NOAA + if (!IS_NOAA_CHANNEL(channel)) +#endif { - uint8_t State[8]; - uint8_t Attributes = 0xFF; // default attributes - uint16_t Offset = 0x0D60 + (Channel & ~7u); - - Attributes &= (uint8_t)(~MR_CH_COMPAND); // default to '0' = compander disabled + uint8_t state[8]; + ChannelAttributes_t att = { + .band = 0xf, + .compander = 0, + .scanlist1 = 0, + .scanlist2 = 0, + }; // default attributes - EEPROM_ReadBuffer(Offset, State, sizeof(State)); + uint16_t offset = 0x0D60 + (channel & ~7u); + EEPROM_ReadBuffer(offset, state, sizeof(state)); - if (keep) - { - Attributes = (pVFO->SCANLIST1_PARTICIPATION << 7) | (pVFO->SCANLIST2_PARTICIPATION << 6) | (pVFO->Compander << 4) | (pVFO->Band << 0); - if (State[Channel & 7u] == Attributes) + if (keep) { + att.band = pVFO->Band; + att.scanlist1 = pVFO->SCANLIST1_PARTICIPATION; + att.scanlist2 = pVFO->SCANLIST2_PARTICIPATION; + att.compander = pVFO->Compander; + if (state[channel & 7u] == att.__val) return; // no change in the attributes } - State[Channel & 7u] = Attributes; + state[channel & 7u] = att.__val; + EEPROM_WriteBuffer(offset, state); - EEPROM_WriteBuffer(Offset, State); + gMR_ChannelAttributes[channel] = att; - gMR_ChannelAttributes[Channel] = Attributes; - -// #ifndef ENABLE_KEEP_MEM_NAME - if (IS_MR_CHANNEL(Channel)) - { // it's a memory channel - - const uint16_t OffsetMR = Channel * 16; - if (!keep) - { // clear/reset the channel name - //memset(&State, 0xFF, sizeof(State)); - memset(&State, 0x00, sizeof(State)); // follow the QS way - EEPROM_WriteBuffer(0x0F50 + OffsetMR, State); - EEPROM_WriteBuffer(0x0F58 + OffsetMR, State); - } -// else -// { // update the channel name -// memmove(State, pVFO->Name + 0, 8); -// EEPROM_WriteBuffer(0x0F50 + OffsetMR, State); -// //memset(State, 0xFF, sizeof(State)); -// memset(State, 0x00, sizeof(State)); // follow the QS way -// memmove(State, pVFO->Name + 8, 2); -// EEPROM_WriteBuffer(0x0F58 + OffsetMR, State); -// } + if (IS_MR_CHANNEL(channel)) { // it's a memory channel + const uint16_t OffsetMR = channel * 16; + if (!keep) { + // clear/reset the channel name + memset(&state, 0x00, sizeof(state)); + EEPROM_WriteBuffer(0x0F50 + OffsetMR, state); + EEPROM_WriteBuffer(0x0F58 + OffsetMR, state); } -// #endif + } } } diff --git a/settings.h b/settings.h index fca1ca2..85505f1 100644 --- a/settings.h +++ b/settings.h @@ -127,9 +127,9 @@ enum CHANNEL_DisplayMode_t { typedef enum CHANNEL_DisplayMode_t CHANNEL_DisplayMode_t; typedef struct { - uint8_t ScreenChannel[2]; - uint8_t FreqChannel[2]; - uint8_t MrChannel[2]; + 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 #ifdef ENABLE_NOAA uint8_t NoaaChannel[2]; #endif @@ -254,6 +254,6 @@ void SETTINGS_SaveVfoIndices(void); void SETTINGS_SaveSettings(void); void SETTINGS_SaveChannel(uint8_t Channel, uint8_t VFO, const VFO_Info_t *pVFO, uint8_t Mode); void SETTINGS_SaveBatteryCalibration(const uint16_t * batteryCalibration); -void SETTINGS_UpdateChannel(uint8_t Channel, const VFO_Info_t *pVFO, bool keep); +void SETTINGS_UpdateChannel(uint8_t channel, const VFO_Info_t *pVFO, bool keep); #endif diff --git a/ui/main.c b/ui/main.c index dff0a01..588c925 100644 --- a/ui/main.c +++ b/ui/main.c @@ -457,15 +457,15 @@ void UI_DisplayMain(void) { // it's a channel // show the scan list assigment symbols - const uint8_t attributes = gMR_ChannelAttributes[gEeprom.ScreenChannel[vfo_num]]; - if (attributes & MR_CH_SCANLIST1) + const ChannelAttributes_t att = gMR_ChannelAttributes[gEeprom.ScreenChannel[vfo_num]]; + if (att.scanlist1) memmove(p_line0 + 113, BITMAP_ScanList1, sizeof(BITMAP_ScanList1)); - if (attributes & MR_CH_SCANLIST2) + if (att.scanlist2) memmove(p_line0 + 120, BITMAP_ScanList2, sizeof(BITMAP_ScanList2)); // compander symbol #ifndef ENABLE_BIG_FREQ - if ((attributes & MR_CH_COMPAND) > 0) + if (att.compander) memmove(p_line0 + 120 + LCD_WIDTH, BITMAP_compand, sizeof(BITMAP_compand)); #else // TODO: // find somewhere else to put the symbol @@ -543,8 +543,8 @@ void UI_DisplayMain(void) } // show the channel symbols - const uint8_t attributes = gMR_ChannelAttributes[gEeprom.ScreenChannel[vfo_num]]; - if ((attributes & MR_CH_COMPAND) > 0) + const ChannelAttributes_t att = gMR_ChannelAttributes[gEeprom.ScreenChannel[vfo_num]]; + if (att.compander) #ifdef ENABLE_BIG_FREQ memmove(p_line0 + 120, BITMAP_compand, sizeof(BITMAP_compand)); #else