Some cleanups.

This commit is contained in:
Dual Tachyon 2023-09-01 00:49:14 +01:00
parent d91d9d65f4
commit 2cd891271b
14 changed files with 84 additions and 76 deletions

View File

@ -273,7 +273,7 @@ void FUN_000052f0(void)
GPIO_ClearBit(&GPIOC->DATA, GPIOC_PIN_AUDIO_PATH);
g_20000342 = 20;
gSystickFlag10 = false;
g_2000036B = 0;
gEnableSpeaker = false;
g_20000377 = 1;
}
break;
@ -310,7 +310,7 @@ void APP_StartListening(FUNCTION_Type_t Function)
}
gVFO_RSSI_Level[gEeprom.RX_CHANNEL == 0] = 0;
GPIO_SetBit(&GPIOC->DATA, GPIOC_PIN_AUDIO_PATH);
g_2000036B = 1;
gEnableSpeaker = true;
BACKLIGHT_TurnOn();
if (gStepDirection) {
switch (gEeprom.SCAN_RESUME_MODE) {
@ -490,7 +490,7 @@ void APP_PlayFM(void)
gEeprom.FM_SelectedFrequency = gEeprom.FM_FrequencyPlaying;
}
GPIO_SetBit(&GPIOC->DATA, GPIOC_PIN_AUDIO_PATH);
g_2000036B = 1;
gEnableSpeaker = true;
} else {
if (gFM_ChannelPosition < 20) {
gFM_Channels[gFM_ChannelPosition++] = gEeprom.FM_FrequencyPlaying;
@ -523,7 +523,7 @@ void APP_StartFM(void)
g_2000038E = 0;
BK1080_Init(gEeprom.FM_FrequencyPlaying, true);
GPIO_SetBit(&GPIOC->DATA, GPIOC_PIN_AUDIO_PATH);
g_2000036B = 1;
gEnableSpeaker = true;
gUpdateStatus = true;
}
@ -932,7 +932,7 @@ void APP_TimeSlice10ms(void)
BK4819_TransmitTone(true, 500);
SYSTEM_DelayMs(2);
GPIO_SetBit(&GPIOC->DATA, GPIOC_PIN_AUDIO_PATH);
g_2000036B = 1;
gEnableSpeaker = true;
g_20000420 = 0;
}
}
@ -989,8 +989,8 @@ void APP_TimeSlice10ms(void)
BK4819_EnableFrequencyScan();
} else {
BK4819_SetScanFrequency(gScanFrequency);
g_CxCSS_Index = 0xFF;
g_CxCSS_Type = 0xFF;
gCS_ScannedIndex = 0xFF;
gCS_ScannedType = 0xFF;
g_2000045F = 0;
g_2000045C = 0;
g_20000464 = 0;
@ -1011,8 +1011,8 @@ void APP_TimeSlice10ms(void)
Index = DCS_GetCdcssIndex(Result);
if (Index != 0xFF) {
g_CxCSS_Index = Index;
g_CxCSS_Type = 0x02;
gCS_ScannedIndex = Index;
gCS_ScannedType = CODE_TYPE_DIGITAL;
gScanState = 2;
g_2000045C = 1;
}
@ -1021,8 +1021,8 @@ void APP_TimeSlice10ms(void)
Index = DCS_GetCtcssIndex(CtcssFreq);
if (Index != 0xFF) {
if (Index == g_CxCSS_Index && g_CxCSS_Type == 0x01) {
g_2000045F += 1;
if (Index == gCS_ScannedIndex && gCS_ScannedType == CODE_TYPE_CONTINUOUS_TONE) {
g_2000045F++;
if (1 < g_2000045F) {
gScanState = 2;
g_2000045C = 1;
@ -1030,8 +1030,8 @@ void APP_TimeSlice10ms(void)
} else {
g_2000045F = 0;
}
g_CxCSS_Type = 0x01;
g_CxCSS_Index = Index;
gCS_ScannedType = CODE_TYPE_CONTINUOUS_TONE;
gCS_ScannedIndex = Index;
}
}
if (gScanState < 2) {
@ -1238,7 +1238,7 @@ void FUN_00001150(void)
{
g_20000383 = 0;
GPIO_ClearBit(&GPIOC->DATA, GPIOC_PIN_AUDIO_PATH);
g_2000036B = 0;
gEnableSpeaker = false;
if (gEeprom.ALARM_MODE == ALARM_MODE_TONE) {
RADIO_SendEndOfTransmission();
RADIO_EnableCxCSS();
@ -1282,8 +1282,8 @@ void FUN_000075b0(void)
BK4819_EnableFrequencyScan();
}
g_2000045D = 0x15;
g_CxCSS_Index = 0xFF;
g_CxCSS_Type = 0xFF;
gCS_ScannedIndex = 0xFF;
gCS_ScannedType = 0xFF;
g_2000045F = 0;
g_2000045C = 0;
gDTMF_RequestPending = false;
@ -1856,7 +1856,7 @@ static void APP_ProcessKey(KEY_Code_t Key, bool bKeyPressed, bool bKeyHeld)
char Code;
if (Key == KEY_SIDE2) {
Code = -2;
Code = 0xFE;
} else {
Code = DTMF_GetCharacter(Key);
if (Code == 0xFF) {
@ -1867,7 +1867,7 @@ static void APP_ProcessKey(KEY_Code_t Key, bool bKeyPressed, bool bKeyHeld)
if (bKeyHeld || !bKeyPressed) {
if (!bKeyPressed) {
GPIO_ClearBit(&GPIOC->DATA, GPIOC_PIN_AUDIO_PATH);
g_2000036B = 0;
gEnableSpeaker = false;
BK4819_ExitDTMF_TX(false);
if (gCrossTxRadioInfo->SCRAMBLING_TYPE == 0 || !gSetting_ScrambleEnable) {
BK4819_DisableScramble();
@ -1878,10 +1878,10 @@ static void APP_ProcessKey(KEY_Code_t Key, bool bKeyPressed, bool bKeyHeld)
} else {
if (gEeprom.DTMF_SIDE_TONE) {
GPIO_SetBit(&GPIOC->DATA, GPIOC_PIN_AUDIO_PATH);
g_2000036B = 1;
gEnableSpeaker = true;
}
BK4819_DisableScramble();
if (Code == -2) {
if (Code == 0xFE) {
BK4819_TransmitTone(gEeprom.DTMF_SIDE_TONE, 1750);
} else {
BK4819_PlayDTMFEx(gEeprom.DTMF_SIDE_TONE, Code);

View File

@ -36,8 +36,6 @@ volatile uint16_t gFmPlayCountdown = 1;
volatile int8_t gFM_Step;
bool gFM_AutoScan;
uint8_t gFM_ChannelPosition;
// Doubts about whether this should be signed or not.
int16_t gFM_FrequencyDeviation;
bool FM_CheckValidChannel(uint8_t Channel)
{
@ -91,7 +89,7 @@ void FM_TurnOff(void)
gFM_Step = 0;
g_2000038E = 0;
GPIO_ClearBit(&GPIOC->DATA, GPIOC_PIN_AUDIO_PATH);
g_2000036B = 0;
gEnableSpeaker = false;
BK1080_Init(0, false);
gUpdateStatus = true;
}
@ -112,7 +110,7 @@ void FM_EraseChannels(void)
void FM_Tune(uint16_t Frequency, int8_t Step, bool bFlag)
{
GPIO_ClearBit(&GPIOC->DATA, GPIOC_PIN_AUDIO_PATH);
g_2000036B = 0;
gEnableSpeaker = false;
if (gFM_Step == 0) {
gFmPlayCountdown = 120;
} else {
@ -151,7 +149,7 @@ void FM_Play(void)
gScheduleFM = false;
gAskToSave = false;
GPIO_SetBit(&GPIOC->DATA, GPIOC_PIN_AUDIO_PATH);
g_2000036B = 1;
gEnableSpeaker = true;
}
int FM_CheckFrequencyLock(uint16_t Frequency, uint16_t LowerLimit)
@ -174,19 +172,19 @@ int FM_CheckFrequencyLock(uint16_t Frequency, uint16_t LowerLimit)
}
if (Deviation < 280 || Deviation > 3815) {
if ((LowerLimit < Frequency) && (Frequency - g_20000362) == 1) {
if (gFM_FrequencyDeviation & 0x800) {
if ((LowerLimit < Frequency) && (Frequency - BK1080_BaseFrequency) == 1) {
if (BK1080_FrequencyDeviation & 0x800) {
goto Bail;
}
if (gFM_FrequencyDeviation < 20) {
if (BK1080_FrequencyDeviation < 20) {
goto Bail;
}
}
if ((LowerLimit <= Frequency) && (g_20000362 - Frequency) == 1) {
if ((gFM_FrequencyDeviation & 0x800) == 0) {
if ((LowerLimit <= Frequency) && (BK1080_BaseFrequency - Frequency) == 1) {
if ((BK1080_FrequencyDeviation & 0x800) == 0) {
goto Bail;
}
if (4075 < gFM_FrequencyDeviation) {
if (4075 < BK1080_FrequencyDeviation) {
goto Bail;
}
}
@ -194,45 +192,49 @@ int FM_CheckFrequencyLock(uint16_t Frequency, uint16_t LowerLimit)
}
Bail:
gFM_FrequencyDeviation = (uint16_t)Deviation;
g_20000362 = Frequency;
BK1080_FrequencyDeviation = Deviation;
BK1080_BaseFrequency = Frequency;
return ret;
}
void FM_Key_DIGITS(KEY_Code_t Key, bool bKeyPressed, bool bKeyHeld)
{
#define STATE_FREQ_MODE 0
#define STATE_MR_MODE 1
#define STATE_SAVE 2
if (!bKeyHeld && bKeyPressed) {
if (!gWasFKeyPressed) {
uint8_t Value;
uint8_t State;
if (gAskToDelete) {
gBeepToPlay = BEEP_500HZ_60MS_DOUBLE_BEEP_OPTIONAL;
return;
}
if (gAskToSave) {
Value = 2;
State = STATE_SAVE;
} else {
if (gFM_Step) {
gBeepToPlay = BEEP_500HZ_60MS_DOUBLE_BEEP_OPTIONAL;
return;
}
if (gEeprom.FM_IsMrMode) {
Value = 1;
State = STATE_MR_MODE;
} else {
Value = 0;
State = STATE_FREQ_MODE;
}
}
INPUTBOX_Append(Key);
gRequestDisplayScreen = DISPLAY_FM;
if (Value == 0) {
if (State == STATE_FREQ_MODE) {
if (gInputBoxIndex == 1) {
if (1 < gInputBox[0]) {
if (gInputBox[0] > 1) {
gInputBox[1] = gInputBox[0];
gInputBox[0] = 0;
gInputBoxIndex = 2;
}
} else if (3 < gInputBoxIndex) {
} else if (gInputBoxIndex > 3) {
uint32_t Frequency;
gInputBoxIndex = 0;
@ -255,7 +257,7 @@ void FM_Key_DIGITS(KEY_Code_t Key, bool bKeyPressed, bool bKeyHeld)
gInputBoxIndex = 0;
Channel = ((gInputBox[0] * 10) + gInputBox[1]) - 1;
if (Value == 1) {
if (State == STATE_MR_MODE) {
if (FM_CheckValidChannel(Channel)) {
gAnotherVoiceID = (VOICE_ID_t)Key;
gEeprom.FM_SelectedChannel = Channel;

View File

@ -23,6 +23,9 @@
#include "ui/inputbox.h"
#include "ui/ui.h"
DCS_CodeType_t gCS_ScannedType;
uint8_t gCS_ScannedIndex;
void SCANNER_Key_DIGITS(KEY_Code_t Key, bool bKeyPressed, bool bKeyHeld)
{
if (!bKeyHeld && bKeyPressed) {
@ -164,18 +167,18 @@ void SCANNER_Key_MENU(bool bKeyPressed, bool bKeyHeld)
if (g_20000458 == 0) {
RADIO_InitInfo(gTxInfo, gTxInfo->CHANNEL_SAVE, FREQUENCY_GetBand(gScanFrequency), gScanFrequency);
if (g_2000045C == 1) {
gTxInfo->ConfigRX.CodeType = g_CxCSS_Type;
gTxInfo->ConfigRX.Code = g_CxCSS_Index;
gTxInfo->ConfigRX.CodeType = gCS_ScannedType;
gTxInfo->ConfigRX.Code = gCS_ScannedIndex;
}
gTxInfo->ConfigTX = gTxInfo->ConfigRX;
gTxInfo->STEP_SETTING = gStepSetting;
} else {
RADIO_ConfigureChannel(0, 2);
RADIO_ConfigureChannel(1, 2);
gTxInfo->ConfigRX.CodeType = g_CxCSS_Type;
gTxInfo->ConfigRX.Code = g_CxCSS_Index;
gTxInfo->ConfigTX.CodeType = g_CxCSS_Type;
gTxInfo->ConfigTX.Code = g_CxCSS_Index;
gTxInfo->ConfigRX.CodeType = gCS_ScannedType;
gTxInfo->ConfigRX.Code = gCS_ScannedIndex;
gTxInfo->ConfigTX.CodeType = gCS_ScannedType;
gTxInfo->ConfigTX.Code = gCS_ScannedIndex;
}
if (IS_MR_CHANNEL(gTxInfo->CHANNEL_SAVE)) {

View File

@ -17,8 +17,12 @@
#ifndef APP_SCANNER_H
#define APP_SCANNER_H
#include "dcs.h"
#include "driver/keyboard.h"
extern DCS_CodeType_t gCS_ScannedType;
extern uint8_t gCS_ScannedIndex;
void SCANNER_Key_DIGITS(KEY_Code_t Key, bool bKeyPressed, bool bKeyHeld);
void SCANNER_Key_EXIT(bool bKeyPressed, bool bKeyHeld);
void SCANNER_Key_MENU(bool bKeyPressed, bool bKeyHeld);

View File

@ -138,7 +138,7 @@ void AUDIO_PlayBeep(BEEP_Type_t Beep)
BK4819_TurnsOffTones_TurnsOnRX();
SYSTEM_DelayMs(5);
BK4819_WriteRegister(BK4819_REG_71, ToneConfig);
if (g_2000036B == 1) {
if (gEnableSpeaker) {
GPIO_SetBit(&GPIOC->DATA, GPIOC_PIN_AUDIO_PATH);
}
if (gFmRadioMode) {
@ -218,7 +218,7 @@ void AUDIO_PlaySingleVoice(bool bFlag)
if (gFmRadioMode) {
BK1080_Mute(false);
}
if (g_2000036B == 0) {
if (!gEnableSpeaker) {
GPIO_ClearBit(&GPIOC->DATA, GPIOC_PIN_AUDIO_PATH);
}
gVoiceWriteIndex = 0;
@ -333,7 +333,7 @@ void AUDIO_PlayQueuedVoice(void)
if (gFmRadioMode) {
BK1080_Mute(false);
}
if (g_2000036B == 0) {
if (!gEnableSpeaker) {
GPIO_ClearBit(&GPIOC->DATA, GPIOC_PIN_AUDIO_PATH);
}
g_200003B6 = 80;

View File

@ -37,6 +37,9 @@ static const uint16_t BK1080_RegisterTable[] = {
static bool gIsInitBK1080;
uint16_t BK1080_BaseFrequency;
int16_t BK1080_FrequencyDeviation;
void BK1080_Init(uint16_t Frequency, bool bDoScan)
{
uint8_t i;
@ -106,8 +109,8 @@ void BK1080_SetFrequency(uint16_t Frequency)
void BK1080_GetFrequencyDeviation(uint16_t Frequency)
{
g_20000362 = Frequency;
BK1080_BaseFrequency = Frequency;
// Doubts whether this register is signed or not
gFM_FrequencyDeviation = (int16_t)BK1080_ReadRegister(BK1080_REG_07) / 16;
BK1080_FrequencyDeviation = (int16_t)BK1080_ReadRegister(BK1080_REG_07) / 16;
}

View File

@ -21,6 +21,9 @@
#include <stdint.h>
#include "driver/bk1080-regs.h"
extern uint16_t BK1080_BaseFrequency;
extern int16_t BK1080_FrequencyDeviation;
void BK1080_Init(uint16_t Frequency, bool bDoScan);
uint16_t BK1080_ReadRegister(BK1080_Register_t Register);
void BK1080_WriteRegister(BK1080_Register_t Register, uint16_t Value);

View File

@ -147,7 +147,7 @@ void FUNCTION_Select(FUNCTION_Type_t Function)
BK4819_PlayTone(500, 0);
SYSTEM_DelayMs(2);
GPIO_SetBit(&GPIOC->DATA, GPIOC_PIN_AUDIO_PATH);
g_2000036B = 1;
gEnableSpeaker = true;
SYSTEM_DelayMs(60);
BK4819_ExitTxMute();
gBatterySaveCountdown = 1000;
@ -185,7 +185,7 @@ void FUNCTION_Select(FUNCTION_Type_t Function)
Delay = gEeprom.DTMF_PRELOAD_TIME;
if (gEeprom.DTMF_SIDE_TONE) {
GPIO_SetBit(&GPIOC->DATA, GPIOC_PIN_AUDIO_PATH);
g_2000036B = 1;
gEnableSpeaker = true;
Delay = gEeprom.DTMF_PRELOAD_TIME;
if (gEeprom.DTMF_PRELOAD_TIME < 60) {
Delay = 60;
@ -205,7 +205,7 @@ void FUNCTION_Select(FUNCTION_Type_t Function)
GPIO_ClearBit(&GPIOC->DATA, GPIOC_PIN_AUDIO_PATH);
g_2000036B = 0;
gEnableSpeaker = false;
BK4819_ExitDTMF_TX(false);
Skip:
@ -219,7 +219,7 @@ Skip:
GPIO_SetBit(&GPIOC->DATA, GPIOC_PIN_AUDIO_PATH);
g_20000420 = 0;
g_2000038E = 0;
g_2000036B = 1;
gEnableSpeaker = true;
gSchedulePowerSave = false;
gBatterySaveCountdown = 1000;
return;

5
misc.c
View File

@ -51,8 +51,7 @@ volatile uint16_t g_2000033A;
volatile uint16_t gTxTimerCountdown = 1000;
volatile uint16_t g_20000342;
volatile uint16_t gNOAA_Countdown;
uint16_t g_20000362;
uint8_t g_2000036B;
bool gEnableSpeaker;
uint8_t gKeyLockCountdown;
uint8_t gRTTECountdown;
bool bIsInLockScreen;
@ -132,8 +131,6 @@ uint8_t gMenuListCount;
uint8_t g_20000442;
uint8_t g_20000458;
uint8_t gBackupCROSS_BAND_RX_TX;
uint8_t g_CxCSS_Type;
uint8_t g_CxCSS_Index;
uint8_t g_2000045C;
uint8_t g_2000045D;
uint8_t g_2000045F;

7
misc.h
View File

@ -82,8 +82,7 @@ extern volatile uint16_t gTxTimerCountdown;
extern volatile uint16_t g_20000342;
extern volatile uint16_t gFmPlayCountdown;
extern volatile uint16_t gNOAA_Countdown;
extern uint16_t g_20000362;
extern uint8_t g_2000036B;
extern bool gEnableSpeaker;
extern uint8_t gKeyLockCountdown;
extern uint8_t gRTTECountdown;
extern bool bIsInLockScreen;
@ -163,8 +162,6 @@ extern uint8_t gMenuListCount;
extern uint8_t g_20000442;
extern uint8_t g_20000458;
extern uint8_t gBackupCROSS_BAND_RX_TX;
extern uint8_t g_CxCSS_Type;
extern uint8_t g_CxCSS_Index;
extern uint8_t g_2000045C;
extern uint8_t g_2000045D;
extern uint8_t g_2000045F;
@ -202,8 +199,6 @@ extern volatile bool gScheduleFM;
extern volatile uint16_t ScanPauseDelayIn10msec;
extern int16_t gFM_FrequencyDeviation;
extern uint16_t gCurrentRSSI;
extern volatile int8_t gStepDirection;

View File

@ -476,7 +476,7 @@ void RADIO_SetupRegisters(bool bSwitchToFunction0)
uint32_t Frequency;
GPIO_ClearBit(&GPIOC->DATA, GPIOC_PIN_AUDIO_PATH);
g_2000036B = 0;
gEnableSpeaker = false;
BK4819_ToggleGpioOut(BK4819_GPIO0_PIN28, false);
Bandwidth = gRxInfo->CHANNEL_BANDWIDTH;
@ -643,7 +643,7 @@ void RADIO_PrepareTransmit(void)
GPIO_ClearBit(&GPIOC->DATA, GPIOC_PIN_AUDIO_PATH);
g_2000036B = 0;
gEnableSpeaker = false;
BK4819_ToggleGpioOut(BK4819_GPIO6_PIN2, false);
Bandwidth = gCrossTxRadioInfo->CHANNEL_BANDWIDTH;
@ -802,7 +802,7 @@ void RADIO_SendEndOfTransmission(void)
if (g_200003BC == 0 && (gCrossTxRadioInfo->DTMF_PTT_ID_TX_MODE == PTT_ID_EOT || gCrossTxRadioInfo->DTMF_PTT_ID_TX_MODE == PTT_ID_BOTH)) {
if (gEeprom.DTMF_SIDE_TONE) {
GPIO_SetBit(&GPIOC->DATA, GPIOC_PIN_AUDIO_PATH);
g_2000036B = 1;
gEnableSpeaker = true;
SYSTEM_DelayMs(60);
}
BK4819_EnterDTMF_TX(gEeprom.DTMF_SIDE_TONE);
@ -815,7 +815,7 @@ void RADIO_SendEndOfTransmission(void)
gEeprom.DTMF_CODE_INTERVAL_TIME
);
GPIO_ClearBit(&GPIOC->DATA, GPIOC_PIN_AUDIO_PATH);
g_2000036B = 0;
gEnableSpeaker = false;
}
BK4819_ExitDTMF_TX(true);
}

View File

@ -29,7 +29,7 @@ void UI_DisplayBattery(uint8_t Level)
switch (Level) {
case 0:
pBitmap = NULL;
bClearMode = 1;
bClearMode = true;
break;
case 1:
pBitmap = BITMAP_BatteryLevel1;

View File

@ -91,9 +91,9 @@ void UI_DisplayLock(void)
AUDIO_PlayBeep(Beep);
gUpdateDisplay = true;
break;
case KEY_EXIT: // Delete digit
case KEY_EXIT:
if (gInputBoxIndex) {
gInputBoxIndex -= 1;
gInputBoxIndex--;
gInputBox[gInputBoxIndex] = 10;
gUpdateDisplay = true;
}

View File

@ -16,6 +16,7 @@
#include <stdbool.h>
#include <string.h>
#include "app/scanner.h"
#include "dcs.h"
#include "driver/st7565.h"
#include "external/printf/printf.h"
@ -42,10 +43,10 @@ void UI_DisplayScanner(void)
if (gScanState < 2 || g_2000045C != 1) {
sprintf(String, "CTC:******");
} else if (g_CxCSS_Type == 1) {
sprintf(String, "CTC:%.1fHz", CTCSS_Options[g_CxCSS_Index] * 0.1);
} else if (gCS_ScannedType == CODE_TYPE_CONTINUOUS_TONE) {
sprintf(String, "CTC:%.1fHz", CTCSS_Options[gCS_ScannedIndex] * 0.1);
} else {
sprintf(String, "DCS:D%03oN", DCS_Options[g_CxCSS_Index]);
sprintf(String, "DCS:D%03oN", DCS_Options[gCS_ScannedIndex]);
}
UI_PrintString(String, 2, 127, 3, 8, 0);
memset(String, 0, sizeof(String));