Refactoring #285

Signed-off-by: Krzysiek Egzmont <egzumer@gmail.com>
This commit is contained in:
Juan Antonio 2023-12-16 18:34:05 +01:00 committed by Krzysiek Egzmont
parent e7a21c470f
commit 2a75f8a9be
6 changed files with 213 additions and 215 deletions

View File

@ -1135,6 +1135,7 @@ static void CheckKeys(void)
void APP_TimeSlice10ms(void)
{
gNextTimeslice = false;
gFlashLightBlinkCounter++;
#ifdef ENABLE_BOOT_BEEPS
@ -1317,6 +1318,7 @@ void cancelUserInputModes(void)
// this is called once every 500ms
void APP_TimeSlice500ms(void)
{
gNextTimeslice_500ms = false;
bool exit_menu = false;
// Skipped authentic device check
@ -1433,25 +1435,24 @@ void APP_TimeSlice500ms(void)
#endif
}
if (!gCssBackgroundScan
#ifdef ENABLE_FMRADIO
if ((gFM_ScanState == FM_SCAN_OFF || gAskToSave) && !gCssBackgroundScan)
#else
if (!gCssBackgroundScan)
&& (gFM_ScanState == FM_SCAN_OFF || gAskToSave)
#endif
{
) {
if (gScanStateDir == SCAN_OFF && !SCANNER_IsScanning()
#ifdef ENABLE_AIRCOPY
if (gScanStateDir == SCAN_OFF && gScreenToDisplay != DISPLAY_AIRCOPY && !SCANNER_IsScanning())
#else
if (gScanStateDir == SCAN_OFF && !SCANNER_IsScanning())
&& gScreenToDisplay != DISPLAY_AIRCOPY
#endif
{
if (gEeprom.AUTO_KEYPAD_LOCK && gKeyLockCountdown > 0 && !gDTMF_InputMode && gScreenToDisplay != DISPLAY_MENU)
{
if (--gKeyLockCountdown == 0)
) {
if (gEeprom.AUTO_KEYPAD_LOCK && gKeyLockCountdown > 0 && !gDTMF_InputMode && gScreenToDisplay != DISPLAY_MENU) {
if (--gKeyLockCountdown == 0) {
gEeprom.KEY_LOCK = true; // lock the keyboard
gUpdateStatus = true; // lock symbol needs showing
}
}
if (exit_menu)
{
gMenuCountdown = 0;
@ -1485,7 +1486,6 @@ void APP_TimeSlice500ms(void)
gUpdateStatus = true;
gUpdateDisplay = true;
{
GUI_DisplayType_t disp = DISPLAY_INVALID;
#ifdef ENABLE_FMRADIO
@ -1494,15 +1494,16 @@ void APP_TimeSlice500ms(void)
}
#endif
if (disp == DISPLAY_INVALID)
{
if (disp == DISPLAY_INVALID) {
#ifndef ENABLE_NO_CODE_SCAN_TIMEOUT
if (!SCANNER_IsScanning())
#endif
{
disp = DISPLAY_MAIN;
}
}
if (disp != DISPLAY_INVALID)
if (disp != DISPLAY_INVALID) {
GUI_SelectNextDisplay(disp);
}
}
@ -1781,11 +1782,11 @@ static void ProcessKey(KEY_Code_t Key, bool bKeyPressed, bool bKeyHeld)
gUpdateStatus = true;
}
if (!bFlag)
{
if (gCurrentFunction == FUNCTION_TRANSMIT)
{ // transmitting
if (bFlag) {
goto Skip;
}
if (gCurrentFunction == FUNCTION_TRANSMIT) {
#if defined(ENABLE_ALARM) || defined(ENABLE_TX1750)
if (gAlarmState == ALARM_STATE_OFF)
#endif
@ -1804,6 +1805,7 @@ static void ProcessKey(KEY_Code_t Key, bool bKeyPressed, bool bKeyHeld)
}
else
{
Code = DTMF_GetCharacter(Key - KEY_0);
if (Code == 0xFF)
goto Skip;
@ -1844,8 +1846,7 @@ static void ProcessKey(KEY_Code_t Key, bool bKeyPressed, bool bKeyHeld)
}
}
#if defined(ENABLE_ALARM) || defined(ENABLE_TX1750)
else if ((!bKeyHeld && bKeyPressed) || (gAlarmState == ALARM_STATE_TX1750 && bKeyHeld && !bKeyPressed))
{
else if ((!bKeyHeld && bKeyPressed) || (gAlarmState == ALARM_STATE_TX1750 && bKeyHeld && !bKeyPressed)) {
ALARM_Off();
if (gEeprom.REPEATER_TAIL_TONE_ELIMINATION == 0)
@ -1864,16 +1865,14 @@ static void ProcessKey(KEY_Code_t Key, bool bKeyPressed, bool bKeyHeld)
else if (Key != KEY_SIDE1 && Key != KEY_SIDE2 && gScreenToDisplay != DISPLAY_INVALID) {
ProcessKeysFunctions[gScreenToDisplay](Key, bKeyPressed, bKeyHeld);
}
else
else if (!SCANNER_IsScanning()
#ifdef ENABLE_AIRCOPY
if (!SCANNER_IsScanning() && gScreenToDisplay != DISPLAY_AIRCOPY)
#else
if (!SCANNER_IsScanning())
&& gScreenToDisplay != DISPLAY_AIRCOPY
#endif
{
) {
ACTION_Handle(Key, bKeyPressed, bKeyHeld);
}
else if (!bKeyHeld && bKeyPressed)
else if (!bKeyHeld && bKeyPressed) {
gBeepToPlay = BEEP_500HZ_60MS_DOUBLE_BEEP_OPTIONAL;
}
@ -1907,21 +1906,21 @@ Skip:
#ifdef ENABLE_FMRADIO
if (gRequestSaveFM)
{
gRequestSaveFM = false;
if (!bKeyHeld)
SETTINGS_SaveFM();
else
gFlagSaveFM = true;
gRequestSaveFM = false;
}
#endif
if (gRequestSaveVFO)
{
gRequestSaveVFO = false;
if (!bKeyHeld)
SETTINGS_SaveVfoIndices();
else
gFlagSaveVfo = true;
gRequestSaveVFO = false;
}
if (gRequestSaveChannel > 0) // TODO: remove the gRequestSaveChannel, why use global variable for that??

View File

@ -16,13 +16,15 @@
#include <stdio.h> // NULL
#include "audio.h"
#include "../audio.h"
#include "../bsp/dp32g030/gpio.h"
#include "../bsp/dp32g030/portcon.h"
#include "bk4819.h"
#include "bsp/dp32g030/gpio.h"
#include "bsp/dp32g030/portcon.h"
#include "driver/gpio.h"
#include "driver/system.h"
#include "driver/systick.h"
#include "gpio.h"
#include "system.h"
#include "systick.h"
#ifndef ARRAY_SIZE
#define ARRAY_SIZE(x) (sizeof(x) / sizeof(x[0]))
@ -127,7 +129,6 @@ static uint16_t BK4819_ReadU16(void)
PORTCON_PORTC_IE = (PORTCON_PORTC_IE & ~PORTCON_PORTC_IE_C2_MASK) | PORTCON_PORTC_IE_C2_BITS_ENABLE;
GPIOC->DIR = (GPIOC->DIR & ~GPIO_DIR_2_MASK) | GPIO_DIR_2_BITS_INPUT;
SYSTICK_DelayUs(1);
Value = 0;
for (i = 0; i < 16; i++)
{

View File

@ -117,19 +117,13 @@ KEY_Code_t KEYBOARD_Poll(void)
GPIOA->DATA &= keyboard[j].set_to_zero_mask;
// Read all 4 GPIO pins at once .. with de-noise, max of 8 sample loops
for (i = 0, k = 0, reg = 0; i < 3 && k < 8; i++, k++)
{
uint16_t reg2;
for (i = 0, k = 0, reg = 0; i < 3 && k < 8; i++, k++) {
SYSTICK_DelayUs(1);
reg2 = GPIOA->DATA;
if (reg != reg2)
{ // noise
uint16_t reg2 = GPIOA->DATA;
i *= reg == reg2;
reg = reg2;
i = 0;
}
}
if (i < 3)
break; // noise is too bad

View File

@ -14,10 +14,10 @@
* limitations under the License.
*/
#include "bsp/dp32g030/pmu.h"
#include "bsp/dp32g030/syscon.h"
#include "driver/system.h"
#include "driver/systick.h"
#include "../bsp/dp32g030/pmu.h"
#include "../bsp/dp32g030/syscon.h"
#include "system.h"
#include "systick.h"
void SYSTEM_DelayMs(uint32_t Delay)
{

View File

@ -15,8 +15,8 @@
*/
#include "ARMCM0.h"
#include "driver/systick.h"
#include "misc.h"
#include "systick.h"
#include "../misc.h"
// 0x20000324
static uint32_t gTickMultiplier;
@ -30,16 +30,20 @@ void SYSTICK_Init(void)
void SYSTICK_DelayUs(uint32_t Delay)
{
const uint32_t ticks = Delay * gTickMultiplier;
uint32_t i = 0;
uint32_t elapsed_ticks = 0;
uint32_t Start = SysTick->LOAD;
uint32_t Previous = SysTick->VAL;
do {
uint32_t Current;
uint32_t Delta;
while ((Current = SysTick->VAL) == Previous) {}
Delta = (Current < Previous) ? -Current : Start - Current;
i += Delta + Previous;
Previous = Current;
} while (i < ticks);
}
do {
Current = SysTick->VAL;
} while (Current == Previous);
uint32_t Delta = ((Current < Previous) ? - Current : Start - Current);
elapsed_ticks += Delta + Previous;
Previous = Current;
} while (elapsed_ticks < ticks);
}

38
main.c
View File

@ -14,18 +14,26 @@
* limitations under the License.
*/
#include <stdint.h>
#include <string.h>
#include <stdio.h> // NULL
#ifdef ENABLE_AM_FIX
#include "am_fix.h"
#endif
#include "audio.h"
#include "board.h"
#include "misc.h"
#include "radio.h"
#include "settings.h"
#include "version.h"
#include "app/app.h"
#include "app/dtmf.h"
#include "audio.h"
#include "bsp/dp32g030/gpio.h"
#include "bsp/dp32g030/syscon.h"
#include "board.h"
#include "driver/backlight.h"
#include "driver/bk4819.h"
#include "driver/gpio.h"
@ -34,16 +42,13 @@
#ifdef ENABLE_UART
#include "driver/uart.h"
#endif
#include "helper/battery.h"
#include "helper/boot.h"
#include "misc.h"
#include "radio.h"
#include "settings.h"
#include "ui/lock.h"
#include "ui/welcome.h"
#include "ui/menu.h"
#include "version.h"
void _putchar(__attribute__((unused)) char c)
{
@ -67,6 +72,7 @@ void Main(void)
| SYSCON_DEV_CLK_GATE_AES_BITS_ENABLE
| SYSCON_DEV_CLK_GATE_PWM_PLUS0_BITS_ENABLE;
SYSTICK_Init();
BOARD_Init();
@ -211,24 +217,18 @@ void Main(void)
#ifdef ENABLE_NOAA
RADIO_ConfigureNOAA();
#endif
// ******************
}
while (1)
{
while (true) {
APP_Update();
if (gNextTimeslice)
{
APP_TimeSlice10ms();
gNextTimeslice = false;
}
if (gNextTimeslice) {
if (gNextTimeslice_500ms)
{
APP_TimeSlice10ms();
if (gNextTimeslice_500ms) {
APP_TimeSlice500ms();
gNextTimeslice_500ms = false;
}
}
}
}