uv-k5-firmware-custom/settings.c

311 lines
8.9 KiB
C
Raw Normal View History

2023-09-09 07:03:56 +00:00
/* 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 <string.h>
2023-09-14 08:56:30 +00:00
#ifdef ENABLE_FMRADIO
#include "app/fm.h"
#endif
2023-09-09 07:03:56 +00:00
#include "driver/eeprom.h"
#include "driver/uart.h"
#include "misc.h"
#include "settings.h"
EEPROM_Config_t gEeprom;
2023-09-14 08:56:30 +00:00
#ifdef ENABLE_FMRADIO
void SETTINGS_SaveFM(void)
2023-09-09 07:03:56 +00:00
{
2023-09-14 08:56:30 +00:00
unsigned int i;
2023-09-28 12:26:27 +00:00
2023-09-14 08:56:30 +00:00
struct
{
uint16_t Frequency;
uint8_t Channel;
bool IsChannelSelected;
uint8_t Padding[4];
} State;
2023-09-28 12:26:27 +00:00
2023-09-14 08:56:30 +00:00
memset(&State, 0xFF, sizeof(State));
State.Channel = gEeprom.FM_SelectedChannel;
State.Frequency = gEeprom.FM_SelectedFrequency;
State.IsChannelSelected = gEeprom.FM_IsMrMode;
2023-09-28 12:26:27 +00:00
2023-09-14 08:56:30 +00:00
EEPROM_WriteBuffer(0x0E88, &State);
for (i = 0; i < 5; i++)
EEPROM_WriteBuffer(0x0E40 + (i * 8), &gFM_Channels[i * 4]);
}
#endif
2023-09-09 07:03:56 +00:00
void SETTINGS_SaveVfoIndices(void)
{
uint8_t State[8];
#ifndef ENABLE_NOAA
EEPROM_ReadBuffer(0x0E80, State, sizeof(State));
#endif
2023-09-28 12:26:27 +00:00
2023-09-09 07:03:56 +00:00
State[0] = gEeprom.ScreenChannel[0];
State[1] = gEeprom.MrChannel[0];
State[2] = gEeprom.FreqChannel[0];
State[3] = gEeprom.ScreenChannel[1];
State[4] = gEeprom.MrChannel[1];
State[5] = gEeprom.FreqChannel[1];
2023-09-14 08:56:30 +00:00
#ifdef ENABLE_NOAA
2023-09-09 07:03:56 +00:00
State[6] = gEeprom.NoaaChannel[0];
State[7] = gEeprom.NoaaChannel[1];
#endif
EEPROM_WriteBuffer(0x0E80, State);
}
void SETTINGS_SaveSettings(void)
{
uint8_t State[8];
uint32_t Password[2];
State[0] = gEeprom.CHAN_1_CALL;
State[1] = gEeprom.SQUELCH_LEVEL;
State[2] = gEeprom.TX_TIMEOUT_TIMER;
2023-09-14 08:56:30 +00:00
#ifdef ENABLE_NOAA
2023-09-09 07:03:56 +00:00
State[3] = gEeprom.NOAA_AUTO_SCAN;
#else
State[3] = false;
#endif
State[4] = gEeprom.KEY_LOCK;
#ifdef ENABLE_VOX
State[5] = gEeprom.VOX_SWITCH;
State[6] = gEeprom.VOX_LEVEL;
#else
State[5] = false;
State[6] = 0;
#endif
2023-09-09 07:03:56 +00:00
State[7] = gEeprom.MIC_SENSITIVITY;
EEPROM_WriteBuffer(0x0E70, State);
State[0] = 0xFF;
State[1] = gEeprom.CHANNEL_DISPLAY_MODE;
State[2] = gEeprom.CROSS_BAND_RX_TX;
State[3] = gEeprom.BATTERY_SAVE;
State[4] = gEeprom.DUAL_WATCH;
State[5] = gEeprom.BACKLIGHT;
State[6] = gEeprom.TAIL_NOTE_ELIMINATION;
State[7] = gEeprom.VFO_OPEN;
EEPROM_WriteBuffer(0x0E78, State);
State[0] = gEeprom.BEEP_CONTROL;
State[1] = gEeprom.KEY_1_SHORT_PRESS_ACTION;
State[2] = gEeprom.KEY_1_LONG_PRESS_ACTION;
State[3] = gEeprom.KEY_2_SHORT_PRESS_ACTION;
State[4] = gEeprom.KEY_2_LONG_PRESS_ACTION;
State[5] = gEeprom.SCAN_RESUME_MODE;
State[6] = gEeprom.AUTO_KEYPAD_LOCK;
State[7] = gEeprom.POWER_ON_DISPLAY_MODE;
EEPROM_WriteBuffer(0x0E90, State);
memset(Password, 0xFF, sizeof(Password));
Password[0] = gEeprom.POWER_ON_PASSWORD;
EEPROM_WriteBuffer(0x0E98, State);
2023-09-14 08:56:30 +00:00
#ifdef ENABLE_VOICE
2023-09-09 07:03:56 +00:00
memset(State, 0xFF, sizeof(State));
State[0] = gEeprom.VOICE_PROMPT;
EEPROM_WriteBuffer(0x0EA0, State);
#endif
#if defined(ENABLE_ALARM) || defined(ENABLE_TX1750)
2023-09-09 08:01:52 +00:00
State[0] = gEeprom.ALARM_MODE;
#else
State[0] = false;
#endif
2023-09-09 07:03:56 +00:00
State[1] = gEeprom.ROGER;
State[2] = gEeprom.REPEATER_TAIL_TONE_ELIMINATION;
State[3] = gEeprom.TX_CHANNEL;
EEPROM_WriteBuffer(0x0EA8, State);
State[0] = gEeprom.DTMF_SIDE_TONE;
State[1] = gEeprom.DTMF_SEPARATE_CODE;
State[2] = gEeprom.DTMF_GROUP_CALL_CODE;
State[3] = gEeprom.DTMF_DECODE_RESPONSE;
State[4] = gEeprom.DTMF_AUTO_RESET_TIME;
State[5] = gEeprom.DTMF_PRELOAD_TIME / 10U;
State[6] = gEeprom.DTMF_FIRST_CODE_PERSIST_TIME / 10U;
State[7] = gEeprom.DTMF_HASH_CODE_PERSIST_TIME / 10U;
EEPROM_WriteBuffer(0x0ED0, State);
memset(State, 0xFF, sizeof(State));
State[0] = gEeprom.DTMF_CODE_PERSIST_TIME / 10U;
State[1] = gEeprom.DTMF_CODE_INTERVAL_TIME / 10U;
State[2] = gEeprom.PERMIT_REMOTE_KILL;
EEPROM_WriteBuffer(0x0ED8, State);
State[0] = gEeprom.SCAN_LIST_DEFAULT;
State[1] = gEeprom.SCAN_LIST_ENABLED[0];
State[2] = gEeprom.SCANLIST_PRIORITY_CH1[0];
State[3] = gEeprom.SCANLIST_PRIORITY_CH2[0];
State[4] = gEeprom.SCAN_LIST_ENABLED[1];
State[5] = gEeprom.SCANLIST_PRIORITY_CH1[1];
State[6] = gEeprom.SCANLIST_PRIORITY_CH2[1];
State[7] = 0xFF;
EEPROM_WriteBuffer(0x0F18, State);
memset(State, 0xFF, sizeof(State));
2023-09-19 08:16:57 +00:00
State[0] = gSetting_F_LOCK;
State[1] = gSetting_350TX;
State[2] = gSetting_KILLED;
State[3] = gSetting_200TX;
State[4] = gSetting_500TX;
State[5] = gSetting_350EN;
State[6] = gSetting_ScrambleEnable;
if (!gSetting_TX_EN) State[7] &= ~(1u << 0);
if (!gSetting_live_DTMF_decoder) State[7] &= ~(1u << 1);
State[7] = (State[7] & ~(3u << 2)) | ((gSetting_battery_text & 3u) << 2);
#ifdef ENABLE_AUDIO_BAR
if (!gSetting_mic_bar) State[7] &= ~(1u << 4);
#endif
2023-09-21 22:25:46 +00:00
#ifdef ENABLE_AM_FIX
2023-09-21 22:06:47 +00:00
if (!gSetting_AM_fix) State[7] &= ~(1u << 5);
#endif
if (!gSetting_backlight_on_tx_rx) State[7] &= ~(1u << 6);
2023-09-09 07:03:56 +00:00
EEPROM_WriteBuffer(0x0F40, State);
}
2023-09-25 17:08:21 +00:00
void SETTINGS_LoadChannel(uint8_t Channel, uint8_t VFO, const VFO_Info_t *pVFO)
{
}
2023-09-09 07:03:56 +00:00
void SETTINGS_SaveChannel(uint8_t Channel, uint8_t VFO, const VFO_Info_t *pVFO, uint8_t Mode)
{
2023-09-14 08:56:30 +00:00
#ifdef ENABLE_NOAA
2023-09-09 07:03:56 +00:00
if (IS_NOT_NOAA_CHANNEL(Channel))
#endif
{
const uint16_t OffsetMR = Channel * 16;
uint16_t OffsetVFO = OffsetMR;
if (!IS_MR_CHANNEL(Channel))
2023-09-25 17:08:21 +00:00
{ // it's a VFO, not a channel
2023-09-09 07:03:56 +00:00
OffsetVFO = (VFO == 0) ? 0x0C80 : 0x0C90;
OffsetVFO += (Channel - FREQ_CHANNEL_FIRST) * 32;
}
2023-09-15 09:57:26 +00:00
if (Mode >= 2 || !IS_MR_CHANNEL(Channel))
2023-09-25 17:08:21 +00:00
{ // copy VFO to a channel
2023-09-28 12:26:27 +00:00
uint8_t State[8];
((uint32_t *)State)[0] = pVFO->freq_config_RX.Frequency;
((uint32_t *)State)[1] = pVFO->TX_OFFSET_FREQUENCY;
EEPROM_WriteBuffer(OffsetVFO + 0, State);
State[0] = pVFO->freq_config_RX.Code;
State[1] = pVFO->freq_config_TX.Code;
State[2] = (pVFO->freq_config_TX.CodeType << 4) | pVFO->freq_config_RX.CodeType;
2023-09-28 22:32:08 +00:00
State[3] = ((pVFO->AM_mode & 1u) << 4) | pVFO->TX_OFFSET_FREQUENCY_DIRECTION;
2023-09-28 12:26:27 +00:00
State[4] = 0
2023-09-09 07:03:56 +00:00
| (pVFO->BUSY_CHANNEL_LOCK << 4)
| (pVFO->OUTPUT_POWER << 2)
| (pVFO->CHANNEL_BANDWIDTH << 1)
| (pVFO->FrequencyReverse << 0);
2023-09-30 10:22:19 +00:00
State[5] = (pVFO->DTMF_PTT_ID_TX_MODE << 1) | (pVFO->DTMF_DECODING_ENABLE << 0);
2023-09-28 12:26:27 +00:00
State[6] = pVFO->STEP_SETTING;
State[7] = pVFO->SCRAMBLING_TYPE;
EEPROM_WriteBuffer(OffsetVFO + 8, State);
2023-09-09 07:03:56 +00:00
SETTINGS_UpdateChannel(Channel, pVFO, true);
if (IS_MR_CHANNEL(Channel))
{
2023-10-02 01:02:34 +00:00
#ifndef ENABLE_KEEP_MEM_NAME
// clear/reset the channel name
2023-09-28 12:26:27 +00:00
//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
if (Mode >= 3)
{ // save the channel name
2023-09-28 12:26:27 +00:00
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);
}
#endif
}
2023-09-09 07:03:56 +00:00
}
}
}
void SETTINGS_UpdateChannel(uint8_t Channel, const VFO_Info_t *pVFO, bool keep)
2023-09-09 07:03:56 +00:00
{
2023-09-14 08:56:30 +00:00
#ifdef ENABLE_NOAA
2023-09-09 07:03:56 +00:00
if (IS_NOT_NOAA_CHANNEL(Channel))
#endif
{
uint8_t State[8];
uint8_t Attributes = 0xFF; // default attributes
#ifdef ENABLE_COMPANDER
Attributes &= ~MR_CH_COMPAND; // default to '0' = compander disabled
#endif
uint16_t Offset = 0x0D60 + (Channel & ~7u);
2023-09-09 07:03:56 +00:00
EEPROM_ReadBuffer(Offset, State, sizeof(State));
if (keep)
2023-09-09 07:03:56 +00:00
{
#ifdef ENABLE_COMPANDER
Attributes = (pVFO->SCANLIST1_PARTICIPATION << 7) | (pVFO->SCANLIST2_PARTICIPATION << 6) | (pVFO->Compander << 4) | (pVFO->Band << 0);
#else
Attributes = (pVFO->SCANLIST1_PARTICIPATION << 7) | (pVFO->SCANLIST2_PARTICIPATION << 6) | (pVFO->Band << 0);
#endif
if (State[Channel & 7u] == Attributes)
return; // no change in the attributes
2023-09-09 07:03:56 +00:00
}
State[Channel & 7u] = Attributes;
2023-09-09 07:03:56 +00:00
EEPROM_WriteBuffer(Offset, State);
gMR_ChannelAttributes[Channel] = Attributes;
2023-10-02 01:02:34 +00:00
// #ifndef ENABLE_KEEP_MEM_NAME
if (IS_MR_CHANNEL(Channel))
{
2023-09-09 07:03:56 +00:00
const uint16_t OffsetMR = Channel * 16;
if (!keep)
{ // clear/reset the channel name
2023-09-28 12:26:27 +00:00
//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);
2023-09-28 12:26:27 +00:00
// //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);
// }
2023-09-09 07:03:56 +00:00
}
// #endif
2023-09-09 07:03:56 +00:00
}
}