From 2b85e957b11a33012fc9e7904742805278c65805 Mon Sep 17 00:00:00 2001 From: Karel Tucek Date: Thu, 26 Dec 2024 17:42:00 +0100 Subject: [PATCH 1/6] Light entire matrix at the beginning of switch test mode. --- device/src/keyboard/key_scanner.c | 5 +- device/src/state_sync.c | 16 ++++++ device/src/state_sync.h | 1 + right/src/ledmap.c | 52 ++++++------------- right/src/test_switches.c | 27 ++++++++++ right/src/test_switches.h | 1 + .../usb_commands/usb_command_set_variable.c | 7 +-- right/src/usb_report_updater.c | 2 +- 8 files changed, 66 insertions(+), 45 deletions(-) diff --git a/device/src/keyboard/key_scanner.c b/device/src/keyboard/key_scanner.c index d85b30d6c..ea2d75d9b 100644 --- a/device/src/keyboard/key_scanner.c +++ b/device/src/keyboard/key_scanner.c @@ -22,6 +22,7 @@ #include "attributes.h" #include "layouts/key_layout.h" #include "layouts/key_layout_80_to_universal.h" +#include "test_switches.h" // Thread definitions @@ -108,8 +109,6 @@ static void scanKeys() { memset(compressedBuffer, 0, compressedLength); } - backlighting_mode_t currentBacklightingMode = Ledmap_GetEffectiveBacklightMode(); - uint8_t slotId = DEVICE_IS_UHK80_LEFT ? SlotId_LeftKeyboardHalf : SlotId_RightKeyboardHalf; for (uint8_t rowId=0; rowId #include "peripherals/merge_sensor.h" #include "power_mode.h" +#include "test_switches.h" #define WAKE(TID) if (TID != 0) { k_wakeup(TID); } @@ -128,6 +129,7 @@ static state_sync_prop_t stateSyncProps[StateSyncPropertyId_Count] = { SIMPLE(FunctionalColors, SyncDirection_RightToLeft, DirtyState_Clean, &Cfg.KeyActionColors), SIMPLE(PowerMode, SyncDirection_RightToLeft, DirtyState_Clean, &CurrentPowerMode), CUSTOM(Config, SyncDirection_RightToLeft, DirtyState_Clean), + CUSTOM(SwitchTestMode, SyncDirection_RightToLeft, DirtyState_Clean), }; static void invalidateProperty(state_sync_prop_id_t propId) { @@ -347,6 +349,15 @@ static void receiveProperty(device_id_t src, state_sync_prop_id_t propId, const break; case StateSyncPropertyId_MergeSensor: break; + case StateSyncPropertyId_SwitchTestMode: + if (!isLocalUpdate) { + bool newMode = *(bool*)data; + if (newMode != TestSwitches) { + newMode ? TestSwitches_Activate() : TestSwitches_Deactivate(); + Main_Wake(); + } + } + break; default: printk("Property %i ('%s') has no receive handler. If this is correct, please add a " "separate empty case...\n", @@ -488,6 +499,10 @@ static void prepareData(device_id_t dst, const uint8_t *propDataPtr, state_sync_ submitPreparedData(dst, propId, (const uint8_t *)&buffer, sizeof(buffer)); return; } break; + case StateSyncPropertyId_SwitchTestMode: { + submitPreparedData(dst, propId, (const uint8_t *)&TestSwitches, sizeof(TestSwitches)); + return; + } default: break; } @@ -531,6 +546,7 @@ static void updateProperty(state_sync_prop_id_t propId) { static bool handlePropertyUpdateRightToLeft() { UPDATE_AND_RETURN_IF_DIRTY(StateSyncPropertyId_ResetRightLeftLink); UPDATE_AND_RETURN_IF_DIRTY(StateSyncPropertyId_Config); + UPDATE_AND_RETURN_IF_DIRTY(StateSyncPropertyId_SwitchTestMode); if (KeyBacklightBrightness != 0) { // Update relevant data diff --git a/device/src/state_sync.h b/device/src/state_sync.h index a332e5813..10053e954 100644 --- a/device/src/state_sync.h +++ b/device/src/state_sync.h @@ -94,6 +94,7 @@ StateSyncPropertyId_FunctionalColors = 25, StateSyncPropertyId_PowerMode = 26, StateSyncPropertyId_Config = 27, + StateSyncPropertyId_SwitchTestMode = 28, StateSyncPropertyId_Count, } state_sync_prop_id_t; diff --git a/right/src/ledmap.c b/right/src/ledmap.c index deb1eac74..0eacadd59 100644 --- a/right/src/ledmap.c +++ b/right/src/ledmap.c @@ -10,6 +10,7 @@ #include "slot.h" #include "config_manager.h" #include "event_scheduler.h" +#include "test_switches.h" #ifdef __ZEPHYR__ #include "keyboard/leds.h" @@ -29,14 +30,7 @@ static const rgb_t white = RGB(0xff, 0xff, 0xff); bool Ledmap_AlwaysOn = false; backlighting_mode_t TemporaryBacklightingMode = BacklightingMode_Unspecified; -typedef enum { - BacklightingLedTestModeState_All, - BacklightingLedTestModeState_Additive, -} backlighting_led_test_mode_state_t; - -bool Ledmap_LedTestActive = false; static uint32_t backlightingLedTestStart = 0; -static backlighting_led_test_mode_state_t backlightingLedTestModeState = BacklightingLedTestModeState_All; #if DEVICE_ID == DEVICE_ID_UHK60V1 @@ -594,38 +588,26 @@ static void setEntireMatrix(uint8_t v) { #endif } -static void setAllTo(const rgb_t* color) { - for (uint8_t slotId=0; slotId Date: Fri, 27 Dec 2024 23:12:32 +0100 Subject: [PATCH 2/6] Fix exit from test led mode for uhk60. --- right/src/test_switches.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/right/src/test_switches.c b/right/src/test_switches.c index 3239e2dec..6cd6e89d8 100644 --- a/right/src/test_switches.c +++ b/right/src/test_switches.c @@ -140,7 +140,9 @@ void TestSwitches_Deactivate(void) #if DEVICE_IS_UHK80_RIGHT StateSync_UpdateProperty(StateSyncPropertyId_SwitchTestMode, NULL); - EventVector_Set(EventVector_KeymapReloadNeeded); #endif +#if DEVICE_IS_MASTER + EventVector_Set(EventVector_KeymapReloadNeeded); +#endif } From c27a4065f084313d542efb8e90177c44067d30a9 Mon Sep 17 00:00:00 2001 From: Karel Tucek Date: Sat, 28 Dec 2024 01:27:05 +0100 Subject: [PATCH 3/6] Reload uhk60 keymap even in key switch mode if needed. --- right/src/slave_drivers/uhk_module_driver.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/right/src/slave_drivers/uhk_module_driver.c b/right/src/slave_drivers/uhk_module_driver.c index 82ce95ff6..bb07de829 100644 --- a/right/src/slave_drivers/uhk_module_driver.c +++ b/right/src/slave_drivers/uhk_module_driver.c @@ -118,7 +118,7 @@ static void reloadKeymapIfNeeded() EventVector_WakeMain(); } #else - if (!someoneElseWillDoTheJob && !TestSwitches) { + if (!someoneElseWillDoTheJob) { EventVector_Set(EventVector_KeymapReloadNeeded); } From 332557fbbf487b60dc0d5d5ca085211ec00e85d7 Mon Sep 17 00:00:00 2001 From: Karel Tucek Date: Sun, 29 Dec 2024 22:48:37 +0100 Subject: [PATCH 4/6] Require valid messages to be non-empty. --- shared/crc16.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/shared/crc16.c b/shared/crc16.c index d7a088d77..1aaa0cb04 100644 --- a/shared/crc16.c +++ b/shared/crc16.c @@ -51,5 +51,5 @@ bool CRC16_IsMessageValid(i2c_message_t *message) crc16_init(&crc16data); crc16_update(&crc16data, message->data, message->length); crc16_finalize(&crc16data, &hash); - return message->crc == hash; + return message->crc == hash && message->length != 0; } From aca35f4d09ac55bcddddb99dc85ec20d3ace4ba3 Mon Sep 17 00:00:00 2001 From: Karel Tucek Date: Mon, 30 Dec 2024 00:26:25 +0100 Subject: [PATCH 5/6] Auxiliary changes. --- right/src/macros/status_buffer.h | 2 + right/src/slave_drivers/uhk_module_driver.h | 68 ++++++++++----------- shared/slave_protocol.h | 18 +++--- 3 files changed, 45 insertions(+), 43 deletions(-) diff --git a/right/src/macros/status_buffer.h b/right/src/macros/status_buffer.h index 081116404..d7ebf8fdf 100644 --- a/right/src/macros/status_buffer.h +++ b/right/src/macros/status_buffer.h @@ -13,6 +13,8 @@ // Typedefs: + #define PRINTM(...) Macros_ReportPrintf(NULL, __VA_ARGS__) + // Variables: // extern bool Macros_ConsumeStatusCharDirtyFlag; diff --git a/right/src/slave_drivers/uhk_module_driver.h b/right/src/slave_drivers/uhk_module_driver.h index 4ac618ef4..e4c65b627 100644 --- a/right/src/slave_drivers/uhk_module_driver.h +++ b/right/src/slave_drivers/uhk_module_driver.h @@ -31,60 +31,60 @@ typedef enum { // Sync communication - UhkModulePhase_RequestSync, - UhkModulePhase_ReceiveSync, - UhkModulePhase_ProcessSync, + UhkModulePhase_RequestSync = 0, + UhkModulePhase_ReceiveSync = 1, + UhkModulePhase_ProcessSync = 2, // Get protocol version - UhkModulePhase_RequestModuleProtocolVersion, - UhkModulePhase_ReceiveModuleProtocolVersion, - UhkModulePhase_ProcessModuleProtocolVersion, + UhkModulePhase_RequestModuleProtocolVersion = 3, + UhkModulePhase_ReceiveModuleProtocolVersion = 4, + UhkModulePhase_ProcessModuleProtocolVersion = 5, // Get firmware version - UhkModulePhase_RequestFirmwareVersion, - UhkModulePhase_ReceiveFirmwareVersion, - UhkModulePhase_ProcessFirmwareVersion, + UhkModulePhase_RequestFirmwareVersion = 6, + UhkModulePhase_ReceiveFirmwareVersion = 7, + UhkModulePhase_ProcessFirmwareVersion = 8, // Get module id - UhkModulePhase_RequestModuleId, - UhkModulePhase_ReceiveModuleId, - UhkModulePhase_ProcessModuleId, + UhkModulePhase_RequestModuleId = 9, + UhkModulePhase_ReceiveModuleId = 10, + UhkModulePhase_ProcessModuleId = 11, // Get module key count - UhkModulePhase_RequestModuleKeyCount, - UhkModulePhase_ReceiveModuleKeyCount, - UhkModulePhase_ProcessModuleKeyCount, + UhkModulePhase_RequestModuleKeyCount = 12, + UhkModulePhase_ReceiveModuleKeyCount = 13, + UhkModulePhase_ProcessModuleKeyCount = 14, // Get module key count - UhkModulePhase_RequestModulePointerCount, - UhkModulePhase_ReceiveModulePointerCount, - UhkModulePhase_ProcessModulePointerCount, + UhkModulePhase_RequestModulePointerCount = 15, + UhkModulePhase_ReceiveModulePointerCount = 16, + UhkModulePhase_ProcessModulePointerCount = 17, // Get key states - UhkModulePhase_RequestKeyStates, - UhkModulePhase_ReceiveKeystates, - UhkModulePhase_ProcessKeystates, + UhkModulePhase_RequestKeyStates = 18, + UhkModulePhase_ReceiveKeystates = 19, + UhkModulePhase_ProcessKeystates = 20, // Get git tag - UhkModulePhase_RequestGitTag, - UhkModulePhase_ReceiveGitTag, - UhkModulePhase_ProcessGitTag, + UhkModulePhase_RequestGitTag = 21, + UhkModulePhase_ReceiveGitTag = 22, + UhkModulePhase_ProcessGitTag = 23, // Get git repo - UhkModulePhase_RequestGitRepo, - UhkModulePhase_ReceiveGitRepo, - UhkModulePhase_ProcessGitRepo, + UhkModulePhase_RequestGitRepo = 24, + UhkModulePhase_ReceiveGitRepo = 25, + UhkModulePhase_ProcessGitRepo = 26, // Get firmware checksum - UhkModulePhase_RequestFirmwareChecksum, - UhkModulePhase_ReceiveFirmwareChecksum, - UhkModulePhase_ProcessFirmwareChecksum, + UhkModulePhase_RequestFirmwareChecksum = 27, + UhkModulePhase_ReceiveFirmwareChecksum = 28, + UhkModulePhase_ProcessFirmwareChecksum = 29, // Misc phases - UhkModulePhase_SetTestLed, - UhkModulePhase_SetLedPwmBrightness, - UhkModulePhase_JumpToBootloader, - UhkModulePhase_ResetTrackpoint, + UhkModulePhase_SetTestLed = 30, + UhkModulePhase_SetLedPwmBrightness = 31, + UhkModulePhase_JumpToBootloader = 32, + UhkModulePhase_ResetTrackpoint = 33, } uhk_module_phase_t; diff --git a/shared/slave_protocol.h b/shared/slave_protocol.h index 882f506ad..85fc136f5 100644 --- a/shared/slave_protocol.h +++ b/shared/slave_protocol.h @@ -34,15 +34,15 @@ } module_specific_command_t; typedef enum { - SlaveProperty_Sync, - SlaveProperty_ModuleProtocolVersion, - SlaveProperty_FirmwareVersion, - SlaveProperty_ModuleId, - SlaveProperty_KeyCount, - SlaveProperty_PointerCount, - SlaveProperty_GitTag, - SlaveProperty_GitRepo, - SlaveProperty_FirmwareChecksum, + SlaveProperty_Sync = 0, + SlaveProperty_ModuleProtocolVersion = 1, + SlaveProperty_FirmwareVersion = 2, + SlaveProperty_ModuleId = 3, + SlaveProperty_KeyCount = 4, + SlaveProperty_PointerCount = 5, + SlaveProperty_GitTag = 6, + SlaveProperty_GitRepo = 7, + SlaveProperty_FirmwareChecksum = 8, } slave_property_t; typedef enum { From ce69d897929953837b3b6904ce9732d12036ddbe Mon Sep 17 00:00:00 2001 From: Karel Tucek Date: Tue, 31 Dec 2024 00:15:13 +0100 Subject: [PATCH 6/6] Reload ansi/iso flag when hyardware config is written. --- .../usb_commands/usb_command_launch_storage_transfer.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/right/src/usb_commands/usb_command_launch_storage_transfer.c b/right/src/usb_commands/usb_command_launch_storage_transfer.c index 259b1494e..2316313a1 100644 --- a/right/src/usb_commands/usb_command_launch_storage_transfer.c +++ b/right/src/usb_commands/usb_command_launch_storage_transfer.c @@ -1,4 +1,6 @@ #include "usb_commands/usb_command_launch_storage_transfer.h" +#include "event_scheduler.h" +#include "ledmap.h" #include "usb_protocol_handler.h" #include "config_parser/config_globals.h" @@ -39,6 +41,12 @@ void UsbCommand_LaunchStorageTransfer(const uint8_t *GenericHidOutBuffer, uint8_ status_t status = EEPROM_LaunchTransfer(storageOperation, configBufferId, NULL); #endif + if (configBufferId == ConfigBufferId_HardwareConfig) { + // reload is/ansi led settings + Ledmap_InitLedLayout(); + EventVector_Set(EventVector_LedMapUpdateNeeded); + } + if (status != kStatus_Success) { SetUsbTxBufferUint8(0, UsbStatusCode_LaunchStorageTransferTransferError); SetUsbTxBufferUint32(1, status);