Merge branch 'batcal'

This commit is contained in:
Krzysiek Egzmont
2023-10-04 18:43:28 +02:00
32 changed files with 962 additions and 800 deletions

View File

@@ -224,19 +224,21 @@ void ACTION_Scan(bool bRestart)
}
}
void ACTION_Vox(void)
{
gEeprom.VOX_SWITCH = !gEeprom.VOX_SWITCH;
gRequestSaveSettings = true;
gFlagReconfigureVfos = true;
#ifdef ENABLE_VOICE
gAnotherVoiceID = VOICE_ID_VOX;
#endif
gUpdateStatus = true;
}
#ifdef ENABLE_VOX
void ACTION_Vox(void)
{
gEeprom.VOX_SWITCH = !gEeprom.VOX_SWITCH;
gRequestSaveSettings = true;
gFlagReconfigureVfos = true;
#ifdef ENABLE_VOICE
gAnotherVoiceID = VOICE_ID_VOX;
#endif
gUpdateStatus = true;
}
#endif
#if defined(ENABLE_ALARM) || defined(ENABLE_TX1750)
static void ACTION_AlarmOr1750(bool b1750)
static void ACTION_AlarmOr1750(const bool b1750)
{
gInputBoxIndex = 0;
@@ -252,7 +254,7 @@ void ACTION_Vox(void)
gFlagPrepareTX = true;
// if (gScreenToDisplay != DISPLAY_MENU) // 1of11 .. don't close the menu
if (gScreenToDisplay != DISPLAY_MENU) // 1of11 .. don't close the menu
gRequestDisplayScreen = DISPLAY_MAIN;
}
#endif
@@ -268,7 +270,9 @@ void ACTION_Vox(void)
FM_TurnOff();
gInputBoxIndex = 0;
gVoxResumeCountdown = 80;
#ifdef ENABLE_VOX
gVoxResumeCountdown = 80;
#endif
gFlagReconfigureVfos = true;
gRequestDisplayScreen = DISPLAY_MAIN;
@@ -369,7 +373,9 @@ void ACTION_Handle(KEY_Code_t Key, bool bKeyPressed, bool bKeyHeld)
ACTION_Scan(true);
break;
case ACTION_OPT_VOX:
ACTION_Vox();
#ifdef ENABLE_VOX
ACTION_Vox();
#endif
break;
case ACTION_OPT_ALARM:
#ifdef ENABLE_ALARM

View File

@@ -23,7 +23,9 @@
void ACTION_Power(void);
void ACTION_Monitor(void);
void ACTION_Scan(bool bFlag);
void ACTION_Vox(void);
#ifdef ENABLE_VOX
void ACTION_Vox(void);
#endif
#ifdef ENABLE_ALARM
//static void ACTION_AlarmOr1750(bool b1750)
#endif

281
app/app.c
View File

@@ -486,7 +486,7 @@ void APP_StartListening(FUNCTION_Type_t Function, const bool reset_am_fix)
gEnableSpeaker = true;
if (gSetting_backlight_on_rx)
if (gSetting_backlight_on_tx_rx >= 2)
BACKLIGHT_TurnOn();
if (gScanState != SCAN_OFF)
@@ -519,6 +519,7 @@ void APP_StartListening(FUNCTION_Type_t Function, const bool reset_am_fix)
gRxVfo->pRX->Frequency = NoaaFrequencyTable[gNoaaChannel];
gRxVfo->pTX->Frequency = NoaaFrequencyTable[gNoaaChannel];
gEeprom.ScreenChannel[chan] = gRxVfo->CHANNEL_SAVE;
gNOAA_Countdown_10ms = 500; // 5 sec
gScheduleNOAA = false;
}
@@ -543,7 +544,7 @@ void APP_StartListening(FUNCTION_Type_t Function, const bool reset_am_fix)
}
{ // RF RX front end gain
// original setting
uint16_t lna_short = orig_lna_short;
uint16_t lna = orig_lna;
@@ -574,9 +575,9 @@ void APP_StartListening(FUNCTION_Type_t Function, const bool reset_am_fix)
(gEeprom.DAC_GAIN << 0)); // AF DAC Gain (after Gain-1 and Gain-2)
#ifdef ENABLE_VOICE
// if (gVoiceWriteIndex == 0)
if (gVoiceWriteIndex == 0) // AM/FM RX mode will be set when the voice has finished
#endif
BK4819_SetAF(gRxVfo->AM_mode ? BK4819_AF_AM : BK4819_AF_OPEN);
BK4819_SetAF(gRxVfo->AM_mode ? BK4819_AF_AM : BK4819_AF_FM); // no need, set it now
FUNCTION_Select(Function);
@@ -630,7 +631,7 @@ static void FREQ_NextChannel(void)
RADIO_SetupRegisters(true);
// ScanPauseDelayIn_10ms = scan_pause_delay_in_6_10ms;
ScanPauseDelayIn_10ms = 10; // 100ms
ScanPauseDelayIn_10ms = 10; // 100ms .. it don't like any faster :(
bScanKeepFrequency = false;
gUpdateDisplay = true;
@@ -671,9 +672,7 @@ static void MR_NextChannel(void)
// if (gEeprom.DUAL_WATCH != DUAL_WATCH_OFF)
{
// chan = (gEeprom.RX_CHANNEL + 1) & 1u;
// chan = gEeprom.MrChannel[chan];
// chan = gEeprom.ScreenChannel[chan];
// chan = gEeprom.VfoInfo[chan].CHANNEL_SAVE;
// chan = 14;
// if (RADIO_CheckValidChannel(chan, false, 0))
// {
@@ -851,36 +850,38 @@ void APP_CheckRadioInterrupts(void)
if (interrupt_status_bits & BK4819_REG_02_CTCSS_FOUND)
g_CTCSS_Lost = false;
if (interrupt_status_bits & BK4819_REG_02_VOX_LOST)
{
g_VOX_Lost = true;
gVoxPauseCountdown = 10;
if (gEeprom.VOX_SWITCH)
#ifdef ENABLE_VOX
if (interrupt_status_bits & BK4819_REG_02_VOX_LOST)
{
if (gCurrentFunction == FUNCTION_POWER_SAVE && !gRxIdleMode)
g_VOX_Lost = true;
gVoxPauseCountdown = 10;
if (gEeprom.VOX_SWITCH)
{
gPowerSave_10ms = power_save2_10ms;
gPowerSaveCountdownExpired = 0;
}
if (gEeprom.DUAL_WATCH != DUAL_WATCH_OFF && (gScheduleDualWatch || gDualWatchCountdown_10ms < dual_watch_count_after_vox_10ms))
{
gDualWatchCountdown_10ms = dual_watch_count_after_vox_10ms;
gScheduleDualWatch = false;
// let the user see DW is not active
gDualWatchActive = false;
gUpdateStatus = true;
if (gCurrentFunction == FUNCTION_POWER_SAVE && !gRxIdleMode)
{
gPowerSave_10ms = power_save2_10ms;
gPowerSaveCountdownExpired = 0;
}
if (gEeprom.DUAL_WATCH != DUAL_WATCH_OFF && (gScheduleDualWatch || gDualWatchCountdown_10ms < dual_watch_count_after_vox_10ms))
{
gDualWatchCountdown_10ms = dual_watch_count_after_vox_10ms;
gScheduleDualWatch = false;
// let the user see DW is not active
gDualWatchActive = false;
gUpdateStatus = true;
}
}
}
}
if (interrupt_status_bits & BK4819_REG_02_VOX_FOUND)
{
g_VOX_Lost = false;
gVoxPauseCountdown = 0;
}
if (interrupt_status_bits & BK4819_REG_02_VOX_FOUND)
{
g_VOX_Lost = false;
gVoxPauseCountdown = 0;
}
#endif
if (interrupt_status_bits & BK4819_REG_02_SQUELCH_LOST)
{
@@ -935,83 +936,85 @@ void APP_EndTransmission(void)
RADIO_SetupRegisters(false);
}
static void APP_HandleVox(void)
{
if (gSetting_KILLED)
return;
if (gVoxResumeCountdown == 0)
#ifdef ENABLE_VOX
static void APP_HandleVox(void)
{
if (gVoxPauseCountdown)
if (gSetting_KILLED)
return;
}
else
{
g_VOX_Lost = false;
gVoxPauseCountdown = 0;
}
#ifdef ENABLE_FMRADIO
if (gFmRadioMode)
return;
#endif
if (gCurrentFunction == FUNCTION_RECEIVE || gCurrentFunction == FUNCTION_MONITOR)
return;
if (gScanState != SCAN_OFF || gCssScanMode != CSS_SCAN_MODE_OFF)
return;
if (gVOX_NoiseDetected)
{
if (g_VOX_Lost)
gVoxStopCountdown_10ms = vox_stop_count_down_10ms;
else
if (gVoxStopCountdown_10ms == 0)
gVOX_NoiseDetected = false;
if (gCurrentFunction == FUNCTION_TRANSMIT && !gPttIsPressed && !gVOX_NoiseDetected)
if (gVoxResumeCountdown == 0)
{
if (gFlagEndTransmission)
{
//if (gCurrentFunction != FUNCTION_FOREGROUND)
FUNCTION_Select(FUNCTION_FOREGROUND);
}
if (gVoxPauseCountdown)
return;
}
else
{
g_VOX_Lost = false;
gVoxPauseCountdown = 0;
}
#ifdef ENABLE_FMRADIO
if (gFmRadioMode)
return;
#endif
if (gCurrentFunction == FUNCTION_RECEIVE || gCurrentFunction == FUNCTION_MONITOR)
return;
if (gScanState != SCAN_OFF || gCssScanMode != CSS_SCAN_MODE_OFF)
return;
if (gVOX_NoiseDetected)
{
if (g_VOX_Lost)
gVoxStopCountdown_10ms = vox_stop_count_down_10ms;
else
if (gVoxStopCountdown_10ms == 0)
gVOX_NoiseDetected = false;
if (gCurrentFunction == FUNCTION_TRANSMIT && !gPttIsPressed && !gVOX_NoiseDetected)
{
APP_EndTransmission();
if (gEeprom.REPEATER_TAIL_TONE_ELIMINATION == 0)
if (gFlagEndTransmission)
{
//if (gCurrentFunction != FUNCTION_FOREGROUND)
FUNCTION_Select(FUNCTION_FOREGROUND);
}
else
gRTTECountdown = gEeprom.REPEATER_TAIL_TONE_ELIMINATION * 10;
{
APP_EndTransmission();
if (gEeprom.REPEATER_TAIL_TONE_ELIMINATION == 0)
{
//if (gCurrentFunction != FUNCTION_FOREGROUND)
FUNCTION_Select(FUNCTION_FOREGROUND);
}
else
gRTTECountdown = gEeprom.REPEATER_TAIL_TONE_ELIMINATION * 10;
}
gUpdateStatus = true;
gUpdateDisplay = true;
gFlagEndTransmission = false;
}
gUpdateStatus = true;
gUpdateDisplay = true;
gFlagEndTransmission = false;
return;
}
return;
}
if (g_VOX_Lost)
{
gVOX_NoiseDetected = true;
if (gCurrentFunction == FUNCTION_POWER_SAVE)
FUNCTION_Select(FUNCTION_FOREGROUND);
if (gCurrentFunction != FUNCTION_TRANSMIT && gSerialConfigCountDown_500ms == 0)
if (g_VOX_Lost)
{
gDTMF_ReplyState = DTMF_REPLY_NONE;
RADIO_PrepareTX();
gUpdateDisplay = true;
gVOX_NoiseDetected = true;
if (gCurrentFunction == FUNCTION_POWER_SAVE)
FUNCTION_Select(FUNCTION_FOREGROUND);
if (gCurrentFunction != FUNCTION_TRANSMIT && gSerialConfigCountDown_500ms == 0)
{
gDTMF_ReplyState = DTMF_REPLY_NONE;
RADIO_PrepareTX();
gUpdateDisplay = true;
}
}
}
}
#endif
void APP_Update(void)
{
@@ -1145,8 +1148,10 @@ void APP_Update(void)
}
#endif
if (gEeprom.VOX_SWITCH)
APP_HandleVox();
#ifdef ENABLE_VOX
if (gEeprom.VOX_SWITCH)
APP_HandleVox();
#endif
if (gSchedulePowerSave)
{
@@ -1211,10 +1216,14 @@ void APP_Update(void)
{
BK4819_Conditional_RX_TurnOn_and_GPIO6_Enable();
if (gEeprom.VOX_SWITCH)
BK4819_EnableVox(gEeprom.VOX1_THRESHOLD, gEeprom.VOX0_THRESHOLD);
#ifdef ENABLE_VOX
if (gEeprom.VOX_SWITCH)
BK4819_EnableVox(gEeprom.VOX1_THRESHOLD, gEeprom.VOX0_THRESHOLD);
#endif
if (gEeprom.DUAL_WATCH != DUAL_WATCH_OFF && gScanState == SCAN_OFF && gCssScanMode == CSS_SCAN_MODE_OFF)
if (gEeprom.DUAL_WATCH != DUAL_WATCH_OFF &&
gScanState == SCAN_OFF &&
gCssScanMode == CSS_SCAN_MODE_OFF)
{ // dual watch mode, toggle between the two VFO's
DUALWATCH_Alternate();
@@ -1390,7 +1399,8 @@ void APP_TimeSlice10ms(void)
#endif
#ifdef ENABLE_AM_FIX
if (gEeprom.VfoInfo[gEeprom.RX_CHANNEL].AM_mode && gSetting_AM_fix)
// if (gEeprom.VfoInfo[gEeprom.RX_CHANNEL].AM_mode && gSetting_AM_fix)
if (gRxVfo->AM_mode && gSetting_AM_fix)
AM_fix_10ms(gEeprom.RX_CHANNEL);
#endif
@@ -1445,11 +1455,13 @@ void APP_TimeSlice10ms(void)
if (gFlashLightState == FLASHLIGHT_BLINK && (gFlashLightBlinkCounter & 15u) == 0)
GPIO_FlipBit(&GPIOC->DATA, GPIOC_PIN_FLASHLIGHT);
if (gVoxResumeCountdown > 0)
gVoxResumeCountdown--;
if (gVoxPauseCountdown > 0)
gVoxPauseCountdown--;
#ifdef ENABLE_VOX
if (gVoxResumeCountdown > 0)
gVoxResumeCountdown--;
if (gVoxPauseCountdown > 0)
gVoxPauseCountdown--;
#endif
if (gCurrentFunction == FUNCTION_TRANSMIT)
{
@@ -1985,6 +1997,7 @@ void APP_TimeSlice500ms(void)
static void ALARM_Off(void)
{
gAlarmState = ALARM_STATE_OFF;
GPIO_ClearBit(&GPIOC->DATA, GPIOC_PIN_AUDIO_PATH);
gEnableSpeaker = false;
@@ -1994,13 +2007,15 @@ void APP_TimeSlice500ms(void)
RADIO_EnableCxCSS();
}
gVoxResumeCountdown = 80;
#ifdef ENABLE_VOX
gVoxResumeCountdown = 80;
#endif
SYSTEM_DelayMs(5);
RADIO_SetupRegisters(true);
// if (gScreenToDisplay != DISPLAY_MENU) // 1of11 .. don't close the menu
if (gScreenToDisplay != DISPLAY_MENU) // 1of11 .. don't close the menu
gRequestDisplayScreen = DISPLAY_MAIN;
}
#endif
@@ -2054,17 +2069,6 @@ static void APP_ProcessKey(KEY_Code_t Key, bool bKeyPressed, bool bKeyHeld)
if (gEeprom.AUTO_KEYPAD_LOCK)
gKeyLockCountdown = 30; // 15 seconds
if (Key == KEY_EXIT && bKeyPressed && bKeyHeld && gDTMF_RX_live[0] != 0)
{ // clear the live DTMF decoder if the EXIT key is held
if (gDTMF_RX_live[0] != 0)
{
gDTMF_RX_live_timeout = 0;
memset(gDTMF_RX_live, 0, sizeof(gDTMF_RX_live));
gUpdateDisplay = true;
}
}
if (!bKeyPressed)
{
if (gFlagSaveVfo)
@@ -2100,11 +2104,24 @@ static void APP_ProcessKey(KEY_Code_t Key, bool bKeyPressed, bool bKeyHeld)
}
else
{
if (Key != KEY_PTT)
BACKLIGHT_TurnOn();
if (Key == KEY_EXIT && bKeyHeld)
{ // exit key held pressed
// clear the live DTMF decoder
if (gDTMF_RX_live[0] != 0)
{
memset(gDTMF_RX_live, 0, sizeof(gDTMF_RX_live));
gDTMF_RX_live_timeout = 0;
gUpdateDisplay = true;
}
}
if (gScreenToDisplay == DISPLAY_MENU) // 1of11
gMenuCountdown = menu_timeout_500ms;
BACKLIGHT_TurnOn();
if (gDTMF_DecodeRingCountdown_500ms > 0)
{ // cancel the ringing
gDTMF_DecodeRingCountdown_500ms = 0;
@@ -2161,24 +2178,27 @@ static void APP_ProcessKey(KEY_Code_t Key, bool bKeyPressed, bool bKeyHeld)
Key != KEY_MENU)
{
if (gScanState != SCAN_OFF || gCssScanMode != CSS_SCAN_MODE_OFF)
{ // frequency or CTCSS/DCS scanning
{ // FREQ/CTCSS/DCS scanning
if (bKeyPressed && !bKeyHeld)
AUDIO_PlayBeep(BEEP_500HZ_60MS_DOUBLE_BEEP_OPTIONAL);
return;
}
}
if (gPttWasPressed && Key == KEY_PTT)
if (Key == KEY_PTT)
{
bFlag = bKeyHeld;
if (!bKeyPressed)
if (gPttWasPressed)
{
bFlag = true;
gPttWasPressed = false;
bFlag = bKeyHeld;
if (!bKeyPressed)
{
bFlag = true;
gPttWasPressed = false;
}
}
}
if (gPttWasReleased && Key != KEY_PTT)
else
if (gPttWasReleased)
{
if (bKeyHeld)
bFlag = true;
@@ -2260,10 +2280,12 @@ static void APP_ProcessKey(KEY_Code_t Key, bool bKeyPressed, bool bKeyHeld)
}
#if defined(ENABLE_ALARM) || defined(ENABLE_TX1750)
else
if (!bKeyHeld && bKeyPressed)
if ((!bKeyHeld && bKeyPressed) || (gAlarmState == ALARM_STATE_TX1750 && bKeyHeld && !bKeyPressed))
{
ALARM_Off();
// TODO: fix side key 1750, you have to press it twice to restart the tone :(
if (gEeprom.REPEATER_TAIL_TONE_ELIMINATION == 0)
{
//if (gCurrentFunction != FUNCTION_FOREGROUND)
@@ -2275,6 +2297,7 @@ static void APP_ProcessKey(KEY_Code_t Key, bool bKeyPressed, bool bKeyHeld)
if (Key == KEY_PTT)
gPttWasPressed = true;
else
if (!bKeyHeld)
gPttWasReleased = true;
}
#endif

View File

@@ -127,7 +127,9 @@ void GENERIC_Key_PTT(bool bKeyPressed)
}
gFlagEndTransmission = false;
gVOX_NoiseDetected = false;
#ifdef ENABLE_VOX
gVOX_NoiseDetected = false;
#endif
}
RADIO_SetVfoState(VFO_STATE_NORMAL);

View File

@@ -28,6 +28,7 @@
#include "app/spectrum.h"
#endif
#include "audio.h"
#include "board.h"
#include "driver/bk4819.h"
#include "dtmf.h"
#include "frequencies.h"
@@ -101,11 +102,11 @@ static void processFKeyFunction(const KEY_Code_t Key, const bool beep)
if (gEeprom.DUAL_WATCH == DUAL_WATCH_CHAN_B)
gEeprom.DUAL_WATCH = DUAL_WATCH_CHAN_A;
else
gEeprom.TX_CHANNEL = (Vfo == 0);
gEeprom.TX_CHANNEL = (Vfo + 1) & 1u;
gRequestSaveSettings = 1;
gFlagReconfigureVfos = true;
gRequestDisplayScreen = DISPLAY_MAIN;
if (beep)
@@ -123,7 +124,7 @@ static void processFKeyFunction(const KEY_Code_t Key, const bool beep)
uint8_t Channel;
if (IS_MR_CHANNEL(gTxVfo->CHANNEL_SAVE))
{
{ // swap to frequency mode
gEeprom.ScreenChannel[Vfo] = gEeprom.FreqChannel[gEeprom.TX_CHANNEL];
#ifdef ENABLE_VOICE
gAnotherVoiceID = VOICE_ID_FREQUENCY_MODE;
@@ -135,7 +136,7 @@ static void processFKeyFunction(const KEY_Code_t Key, const bool beep)
Channel = RADIO_FindNextChannel(gEeprom.MrChannel[gEeprom.TX_CHANNEL], 1, false, 0);
if (Channel != 0xFF)
{
{ // swap to channel mode
gEeprom.ScreenChannel[Vfo] = Channel;
#ifdef ENABLE_VOICE
AUDIO_SetVoiceID(0, VOICE_ID_CHANNEL_MODE);
@@ -217,7 +218,15 @@ static void processFKeyFunction(const KEY_Code_t Key, const bool beep)
break;
case KEY_7:
ACTION_Vox();
#ifdef ENABLE_VOX
ACTION_Vox();
#else
// TODO: make use of the function key press
#endif
break;
case KEY_8:
@@ -307,7 +316,7 @@ static void MAIN_Key_DIGITS(KEY_Code_t Key, bool bKeyPressed, bool bKeyHeld)
if (IS_MR_CHANNEL(gTxVfo->CHANNEL_SAVE))
{ // user is entering channel number
uint16_t Channel;
if (gInputBoxIndex != 3)
@@ -346,7 +355,7 @@ static void MAIN_Key_DIGITS(KEY_Code_t Key, bool bKeyPressed, bool bKeyHeld)
// #endif
if (IS_FREQ_CHANNEL(gTxVfo->CHANNEL_SAVE))
{ // user is entering frequency
uint32_t Frequency;
if (gInputBoxIndex < 6)
@@ -378,7 +387,7 @@ static void MAIN_Key_DIGITS(KEY_Code_t Key, bool bKeyPressed, bool bKeyHeld)
{
Frequency = frequencyBandTable[ARRAY_SIZE(frequencyBandTable) - 1].upper;
}
{
const FREQUENCY_Band_t band = FREQUENCY_GetBand(Frequency);
@@ -391,35 +400,35 @@ static void MAIN_Key_DIGITS(KEY_Code_t Key, bool bKeyPressed, bool bKeyHeld)
gTxVfo->Band = band;
gEeprom.ScreenChannel[Vfo] = band + FREQ_CHANNEL_FIRST;
gEeprom.FreqChannel[Vfo] = band + FREQ_CHANNEL_FIRST;
SETTINGS_SaveVfoIndices();
RADIO_ConfigureChannel(Vfo, VFO_CONFIGURE_RELOAD);
}
// Frequency += 75; // is this meant to be rounding ?
Frequency += gTxVfo->StepFrequency / 2; // no idea, but this is
Frequency = FREQUENCY_FloorToStep(Frequency, gTxVfo->StepFrequency, frequencyBandTable[gTxVfo->Band].lower);
if (Frequency >= BX4819_band1.upper && Frequency < BX4819_band2.lower)
{ // clamp the frequency to the limit
const uint32_t center = (BX4819_band1.upper + BX4819_band2.lower) / 2;
Frequency = (Frequency < center) ? BX4819_band1.upper - gTxVfo->StepFrequency : BX4819_band2.lower;
}
gTxVfo->freq_config_RX.Frequency = Frequency;
gRequestSaveChannel = 1;
return;
}
}
#ifdef ENABLE_NOAA
else
if (IS_NOAA_CHANNEL(gTxVfo->CHANNEL_SAVE))
{ // user is entering NOAA channel
uint8_t Channel;
if (gInputBoxIndex != 2)
@@ -532,7 +541,8 @@ static void MAIN_Key_MENU(const bool bKeyPressed, const bool bKeyHeld)
{ // menu key held down (long press)
if (bKeyPressed)
{
{ // long press MENU key
if (gScreenToDisplay == DISPLAY_MAIN)
{
if (gInputBoxIndex > 0)
@@ -544,34 +554,28 @@ static void MAIN_Key_MENU(const bool bKeyPressed, const bool bKeyHeld)
gWasFKeyPressed = false;
gUpdateStatus = true;
// TODO: long press M-key
#ifdef ENABLE_COPY_CHAN_TO_VFO
if (gEeprom.VFO_OPEN &&
gEeprom.DUAL_WATCH == DUAL_WATCH_OFF &&
gScanState == SCAN_OFF &&
gCssScanMode == CSS_SCAN_MODE_OFF)
{ // copy channel to VFO
int channel = -1;
int vfo = -1;
//int selected = -1;
if (IS_FREQ_CHANNEL(gRxVfo->CHANNEL_SAVE))
{ // VFO mode
if (IS_MR_CHANNEL(gTxVfo->CHANNEL_SAVE))
{ // other VFO is in channel mode
channel = gTxVfo->CHANNEL_SAVE;
vfo = gRxVfo->CHANNEL_SAVE;
}
if (IS_FREQ_CHANNEL(gEeprom.ScreenChannel[0]) &&
IS_MR_CHANNEL(gEeprom.ScreenChannel[1]))
{
channel = gEeprom.ScreenChannel[1];
vfo = 0;
}
else
if (IS_FREQ_CHANNEL(gTxVfo->CHANNEL_SAVE))
{ // VFO mode
if (IS_MR_CHANNEL(gRxVfo->CHANNEL_SAVE))
{ // other VFO is in channel mode
channel = gRxVfo->CHANNEL_SAVE;
vfo = gTxVfo->CHANNEL_SAVE;
}
if (IS_FREQ_CHANNEL(gEeprom.ScreenChannel[1]) &&
IS_MR_CHANNEL(gEeprom.ScreenChannel[0]))
{
channel = gEeprom.ScreenChannel[0];
vfo = 1;
}
if (channel >= 0 && vfo >= 0)
@@ -579,15 +583,29 @@ static void MAIN_Key_MENU(const bool bKeyPressed, const bool bKeyHeld)
gBeepToPlay = BEEP_1KHZ_60MS_OPTIONAL;
gEeprom.MrChannel[vfo] = channel;
gEeprom.ScreenChannel[vfo] = channel;
RADIO_ConfigureChannel(vfo, VFO_CONFIGURE_RELOAD);
// TODO: finish this
channel = FREQ_CHANNEL_FIRST + gEeprom.VfoInfo[vfo].Band;
gEeprom.MrChannel[vfo] = channel;
gEeprom.ScreenChannel[vfo] = channel;
gEeprom.VfoInfo[vfo].CHANNEL_SAVE = channel;
//gEeprom.RX_CHANNEL = () & 1; // swap to the VFO
// swap to the VFO
gEeprom.TX_CHANNEL = vfo;
gEeprom.RX_CHANNEL = vfo;
RADIO_SelectVfos();
RADIO_ApplyOffset(gRxVfo);
RADIO_ConfigureSquelchAndOutputPower(gRxVfo);
// gRequestSaveVFO = true;
// gVfoConfigureMode = VFO_CONFIGURE_RELOAD;
// gRequestDisplayScreen = DISPLAY_MAIN;
RADIO_SetupRegisters(true);
// SETTINGS_SaveChannel(gRxVfo->CHANNEL_SAVE, gEeprom.RX_CHANNEL, gRxVfo, 1);
gUpdateStatus = true;
gUpdateDisplay = true;
}
}
#endif
@@ -604,7 +622,7 @@ static void MAIN_Key_MENU(const bool bKeyPressed, const bool bKeyHeld)
gInputBoxIndex = 0;
gBeepToPlay = BEEP_1KHZ_60MS_OPTIONAL;
if (bFlag)
{
gFlagRefreshSetting = true;
@@ -655,7 +673,7 @@ static void MAIN_Key_STAR(bool bKeyPressed, bool bKeyHeld)
gDTMF_InputMode = true;
memmove(gDTMF_InputBox, gDTMF_String, sizeof(gDTMF_InputBox));
gDTMF_InputIndex = 0;
gRequestDisplayScreen = DISPLAY_MAIN;
return;
}
@@ -750,7 +768,7 @@ static void MAIN_Key_UP_DOWN(bool bKeyPressed, bool bKeyHeld, int8_t Direction)
}
gTxVfo->freq_config_RX.Frequency = frequency;
gRequestSaveChannel = 1;
return;
}

View File

@@ -47,26 +47,33 @@
#define ARRAY_SIZE(x) (sizeof(x) / sizeof(x[0]))
#endif
void writeXtalFreqCal(const int32_t value)
{
struct
#ifdef ENABLE_F_CAL_MENU
void writeXtalFreqCal(const int32_t value, const bool update_eeprom)
{
int16_t BK4819_XtalFreqLow;
uint16_t EEPROM_1F8A;
uint16_t EEPROM_1F8C;
uint8_t VOLUME_GAIN;
uint8_t DAC_GAIN;
} __attribute__((packed)) Misc;
gEeprom.BK4819_XTAL_FREQ_LOW = value;
BK4819_WriteRegister(BK4819_REG_3B, 22656 + gEeprom.BK4819_XTAL_FREQ_LOW);
// radio 1 .. 04 00 46 00 50 00 2C 0E
// radio 2 .. 05 00 46 00 50 00 2C 0E
EEPROM_ReadBuffer(0x1F88, &Misc, 8);
Misc.BK4819_XtalFreqLow = gEeprom.BK4819_XTAL_FREQ_LOW;
EEPROM_WriteBuffer(0x1F88, &Misc);
}
BK4819_WriteRegister(BK4819_REG_3B, 22656 + value);
if (update_eeprom)
{
struct
{
int16_t BK4819_XtalFreqLow;
uint16_t EEPROM_1F8A;
uint16_t EEPROM_1F8C;
uint8_t VOLUME_GAIN;
uint8_t DAC_GAIN;
} __attribute__((packed)) misc;
gEeprom.BK4819_XTAL_FREQ_LOW = value;
// radio 1 .. 04 00 46 00 50 00 2C 0E
// radio 2 .. 05 00 46 00 50 00 2C 0E
//
EEPROM_ReadBuffer(0x1F88, &misc, 8);
misc.BK4819_XtalFreqLow = value;
EEPROM_WriteBuffer(0x1F88, &misc);
}
}
#endif
void MENU_StartCssScan(int8_t Direction)
{
@@ -192,12 +199,11 @@ int MENU_GetLimits(uint8_t Cursor, int32_t *pMin, int32_t *pMax)
*pMax = ARRAY_SIZE(gSubMenu_RESET) - 1;
break;
#ifdef ENABLE_COMPANDER
case MENU_COMPAND:
*pMin = 0;
*pMax = ARRAY_SIZE(gSubMenu_Compand) - 1;
break;
#endif
case MENU_COMPAND:
case MENU_ABR_ON_TX_RX:
*pMin = 0;
*pMax = ARRAY_SIZE(gSubMenu_RX_TX) - 1;
break;
#ifdef ENABLE_AM_FIX_TEST1
case MENU_AM_FIX_TEST1:
@@ -212,7 +218,6 @@ int MENU_GetLimits(uint8_t Cursor, int32_t *pMin, int32_t *pMax)
#ifdef ENABLE_AUDIO_BAR
case MENU_MIC_BAR:
#endif
case MENU_ABR_ON_RX:
case MENU_BCL:
case MENU_BEEP:
case MENU_AUTOLK:
@@ -246,7 +251,9 @@ int MENU_GetLimits(uint8_t Cursor, int32_t *pMin, int32_t *pMax)
*pMax = ARRAY_SIZE(gSubMenu_TOT) - 1;
break;
case MENU_VOX:
#ifdef ENABLE_VOX
case MENU_VOX:
#endif
case MENU_RP_STE:
*pMin = 0;
*pMax = 10;
@@ -291,11 +298,6 @@ int MENU_GetLimits(uint8_t Cursor, int32_t *pMin, int32_t *pMax)
*pMax = ARRAY_SIZE(gSubMenu_PTT_ID) - 1;
break;
case MENU_VOL:
*pMin = 0;
*pMax = 2300;
break;
case MENU_BAT_TXT:
*pMin = 0;
*pMax = ARRAY_SIZE(gSubMenu_BAT_TXT) - 1;
@@ -497,21 +499,23 @@ void MENU_AcceptSetting(void)
gEeprom.BATTERY_SAVE = gSubMenuSelection;
break;
case MENU_VOX:
gEeprom.VOX_SWITCH = gSubMenuSelection != 0;
if (gEeprom.VOX_SWITCH)
gEeprom.VOX_LEVEL = gSubMenuSelection - 1;
BOARD_EEPROM_LoadMoreSettings();
gFlagReconfigureVfos = true;
gUpdateStatus = true;
break;
#ifdef ENABLE_VOX
case MENU_VOX:
gEeprom.VOX_SWITCH = gSubMenuSelection != 0;
if (gEeprom.VOX_SWITCH)
gEeprom.VOX_LEVEL = gSubMenuSelection - 1;
BOARD_EEPROM_LoadMoreSettings();
gFlagReconfigureVfos = true;
gUpdateStatus = true;
break;
#endif
case MENU_ABR:
gEeprom.BACKLIGHT = gSubMenuSelection;
break;
case MENU_ABR_ON_RX:
gSetting_backlight_on_rx = gSubMenuSelection;
case MENU_ABR_ON_TX_RX:
gSetting_backlight_on_tx_rx = gSubMenuSelection;
break;
case MENU_TDR:
@@ -595,15 +599,13 @@ void MENU_AcceptSetting(void)
break;
#endif
#ifdef ENABLE_COMPANDER
case MENU_COMPAND:
gTxVfo->Compander = gSubMenuSelection;
SETTINGS_UpdateChannel(gTxVfo->CHANNEL_SAVE, gTxVfo, true);
gVfoConfigureMode = VFO_CONFIGURE;
gFlagResetVfos = true;
// gRequestSaveChannel = 1;
return;
#endif
case MENU_COMPAND:
gTxVfo->Compander = gSubMenuSelection;
SETTINGS_UpdateChannel(gTxVfo->CHANNEL_SAVE, gTxVfo, true);
gVfoConfigureMode = VFO_CONFIGURE;
gFlagResetVfos = true;
// gRequestSaveChannel = 1;
return;
case MENU_1_CALL:
gEeprom.CHAN_1_CALL = gSubMenuSelection;
@@ -640,12 +642,6 @@ void MENU_AcceptSetting(void)
gRequestSaveChannel = 1;
return;
case MENU_VOL:
if(gF_LOCK) {
EEPROM_WriteBuffer(0x1F40, gBatteryCalibration);
}
break;
case MENU_BAT_TXT:
gSetting_battery_text = gSubMenuSelection;
break;
@@ -757,13 +753,23 @@ void MENU_AcceptSetting(void)
#ifdef ENABLE_F_CAL_MENU
case MENU_F_CALI:
writeXtalFreqCal(gSubMenuSelection);
writeXtalFreqCal(gSubMenuSelection, true);
return;
#endif
case MENU_BATCAL:
gBatteryCalibration[3] = gSubMenuSelection;
gBatteryCalibration[0] = 520*gSubMenuSelection/760; //5.2V empty, blinking above this value, reduced functionality below
gBatteryCalibration[1] = 700*gSubMenuSelection/760; // 7V, ~5%, 1 bars above this value
gBatteryCalibration[2] = 745*gSubMenuSelection/760; // 7.45V, ~17%, 2 bars above this value
gBatteryCalibration[3] = gSubMenuSelection; // 7.6V, ~29%, 3 bars above this value
gBatteryCalibration[4] = 788*gSubMenuSelection/760; // 7.88V, ~65% 4 bars above this value
gBatteryCalibration[5] = 2300;
EEPROM_WriteBuffer(0x1F40, gBatteryCalibration);
uint16_t buf[4];
EEPROM_ReadBuffer(0x1F48, buf, sizeof(buf));
buf[0] = gBatteryCalibration[4];
buf[1] = gBatteryCalibration[5];
EEPROM_WriteBuffer(0x1F48, buf);
break;
}
@@ -921,10 +927,12 @@ void MENU_ShowCurrentSetting(void)
gSubMenuSelection = gEeprom.BATTERY_SAVE;
break;
case MENU_VOX:
gSubMenuSelection = gEeprom.VOX_SWITCH ? gEeprom.VOX_LEVEL + 1 : 0;
break;
#ifdef ENABLE_VOX
case MENU_VOX:
gSubMenuSelection = gEeprom.VOX_SWITCH ? gEeprom.VOX_LEVEL + 1 : 0;
break;
#endif
case MENU_ABR:
gSubMenuSelection = gEeprom.BACKLIGHT;
@@ -932,8 +940,8 @@ void MENU_ShowCurrentSetting(void)
GPIO_SetBit(&GPIOB->DATA, GPIOB_PIN_BACKLIGHT); // turn the backlight ON while in backlight menu
break;
case MENU_ABR_ON_RX:
gSubMenuSelection = gSetting_backlight_on_rx;
case MENU_ABR_ON_TX_RX:
gSubMenuSelection = gSetting_backlight_on_tx_rx;
break;
case MENU_TDR:
@@ -996,11 +1004,9 @@ void MENU_ShowCurrentSetting(void)
break;
#endif
#ifdef ENABLE_COMPANDER
case MENU_COMPAND:
gSubMenuSelection = gTxVfo->Compander;
return;
#endif
case MENU_COMPAND:
gSubMenuSelection = gTxVfo->Compander;
return;
case MENU_1_CALL:
gSubMenuSelection = gEeprom.CHAN_1_CALL;
@@ -1044,10 +1050,6 @@ void MENU_ShowCurrentSetting(void)
gSubMenuSelection = gTxVfo->DTMF_PTT_ID_TX_MODE;
break;
case MENU_VOL:
gSubMenuSelection = gBatteryCalibration[3];
return;
case MENU_BAT_TXT:
gSubMenuSelection = gSetting_battery_text;
return;

View File

@@ -19,6 +19,10 @@
#include "driver/keyboard.h"
#ifdef ENABLE_F_CAL_MENU
void writeXtalFreqCal(const int32_t value, const bool update_eeprom);
#endif
int MENU_GetLimits(uint8_t Cursor, int32_t *pMin, int32_t *pMax);
void MENU_AcceptSetting(void);
void MENU_SelectNextCode(void);

View File

@@ -412,7 +412,9 @@ void SCANNER_Start(void)
g_CDCSS_Lost = false;
gCDCSSCodeType = 0;
g_CTCSS_Lost = false;
g_VOX_Lost = false;
#ifdef ENABLE_VOX
g_VOX_Lost = false;
#endif
g_SquelchLost = false;
gScannerEditState = 0;
gScanProgressIndicator = 0;