Added big chunk of code to support main().

This commit is contained in:
Dual Tachyon 2023-08-13 23:27:35 +01:00
parent 4afecf57f1
commit 334f4fde0b
14 changed files with 385 additions and 21 deletions

View File

@ -33,6 +33,7 @@ OBJS += driver/systick.o
OBJS += driver/uart.o
# Main
OBJS += aircopy.o
OBJS += audio.o
OBJS += battery.o
OBJS += board.o
@ -43,6 +44,7 @@ OBJS += font.o
OBJS += frequencies.o
OBJS += functions.o
OBJS += gui.o
OBJS += helper.o
OBJS += misc.o
OBJS += radio.o
OBJS += settings.o

4
aircopy.c Normal file
View File

@ -0,0 +1,4 @@
#include "aircopy.h"
AIRCOPY_State_t gAircopyState;

15
aircopy.h Normal file
View File

@ -0,0 +1,15 @@
#ifndef AIRCOPY_H
#define AIRCOPY_H
enum AIRCOPY_State_t {
AIRCOPY_READY = 0U,
AIRCOPY_TRANSFER = 1U,
AIRCOPY_CMP = 2U,
};
typedef enum AIRCOPY_State_t AIRCOPY_State_t;
extern AIRCOPY_State_t gAircopyState;
#endif

View File

@ -210,7 +210,7 @@ void AUDIO_PlaySingleVoice(bool bFlag)
if (bFlag) {
SYSTEM_DelayMs(Delay * 10);
if (gCurrentFunction == FUNCTION_4 || gCurrentFunction == FUNCTION_2) {
if (gRxRadioInfo->_0x0033 == true) {
if (gInfoCHAN_A->_0x0033 == true) {
BK4819_SetAF(BK4819_AF_7);
} else {
BK4819_SetAF(BK4819_AF_OPEN);

View File

@ -24,13 +24,13 @@ uint8_t gCurrentFunction;
void FUNCTION_Init(void)
{
if (gRxRadioInfo->CHANNEL_SAVE < 207) {
if (gInfoCHAN_A->CHANNEL_SAVE < 207) {
gCopyOfCodeType = gCodeType;
if (g_20000381 == 0) {
if (gRxRadioInfo->_0x0033 == true) {
if (gInfoCHAN_A->_0x0033 == true) {
gCopyOfCodeType = 0;
} else {
gCopyOfCodeType = gRxRadioInfo->pDCS_Current->CodeType;
gCopyOfCodeType = gInfoCHAN_A->pDCS_Current->CodeType;
}
}
} else {

136
gui.c
View File

@ -1,10 +1,27 @@
#include <string.h>
#include "audio.h"
#include "driver/eeprom.h"
#include "driver/keyboard.h"
#include "driver/st7565.h"
#include "font.h"
#include "gui.h"
#include "helper.h"
#include "misc.h"
#include "settings.h"
GUI_DisplayType_t gScreenToDisplay;
uint8_t g_200003C6;
uint8_t g_20000380;
uint8_t g_20000390;
uint8_t g_200003BA;
uint8_t g_200003BB;
uint8_t g_20000367;
bool gAskForConfirmation;
bool gAskToSave;
bool gAskToDelete;
void GUI_Welcome(void)
{
char WelcomeString0[16];
@ -50,3 +67,122 @@ void GUI_PrintString(const char *pString, uint8_t Start, uint8_t End, uint8_t Li
}
}
void GUI_PasswordScreen(void)
{
KEY_Code_t Key;
BEEP_Type_t Beep;
gUpdateDisplay = true;
memset(gNumberForPrintf, 10, sizeof(gNumberForPrintf));
while (1) {
while (!gMaybeVsync) {
}
Key = KEYBOARD_Poll();
if (gKeyReading0 == Key) {
gDebounceCounter++;
if (gDebounceCounter == 2) {
if (Key == KEY_INVALID) {
gKeyReading1 = 0xFF;
} else {
gKeyReading1 = Key;
switch (Key) {
case KEY_0: case KEY_1: case KEY_2: case KEY_3:
case KEY_4: case KEY_5: case KEY_6: case KEY_7:
case KEY_8: case KEY_9:
NUMBER_Append(Key - KEY_0);
if (gNumberOffset < 6) {
Beep = BEEP_1KHZ_60MS_OPTIONAL;
} else {
uint32_t Password;
gNumberOffset = 0;
NUMBER_Get(gNumberForPrintf, &Password);
if ((gEeprom.POWER_ON_PASSWORD * 100) == Password) {
AUDIO_PlayBeep(BEEP_1KHZ_60MS_OPTIONAL);
return;
}
memset(gNumberForPrintf, 10, sizeof(gNumberForPrintf));
Beep = BEEP_500HZ_60MS_DOUBLE_BEEP_OPTIONAL;
}
AUDIO_PlayBeep(Beep);
gUpdateDisplay = true;
break;
case KEY_EXIT: // Delete digit
if (gNumberOffset != 0) {
gNumberOffset -= 1;
gNumberForPrintf[gNumberOffset] = 10;
gUpdateDisplay = true;
}
AUDIO_PlayBeep(BEEP_1KHZ_60MS_OPTIONAL);
default:
break;
}
}
//DAT_2000042c = 0;
}
} else {
gDebounceCounter = 0;
gKeyReading0 = Key;
}
#if 0
if (UART_CheckForCommand()) {
__disable_irq();
ProcessUartCommand();
__enable_irq();
}
#endif
if (gUpdateDisplay) {
GUI_LockScreen();
gUpdateDisplay = false;
}
}
}
void GUI_LockScreen(void)
{
char String[7];
uint8_t i;
memset(gStatusLine, 0, sizeof(gStatusLine));
memset(gFrameBuffer, 0, sizeof(gFrameBuffer));
strcat(String, "LOCK");
GUI_PrintString(String, 0, 127, 1, 10, true);
for (i = 0; i < 6; i++) {
if (gNumberForPrintf[i] == 10) {
String[i] = '-';
} else {
String[i] = '*';
}
}
String[6] = 0;
GUI_PrintString(String, 0, 127, 3, 12, true);
ST7565_BlitStatusLine();
ST7565_BlitFullScreen();
}
void GUI_SelectNextDisplay(GUI_DisplayType_t Display)
{
if (Display != DISPLAY_INVALID) {
if (gScreenToDisplay != Display) {
gNumberOffset = 0;
g_200003C6 = 0;
g_20000381 = 0;
g_20000380 = 0;
g_20000390 = 0;
gAskForConfirmation = 0;
g_200003BA = 0;
g_200003BB = 0;
gF_LOCK = 0;
gAskToSave = false;
gAskToDelete = false;
if (g_20000367 == 1) {
g_20000367 = 0;
g_2000036F = 1;
}
}
gUpdateDisplay = true;
gScreenToDisplay = Display;
}
}

30
gui.h
View File

@ -1,8 +1,38 @@
#ifndef GUI_H
#define GUI_H
#include <stdbool.h>
#include <stdint.h>
enum GUI_DisplayType_t {
DISPLAY_MAIN = 0x00U,
DISPLAY_FM = 0x01U,
DISPLAY_MENU = 0x02U,
DISPLAY_SCANNER = 0x03U,
DISPLAY_AIRCOPY = 0x04U,
DISPLAY_INVALID = 0xFFU,
};
typedef enum GUI_DisplayType_t GUI_DisplayType_t;
extern GUI_DisplayType_t gScreenToDisplay;
extern uint8_t g_200003C6;
extern uint8_t g_20000380;
extern uint8_t g_20000390;
extern uint8_t g_200003BA;
extern uint8_t g_200003BB;
extern uint8_t g_20000367;
extern bool gAskForConfirmation;
extern bool gAskToSave;
extern bool gAskToDelete;
void GUI_Welcome(void);
void GUI_PrintString(const char *pString, uint8_t Start, uint8_t End, uint8_t Line, int Width, bool bCentered);
void GUI_PasswordScreen(void);
void GUI_LockScreen(void);
void GUI_SelectNextDisplay(GUI_DisplayType_t Display);
#endif

73
helper.c Normal file
View File

@ -0,0 +1,73 @@
#include "aircopy.h"
#include "bsp/dp32g030/gpio.h"
#include "driver/bk4819.h"
#include "driver/keyboard.h"
#include "driver/gpio.h"
#include "driver/system.h"
#include "gui.h"
#include "misc.h"
#include "radio.h"
#include "settings.h"
uint8_t gKeyReading0;
uint8_t gKeyReading1;
uint8_t g_2000042A;
uint8_t HELPER_GetKey(void)
{
KEY_Code_t Keys[2];
uint8_t i;
uint8_t ret;
ret = 0;
for (i = 0; i < 2; i++) {
if (GPIO_CheckBit(&GPIOC->DATA, 5)) {
return 0;
}
Keys[i] = KEYBOARD_Poll();
SYSTEM_DelayMs(20);
}
if (Keys[0] == Keys[1]) {
gKeyReading0 = Keys[0];
gKeyReading1 = Keys[0];
g_2000042A = 2;
if (i == KEY_SIDE1) {
ret = 1;
} else if (i == KEY_SIDE2) {
ret = 2;
}
}
return ret;
}
void HELPER_CheckBootKey(uint8_t KeyType)
{
if (KeyType == 1) {
GUI_SelectNextDisplay(DISPLAY_MENU);
g_2000044C = 0x39;
gF_LOCK = 1;
} else if (KeyType == 2) {
gEeprom.DUAL_WATCH = 0;
gEeprom.BATTERY_SAVE = 0;
gEeprom.VOX_SWITCH = false;
gEeprom.CROSS_BAND_RX_TX = 0;
gEeprom.AUTO_KEYPAD_LOCK = false;
gEeprom.KEY_1_SHORT_PRESS_ACTION = 0;
gEeprom.KEY_1_LONG_PRESS_ACTION = 0;
gEeprom.KEY_2_SHORT_PRESS_ACTION = 0;
gEeprom.KEY_2_LONG_PRESS_ACTION = 0;
RADIO_InitInfo(gInfoCHAN_A, 205, 5, 41002500);
gInfoCHAN_A->CHANNEL_BANDWIDTH = BANDWIDTH_NARROW;
gInfoCHAN_A->OUTPUT_POWER = 0;
RADIO_ConfigureSquelchAndOutputPower(gInfoCHAN_A);
gCrossTxRadioInfo = gInfoCHAN_A;
RADIO_SetupRegisters(true);
BK4819_SetupAircopy();
BK4819_ResetFSK();
gAircopyState = AIRCOPY_READY;
} else {
}
}

14
helper.h Normal file
View File

@ -0,0 +1,14 @@
#ifndef HELPER_H
#define HELPER_H
#include <stdint.h>
extern uint8_t gKeyReading0;
extern uint8_t gKeyReading1;
extern uint8_t g_2000042A;
uint8_t HELPER_GetKey(void);
void HELPER_CheckBootKey(uint8_t KeyType);
#endif

29
main.c
View File

@ -17,6 +17,7 @@
#include <stdbool.h>
#include "ARMCM0.h"
#include "audio.h"
#include "battery.h"
#include "bsp/dp32g030/gpio.h"
#include "bsp/dp32g030/portcon.h"
@ -36,8 +37,10 @@
#include "driver/uart.h"
#include "functions.h"
#include "gui.h"
#include "helper.h"
#include "misc.h"
#include "radio.h"
#include "settings.h"
static const char Version[] = "UV-K5 Firmware, v0.01 Open Edition\r\n";
@ -152,9 +155,35 @@ void Main(void)
GPIO_ClearBit(&GPIOB->DATA, GPIOB_PIN_BACKLIGHT);
g_2000037E = 1;
} else {
uint8_t KeyType;
uint8_t Channel;
GUI_Welcome();
BACKLIGHT_TurnOn();
SYSTEM_DelayMs(1000);
g_2000044C = 0x33;
HELPER_GetKey();
KeyType = HELPER_GetKey();
if (gEeprom.POWER_ON_PASSWORD < 1000000) {
g_2000036E = 1;
GUI_PasswordScreen();
g_2000036E = 0;
}
HELPER_CheckBootKey(KeyType);
GPIO_ClearBit(&GPIOA->DATA, 12);
g_2000036F = 1;
AUDIO_SetVoiceID(0, VOICE_ID_ENG_WELCOME);
Channel = gEeprom.EEPROM_0E80_0E83[gEeprom.TX_CHANNEL] + 1;
if (Channel < 201) {
AUDIO_SetVoiceID(1, VOICE_ID_ENG_CHANNEL_MODE);
AUDIO_SetDigitVoice(2, Channel);
} else if ((Channel - 201) < 7) {
AUDIO_SetVoiceID(1, VOICE_ID_ENG_FREQUENCY_MODE);
}
AUDIO_PlaySingleVoice(0);
}
// Below this line is development/test area not conforming to the original firmware

41
misc.c
View File

@ -14,6 +14,7 @@
* limitations under the License.
*/
#include <string.h>
#include "misc.h"
const uint32_t *gUpperLimitFrequencyBandTable;
@ -49,6 +50,8 @@ uint8_t gMR_ChannelParameters[207];
uint8_t g_2000036B;
uint8_t g_2000036F;
uint8_t g_20000381;
uint8_t g_2000036E;
uint8_t gF_LOCK;
uint8_t g_200003AA;
uint8_t g_2000042F;
@ -66,6 +69,11 @@ uint8_t gSystickCountdown3;
uint8_t g_20000377;
uint8_t gSystickCountdown2;
uint8_t g_2000037E;
uint8_t g_2000044C;
bool gMaybeVsync;
uint8_t gDebounceCounter;
bool gUpdateDisplay;
uint8_t gCopyOfCodeType;
@ -77,5 +85,38 @@ bool gNoaaChannel;
uint8_t gCodeType;
uint8_t gCode;
uint8_t gNumberOffset;
uint8_t gNumberForPrintf[8];
uint16_t g_200003B6;
//
void NUMBER_Append(uint8_t Digit)
{
if (gNumberOffset == 0) {
memset(gNumberForPrintf, 10, sizeof(gNumberOffset));
} else if (gNumberOffset >= sizeof(gNumberOffset)) {
return;
}
gNumberForPrintf[gNumberOffset++] = Digit;
}
void NUMBER_Get(uint8_t *pDigits, uint32_t *pInteger)
{
uint32_t Value;
uint32_t Multiplier;
uint8_t i;
Multiplier = 10000000;
Value = 0;
for (i = 0; i < 8; i++) {
if (pDigits[i] > 9) {
break;
}
Value += pDigits[i] * Multiplier;
Multiplier /= 10U;
}
*pInteger = Value;
}

15
misc.h
View File

@ -53,6 +53,8 @@ extern uint8_t gMR_ChannelParameters[207];
extern uint8_t g_2000036B;
extern uint8_t g_2000036F;
extern uint8_t g_20000381;
extern uint8_t g_2000036E;
extern uint8_t gF_LOCK;
extern uint8_t g_200003AA;
extern uint8_t g_2000042F;
@ -70,6 +72,11 @@ extern uint8_t gSystickCountdown3;
extern uint8_t g_20000377;
extern uint8_t gSystickCountdown2;
extern uint8_t g_2000037E;
extern uint8_t g_2000044C;
extern bool gMaybeVsync;
extern uint8_t gDebounceCounter;
extern bool gUpdateDisplay;
extern uint8_t gCopyOfCodeType;
@ -81,7 +88,15 @@ extern bool gNoaaChannel;
extern uint8_t gCodeType;
extern uint8_t gCode;
extern uint8_t gNumberOffset;
extern uint8_t gNumberForPrintf[8];
extern uint16_t g_200003B6;
// --------
void NUMBER_Append(uint8_t Digit);
void NUMBER_Get(uint8_t *pDigits, uint32_t *pInteger);
#endif

32
radio.c
View File

@ -28,7 +28,7 @@
#include "settings.h"
RADIO_Info_t *gTxRadioInfo;
RADIO_Info_t *gRxRadioInfo;
RADIO_Info_t *gInfoCHAN_A;
RADIO_Info_t *gCrossTxRadioInfo;
bool RADIO_CheckValidChannel(uint8_t ChNum, bool bCheckScanList, uint8_t RadioNum)
@ -442,13 +442,13 @@ void RADIO_ConfigureTX(void)
}
}
gRxRadioInfo = &gEeprom.RadioInfo[gEeprom.RX_CHANNEL];
gInfoCHAN_A = &gEeprom.RadioInfo[gEeprom.RX_CHANNEL];
RADIO_ConfigureCrossTX();
}
void RADIO_ConfigureCrossTX(void)
{
gCrossTxRadioInfo = gRxRadioInfo;
gCrossTxRadioInfo = gInfoCHAN_A;
if (gEeprom.CROSS_BAND_RX_TX != 0) { // != OFF
gCrossTxRadioInfo = &gEeprom.RadioInfo[gEeprom.TX_CHANNEL];
}
@ -465,7 +465,7 @@ void RADIO_SetupRegisters(bool bSwitchToFunction0)
g_2000036B = 0;
BK4819_ToggleGpioOut(BK4819_GPIO0_PIN28, false);
Bandwidth = gRxRadioInfo->CHANNEL_BANDWIDTH;
Bandwidth = gInfoCHAN_A->CHANNEL_BANDWIDTH;
if (Bandwidth != 0) { // != WIDE
Bandwidth = 1; // NARROW
}
@ -485,16 +485,16 @@ void RADIO_SetupRegisters(bool bSwitchToFunction0)
}
BK4819_WriteRegister(BK4819_REG_3F, 0);
BK4819_WriteRegister(BK4819_REG_7D, gEeprom.MIC_SENSITIVITY_TUNING | 0xE940);
if (gRxRadioInfo->CHANNEL_SAVE < 207 || gIsNoaaMode != false) {
Frequency = gRxRadioInfo->pDCS_Current->Frequency;
if (gInfoCHAN_A->CHANNEL_SAVE < 207 || gIsNoaaMode != false) {
Frequency = gInfoCHAN_A->pDCS_Current->Frequency;
} else {
Frequency = NoaaFrequencyTable[gNoaaChannel];
}
BK4819_SetFrequency(Frequency);
BK4819_SetupSquelch(
gRxRadioInfo->SquelchOpenRSSIThresh, gRxRadioInfo->SquelchCloseRSSIThresh,
gRxRadioInfo->SquelchOpenNoiseThresh, gRxRadioInfo->SquelchCloseNoiseThresh,
gRxRadioInfo->SquelchCloseGlitchThresh, gRxRadioInfo->SquelchOpenGlitchThresh);
gInfoCHAN_A->SquelchOpenRSSIThresh, gInfoCHAN_A->SquelchCloseRSSIThresh,
gInfoCHAN_A->SquelchOpenNoiseThresh, gInfoCHAN_A->SquelchCloseNoiseThresh,
gInfoCHAN_A->SquelchCloseGlitchThresh, gInfoCHAN_A->SquelchOpenGlitchThresh);
BK4819_PickRXFilterPathBasedOnFrequency(Frequency);
BK4819_ToggleGpioOut(BK4819_GPIO6_PIN2, true);
BK4819_WriteRegister(BK4819_REG_48, 0xB3A8);
@ -502,16 +502,16 @@ void RADIO_SetupRegisters(bool bSwitchToFunction0)
// SQUELCH_LOST SQUELCH_FOUND
InterruptMask = 0x000C;
if (gRxRadioInfo->CHANNEL_SAVE < 207) {
if (gRxRadioInfo->_0x0033 != true) {
if (gInfoCHAN_A->CHANNEL_SAVE < 207) {
if (gInfoCHAN_A->_0x0033 != true) {
uint8_t CodeType;
uint8_t CodeWord;
CodeType = gCodeType;
CodeWord = gCode;
if (g_20000381 == 0) {
CodeType = gRxRadioInfo->pDCS_Current->CodeType;
CodeWord = gRxRadioInfo->pDCS_Current->RX_TX_Code;
CodeType = gInfoCHAN_A->pDCS_Current->CodeType;
CodeWord = gInfoCHAN_A->pDCS_Current->RX_TX_Code;
}
switch (CodeType) {
case CODE_TYPE_DIGITAL:
@ -533,10 +533,10 @@ void RADIO_SetupRegisters(bool bSwitchToFunction0)
InterruptMask = 0x040C;
break;
}
if (gRxRadioInfo->SCRAMBLING_TYPE == 0 || gSetting_ScrambleEnable == false) {
if (gInfoCHAN_A->SCRAMBLING_TYPE == 0 || gSetting_ScrambleEnable == false) {
BK4819_DisableScramble();
} else {
BK4819_EnableScramble(gRxRadioInfo->SCRAMBLING_TYPE - 1);
BK4819_EnableScramble(gInfoCHAN_A->SCRAMBLING_TYPE - 1);
}
}
} else {
@ -552,7 +552,7 @@ void RADIO_SetupRegisters(bool bSwitchToFunction0)
} else {
BK4819_DisableVox();
}
if ((gRxRadioInfo->_0x0033 == true) || ((gRxRadioInfo->DTMF_DECODING_ENABLE != true && (gSetting_KILLED != true)))) {
if ((gInfoCHAN_A->_0x0033 == true) || ((gInfoCHAN_A->DTMF_DECODING_ENABLE != true && (gSetting_KILLED != true)))) {
BK4819_DisableDTMF_SelCall();
} else {
BK4819_ConfigureDTMF_SelCall_and_UnknownRegister();

View File

@ -31,6 +31,11 @@ enum {
RADIO_CHANNEL_DOWN = 0xFFU,
};
enum {
BANDWIDTH_WIDE = 0U,
BANDWIDTH_NARROW = 1U,
};
typedef struct {
uint32_t Frequency;
uint8_t CodeType;
@ -70,7 +75,7 @@ typedef struct RADIO_Info_t {
} RADIO_Info_t;
extern RADIO_Info_t *gTxRadioInfo;
extern RADIO_Info_t *gRxRadioInfo;
extern RADIO_Info_t *gInfoCHAN_A;
extern RADIO_Info_t *gCrossTxRadioInfo;
bool RADIO_CheckValidChannel(uint8_t ChNum, bool bCheckScanList, uint8_t RadioNum);