Move some code from parse_keymap.* to config_state.*
This commit is contained in:
@@ -1,3 +1,33 @@
|
||||
#include "config_state.h"
|
||||
|
||||
uint8_t ConfigBuffer[EEPROM_SIZE];
|
||||
|
||||
uint8_t readUInt8(serialized_buffer_t *buffer) {
|
||||
return buffer->buffer[buffer->offset++];
|
||||
}
|
||||
|
||||
uint16_t readUInt16(serialized_buffer_t *buffer) {
|
||||
uint8_t firstByte = buffer->buffer[buffer->offset++];
|
||||
return firstByte + (buffer->buffer[buffer->offset++] << 8);
|
||||
}
|
||||
|
||||
bool readBool(serialized_buffer_t *buffer) {
|
||||
return buffer->buffer[buffer->offset++] == 1;
|
||||
}
|
||||
|
||||
uint16_t readCompactLength(serialized_buffer_t *buffer) {
|
||||
uint16_t length = readUInt8(buffer);
|
||||
if (length == 0xFF) {
|
||||
length = readUInt16(buffer);
|
||||
}
|
||||
return length;
|
||||
}
|
||||
|
||||
const char *readString(serialized_buffer_t *buffer, uint16_t *len) {
|
||||
const char *str = (const char *)&(buffer->buffer[buffer->offset]);
|
||||
|
||||
*len = readCompactLength(buffer);
|
||||
buffer->offset += *len;
|
||||
|
||||
return str;
|
||||
}
|
||||
|
||||
@@ -9,8 +9,33 @@
|
||||
|
||||
#define EEPROM_SIZE (32*1024)
|
||||
|
||||
// Typedefs:
|
||||
|
||||
typedef struct {
|
||||
uint8_t *buffer;
|
||||
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 uint8_t ConfigBuffer[EEPROM_SIZE];
|
||||
|
||||
// Functions:
|
||||
|
||||
uint8_t readUInt8(serialized_buffer_t *buffer);
|
||||
uint16_t readUInt16(serialized_buffer_t *buffer);
|
||||
bool readBool(serialized_buffer_t *buffer);
|
||||
uint16_t readCompactLength(serialized_buffer_t *buffer);
|
||||
const char *readString(serialized_buffer_t *buffer, uint16_t *len);
|
||||
|
||||
#endif
|
||||
|
||||
@@ -2,40 +2,8 @@
|
||||
#include "key_action.h"
|
||||
#include "current_keymap.h"
|
||||
|
||||
#define longCompactLengthPrefix 0xff
|
||||
|
||||
static bool isDryRun;
|
||||
|
||||
static uint8_t readUInt8(serialized_buffer_t *buffer) {
|
||||
return buffer->buffer[buffer->offset++];
|
||||
}
|
||||
|
||||
static uint16_t readUInt16(serialized_buffer_t *buffer) {
|
||||
uint8_t firstByte = buffer->buffer[buffer->offset++];
|
||||
return firstByte + (buffer->buffer[buffer->offset++] << 8);
|
||||
}
|
||||
|
||||
static bool readBool(serialized_buffer_t *buffer) {
|
||||
return buffer->buffer[buffer->offset++] == 1;
|
||||
}
|
||||
|
||||
static uint16_t readCompactLength(serialized_buffer_t *buffer) {
|
||||
uint16_t length = readUInt8(buffer);
|
||||
if (length == longCompactLengthPrefix) {
|
||||
length = readUInt16(buffer);
|
||||
}
|
||||
return length;
|
||||
}
|
||||
|
||||
static const char *readString(serialized_buffer_t *buffer, uint16_t *len) {
|
||||
const char *str = (const char *)&(buffer->buffer[buffer->offset]);
|
||||
|
||||
*len = readCompactLength(buffer);
|
||||
buffer->offset += *len;
|
||||
|
||||
return str;
|
||||
}
|
||||
|
||||
static parser_error_t parseNoneAction(key_action_t *keyAction, serialized_buffer_t *buffer) {
|
||||
keyAction->type = KeyActionType_None;
|
||||
return ParserError_Success;
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
#include "config_state.h"
|
||||
|
||||
// Macros:
|
||||
|
||||
@@ -49,21 +50,6 @@
|
||||
SerializedMouseAction_Decelerate,
|
||||
} serialized_mouse_action_t;
|
||||
|
||||
typedef struct {
|
||||
uint8_t *buffer;
|
||||
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;
|
||||
|
||||
// Functions:
|
||||
|
||||
parser_error_t ParseKeymap(serialized_buffer_t *buffer);
|
||||
|
||||
Reference in New Issue
Block a user