diff --git a/right/src/config/config_state.h b/right/src/config/config_state.h index 84065d0..931f391 100644 --- a/right/src/config/config_state.h +++ b/right/src/config/config_state.h @@ -3,6 +3,7 @@ // Includes: + #include #include "fsl_common.h" // Macros: @@ -16,16 +17,6 @@ uint16_t offset; } serialized_buffer_t; - typedef enum { - ParserError_Success, - ParserError_InvalidSerializedKeystrokeType, - ParserError_InvalidSerializedMouseAction, - ParserError_InvalidSerializedKeyActionType, - ParserError_InvalidLayerCount, - ParserError_InvalidModuleCount, - ParserError_InvalidActionCount, - } parser_error_t; - // Variables: extern serialized_buffer_t ConfigBuffer; diff --git a/right/src/config/parse_config.c b/right/src/config/parse_config.c new file mode 100644 index 0000000..cde0ecc --- /dev/null +++ b/right/src/config/parse_config.c @@ -0,0 +1,46 @@ +#include "parse_config.h" +#include "parse_keymap.h" + +static parser_error_t parseModuleConfiguration(serialized_buffer_t *buffer) { + uint8_t id = readUInt8(buffer); + uint8_t initialPointerSpeed = readUInt8(buffer); + uint8_t pointerAcceleration = readUInt8(buffer); + uint8_t maxPointerSpeed = readUInt8(buffer); + + (void)id; + (void)initialPointerSpeed; + (void)pointerAcceleration; + (void)maxPointerSpeed; + return ParserError_Success; +} + +parser_error_t ParseConfig(serialized_buffer_t *buffer) { + uint16_t dataModelVersion = readUInt16(buffer); + parser_error_t errorCode; + uint16_t moduleConfigurationCount = readCompactLength(buffer); + uint16_t macroCount; + uint16_t keymapCount; + + (void)dataModelVersion; + for (uint8_t moduleConfigurationIdx = 0; moduleConfigurationIdx < moduleConfigurationCount; moduleConfigurationIdx++) { + errorCode = parseModuleConfiguration(buffer); + if (errorCode != ParserError_Success) { + return errorCode; + } + } + macroCount = readCompactLength(buffer); + for (uint8_t macroIdx = 0; macroIdx < macroCount; macroIdx++) { + // errorCode = ParseMacro(buffer); + // if (errorCode != ParserError_Success) { + // return errorCode; + // } + } + keymapCount = readCompactLength(buffer); + for (uint8_t keymapIdx = 0; keymapIdx < keymapCount; keymapIdx++) { + errorCode = ParseKeymap(buffer); + if (errorCode != ParserError_Success) { + return errorCode; + } + } + return ParserError_Success; +} diff --git a/right/src/config/parse_config.h b/right/src/config/parse_config.h new file mode 100644 index 0000000..494d721 --- /dev/null +++ b/right/src/config/parse_config.h @@ -0,0 +1,24 @@ +#ifndef __PARSE_CONFIG_H__ +#define __PARSE_CONFIG_H__ + +// Includes: + + #include "config_state.h" + +// Typedefs: + + typedef enum { + ParserError_Success, + ParserError_InvalidSerializedKeystrokeType, + ParserError_InvalidSerializedMouseAction, + ParserError_InvalidSerializedKeyActionType, + ParserError_InvalidLayerCount, + ParserError_InvalidModuleCount, + ParserError_InvalidActionCount, + } parser_error_t; + +// Functions: + + parser_error_t ParseConfig(serialized_buffer_t *buffer); + +#endif diff --git a/right/src/config/parse_keymap.h b/right/src/config/parse_keymap.h index 63f6252..8e2bd1e 100644 --- a/right/src/config/parse_keymap.h +++ b/right/src/config/parse_keymap.h @@ -5,7 +5,7 @@ #include #include - #include "config_state.h" + #include "parse_config.h" // Macros: diff --git a/right/src/usb_protocol_handler.c b/right/src/usb_protocol_handler.c index a021999..68b8cea 100644 --- a/right/src/usb_protocol_handler.c +++ b/right/src/usb_protocol_handler.c @@ -4,7 +4,7 @@ #include "i2c_addresses.h" #include "led_driver.h" #include "peripherals/merge_sensor.h" -#include "config/parse_keymap.h" +#include "config/parse_config.h" #include "config/config_state.h" #include "led_pwm.h" #include "slave_scheduler.h" @@ -194,7 +194,7 @@ void uploadConfig() void applyConfig() { ConfigBuffer.offset = 0; - GenericHidOutBuffer[0] = ParseKeymap(&ConfigBuffer); + GenericHidOutBuffer[0] = ParseConfig(&ConfigBuffer); GenericHidOutBuffer[1] = ConfigBuffer.offset; GenericHidOutBuffer[2] = ConfigBuffer.offset >> 8; }