diff --git a/right/src/keymap.c b/right/src/keymap.c index e237f47..c0a8092 100644 --- a/right/src/keymap.c +++ b/right/src/keymap.c @@ -6,7 +6,14 @@ #include "config_parser/config_globals.h" #include "macros.h" -keymap_reference_t AllKeymaps[MAX_KEYMAP_NUM] = { { "FTY", 0, 3 } }; +keymap_reference_t AllKeymaps[MAX_KEYMAP_NUM] = { + { + .abbreviation = "FTY", + .offset = 0, + .abbreviationLen = 3 + } +}; + uint8_t AllKeymapsCount; uint8_t DefaultKeymapIndex; uint8_t CurrentKeymapIndex = 0; @@ -19,6 +26,17 @@ void SwitchKeymap(uint8_t index) LedDisplay_SetCurrentKeymapText(); } +bool SwitchKeymapByAbbreviation(uint8_t length, char *abbrev) +{ + for (uint8_t i=0; iabbreviationLen == length && strcmp(keymap->abbreviation, abbrev) == 0) { + return true; + } + } + return false; +} + // The factory keymap is initialized before it gets overwritten by the default keymap of the EEPROM. key_action_t CurrentKeymap[LAYER_COUNT][SLOT_COUNT][MAX_KEY_COUNT_PER_MODULE] = { // Base layer diff --git a/right/src/keymap.h b/right/src/keymap.h index 1f03772..3a737d2 100644 --- a/right/src/keymap.h +++ b/right/src/keymap.h @@ -30,5 +30,6 @@ // Functions: void SwitchKeymap(uint8_t index); + bool SwitchKeymapByAbbreviation(uint8_t length, char *abbrev); #endif diff --git a/right/src/usb_commands/usb_command_switch_keymap.c b/right/src/usb_commands/usb_command_switch_keymap.c new file mode 100644 index 0000000..f8e8475 --- /dev/null +++ b/right/src/usb_commands/usb_command_switch_keymap.c @@ -0,0 +1,17 @@ +#include "usb_protocol_handler.h" +#include "usb_commands/usb_command_switch_keymap.h" +#include "keymap.h" + +void UsbCommand_SwitchKeymap(void) +{ + uint32_t keymapLength = GetUsbRxBufferUint8(1); + char *keymapAbbrev = (char*)GenericHidInBuffer + 2; + + if (keymapLength > KEYMAP_ABBREVIATION_LENGTH) { + SetUsbTxBufferUint8(0, UsbStatusCode_SwitchKeymap_InvalidAbbreviationLength); + } + + if (!SwitchKeymapByAbbreviation(keymapLength, keymapAbbrev)) { + SetUsbTxBufferUint8(0, UsbStatusCode_SwitchKeymap_InvalidAbbreviation); + } +} diff --git a/right/src/usb_commands/usb_command_switch_keymap.h b/right/src/usb_commands/usb_command_switch_keymap.h new file mode 100644 index 0000000..be22c77 --- /dev/null +++ b/right/src/usb_commands/usb_command_switch_keymap.h @@ -0,0 +1,15 @@ +#ifndef __USB_COMMAND_SWITCH_KEYMAP_H__ +#define __USB_COMMAND_SWITCH_KEYMAP_H__ + +// Functions: + + void UsbCommand_SwitchKeymap(void); + +// Typedefs: + + typedef enum { + UsbStatusCode_SwitchKeymap_InvalidAbbreviationLength = 2, + UsbStatusCode_SwitchKeymap_InvalidAbbreviation = 3, + } usb_status_code_switch_keymap_t; + +#endif diff --git a/right/src/usb_protocol_handler.c b/right/src/usb_protocol_handler.c index b933aa2..20b23ed 100644 --- a/right/src/usb_protocol_handler.c +++ b/right/src/usb_protocol_handler.c @@ -16,6 +16,7 @@ #include "usb_commands/usb_command_send_kboot_command_to_module.h" #include "usb_commands/usb_command_get_slave_i2c_errors.h" #include "usb_commands/usb_command_set_i2c_baud_rate.h" +#include "usb_commands/usb_command_switch_keymap.h" void UsbProtocolHandler(void) { @@ -73,6 +74,9 @@ void UsbProtocolHandler(void) case UsbCommandId_SetI2cBaudRate: UsbCommand_SetI2cBaudRate(); break; + case UsbCommandId_SwitchKeymap: + UsbCommand_SwitchKeymap(); + break; default: SetUsbTxBufferUint8(0, UsbStatusCode_InvalidCommand); break; diff --git a/right/src/usb_protocol_handler.h b/right/src/usb_protocol_handler.h index 5ef3b99..7f48f29 100644 --- a/right/src/usb_protocol_handler.h +++ b/right/src/usb_protocol_handler.h @@ -33,6 +33,7 @@ UsbCommandId_GetModuleProperty = 0x0e, UsbCommandId_GetSlaveI2cErrors = 0x0f, UsbCommandId_SetI2cBaudRate = 0x10, + UsbCommandId_SwitchKeymap = 0x11, } usb_command_id_t; typedef enum {