Add new UsbCommand_GetModuleProperties() device protocol command.

This commit is contained in:
László Monda
2017-12-15 02:46:30 +01:00
parent fd43e81e46
commit 85e92d21b4
6 changed files with 41 additions and 2 deletions

View File

@@ -13,7 +13,7 @@
// Macros:
#define SLOT_COUNT 4
#define IS_VALID_SLAVE_SLOT(slotId) (SlotId_LeftKeyboardHalf <= (slotId) && (slotId) <= SlotId_RightModule)
#define IS_VALID_MODULE_SLOT(slotId) (SlotId_LeftKeyboardHalf <= (slotId) && (slotId) <= SlotId_RightModule)
// Typedefs:

View File

@@ -0,0 +1,21 @@
#include "fsl_common.h"
#include "usb_commands/usb_command_get_module_properties.h"
#include "usb_protocol_handler.h"
#include "slot.h"
#include "slave_drivers/uhk_module_driver.h"
void UsbCommand_GetModuleProperties()
{
slot_t slotId = GetUsbRxBufferUint8(1);
if (!IS_VALID_MODULE_SLOT(slotId)) {
SetUsbTxBufferUint8(0, UsbStatusCode_ReadConfig_InvalidModuleSlotId);
}
uint8_t moduleDriverId = SLOT_ID_TO_UHK_MODULE_DRIVER_ID(slotId);
uhk_module_state_t *moduleState = UhkModuleStates + moduleDriverId;
GenericHidOutBuffer[1] = moduleState->moduleId;
memcpy(GenericHidOutBuffer + 2, &moduleState->moduleProtocolVersion, sizeof(version_t));
memcpy(GenericHidOutBuffer + 2 + sizeof(version_t), &moduleState->firmwareVersion, sizeof(version_t));
}

View File

@@ -0,0 +1,14 @@
#ifndef __USB_COMMAND_GET_MODULE_PROPERTIES_H__
#define __USB_COMMAND_GET_MODULE_PROPERTIES_H__
// Functions:
void UsbCommand_GetModuleProperties();
// Typedefs:
typedef enum {
UsbStatusCode_ReadConfig_InvalidModuleSlotId = 2,
} usb_status_code_get_module_properties_t;
#endif

View File

@@ -7,7 +7,7 @@ void UsbCommand_JumpToModuleBootloader(void)
{
uint8_t slotId = GetUsbRxBufferUint8(1);
if (!IS_VALID_SLAVE_SLOT(slotId)) {
if (!IS_VALID_MODULE_SLOT(slotId)) {
SetUsbTxBufferUint8(0, UsbStatusCode_JumpToModuleBootloader_InvalidSlaveSlotId);
return;
}

View File

@@ -61,6 +61,9 @@ void UsbProtocolHandler(void)
case UsbCommandId_SetLedPwmBrightness:
UsbCommand_SetLedPwmBrightness();
break;
case UsbCommandId_GetModuleProperties:
UsbCommand_GetModuleProperties();
break;
default:
SetUsbTxBufferUint8(0, UsbStatusCode_InvalidCommand);
break;

View File

@@ -30,6 +30,7 @@
UsbCommandId_GetDebugBuffer = 0x0b,
UsbCommandId_GetAdcValue = 0x0c,
UsbCommandId_SetLedPwmBrightness = 0x0d,
UsbCommandId_GetModuleProperties = 0x0e,
} usb_command_id_t;
typedef enum {