diff --git a/app/action.c b/app/action.c index e980b91..ff6ba58 100644 --- a/app/action.c +++ b/app/action.c @@ -230,7 +230,7 @@ void ACTION_Handle(KEY_Code_t Key, bool bKeyPressed, bool bKeyHeld) gDTMF_InputBox[--gDTMF_InputIndex] = '-'; if (gDTMF_InputIndex) { - gPttWasReleased = true; + gPttWasReleased = true; gRequestDisplayScreen = DISPLAY_MAIN; return; } diff --git a/app/app.c b/app/app.c index ae079dc..99b68db 100644 --- a/app/app.c +++ b/app/app.c @@ -907,6 +907,8 @@ void APP_Update(void) void APP_CheckKeys(void) { + const uint16_t key_repeat_delay = 70; // 700ms + KEY_Code_t Key; #ifndef DISABLE_AIRCOPY @@ -920,15 +922,25 @@ void APP_CheckKeys(void) if (gPttIsPressed) { if (GPIO_CheckBit(&GPIOC->DATA, GPIOC_PIN_PTT)) - { - SYSTEM_DelayMs(20); + { // PTT released - if (GPIO_CheckBit(&GPIOC->DATA, GPIOC_PIN_PTT)) + // denoise the PTT + unsigned int i = 4; // loop for 4ms + unsigned int count = 0; + while (i-- > 0) + { + SYSTEM_DelayMs(1); + if (GPIO_CheckBit(&GPIOC->DATA, GPIOC_PIN_PTT)) + count++; + else + if (count > 0) + count--; + } + + if (count >= 2) { APP_ProcessKey(KEY_PTT, false, false); - gPttIsPressed = false; - if (gKeyReading1 != KEY_INVALID) gPttWasReleased = true; } @@ -938,7 +950,7 @@ void APP_CheckKeys(void) { if (!GPIO_CheckBit(&GPIOC->DATA, GPIOC_PIN_PTT)) { - if (++gPttDebounceCounter > 4) + if (++gPttDebounceCounter >= 4) // 40ms { gPttIsPressed = true; APP_ProcessKey(KEY_PTT, true, false); @@ -982,7 +994,7 @@ void APP_CheckKeys(void) gKeyBeingHeld = false; } else - if (gDebounceCounter == 128) + if (gDebounceCounter == key_repeat_delay) { if (Key == KEY_STAR || Key == KEY_F || Key == KEY_SIDE2 || Key == KEY_SIDE1 || Key == KEY_UP || Key == KEY_DOWN) { @@ -991,7 +1003,7 @@ void APP_CheckKeys(void) } } else - if (gDebounceCounter > 128) + if (gDebounceCounter > key_repeat_delay) { if (Key == KEY_UP || Key == KEY_DOWN) { @@ -1003,14 +1015,14 @@ void APP_CheckKeys(void) if (gDebounceCounter < 0xFFFF) return; - gDebounceCounter = 128; + gDebounceCounter = key_repeat_delay; } } void APP_TimeSlice10ms(void) { gFlashLightBlinkCounter++; - + if (UART_IsCommandAvailable()) { __disable_irq(); @@ -1102,6 +1114,7 @@ void APP_TimeSlice10ms(void) } #endif + // repeater tail tone elimination if (gRTTECountdown) { if (--gRTTECountdown == 0) @@ -1560,9 +1573,7 @@ static void APP_ProcessKey(KEY_Code_t Key, bool bKeyPressed, bool bKeyHeld) if (gDTMF_DecodeRing) { gDTMF_DecodeRing = false; - AUDIO_PlayBeep(BEEP_1KHZ_60MS_OPTIONAL); - if (Key != KEY_PTT) { gPttWasReleased = true; diff --git a/dcs.h b/dcs.h index 08db2bf..b8dfdc0 100644 --- a/dcs.h +++ b/dcs.h @@ -19,11 +19,12 @@ #include -enum DCS_CodeType_t { - CODE_TYPE_OFF = 0x00U, - CODE_TYPE_CONTINUOUS_TONE = 0x01U, - CODE_TYPE_DIGITAL = 0x02U, - CODE_TYPE_REVERSE_DIGITAL = 0x03U, +enum DCS_CodeType_t +{ + CODE_TYPE_OFF = 0, + CODE_TYPE_CONTINUOUS_TONE, + CODE_TYPE_DIGITAL, + CODE_TYPE_REVERSE_DIGITAL }; typedef enum DCS_CodeType_t DCS_CodeType_t; diff --git a/driver/backlight.c b/driver/backlight.c index c50c77d..0ac2a0a 100644 --- a/driver/backlight.c +++ b/driver/backlight.c @@ -19,19 +19,14 @@ #include "driver/gpio.h" #include "settings.h" -uint8_t gBacklightCountdown; +uint8_t gBacklightCountdown = 0; void BACKLIGHT_TurnOn(void) { if (gEeprom.BACKLIGHT > 0) { - GPIO_SetBit(&GPIOB->DATA, GPIOB_PIN_BACKLIGHT); - #if 0 - gBacklightCountdown = 1 + (gEeprom.BACKLIGHT * 2); - #else - // much longer backlight times - gBacklightCountdown = (gEeprom.BACKLIGHT * 20) - 19; - #endif + GPIO_SetBit(&GPIOB->DATA, GPIOB_PIN_BACKLIGHT); // turn the backlight ON + gBacklightCountdown = (gEeprom.BACKLIGHT < 5) ? (gEeprom.BACKLIGHT * 20) - 19 : 0; // much longer backlight times } } diff --git a/firmware b/firmware index 92a7bab..ec0749c 100644 Binary files a/firmware and b/firmware differ diff --git a/firmware.bin b/firmware.bin index 4e9d0a4..02a3cff 100644 Binary files a/firmware.bin and b/firmware.bin differ diff --git a/firmware.packed.bin b/firmware.packed.bin index 70c634a..7c0eb3d 100644 Binary files a/firmware.packed.bin and b/firmware.packed.bin differ diff --git a/functions.h b/functions.h index 1cc836f..991d921 100644 --- a/functions.h +++ b/functions.h @@ -19,18 +19,19 @@ #include -enum FUNCTION_Type_t { - FUNCTION_FOREGROUND = 0U, - FUNCTION_TRANSMIT = 1U, - FUNCTION_MONITOR = 2U, - FUNCTION_INCOMING = 3U, - FUNCTION_RECEIVE = 4U, - FUNCTION_POWER_SAVE = 5U, +enum FUNCTION_Type_t +{ + FUNCTION_FOREGROUND = 0, + FUNCTION_TRANSMIT, + FUNCTION_MONITOR, + FUNCTION_INCOMING, + FUNCTION_RECEIVE, + FUNCTION_POWER_SAVE }; typedef enum FUNCTION_Type_t FUNCTION_Type_t; -extern FUNCTION_Type_t gCurrentFunction; +extern FUNCTION_Type_t gCurrentFunction; void FUNCTION_Init(void); void FUNCTION_Select(FUNCTION_Type_t Function); diff --git a/main.c b/main.c index 910f66f..9dffc76 100644 --- a/main.c +++ b/main.c @@ -64,7 +64,6 @@ void Main(void) SYSTICK_Init(); BOARD_Init(); - UART_Init(); #ifdef GIT_HASH @@ -110,8 +109,12 @@ void Main(void) if (!gChargingWithTypeC && !gBatteryDisplayLevel) { FUNCTION_Select(FUNCTION_POWER_SAVE); - //if (gEeprom.BACKLIGHT < 5) - GPIO_ClearBit(&GPIOB->DATA, GPIOB_PIN_BACKLIGHT); + + if (gEeprom.BACKLIGHT < 5) + GPIO_ClearBit(&GPIOB->DATA, GPIOB_PIN_BACKLIGHT); // turn the backlight OFF + else + GPIO_SetBit(&GPIOB->DATA, GPIOB_PIN_BACKLIGHT); // turn the backlight ON + gReducedService = true; } else diff --git a/radio.c b/radio.c index ec0e34a..5bdb0b8 100644 --- a/radio.c +++ b/radio.c @@ -874,17 +874,20 @@ void RADIO_EnableCxCSS(void) { switch (gCurrentVfo->pTX->CodeType) { + case CODE_TYPE_OFF: + break; + + case CODE_TYPE_CONTINUOUS_TONE: + BK4819_EnableCTCSS(); + SYSTEM_DelayMs(200); + break; + case CODE_TYPE_DIGITAL: case CODE_TYPE_REVERSE_DIGITAL: BK4819_EnableCDCSS(); - break; - - default: - BK4819_EnableCTCSS(); + SYSTEM_DelayMs(200); break; } - - SYSTEM_DelayMs(200); } void RADIO_PrepareCssTX(void) diff --git a/scheduler.c b/scheduler.c index be11dd0..089e65b 100644 --- a/scheduler.c +++ b/scheduler.c @@ -22,6 +22,10 @@ #include "misc.h" #include "settings.h" +#include "driver/backlight.h" +#include "bsp/dp32g030/gpio.h" +#include "driver/gpio.h" + #define DECREMENT_AND_TRIGGER(cnt, flag) \ do { \ if (cnt) { \ @@ -35,40 +39,41 @@ static volatile uint32_t gGlobalSysTickCounter; void SystickHandler(void); +// we come here every 10ms void SystickHandler(void) { gGlobalSysTickCounter++; + gNextTimeslice = true; - if ((gGlobalSysTickCounter % 50) == 0) { + + if ((gGlobalSysTickCounter % 50) == 0) + { gNextTimeslice500ms = true; DECREMENT_AND_TRIGGER(gTxTimerCountdown, gTxTimeoutReached); } - if ((gGlobalSysTickCounter & 3) == 0) { - gNextTimeslice40ms = true; - } - if (gSystickCountdown2) { - gSystickCountdown2--; - } - if (gFoundCDCSSCountdown) { - gFoundCDCSSCountdown--; - } - if (gFoundCTCSSCountdown) { - gFoundCTCSSCountdown--; - } - if (gCurrentFunction == FUNCTION_FOREGROUND) { - DECREMENT_AND_TRIGGER(gBatterySaveCountdown, gSchedulePowerSave); - } - if (gCurrentFunction == FUNCTION_POWER_SAVE) { - DECREMENT_AND_TRIGGER(gBatterySave, gBatterySaveCountdownExpired); - } - if (gScanState == SCAN_OFF && gCssScanMode == CSS_SCAN_MODE_OFF && gEeprom.DUAL_WATCH != DUAL_WATCH_OFF) { - if (gCurrentFunction != FUNCTION_MONITOR && gCurrentFunction != FUNCTION_TRANSMIT) { - if (gCurrentFunction != FUNCTION_RECEIVE) { + if ((gGlobalSysTickCounter & 3) == 0) + gNextTimeslice40ms = true; + + if (gSystickCountdown2) + gSystickCountdown2--; + + if (gFoundCDCSSCountdown) + gFoundCDCSSCountdown--; + + if (gFoundCTCSSCountdown) + gFoundCTCSSCountdown--; + + if (gCurrentFunction == FUNCTION_FOREGROUND) + DECREMENT_AND_TRIGGER(gBatterySaveCountdown, gSchedulePowerSave); + + if (gCurrentFunction == FUNCTION_POWER_SAVE) + DECREMENT_AND_TRIGGER(gBatterySave, gBatterySaveCountdownExpired); + + if (gScanState == SCAN_OFF && gCssScanMode == CSS_SCAN_MODE_OFF && gEeprom.DUAL_WATCH != DUAL_WATCH_OFF) + if (gCurrentFunction != FUNCTION_MONITOR && gCurrentFunction != FUNCTION_TRANSMIT) + if (gCurrentFunction != FUNCTION_RECEIVE) DECREMENT_AND_TRIGGER(gDualWatchCountdown, gScheduleDualWatch); - } - } - } #ifndef DISABLE_NOAA if (gScanState == SCAN_OFF && gCssScanMode == CSS_SCAN_MODE_OFF && gEeprom.DUAL_WATCH == DUAL_WATCH_OFF) @@ -77,11 +82,9 @@ void SystickHandler(void) DECREMENT_AND_TRIGGER(gNOAA_Countdown, gScheduleNOAA); #endif - if (gScanState != SCAN_OFF || gCssScanMode == CSS_SCAN_MODE_SCANNING) { - if (gCurrentFunction != FUNCTION_MONITOR && gCurrentFunction != FUNCTION_TRANSMIT) { + if (gScanState != SCAN_OFF || gCssScanMode == CSS_SCAN_MODE_SCANNING) + if (gCurrentFunction != FUNCTION_MONITOR && gCurrentFunction != FUNCTION_TRANSMIT) DECREMENT_AND_TRIGGER(ScanPauseDelayIn10msec, gScheduleScanListen); - } - } DECREMENT_AND_TRIGGER(gTailNoteEliminationCountdown, gFlagTteComplete); @@ -89,13 +92,28 @@ void SystickHandler(void) DECREMENT_AND_TRIGGER(gCountdownToPlayNextVoice, gFlagPlayQueuedVoice); #endif - if (gFM_ScanState != FM_SCAN_OFF && gCurrentFunction != FUNCTION_MONITOR) { - if (gCurrentFunction != FUNCTION_TRANSMIT && gCurrentFunction != FUNCTION_RECEIVE) { + if (gFM_ScanState != FM_SCAN_OFF && gCurrentFunction != FUNCTION_MONITOR) + if (gCurrentFunction != FUNCTION_TRANSMIT && gCurrentFunction != FUNCTION_RECEIVE) DECREMENT_AND_TRIGGER(gFmPlayCountdown, gScheduleFM); - } - } - if (gVoxStopCountdown) { - gVoxStopCountdown--; - } -} + if (gVoxStopCountdown) + gVoxStopCountdown--; + + #if 0 + if (gCurrentFunction == FUNCTION_TRANSMIT || gBacklightCountdown > 0) + { + GPIO_SetBit(&GPIOB->DATA, GPIOB_PIN_BACKLIGHT); // turn the backlight ON + } + else + if (gEeprom.BACKLIGHT >= 5) + { // backlight ON - half brightness + // was hoping to use this but don't like the odd flicker + if (gGlobalSysTickCounter & 1) + GPIO_SetBit(&GPIOB->DATA, GPIOB_PIN_BACKLIGHT); // turn the backlight ON + else + GPIO_ClearBit(&GPIOB->DATA, GPIOB_PIN_BACKLIGHT); // turn the backlight OFF + } + else + GPIO_ClearBit(&GPIOB->DATA, GPIOB_PIN_BACKLIGHT); // turn the backlight OFF + #endif +}