diff --git a/right/src/eeprom.c b/right/src/eeprom.c index a348858..c51181e 100644 --- a/right/src/eeprom.c +++ b/right/src/eeprom.c @@ -125,3 +125,8 @@ status_t EEPROM_LaunchTransfer(eeprom_operation_t operation, config_buffer_id_t IsEepromBusy = LastEepromTransferStatus == kStatus_Success; return LastEepromTransferStatus; } + +bool IsEepromOperationValid(eeprom_operation_t operation) +{ + return operation == EepromOperation_Read || operation == EepromOperation_Write; +} diff --git a/right/src/eeprom.h b/right/src/eeprom.h index a3415e0..7de803a 100644 --- a/right/src/eeprom.h +++ b/right/src/eeprom.h @@ -31,5 +31,6 @@ void EEPROM_Init(void); status_t EEPROM_LaunchTransfer(eeprom_operation_t operation, config_buffer_id_t config_buffer_id, void (*successCallback)); + bool IsEepromOperationValid(eeprom_operation_t operation); #endif diff --git a/right/src/usb_commands/usb_command_launch_eeprom_transfer.c b/right/src/usb_commands/usb_command_launch_eeprom_transfer.c new file mode 100644 index 0000000..e494b89 --- /dev/null +++ b/right/src/usb_commands/usb_command_launch_eeprom_transfer.c @@ -0,0 +1,25 @@ +#include "fsl_common.h" +#include "usb_commands/usb_command_launch_eeprom_transfer.h" +#include "usb_protocol_handler.h" +#include "eeprom.h" +#include "config_parser/config_globals.h" + +void UsbCommand_LaunchEepromTransfer(void) +{ + eeprom_operation_t eepromOperation = GetUsbRxBufferUint8(1); + config_buffer_id_t configBufferId = GetUsbRxBufferUint8(2); + + if (!IsEepromOperationValid(eepromOperation)) { + SetUsbTxBufferUint8(0, UsbStatusCode_LaunchEepromTransfer_InvalidEepromOperation); + } + + if (!IsConfigBufferIdValid(configBufferId)) { + SetUsbTxBufferUint8(0, UsbStatusCode_LaunchEepromTransfer_InvalidConfigBufferId); + } + + status_t status = EEPROM_LaunchTransfer(eepromOperation, configBufferId, NULL); + if (status != kStatus_Success) { + SetUsbTxBufferUint8(0, UsbStatusCode_LaunchEepromTransfer_TransferError); + SetUsbTxBufferUint32(1, status); + } +} diff --git a/right/src/usb_commands/usb_command_launch_eeprom_transfer.h b/right/src/usb_commands/usb_command_launch_eeprom_transfer.h new file mode 100644 index 0000000..d34158c --- /dev/null +++ b/right/src/usb_commands/usb_command_launch_eeprom_transfer.h @@ -0,0 +1,16 @@ +#ifndef __USB_COMMAND_LAUNCH_EEPROM_TRANSFER_H__ +#define __USB_COMMAND_LAUNCH_EEPROM_TRANSFER_H__ + +// Typedef + + typedef enum { + UsbStatusCode_LaunchEepromTransfer_InvalidEepromOperation = 2, + UsbStatusCode_LaunchEepromTransfer_InvalidConfigBufferId = 3, + UsbStatusCode_LaunchEepromTransfer_TransferError = 4, + } usb_status_code_launch_eeprom_transfer_t; + +// Functions: + + void UsbCommand_LaunchEepromTransfer(void); + +#endif diff --git a/right/src/usb_commands/usb_command_launch_eeprom_transfer_legacy.c b/right/src/usb_commands/usb_command_launch_eeprom_transfer_legacy.c deleted file mode 100644 index ae79309..0000000 --- a/right/src/usb_commands/usb_command_launch_eeprom_transfer_legacy.c +++ /dev/null @@ -1,23 +0,0 @@ -#include "fsl_common.h" -#include "usb_commands/usb_command_launch_eeprom_transfer_legacy.h" -#include "usb_protocol_handler.h" -#include "eeprom.h" - -void UsbCommand_LaunchEepromTransferLegacy(void) -{ - uint8_t legacyEepromTransferId = GetUsbRxBufferUint8(1); - switch (legacyEepromTransferId) { - case 0: - EEPROM_LaunchTransfer(EepromOperation_Read, ConfigBufferId_HardwareConfig, NULL); - break; - case 1: - EEPROM_LaunchTransfer(EepromOperation_Write, ConfigBufferId_HardwareConfig, NULL); - break; - case 2: - EEPROM_LaunchTransfer(EepromOperation_Read, ConfigBufferId_ValidatedUserConfig, NULL); - break; - case 3: - EEPROM_LaunchTransfer(EepromOperation_Write, ConfigBufferId_ValidatedUserConfig, NULL); - break; - } -} diff --git a/right/src/usb_commands/usb_command_launch_eeprom_transfer_legacy.h b/right/src/usb_commands/usb_command_launch_eeprom_transfer_legacy.h deleted file mode 100644 index adc78ba..0000000 --- a/right/src/usb_commands/usb_command_launch_eeprom_transfer_legacy.h +++ /dev/null @@ -1,8 +0,0 @@ -#ifndef __USB_COMMAND_LAUNCH_EEPROM_TRANSFER_LEGACY_H__ -#define __USB_COMMAND_LAUNCH_EEPROM_TRANSFER_LEGACY_H__ - -// Functions: - - void UsbCommand_LaunchEepromTransferLegacy(void); - -#endif diff --git a/right/src/usb_protocol_handler.c b/right/src/usb_protocol_handler.c index 9546697..ffc7441 100644 --- a/right/src/usb_protocol_handler.c +++ b/right/src/usb_protocol_handler.c @@ -7,7 +7,7 @@ #include "usb_commands/usb_command_apply_config.h" #include "usb_commands/usb_command_set_led_pwm_brightness.h" #include "usb_commands/usb_command_get_adc_value.h" -#include "usb_commands/usb_command_launch_eeprom_transfer_legacy.h" +#include "usb_commands/usb_command_launch_eeprom_transfer.h" #include "usb_commands/usb_command_read_config.h" #include "usb_commands/usb_command_get_keyboard_state.h" #include "usb_commands/usb_command_get_debug_buffer.h" @@ -40,8 +40,8 @@ void UsbProtocolHandler(void) case UsbCommandId_GetAdcValue: UsbCommand_GetAdcValue(); break; - case UsbCommandId_LaunchEepromTransferLegacy: - UsbCommand_LaunchEepromTransferLegacy(); + case UsbCommandId_LaunchEepromTransfer: + UsbCommand_LaunchEepromTransfer(); break; case UsbCommandId_ReadConfig: UsbCommand_ReadConfig(); diff --git a/right/src/usb_protocol_handler.h b/right/src/usb_protocol_handler.h index 4798c63..6e5508a 100644 --- a/right/src/usb_protocol_handler.h +++ b/right/src/usb_protocol_handler.h @@ -13,23 +13,23 @@ // Typedefs: typedef enum { - UsbCommandId_GetProperty = 0x00, + UsbCommandId_GetProperty = 0x00, - UsbCommandId_Reenumerate = 0x01, - UsbCommandId_JumpToModuleBootloader = 0x02, // was 0x12 - UsbCommandId_SendKbootCommandToModule = 0x03, // was 0x13 + UsbCommandId_Reenumerate = 0x01, + UsbCommandId_JumpToModuleBootloader = 0x02, // was 0x12 + UsbCommandId_SendKbootCommandToModule = 0x03, // was 0x13 - UsbCommandId_ReadConfig = 0x04, // was 0x0d and 0x0f - UsbCommandId_WriteHardwareConfig = 0x05, // was 0x0e - UsbCommandId_WriteStagingUserConfig = 0x06, // was 0x08 - UsbCommandId_ApplyConfig = 0x07, // was 0x09, - UsbCommandId_LaunchEepromTransferLegacy = 0x0C, + UsbCommandId_ReadConfig = 0x04, // was 0x0d and 0x0f + UsbCommandId_WriteHardwareConfig = 0x05, // was 0x0e + UsbCommandId_WriteStagingUserConfig = 0x06, // was 0x08 + UsbCommandId_ApplyConfig = 0x07, // was 0x09 + UsbCommandId_LaunchEepromTransfer = 0x08, // was 0x0C - UsbCommandId_GetKeyboardState = 0x10, - UsbCommandId_SetTestLed = 0x14, //was 0x02 - UsbCommandId_GetDebugBuffer = 0x11, - UsbCommandId_GetAdcValue = 0x0B, - UsbCommandId_SetLedPwmBrightness = 0x0A, + UsbCommandId_GetKeyboardState = 0x10, + UsbCommandId_SetTestLed = 0x14, // was 0x02 + UsbCommandId_GetDebugBuffer = 0x11, + UsbCommandId_GetAdcValue = 0x0B, + UsbCommandId_SetLedPwmBrightness = 0x0A, } usb_command_id_t; typedef enum {