From 9ef0c484bad8dbc8b463b12f627b972a58a63f14 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A1szl=C3=B3=20Monda?= Date: Thu, 3 Mar 2016 11:12:24 +0100 Subject: [PATCH] Make Generic HID the first interface because further interfaces may be added in the future and this way its index will be fixed and well defined. --- right/usb_composite_device.c | 18 +++++++++--------- right/usb_interface_generic_hid.h | 2 +- right/usb_interface_mouse.h | 2 +- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/right/usb_composite_device.c b/right/usb_composite_device.c index 242e62e..978a9db 100644 --- a/right/usb_composite_device.c +++ b/right/usb_composite_device.c @@ -20,15 +20,15 @@ static usb_status_t UsbDeviceCallback(usb_device_handle handle, uint32_t event, usb_composite_device_t UsbCompositeDevice; usb_device_class_config_struct_t UsbDeviceCompositeClassConfig[USB_COMPOSITE_INTERFACE_COUNT] = { + {UsbGenericHidCallback, (class_handle_t)NULL, &UsbGenericHidClass}, {UsbKeyboardCallback, (class_handle_t)NULL, &UsbKeyboardClass}, {UsbMouseCallback, (class_handle_t)NULL, &UsbMouseClass}, - {UsbGenericHidCallback, (class_handle_t)NULL, &UsbGenericHidClass} }; usb_device_class_config_list_struct_t UsbDeviceCompositeConfigList = { UsbDeviceCompositeClassConfig, UsbDeviceCallback, - USB_COMPOSITE_INTERFACE_COUNT, + USB_COMPOSITE_INTERFACE_COUNT }; static usb_status_t UsbDeviceCallback(usb_device_handle handle, uint32_t event, void *param) @@ -49,9 +49,9 @@ static usb_status_t UsbDeviceCallback(usb_device_handle handle, uint32_t event, case kUSB_DeviceEventSetConfiguration: UsbCompositeDevice.attach = 1U; UsbCompositeDevice.currentConfiguration = *temp8; - UsbMouseSetConfiguration(UsbCompositeDevice.mouseHandle, *temp8); - UsbKeyboardSetConfiguration(UsbCompositeDevice.keyboardHandle, *temp8); UsbGenericHidSetConfiguration(UsbCompositeDevice.genericHidHandle, *temp8); + UsbKeyboardSetConfiguration(UsbCompositeDevice.keyboardHandle, *temp8); + UsbMouseSetConfiguration(UsbCompositeDevice.mouseHandle, *temp8); error = kStatus_USB_Success; break; case kUSB_DeviceEventGetConfiguration: @@ -64,9 +64,9 @@ static usb_status_t UsbDeviceCallback(usb_device_handle handle, uint32_t event, uint8_t alternateSetting = (uint8_t)(*temp16 & 0x00FFU); if (interface < USB_COMPOSITE_INTERFACE_COUNT) { UsbCompositeDevice.currentInterfaceAlternateSetting[interface] = alternateSetting; - UsbMouseSetInterface(UsbCompositeDevice.mouseHandle, interface, alternateSetting); - UsbKeyboardSetInterface(UsbCompositeDevice.keyboardHandle, interface, alternateSetting); UsbGenericHidSetInterface(UsbCompositeDevice.genericHidHandle, interface, alternateSetting); + UsbKeyboardSetInterface(UsbCompositeDevice.keyboardHandle, interface, alternateSetting); + UsbMouseSetInterface(UsbCompositeDevice.mouseHandle, interface, alternateSetting); error = kStatus_USB_Success; } } @@ -118,9 +118,9 @@ void USB_DeviceApplicationInit(void) UsbCompositeDevice.attach = 0U; USB_DeviceClassInit(CONTROLLER_ID, &UsbDeviceCompositeConfigList, &UsbCompositeDevice.deviceHandle); - UsbCompositeDevice.keyboardHandle = UsbDeviceCompositeConfigList.config[0].classHandle; - UsbCompositeDevice.mouseHandle = UsbDeviceCompositeConfigList.config[1].classHandle; - UsbCompositeDevice.genericHidHandle = UsbDeviceCompositeConfigList.config[2].classHandle; + UsbCompositeDevice.genericHidHandle = UsbDeviceCompositeConfigList.config[USB_GENERIC_HID_INTERFACE_INDEX].classHandle; + UsbCompositeDevice.keyboardHandle = UsbDeviceCompositeConfigList.config[USB_KEYBOARD_INTERFACE_INDEX].classHandle; + UsbCompositeDevice.mouseHandle = UsbDeviceCompositeConfigList.config[USB_MOUSE_INTERFACE_INDEX].classHandle; NVIC_SetPriority((IRQn_Type)irqNumber, USB_DEVICE_INTERRUPT_PRIORITY); NVIC_EnableIRQ((IRQn_Type)irqNumber); diff --git a/right/usb_interface_generic_hid.h b/right/usb_interface_generic_hid.h index 910bde4..7b14fa5 100644 --- a/right/usb_interface_generic_hid.h +++ b/right/usb_interface_generic_hid.h @@ -16,7 +16,7 @@ #define USB_GENERIC_HID_SUBCLASS (0x00U) #define USB_GENERIC_HID_PROTOCOL (0x00U) - #define USB_GENERIC_HID_INTERFACE_INDEX (2U) + #define USB_GENERIC_HID_INTERFACE_INDEX (0U) #define USB_GENERIC_HID_INTERFACE_COUNT (1U) #define USB_GENERIC_HID_INTERFACE_ALTERNATE_SETTING (0U) diff --git a/right/usb_interface_mouse.h b/right/usb_interface_mouse.h index b706f2e..4f3280e 100644 --- a/right/usb_interface_mouse.h +++ b/right/usb_interface_mouse.h @@ -16,7 +16,7 @@ #define USB_MOUSE_SUBCLASS (0x01U) #define USB_MOUSE_PROTOCOL (0x02U) - #define USB_MOUSE_INTERFACE_INDEX (0U) + #define USB_MOUSE_INTERFACE_INDEX (2U) #define USB_MOUSE_INTERFACE_COUNT (1U) #define USB_MOUSE_INTERFACE_ALTERNATE_SETTING (0U)