From 18daf70365b8405e76f4028ff1a16d9cba146a4f Mon Sep 17 00:00:00 2001 From: Armel FAUVEAU Date: Thu, 31 Oct 2024 00:37:47 +0100 Subject: [PATCH] Add Narrower feature --- Makefile | 6 ++++- app/action.c | 68 ++++++++++++++++++++++++++++++++++++++-------------- app/menu.c | 18 ++++++++++++++ misc.c | 3 +++ misc.h | 3 +++ radio.c | 16 +++++++++++++ settings.c | 13 ++++++++-- ui/main.c | 40 +++++++++++++++++++++++-------- ui/menu.c | 24 +++++++++++++++---- ui/menu.h | 6 +++++ 10 files changed, 162 insertions(+), 35 deletions(-) diff --git a/Makefile b/Makefile index 99785b3..d4fed6c 100644 --- a/Makefile +++ b/Makefile @@ -47,8 +47,9 @@ ENABLE_FEAT_F4HWN_RX_TX_TIMER ?= 1 ENABLE_FEAT_F4HWN_CHARGING_C ?= 1 ENABLE_FEAT_F4HWN_SLEEP ?= 1 ENABLE_FEAT_F4HWN_RESTORE_SCAN ?= 1 +ENABLE_FEAT_F4HWN_NARROWER ?= 1 ENABLE_FEAT_F4HWN_RESET_CHANNEL ?= 0 -ENABLE_FEAT_F4HWN_PMR ?= 0 +ENABLE_FEAT_F4HWN_PMR ?= 0 ENABLE_FEAT_F4HWN_GMRS_FRS_MURS ?= 0 ENABLE_FEAT_F4HWN_CA ?= 1 @@ -427,6 +428,9 @@ endif ifeq ($(ENABLE_FEAT_F4HWN_RESTORE_SCAN),1) CFLAGS += -DENABLE_FEAT_F4HWN_RESTORE_SCAN endif +ifeq ($(ENABLE_FEAT_F4HWN_NARROWER),1) + CFLAGS += -DENABLE_FEAT_F4HWN_NARROWER +endif ifeq ($(ENABLE_FEAT_F4HWN_RESET_CHANNEL),1) CFLAGS += -DENABLE_FEAT_F4HWN_RESET_CHANNEL endif diff --git a/app/action.c b/app/action.c index d1aa3ec..4d33bb5 100644 --- a/app/action.c +++ b/app/action.c @@ -525,24 +525,56 @@ void ACTION_Ptt(void) void ACTION_Wn(void) { - if (FUNCTION_IsRx()) - { - gRxVfo->CHANNEL_BANDWIDTH = (gRxVfo->CHANNEL_BANDWIDTH == 0) ? 1: 0; - #ifdef ENABLE_AM_FIX - BK4819_SetFilterBandwidth(gRxVfo->CHANNEL_BANDWIDTH, true); - #else - BK4819_SetFilterBandwidth(gRxVfo->CHANNEL_BANDWIDTH, false); - #endif - } - else - { - gTxVfo->CHANNEL_BANDWIDTH = (gTxVfo->CHANNEL_BANDWIDTH == 0) ? 1: 0; - #ifdef ENABLE_AM_FIX - BK4819_SetFilterBandwidth(gTxVfo->CHANNEL_BANDWIDTH, true); - #else - BK4819_SetFilterBandwidth(gTxVfo->CHANNEL_BANDWIDTH, false); - #endif - } + #ifdef ENABLE_FEAT_F4HWN_NARROWER + bool narrower = 0; + if (FUNCTION_IsRx()) + { + gRxVfo->CHANNEL_BANDWIDTH = (gRxVfo->CHANNEL_BANDWIDTH == 0) ? 1: 0; + if(gRxVfo->CHANNEL_BANDWIDTH == BANDWIDTH_NARROW && gSetting_set_nfm == 1) + { + narrower = 1; + } + + #ifdef ENABLE_AM_FIX + BK4819_SetFilterBandwidth(gRxVfo->CHANNEL_BANDWIDTH + narrower, true); + #else + BK4819_SetFilterBandwidth(gRxVfo->CHANNEL_BANDWIDTH + narrower, false); + #endif + } + else + { + gTxVfo->CHANNEL_BANDWIDTH = (gTxVfo->CHANNEL_BANDWIDTH == 0) ? 1: 0; + if(gTxVfo->CHANNEL_BANDWIDTH == BANDWIDTH_NARROW && gSetting_set_nfm == 1) + { + narrower = 1; + } + + #ifdef ENABLE_AM_FIX + BK4819_SetFilterBandwidth(gTxVfo->CHANNEL_BANDWIDTH, true); + #else + BK4819_SetFilterBandwidth(gTxVfo->CHANNEL_BANDWIDTH, false); + #endif + } + #else + if (FUNCTION_IsRx()) + { + gRxVfo->CHANNEL_BANDWIDTH = (gRxVfo->CHANNEL_BANDWIDTH == 0) ? 1: 0; + #ifdef ENABLE_AM_FIX + BK4819_SetFilterBandwidth(gRxVfo->CHANNEL_BANDWIDTH, true); + #else + BK4819_SetFilterBandwidth(gRxVfo->CHANNEL_BANDWIDTH, false); + #endif + } + else + { + gTxVfo->CHANNEL_BANDWIDTH = (gTxVfo->CHANNEL_BANDWIDTH == 0) ? 1: 0; + #ifdef ENABLE_AM_FIX + BK4819_SetFilterBandwidth(gTxVfo->CHANNEL_BANDWIDTH, true); + #else + BK4819_SetFilterBandwidth(gTxVfo->CHANNEL_BANDWIDTH, false); + #endif + } + #endif } void ACTION_BackLight(void) diff --git a/app/menu.c b/app/menu.c index 44886dc..bfddebe 100644 --- a/app/menu.c +++ b/app/menu.c @@ -418,6 +418,12 @@ int MENU_GetLimits(uint8_t menu_id, int32_t *pMin, int32_t *pMax) //*pMin = 0; *pMax = ARRAY_SIZE(gSubMenu_SET_MET) - 1; break; + #ifdef ENABLE_FEAT_F4HWN_NARROWER + case MENU_SET_NFM: + //*pMin = 0; + *pMax = ARRAY_SIZE(gSubMenu_SET_NFM) - 1; + break; + #endif #endif default: @@ -917,6 +923,13 @@ void MENU_AcceptSetting(void) case MENU_SET_GUI: gSetting_set_gui = gSubMenuSelection; break; + #ifdef ENABLE_FEAT_F4HWN_NARROWER + case MENU_SET_NFM: + gSetting_set_nfm = gSubMenuSelection; + RADIO_SetTxParameters(); + RADIO_SetupRegisters(true); + break; + #endif case MENU_SET_TMR: gSetting_set_tmr = gSubMenuSelection; break; @@ -1351,6 +1364,11 @@ void MENU_ShowCurrentSetting(void) case MENU_SET_GUI: gSubMenuSelection = gSetting_set_gui; break; + #ifdef ENABLE_FEAT_F4HWN_NARROWER + case MENU_SET_NFM: + gSubMenuSelection = gSetting_set_nfm; + break; + #endif case MENU_SET_TMR: gSubMenuSelection = gSetting_set_tmr; break; diff --git a/misc.c b/misc.c index 5b34b20..40adb3b 100644 --- a/misc.c +++ b/misc.c @@ -125,6 +125,9 @@ enum BacklightOnRxTx_t gSetting_backlight_on_tx_rx; bool gSetting_set_lck = false; bool gSetting_set_met = 0; bool gSetting_set_gui = 0; + #ifdef ENABLE_FEAT_F4HWN_NARROWER + bool gSetting_set_nfm = 0; + #endif bool gSetting_set_tmr = 0; bool gSetting_set_ptt_session; uint8_t gDebug; diff --git a/misc.h b/misc.h index a4d25b0..9b05c2a 100644 --- a/misc.h +++ b/misc.h @@ -178,6 +178,9 @@ extern enum BacklightOnRxTx_t gSetting_backlight_on_tx_rx; extern bool gSetting_set_lck; extern bool gSetting_set_met; extern bool gSetting_set_gui; + #ifdef ENABLE_FEAT_F4HWN_NARROWER + extern bool gSetting_set_nfm; + #endif extern bool gSetting_set_tmr; extern bool gSetting_set_ptt_session; extern uint8_t gDebug; diff --git a/radio.c b/radio.c index 5170545..0fe2b1a 100644 --- a/radio.c +++ b/radio.c @@ -658,6 +658,13 @@ void RADIO_SetupRegisters(bool switchToForeground) { BK4819_FilterBandwidth_t Bandwidth = gRxVfo->CHANNEL_BANDWIDTH; + #ifdef ENABLE_FEAT_F4HWN_NARROWER + if(Bandwidth == BK4819_FILTER_BW_NARROW && gSetting_set_nfm == 1) + { + Bandwidth = BK4819_FILTER_BW_NARROWER; + } + #endif + AUDIO_AudioPathOff(); gEnableSpeaker = false; @@ -671,6 +678,7 @@ void RADIO_SetupRegisters(bool switchToForeground) [[fallthrough]]; case BK4819_FILTER_BW_WIDE: case BK4819_FILTER_BW_NARROW: + case BK4819_FILTER_BW_NARROWER: #ifdef ENABLE_AM_FIX // BK4819_SetFilterBandwidth(Bandwidth, gRxVfo->Modulation == MODULATION_AM && gSetting_AM_fix); BK4819_SetFilterBandwidth(Bandwidth, true); @@ -892,6 +900,13 @@ void RADIO_SetTxParameters(void) { BK4819_FilterBandwidth_t Bandwidth = gCurrentVfo->CHANNEL_BANDWIDTH; + #ifdef ENABLE_FEAT_F4HWN_NARROWER + if(Bandwidth == BK4819_FILTER_BW_NARROW && gSetting_set_nfm == 1) + { + Bandwidth = BK4819_FILTER_BW_NARROWER; + } + #endif + AUDIO_AudioPathOff(); gEnableSpeaker = false; @@ -905,6 +920,7 @@ void RADIO_SetTxParameters(void) [[fallthrough]]; case BK4819_FILTER_BW_WIDE: case BK4819_FILTER_BW_NARROW: + case BK4819_FILTER_BW_NARROWER: #ifdef ENABLE_AM_FIX // BK4819_SetFilterBandwidth(Bandwidth, gCurrentVfo->Modulation == MODULATION_AM && gSetting_AM_fix); BK4819_SetFilterBandwidth(Bandwidth, true); diff --git a/settings.c b/settings.c index c0d6489..5954875 100644 --- a/settings.c +++ b/settings.c @@ -70,7 +70,12 @@ void SETTINGS_InitEEPROM(void) gEeprom.BATTERY_SAVE = (Data[3] < 5) ? Data[3] : 4; gEeprom.DUAL_WATCH = (Data[4] < 3) ? Data[4] : DUAL_WATCH_CHAN_A; gEeprom.BACKLIGHT_TIME = (Data[5] < 62) ? Data[5] : 12; - gEeprom.TAIL_TONE_ELIMINATION = (Data[6] < 2) ? Data[6] : false; + #ifdef ENABLE_FEAT_F4HWN_NARROWER + gEeprom.TAIL_TONE_ELIMINATION = ((Data[6] & 0x01) < 2) ? (Data[6] & 0x01) : false; + gSetting_set_nfm = (((Data[6] >> 1) & 0x03) < 3) ? ((Data[6] >> 1) & 0x03) : 0; + #else + gEeprom.TAIL_TONE_ELIMINATION = (Data[6] < 2) ? Data[6] : false; + #endif #ifdef ENABLE_FEAT_F4HWN_RESTORE_SCAN gEeprom.VFO_OPEN = Data[7] & 0x01; @@ -620,7 +625,11 @@ void SETTINGS_SaveSettings(void) State[5] = gEeprom.BACKLIGHT_TIME; #endif - State[6] = gEeprom.TAIL_TONE_ELIMINATION; + #ifdef ENABLE_FEAT_F4HWN_NARROWER + State[6] = (gEeprom.TAIL_TONE_ELIMINATION & 0x01) | ((gSetting_set_nfm & 0x03) << 1); + #else + State[6] = gEeprom.TAIL_TONE_ELIMINATION; + #endif #ifdef ENABLE_FEAT_F4HWN_RESTORE_SCAN State[7] = (gEeprom.VFO_OPEN & 0x01) | ((gEeprom.CURRENT_STATE & 0x07) << 1) | ((gEeprom.SCAN_LIST_DEFAULT & 0x07) << 4); diff --git a/ui/main.c b/ui/main.c index 321f54a..b9d7c04 100644 --- a/ui/main.c +++ b/ui/main.c @@ -1276,16 +1276,36 @@ void UI_DisplayMain(void) #endif #if ENABLE_FEAT_F4HWN - if (isMainOnly(true)) - { - const char *bandWidthNames[] = {"W", "N"}; - UI_PrintStringSmallNormal(bandWidthNames[vfoInfo->CHANNEL_BANDWIDTH], LCD_WIDTH + 80, 0, line + 1); - } - else - { - const char *bandWidthNames[] = {"WIDE", "NAR"}; - GUI_DisplaySmallest(bandWidthNames[vfoInfo->CHANNEL_BANDWIDTH], 91, line == 0 ? 17 : 49, false, true); - } + #ifdef ENABLE_FEAT_F4HWN_NARROWER + bool narrower = 0; + + if(vfoInfo->CHANNEL_BANDWIDTH == BANDWIDTH_NARROW && gSetting_set_nfm == 1) + { + narrower = 1; + } + + if (isMainOnly(true)) + { + const char *bandWidthNames[] = {"W", "N", "N+"}; + UI_PrintStringSmallNormal(bandWidthNames[vfoInfo->CHANNEL_BANDWIDTH + narrower], LCD_WIDTH + 80, 0, line + 1); + } + else + { + const char *bandWidthNames[] = {"WIDE", "NAR", "NAR+"}; + GUI_DisplaySmallest(bandWidthNames[vfoInfo->CHANNEL_BANDWIDTH + narrower], 91, line == 0 ? 17 : 49, false, true); + } + #else + if (isMainOnly(true)) + { + const char *bandWidthNames[] = {"W", "N"}; + UI_PrintStringSmallNormal(bandWidthNames[vfoInfo->CHANNEL_BANDWIDTH], LCD_WIDTH + 80, 0, line + 1); + } + else + { + const char *bandWidthNames[] = {"WIDE", "NAR"}; + GUI_DisplaySmallest(bandWidthNames[vfoInfo->CHANNEL_BANDWIDTH], 91, line == 0 ? 17 : 49, false, true); + } + #endif #else if (vfoInfo->CHANNEL_BANDWIDTH == BANDWIDTH_NARROW) UI_PrintStringSmallNormal("N", LCD_WIDTH + 70, 0, line + 1); diff --git a/ui/menu.c b/ui/menu.c index 633f20b..46282a7 100644 --- a/ui/menu.c +++ b/ui/menu.c @@ -138,18 +138,21 @@ const t_menu_item MenuList[] = {"Sql", MENU_SQL }, #ifdef ENABLE_FEAT_F4HWN {"SetPwr", MENU_SET_PWR }, - {"SetPtt", MENU_SET_PTT }, - {"SetTot", MENU_SET_TOT }, - {"SetEot", MENU_SET_EOT }, + {"SetPTT", MENU_SET_PTT }, + {"SetTOT", MENU_SET_TOT }, + {"SetEOT", MENU_SET_EOT }, {"SetCtr", MENU_SET_CTR }, {"SetInv", MENU_SET_INV }, {"SetLck", MENU_SET_LCK }, {"SetMet", MENU_SET_MET }, - {"SetGui", MENU_SET_GUI }, + {"SetGUI", MENU_SET_GUI }, {"SetTmr", MENU_SET_TMR }, #ifdef ENABLE_FEAT_F4HWN_SLEEP {"SetOff", MENU_SET_OFF }, #endif + #ifdef ENABLE_FEAT_F4HWN_NARROWER + {"SetNFM", MENU_SET_NFM }, + #endif #endif // hidden menu items from here on // enabled if pressing both the PTT and upper side button at power-on @@ -390,6 +393,14 @@ const char gSubMenu_SCRAMBLER[][7] = "TINY", "CLASSIC" }; + + #ifdef ENABLE_FEAT_F4HWN_NARROWER + const char gSubMenu_SET_NFM[][8] = + { + "12.5kHz", + "6.25kHz" + }; + #endif #endif const t_sidefunction gSubMenu_SIDEFUNCTIONS[] = @@ -1045,6 +1056,11 @@ void UI_DisplayMenu(void) strcpy(String, gSubMenu_SET_MET[gSubMenuSelection]); // Same as SET_MET break; + #ifdef ENABLE_FEAT_F4HWN_NARROWER + case MENU_SET_NFM: + strcpy(String, gSubMenu_SET_NFM[gSubMenuSelection]); + break; + #endif #endif } diff --git a/ui/menu.h b/ui/menu.h index c5192c7..954623e 100644 --- a/ui/menu.h +++ b/ui/menu.h @@ -141,6 +141,9 @@ enum MENU_SET_MET, MENU_SET_GUI, MENU_SET_TMR, + #ifdef ENABLE_FEAT_F4HWN_NARROWER + MENU_SET_NFM, + #endif #endif MENU_BATCAL, // battery voltage calibration MENU_F1SHRT, @@ -179,6 +182,9 @@ extern const char gSubMenu_D_RSP[4][11]; extern const char gSubMenu_SET_TOT[4][7]; extern const char gSubMenu_SET_LCK[2][9]; extern const char gSubMenu_SET_MET[2][8]; + #ifdef ENABLE_FEAT_F4HWN_NARROWER + extern const char gSubMenu_SET_NFM[2][8]; + #endif #endif extern const char* const gSubMenu_PTT_ID[5];