From e35eac68350d9ae26983cf7325343159d174c364 Mon Sep 17 00:00:00 2001 From: Armel FAUVEAU Date: Fri, 24 Jan 2025 03:54:26 +0100 Subject: [PATCH] Add Mute action --- app/action.c | 20 ++++++++++++++++++++ app/action.h | 1 + bitmaps.c | 16 ++++++++++++++++ bitmaps.h | 1 + driver/bk1080.c | 6 +++++- misc.c | 1 + misc.h | 1 + settings.c | 4 ++++ settings.h | 4 ++++ ui/menu.c | 1 + ui/status.c | 43 ++++++++++++++++++++++++++++++------------- 11 files changed, 84 insertions(+), 14 deletions(-) diff --git a/app/action.c b/app/action.c index 08a3540..fdf32c5 100644 --- a/app/action.c +++ b/app/action.c @@ -111,6 +111,7 @@ void (*action_opt_table[])(void) = { [ACTION_OPT_PTT] = &ACTION_Ptt, [ACTION_OPT_WN] = &ACTION_Wn, [ACTION_OPT_BACKLIGHT] = &ACTION_BackLight, + [ACTION_OPT_MUTE] = &ACTION_Mute, #ifdef ENABLE_FEAT_F4HWN_RESCUE_OPS [ACTION_OPT_POWER_HIGH] = &ACTION_Power_High, [ACTION_OPT_REMOVE_OFFSET] = &ACTION_Remove_Offset, @@ -625,6 +626,25 @@ void ACTION_BackLightOnDemand(void) BACKLIGHT_TurnOn(); } +void ACTION_Mute(void) +{ + // Toggle mute state + gMute = !gMute; + + // Update the registers + #ifdef ENABLE_FMRADIO + BK1080_WriteRegister(BK1080_REG_05_SYSTEM_CONFIGURATION2, gMute ? 0x0A10 : 0x0A1F); + #endif + gEeprom.VOLUME_GAIN = gMute ? 0 : gEeprom.VOLUME_GAIN_BACKUP; + BK4819_WriteRegister(BK4819_REG_48, + (11u << 12) | // ??? .. 0 ~ 15, doesn't seem to make any difference + (0u << 10) | // AF Rx Gain-1 + (gEeprom.VOLUME_GAIN << 4) | // AF Rx Gain-2 + (gEeprom.DAC_GAIN << 0)); // AF DAC Gain (after Gain-1 and Gain-2) + + gUpdateStatus = true; +} + #ifdef ENABLE_FEAT_F4HWN_RESCUE_OPS void ACTION_Power_High(void) { diff --git a/app/action.h b/app/action.h index 735c1c3..d4dad6f 100644 --- a/app/action.h +++ b/app/action.h @@ -42,6 +42,7 @@ void ACTION_SwitchDemodul(void); void ACTION_Wn(void); void ACTION_BackLightOnDemand(void); void ACTION_BackLight(void); + void ACTION_Mute(void); #ifdef ENABLE_FEAT_F4HWN_RESCUE_OPS void ACTION_Power_High(void); void ACTION_Remove_Offset(void); diff --git a/bitmaps.c b/bitmaps.c index 305ab8f..9ae0aa1 100644 --- a/bitmaps.c +++ b/bitmaps.c @@ -57,6 +57,22 @@ const uint8_t gFontLight[9] = 0b00001100, }; +const uint8_t gFontSound[12] = +{ + 0b00011100, + 0b00011100, + 0b00010100, + 0b00100010, + 0b01000001, + 0b01111111, + 0b00000000, + 0b00100010, + 0b00010100, + 0b00001000, + 0b00010100, + 0b00100010, +}; + const uint8_t gFontXB[2][6] = { // "XB" {0x00, 0x63, 0x14, 0x8, 0x14, 0x63}, diff --git a/bitmaps.h b/bitmaps.h index 040b997..565dd35 100644 --- a/bitmaps.h +++ b/bitmaps.h @@ -12,6 +12,7 @@ extern const uint8_t gFontS[6]; extern const uint8_t gFontKeyLock[9]; extern const uint8_t gFontLight[9]; +extern const uint8_t gFontSound[12]; extern const uint8_t gFontXB[2][6]; extern const uint8_t gFontMO[2][6]; diff --git a/driver/bk1080.c b/driver/bk1080.c index 3c8e921..151bea6 100644 --- a/driver/bk1080.c +++ b/driver/bk1080.c @@ -68,7 +68,11 @@ void BK1080_Init(uint16_t freq, uint8_t band/*, uint8_t space*/) BK1080_WriteRegister(BK1080_REG_02_POWER_CONFIGURATION, 0x0201); } - BK1080_WriteRegister(BK1080_REG_05_SYSTEM_CONFIGURATION2, 0x0A1F); + #ifdef ENABLE_FEAT_F4HWN + BK1080_WriteRegister(BK1080_REG_05_SYSTEM_CONFIGURATION2, gMute ? 0x0A10 : 0x0A1F); + #else + BK1080_WriteRegister(BK1080_REG_05_SYSTEM_CONFIGURATION2, 0x0A1F); + #endif BK1080_SetFrequency(freq, band/*, space*/); } else { diff --git a/misc.c b/misc.c index 3fa47e0..5cd0809 100644 --- a/misc.c +++ b/misc.c @@ -308,6 +308,7 @@ uint8_t gIsLocked = 0xFF; #ifdef ENABLE_FEAT_F4HWN bool gK5startup = true; bool gBackLight = false; + bool gMute = false; uint8_t gBacklightTimeOriginal; uint8_t gBacklightBrightnessOld; uint8_t gPttOnePushCounter = 0; diff --git a/misc.h b/misc.h index b6c1811..5654740 100644 --- a/misc.h +++ b/misc.h @@ -377,6 +377,7 @@ extern volatile uint8_t boot_counter_10ms; #ifdef ENABLE_FEAT_F4HWN extern bool gK5startup; extern bool gBackLight; + extern bool gMute; extern uint8_t gBacklightTimeOriginal; extern uint8_t gBacklightBrightnessOld; extern uint8_t gPttOnePushCounter; diff --git a/settings.c b/settings.c index efd78af..f036076 100644 --- a/settings.c +++ b/settings.c @@ -434,6 +434,10 @@ void SETTINGS_LoadCalibration(void) gEeprom.VOLUME_GAIN = (Misc.VOLUME_GAIN < 64) ? Misc.VOLUME_GAIN : 58; gEeprom.DAC_GAIN = (Misc.DAC_GAIN < 16) ? Misc.DAC_GAIN : 8; + #ifdef ENABLE_FEAT_F4HWN + gEeprom.VOLUME_GAIN_BACKUP = gEeprom.VOLUME_GAIN; + #endif + BK4819_WriteRegister(BK4819_REG_3B, 22656 + gEeprom.BK4819_XTAL_FREQ_LOW); // BK4819_WriteRegister(BK4819_REG_3C, gEeprom.BK4819_XTAL_FREQ_HIGH); } diff --git a/settings.h b/settings.h index 8947379..b0f3d88 100644 --- a/settings.h +++ b/settings.h @@ -117,6 +117,7 @@ enum ACTION_OPT_t { ACTION_OPT_PTT, ACTION_OPT_WN, ACTION_OPT_BACKLIGHT, + ACTION_OPT_MUTE, #ifdef ENABLE_FEAT_F4HWN_RESCUE_OPS ACTION_OPT_POWER_HIGH, ACTION_OPT_REMOVE_OFFSET, @@ -272,6 +273,9 @@ typedef struct { bool NOAA_AUTO_SCAN; #endif uint8_t VOLUME_GAIN; + #ifdef ENABLE_FEAT_F4HWN + uint8_t VOLUME_GAIN_BACKUP; + #endif uint8_t DAC_GAIN; VFO_Info_t VfoInfo[2]; diff --git a/ui/menu.c b/ui/menu.c index bc5d80f..730a799 100644 --- a/ui/menu.c +++ b/ui/menu.c @@ -451,6 +451,7 @@ const t_sidefunction gSubMenu_SIDEFUNCTIONS[] = {"MAIN ONLY", ACTION_OPT_MAINONLY}, {"PTT", ACTION_OPT_PTT}, {"WIDE\nNARROW", ACTION_OPT_WN}, + {"MUTE", ACTION_OPT_MUTE}, #ifdef ENABLE_FEAT_F4HWN_RESCUE_OPS {"POWER\nHIGH", ACTION_OPT_POWER_HIGH}, {"REMOVE\nOFFSET", ACTION_OPT_REMOVE_OFFSET}, diff --git a/ui/status.c b/ui/status.c index 6ba6747..7f05e65 100644 --- a/ui/status.c +++ b/ui/status.c @@ -212,30 +212,47 @@ void UI_DisplayStatus() x = MAX(x1, 69u); - // KEY-LOCK indicator + const void *src = NULL; // Pointer to the font/bitmap to copy + size_t size = 0; // Size of the font/bitmap + + // Determine the source and size based on conditions if (gEeprom.KEY_LOCK) { - memcpy(line + x + 1, gFontKeyLock, sizeof(gFontKeyLock)); + src = gFontKeyLock; + size = sizeof(gFontKeyLock); } else if (gWasFKeyPressed) { #ifdef ENABLE_FEAT_F4HWN_RESCUE_OPS - if(gEeprom.MENU_LOCK == false) { - memcpy(line + x + 1, gFontF, sizeof(gFontF)); - } + if (!gEeprom.MENU_LOCK) { + src = gFontF; + size = sizeof(gFontF); + } #else - memcpy(line + x + 1, gFontF, sizeof(gFontF)); + src = gFontF; + size = sizeof(gFontF); #endif } - else if (gBackLight) - { - memcpy(line + x + 1, gFontLight, sizeof(gFontLight)); + #ifdef ENABLE_FEAT_F4HWN + else if (gMute) { + src = gFontSound; + size = sizeof(gFontSound); + } + #endif + else if (gBackLight) { + src = gFontLight; + size = sizeof(gFontLight); } #ifdef ENABLE_FEAT_F4HWN_CHARGING_C - else if (gChargingWithTypeC) - { - memcpy(line + x + 1, BITMAP_USB_C, sizeof(BITMAP_USB_C)); + else if (gChargingWithTypeC) { + src = BITMAP_USB_C; + size = sizeof(BITMAP_USB_C); } #endif - + + // Perform the memcpy if a source was selected + if (src) { + memcpy(line + x + 1, src, size); + } + // Battery unsigned int x2 = LCD_WIDTH - sizeof(BITMAP_BatteryLevel1) - 0;