diff --git a/right/build/kds/MK22FN512xxx12_flash.ld b/right/build/kds/MK22FN512xxx12_flash.ld index 7226037..4fad685 100644 --- a/right/build/kds/MK22FN512xxx12_flash.ld +++ b/right/build/kds/MK22FN512xxx12_flash.ld @@ -214,7 +214,14 @@ SECTIONS __bss_end__ = .; __END_BSS = .; } > m_data - + + .m_data_2 : + { + . = ALIGN(4); + *(.m_data_2) /* This is an User defined section */ + . = ALIGN(4); + } > m_data_2 + .heap : { . = ALIGN(8); diff --git a/right/src/config_parser/config_state.c b/right/src/config_parser/config_state.c index 79e6b12..3bb01c3 100644 --- a/right/src/config_parser/config_state.c +++ b/right/src/config_parser/config_state.c @@ -3,8 +3,12 @@ static uint8_t hardwareConfig[HARDWARE_CONFIG_SIZE]; config_buffer_t HardwareConfigBuffer = {hardwareConfig}; -static uint8_t userConfig[USER_CONFIG_SIZE]; -config_buffer_t UserConfigBuffer = {userConfig}; +static uint8_t userConfig1[USER_CONFIG_SIZE]; +static uint8_t __attribute__((section (".m_data_2"))) userConfig2[USER_CONFIG_SIZE]; +config_buffer_t UserConfigBuffer = { userConfig1 }; +config_buffer_t StagingUserConfigBuffer = { userConfig2 }; + +bool ParserRunDry; uint8_t readUInt8(config_buffer_t *buffer) { return buffer->buffer[buffer->offset++]; diff --git a/right/src/config_parser/config_state.h b/right/src/config_parser/config_state.h index 1af70b8..84dfd00 100644 --- a/right/src/config_parser/config_state.h +++ b/right/src/config_parser/config_state.h @@ -21,8 +21,10 @@ // Variables: + extern bool ParserRunDry; extern config_buffer_t HardwareConfigBuffer; extern config_buffer_t UserConfigBuffer; + extern config_buffer_t StagingUserConfigBuffer; // Functions: diff --git a/right/src/config_parser/parse_keymap.c b/right/src/config_parser/parse_keymap.c index 15e51dc..27695cd 100644 --- a/right/src/config_parser/parse_keymap.c +++ b/right/src/config_parser/parse_keymap.c @@ -3,8 +3,6 @@ #include "current_keymap.h" #include "led_display.h" -static bool isDryRun; - static parser_error_t parseNoneAction(key_action_t *keyAction, config_buffer_t *buffer) { keyAction->type = KeyActionType_None; return ParserError_Success; @@ -146,7 +144,7 @@ static parser_error_t parseKeyActions(uint8_t targetLayer, config_buffer_t *buff return ParserError_InvalidActionCount; } for (uint16_t actionIdx = 0; actionIdx < actionCount; actionIdx++) { - errorCode = parseKeyAction(isDryRun ? &dummyKeyAction : &CurrentKeymap[targetLayer][moduleId][actionIdx], buffer); + errorCode = parseKeyAction(ParserRunDry ? &dummyKeyAction : &CurrentKeymap[targetLayer][moduleId][actionIdx], buffer); if (errorCode != ParserError_Success) { return errorCode; } @@ -187,22 +185,28 @@ parser_error_t ParseKeymap(config_buffer_t *buffer) {; const char *name = readString(buffer, &nameLen); const char *description = readString(buffer, &descriptionLen); uint16_t layerCount = readCompactLength(buffer); + bool temp; (void)name; (void)description; if (layerCount != LAYER_COUNT) { return ParserError_InvalidLayerCount; } - isDryRun = !isDefault; - if (!isDryRun) { + temp = ParserRunDry; + if (!isDefault) { + ParserRunDry = true; + } + if (!ParserRunDry) { LedDisplay_SetText(abbreviationLen, abbreviation); } for (uint16_t layerIdx = 0; layerIdx < layerCount; layerIdx++) { errorCode = parseLayer(buffer, layerIdx); if (errorCode != ParserError_Success) { + ParserRunDry = temp; return errorCode; } } + ParserRunDry = temp; return ParserError_Success; } diff --git a/right/src/usb_protocol_handler.c b/right/src/usb_protocol_handler.c index 778ec7f..c1f7c08 100644 --- a/right/src/usb_protocol_handler.c +++ b/right/src/usb_protocol_handler.c @@ -85,10 +85,26 @@ void readMergeSensor(void) void applyConfig(void) { + uint8_t *temp; + + ParserRunDry = true; + StagingUserConfigBuffer.offset = 0; + GenericHidOutBuffer[0] = ParseConfig(&StagingUserConfigBuffer); + GenericHidOutBuffer[1] = StagingUserConfigBuffer.offset; + GenericHidOutBuffer[2] = StagingUserConfigBuffer.offset >> 8; + GenericHidOutBuffer[3] = 0; + if (GenericHidOutBuffer[0]) { + return; + } + ParserRunDry = false; + temp = UserConfigBuffer.buffer; + UserConfigBuffer.buffer = StagingUserConfigBuffer.buffer; + StagingUserConfigBuffer.buffer = temp; UserConfigBuffer.offset = 0; GenericHidOutBuffer[0] = ParseConfig(&UserConfigBuffer); GenericHidOutBuffer[1] = UserConfigBuffer.offset; GenericHidOutBuffer[2] = UserConfigBuffer.offset >> 8; + GenericHidOutBuffer[3] = 1; } void setLedPwm(void) @@ -144,7 +160,7 @@ void writeConfiguration(bool isHardware) return; } - uint8_t *buffer = isHardware ? HardwareConfigBuffer.buffer : UserConfigBuffer.buffer; + uint8_t *buffer = isHardware ? HardwareConfigBuffer.buffer : StagingUserConfigBuffer.buffer; uint16_t bufferLength = isHardware ? HARDWARE_CONFIG_SIZE : USER_CONFIG_SIZE; if (offset + length > bufferLength) {