From d5e7ac40b3ba08efbe365dbf54a9372e277d13f8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karel=20Tu=C4=8Dek?= Date: Mon, 2 Dec 2024 22:17:39 +0100 Subject: [PATCH 1/5] Light all leds when flash is empty. --- right/src/config_parser/parse_config.c | 5 +++++ right/src/config_parser/parse_config.h | 1 + right/src/led_manager.c | 6 ++++-- right/src/led_manager.h | 2 ++ right/src/usb_commands/usb_command_apply_config.c | 13 +++++++++++++ shared/versioning.h | 3 +++ 6 files changed, 28 insertions(+), 2 deletions(-) diff --git a/right/src/config_parser/parse_config.c b/right/src/config_parser/parse_config.c index 6fa61df7..d4c4bd5e 100644 --- a/right/src/config_parser/parse_config.c +++ b/right/src/config_parser/parse_config.c @@ -29,6 +29,8 @@ version_t DataModelVersion = {0, 0, 0}; +bool ConfigParser_ConfigVersionIsEmpty = false; + bool PerKeyRgbPresent = false; void readRgbColor(config_buffer_t *buffer, rgb_t* keyActionColors, key_action_color_t keyActionColor) @@ -53,6 +55,8 @@ parser_error_t parseConfig(config_buffer_t *buffer) DataModelVersion.minor = ReadUInt16(buffer); DataModelVersion.patch = ReadUInt16(buffer); + ConfigParser_ConfigVersionIsEmpty = VERSION_EQUAL(DataModelVersion, 0, 0, 0) || VERSION_EQUAL(DataModelVersion, 0xFFFF, 0xFFFF, 0xFFFF); + #ifdef __ZEPHYR__ if (!ParserRunDry) { printk("Flashed User Config version: %u.%u.%u\n", DataModelVersion.major, DataModelVersion.minor, DataModelVersion.patch); @@ -327,6 +331,7 @@ parser_error_t parseConfig(config_buffer_t *buffer) Cfg.KeyBacklightFadeOutTimeout = keyBacklightFadeOutTimeout; Cfg.KeyBacklightFadeOutBatteryTimeout = keyBacklightFadeOutBatteryTimeout; + AlwaysOnMode = false; LedManager_RecalculateLedBrightness(); LedManager_UpdateSleepModes(); BtPair_ClearUnknownBonds(); diff --git a/right/src/config_parser/parse_config.h b/right/src/config_parser/parse_config.h index db546787..50ca40d1 100644 --- a/right/src/config_parser/parse_config.h +++ b/right/src/config_parser/parse_config.h @@ -47,6 +47,7 @@ extern version_t DataModelVersion; extern bool PerKeyRgbPresent; + extern bool ConfigParser_ConfigVersionIsEmpty; // Functions: diff --git a/right/src/led_manager.c b/right/src/led_manager.c index b1b284ea..cfd5016c 100644 --- a/right/src/led_manager.c +++ b/right/src/led_manager.c @@ -23,18 +23,20 @@ bool DisplaySleepModeActive = false; uint8_t DisplayBrightness = 0xff; uint8_t KeyBacklightBrightness = 0xff; +bool AlwaysOnMode = false; + static void recalculateLedBrightness() { bool globalSleepMode = !Cfg.LedsEnabled || CurrentPowerMode > PowerMode_Awake || Cfg.LedBrightnessMultiplier == 0.0f; - if (globalSleepMode || KeyBacklightSleepModeActive) { + if (!AlwaysOnMode && (globalSleepMode || KeyBacklightSleepModeActive)) { KeyBacklightBrightness = 0; } else { uint8_t keyBacklightBrightnessBase = RunningOnBattery ? Cfg.KeyBacklightBrightnessBatteryDefault : Cfg.KeyBacklightBrightnessDefault; KeyBacklightBrightness = MIN(255, keyBacklightBrightnessBase * Cfg.LedBrightnessMultiplier); } - if (globalSleepMode || DisplaySleepModeActive) { + if (!AlwaysOnMode && (globalSleepMode || DisplaySleepModeActive)) { DisplayBrightness = 0; } else { uint8_t displayBrightnessBase = RunningOnBattery ? Cfg.DisplayBrightnessBatteryDefault : Cfg.DisplayBrightnessDefault; diff --git a/right/src/led_manager.h b/right/src/led_manager.h index b8bdf01e..eb626e96 100644 --- a/right/src/led_manager.h +++ b/right/src/led_manager.h @@ -16,6 +16,8 @@ extern bool KeyBacklightSleepModeActive; extern bool DisplaySleepModeActive; + extern bool AlwaysOnMode; + // Functions: void LedManager_FullUpdate(); diff --git a/right/src/usb_commands/usb_command_apply_config.c b/right/src/usb_commands/usb_command_apply_config.c index eb78e105..598c26eb 100644 --- a/right/src/usb_commands/usb_command_apply_config.c +++ b/right/src/usb_commands/usb_command_apply_config.c @@ -45,6 +45,12 @@ void UsbCommand_ApplyConfigAsync(void) { } } +static bool flashEmpty() { + bool hwConfigEmpty = HardwareConfig->majorVersion == 0 || HardwareConfig->majorVersion == 255; + bool swConfigEmpty = ConfigParser_ConfigVersionIsEmpty; + return swConfigEmpty && hwConfigEmpty; +} + void UsbCommand_ApplyFactory(void) { EventVector_Unset(EventVector_ApplyConfig); @@ -55,6 +61,13 @@ void UsbCommand_ApplyFactory(void) ConfigManager_ResetConfiguration(false); + if (flashEmpty()) { + Cfg.LedMap_ConstantRGB = (rgb_t){ 255, 255, 255 }; + Ledmap_SetLedBacklightingMode(BacklightingMode_ConstantRGB); + AlwaysOnMode = true; + EventVector_Set(EventVector_LedMapUpdateNeeded); + } + #ifdef __ZEPHYR__ StateSync_ResetConfig(); StateSync_ResetRightLeftLink(true); diff --git a/shared/versioning.h b/shared/versioning.h index 26338af7..1431ce54 100644 --- a/shared/versioning.h +++ b/shared/versioning.h @@ -18,6 +18,9 @@ (((v).major > (MAJ)) || ((v).major == (MAJ) && (v).minor > (MIN)) || \ ((v).major == (MAJ) && (v).minor == (MIN) && (v).patch >= (PATCH))) +#define VERSION_EQUAL(v, MAJ, MIN, PATCH) \ + ((v).major == (MAJ) && (v).minor == (MIN) && (v).patch == (PATCH)) + // Typedefs: typedef struct { From 6bef3c42d29c738685e52a7a9b83f1ec1950536e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karel=20Tu=C4=8Dek?= Date: Tue, 3 Dec 2024 12:06:46 +0100 Subject: [PATCH 2/5] Handle left side empty flash scenario independently of right. --- device/src/main.c | 5 ++++- right/src/config_parser/parse_config.c | 2 +- right/src/usb_commands/usb_command_apply_config.c | 2 ++ 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/device/src/main.c b/device/src/main.c index 5a35ca83..7319f554 100644 --- a/device/src/main.c +++ b/device/src/main.c @@ -126,7 +126,6 @@ int main(void) { } if (DEVICE_IS_UHK80_LEFT || DEVICE_IS_UHK80_RIGHT) { - ConfigManager_ResetConfiguration(false); Ledmap_InitLedLayout(); } @@ -148,6 +147,10 @@ int main(void) { Macros_Initialize(); } + if (DEVICE_IS_UHK80_LEFT) { + UsbCommand_ApplyFactory(); + } + USB_EnableHid(); // has to be after USB_SetSerialNumber bt_enable(NULL); diff --git a/right/src/config_parser/parse_config.c b/right/src/config_parser/parse_config.c index d4c4bd5e..8e1215af 100644 --- a/right/src/config_parser/parse_config.c +++ b/right/src/config_parser/parse_config.c @@ -29,7 +29,7 @@ version_t DataModelVersion = {0, 0, 0}; -bool ConfigParser_ConfigVersionIsEmpty = false; +bool ConfigParser_ConfigVersionIsEmpty = true; bool PerKeyRgbPresent = false; diff --git a/right/src/usb_commands/usb_command_apply_config.c b/right/src/usb_commands/usb_command_apply_config.c index 598c26eb..7112d982 100644 --- a/right/src/usb_commands/usb_command_apply_config.c +++ b/right/src/usb_commands/usb_command_apply_config.c @@ -65,6 +65,8 @@ void UsbCommand_ApplyFactory(void) Cfg.LedMap_ConstantRGB = (rgb_t){ 255, 255, 255 }; Ledmap_SetLedBacklightingMode(BacklightingMode_ConstantRGB); AlwaysOnMode = true; + Cfg.KeyBacklightBrightnessDefault = 255; + Cfg.KeyBacklightBrightnessBatteryDefault = 255; EventVector_Set(EventVector_LedMapUpdateNeeded); } From 2a9131903cc753922d40c30610a7878a8ab3b78d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karel=20Tu=C4=8Dek?= Date: Wed, 4 Dec 2024 18:32:26 +0100 Subject: [PATCH 3/5] Light up leds even if only hw config is empty. --- .../usb_commands/usb_command_apply_config.c | 28 +++++++++++-------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/right/src/usb_commands/usb_command_apply_config.c b/right/src/usb_commands/usb_command_apply_config.c index 7112d982..cbe533f6 100644 --- a/right/src/usb_commands/usb_command_apply_config.c +++ b/right/src/usb_commands/usb_command_apply_config.c @@ -45,10 +45,17 @@ void UsbCommand_ApplyConfigAsync(void) { } } -static bool flashEmpty() { - bool hwConfigEmpty = HardwareConfig->majorVersion == 0 || HardwareConfig->majorVersion == 255; - bool swConfigEmpty = ConfigParser_ConfigVersionIsEmpty; - return swConfigEmpty && hwConfigEmpty; +static void setLedsWhite() { + Cfg.LedMap_ConstantRGB = (rgb_t){ 255, 255, 255 }; + Ledmap_SetLedBacklightingMode(BacklightingMode_ConstantRGB); + AlwaysOnMode = true; + Cfg.KeyBacklightBrightnessDefault = 255; + Cfg.KeyBacklightBrightnessBatteryDefault = 255; + EventVector_Set(EventVector_LedMapUpdateNeeded); +} + +static bool hwConfigEmpty() { + return HardwareConfig->majorVersion == 0 || HardwareConfig->majorVersion == 255; } void UsbCommand_ApplyFactory(void) @@ -61,13 +68,8 @@ void UsbCommand_ApplyFactory(void) ConfigManager_ResetConfiguration(false); - if (flashEmpty()) { - Cfg.LedMap_ConstantRGB = (rgb_t){ 255, 255, 255 }; - Ledmap_SetLedBacklightingMode(BacklightingMode_ConstantRGB); - AlwaysOnMode = true; - Cfg.KeyBacklightBrightnessDefault = 255; - Cfg.KeyBacklightBrightnessBatteryDefault = 255; - EventVector_Set(EventVector_LedMapUpdateNeeded); + if (hwConfigEmpty()) { + setLedsWhite(); } #ifdef __ZEPHYR__ @@ -122,6 +124,10 @@ uint8_t UsbCommand_ApplyConfig(void) MacroEvent_OnInit(); + if (hwConfigEmpty()) { + setLedsWhite(); + } + #ifdef __ZEPHYR__ StateSync_ResetConfig(); #endif From 015d905f2597c22a364d786c6cde53fd62e24860 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karel=20Tu=C4=8Dek?= Date: Wed, 4 Dec 2024 18:41:59 +0100 Subject: [PATCH 4/5] Clean unused variable. --- right/src/config_parser/parse_config.c | 4 ---- right/src/config_parser/parse_config.h | 1 - 2 files changed, 5 deletions(-) diff --git a/right/src/config_parser/parse_config.c b/right/src/config_parser/parse_config.c index 8e1215af..692fa768 100644 --- a/right/src/config_parser/parse_config.c +++ b/right/src/config_parser/parse_config.c @@ -29,8 +29,6 @@ version_t DataModelVersion = {0, 0, 0}; -bool ConfigParser_ConfigVersionIsEmpty = true; - bool PerKeyRgbPresent = false; void readRgbColor(config_buffer_t *buffer, rgb_t* keyActionColors, key_action_color_t keyActionColor) @@ -55,8 +53,6 @@ parser_error_t parseConfig(config_buffer_t *buffer) DataModelVersion.minor = ReadUInt16(buffer); DataModelVersion.patch = ReadUInt16(buffer); - ConfigParser_ConfigVersionIsEmpty = VERSION_EQUAL(DataModelVersion, 0, 0, 0) || VERSION_EQUAL(DataModelVersion, 0xFFFF, 0xFFFF, 0xFFFF); - #ifdef __ZEPHYR__ if (!ParserRunDry) { printk("Flashed User Config version: %u.%u.%u\n", DataModelVersion.major, DataModelVersion.minor, DataModelVersion.patch); diff --git a/right/src/config_parser/parse_config.h b/right/src/config_parser/parse_config.h index 50ca40d1..db546787 100644 --- a/right/src/config_parser/parse_config.h +++ b/right/src/config_parser/parse_config.h @@ -47,7 +47,6 @@ extern version_t DataModelVersion; extern bool PerKeyRgbPresent; - extern bool ConfigParser_ConfigVersionIsEmpty; // Functions: From c77218b842a0124977c80687c674d833e9381848 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karel=20Tu=C4=8Dek?= Date: Thu, 5 Dec 2024 00:46:41 +0100 Subject: [PATCH 5/5] Add light all leds that lights all led slots. --- right/src/ledmap.c | 19 +++++++++++++++++++ right/src/ledmap.h | 1 + .../usb_commands/usb_command_apply_config.c | 5 +++-- 3 files changed, 23 insertions(+), 2 deletions(-) diff --git a/right/src/ledmap.c b/right/src/ledmap.c index 2898435e..451a3610 100644 --- a/right/src/ledmap.c +++ b/right/src/ledmap.c @@ -591,6 +591,22 @@ static void updateLedsByLedTestStragegy() { } } +static void updateLedsByLightAllStragegy() { +#ifdef __ZEPHYR__ +#if DEVICE_IS_UHK80_LEFT || DEVICE_IS_UHK80_RIGHT + for (uint8_t i = 0; i < UHK80_LED_DRIVER_LED_COUNT_MAX; i++) { + Uhk80LedDriverValues[i] = 255; + } +#endif +#else + for (uint8_t slotId=0; slotId +#include "ledmap.h" #include "usb_commands/usb_command_apply_config.h" #include "config_parser/config_globals.h" #include "config_parser/parse_config.h" @@ -46,8 +47,8 @@ void UsbCommand_ApplyConfigAsync(void) { } static void setLedsWhite() { - Cfg.LedMap_ConstantRGB = (rgb_t){ 255, 255, 255 }; - Ledmap_SetLedBacklightingMode(BacklightingMode_ConstantRGB); + // Set the led test backlight mode, but don't activate the switch test mode. + Ledmap_SetLedBacklightingMode(BacklightingMode_LightAll); AlwaysOnMode = true; Cfg.KeyBacklightBrightnessDefault = 255; Cfg.KeyBacklightBrightnessBatteryDefault = 255;