Add the parser for the top-level configuration

This commit is contained in:
Eric Tang
2017-07-09 10:35:52 -07:00
parent bbdb09b5f5
commit ec5f774944
5 changed files with 74 additions and 13 deletions

View File

@@ -3,6 +3,7 @@
// Includes:
#include <stdint.h>
#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;

View File

@@ -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;
}

View File

@@ -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

View File

@@ -5,7 +5,7 @@
#include <stdint.h>
#include <stdbool.h>
#include "config_state.h"
#include "parse_config.h"
// Macros:

View File

@@ -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;
}