Extract UsbCommand_ReadConfig() to usb_command_read_config.c. Rename Set{Response,Error}* to SetUsb{Response,Error}

This commit is contained in:
László Monda
2017-11-04 02:11:49 +01:00
parent c0b41b8e60
commit 336c2e5368
4 changed files with 53 additions and 42 deletions

View 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);
}