Extract UsbCommand_ReadConfig() to usb_command_read_config.c. Rename Set{Response,Error}* to SetUsb{Response,Error}
This commit is contained in:
25
right/src/usb_commands/usb_command_read_config.c
Normal file
25
right/src/usb_commands/usb_command_read_config.c
Normal file
@@ -0,0 +1,25 @@
|
||||
#include "fsl_common.h"
|
||||
#include "usb_commands/usb_command_read_config.h"
|
||||
#include "usb_protocol_handler.h"
|
||||
#include "eeprom.h"
|
||||
|
||||
void UsbCommand_ReadConfig(bool isHardware)
|
||||
{
|
||||
uint8_t length = GenericHidInBuffer[1];
|
||||
uint16_t offset = *(uint16_t*)(GenericHidInBuffer+2);
|
||||
|
||||
if (length > USB_GENERIC_HID_OUT_BUFFER_LENGTH-1) {
|
||||
SetUsbError(ConfigTransferResponse_LengthTooLarge);
|
||||
return;
|
||||
}
|
||||
|
||||
uint8_t *buffer = isHardware ? HardwareConfigBuffer.buffer : ValidatedUserConfigBuffer.buffer;
|
||||
uint16_t bufferLength = isHardware ? HARDWARE_CONFIG_SIZE : USER_CONFIG_SIZE;
|
||||
|
||||
if (offset + length > bufferLength) {
|
||||
SetUsbError(ConfigTransferResponse_BufferOutOfBounds);
|
||||
return;
|
||||
}
|
||||
|
||||
memcpy(GenericHidOutBuffer+1, buffer+offset, length);
|
||||
}
|
||||
Reference in New Issue
Block a user