Extract UsbCommand_WriteConfig()

This commit is contained in:
László Monda
2017-11-04 08:43:27 +01:00
parent 232f595b41
commit 54496ca210
3 changed files with 36 additions and 23 deletions

View File

@@ -0,0 +1,25 @@
#include "fsl_common.h"
#include "usb_commands/usb_command_write_config.h"
#include "usb_protocol_handler.h"
#include "eeprom.h"
void UsbCommand_WriteConfig(bool isHardware)
{
uint8_t length = GenericHidInBuffer[1];
uint16_t offset = *((uint16_t*)(GenericHidInBuffer+1+1));
if (length > USB_GENERIC_HID_OUT_BUFFER_LENGTH-1-1-2) {
SetUsbError(ConfigTransferResponse_LengthTooLarge);
return;
}
uint8_t *buffer = isHardware ? HardwareConfigBuffer.buffer : StagingUserConfigBuffer.buffer;
uint16_t bufferLength = isHardware ? HARDWARE_CONFIG_SIZE : USER_CONFIG_SIZE;
if (offset + length > bufferLength) {
SetUsbError(ConfigTransferResponse_BufferOutOfBounds);
return;
}
memcpy(buffer+offset, GenericHidInBuffer+1+1+2, length);
}