0
mirror of https://github.com/OneOfEleven/uv-k5-firmware-custom.git synced 2025-06-19 22:58:04 +03:00

fix dual watch bug + other stuff

This commit is contained in:
OneOfEleven
2023-11-02 10:00:51 +00:00
parent b0f105572a
commit 2638d803c0
47 changed files with 1880 additions and 2385 deletions

381
radio.c
View File

@ -42,6 +42,7 @@
#include "ui/menu.h"
#include "ui/ui.h"
vfo_info_t g_vfo_info[2];
vfo_info_t *g_tx_vfo;
vfo_info_t *g_rx_vfo;
vfo_info_t *g_current_vfo;
@ -53,16 +54,13 @@ vfo_state_t g_vfo_state[2];
bool RADIO_CheckValidChannel(uint16_t Channel, bool bCheckScanList, uint8_t VFO)
{ // return true if the channel appears valid
uint8_t Attributes;
uint8_t PriorityCh1;
uint8_t PriorityCh2;
unsigned int i;
uint8_t priority_channel[2];
if (Channel > USER_CHANNEL_LAST)
return false;
Attributes = g_user_channel_attributes[Channel];
if ((Attributes & USER_CH_BAND_MASK) > BAND7_470MHz)
if (g_user_channel_attributes[Channel].band > BAND7_470MHz)
return false;
if (bCheckScanList)
@ -70,29 +68,29 @@ bool RADIO_CheckValidChannel(uint16_t Channel, bool bCheckScanList, uint8_t VFO)
switch (VFO)
{
case 0:
if ((Attributes & USER_CH_SCANLIST1) == 0)
if (g_user_channel_attributes[Channel].scanlist1 == 0)
return false;
PriorityCh1 = g_eeprom.scan_list_priority_ch1[0];
PriorityCh2 = g_eeprom.scan_list_priority_ch2[0];
for (i = 0; i < 2; i++)
priority_channel[i] = g_eeprom.config.setting.priority_scan_list[VFO].channel[i];
break;
case 1:
if ((Attributes & USER_CH_SCANLIST2) == 0)
if (g_user_channel_attributes[Channel].scanlist2 == 0)
return false;
PriorityCh1 = g_eeprom.scan_list_priority_ch1[1];
PriorityCh2 = g_eeprom.scan_list_priority_ch2[1];
for (i = 0; i < 2; i++)
priority_channel[i] = g_eeprom.config.setting.priority_scan_list[VFO].channel[i];
break;
default:
return true;
}
if (PriorityCh1 == Channel)
if (priority_channel[0] == Channel)
return false;
if (PriorityCh2 == Channel)
if (priority_channel[1] == Channel)
return false;
}
@ -151,113 +149,116 @@ void RADIO_InitInfo(vfo_info_t *p_vfo, const uint8_t ChannelSave, const uint32_t
void RADIO_configure_channel(const unsigned int VFO, const unsigned int configure)
{
uint8_t Channel;
uint8_t Attributes;
uint8_t Band;
uint16_t Base;
uint32_t Frequency;
vfo_info_t *p_vfo = &g_eeprom.vfo_info[VFO];
unsigned int channel;
t_channel_attrib attributes;
// uint16_t base;
uint32_t frequency;
vfo_info_t *p_vfo = &g_vfo_info[VFO];
if (!g_setting_350_enable)
if (!g_eeprom.config.setting.enable_350)
{
if (g_eeprom.freq_channel[VFO] == (FREQ_CHANNEL_LAST - 2))
g_eeprom.freq_channel[VFO] = FREQ_CHANNEL_LAST - 1;
if (g_eeprom.config.setting.indices.vfo[VFO].frequency == (FREQ_CHANNEL_LAST - 2))
g_eeprom.config.setting.indices.vfo[VFO].frequency = FREQ_CHANNEL_LAST - 1;
if (g_eeprom.screen_channel[VFO] == (FREQ_CHANNEL_LAST - 2))
g_eeprom.screen_channel[VFO] = FREQ_CHANNEL_LAST - 1;
if (g_eeprom.config.setting.indices.vfo[VFO].screen == (FREQ_CHANNEL_LAST - 2))
g_eeprom.config.setting.indices.vfo[VFO].screen = FREQ_CHANNEL_LAST - 1;
}
Channel = g_eeprom.screen_channel[VFO];
channel = g_eeprom.config.setting.indices.vfo[VFO].screen;
p_vfo->freq_in_channel = 0xff;
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(p_vfo, g_eeprom.screen_channel[VFO], NOAA_FREQUENCY_TABLE[Channel - NOAA_CHANNEL_FIRST]);
if (g_eeprom.cross_vfo_rx_tx == CROSS_BAND_OFF)
RADIO_InitInfo(p_vfo, g_eeprom.config.setting.indices.vfo[VFO].screen, NOAA_FREQUENCY_TABLE[channel - NOAA_CHANNEL_FIRST]);
if (g_eeprom.config.setting.cross_vfo == CROSS_BAND_OFF)
return;
g_eeprom.cross_vfo_rx_tx = CROSS_BAND_OFF;
g_eeprom.config.setting.cross_vfo = CROSS_BAND_OFF;
g_update_status = true;
return;
}
#endif
if (Channel <= USER_CHANNEL_LAST)
if (channel <= USER_CHANNEL_LAST)
{
Channel = RADIO_FindNextChannel(Channel, SCAN_STATE_DIR_FORWARD, false, VFO);
if (Channel == 0xFF)
channel = RADIO_FindNextChannel(channel, SCAN_STATE_DIR_FORWARD, false, VFO);
if (channel == 0xFF)
{
Channel = g_eeprom.freq_channel[VFO];
g_eeprom.screen_channel[VFO] = g_eeprom.freq_channel[VFO];
channel = g_eeprom.config.setting.indices.vfo[VFO].frequency;
g_eeprom.config.setting.indices.vfo[VFO].screen = channel;
}
else
{
g_eeprom.screen_channel[VFO] = Channel;
g_eeprom.user_channel[VFO] = Channel;
g_eeprom.config.setting.indices.vfo[VFO].screen = channel;
g_eeprom.config.setting.indices.vfo[VFO].user = channel;
}
}
}
else
Channel = FREQ_CHANNEL_LAST - 1;
{
channel = FREQ_CHANNEL_LAST - 1;
}
Attributes = g_user_channel_attributes[Channel];
if (Attributes == 0xFF)
attributes = g_user_channel_attributes[channel];
if (attributes.band > BAND7_470MHz)
{ // invalid/unused channel
uint8_t Index;
unsigned int index;
if (Channel <= USER_CHANNEL_LAST)
if (channel <= USER_CHANNEL_LAST)
{
Channel = g_eeprom.freq_channel[VFO];
g_eeprom.screen_channel[VFO] = g_eeprom.freq_channel[VFO];
channel = g_eeprom.config.setting.indices.vfo[VFO].frequency;
g_eeprom.config.setting.indices.vfo[VFO].screen = channel;
}
Index = Channel - FREQ_CHANNEL_FIRST;
index = channel - FREQ_CHANNEL_FIRST;
RADIO_InitInfo(p_vfo, Channel, FREQ_BAND_TABLE[Index].lower);
RADIO_InitInfo(p_vfo, channel, FREQ_BAND_TABLE[index].lower);
return;
}
Band = Attributes & USER_CH_BAND_MASK;
if (Band > BAND7_470MHz)
Band = BAND6_400MHz;
if (attributes.band > BAND7_470MHz)
attributes.band = BAND6_400MHz;
if (Channel <= USER_CHANNEL_LAST)
if (channel <= USER_CHANNEL_LAST)
{ // USER channel
p_vfo->band = Band;
p_vfo->scanlist_2_participation = (Attributes & USER_CH_SCANLIST2) ? 1 : 0;
p_vfo->scanlist_1_participation = (Attributes & USER_CH_SCANLIST1) ? 1 : 0;
p_vfo->band = attributes.band;
p_vfo->scanlist_2_participation = attributes.scanlist2;
p_vfo->scanlist_1_participation = attributes.scanlist1;
}
else
if (IS_FREQ_CHANNEL(Channel))
if (IS_FREQ_CHANNEL(channel))
{ // VFO channel
Band = Channel - FREQ_CHANNEL_FIRST;
g_eeprom.vfo_info[VFO].band = Band; // shouldn't this be "Band / 2" ? .. two VFO's per band
attributes.band = channel - FREQ_CHANNEL_FIRST; // shouldn't this be "Band / 2" ? .. two VFO's per band TODO:
g_vfo_info[VFO].band = attributes.band;
#if 0
p_vfo->scanlist_2_participation = 1;
p_vfo->scanlist_1_participation = 1;
#else
// allowing the vfo's to be included in the scanning
p_vfo->scanlist_2_participation = (Attributes & USER_CH_SCANLIST2) ? 1 : 0;
p_vfo->scanlist_1_participation = (Attributes & USER_CH_SCANLIST1) ? 1 : 0;
p_vfo->scanlist_2_participation = attributes.scanlist2;
p_vfo->scanlist_1_participation = attributes.scanlist1;
#endif
}
p_vfo->channel_save = Channel;
p_vfo->channel_save = channel;
if (Channel <= USER_CHANNEL_LAST)
Base = Channel * 16;
else
Base = 0x0C80 + ((Channel - FREQ_CHANNEL_FIRST) * 16 * 2) + (VFO * 16); // VFO channel
// if (channel <= USER_CHANNEL_LAST)
// base = channel * 16;
// else
// base = 0x0C80 + ((channel - FREQ_CHANNEL_FIRST) * 16 * 2) + (VFO * 16); // VFO channel
if (configure == VFO_CONFIGURE_RELOAD || IS_FREQ_CHANNEL(Channel))
if (configure == VFO_CONFIGURE_RELOAD || IS_FREQ_CHANNEL(channel))
{
const unsigned int chan = CHANNEL_NUM(channel, VFO);
t_channel m_channel;
EEPROM_ReadBuffer(Base, &m_channel, sizeof(m_channel));
// EEPROM_ReadBuffer(Base, &m_channel, sizeof(t_channel));
memcpy(&m_channel, &g_eeprom.config.channel[chan], sizeof(t_channel));
p_vfo->freq_config_rx.frequency = m_channel.frequency;
@ -321,26 +322,26 @@ void RADIO_configure_channel(const unsigned int VFO, const unsigned int configur
p_vfo->squelch_level = (m_channel.squelch_level < 10) ? m_channel.squelch_level : 0;
}
Frequency = p_vfo->freq_config_rx.frequency;
frequency = p_vfo->freq_config_rx.frequency;
if (Frequency < FREQ_BAND_TABLE[Band].lower)
Frequency = FREQ_BAND_TABLE[Band].lower;
if (frequency < FREQ_BAND_TABLE[attributes.band].lower)
frequency = FREQ_BAND_TABLE[attributes.band].lower;
else
if (Frequency >= FREQ_BAND_TABLE[Band].upper)
Frequency = FREQUENCY_floor_to_step(Frequency, p_vfo->step_freq, FREQ_BAND_TABLE[Band].lower, FREQ_BAND_TABLE[Band].upper);
if (frequency >= FREQ_BAND_TABLE[attributes.band].upper)
frequency = FREQUENCY_floor_to_step(frequency, p_vfo->step_freq, FREQ_BAND_TABLE[attributes.band].lower, FREQ_BAND_TABLE[attributes.band].upper);
else
if (Channel >= FREQ_CHANNEL_FIRST)
Frequency = FREQUENCY_floor_to_step(Frequency, p_vfo->step_freq, FREQ_BAND_TABLE[Band].lower, FREQ_BAND_TABLE[Band].upper);
if (channel >= FREQ_CHANNEL_FIRST)
frequency = FREQUENCY_floor_to_step(frequency, p_vfo->step_freq, FREQ_BAND_TABLE[attributes.band].lower, FREQ_BAND_TABLE[attributes.band].upper);
if (!g_setting_350_enable && Frequency >= 35000000 && Frequency < 40000000)
if (!g_eeprom.config.setting.enable_350 && frequency >= 35000000 && frequency < 40000000)
{ // 350~400Mhz not allowed
// hop onto the next band up
Frequency = 43350000;
p_vfo->freq_config_rx.frequency = Frequency;
p_vfo->freq_config_tx.frequency = Frequency;
Band = FREQUENCY_GetBand(Frequency);
p_vfo->band = Band;
frequency = 43350000;
p_vfo->freq_config_rx.frequency = frequency;
p_vfo->freq_config_tx.frequency = frequency;
attributes.band = FREQUENCY_GetBand(frequency);
p_vfo->band = attributes.band;
p_vfo->frequency_reverse = 0;
p_vfo->tx_offset_freq_dir = TX_OFFSET_FREQ_DIR_OFF;
p_vfo->tx_offset_freq = 0;
@ -351,15 +352,15 @@ void RADIO_configure_channel(const unsigned int VFO, const unsigned int configur
}
p_vfo->freq_config_rx.frequency = Frequency;
p_vfo->freq_config_rx.frequency = frequency;
if (Frequency >= AIR_BAND.lower && Frequency < AIR_BAND.upper)
if (frequency >= AIR_BAND.lower && frequency < AIR_BAND.upper)
{ // air band
p_vfo->tx_offset_freq_dir = TX_OFFSET_FREQ_DIR_OFF;
p_vfo->tx_offset_freq = 0;
}
else
if (Channel > USER_CHANNEL_LAST)
if (channel > USER_CHANNEL_LAST)
{
p_vfo->tx_offset_freq = FREQUENCY_floor_to_step(p_vfo->tx_offset_freq + (p_vfo->step_freq / 2), p_vfo->step_freq, 0, p_vfo->tx_offset_freq + p_vfo->step_freq);
}
@ -368,8 +369,9 @@ void RADIO_configure_channel(const unsigned int VFO, const unsigned int configur
// channel name
memset(p_vfo->name, 0, sizeof(p_vfo->name));
if (Channel <= USER_CHANNEL_LAST)
EEPROM_ReadBuffer(0x0F50 + (Channel * 16), p_vfo->name, 10); // only 10 bytes used
if (channel <= USER_CHANNEL_LAST)
// EEPROM_ReadBuffer(0x0F50 + (Channel * 16), p_vfo->name, 10); // only 10 bytes used
memcpy(p_vfo->name, &g_eeprom.config.channel_name[channel].name, sizeof(g_eeprom.config.channel_name[channel].name));
if (p_vfo->am_mode > 0)
{ // freq/chan is in AM mode
@ -383,7 +385,7 @@ void RADIO_configure_channel(const unsigned int VFO, const unsigned int configur
RADIO_ConfigureSquelchAndOutputPower(p_vfo);
#ifdef ENABLE_AM_FIX
if (p_vfo->am_mode > 0 && g_setting_am_fix)
if (p_vfo->am_mode > 0 && g_eeprom.config.setting.am_fix)
{
AM_fix_reset(VFO);
AM_fix_10ms(VFO);
@ -405,25 +407,25 @@ void RADIO_configure_channel(const unsigned int VFO, const unsigned int configur
}
#endif
// if (configure == VFO_CONFIGURE_RELOAD || IS_FREQ_CHANNEL(Channel))
if (IS_FREQ_CHANNEL(Channel))
p_vfo->freq_in_channel = BOARD_find_channel(Frequency); // find channel that has this frequency
// if (configure == VFO_CONFIGURE_RELOAD || IS_FREQ_CHANNEL(channel))
if (IS_FREQ_CHANNEL(channel))
p_vfo->freq_in_channel = SETTINGS_find_channel(frequency); // find channel that has this frequency
}
void RADIO_ConfigureSquelchAndOutputPower(vfo_info_t *p_vfo)
{
uint8_t TX_power[3];
uint16_t Base;
frequency_band_t Band;
// uint8_t tx_power[3];
// uint16_t base;
// frequency_band_t band;
uint8_t squelch_level;
// *******************************
// squelch
Band = FREQUENCY_GetBand(p_vfo->p_rx->frequency);
Base = (Band < BAND4_174MHz) ? 0x1E60 : 0x1E00;
// band = FREQUENCY_GetBand(p_vfo->p_rx->frequency);
// base = (Band < BAND4_174MHz) ? 0x1E60 : 0x1E00;
squelch_level = (p_vfo->squelch_level > 0) ? p_vfo->squelch_level : g_eeprom.squelch_level;
squelch_level = (p_vfo->squelch_level > 0) ? p_vfo->squelch_level : g_eeprom.config.setting.squelch_level;
// note that 'noise' and 'glitch' values are inverted compared to 'rssi' values
@ -435,11 +437,12 @@ void RADIO_ConfigureSquelchAndOutputPower(vfo_info_t *p_vfo)
p_vfo->squelch_open_noise_thresh = 127; // 127 ~ 0
p_vfo->squelch_close_noise_thresh = 127; // 127 ~ 0
p_vfo->squelch_close_glitch_thresh = 255; // 255 ~ 0
p_vfo->squelch_open_glitch_thresh = 255; // 255 ~ 0
p_vfo->squelch_close_glitch_thresh = 255; // 255 ~ 0
}
else
{ // squelch >= 1
#if 0
Base += squelch_level; // my eeprom squelch-1
// VHF UHF
EEPROM_ReadBuffer(Base + 0x00, &p_vfo->squelch_open_rssi_thresh, 1); // 50 10
@ -448,9 +451,21 @@ void RADIO_ConfigureSquelchAndOutputPower(vfo_info_t *p_vfo)
EEPROM_ReadBuffer(Base + 0x20, &p_vfo->squelch_open_noise_thresh, 1); // 65 90
EEPROM_ReadBuffer(Base + 0x30, &p_vfo->squelch_close_noise_thresh, 1); // 70 100
EEPROM_ReadBuffer(Base + 0x40, &p_vfo->squelch_close_glitch_thresh, 1); // 90 90
EEPROM_ReadBuffer(Base + 0x50, &p_vfo->squelch_open_glitch_thresh, 1); // 100 100
EEPROM_ReadBuffer(Base + 0x40, &p_vfo->squelch_close_glitch_thresh, 1); // 90 90 BUG ??? .. these 2 swapped ?
EEPROM_ReadBuffer(Base + 0x50, &p_vfo->squelch_open_glitch_thresh, 1); // 100 100 " "
#else
unsigned int band = (unsigned int)FREQUENCY_GetBand(p_vfo->p_rx->frequency);
band = (band < BAND4_174MHz) ? 1 : 0;
p_vfo->squelch_open_rssi_thresh = g_eeprom.calib.squelch_band[band].open_rssi_thresh[squelch_level];
p_vfo->squelch_close_rssi_thresh = g_eeprom.calib.squelch_band[band].close_rssi_thresh[squelch_level];
p_vfo->squelch_open_noise_thresh = g_eeprom.calib.squelch_band[band].open_noise_thresh[squelch_level];
p_vfo->squelch_close_noise_thresh = g_eeprom.calib.squelch_band[band].close_noise_thresh[squelch_level];
p_vfo->squelch_open_glitch_thresh = g_eeprom.calib.squelch_band[band].open_glitch_thresh[squelch_level];
p_vfo->squelch_close_glitch_thresh = g_eeprom.calib.squelch_band[band].close_glitch_thresh[squelch_level];
#endif
// *********
// used in AM mode
@ -528,45 +543,49 @@ void RADIO_ConfigureSquelchAndOutputPower(vfo_info_t *p_vfo)
// *******************************
// output power
// my calibration data
//
// 1ED0 32 32 32 64 64 64 8C 8C 8C FF FF FF FF FF FF FF .. 50 MHz
// 1EE0 32 32 32 64 64 64 8C 8C 8C FF FF FF FF FF FF FF .. 108 MHz
// 1EF0 5F 5F 5F 69 69 69 91 91 8F FF FF FF FF FF FF FF .. 137 MHz
// 1F00 32 32 32 64 64 64 8C 8C 8C FF FF FF FF FF FF FF .. 174 MHz
// 1F10 5A 5A 5A 64 64 64 82 82 82 FF FF FF FF FF FF FF .. 350 MHz
// 1F20 5A 5A 5A 64 64 64 8F 91 8A FF FF FF FF FF FF FF .. 400 MHz
// 1F30 32 32 32 64 64 64 8C 8C 8C FF FF FF FF FF FF FF .. 470 MHz
{
// my calibration data
//
// 1ED0 32 32 32 64 64 64 8C 8C 8C FF FF FF FF FF FF FF .. 50 MHz
// 1EE0 32 32 32 64 64 64 8C 8C 8C FF FF FF FF FF FF FF .. 108 MHz
// 1EF0 5F 5F 5F 69 69 69 91 91 8F FF FF FF FF FF FF FF .. 137 MHz
// 1F00 32 32 32 64 64 64 8C 8C 8C FF FF FF FF FF FF FF .. 174 MHz
// 1F10 5A 5A 5A 64 64 64 82 82 82 FF FF FF FF FF FF FF .. 350 MHz
// 1F20 5A 5A 5A 64 64 64 8F 91 8A FF FF FF FF FF FF FF .. 400 MHz
// 1F30 32 32 32 64 64 64 8C 8C 8C FF FF FF FF FF FF FF .. 470 MHz
uint8_t tx_power[3];
const unsigned int band = (unsigned int)FREQUENCY_GetBand(p_vfo->p_tx->frequency);
// EEPROM_ReadBuffer(0x1ED0 + (band * 16) + (p_vfo->output_power * 3), tx_power, 3);
memcpy(&tx_power, &g_eeprom.calib.tx_band_power[band].level[p_vfo->output_power], 3);
Band = FREQUENCY_GetBand(p_vfo->p_tx->frequency);
EEPROM_ReadBuffer(0x1ED0 + (Band * 16) + (p_vfo->output_power * 3), TX_power, 3);
#ifdef ENABLE_REDUCE_LOW_MID_TX_POWER
// make low and mid even lower
if (p_vfo->output_power == OUTPUT_POWER_LOW)
{
TX_power[0] /= 5; //TX_power[0] /= 8;
TX_power[1] /= 5; //TX_power[1] /= 8;
TX_power[2] /= 5; //TX_power[2] /= 8; get more low power
}
else
if (p_vfo->output_power == OUTPUT_POWER_MID)
{
TX_power[0] /= 3; //TX_power[0] /= 5;
TX_power[1] /= 3; //TX_power[1] /= 5;
TX_power[2] /= 3; //TX_power[2] /= 5; get more low power
}
#endif
p_vfo->txp_calculated_setting = FREQUENCY_CalculateOutputPower(
TX_power[0],
TX_power[1],
TX_power[2],
FREQ_BAND_TABLE[Band].lower,
(FREQ_BAND_TABLE[Band].lower + FREQ_BAND_TABLE[Band].upper) / 2,
FREQ_BAND_TABLE[Band].upper,
p_vfo->p_tx->frequency);
#ifdef ENABLE_REDUCE_LOW_MID_TX_POWER
// make low and mid even lower
if (p_vfo->output_power == OUTPUT_POWER_LOW)
{
tx_power[0] /= 5; //tx_power[0] /= 8;
tx_power[1] /= 5; //tx_power[1] /= 8;
tx_power[2] /= 5; //tx_power[2] /= 8; get more low power
}
else
if (p_vfo->output_power == OUTPUT_POWER_MID)
{
tx_power[0] /= 3; //tx_power[0] /= 5;
tx_power[1] /= 3; //tx_power[1] /= 5;
tx_power[2] /= 3; //tx_power[2] /= 5; get more low power
}
#endif
p_vfo->txp_calculated_setting = FREQUENCY_CalculateOutputPower(
tx_power[0],
tx_power[1],
tx_power[2],
FREQ_BAND_TABLE[band].lower,
(FREQ_BAND_TABLE[band].lower + FREQ_BAND_TABLE[band].upper) / 2,
FREQ_BAND_TABLE[band].upper,
p_vfo->p_tx->frequency);
}
// *******************************
}
@ -612,16 +631,16 @@ void RADIO_ApplyOffset(vfo_info_t *p_vfo, const bool set_pees)
static void RADIO_SelectCurrentVfo(void)
{
g_current_vfo = (g_eeprom.cross_vfo_rx_tx == CROSS_BAND_OFF) ? g_rx_vfo : &g_eeprom.vfo_info[g_eeprom.tx_vfo];
g_current_vfo = (g_eeprom.config.setting.cross_vfo == CROSS_BAND_OFF) ? g_rx_vfo : &g_vfo_info[g_eeprom.config.setting.tx_vfo_num];
}
void RADIO_select_vfos(void)
{
g_eeprom.tx_vfo = get_TX_VFO();
g_eeprom.rx_vfo = (g_eeprom.cross_vfo_rx_tx == CROSS_BAND_OFF) ? g_eeprom.tx_vfo : (g_eeprom.tx_vfo + 1) & 1u;
g_eeprom.config.setting.tx_vfo_num = get_TX_VFO();
g_rx_vfo_num = (g_eeprom.config.setting.cross_vfo == CROSS_BAND_OFF) ? g_eeprom.config.setting.tx_vfo_num : (g_eeprom.config.setting.tx_vfo_num + 1) & 1u;
g_tx_vfo = &g_eeprom.vfo_info[g_eeprom.tx_vfo];
g_rx_vfo = &g_eeprom.vfo_info[g_eeprom.rx_vfo];
g_tx_vfo = &g_vfo_info[g_eeprom.config.setting.tx_vfo_num];
g_rx_vfo = &g_vfo_info[g_rx_vfo_num];
RADIO_SelectCurrentVfo();
}
@ -649,7 +668,7 @@ void RADIO_setup_registers(bool switch_to_function_foreground)
case BK4819_FILTER_BW_NARROW:
#ifdef ENABLE_AM_FIX
#if 0
// BK4819_SetFilterBandwidth(Bandwidth, g_rx_vfo->am_mode > 0 && g_setting_am_fix);
// BK4819_SetFilterBandwidth(Bandwidth, g_rx_vfo->am_mode > 0 && g_eeprom.config.setting.am_fix);
BK4819_SetFilterBandwidth(Bandwidth, true);
#else
if (g_rx_vfo->am_mode > 1)
@ -692,7 +711,7 @@ void RADIO_setup_registers(bool switch_to_function_foreground)
BK4819_WriteRegister(0x3F, 0); // disable interrupts
#ifdef ENABLE_NOAA
if (IS_NOAA_CHANNEL(g_rx_vfo->channel_save) && g_is_noaa_mode)
if (IS_NOAA_CHANNEL(g_rx_vfo->channel_save) && g_noaa_mode)
Frequency = NOAA_FREQUENCY_TABLE[g_noaa_channel];
else
#endif
@ -717,10 +736,10 @@ void RADIO_setup_registers(bool switch_to_function_foreground)
// else
{
BK4819_WriteRegister(0x48,
(11u << 12) | // ??? .. 0 ~ 15, doesn't seem to make any difference
( 0u << 10) | // AF Rx Gain-1
(g_eeprom.volume_gain << 4) | // AF Rx Gain-2
(g_eeprom.dac_gain << 0)); // AF DAC Gain (after Gain-1 and Gain-2)
(11u << 12) | // ??? .. 0 ~ 15, doesn't seem to make any difference
( 0u << 10) | // AF Rx Gain-1
(g_eeprom.calib.volume_gain << 4) | // AF Rx Gain-2
(g_eeprom.calib.dac_gain << 0)); // AF DAC Gain (after Gain-1 and Gain-2)
}
#ifdef ENABLE_VOICE
@ -787,7 +806,7 @@ void RADIO_setup_registers(bool switch_to_function_foreground)
break;
}
if (g_rx_vfo->scrambling_type > 0 && g_setting_scramble_enable)
if (g_rx_vfo->scrambling_type > 0 && g_eeprom.config.setting.enable_scrambler)
BK4819_EnableScramble(g_rx_vfo->scrambling_type - 1);
else
BK4819_DisableScramble();
@ -807,11 +826,11 @@ void RADIO_setup_registers(bool switch_to_function_foreground)
#ifdef ENABLE_FMRADIO
!g_fm_radio_mode &&
#endif
g_eeprom.vox_switch &&
g_eeprom.config.setting.vox_switch &&
IS_NOT_NOAA_CHANNEL(g_current_vfo->channel_save) &&
g_current_vfo->am_mode == 0)
{
BK4819_EnableVox(g_eeprom.vox1_threshold, g_eeprom.vox0_threshold);
BK4819_EnableVox(g_vox_threshold[1], g_vox_threshold[0]);
interrupt_mask |= BK4819_REG_3F_VOX_FOUND | BK4819_REG_3F_VOX_LOST;
}
else
@ -848,15 +867,15 @@ void RADIO_setup_registers(bool switch_to_function_foreground)
g_update_status = true;
if (g_eeprom.noaa_auto_scan)
if (g_eeprom.config.setting.noaa_auto_scan)
{
if (g_eeprom.dual_watch != DUAL_WATCH_OFF)
if (g_eeprom.config.setting.dual_watch != DUAL_WATCH_OFF)
{
if (IS_NOT_NOAA_CHANNEL(g_eeprom.screen_channel[0]))
if (IS_NOT_NOAA_CHANNEL(g_eeprom.config.setting.indices.vfo[0].screen))
{
if (IS_NOT_NOAA_CHANNEL(g_eeprom.screen_channel[1]))
if (IS_NOT_NOAA_CHANNEL(g_eeprom.config.setting.indices.vfo[1].screen))
{
g_is_noaa_mode = false;
g_noaa_mode = false;
return;
}
ChanAB = 1;
@ -864,25 +883,25 @@ void RADIO_setup_registers(bool switch_to_function_foreground)
else
ChanAB = 0;
if (!g_is_noaa_mode)
g_noaa_channel = g_eeprom.vfo_info[ChanAB].channel_save - NOAA_CHANNEL_FIRST;
if (!g_noaa_mode)
g_noaa_channel = g_vfo_info[ChanAB].channel_save - NOAA_CHANNEL_FIRST;
g_is_noaa_mode = true;
g_noaa_mode = true;
return;
}
if (g_rx_vfo->channel_save >= NOAA_CHANNEL_FIRST)
{
g_is_noaa_mode = true;
g_noaa_mode = true;
g_noaa_channel = g_rx_vfo->channel_save - NOAA_CHANNEL_FIRST;
g_noaa_tick_10ms = noaa_tick_2_10ms;
g_schedule_noaa = false;
}
else
g_is_noaa_mode = false;
g_noaa_mode = false;
}
else
g_is_noaa_mode = false;
g_noaa_mode = false;
}
#endif
@ -905,7 +924,7 @@ void RADIO_enableTX(const bool fsk_tx)
case BK4819_FILTER_BW_NARROW:
#ifdef ENABLE_AM_FIX
#if 0
// BK4819_SetFilterBandwidth(Bandwidth, g_current_vfo->am_mode > 0 && g_setting_am_fix);
// BK4819_SetFilterBandwidth(Bandwidth, g_current_vfo->am_mode > 0 && g_eeprom.config.setting.am_fix);
BK4819_SetFilterBandwidth(Bandwidth, true);
#else
if (g_current_vfo->am_mode > 1)
@ -980,7 +999,7 @@ void RADIO_set_vfo_state(vfo_state_t State)
}
else
{ // 1of11
const unsigned int vfo = (g_eeprom.cross_vfo_rx_tx == CROSS_BAND_OFF) ? g_eeprom.rx_vfo : g_eeprom.tx_vfo;
const unsigned int vfo = (g_eeprom.config.setting.cross_vfo == CROSS_BAND_OFF) ? g_rx_vfo_num : g_eeprom.config.setting.tx_vfo_num;
g_vfo_state[vfo] = State;
}
@ -995,21 +1014,21 @@ void RADIO_PrepareTX(void)
{
vfo_state_t State = VFO_STATE_NORMAL; // default to OK to TX
if (g_eeprom.dual_watch != DUAL_WATCH_OFF)
if (g_eeprom.config.setting.dual_watch != DUAL_WATCH_OFF)
{ // dual-RX is enabled
#if 0
if (g_rx_vfo_is_active)
{ // use the TX vfo
g_eeprom.rx_vfo = g_eeprom.tx_vfo;
g_rx_vfo = &g_eeprom.vfo_info[g_eeprom.tx_vfo];
g_rx_vfo_num = g_eeprom.config.setting.tx_vfo_num;
g_rx_vfo = &g_vfo_info[g_eeprom.config.setting.tx_vfo_num];
g_rx_vfo_is_active = false;
}
g_current_vfo = g_rx_vfo;
#else
if (!g_rx_vfo_is_active)
{ // use the current RX vfo
g_eeprom.rx_vfo = g_eeprom.tx_vfo;
g_rx_vfo = &g_eeprom.vfo_info[g_eeprom.tx_vfo];
g_rx_vfo_num = g_eeprom.config.setting.tx_vfo_num;
g_rx_vfo = &g_vfo_info[g_eeprom.config.setting.tx_vfo_num];
g_rx_vfo_is_active = true;
}
g_current_vfo = g_rx_vfo;
@ -1027,7 +1046,7 @@ void RADIO_PrepareTX(void)
}
else
#endif
if (!g_setting_tx_enable || g_serial_config_tick_500ms > 0)
if (!g_eeprom.config.setting.tx_enable || g_serial_config_tick_500ms > 0)
{ // TX is disabled or config upload/download in progress
State = VFO_STATE_TX_DISABLE;
}
@ -1086,11 +1105,11 @@ void RADIO_PrepareTX(void)
if (g_alarm_state == ALARM_STATE_OFF)
#endif
{
if (g_eeprom.tx_timeout_timer == 0)
if (g_eeprom.config.setting.tx_timeout == 0)
g_tx_timer_tick_500ms = 60; // 30 sec
else
if (g_eeprom.tx_timeout_timer < (ARRAY_SIZE(g_sub_menu_tx_timeout) - 1))
g_tx_timer_tick_500ms = 120 * g_eeprom.tx_timeout_timer; // minutes
if (g_eeprom.config.setting.tx_timeout < (ARRAY_SIZE(g_sub_menu_tx_timeout) - 1))
g_tx_timer_tick_500ms = 120 * g_eeprom.config.setting.tx_timeout; // minutes
else
g_tx_timer_tick_500ms = 120 * 15; // 15 minutes
}
@ -1148,35 +1167,35 @@ void RADIO_tx_eot(void)
if (g_dtmf_call_state == DTMF_CALL_STATE_NONE &&
(g_current_vfo->dtmf_ptt_id_tx_mode == PTT_ID_TX_DOWN || g_current_vfo->dtmf_ptt_id_tx_mode == PTT_ID_BOTH))
{ // end-of-tx
if (g_eeprom.dtmf_side_tone)
if (g_eeprom.config.setting.dtmf.side_tone)
{
GPIO_SetBit(&GPIOC->DATA, GPIOC_PIN_SPEAKER);
SYSTEM_DelayMs(60);
}
BK4819_EnterDTMF_TX(g_eeprom.dtmf_side_tone);
BK4819_EnterDTMF_TX(g_eeprom.config.setting.dtmf.side_tone);
BK4819_PlayDTMFString(
g_eeprom.dtmf_key_down_code,
g_eeprom.config.setting.dtmf.key_down_code,
0,
g_eeprom.dtmf_first_code_persist_time,
g_eeprom.dtmf_hash_code_persist_time,
g_eeprom.dtmf_code_persist_time,
g_eeprom.dtmf_code_interval_time);
g_eeprom.config.setting.dtmf.first_code_persist_time * 10,
g_eeprom.config.setting.dtmf.hash_code_persist_time * 10,
g_eeprom.config.setting.dtmf.code_persist_time * 10,
g_eeprom.config.setting.dtmf.code_interval_time * 10);
GPIO_ClearBit(&GPIOC->DATA, GPIOC_PIN_SPEAKER);
}
else
if (g_eeprom.roger_mode == ROGER_MODE_ROGER)
if (g_eeprom.config.setting.roger_mode == ROGER_MODE_ROGER)
{
BK4819_PlayRoger();
}
else
#ifdef ENABLE_MDC1200
// if (g_eeprom.roger_mode == ROGER_MODE_MDC)
// if (g_eeprom.config.setting.roger_mode == ROGER_MODE_MDC)
if (g_current_vfo->mdc1200_mode == MDC1200_MODE_EOT || g_current_vfo->mdc1200_mode == MDC1200_MODE_BOTH)
{
BK4819_send_MDC1200(MDC1200_OP_CODE_POST_ID, 0x00, g_eeprom.mdc1200_id);
BK4819_send_MDC1200(MDC1200_OP_CODE_POST_ID, 0x00, g_eeprom.config.setting.mdc1200_id);
}
else
#endif