diff --git a/Makefile b/Makefile index a7411a9..8843d7d 100644 --- a/Makefile +++ b/Makefile @@ -14,14 +14,15 @@ ENABLE_CHAN_NAME_FREQ := 1 ENABLE_WIDE_RX := 1 ENABLE_TX_WHEN_AM := 0 ENABLE_CTCSS_TAIL_PHASE_SHIFT := 1 +ENABLE_MAIN_KEY_HOLD := 1 #ENABLE_SINGLE_VFO_CHAN := 1 #ENABLE_BAND_SCOPE := 1 TARGET = firmware BSP_DEFINITIONS := $(wildcard hardware/*/*.def) -BSP_HEADERS := $(patsubst hardware/%,bsp/%,$(BSP_DEFINITIONS)) -BSP_HEADERS := $(patsubst %.def,%.h,$(BSP_HEADERS)) +BSP_HEADERS := $(patsubst hardware/%,bsp/%,$(BSP_DEFINITIONS)) +BSP_HEADERS := $(patsubst %.def,%.h,$(BSP_HEADERS)) OBJS = # Startup files @@ -129,7 +130,9 @@ ifeq ($(ENABLE_OVERLAY),1) ASFLAGS += -DENABLE_OVERLAY endif -CFLAGS = -Os -Wall -Werror -mcpu=cortex-m0 -fno-builtin -fshort-enums -fno-delete-null-pointer-checks -std=c11 -MMD +#CFLAGS = -Os -Wall -Werror -mcpu=cortex-m0 -fno-builtin -fshort-enums -fno-delete-null-pointer-checks -std=c11 -MMD +#CFLAGS = -O2 -Wall -Werror -mcpu=cortex-m0 -fno-builtin -fshort-enums -fno-delete-null-pointer-checks -std=c11 -MMD -fdata-sections -ffunction-sections +CFLAGS = -Os -Wall -Werror -mcpu=cortex-m0 -fno-builtin -fshort-enums -fno-delete-null-pointer-checks -std=c11 -MMD -fdata-sections -ffunction-sections CFLAGS += -DPRINTF_INCLUDE_CONFIG_H CFLAGS += -DGIT_HASH=\"$(GIT_HASH)\" ifeq ($(ENABLE_AIRCOPY),1) @@ -171,6 +174,9 @@ endif ifeq ($(ENABLE_CTCSS_TAIL_PHASE_SHIFT),1) CFLAGS += -DENABLE_CTCSS_TAIL_PHASE_SHIFT endif +ifeq ($(ENABLE_MAIN_KEY_HOLD),1) + CFLAGS += -DENABLE_MAIN_KEY_HOLD +endif ifeq ($(ENABLE_SINGLE_VFO_CHAN),1) CFLAGS += -DENABLE_SINGLE_VFO_CHAN endif @@ -179,6 +185,7 @@ ifeq ($(ENABLE_BAND_SCOPE),1) endif LDFLAGS = -mcpu=cortex-m0 -nostartfiles -Wl,-T,firmware.ld +#LDFLAGS = -mcpu=cortex-m0 -nostartfiles -Wl,-T,firmware.ld,--gc-sections ifeq ($(DEBUG),1) ASFLAGS += -g diff --git a/README.md b/README.md index 6d2e098..fbec079 100644 --- a/README.md +++ b/README.md @@ -24,6 +24,7 @@ You can edit those changes by (currently) editing the MakeFile, look for these l * ENABLE_WIDE_RX := 1 enable the RX in the full 18MHz to 1300MHz (though frontend is not tuned for full range) * ENABLE_TX_WHEN_AM := 0 allow TX when RX set to AM * ENABLE_CTCSS_TAIL_PHASE_SHIFT := 1 use CTCSS tail phase shift rather than QS's 55Hz tone method +* ENABLE_MAIN_KEY_HOLD := 1 keys 0-9 can be held down to bypass having to press the F-key * #ENABLE_SINGLE_VFO_CHAN := 1 not yet implemented * #ENABLE_BAND_SCOPE := 1 not yet implemented diff --git a/app/app.c b/app/app.c index 4d14c83..5413443 100644 --- a/app/app.c +++ b/app/app.c @@ -1031,8 +1031,7 @@ void APP_Update(void) // called every 10ms void APP_CheckKeys(void) { - const uint16_t key_repeat_delay = 60; // 600ms - KEY_Code_t Key; + KEY_Code_t Key; #ifdef ENABLE_AIRCOPY if (gSetting_KILLED || (gScreenToDisplay == DISPLAY_AIRCOPY && gAircopyState != AIRCOPY_READY)) @@ -1088,30 +1087,32 @@ void APP_CheckKeys(void) if (++gPttDebounceCounter >= 3) // 30ms { // start transmitting gPttDebounceCounter = 0; - gPttIsPressed = true; + gPttIsPressed = true; APP_ProcessKey(KEY_PTT, true, false); } } else gPttDebounceCounter = 0; + // ***************** + + // scan the hardware keys Key = KEYBOARD_Poll(); if (gKeyReading0 != Key) - { + { // new key pressed + if (gKeyReading0 != KEY_INVALID && Key != KEY_INVALID) - APP_ProcessKey(gKeyReading1, false, gKeyBeingHeld); - - gKeyReading0 = Key; + APP_ProcessKey(gKeyReading1, false, gKeyBeingHeld); // key pressed without releasing previous key + gKeyReading0 = Key; gDebounceCounter = 0; return; } - gDebounceCounter++; + if (++gDebounceCounter == key_debounce) + { // debounced new key pressed - if (gDebounceCounter == 2) - { if (Key == KEY_INVALID) { if (gKeyReading1 != KEY_INVALID) @@ -1127,23 +1128,36 @@ void APP_CheckKeys(void) } gKeyBeingHeld = false; + return; } - else + + // key is being held pressed + if (gDebounceCounter == key_repeat_delay) - { - if (Key == KEY_STAR || Key == KEY_F || Key == KEY_SIDE2 || Key == KEY_SIDE1 || Key == KEY_UP || Key == KEY_DOWN) + { // initial delay after pressed + if (Key == KEY_STAR || + Key == KEY_F || + Key == KEY_SIDE2 || + Key == KEY_SIDE1 || + Key == KEY_UP || + Key == KEY_DOWN + #ifdef ENABLE_MAIN_KEY_HOLD + || Key <= KEY_9 // keys 0-9 can be held down to bypass pressing the F-Key + #endif + ) { gKeyBeingHeld = true; APP_ProcessKey(Key, true, true); } + return; } - else + if (gDebounceCounter > key_repeat_delay) - { + { // key repeat if (Key == KEY_UP || Key == KEY_DOWN) { gKeyBeingHeld = true; - if ((gDebounceCounter & 15) == 0) + if ((gDebounceCounter % key_repeat) == 0) APP_ProcessKey(Key, true, true); } @@ -1151,6 +1165,7 @@ void APP_CheckKeys(void) return; gDebounceCounter = key_repeat_delay; + return; } } @@ -1481,7 +1496,7 @@ void APP_TimeSlice500ms(void) { if (--gVoltageMenuCountdown == 0) { - if (gInputBoxIndex || gDTMF_InputMode || gScreenToDisplay == DISPLAY_MENU) + if (gInputBoxIndex > 0 || gDTMF_InputMode || gScreenToDisplay == DISPLAY_MENU) AUDIO_PlayBeep(BEEP_500HZ_60MS_DOUBLE_BEEP_OPTIONAL); if (gScreenToDisplay == DISPLAY_SCANNER) diff --git a/app/generic.c b/app/generic.c index 78f5646..fdbe80e 100644 --- a/app/generic.c +++ b/app/generic.c @@ -35,7 +35,7 @@ void GENERIC_Key_F(bool bKeyPressed, bool bKeyHeld) { - if (gInputBoxIndex) + if (gInputBoxIndex > 0) { if (!bKeyHeld && bKeyPressed) gBeepToPlay = BEEP_500HZ_60MS_DOUBLE_BEEP_OPTIONAL; diff --git a/app/main.c b/app/main.c index 830b711..cee7b1d 100644 --- a/app/main.c +++ b/app/main.c @@ -37,13 +37,205 @@ // #define ARRAY_SIZE(x) (sizeof(x) / sizeof(x[0])) //#endif -static void MAIN_Key_DIGITS(KEY_Code_t Key, bool bKeyPressed, bool bKeyHeld) +static void processFKeyFunction(const KEY_Code_t Key) { uint8_t Band; uint8_t Vfo = gEeprom.TX_CHANNEL; + switch (Key) + { + case KEY_0: + #ifdef ENABLE_FMRADIO + ACTION_FM(); + #endif + break; + + case KEY_1: + if (!IS_FREQ_CHANNEL(gTxVfo->CHANNEL_SAVE)) + { + gWasFKeyPressed = false; + gUpdateStatus = true; + gBeepToPlay = BEEP_1KHZ_60MS_OPTIONAL; + return; + } + + Band = gTxVfo->Band + 1; + if (gSetting_350EN || Band != BAND5_350MHz) + { + if (BAND7_470MHz < Band) + Band = BAND1_50MHz; + } + else + Band = BAND6_400MHz; + gTxVfo->Band = Band; + + gEeprom.ScreenChannel[Vfo] = FREQ_CHANNEL_FIRST + Band; + gEeprom.FreqChannel[Vfo] = FREQ_CHANNEL_FIRST + Band; + gRequestSaveVFO = true; + gVfoConfigureMode = VFO_CONFIGURE_RELOAD; + gBeepToPlay = BEEP_1KHZ_60MS_OPTIONAL; + gRequestDisplayScreen = DISPLAY_MAIN; + break; + + case KEY_2: + if (gEeprom.CROSS_BAND_RX_TX == CROSS_BAND_CHAN_A) + gEeprom.CROSS_BAND_RX_TX = CROSS_BAND_CHAN_B; + else + if (gEeprom.CROSS_BAND_RX_TX == CROSS_BAND_CHAN_B) + gEeprom.CROSS_BAND_RX_TX = CROSS_BAND_CHAN_A; + else + if (gEeprom.DUAL_WATCH == DUAL_WATCH_CHAN_A) + gEeprom.DUAL_WATCH = DUAL_WATCH_CHAN_B; + else + if (gEeprom.DUAL_WATCH == DUAL_WATCH_CHAN_B) + gEeprom.DUAL_WATCH = DUAL_WATCH_CHAN_A; + else + gEeprom.TX_CHANNEL = (Vfo == 0); + + gRequestSaveSettings = 1; + gFlagReconfigureVfos = true; + gRequestDisplayScreen = DISPLAY_MAIN; + gBeepToPlay = BEEP_1KHZ_60MS_OPTIONAL; + break; + + case KEY_3: + #ifdef ENABLE_NOAA + if (gEeprom.VFO_OPEN && IS_NOT_NOAA_CHANNEL(gTxVfo->CHANNEL_SAVE)) + #else + if (gEeprom.VFO_OPEN) + #endif + { + uint8_t Channel; + + if (IS_MR_CHANNEL(gTxVfo->CHANNEL_SAVE)) + { + gEeprom.ScreenChannel[Vfo] = gEeprom.FreqChannel[gEeprom.TX_CHANNEL]; + #ifdef ENABLE_VOICE + gAnotherVoiceID = VOICE_ID_FREQUENCY_MODE; + #endif + gRequestSaveVFO = true; + gVfoConfigureMode = VFO_CONFIGURE_RELOAD; + break; + } + + Channel = RADIO_FindNextChannel(gEeprom.MrChannel[gEeprom.TX_CHANNEL], 1, false, 0); + if (Channel != 0xFF) + { + gEeprom.ScreenChannel[Vfo] = Channel; + #ifdef ENABLE_VOICE + AUDIO_SetVoiceID(0, VOICE_ID_CHANNEL_MODE); + AUDIO_SetDigitVoice(1, Channel + 1); + gAnotherVoiceID = (VOICE_ID_t)0xFE; + #endif + gRequestSaveVFO = true; + gVfoConfigureMode = VFO_CONFIGURE_RELOAD; + break; + } + } + + gBeepToPlay = BEEP_500HZ_60MS_DOUBLE_BEEP_OPTIONAL; + break; + + case KEY_4: + gWasFKeyPressed = false; + gUpdateStatus = true; + gBeepToPlay = BEEP_1KHZ_60MS_OPTIONAL; + gFlagStartScan = true; + gScanSingleFrequency = false; + gBackupCROSS_BAND_RX_TX = gEeprom.CROSS_BAND_RX_TX; + gEeprom.CROSS_BAND_RX_TX = CROSS_BAND_OFF; + break; + + case KEY_5: + // TODO: something wrong here !! + #ifdef ENABLE_NOAA + if (IS_NOT_NOAA_CHANNEL(gTxVfo->CHANNEL_SAVE)) + { + gEeprom.ScreenChannel[Vfo] = gEeprom.NoaaChannel[gEeprom.TX_CHANNEL]; + } + else + { + gEeprom.ScreenChannel[Vfo] = gEeprom.FreqChannel[gEeprom.TX_CHANNEL]; + #ifdef ENABLE_VOICE + gAnotherVoiceID = VOICE_ID_FREQUENCY_MODE; + #endif + } + #else + //gEeprom.ScreenChannel[Vfo] = gEeprom.NoaaChannel[gEeprom.TX_CHANNEL]; + gEeprom.ScreenChannel[Vfo] = gEeprom.FreqChannel[gEeprom.TX_CHANNEL]; + #ifdef ENABLE_VOICE + gAnotherVoiceID = VOICE_ID_FREQUENCY_MODE; + #endif + #endif + + gRequestSaveVFO = true; + gVfoConfigureMode = VFO_CONFIGURE_RELOAD; + break; + + case KEY_6: + ACTION_Power(); + break; + + case KEY_7: + ACTION_Vox(); + break; + + case KEY_8: + gTxVfo->FrequencyReverse = gTxVfo->FrequencyReverse == false; + gRequestSaveChannel = 1; + break; + + case KEY_9: + if (RADIO_CheckValidChannel(gEeprom.CHAN_1_CALL, false, 0)) + { + gEeprom.MrChannel[Vfo] = gEeprom.CHAN_1_CALL; + gEeprom.ScreenChannel[Vfo] = gEeprom.CHAN_1_CALL; + #ifdef ENABLE_VOICE + AUDIO_SetVoiceID(0, VOICE_ID_CHANNEL_MODE); + AUDIO_SetDigitVoice(1, gEeprom.CHAN_1_CALL + 1); + gAnotherVoiceID = (VOICE_ID_t)0xFE; + #endif + gRequestSaveVFO = true; + gVfoConfigureMode = VFO_CONFIGURE_RELOAD; + break; + } + + gBeepToPlay = BEEP_500HZ_60MS_DOUBLE_BEEP_OPTIONAL; + break; + + default: + gBeepToPlay = BEEP_1KHZ_60MS_OPTIONAL; + gUpdateStatus = true; + gWasFKeyPressed = false; + break; + } +} + +static void MAIN_Key_DIGITS(KEY_Code_t Key, bool bKeyPressed, bool bKeyHeld) +{ if (bKeyHeld) + { // key held down + + #ifdef ENABLE_MAIN_KEY_HOLD + if (bKeyPressed) + { + if (gScreenToDisplay == DISPLAY_MAIN) + { // we're going to go straight to the function key function + // without the F-key being first pressed + if (gInputBoxIndex > 0) + { // delete last char inputted + gInputBoxIndex = 0; + gRequestDisplayScreen = DISPLAY_MAIN; + } + gWasFKeyPressed = false; + gUpdateStatus = true; + processFKeyFunction(Key); + } + } + #endif + return; + } if (!bKeyPressed) return; @@ -52,7 +244,10 @@ static void MAIN_Key_DIGITS(KEY_Code_t Key, bool bKeyPressed, bool bKeyHeld) if (!gWasFKeyPressed) { + uint8_t Vfo = gEeprom.TX_CHANNEL; + INPUTBOX_Append(Key); + gRequestDisplayScreen = DISPLAY_MAIN; if (IS_MR_CHANNEL(gTxVfo->CHANNEL_SAVE)) @@ -105,7 +300,7 @@ static void MAIN_Key_DIGITS(KEY_Code_t Key, bool bKeyPressed, bool bKeyHeld) NUMBER_Get(gInputBox, &Frequency); - if (gSetting_350EN || Frequency < 35000000 || Frequency >= 40000000) + if (gSetting_350EN || Frequency < 35000000 || Frequency >= 40000000) { unsigned int i; for (i = 0; i < 7; i++) @@ -142,7 +337,7 @@ static void MAIN_Key_DIGITS(KEY_Code_t Key, bool bKeyPressed, bool bKeyHeld) else { uint8_t Channel; - + if (gInputBoxIndex != 2) { #ifdef ENABLE_VOICE @@ -151,9 +346,9 @@ static void MAIN_Key_DIGITS(KEY_Code_t Key, bool bKeyPressed, bool bKeyHeld) gRequestDisplayScreen = DISPLAY_MAIN; return; } - + gInputBoxIndex = 0; - + Channel = (gInputBox[0] * 10) + gInputBox[1]; if (Channel >= 1 && Channel <= 10) { @@ -169,7 +364,7 @@ static void MAIN_Key_DIGITS(KEY_Code_t Key, bool bKeyPressed, bool bKeyHeld) } } #endif - + gRequestDisplayScreen = DISPLAY_MAIN; gBeepToPlay = BEEP_500HZ_60MS_DOUBLE_BEEP_OPTIONAL; return; @@ -178,173 +373,7 @@ static void MAIN_Key_DIGITS(KEY_Code_t Key, bool bKeyPressed, bool bKeyHeld) gWasFKeyPressed = false; gUpdateStatus = true; - switch (Key) - { - case KEY_0: - #ifdef ENABLE_FMRADIO - ACTION_FM(); - #endif - break; - - case KEY_1: - if (!IS_FREQ_CHANNEL(gTxVfo->CHANNEL_SAVE)) - { - gWasFKeyPressed = false; - gUpdateStatus = true; - gBeepToPlay = BEEP_1KHZ_60MS_OPTIONAL; - return; - } - - Band = gTxVfo->Band + 1; - if (gSetting_350EN || Band != BAND5_350MHz) - { - if (BAND7_470MHz < Band) - Band = BAND1_50MHz; - } - else - Band = BAND6_400MHz; - gTxVfo->Band = Band; - - gEeprom.ScreenChannel[Vfo] = FREQ_CHANNEL_FIRST + Band; - gEeprom.FreqChannel[Vfo] = FREQ_CHANNEL_FIRST + Band; - gRequestSaveVFO = true; - gVfoConfigureMode = VFO_CONFIGURE_RELOAD; - gBeepToPlay = BEEP_1KHZ_60MS_OPTIONAL; - gRequestDisplayScreen = DISPLAY_MAIN; - break; - - case KEY_2: - if (gEeprom.CROSS_BAND_RX_TX == CROSS_BAND_CHAN_A) - gEeprom.CROSS_BAND_RX_TX = CROSS_BAND_CHAN_B; - else - if (gEeprom.CROSS_BAND_RX_TX == CROSS_BAND_CHAN_B) - gEeprom.CROSS_BAND_RX_TX = CROSS_BAND_CHAN_A; - else - if (gEeprom.DUAL_WATCH == DUAL_WATCH_CHAN_A) - gEeprom.DUAL_WATCH = DUAL_WATCH_CHAN_B; - else - if (gEeprom.DUAL_WATCH == DUAL_WATCH_CHAN_B) - gEeprom.DUAL_WATCH = DUAL_WATCH_CHAN_A; - else - gEeprom.TX_CHANNEL = (Vfo == 0); - - gRequestSaveSettings = 1; - gFlagReconfigureVfos = true; - gRequestDisplayScreen = DISPLAY_MAIN; - gBeepToPlay = BEEP_1KHZ_60MS_OPTIONAL; - break; - - case KEY_3: - #ifdef ENABLE_NOAA - if (gEeprom.VFO_OPEN && IS_NOT_NOAA_CHANNEL(gTxVfo->CHANNEL_SAVE)) - #else - if (gEeprom.VFO_OPEN) - #endif - { - uint8_t Channel; - - if (IS_MR_CHANNEL(gTxVfo->CHANNEL_SAVE)) - { - gEeprom.ScreenChannel[Vfo] = gEeprom.FreqChannel[gEeprom.TX_CHANNEL]; - #ifdef ENABLE_VOICE - gAnotherVoiceID = VOICE_ID_FREQUENCY_MODE; - #endif - gRequestSaveVFO = true; - gVfoConfigureMode = VFO_CONFIGURE_RELOAD; - break; - } - - Channel = RADIO_FindNextChannel(gEeprom.MrChannel[gEeprom.TX_CHANNEL], 1, false, 0); - if (Channel != 0xFF) - { - gEeprom.ScreenChannel[Vfo] = Channel; - #ifdef ENABLE_VOICE - AUDIO_SetVoiceID(0, VOICE_ID_CHANNEL_MODE); - AUDIO_SetDigitVoice(1, Channel + 1); - gAnotherVoiceID = (VOICE_ID_t)0xFE; - #endif - gRequestSaveVFO = true; - gVfoConfigureMode = VFO_CONFIGURE_RELOAD; - break; - } - } - - gBeepToPlay = BEEP_500HZ_60MS_DOUBLE_BEEP_OPTIONAL; - break; - - case KEY_4: - gWasFKeyPressed = false; - gUpdateStatus = true; - gBeepToPlay = BEEP_1KHZ_60MS_OPTIONAL; - gFlagStartScan = true; - gScanSingleFrequency = false; - gBackupCROSS_BAND_RX_TX = gEeprom.CROSS_BAND_RX_TX; - gEeprom.CROSS_BAND_RX_TX = CROSS_BAND_OFF; - break; - - case KEY_5: - // TODO: something wrong here !! - #ifdef ENABLE_NOAA - if (IS_NOT_NOAA_CHANNEL(gTxVfo->CHANNEL_SAVE)) - { - gEeprom.ScreenChannel[Vfo] = gEeprom.NoaaChannel[gEeprom.TX_CHANNEL]; - } - else - { - gEeprom.ScreenChannel[Vfo] = gEeprom.FreqChannel[gEeprom.TX_CHANNEL]; - #ifdef ENABLE_VOICE - gAnotherVoiceID = VOICE_ID_FREQUENCY_MODE; - #endif - } - #else - //gEeprom.ScreenChannel[Vfo] = gEeprom.NoaaChannel[gEeprom.TX_CHANNEL]; - gEeprom.ScreenChannel[Vfo] = gEeprom.FreqChannel[gEeprom.TX_CHANNEL]; - #ifdef ENABLE_VOICE - gAnotherVoiceID = VOICE_ID_FREQUENCY_MODE; - #endif - #endif - - gRequestSaveVFO = true; - gVfoConfigureMode = VFO_CONFIGURE_RELOAD; - break; - - case KEY_6: - ACTION_Power(); - break; - - case KEY_7: - ACTION_Vox(); - break; - - case KEY_8: - gTxVfo->FrequencyReverse = gTxVfo->FrequencyReverse == false; - gRequestSaveChannel = 1; - break; - - case KEY_9: - if (RADIO_CheckValidChannel(gEeprom.CHAN_1_CALL, false, 0)) - { - gEeprom.MrChannel[Vfo] = gEeprom.CHAN_1_CALL; - gEeprom.ScreenChannel[Vfo] = gEeprom.CHAN_1_CALL; - #ifdef ENABLE_VOICE - AUDIO_SetVoiceID(0, VOICE_ID_CHANNEL_MODE); - AUDIO_SetDigitVoice(1, gEeprom.CHAN_1_CALL + 1); - gAnotherVoiceID = (VOICE_ID_t)0xFE; - #endif - gRequestSaveVFO = true; - gVfoConfigureMode = VFO_CONFIGURE_RELOAD; - break; - } - - gBeepToPlay = BEEP_500HZ_60MS_DOUBLE_BEEP_OPTIONAL; - break; - - default: - gBeepToPlay = BEEP_1KHZ_60MS_OPTIONAL; - gUpdateStatus = true; - gWasFKeyPressed = false; - break; - } + processFKeyFunction(Key); } static void MAIN_Key_EXIT(bool bKeyPressed, bool bKeyHeld) @@ -477,7 +506,7 @@ static void MAIN_Key_STAR(bool bKeyPressed, bool bKeyHeld) gBackupCROSS_BAND_RX_TX = gEeprom.CROSS_BAND_RX_TX; gEeprom.CROSS_BAND_RX_TX = CROSS_BAND_OFF; #endif - + gPttWasReleased = true; } } @@ -503,7 +532,7 @@ static void MAIN_Key_UP_DOWN(bool bKeyPressed, bool bKeyHeld, int8_t Direction) AUDIO_SetDigitVoice(0, gTxVfo->CHANNEL_SAVE + 1); gAnotherVoiceID = (VOICE_ID_t)0xFE; #endif - + return; } } @@ -558,7 +587,7 @@ static void MAIN_Key_UP_DOWN(bool bKeyPressed, bool bKeyHeld, int8_t Direction) gEeprom.ScreenChannel[gEeprom.TX_CHANNEL] = Channel; } #endif - + gRequestSaveVFO = true; gVfoConfigureMode = VFO_CONFIGURE_RELOAD; return; diff --git a/app/menu.c b/app/menu.c index 655bbcd..58863d1 100644 --- a/app/menu.c +++ b/app/menu.c @@ -977,9 +977,9 @@ static void MENU_Key_DIGITS(KEY_Code_t Key, bool bKeyPressed, bool bKeyHeld) return; } - gInputBoxIndex = 0; + gInputBoxIndex = 0; NUMBER_Get(gInputBox, &Frequency); - Frequency += 75; + Frequency += 75; #ifdef ENABLE_VOICE gAnotherVoiceID = (VOICE_ID_t)Key; #endif diff --git a/app/scanner.c b/app/scanner.c index 299cc26..cc914f1 100644 --- a/app/scanner.c +++ b/app/scanner.c @@ -102,7 +102,7 @@ static void SCANNER_Key_EXIT(bool bKeyPressed, bool bKeyHeld) break; case 1: - if (gInputBoxIndex) + if (gInputBoxIndex > 0) { gInputBox[--gInputBoxIndex] = 10; gRequestDisplayScreen = DISPLAY_SCANNER; diff --git a/driver/keyboard.c b/driver/keyboard.c index ffc3422..6f5f0d9 100644 --- a/driver/keyboard.c +++ b/driver/keyboard.c @@ -22,8 +22,8 @@ KEY_Code_t gKeyReading0 = KEY_INVALID; KEY_Code_t gKeyReading1 = KEY_INVALID; -uint16_t gDebounceCounter; -bool gWasFKeyPressed; +uint16_t gDebounceCounter; +bool gWasFKeyPressed; KEY_Code_t KEYBOARD_Poll(void) { @@ -36,6 +36,7 @@ KEY_Code_t KEYBOARD_Poll(void) SYSTICK_DelayUs(1); + // ***************** // Keys connected to gnd if (!GPIO_CheckBit(&GPIOA->DATA, GPIOA_PIN_KEYBOARD_0)) @@ -52,7 +53,9 @@ KEY_Code_t KEYBOARD_Poll(void) // Original doesn't do PTT + // ***************** // First row + GPIO_ClearBit(&GPIOA->DATA, GPIOA_PIN_KEYBOARD_4); SYSTICK_DelayUs(1); @@ -80,7 +83,9 @@ KEY_Code_t KEYBOARD_Poll(void) goto Bye; } + // ***************** // Second row + GPIO_ClearBit(&GPIOA->DATA, GPIOA_PIN_KEYBOARD_5); SYSTICK_DelayUs(1); @@ -111,7 +116,9 @@ KEY_Code_t KEYBOARD_Poll(void) goto Bye; } + // ***************** // Third row + GPIO_ClearBit(&GPIOA->DATA, GPIOA_PIN_KEYBOARD_4); SYSTICK_DelayUs(1); @@ -148,7 +155,9 @@ KEY_Code_t KEYBOARD_Poll(void) goto Bye; } + // ***************** // Fourth row + GPIO_ClearBit(&GPIOA->DATA, GPIOA_PIN_KEYBOARD_7); SYSTICK_DelayUs(1); @@ -179,6 +188,8 @@ KEY_Code_t KEYBOARD_Poll(void) goto Bye; } + // ***************** + Bye: GPIO_SetBit(&GPIOA->DATA, GPIOA_PIN_KEYBOARD_4); GPIO_SetBit(&GPIOA->DATA, GPIOA_PIN_KEYBOARD_5); diff --git a/firmware b/firmware index 1d1fe3c..2ca89fd 100644 Binary files a/firmware and b/firmware differ diff --git a/firmware.bin b/firmware.bin index 2ffde21..446b70e 100644 Binary files a/firmware.bin and b/firmware.bin differ diff --git a/firmware.packed.bin b/firmware.packed.bin index bce0348..d8f0163 100644 Binary files a/firmware.packed.bin and b/firmware.packed.bin differ diff --git a/misc.c b/misc.c index cb58590..c1cf0ae 100644 --- a/misc.c +++ b/misc.c @@ -18,13 +18,16 @@ #include "misc.h" -const uint8_t g_scan_delay = 21; // 210ms -//const uint8_t g_scan_delay = 2; // 20ms +const uint16_t key_repeat_delay = 40; // 400ms +const uint16_t key_repeat = 8; // was 15 (150ms) .. MUST be less than 'key_repeat_delay' +const uint16_t key_debounce = 2; // 20ms + +const uint8_t g_scan_delay = 21; // 210ms const uint8_t g_menu_timeout = 2 * 30; // 30 seconds -const uint16_t gMax_bat_v = 843; // 8.43V -const uint16_t gMin_bat_v = 660; // 6.6V +const uint16_t gMax_bat_v = 843; // 8.43V +const uint16_t gMin_bat_v = 660; // 6.6V const uint32_t gDefaultAesKey[4] = {0x4AA5CC60, 0x0312CC5F, 0xFFD2DABB, 0x6BBA7F92}; diff --git a/misc.h b/misc.h index fa9d21f..fc16403 100644 --- a/misc.h +++ b/misc.h @@ -74,6 +74,10 @@ enum CssScanMode_t typedef enum CssScanMode_t CssScanMode_t; +extern const uint16_t key_repeat_delay; +extern const uint16_t key_repeat; +extern const uint16_t key_debounce; + extern const uint8_t g_scan_delay; extern const uint8_t g_menu_timeout; diff --git a/ui/fmradio.c b/ui/fmradio.c index 4eafa5a..9574f5f 100644 --- a/ui/fmradio.c +++ b/ui/fmradio.c @@ -81,7 +81,7 @@ void UI_DisplayFM(void) UI_PrintString(String, 0, 127, 2, 10); memset(String, 0, sizeof(String)); - if (gAskToSave || (gEeprom.FM_IsMrMode && gInputBoxIndex)) + if (gAskToSave || (gEeprom.FM_IsMrMode && gInputBoxIndex > 0)) { UI_GenerateChannelString(String, gFM_ChannelPosition); } diff --git a/ui/helper.c b/ui/helper.c index e9be833..7500f12 100644 --- a/ui/helper.c +++ b/ui/helper.c @@ -45,7 +45,7 @@ void UI_GenerateChannelString(char *pString, const uint8_t Channel) void UI_GenerateChannelStringEx(char *pString, const bool bShowPrefix, const uint8_t ChannelNumber) { - if (gInputBoxIndex) + if (gInputBoxIndex > 0) { unsigned int i; for (i = 0; i < 3; i++) diff --git a/ui/inputbox.c b/ui/inputbox.c index 91a1444..a11cfc2 100644 --- a/ui/inputbox.c +++ b/ui/inputbox.c @@ -15,18 +15,20 @@ */ #include + #include "ui/inputbox.h" -char gInputBox[8]; +char gInputBox[8]; uint8_t gInputBoxIndex; void INPUTBOX_Append(char Digit) { - if (gInputBoxIndex == 0) { + if (gInputBoxIndex == 0) memset(gInputBox, 10, sizeof(gInputBox)); - } else if (gInputBoxIndex >= sizeof(gInputBox)) { + else + if (gInputBoxIndex >= sizeof(gInputBox)) return; - } + gInputBox[gInputBoxIndex++] = Digit; } diff --git a/ui/inputbox.h b/ui/inputbox.h index 66026f2..be01fe9 100644 --- a/ui/inputbox.h +++ b/ui/inputbox.h @@ -19,7 +19,7 @@ #include -extern char gInputBox[8]; +extern char gInputBox[8]; extern uint8_t gInputBoxIndex; void INPUTBOX_Append(char Digit); diff --git a/ui/lock.c b/ui/lock.c index 8b0f27a..a094a2d 100644 --- a/ui/lock.c +++ b/ui/lock.c @@ -62,11 +62,12 @@ void UI_DisplayLock(void) // TODO: Original code doesn't do the below, but is needed for proper key debounce gNextTimeslice = false; - Key = KEYBOARD_Poll(); + + Key = KEYBOARD_Poll(); if (gKeyReading0 == Key) { - if (++gDebounceCounter == 2) + if (++gDebounceCounter == key_debounce) { if (Key == KEY_INVALID) { @@ -89,7 +90,8 @@ void UI_DisplayLock(void) case KEY_8: case KEY_9: INPUTBOX_Append(Key - KEY_0); - if (gInputBoxIndex < 6) + + if (gInputBoxIndex < 6) // 6 frequency digits { Beep = BEEP_1KHZ_60MS_OPTIONAL; } @@ -118,7 +120,7 @@ void UI_DisplayLock(void) break; case KEY_EXIT: - if (gInputBoxIndex) + if (gInputBoxIndex > 0) { gInputBox[--gInputBoxIndex] = 10; gUpdateDisplay = true; diff --git a/ui/main.c b/ui/main.c index 01920ee..cced1c0 100644 --- a/ui/main.c +++ b/ui/main.c @@ -170,11 +170,10 @@ void UI_DisplayMain(void) // show the memory channel symbol memcpy(pLine1 + x, BITMAP_M, sizeof(BITMAP_M)); - // show the memory channel number if (gInputBoxIndex == 0 || gEeprom.TX_CHANNEL != vfo_num) - NUMBER_ToDigits(gEeprom.ScreenChannel[vfo_num] + 1, String); + NUMBER_ToDigits(gEeprom.ScreenChannel[vfo_num] + 1, String); // show the memory channel number else - memcpy(String + 5, gInputBox, 3); + memcpy(String + 5, gInputBox, 3); // show the input text UI_DisplaySmallDigits(3, String + 5, x + sizeof(BITMAP_M), Line + 1, false); } else @@ -258,7 +257,7 @@ void UI_DisplayMain(void) else { // normal state - if (gInputBoxIndex && IS_FREQ_CHANNEL(gEeprom.ScreenChannel[vfo_num]) && gEeprom.TX_CHANNEL == vfo_num) + if (gInputBoxIndex > 0 && IS_FREQ_CHANNEL(gEeprom.ScreenChannel[vfo_num]) && gEeprom.TX_CHANNEL == vfo_num) { // user is entering a new frequency UI_DisplayFrequency(gInputBox, 31, Line, true, false); }