diff --git a/right/src/slot.h b/right/src/slot.h index 618e33a..e60b10e 100644 --- a/right/src/slot.h +++ b/right/src/slot.h @@ -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: diff --git a/right/src/usb_commands/usb_command_get_module_properties.c b/right/src/usb_commands/usb_command_get_module_properties.c new file mode 100644 index 0000000..bd40fd2 --- /dev/null +++ b/right/src/usb_commands/usb_command_get_module_properties.c @@ -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)); +} diff --git a/right/src/usb_commands/usb_command_get_module_properties.h b/right/src/usb_commands/usb_command_get_module_properties.h new file mode 100644 index 0000000..50bb7d8 --- /dev/null +++ b/right/src/usb_commands/usb_command_get_module_properties.h @@ -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 diff --git a/right/src/usb_commands/usb_command_jump_to_module_bootloader.c b/right/src/usb_commands/usb_command_jump_to_module_bootloader.c index 2dfa08e..4cd01dc 100644 --- a/right/src/usb_commands/usb_command_jump_to_module_bootloader.c +++ b/right/src/usb_commands/usb_command_jump_to_module_bootloader.c @@ -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; } diff --git a/right/src/usb_protocol_handler.c b/right/src/usb_protocol_handler.c index 9c7ff45..363dbd6 100644 --- a/right/src/usb_protocol_handler.c +++ b/right/src/usb_protocol_handler.c @@ -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; diff --git a/right/src/usb_protocol_handler.h b/right/src/usb_protocol_handler.h index f901f2c..f4590f5 100644 --- a/right/src/usb_protocol_handler.h +++ b/right/src/usb_protocol_handler.h @@ -30,6 +30,7 @@ UsbCommandId_GetDebugBuffer = 0x0b, UsbCommandId_GetAdcValue = 0x0c, UsbCommandId_SetLedPwmBrightness = 0x0d, + UsbCommandId_GetModuleProperties = 0x0e, } usb_command_id_t; typedef enum {