diff --git a/right/src/config_buffer.c b/right/src/config_buffer.c new file mode 100644 index 0000000..9923984 --- /dev/null +++ b/right/src/config_buffer.c @@ -0,0 +1,3 @@ +#include "config_buffer.h" + +uint8_t ConfigBuffer[EEPROM_SIZE]; diff --git a/right/src/config_buffer.h b/right/src/config_buffer.h new file mode 100644 index 0000000..52bc44b --- /dev/null +++ b/right/src/config_buffer.h @@ -0,0 +1,16 @@ +#ifndef __CONFIG_BUFFER_H__ +#define __CONFIG_BUFFER_H__ + +// Includes: + + #include "fsl_common.h" + +// Macros: + + #define EEPROM_SIZE (32*1024) + +// Variables: + + extern uint8_t ConfigBuffer[EEPROM_SIZE]; + +#endif diff --git a/right/src/usb_protocol_handler.c b/right/src/usb_protocol_handler.c index 8a17e0e..54846ac 100644 --- a/right/src/usb_protocol_handler.c +++ b/right/src/usb_protocol_handler.c @@ -4,6 +4,8 @@ #include "i2c_addresses.h" #include "led_driver.h" #include "merge_sensor.h" +#include "deserialize.h" +#include "config_buffer.h" void SetError(uint8_t error); void SetGenericError(); @@ -16,6 +18,8 @@ void ReadLedDriver(); void WriteEeprom(); void ReadEeprom(); void ReadMergeSensor(); +void uploadConfig(); +void applyConfig(); // Functions for setting error statuses @@ -65,6 +69,12 @@ void UsbProtocolHandler() case USB_COMMAND_READ_MERGE_SENSOR: ReadMergeSensor(); break; + case USB_COMMAND_UPLOAD_CONFIG: + uploadConfig(); + break; + case USB_COMMAND_APPLY_CONFIG: + applyConfig(); + break; default: break; } @@ -171,3 +181,21 @@ void ReadMergeSensor() { SetResponseByte(MERGE_SENSOR_IS_MERGED); } + +void uploadConfig() +{ + uint8_t byteCount = GenericHidInBuffer[1]; + uint16_t memoryOffset = *((uint16_t*)(GenericHidInBuffer+2)); + + if (byteCount > USB_GENERIC_HID_OUT_BUFFER_LENGTH-4) { + SetError(UPLOAD_CONFIG_INVALID_PAYLOAD_SIZE); + return; + } + + memcpy(ConfigBuffer+memoryOffset, GenericHidInBuffer+4, byteCount); +} + +void applyConfig() +{ + deserialize_Layer(ConfigBuffer, 0); +} diff --git a/right/src/usb_protocol_handler.h b/right/src/usb_protocol_handler.h index c835b98..69a1789 100644 --- a/right/src/usb_protocol_handler.h +++ b/right/src/usb_protocol_handler.h @@ -21,10 +21,13 @@ #define WRITE_LED_DRIVER_RESPONSE_INVALID_ADDRESS 1 #define WRITE_LED_DRIVER_RESPONSE_INVALID_PAYLOAD_SIZE 2 #define USB_COMMAND_READ_LED_DRIVER 4 - #define USB_COMMAND_WRITE_EEPROM 5 + #define USB_COMMAND_WRITE_EEPROM 5 #define WRITE_EEPROM_RESPONSE_INVALID_PAYLOAD_SIZE 1 #define USB_COMMAND_READ_EEPROM 6 - #define USB_COMMAND_READ_MERGE_SENSOR 7 + #define USB_COMMAND_READ_MERGE_SENSOR 7 + #define USB_COMMAND_UPLOAD_CONFIG 8 + #define UPLOAD_CONFIG_INVALID_PAYLOAD_SIZE 1 + #define USB_COMMAND_APPLY_CONFIG 9 // Functions: