From 063dc61e6517d1abe6088083238ae4c73584c81b Mon Sep 17 00:00:00 2001 From: Krzysiek Egzmont Date: Mon, 9 Oct 2023 21:47:06 +0200 Subject: [PATCH] Part of the recent changes form 1o11, including DTMF input box error #19 --- app/action.c | 6 +- app/app.c | 379 +++++++++++++++++++++++----------------------- app/dtmf.c | 43 ++++-- app/dtmf.h | 11 +- app/generic.c | 255 +++++++++++++++---------------- app/main.c | 124 ++++++++------- app/menu.c | 2 +- app/scanner.c | 2 +- driver/keyboard.c | 25 ++- driver/keyboard.h | 45 +++--- driver/st7565.c | 4 +- driver/st7565.h | 2 +- driver/systick.c | 29 ++-- functions.c | 8 +- misc.c | 2 +- misc.h | 10 +- ui/main.c | 12 +- ui/ui.c | 45 +++--- 18 files changed, 514 insertions(+), 490 deletions(-) diff --git a/app/action.c b/app/action.c index fe07b1d..36b61f6 100644 --- a/app/action.c +++ b/app/action.c @@ -334,10 +334,10 @@ void ACTION_Handle(KEY_Code_t Key, bool bKeyPressed, bool bKeyHeld) { gBeepToPlay = BEEP_1KHZ_60MS_OPTIONAL; - if (gDTMF_InputIndex > 0) + if (gDTMF_InputBox_Index > 0) { - gDTMF_InputBox[--gDTMF_InputIndex] = '-'; - if (gDTMF_InputIndex > 0) + gDTMF_InputBox[--gDTMF_InputBox_Index] = '-'; + if (gDTMF_InputBox_Index > 0) { gPttWasReleased = true; gRequestDisplayScreen = DISPLAY_MAIN; diff --git a/app/app.c b/app/app.c index aa839f9..48d8777 100644 --- a/app/app.c +++ b/app/app.c @@ -1367,27 +1367,20 @@ void APP_CheckKeys(void) return; } + if (gDebounceCounter < key_repeat_delay_10ms) + return; + // key is being held pressed if (gDebounceCounter == key_repeat_delay_10ms) - { // initial delay after pressed - if (Key == KEY_STAR || - Key == KEY_F || - Key == KEY_SIDE2 || - Key == KEY_SIDE1 || - Key == KEY_UP || - Key == KEY_DOWN || - Key == KEY_EXIT || - Key == KEY_MENU || - (Key >= KEY_0 && Key <= KEY_9)) // keys 0-9 can be held down to bypass pressing the F-Key + { // initial key repeat delay after pressed + if (Key != KEY_PTT) { gKeyBeingHeld = true; APP_ProcessKey(Key, true, true); } - return; } - - if (gDebounceCounter > key_repeat_delay_10ms) + else { // key repeat if (Key == KEY_UP || Key == KEY_DOWN) { @@ -1400,7 +1393,6 @@ void APP_CheckKeys(void) return; gDebounceCounter = key_repeat_delay_10ms; - return; } } @@ -1433,34 +1425,23 @@ void APP_TimeSlice10ms(void) if (gCurrentFunction != FUNCTION_POWER_SAVE || !gRxIdleMode) APP_CheckRadioInterrupts(); - if (gCurrentFunction != FUNCTION_TRANSMIT) - { // receiving - if (gUpdateStatus) - UI_DisplayStatus(false); - - if (gUpdateDisplay) - { - gUpdateDisplay = false; - GUI_DisplayScreen(); - } - } - else + if (gCurrentFunction == FUNCTION_TRANSMIT) { // transmitting #ifdef ENABLE_AUDIO_BAR if (gSetting_mic_bar && (gFlashLightBlinkCounter % (150 / 10)) == 0) // once every 150ms UI_DisplayAudioBar(); #endif - - if (gUpdateDisplay) - { - gUpdateDisplay = false; - GUI_DisplayScreen(); - } - - if (gUpdateStatus) - UI_DisplayStatus(false); } + if (gUpdateDisplay) + { + gUpdateDisplay = false; + GUI_DisplayScreen(); + } + + if (gUpdateStatus) + UI_DisplayStatus(false); + // Skipping authentic device checks #ifdef ENABLE_FMRADIO @@ -1474,7 +1455,7 @@ void APP_TimeSlice10ms(void) #ifdef ENABLE_VOX if (gVoxResumeCountdown > 0) gVoxResumeCountdown--; - + if (gVoxPauseCountdown > 0) gVoxPauseCountdown--; #endif @@ -1567,9 +1548,11 @@ void APP_TimeSlice10ms(void) if (gScanDelay_10ms > 0) { - gScanDelay_10ms--; - APP_CheckKeys(); - return; + if (--gScanDelay_10ms > 0) + { + APP_CheckKeys(); + return; + } } if (gScannerEditState != 0) @@ -1698,23 +1681,30 @@ void APP_TimeSlice10ms(void) void cancelUserInputModes(void) { - gKeyInputCountdown = 0; - if (gDTMF_InputMode || gInputBoxIndex > 0) + if (gDTMF_InputMode || gDTMF_InputBox_Index > 0) { - memset(gDTMF_String, 0, sizeof(gDTMF_String)); - gDTMF_InputMode = false; - gDTMF_InputIndex = 0; - gInputBoxIndex = 0; - + DTMF_clear_input_box(); + gBeepToPlay = BEEP_500HZ_60MS_DOUBLE_BEEP_OPTIONAL; gRequestDisplayScreen = DISPLAY_MAIN; + gUpdateDisplay = true; + } - gBeepToPlay = BEEP_1KHZ_60MS_OPTIONAL; + if (gWasFKeyPressed || gKeyInputCountdown > 0 || gInputBoxIndex > 0) + { + gWasFKeyPressed = false; + gInputBoxIndex = 0; + gKeyInputCountdown = 0; + gBeepToPlay = BEEP_500HZ_60MS_DOUBLE_BEEP_OPTIONAL; + gUpdateStatus = true; + gUpdateDisplay = true; } } // this is called once every 500ms void APP_TimeSlice500ms(void) { + bool exit_menu = false; + // Skipped authentic device check if (gKeypadLocked > 0) @@ -1722,9 +1712,19 @@ void APP_TimeSlice500ms(void) gUpdateDisplay = true; if (gKeyInputCountdown > 0) + { if (--gKeyInputCountdown == 0) + { cancelUserInputModes(); + if (gBeepToPlay != BEEP_NONE) + { + AUDIO_PlayBeep(gBeepToPlay); + gBeepToPlay = BEEP_NONE; + } + } + } + if (gDTMF_RX_live_timeout > 0) { #ifdef ENABLE_RSSI_BAR @@ -1742,16 +1742,15 @@ void APP_TimeSlice500ms(void) } } } - + + if (gMenuCountdown > 0) + if (--gMenuCountdown == 0) + exit_menu = (gScreenToDisplay == DISPLAY_MENU); // exit menu mode + if (gDTMF_RX_timeout > 0) if (--gDTMF_RX_timeout == 0) DTMF_clear_RX(); - if (gSerialConfigCountDown_500ms > 0) - { -// gReducedService = true; // a serial config upload/download is in progress - } - // Skipped authentic device check #ifdef ENABLE_FMRADIO @@ -1763,6 +1762,16 @@ void APP_TimeSlice500ms(void) } #endif + if (gBacklightCountdown > 0 && !gAskToSave && gCssScanMode == CSS_SCAN_MODE_OFF) + if (gScreenToDisplay != DISPLAY_MENU || gMenuCursor != MENU_ABR) // don't turn off backlight if user is in backlight menu option + if (--gBacklightCountdown == 0) + if (gEeprom.BACKLIGHT < (ARRAY_SIZE(gSubMenu_BACKLIGHT) - 1)) + GPIO_ClearBit(&GPIOB->DATA, GPIOB_PIN_BACKLIGHT); // turn backlight off + + if (gSerialConfigCountDown_500ms > 0) + { + } + if (gReducedService) { BOARD_ADC_GetBatteryInfo(&gBatteryCurrentVoltage, &gBatteryCurrent); @@ -1793,104 +1802,103 @@ void APP_TimeSlice500ms(void) gBatteryVoltageIndex = 0; BATTERY_GetReadings(true); } + } + + // regular display updates (once every 2 sec) - if need be + if ((gBatteryCheckCounter & 3) == 0) + { + if (gChargingWithTypeC || gSetting_battery_text > 0) + gUpdateStatus = true; + #ifdef ENABLE_SHOW_CHARGE_LEVEL + if (gChargingWithTypeC) + gUpdateDisplay = true; + #endif + } - // regular display updates (once every 2 sec) - if need be - if ((gBatteryCheckCounter & 3) == 0) - { - if (gChargingWithTypeC || gSetting_battery_text > 0) - gUpdateStatus = true; - #ifdef ENABLE_SHOW_CHARGE_LEVEL - if (gChargingWithTypeC) - gUpdateDisplay = true; - #endif - } - - if (gCurrentFunction != FUNCTION_POWER_SAVE) - updateRSSI(gEeprom.RX_VFO); - - #ifdef ENABLE_FMRADIO - if ((gFM_ScanState == FM_SCAN_OFF || gAskToSave) && gCssScanMode == CSS_SCAN_MODE_OFF) + #ifdef ENABLE_FMRADIO + if ((gFM_ScanState == FM_SCAN_OFF || gAskToSave) && gCssScanMode == CSS_SCAN_MODE_OFF) + #else + if (gCssScanMode == CSS_SCAN_MODE_OFF) + #endif + { + #ifdef ENABLE_AIRCOPY + if (gScanStateDir == SCAN_OFF && gScreenToDisplay != DISPLAY_AIRCOPY && (gScreenToDisplay != DISPLAY_SCANNER || gScanCssState >= SCAN_CSS_STATE_FOUND)) #else - if (gCssScanMode == CSS_SCAN_MODE_OFF) + if (gScanStateDir == SCAN_OFF && (gScreenToDisplay != DISPLAY_SCANNER || gScanCssState >= SCAN_CSS_STATE_FOUND)) #endif { - if (gBacklightCountdown > 0) - if (gScreenToDisplay != DISPLAY_MENU || gMenuCursor != MENU_ABR) // don't turn off backlight if user is in backlight menu option - if (--gBacklightCountdown == 0) - if (gEeprom.BACKLIGHT < (ARRAY_SIZE(gSubMenu_BACKLIGHT) - 1)) - GPIO_ClearBit(&GPIOB->DATA, GPIOB_PIN_BACKLIGHT); // turn backlight off - - #ifdef ENABLE_AIRCOPY - if (gScanStateDir == SCAN_OFF && gScreenToDisplay != DISPLAY_AIRCOPY && (gScreenToDisplay != DISPLAY_SCANNER || gScanCssState >= SCAN_CSS_STATE_FOUND)) - #else - if (gScanStateDir == SCAN_OFF && (gScreenToDisplay != DISPLAY_SCANNER || gScanCssState >= SCAN_CSS_STATE_FOUND)) - #endif + if (gEeprom.AUTO_KEYPAD_LOCK && gKeyLockCountdown > 0 && !gDTMF_InputMode) { - bool exit_menu = false; + if (--gKeyLockCountdown == 0) + gEeprom.KEY_LOCK = true; // lock the keyboard + gUpdateStatus = true; // lock symbol needs showing + } - if (gEeprom.AUTO_KEYPAD_LOCK && gKeyLockCountdown > 0 && !gDTMF_InputMode) + if (exit_menu) + { + gMenuCountdown = 0; + + if (gEeprom.BACKLIGHT == 0) { - if (--gKeyLockCountdown == 0) - gEeprom.KEY_LOCK = true; // lock the keyboard - - gUpdateStatus = true; // lock symbol needs showing + gBacklightCountdown = 0; + GPIO_ClearBit(&GPIOB->DATA, GPIOB_PIN_BACKLIGHT); // turn the backlight OFF } - if (gMenuCountdown > 0) - if (--gMenuCountdown == 0) - exit_menu = true; // exit menu mode - - if (exit_menu) + if (gInputBoxIndex > 0 || gDTMF_InputMode) + AUDIO_PlayBeep(BEEP_500HZ_60MS_DOUBLE_BEEP_OPTIONAL); +/* + if (gScreenToDisplay == DISPLAY_SCANNER) { - gMenuCountdown = 0; + BK4819_StopScan(); - if (gEeprom.BACKLIGHT == 0 && gScreenToDisplay == DISPLAY_MENU) - { - gBacklightCountdown = 0; - GPIO_ClearBit(&GPIOB->DATA, GPIOB_PIN_BACKLIGHT); // turn the backlight OFF - } + RADIO_ConfigureChannel(0, VFO_CONFIGURE_RELOAD); + RADIO_ConfigureChannel(1, VFO_CONFIGURE_RELOAD); - if (gInputBoxIndex > 0 || gDTMF_InputMode || gScreenToDisplay == DISPLAY_MENU) - AUDIO_PlayBeep(BEEP_500HZ_60MS_DOUBLE_BEEP_OPTIONAL); + RADIO_SetupRegisters(true); + } +*/ + DTMF_clear_input_box(); - if (gScreenToDisplay == DISPLAY_SCANNER) - { - BK4819_StopScan(); + gWasFKeyPressed = false; + gInputBoxIndex = 0; - RADIO_ConfigureChannel(0, VFO_CONFIGURE_RELOAD); - RADIO_ConfigureChannel(1, VFO_CONFIGURE_RELOAD); + gAskToSave = false; + gAskToDelete = false; - RADIO_SetupRegisters(true); - } + gUpdateStatus = true; + gUpdateDisplay = true; - gWasFKeyPressed = false; - gUpdateStatus = true; - gInputBoxIndex = 0; - gDTMF_InputMode = false; - gDTMF_InputIndex = 0; - gAskToSave = false; - gAskToDelete = false; + { + GUI_DisplayType_t disp = DISPLAY_INVALID; #ifdef ENABLE_FMRADIO if (gFmRadioMode && - gCurrentFunction != FUNCTION_RECEIVE && + gCurrentFunction != FUNCTION_RECEIVE && gCurrentFunction != FUNCTION_MONITOR && gCurrentFunction != FUNCTION_TRANSMIT) { - GUI_SelectNextDisplay(DISPLAY_FM); + disp = DISPLAY_FM; } - else #endif - #ifndef ENABLE_CODE_SCAN_TIMEOUT - if (gScreenToDisplay != DISPLAY_SCANNER) - #endif - GUI_SelectNextDisplay(DISPLAY_MAIN); + + if (disp == DISPLAY_INVALID) + { + #ifndef ENABLE_CODE_SCAN_TIMEOUT + if (gScreenToDisplay != DISPLAY_SCANNER) + #endif + disp = DISPLAY_MAIN; + } + + if (disp != DISPLAY_INVALID) + GUI_SelectNextDisplay(disp); } } } - } + if (gCurrentFunction != FUNCTION_POWER_SAVE && gCurrentFunction != FUNCTION_TRANSMIT) + updateRSSI(gEeprom.RX_VFO); + #ifdef ENABLE_FMRADIO if (!gPttIsPressed && gFM_ResumeCountdown_500ms > 0) { @@ -1948,7 +1956,7 @@ void APP_TimeSlice500ms(void) //if (gCurrentFunction != FUNCTION_POWER_SAVE) FUNCTION_Select(FUNCTION_POWER_SAVE); - ST7565_Configure_GPIO_B11(); + ST7565_HardwareReset(); if (gEeprom.BACKLIGHT < (ARRAY_SIZE(gSubMenu_BACKLIGHT) - 1)) GPIO_ClearBit(&GPIOB->DATA, GPIOB_PIN_BACKLIGHT); // turn the backlight off @@ -2000,7 +2008,10 @@ void APP_TimeSlice500ms(void) { if (--gDTMF_auto_reset_time_500ms == 0) { - gDTMF_CallState = DTMF_CALL_STATE_NONE; + if (gDTMF_CallState == DTMF_CALL_STATE_RECEIVED && gEeprom.DTMF_auto_reset_time >= DTMF_HOLD_MAX) + gDTMF_CallState = DTMF_CALL_STATE_RECEIVED_STAY; // keep message on-screen till a key is pressed + else + gDTMF_CallState = DTMF_CALL_STATE_NONE; gUpdateDisplay = true; } } @@ -2127,7 +2138,7 @@ static void APP_ProcessKey(KEY_Code_t Key, bool bKeyPressed, bool bKeyHeld) } else { - if (Key != KEY_PTT) + if (Key != KEY_PTT || gSetting_backlight_on_tx_rx == 1 || gSetting_backlight_on_tx_rx == 3) BACKLIGHT_TurnOn(); if (Key == KEY_EXIT && bKeyHeld) @@ -2140,6 +2151,9 @@ static void APP_ProcessKey(KEY_Code_t Key, bool bKeyPressed, bool bKeyHeld) gDTMF_RX_live_timeout = 0; gUpdateDisplay = true; } + + // cancel user input + cancelUserInputModes(); } if (gScreenToDisplay == DISPLAY_MENU) // 1of11 @@ -2190,14 +2204,7 @@ static void APP_ProcessKey(KEY_Code_t Key, bool bKeyPressed, bool bKeyHeld) } } - if (Key != KEY_PTT && - Key != KEY_UP && - Key != KEY_DOWN && - Key != KEY_EXIT && - Key != KEY_SIDE1 && - Key != KEY_SIDE2 && - Key != KEY_STAR && - Key != KEY_MENU) + if ((Key >= KEY_0 && Key <= KEY_9) || Key == KEY_F) { if (gScanStateDir != SCAN_OFF || gCssScanMode != CSS_SCAN_MODE_OFF) { // FREQ/CTCSS/DCS scanning @@ -2224,7 +2231,6 @@ static void APP_ProcessKey(KEY_Code_t Key, bool bKeyPressed, bool bKeyHeld) { if (bKeyHeld) bFlag = true; - if (!bKeyPressed) { bFlag = true; @@ -2232,9 +2238,8 @@ static void APP_ProcessKey(KEY_Code_t Key, bool bKeyPressed, bool bKeyHeld) } } - if (gWasFKeyPressed && Key > KEY_9 && Key != KEY_F && Key != KEY_STAR) -// if (gWasFKeyPressed && Key > KEY_9 && Key != KEY_F && Key != KEY_STAR && Key != KEY_MENU) - { + if (gWasFKeyPressed && (Key == KEY_PTT || Key == KEY_EXIT || Key == KEY_SIDE1 || Key == KEY_SIDE2)) + { // cancel the F-key gWasFKeyPressed = false; gUpdateStatus = true; } @@ -2248,59 +2253,58 @@ static void APP_ProcessKey(KEY_Code_t Key, bool bKeyPressed, bool bKeyHeld) if (gAlarmState == ALARM_STATE_OFF) #endif { + char Code; + if (Key == KEY_PTT) { GENERIC_Key_PTT(bKeyPressed); + goto Skip; + } + + if (Key == KEY_SIDE2) + { // transmit 1750Hz tone + Code = 0xFE; } else { - char Code; + Code = DTMF_GetCharacter(Key - KEY_0); + if (Code == 0xFF) + goto Skip; - if (Key == KEY_SIDE2) - { // transmit 1750Hz tone - Code = 0xFE; - } - else + // transmit DTMF keys + } + + if (!bKeyPressed || bKeyHeld) + { + if (!bKeyPressed) { - Code = DTMF_GetCharacter(Key - KEY_0); - if (Code == 0xFF) - goto Skip; - - // transmit DTMF keys - } + GPIO_ClearBit(&GPIOC->DATA, GPIOC_PIN_AUDIO_PATH); - if (!bKeyPressed || bKeyHeld) - { - if (!bKeyPressed) - { - GPIO_ClearBit(&GPIOC->DATA, GPIOC_PIN_AUDIO_PATH); + gEnableSpeaker = false; - gEnableSpeaker = false; + BK4819_ExitDTMF_TX(false); - BK4819_ExitDTMF_TX(false); - - if (gCurrentVfo->SCRAMBLING_TYPE == 0 || !gSetting_ScrambleEnable) - BK4819_DisableScramble(); - else - BK4819_EnableScramble(gCurrentVfo->SCRAMBLING_TYPE - 1); - } - } - else - { - if (gEeprom.DTMF_SIDE_TONE) - { // user will here the DTMF tones in speaker - GPIO_SetBit(&GPIOC->DATA, GPIOC_PIN_AUDIO_PATH); - gEnableSpeaker = true; - } - - BK4819_DisableScramble(); - - if (Code == 0xFE) - BK4819_TransmitTone(gEeprom.DTMF_SIDE_TONE, 1750); + if (gCurrentVfo->SCRAMBLING_TYPE == 0 || !gSetting_ScrambleEnable) + BK4819_DisableScramble(); else - BK4819_PlayDTMFEx(gEeprom.DTMF_SIDE_TONE, Code); + BK4819_EnableScramble(gCurrentVfo->SCRAMBLING_TYPE - 1); } } + else + { + if (gEeprom.DTMF_SIDE_TONE) + { // user will here the DTMF tones in speaker + GPIO_SetBit(&GPIOC->DATA, GPIOC_PIN_AUDIO_PATH); + gEnableSpeaker = true; + } + + BK4819_DisableScramble(); + + if (Code == 0xFE) + BK4819_TransmitTone(gEeprom.DTMF_SIDE_TONE, 1750); + else + BK4819_PlayDTMFEx(gEeprom.DTMF_SIDE_TONE, Code); + } } #if defined(ENABLE_ALARM) || defined(ENABLE_TX1750) else @@ -2308,13 +2312,8 @@ static void APP_ProcessKey(KEY_Code_t Key, bool bKeyPressed, bool bKeyHeld) { 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) - FUNCTION_Select(FUNCTION_FOREGROUND); - } + FUNCTION_Select(FUNCTION_FOREGROUND); else gRTTECountdown = gEeprom.REPEATER_TAIL_TONE_ELIMINATION * 10; @@ -2333,9 +2332,7 @@ static void APP_ProcessKey(KEY_Code_t Key, bool bKeyPressed, bool bKeyHeld) { case DISPLAY_MAIN: MAIN_ProcessKeys(Key, bKeyPressed, bKeyHeld); - - bKeyHeld = false; // allow the channel setting to be saved - +// bKeyHeld = false; // allow the channel setting to be saved break; #ifdef ENABLE_FMRADIO @@ -2376,11 +2373,6 @@ static void APP_ProcessKey(KEY_Code_t Key, bool bKeyPressed, bool bKeyHeld) if (!bKeyHeld && bKeyPressed) gBeepToPlay = BEEP_500HZ_60MS_DOUBLE_BEEP_OPTIONAL; } - else - { - if (Key == KEY_EXIT && bKeyHeld) - cancelUserInputModes(); - } Skip: if (gBeepToPlay != BEEP_NONE) @@ -2402,7 +2394,6 @@ Skip: if (gFlagStopScan) { BK4819_StopScan(); - gFlagStopScan = false; } @@ -2509,6 +2500,8 @@ Skip: if (gFlagStartScan) { + gFlagStartScan = false; + gMonitor = false; #ifdef ENABLE_VOICE @@ -2519,7 +2512,6 @@ Skip: SCANNER_Start(); gRequestDisplayScreen = DISPLAY_SCANNER; - gFlagStartScan = false; } if (gFlagPrepareTX) @@ -2539,6 +2531,7 @@ Skip: #endif GUI_SelectNextDisplay(gRequestDisplayScreen); - gRequestDisplayScreen = DISPLAY_INVALID; + + gUpdateDisplay = true; } diff --git a/app/dtmf.c b/app/dtmf.c index b5135ff..68b23eb 100644 --- a/app/dtmf.c +++ b/app/dtmf.c @@ -36,9 +36,9 @@ char gDTMF_String[15]; char gDTMF_InputBox[15]; -uint8_t gDTMF_InputIndex = 0; -bool gDTMF_InputMode = false; -uint8_t gDTMF_PreviousIndex = 0; +uint8_t gDTMF_InputBox_Index = 0; +bool gDTMF_InputMode = false; +uint8_t gDTMF_PreviousIndex = 0; char gDTMF_RX[17]; uint8_t gDTMF_RX_index = 0; @@ -133,8 +133,26 @@ bool DTMF_FindContact(const char *pContact, char *pResult) char DTMF_GetCharacter(const unsigned int code) { - const char list[] = "0123456789ABCD*#"; - return (code < ARRAY_SIZE(list)) ? list[code] : 0xFF; + switch (code) + { + case KEY_0: return '0'; + case KEY_1: return '1'; + case KEY_2: return '2'; + case KEY_3: return '3'; + case KEY_4: return '4'; + case KEY_5: return '5'; + case KEY_6: return '6'; + case KEY_7: return '7'; + case KEY_8: return '8'; + case KEY_9: return '9'; + case KEY_MENU: return 'A'; + case KEY_UP: return 'B'; + case KEY_DOWN: return 'C'; + case KEY_EXIT: return 'D'; + case KEY_STAR: return '*'; + case KEY_F: return '#'; + default: return 0xff; + } } bool DTMF_CompareMessage(const char *pMsg, const char *pTemplate, const unsigned int size, const bool bCheckGroup) @@ -163,16 +181,23 @@ DTMF_CallMode_t DTMF_CheckGroupCall(const char *pMsg, const unsigned int size) return (i < size) ? DTMF_CALL_MODE_GROUP : DTMF_CALL_MODE_NOT_GROUP; } +void DTMF_clear_input_box(void) +{ + memset(gDTMF_InputBox, 0, sizeof(gDTMF_InputBox)); + gDTMF_InputBox_Index = 0; + gDTMF_InputMode = false; +} + void DTMF_Append(const char code) { - if (gDTMF_InputIndex == 0) + if (gDTMF_InputBox_Index == 0) { - memset(gDTMF_InputBox, '-', sizeof(gDTMF_InputBox)); + memset(gDTMF_InputBox, '-', sizeof(gDTMF_InputBox) - 1); gDTMF_InputBox[sizeof(gDTMF_InputBox) - 1] = 0; } - if (gDTMF_InputIndex < sizeof(gDTMF_InputBox)) - gDTMF_InputBox[gDTMF_InputIndex++] = code; + if (gDTMF_InputBox_Index < (sizeof(gDTMF_InputBox) - 1)) + gDTMF_InputBox[gDTMF_InputBox_Index++] = code; } void DTMF_HandleRequest(void) diff --git a/app/dtmf.h b/app/dtmf.h index 0042ff0..d06ba86 100644 --- a/app/dtmf.h +++ b/app/dtmf.h @@ -33,7 +33,8 @@ typedef enum DTMF_State_t DTMF_State_t; enum DTMF_CallState_t { DTMF_CALL_STATE_NONE = 0, DTMF_CALL_STATE_CALL_OUT, - DTMF_CALL_STATE_RECEIVED + DTMF_CALL_STATE_RECEIVED, + DTMF_CALL_STATE_RECEIVED_STAY }; enum DTMF_DecodeResponse_t { @@ -60,12 +61,17 @@ enum DTMF_CallMode_t { DTMF_CALL_MODE_DTMF }; +enum { // seconds + DTMF_HOLD_MIN = 5, + DTMF_HOLD_MAX = 60 +}; + typedef enum DTMF_CallMode_t DTMF_CallMode_t; extern char gDTMF_String[15]; extern char gDTMF_InputBox[15]; -extern uint8_t gDTMF_InputIndex; +extern uint8_t gDTMF_InputBox_Index; extern bool gDTMF_InputMode; extern uint8_t gDTMF_PreviousIndex; @@ -98,6 +104,7 @@ bool DTMF_FindContact(const char *pContact, char *pResult); char DTMF_GetCharacter(const unsigned int code); bool DTMF_CompareMessage(const char *pDTMF, const char *pTemplate, const unsigned int size, const bool bFlag); DTMF_CallMode_t DTMF_CheckGroupCall(const char *pDTMF, const unsigned int size); +void DTMF_clear_input_box(void); void DTMF_Append(const char vode); void DTMF_HandleRequest(void); void DTMF_Reply(void); diff --git a/app/generic.c b/app/generic.c index 82e8f10..54a43e4 100644 --- a/app/generic.c +++ b/app/generic.c @@ -59,13 +59,13 @@ void GENERIC_Key_F(bool bKeyPressed, bool bKeyHeld) #endif gCurrentFunction != FUNCTION_TRANSMIT) { // toggle the keyboad lock - + #ifdef ENABLE_VOICE gAnotherVoiceID = gEeprom.KEY_LOCK ? VOICE_ID_UNLOCK : VOICE_ID_LOCK; #endif - + gEeprom.KEY_LOCK = !gEeprom.KEY_LOCK; - + gRequestSaveSettings = true; } } @@ -81,6 +81,9 @@ void GENERIC_Key_F(bool bKeyPressed, bool bKeyHeld) gWasFKeyPressed = !gWasFKeyPressed; + if (gWasFKeyPressed) + gKeyInputCountdown = key_input_timeout_500ms; + #ifdef ENABLE_VOICE if (!gWasFKeyPressed) gAnotherVoiceID = VOICE_ID_CANCEL; @@ -106,6 +109,7 @@ void GENERIC_Key_F(bool bKeyPressed, bool bKeyHeld) #endif gBeepToPlay = BEEP_440HZ_500MS; + gPttWasReleased = true; } } @@ -115,161 +119,154 @@ void GENERIC_Key_PTT(bool bKeyPressed) gInputBoxIndex = 0; if (!bKeyPressed || gSerialConfigCountDown_500ms > 0) - { - //if (gScreenToDisplay == DISPLAY_MAIN) - { - if (gCurrentFunction == FUNCTION_TRANSMIT) + { // PTT released + + if (gCurrentFunction == FUNCTION_TRANSMIT) + { // we are transmitting .. stop + + if (gFlagEndTransmission) { - if (gFlagEndTransmission) - { - FUNCTION_Select(FUNCTION_FOREGROUND); - } - else - { - APP_EndTransmission(); - - if (gEeprom.REPEATER_TAIL_TONE_ELIMINATION == 0) - { - FUNCTION_Select(FUNCTION_FOREGROUND); - } - else - gRTTECountdown = gEeprom.REPEATER_TAIL_TONE_ELIMINATION * 10; - } - - gFlagEndTransmission = false; - #ifdef ENABLE_VOX - gVOX_NoiseDetected = false; - #endif + FUNCTION_Select(FUNCTION_FOREGROUND); } + else + { + APP_EndTransmission(); + + if (gEeprom.REPEATER_TAIL_TONE_ELIMINATION == 0) + FUNCTION_Select(FUNCTION_FOREGROUND); + else + gRTTECountdown = gEeprom.REPEATER_TAIL_TONE_ELIMINATION * 10; + } + + gFlagEndTransmission = false; + + #ifdef ENABLE_VOX + gVOX_NoiseDetected = false; + #endif RADIO_SetVfoState(VFO_STATE_NORMAL); if (gScreenToDisplay != DISPLAY_MENU) // 1of11 .. don't close the menu gRequestDisplayScreen = DISPLAY_MAIN; - - return; } - gInputBoxIndex = 0; return; } - if (gScanStateDir != SCAN_OFF) - { - SCANNER_Stop(); + // PTT pressed - gPttDebounceCounter = 0; - gPttIsPressed = false; + if (gScanStateDir != SCAN_OFF || // frequency/channel scanning + gScreenToDisplay == DISPLAY_SCANNER || // CTCSS/CDCSS scanning + gCssScanMode != CSS_SCAN_MODE_OFF) // " " + { // we're scanning .. stop - if (gScreenToDisplay != DISPLAY_MENU) // 1of11 .. don't close the menu - gRequestDisplayScreen = DISPLAY_MAIN; - - return; - } - - #ifdef ENABLE_FMRADIO - if (gFM_ScanState == FM_SCAN_OFF) - #endif - { - if (gCssScanMode == CSS_SCAN_MODE_OFF) - { - #ifdef ENABLE_FMRADIO - if (gScreenToDisplay == DISPLAY_FM) - { - gRequestDisplayScreen = DISPLAY_MAIN; - gInputBoxIndex = 0; - gPttIsPressed = false; - gPttDebounceCounter = 0; - return; - } - #endif - - if (gScreenToDisplay != DISPLAY_SCANNER) - { - if (gCurrentFunction == FUNCTION_TRANSMIT && gRTTECountdown == 0) - { - gInputBoxIndex = 0; - return; - } - - gFlagPrepareTX = true; - - if (gDTMF_InputMode) - { - if (gDTMF_InputIndex > 0 || gDTMF_PreviousIndex > 0) - { - if (gDTMF_InputIndex == 0) - gDTMF_InputIndex = gDTMF_PreviousIndex; - - gDTMF_InputBox[gDTMF_InputIndex] = 0; - - #if 0 - // append our DTMF ID to the inputted DTMF code - - // IF the user inputted code is exactly 3 digits long - if (gDTMF_InputIndex == 3) - gDTMF_CallMode = DTMF_CheckGroupCall(gDTMF_InputBox, 3); - else - #else - // append our DTMF ID to the inputted DTMF code - - // IF the user inputted code is exactly 3 digits long and D-DCD is enabled - if (gDTMF_InputIndex == 3 && gTxVfo->DTMF_DECODING_ENABLE > 0) - gDTMF_CallMode = DTMF_CheckGroupCall(gDTMF_InputBox, 3); - else - #endif - gDTMF_CallMode = DTMF_CALL_MODE_DTMF; - - strcpy(gDTMF_String, gDTMF_InputBox); - - gDTMF_PreviousIndex = gDTMF_InputIndex; - gDTMF_ReplyState = DTMF_REPLY_ANI; - gDTMF_State = DTMF_STATE_0; - } - - if (gScreenToDisplay != DISPLAY_MENU) // 1of11 .. don't close the menu - gRequestDisplayScreen = DISPLAY_MAIN; - - gDTMF_InputMode = false; - gDTMF_InputIndex = 0; - return; - } - - if (gScreenToDisplay != DISPLAY_MENU) // 1of11 .. don't close the menu - gRequestDisplayScreen = DISPLAY_MAIN; - - gFlagPrepareTX = true; - gInputBoxIndex = 0; - - return; - } - - if (gScreenToDisplay != DISPLAY_MENU) // 1of11 .. don't close the menu - gRequestDisplayScreen = DISPLAY_MAIN; - - gEeprom.CROSS_BAND_RX_TX = gBackupCROSS_BAND_RX_TX; - gUpdateStatus = true; + if (gScreenToDisplay == DISPLAY_SCANNER) + { // CTCSS/CDCSS scanning .. stop + gEeprom.CROSS_BAND_RX_TX = gBackup_CROSS_BAND_RX_TX; gFlagStopScan = true; gVfoConfigureMode = VFO_CONFIGURE_RELOAD; gFlagResetVfos = true; } else - { + if (gScanStateDir != SCAN_OFF) + { // frequency/channel scanning . .stop + SCANNER_Stop(); + } + else + if (gCssScanMode != CSS_SCAN_MODE_OFF) + { // CTCSS/CDCSS scanning .. stop MENU_StopCssScan(); - if (gScreenToDisplay != DISPLAY_MENU) // 1of11 .. don't close the menu - gRequestDisplayScreen = DISPLAY_MENU; + #ifdef ENABLE_VOICE + gAnotherVoiceID = VOICE_ID_SCANNING_STOP; + #endif } + + goto cancel_tx; } + #ifdef ENABLE_FMRADIO - else - { + if (gFM_ScanState != FM_SCAN_OFF) + { // FM radio is scanning .. stop FM_PlayAndUpdate(); + #ifdef ENABLE_VOICE + gAnotherVoiceID = VOICE_ID_SCANNING_STOP; + #endif gRequestDisplayScreen = DISPLAY_FM; + goto cancel_tx; } #endif - #ifdef ENABLE_VOICE - gAnotherVoiceID = VOICE_ID_SCANNING_STOP; + #ifdef ENABLE_FMRADIO + if (gScreenToDisplay == DISPLAY_FM) + goto start_tx; // listening to the FM radio .. start TX'ing #endif - gPttWasPressed = true; + if (gCurrentFunction == FUNCTION_TRANSMIT && gRTTECountdown == 0) + { // already transmitting + gInputBoxIndex = 0; + return; + } + + if (gScreenToDisplay != DISPLAY_MENU) // 1of11 .. don't close the menu + gRequestDisplayScreen = DISPLAY_MAIN; + + if (!gDTMF_InputMode && gDTMF_InputBox_Index == 0) + goto start_tx; // wasn't entering a DTMF code .. start TX'ing (maybe) + + // was entering a DTMF string + + if (gDTMF_InputBox_Index > 0 || gDTMF_PreviousIndex > 0) + { // going to transmit a DTMF string + + if (gDTMF_InputBox_Index == 0 && gDTMF_PreviousIndex > 0) + gDTMF_InputBox_Index = gDTMF_PreviousIndex; // use the previous DTMF string + + if (gDTMF_InputBox_Index < sizeof(gDTMF_InputBox)) + gDTMF_InputBox[gDTMF_InputBox_Index] = 0; // NULL term the string + + #if 0 + // append our DTMF ID to the inputted DTMF code - + // IF the user inputted code is exactly 3 digits long + if (gDTMF_InputBox_Index == 3) + gDTMF_CallMode = DTMF_CheckGroupCall(gDTMF_InputBox, 3); + else + gDTMF_CallMode = DTMF_CALL_MODE_DTMF; + #else + // append our DTMF ID to the inputted DTMF code - + // IF the user inputted code is exactly 3 digits long and D-DCD is enabled + if (gDTMF_InputBox_Index == 3 && gTxVfo->DTMF_DECODING_ENABLE > 0) + gDTMF_CallMode = DTMF_CheckGroupCall(gDTMF_InputBox, 3); + else + gDTMF_CallMode = DTMF_CALL_MODE_DTMF; + #endif + + // remember the DTMF string + gDTMF_PreviousIndex = gDTMF_InputBox_Index; + strcpy(gDTMF_String, gDTMF_InputBox); + + gDTMF_ReplyState = DTMF_REPLY_ANI; + gDTMF_State = DTMF_STATE_0; + } + + DTMF_clear_input_box(); + +start_tx: + // request start TX + gFlagPrepareTX = true; + goto done; + +cancel_tx: + if (gPttIsPressed) + { + gPttIsPressed = false; + gPttWasPressed = true; + } + +done: + gPttDebounceCounter = 0; + if (gScreenToDisplay != DISPLAY_MENU && gRequestDisplayScreen != DISPLAY_FM) // 1of11 .. don't close the menu + gRequestDisplayScreen = DISPLAY_MAIN; + gUpdateStatus = true; + gUpdateDisplay = true; } diff --git a/app/main.c b/app/main.c index 50dada8..fdf9af1 100644 --- a/app/main.c +++ b/app/main.c @@ -198,7 +198,7 @@ static void processFKeyFunction(const KEY_Code_t Key, const bool beep) gWasFKeyPressed = false; gFlagStartScan = true; gScanSingleFrequency = false; - gBackupCROSS_BAND_RX_TX = gEeprom.CROSS_BAND_RX_TX; + gBackup_CROSS_BAND_RX_TX = gEeprom.CROSS_BAND_RX_TX; gEeprom.CROSS_BAND_RX_TX = CROSS_BAND_OFF; gUpdateStatus = true; @@ -534,10 +534,10 @@ static void MAIN_Key_EXIT(bool bKeyPressed, bool bKeyHeld) if (bKeyHeld && bKeyPressed) { // exit key held down - if (gInputBoxIndex > 0) + if (gInputBoxIndex > 0 || gDTMF_InputBox_Index > 0 || gDTMF_InputMode) { // cancel key input mode (channel/frequency entry) gDTMF_InputMode = false; - gDTMF_InputIndex = 0; + gDTMF_InputBox_Index = 0; memset(gDTMF_String, 0, sizeof(gDTMF_String)); gInputBoxIndex = 0; gRequestDisplayScreen = DISPLAY_MAIN; @@ -558,6 +558,8 @@ static void MAIN_Key_MENU(const bool bKeyPressed, const bool bKeyHeld) if (bKeyPressed) { // long press MENU key + gWasFKeyPressed = false; + if (gScreenToDisplay == DISPLAY_MAIN) { if (gInputBoxIndex > 0) @@ -642,6 +644,9 @@ static void MAIN_Key_MENU(const bool bKeyPressed, const bool bKeyHeld) static void MAIN_Key_STAR(bool bKeyPressed, bool bKeyHeld) { + if (gCurrentFunction == FUNCTION_TRANSMIT) + return; + if (gInputBoxIndex) { if (!bKeyHeld && bKeyPressed) @@ -649,70 +654,67 @@ static void MAIN_Key_STAR(bool bKeyPressed, bool bKeyHeld) return; } - if (bKeyHeld || !bKeyPressed) - { // long press + if (bKeyHeld && !gWasFKeyPressed) + { // long press .. toggle scanning + if (!bKeyPressed) + return; // released - if (bKeyHeld || bKeyPressed) - { - if (!bKeyHeld) - return; + ACTION_Scan(false); - if (!bKeyPressed) - return; + gBeepToPlay = BEEP_1KHZ_60MS_OPTIONAL; + return; + } - ACTION_Scan(false); - - return; - } + if (bKeyPressed) + { // just pressed +// gBeepToPlay = BEEP_1KHZ_60MS_OPTIONAL; + gBeepToPlay = BEEP_880HZ_40MS_OPTIONAL; + return; + } + + // just released + + if (!gWasFKeyPressed) + { // pressed without the F-key #ifdef ENABLE_NOAA if (gScanStateDir == SCAN_OFF && IS_NOT_NOAA_CHANNEL(gTxVfo->CHANNEL_SAVE)) #else if (gScanStateDir == SCAN_OFF) #endif - { - gKeyInputCountdown = key_input_timeout_500ms; + { // start entering a DTMF string + + memmove(gDTMF_InputBox, gDTMF_String, MIN(sizeof(gDTMF_InputBox), sizeof(gDTMF_String) - 1)); + gDTMF_InputBox_Index = 0; gDTMF_InputMode = true; - memmove(gDTMF_InputBox, gDTMF_String, sizeof(gDTMF_InputBox)); - gDTMF_InputIndex = 0; + + gKeyInputCountdown = key_input_timeout_500ms; gRequestDisplayScreen = DISPLAY_MAIN; - return; } } else - { - gBeepToPlay = BEEP_1KHZ_60MS_OPTIONAL; - if (!gWasFKeyPressed) - { - gBeepToPlay = BEEP_1KHZ_60MS_OPTIONAL; - return; - } - + { // with the F-key gWasFKeyPressed = false; - gUpdateStatus = true; #ifdef ENABLE_NOAA - if (IS_NOT_NOAA_CHANNEL(gTxVfo->CHANNEL_SAVE)) - { - gFlagStartScan = true; - gScanSingleFrequency = true; - gBackupCROSS_BAND_RX_TX = gEeprom.CROSS_BAND_RX_TX; - gEeprom.CROSS_BAND_RX_TX = CROSS_BAND_OFF; - } - else + if (IS_NOAA_CHANNEL(gTxVfo->CHANNEL_SAVE)) { gBeepToPlay = BEEP_500HZ_60MS_DOUBLE_BEEP_OPTIONAL; - } - #else - gFlagStartScan = true; - gScanSingleFrequency = true; - gBackupCROSS_BAND_RX_TX = gEeprom.CROSS_BAND_RX_TX; - gEeprom.CROSS_BAND_RX_TX = CROSS_BAND_OFF; + return; + } #endif - gPttWasReleased = true; + // scan the CTCSS/DCS code + gFlagStartScan = true; + gScanSingleFrequency = true; + gBackup_CROSS_BAND_RX_TX = gEeprom.CROSS_BAND_RX_TX; + gEeprom.CROSS_BAND_RX_TX = CROSS_BAND_OFF; } + + gPttWasReleased = true; + + gUpdateStatus = true; } static void MAIN_Key_UP_DOWN(bool bKeyPressed, bool bKeyHeld, int8_t Direction) @@ -826,31 +828,25 @@ void MAIN_ProcessKeys(KEY_Code_t Key, bool bKeyPressed, bool bKeyHeld) } #endif - if (gDTMF_InputMode && bKeyPressed) + if (gDTMF_InputMode && bKeyPressed && !bKeyHeld) { - if (!bKeyHeld) - { - const char Character = DTMF_GetCharacter(Key - KEY_0); - if (Character != 0xFF) - { // add key to DTMF string - DTMF_Append(Character); - - gKeyInputCountdown = key_input_timeout_500ms; - - gRequestDisplayScreen = DISPLAY_MAIN; - - gPttWasReleased = true; - gBeepToPlay = BEEP_1KHZ_60MS_OPTIONAL; - return; - } + const char Character = DTMF_GetCharacter(Key); + if (Character != 0xFF) + { // add key to DTMF string + DTMF_Append(Character); + gKeyInputCountdown = key_input_timeout_500ms; + gRequestDisplayScreen = DISPLAY_MAIN; + gPttWasReleased = true; + gBeepToPlay = BEEP_1KHZ_60MS_OPTIONAL; + return; } } // TODO: ??? - if (Key > KEY_PTT) - { - Key = KEY_SIDE2; // what's this doing ??? - } +// if (Key > KEY_PTT) +// { +// Key = KEY_SIDE2; // what's this doing ??? +// } switch (Key) { diff --git a/app/menu.c b/app/menu.c index a94b098..fb38396 100644 --- a/app/menu.c +++ b/app/menu.c @@ -674,7 +674,7 @@ void MENU_AcceptSetting(void) { GUI_SelectNextDisplay(DISPLAY_MAIN); gDTMF_InputMode = true; - gDTMF_InputIndex = 3; + gDTMF_InputBox_Index = 3; memmove(gDTMF_InputBox, gDTMF_ID, 4); gRequestDisplayScreen = DISPLAY_INVALID; } diff --git a/app/scanner.c b/app/scanner.c index 91367a7..25cb1e3 100644 --- a/app/scanner.c +++ b/app/scanner.c @@ -95,7 +95,7 @@ static void SCANNER_Key_EXIT(bool bKeyPressed, bool bKeyHeld) case 0: gRequestDisplayScreen = DISPLAY_MAIN; - gEeprom.CROSS_BAND_RX_TX = gBackupCROSS_BAND_RX_TX; + gEeprom.CROSS_BAND_RX_TX = gBackup_CROSS_BAND_RX_TX; gUpdateStatus = true; gFlagStopScan = true; gVfoConfigureMode = VFO_CONFIGURE_RELOAD; diff --git a/driver/keyboard.c b/driver/keyboard.c index c6af554..62882df 100644 --- a/driver/keyboard.c +++ b/driver/keyboard.c @@ -36,8 +36,8 @@ static const struct { // We are very fortunate. // The key and pin defines fit together in a single u8, making this very efficient struct { - uint8_t key : 5; // Key 23 is highest - uint8_t pin : 3; // Pin 6 is highest + KEY_Code_t key : 5; + uint8_t pin : 3; // Pin 6 is highest } pins[4]; } keyboard[] = { @@ -104,6 +104,8 @@ KEY_Code_t KEYBOARD_Poll(void) for (unsigned int j = 0; j < ARRAY_SIZE(keyboard); j++) { uint16_t reg; + unsigned int i; + unsigned int k; // Set all high GPIOA->DATA |= 1u << GPIOA_PIN_KEYBOARD_4 | @@ -114,11 +116,22 @@ KEY_Code_t KEYBOARD_Poll(void) // Clear the pin we are selecting GPIOA->DATA &= keyboard[j].set_to_zero_mask; - // Wait for the pins to stabilize - SYSTICK_DelayUs(1); + // 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; - // Read all 4 GPIO pins at once - reg = GPIOA->DATA; + SYSTICK_DelayUs(1); + + reg2 = GPIOA->DATA; + if (reg != reg2) + { // noise + reg = reg2; + i = 0; + } + } + if (i < 3) + break; // noise is too bad for (unsigned int i = 0; i < ARRAY_SIZE(keyboard[j].pins); i++) { diff --git a/driver/keyboard.h b/driver/keyboard.h index 78c1a4f..5a7d839 100644 --- a/driver/keyboard.h +++ b/driver/keyboard.h @@ -21,28 +21,29 @@ #include #include -typedef enum { - KEY_INVALID = 0, - KEY_0, - KEY_1, - KEY_2, - KEY_3, - KEY_4, - KEY_5, - KEY_6, - KEY_7, - KEY_8, - KEY_9, - KEY_MENU, - KEY_UP, - KEY_DOWN, - KEY_EXIT, - KEY_STAR, - KEY_F, - KEY_PTT, - KEY_SIDE2, - KEY_SIDE1 -} KEY_Code_t; +enum KEY_Code_e { + KEY_0 = 0, // 0 + KEY_1, // 1 + KEY_2, // 2 + KEY_3, // 3 + KEY_4, // 4 + KEY_5, // 5 + KEY_6, // 6 + KEY_7, // 7 + KEY_8, // 8 + KEY_9, // 9 + KEY_MENU, // A + KEY_UP, // B + KEY_DOWN, // C + KEY_EXIT, // D + KEY_STAR, // * + KEY_F, // # + KEY_PTT, // + KEY_SIDE2, // + KEY_SIDE1, // + KEY_INVALID // +}; +typedef enum KEY_Code_e KEY_Code_t; extern KEY_Code_t gKeyReading0; extern KEY_Code_t gKeyReading1; diff --git a/driver/st7565.c b/driver/st7565.c index c2ccd3f..66ee65d 100644 --- a/driver/st7565.c +++ b/driver/st7565.c @@ -146,7 +146,7 @@ void ST7565_Init(const bool full) { SPI0_Init(); - ST7565_Configure_GPIO_B11(); + ST7565_HardwareReset(); SPI_ToggleMasterMode(&SPI0->CR, false); @@ -199,7 +199,7 @@ void ST7565_Init(const bool full) ST7565_FillScreen(0x00); } -void ST7565_Configure_GPIO_B11(void) +void ST7565_HardwareReset(void) { GPIO_SetBit(&GPIOB->DATA, GPIOB_PIN_ST7565_RES); SYSTEM_DelayMs(1); diff --git a/driver/st7565.h b/driver/st7565.h index 5fc2e8d..ac0ffd9 100644 --- a/driver/st7565.h +++ b/driver/st7565.h @@ -31,7 +31,7 @@ void ST7565_BlitFullScreen(void); void ST7565_BlitStatusLine(void); void ST7565_FillScreen(uint8_t Value); void ST7565_Init(const bool full); -void ST7565_Configure_GPIO_B11(void); +void ST7565_HardwareReset(void); void ST7565_SelectColumnAndLine(uint8_t Column, uint8_t Line); void ST7565_WriteByte(uint8_t Value); diff --git a/driver/systick.c b/driver/systick.c index 9b1cddc..5971d74 100644 --- a/driver/systick.c +++ b/driver/systick.c @@ -29,26 +29,17 @@ void SYSTICK_Init(void) void SYSTICK_DelayUs(uint32_t Delay) { - uint32_t i; - uint32_t Start; - uint32_t Previous; - uint32_t Current; - uint32_t Delta; - - i = 0; - Start = SysTick->LOAD; - Previous = SysTick->VAL; + const uint32_t ticks = Delay * gTickMultiplier; + uint32_t i = 0; + uint32_t Start = SysTick->LOAD; + uint32_t Previous = SysTick->VAL; do { - do { - Current = SysTick->VAL; - } while (Current == Previous); - if (Current < Previous) { - Delta = -Current; - } else { - Delta = Start - Current; - } - i += Delta + Previous; + uint32_t Current; + uint32_t Delta; + while ((Current = SysTick->VAL) == Previous) {} + Delta = (Current < Previous) ? -Current : Start - Current; + i += Delta + Previous; Previous = Current; - } while (i < Delay * gTickMultiplier); + } while (i < ticks); } diff --git a/functions.c b/functions.c index cd02ab1..49d8cff 100644 --- a/functions.c +++ b/functions.c @@ -116,8 +116,12 @@ void FUNCTION_Select(FUNCTION_Type_t Function) gFM_RestoreCountdown_10ms = fm_restore_countdown_10ms; #endif - if (gDTMF_CallState == DTMF_CALL_STATE_CALL_OUT || gDTMF_CallState == DTMF_CALL_STATE_RECEIVED) - gDTMF_auto_reset_time_500ms = 1 + (gEeprom.DTMF_auto_reset_time * 2); + if (gDTMF_CallState == DTMF_CALL_STATE_CALL_OUT || + gDTMF_CallState == DTMF_CALL_STATE_RECEIVED || + gDTMF_CallState == DTMF_CALL_STATE_RECEIVED_STAY) + { + gDTMF_auto_reset_time_500ms = gEeprom.DTMF_auto_reset_time * 2; + } gUpdateStatus = true; return; diff --git a/misc.c b/misc.c index cc25ba9..d4ec9f2 100644 --- a/misc.c +++ b/misc.c @@ -220,7 +220,7 @@ bool gKeyBeingHeld; bool gPttIsPressed; uint8_t gPttDebounceCounter; uint8_t gMenuListCount; -uint8_t gBackupCROSS_BAND_RX_TX; +uint8_t gBackup_CROSS_BAND_RX_TX; uint8_t gScanDelay_10ms; #ifdef ENABLE_AIRCOPY uint8_t gAircopySendCountdown; diff --git a/misc.h b/misc.h index 9a5b0c0..61c42c4 100644 --- a/misc.h +++ b/misc.h @@ -24,6 +24,14 @@ #define ARRAY_SIZE(x) (sizeof(x) / sizeof(x[0])) #endif +#ifndef MAX + #define MAX(a, b) ({ __typeof__ (a) _a = (a); __typeof__ (b) _b = (b); _a > _b ? _a : _b; }) +#endif + +#ifndef MIN + #define MIN(a, b) ({ __typeof__ (a) _a = (a); __typeof__ (b) _b = (b); _a < _b ? _a : _b; }) +#endif + #define IS_MR_CHANNEL(x) ((x) >= MR_CHANNEL_FIRST && (x) <= MR_CHANNEL_LAST) #define IS_FREQ_CHANNEL(x) ((x) >= FREQ_CHANNEL_FIRST && (x) <= FREQ_CHANNEL_LAST) #define IS_VALID_CHANNEL(x) ((x) < LAST_CHANNEL) @@ -283,7 +291,7 @@ extern bool gKeyBeingHeld; extern bool gPttIsPressed; extern uint8_t gPttDebounceCounter; extern uint8_t gMenuListCount; -extern uint8_t gBackupCROSS_BAND_RX_TX; +extern uint8_t gBackup_CROSS_BAND_RX_TX; extern uint8_t gScanDelay_10ms; #ifdef ENABLE_AIRCOPY extern uint8_t gAircopySendCountdown; diff --git a/ui/main.c b/ui/main.c index 4bde05a..fa0ef7d 100644 --- a/ui/main.c +++ b/ui/main.c @@ -350,7 +350,7 @@ void UI_DisplayMain(void) if (gDTMF_CallState == DTMF_CALL_STATE_CALL_OUT) strcpy(String, (gDTMF_State == DTMF_STATE_CALL_OUT_RSP) ? "CALL OUT(RSP)" : "CALL OUT"); else - if (gDTMF_CallState == DTMF_CALL_STATE_RECEIVED) + if (gDTMF_CallState == DTMF_CALL_STATE_RECEIVED || gDTMF_CallState == DTMF_CALL_STATE_RECEIVED_STAY) sprintf(String, "CALL FRM:%s", (DTMF_FindContact(gDTMF_Caller, Contact)) ? Contact : gDTMF_Caller); else if (gDTMF_IsTx) @@ -359,10 +359,8 @@ void UI_DisplayMain(void) else { sprintf(String, ">%s", gDTMF_InputBox); - - center_line = CENTER_LINE_IN_USE; } - UI_PrintString(String, 2, 0, vfo_num * 3, 8); + UI_PrintString(String, 2, 0, 0 + (vfo_num * 3), 8); memset(String, 0, sizeof(String)); if (!gDTMF_InputMode) @@ -371,16 +369,12 @@ void UI_DisplayMain(void) if (gDTMF_CallState == DTMF_CALL_STATE_CALL_OUT) sprintf(String, ">%s", (DTMF_FindContact(gDTMF_String, Contact)) ? Contact : gDTMF_String); else - if (gDTMF_CallState == DTMF_CALL_STATE_RECEIVED) + if (gDTMF_CallState == DTMF_CALL_STATE_RECEIVED || gDTMF_CallState == DTMF_CALL_STATE_RECEIVED_STAY) sprintf(String, ">%s", (DTMF_FindContact(gDTMF_Callee, Contact)) ? Contact : gDTMF_Callee); else if (gDTMF_IsTx) sprintf(String, ">%s", gDTMF_String); } - else - { - center_line = CENTER_LINE_IN_USE; - } UI_PrintString(String, 2, 0, 2 + (vfo_num * 3), 8); center_line = CENTER_LINE_IN_USE; diff --git a/ui/ui.c b/ui/ui.c index b370182..0ea903a 100644 --- a/ui/ui.c +++ b/ui/ui.c @@ -77,33 +77,28 @@ void GUI_DisplayScreen(void) void GUI_SelectNextDisplay(GUI_DisplayType_t Display) { - if (Display != DISPLAY_INVALID) + if (Display == DISPLAY_INVALID) + return; + + if (gScreenToDisplay != Display) { - if (gScreenToDisplay != Display) - { - gInputBoxIndex = 0; - gIsInSubMenu = false; - gCssScanMode = CSS_SCAN_MODE_OFF; - gScanStateDir = SCAN_OFF; - #ifdef ENABLE_FMRADIO - gFM_ScanState = FM_SCAN_OFF; - #endif - gAskForConfirmation = 0; - gDTMF_InputMode = false; - gDTMF_InputIndex = 0; - gAskToSave = false; - gAskToDelete = false; + DTMF_clear_input_box(); - if (gWasFKeyPressed) - { - gWasFKeyPressed = false; - gUpdateStatus = true; - } + gInputBoxIndex = 0; + gIsInSubMenu = false; + gCssScanMode = CSS_SCAN_MODE_OFF; + gScanStateDir = SCAN_OFF; + #ifdef ENABLE_FMRADIO + gFM_ScanState = FM_SCAN_OFF; + #endif + gAskForConfirmation = 0; + gAskToSave = false; + gAskToDelete = false; + gWasFKeyPressed = false; - gUpdateStatus = true; - } - - gUpdateDisplay = true; - gScreenToDisplay = Display; + gUpdateStatus = true; } + + gScreenToDisplay = Display; + gUpdateDisplay = true; }