Branch on a per command basis based on the first byte of the USB payload.

This commit is contained in:
László Monda
2016-09-26 02:37:31 +02:00
parent 5d21312a0c
commit 390197e59c
2 changed files with 20 additions and 6 deletions

View File

@@ -56,7 +56,7 @@ static usb_status_t UsbReceiveData()
usb_status_t UsbGenericHidCallback(class_handle_t handle, uint32_t event, void *param) usb_status_t UsbGenericHidCallback(class_handle_t handle, uint32_t event, void *param)
{ {
usb_status_t error = kStatus_USB_Error; usb_status_t error = kStatus_USB_Error;
uint8_t command; uint8_t command, arg;
switch (event) { switch (event) {
case kUSB_DeviceHidEventSendResponse: case kUSB_DeviceHidEventSendResponse:
@@ -64,13 +64,23 @@ usb_status_t UsbGenericHidCallback(class_handle_t handle, uint32_t event, void *
case kUSB_DeviceHidEventRecvResponse: case kUSB_DeviceHidEventRecvResponse:
command = GenericHidBuffer[GenericHidBufferIndex][0]; command = GenericHidBuffer[GenericHidBufferIndex][0];
arg = GenericHidBuffer[GenericHidBufferIndex][1];
switch (command) { switch (command) {
case 0: case USB_COMMAND_JUMP_TO_BOOTLOADER:
TEST_RED_ON(); break;
break; case USB_COMMAND_TEST_LED:
case 1: switch (arg) {
TEST_RED_OFF(); case 0:
TEST_RED_ON();
break;
case 1:
TEST_RED_OFF();
break;
default:
break;
}
case USB_COMMAND_LED_DRIVER:
break; break;
default: default:
break; break;

View File

@@ -22,6 +22,10 @@
#define USB_GENERIC_HID_IN_BUFFER_LENGTH 64 #define USB_GENERIC_HID_IN_BUFFER_LENGTH 64
#define USB_GENERIC_HID_OUT_BUFFER_LENGTH 64 #define USB_GENERIC_HID_OUT_BUFFER_LENGTH 64
#define USB_COMMAND_JUMP_TO_BOOTLOADER 0
#define USB_COMMAND_TEST_LED 1
#define USB_COMMAND_LED_DRIVER 2
// Variables: // Variables:
extern usb_device_class_struct_t UsbGenericHidClass; extern usb_device_class_struct_t UsbGenericHidClass;