0
mirror of https://github.com/OneOfEleven/uv-k5-firmware-custom.git synced 2025-04-28 14:21:25 +03:00

314 lines
9.0 KiB
C
Raw Normal View History

2023-09-09 08:03:56 +01: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 09:56:30 +01:00
#ifdef ENABLE_FMRADIO
#include "app/fm.h"
#endif
2023-09-09 08:03:56 +01:00
#include "driver/eeprom.h"
#include "driver/uart.h"
#include "misc.h"
#include "settings.h"
2023-10-08 17:14:13 +01:00
EEPROM_Config_t g_eeprom;
2023-09-09 08:03:56 +01:00
2023-09-14 09:56:30 +01:00
#ifdef ENABLE_FMRADIO
void SETTINGS_SaveFM(void)
2023-09-09 08:03:56 +01:00
{
2023-09-14 09:56:30 +01:00
unsigned int i;
2023-09-28 13:26:27 +01:00
2023-09-14 09:56:30 +01:00
struct
{
2023-10-08 17:14:13 +01:00
uint16_t frequency;
uint8_t channel;
bool is_channel_selected;
uint8_t padding[4];
} state;
memset(&state, 0xFF, sizeof(state));
state.channel = g_eeprom.fm_selected_channel;
state.frequency = g_eeprom.fm_selected_frequency;
state.is_channel_selected = g_eeprom.fm_is_channel_mode;
EEPROM_WriteBuffer(0x0E88, &state);
2023-09-14 09:56:30 +01:00
for (i = 0; i < 5; i++)
EEPROM_WriteBuffer(0x0E40 + (i * 8), &gFM_Channels[i * 4]);
}
#endif
2023-09-09 08:03:56 +01:00
void SETTINGS_SaveVfoIndices(void)
{
uint8_t State[8];
#ifndef ENABLE_NOAA
EEPROM_ReadBuffer(0x0E80, State, sizeof(State));
#endif
2023-09-28 13:26:27 +01:00
2023-10-08 17:14:13 +01:00
State[0] = g_eeprom.screen_channel[0];
State[1] = g_eeprom.user_channel[0];
State[2] = g_eeprom.freq_channel[0];
State[3] = g_eeprom.screen_channel[1];
State[4] = g_eeprom.user_channel[1];
State[5] = g_eeprom.freq_channel[1];
2023-09-14 09:56:30 +01:00
#ifdef ENABLE_NOAA
2023-10-08 17:14:13 +01:00
State[6] = g_eeprom.noaa_channel[0];
State[7] = g_eeprom.noaa_channel[1];
2023-09-09 08:03:56 +01:00
#endif
EEPROM_WriteBuffer(0x0E80, State);
}
void SETTINGS_SaveSettings(void)
{
2023-10-06 22:16:03 +01:00
uint8_t State[8];
2023-09-09 08:03:56 +01:00
2023-10-08 17:14:13 +01:00
State[0] = g_eeprom.chan_1_call;
State[1] = g_eeprom.squelch_level;
State[2] = g_eeprom.tx_timeout_timer;
2023-09-14 09:56:30 +01:00
#ifdef ENABLE_NOAA
2023-10-08 17:14:13 +01:00
State[3] = g_eeprom.NOAA_auto_scan;
2023-09-09 08:03:56 +01:00
#else
State[3] = false;
#endif
2023-10-08 17:14:13 +01:00
State[4] = g_eeprom.key_lock;
#ifdef ENABLE_VOX
2023-10-08 17:14:13 +01:00
State[5] = g_eeprom.vox_switch;
State[6] = g_eeprom.vox_level;
#else
State[5] = false;
State[6] = 0;
#endif
2023-10-08 17:14:13 +01:00
State[7] = g_eeprom.mic_sensitivity;
2023-09-09 08:03:56 +01:00
EEPROM_WriteBuffer(0x0E70, State);
State[0] = 0xFF;
2023-10-08 17:14:13 +01:00
State[1] = g_eeprom.channel_display_mode;
State[2] = g_eeprom.cross_vfo_rx_tx;
State[3] = g_eeprom.battery_save;
State[4] = g_eeprom.dual_watch;
State[5] = g_eeprom.backlight;
State[6] = g_eeprom.tail_note_elimination;
State[7] = g_eeprom.vfo_open;
2023-09-09 08:03:56 +01:00
EEPROM_WriteBuffer(0x0E78, State);
2023-10-08 17:14:13 +01:00
State[0] = g_eeprom.beep_control;
State[1] = g_eeprom.key1_short_press_action;
State[2] = g_eeprom.key1_long_press_action;
State[3] = g_eeprom.key2_short_press_action;
State[4] = g_eeprom.key2_long_press_action;
State[5] = g_eeprom.scan_resume_mode;
State[6] = g_eeprom.auto_keypad_lock;
State[7] = g_eeprom.pwr_on_display_mode;
2023-09-09 08:03:56 +01:00
EEPROM_WriteBuffer(0x0E90, State);
2023-10-06 22:16:03 +01:00
{
struct {
uint32_t password;
uint32_t spare;
} __attribute__((packed)) array;
memset(&array, 0xff, sizeof(array));
#ifdef ENABLE_PWRON_PASSWORD
2023-10-08 17:14:13 +01:00
array.password = g_eeprom.power_on_password;
2023-10-06 22:16:03 +01:00
#endif
EEPROM_WriteBuffer(0x0E98, &array);
}
2023-09-14 09:56:30 +01:00
#ifdef ENABLE_VOICE
2023-09-09 08:03:56 +01:00
memset(State, 0xFF, sizeof(State));
2023-10-08 17:14:13 +01:00
State[0] = g_eeprom.voice_prompt;
2023-09-09 08:03:56 +01:00
EEPROM_WriteBuffer(0x0EA0, State);
#endif
#if defined(ENABLE_ALARM) || defined(ENABLE_TX1750)
2023-10-08 17:14:13 +01:00
State[0] = g_eeprom.alarm_mode;
2023-09-09 09:01:52 +01:00
#else
State[0] = false;
#endif
2023-10-08 17:14:13 +01:00
State[1] = g_eeprom.roger_mode;
State[2] = g_eeprom.repeater_tail_tone_elimination;
State[3] = g_eeprom.tx_vfo;
2023-09-09 08:03:56 +01:00
EEPROM_WriteBuffer(0x0EA8, State);
2023-10-08 17:14:13 +01:00
State[0] = g_eeprom.DTMF_side_tone;
State[1] = g_eeprom.DTMF_separate_code;
State[2] = g_eeprom.DTMF_group_call_code;
State[3] = g_eeprom.DTMF_decode_response;
State[4] = g_eeprom.DTMF_auto_reset_time;
State[5] = g_eeprom.DTMF_preload_time / 10U;
State[6] = g_eeprom.DTMF_first_code_persist_time / 10U;
State[7] = g_eeprom.DTMF_hash_code_persist_time / 10U;
2023-09-09 08:03:56 +01:00
EEPROM_WriteBuffer(0x0ED0, State);
memset(State, 0xFF, sizeof(State));
2023-10-08 17:14:13 +01:00
State[0] = g_eeprom.DTMF_code_persist_time / 10U;
State[1] = g_eeprom.DTMF_code_interval_time / 10U;
State[2] = g_eeprom.permit_remote_kill;
2023-09-09 08:03:56 +01:00
EEPROM_WriteBuffer(0x0ED8, State);
2023-10-08 17:14:13 +01:00
State[0] = g_eeprom.scan_list_default;
State[1] = g_eeprom.scan_list_enabled[0];
State[2] = g_eeprom.scan_list_priority_ch1[0];
State[3] = g_eeprom.scan_list_priority_ch2[0];
State[4] = g_eeprom.scan_list_enabled[1];
State[5] = g_eeprom.scan_list_priority_ch1[1];
State[6] = g_eeprom.scan_list_priority_ch2[1];
2023-09-09 08:03:56 +01:00
State[7] = 0xFF;
EEPROM_WriteBuffer(0x0F18, State);
memset(State, 0xFF, sizeof(State));
2023-09-19 09:16:57 +01: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 23:25:46 +01:00
#ifdef ENABLE_AM_FIX
2023-09-21 23:06:47 +01:00
if (!gSetting_AM_fix) State[7] &= ~(1u << 5);
#endif
2023-10-04 16:37:11 +01:00
State[7] = (State[7] & ~(3u << 6)) | ((gSetting_backlight_on_tx_rx & 3u) << 6);
2023-09-09 08:03:56 +01:00
EEPROM_WriteBuffer(0x0F40, State);
}
void SETTINGS_SaveChannel(uint8_t Channel, uint8_t VFO, const VFO_Info_t *pVFO, uint8_t Mode)
{
2023-09-14 09:56:30 +01:00
#ifdef ENABLE_NOAA
2023-09-09 08:03:56 +01:00
if (IS_NOT_NOAA_CHANNEL(Channel))
#endif
{
const uint16_t OffsetMR = Channel * 16;
uint16_t OffsetVFO = OffsetMR;
2023-10-08 17:14:13 +01:00
if (Channel > USER_CHANNEL_LAST)
2023-09-25 18:08:21 +01:00
{ // it's a VFO, not a channel
2023-09-09 08:03:56 +01:00
OffsetVFO = (VFO == 0) ? 0x0C80 : 0x0C90;
OffsetVFO += (Channel - FREQ_CHANNEL_FIRST) * 32;
}
2023-10-08 17:14:13 +01:00
if (Mode >= 2 || Channel > USER_CHANNEL_LAST)
2023-09-25 18:08:21 +01:00
{ // copy VFO to a channel
2023-09-28 13:26:27 +01:00
uint8_t State[8];
2023-10-08 17:14:13 +01:00
((uint32_t *)State)[0] = pVFO->freq_config_rx.frequency;
((uint32_t *)State)[1] = pVFO->tx_offset_freq;
2023-09-28 13:26:27 +01:00
EEPROM_WriteBuffer(OffsetVFO + 0, State);
2023-10-08 17:14:13 +01:00
State[0] = pVFO->freq_config_rx.code;
State[1] = pVFO->freq_config_tx.code;
State[2] = (pVFO->freq_config_tx.code_type << 4) | pVFO->freq_config_rx.code_type;
State[3] = ((pVFO->am_mode & 1u) << 4) | pVFO->tx_offset_freq_dir;
2023-09-28 13:26:27 +01:00
State[4] = 0
2023-10-08 17:14:13 +01:00
| (pVFO->busy_channel_lock << 4)
| (pVFO->output_power << 2)
| (pVFO->channel_bandwidth << 1)
| (pVFO->frequency_reverse << 0);
State[5] = ((pVFO->DTMF_ptt_id_tx_mode & 7u) << 1) | ((pVFO->DTMF_decoding_enable & 1u) << 0);
State[6] = pVFO->step_setting;
State[7] = pVFO->scrambling_type;
2023-09-28 13:26:27 +01:00
EEPROM_WriteBuffer(OffsetVFO + 8, State);
2023-09-09 08:03:56 +01:00
SETTINGS_UpdateChannel(Channel, pVFO, true);
2023-10-08 17:14:13 +01:00
if (Channel <= USER_CHANNEL_LAST)
{ // it's a memory channel
2023-10-02 02:02:34 +01:00
#ifndef ENABLE_KEEP_MEM_NAME
// clear/reset the channel name
2023-09-28 13:26:27 +01: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-10-08 17:14:13 +01:00
memmove(State, pVFO->name + 0, 8);
2023-09-28 13:26:27 +01:00
EEPROM_WriteBuffer(0x0F50 + OffsetMR, State);
//memset(State, 0xFF, sizeof(State));
memset(State, 0x00, sizeof(State)); // follow the QS way
2023-10-08 17:14:13 +01:00
memmove(State, pVFO->name + 8, 2);
2023-09-28 13:26:27 +01:00
EEPROM_WriteBuffer(0x0F58 + OffsetMR, State);
}
#endif
}
2023-09-09 08:03:56 +01:00
}
}
}
void SETTINGS_UpdateChannel(uint8_t Channel, const VFO_Info_t *pVFO, bool keep)
2023-09-09 08:03:56 +01:00
{
2023-09-14 09:56:30 +01:00
#ifdef ENABLE_NOAA
2023-09-09 08:03:56 +01:00
if (IS_NOT_NOAA_CHANNEL(Channel))
#endif
{
uint8_t State[8];
uint8_t Attributes = 0xFF; // default attributes
uint16_t Offset = 0x0D60 + (Channel & ~7u);
2023-10-04 16:37:11 +01:00
2023-10-08 17:14:13 +01:00
Attributes &= (uint8_t)(~USER_CH_COMPAND); // default to '0' = compander disabled
2023-09-09 08:03:56 +01:00
EEPROM_ReadBuffer(Offset, State, sizeof(State));
if (keep)
2023-09-09 08:03:56 +01:00
{
2023-10-08 17:14:13 +01:00
Attributes = (pVFO->scanlist_1_participation << 7) | (pVFO->scanlist_2_participation << 6) | (pVFO->compander << 4) | (pVFO->band << 0);
if (State[Channel & 7u] == Attributes)
return; // no change in the attributes
2023-09-09 08:03:56 +01:00
}
State[Channel & 7u] = Attributes;
2023-09-09 08:03:56 +01:00
EEPROM_WriteBuffer(Offset, State);
2023-10-08 17:14:13 +01:00
gUSER_ChannelAttributes[Channel] = Attributes;
2023-09-09 08:03:56 +01:00
2023-10-02 02:02:34 +01:00
// #ifndef ENABLE_KEEP_MEM_NAME
2023-10-08 17:14:13 +01:00
if (Channel <= USER_CHANNEL_LAST)
{ // it's a memory channel
2023-09-09 08:03:56 +01:00
const uint16_t OffsetMR = Channel * 16;
if (!keep)
{ // clear/reset the channel name
2023-09-28 13:26:27 +01: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
2023-10-08 17:14:13 +01:00
// memmove(State, pVFO->name + 0, 8);
// EEPROM_WriteBuffer(0x0F50 + OffsetMR, State);
2023-09-28 13:26:27 +01:00
// //memset(State, 0xFF, sizeof(State));
// memset(State, 0x00, sizeof(State)); // follow the QS way
2023-10-08 17:14:13 +01:00
// memmove(State, pVFO->name + 8, 2);
// EEPROM_WriteBuffer(0x0F58 + OffsetMR, State);
// }
2023-09-09 08:03:56 +01:00
}
// #endif
2023-09-09 08:03:56 +01:00
}
}