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);
|
||||||
|
}
|
||||||
8
right/src/usb_commands/usb_command_read_config.h
Normal file
8
right/src/usb_commands/usb_command_read_config.h
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
#ifndef __USB_COMMAND_READ_CONFIG_H__
|
||||||
|
#define __USB_COMMAND_READ_CONFIG_H__
|
||||||
|
|
||||||
|
// Functions:
|
||||||
|
|
||||||
|
void UsbCommand_ReadConfig(bool isHardware);
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -17,27 +17,23 @@
|
|||||||
#include "microseconds/microseconds_pit.c"
|
#include "microseconds/microseconds_pit.c"
|
||||||
#include "i2c_watchdog.h"
|
#include "i2c_watchdog.h"
|
||||||
#include "usb_commands/usb_command_apply_config.h"
|
#include "usb_commands/usb_command_apply_config.h"
|
||||||
|
#include "usb_commands/usb_command_read_config.h"
|
||||||
|
|
||||||
uint8_t UsbDebugInfo[USB_GENERIC_HID_OUT_BUFFER_LENGTH];
|
uint8_t UsbDebugInfo[USB_GENERIC_HID_OUT_BUFFER_LENGTH];
|
||||||
|
|
||||||
// Functions for setting error statuses
|
// Functions for setting error statuses
|
||||||
|
|
||||||
void setError(uint8_t error)
|
void SetUsbError(uint8_t error)
|
||||||
{
|
{
|
||||||
GenericHidOutBuffer[0] = error;
|
GenericHidOutBuffer[0] = error;
|
||||||
}
|
}
|
||||||
|
|
||||||
void setGenericError(void)
|
void SetUsbResponseByte(uint8_t response)
|
||||||
{
|
|
||||||
setError(UsbResponse_GenericError);
|
|
||||||
}
|
|
||||||
|
|
||||||
void SetResponseByte(uint8_t response)
|
|
||||||
{
|
{
|
||||||
GenericHidOutBuffer[1] = response;
|
GenericHidOutBuffer[1] = response;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SetResponseWord(uint16_t response)
|
void SetUsbResponseWord(uint16_t response)
|
||||||
{
|
{
|
||||||
*((uint16_t*)(GenericHidOutBuffer+1)) = response;
|
*((uint16_t*)(GenericHidOutBuffer+1)) = response;
|
||||||
}
|
}
|
||||||
@@ -50,25 +46,25 @@ void getSystemProperty(void)
|
|||||||
|
|
||||||
switch (propertyId) {
|
switch (propertyId) {
|
||||||
case SystemPropertyId_UsbProtocolVersion:
|
case SystemPropertyId_UsbProtocolVersion:
|
||||||
SetResponseByte(SYSTEM_PROPERTY_USB_PROTOCOL_VERSION);
|
SetUsbResponseByte(SYSTEM_PROPERTY_USB_PROTOCOL_VERSION);
|
||||||
break;
|
break;
|
||||||
case SystemPropertyId_BridgeProtocolVersion:
|
case SystemPropertyId_BridgeProtocolVersion:
|
||||||
SetResponseByte(SYSTEM_PROPERTY_BRIDGE_PROTOCOL_VERSION);
|
SetUsbResponseByte(SYSTEM_PROPERTY_BRIDGE_PROTOCOL_VERSION);
|
||||||
break;
|
break;
|
||||||
case SystemPropertyId_DataModelVersion:
|
case SystemPropertyId_DataModelVersion:
|
||||||
SetResponseByte(SYSTEM_PROPERTY_DATA_MODEL_VERSION);
|
SetUsbResponseByte(SYSTEM_PROPERTY_DATA_MODEL_VERSION);
|
||||||
break;
|
break;
|
||||||
case SystemPropertyId_FirmwareVersion:
|
case SystemPropertyId_FirmwareVersion:
|
||||||
SetResponseByte(SYSTEM_PROPERTY_FIRMWARE_VERSION);
|
SetUsbResponseByte(SYSTEM_PROPERTY_FIRMWARE_VERSION);
|
||||||
break;
|
break;
|
||||||
case SystemPropertyId_HardwareConfigSize:
|
case SystemPropertyId_HardwareConfigSize:
|
||||||
SetResponseWord(HARDWARE_CONFIG_SIZE);
|
SetUsbResponseWord(HARDWARE_CONFIG_SIZE);
|
||||||
break;
|
break;
|
||||||
case SystemPropertyId_UserConfigSize:
|
case SystemPropertyId_UserConfigSize:
|
||||||
SetResponseWord(USER_CONFIG_SIZE);
|
SetUsbResponseWord(USER_CONFIG_SIZE);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
setGenericError();
|
SetUsbError(1);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -91,7 +87,7 @@ void setTestLed(void)
|
|||||||
// To be removed. Now it's already part of getKeyboardState()
|
// To be removed. Now it's already part of getKeyboardState()
|
||||||
void readMergeSensor(void)
|
void readMergeSensor(void)
|
||||||
{
|
{
|
||||||
SetResponseByte(MERGE_SENSOR_IS_MERGED);
|
SetUsbResponseByte(MERGE_SENSOR_IS_MERGED);
|
||||||
}
|
}
|
||||||
|
|
||||||
void setLedPwm(void)
|
void setLedPwm(void)
|
||||||
@@ -125,34 +121,13 @@ void legacyLaunchEepromTransfer(void)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void readConfiguration(bool isHardware)
|
|
||||||
{
|
|
||||||
uint8_t length = GenericHidInBuffer[1];
|
|
||||||
uint16_t offset = *(uint16_t*)(GenericHidInBuffer+2);
|
|
||||||
|
|
||||||
if (length > USB_GENERIC_HID_OUT_BUFFER_LENGTH-1) {
|
|
||||||
setError(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) {
|
|
||||||
setError(ConfigTransferResponse_BufferOutOfBounds);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
memcpy(GenericHidOutBuffer+1, buffer+offset, length);
|
|
||||||
}
|
|
||||||
|
|
||||||
void writeConfiguration(bool isHardware)
|
void writeConfiguration(bool isHardware)
|
||||||
{
|
{
|
||||||
uint8_t length = GenericHidInBuffer[1];
|
uint8_t length = GenericHidInBuffer[1];
|
||||||
uint16_t offset = *((uint16_t*)(GenericHidInBuffer+1+1));
|
uint16_t offset = *((uint16_t*)(GenericHidInBuffer+1+1));
|
||||||
|
|
||||||
if (length > USB_GENERIC_HID_OUT_BUFFER_LENGTH-1-1-2) {
|
if (length > USB_GENERIC_HID_OUT_BUFFER_LENGTH-1-1-2) {
|
||||||
setError(ConfigTransferResponse_LengthTooLarge);
|
SetUsbError(ConfigTransferResponse_LengthTooLarge);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -160,7 +135,7 @@ void writeConfiguration(bool isHardware)
|
|||||||
uint16_t bufferLength = isHardware ? HARDWARE_CONFIG_SIZE : USER_CONFIG_SIZE;
|
uint16_t bufferLength = isHardware ? HARDWARE_CONFIG_SIZE : USER_CONFIG_SIZE;
|
||||||
|
|
||||||
if (offset + length > bufferLength) {
|
if (offset + length > bufferLength) {
|
||||||
setError(ConfigTransferResponse_BufferOutOfBounds);
|
SetUsbError(ConfigTransferResponse_BufferOutOfBounds);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -197,7 +172,7 @@ void jumpToSlaveBootloader(void)
|
|||||||
uint8_t uhkModuleDriverId = GenericHidInBuffer[1];
|
uint8_t uhkModuleDriverId = GenericHidInBuffer[1];
|
||||||
|
|
||||||
if (uhkModuleDriverId >= UHK_MODULE_MAX_COUNT) {
|
if (uhkModuleDriverId >= UHK_MODULE_MAX_COUNT) {
|
||||||
setError(JumpToBootloaderError_InvalidModuleDriverId);
|
SetUsbError(JumpToBootloaderError_InvalidModuleDriverId);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -248,13 +223,13 @@ void UsbProtocolHandler(void)
|
|||||||
legacyLaunchEepromTransfer();
|
legacyLaunchEepromTransfer();
|
||||||
break;
|
break;
|
||||||
case UsbCommandId_ReadHardwareConfiguration:
|
case UsbCommandId_ReadHardwareConfiguration:
|
||||||
readConfiguration(true);
|
UsbCommand_ReadConfig(true);
|
||||||
break;
|
break;
|
||||||
case UsbCommandId_WriteHardwareConfiguration:
|
case UsbCommandId_WriteHardwareConfiguration:
|
||||||
writeConfiguration(true);
|
writeConfiguration(true);
|
||||||
break;
|
break;
|
||||||
case UsbCommandId_ReadUserConfiguration:
|
case UsbCommandId_ReadUserConfiguration:
|
||||||
readConfiguration(false);
|
UsbCommand_ReadConfig(false);
|
||||||
break;
|
break;
|
||||||
case UsbCommandId_GetKeyboardState:
|
case UsbCommandId_GetKeyboardState:
|
||||||
getKeyboardState();
|
getKeyboardState();
|
||||||
|
|||||||
@@ -48,5 +48,8 @@
|
|||||||
// Functions:
|
// Functions:
|
||||||
|
|
||||||
void UsbProtocolHandler(void);
|
void UsbProtocolHandler(void);
|
||||||
|
void SetUsbError(uint8_t error);
|
||||||
|
void SetUsbResponseByte(uint8_t response);
|
||||||
|
void SetUsbResponseWord(uint16_t response);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
Reference in New Issue
Block a user