diff --git a/right/src/usb_composite_device.c b/right/src/usb_composite_device.c index b7f7829..b848834 100644 --- a/right/src/usb_composite_device.c +++ b/right/src/usb_composite_device.c @@ -11,9 +11,9 @@ usb_composite_device_t UsbCompositeDevice; usb_device_class_config_struct_t UsbDeviceCompositeClassConfig[USB_DEVICE_CONFIG_HID] = { {UsbGenericHidCallback, (class_handle_t)NULL, &UsbGenericHidClass}, {UsbBasicKeyboardCallback, (class_handle_t)NULL, &UsbBasicKeyboardClass}, - {UsbMouseCallback, (class_handle_t)NULL, &UsbMouseClass}, {UsbMediaKeyboardCallback, (class_handle_t)NULL, &UsbMediaKeyboardClass}, {UsbSystemKeyboardCallback, (class_handle_t)NULL, &UsbSystemKeyboardClass}, + {UsbMouseCallback, (class_handle_t)NULL, &UsbMouseClass}, }; usb_device_class_config_list_struct_t UsbDeviceCompositeConfigList = { @@ -42,9 +42,9 @@ static usb_status_t UsbDeviceCallback(usb_device_handle handle, uint32_t event, UsbCompositeDevice.currentConfiguration = *temp8; UsbGenericHidSetConfiguration(UsbCompositeDevice.genericHidHandle, *temp8); UsbBasicKeyboardSetConfiguration(UsbCompositeDevice.basicKeyboardHandle, *temp8); - UsbMouseSetConfiguration(UsbCompositeDevice.mouseHandle, *temp8); UsbMediaKeyboardSetConfiguration(UsbCompositeDevice.mediaKeyboardHandle, *temp8); UsbSystemKeyboardSetConfiguration(UsbCompositeDevice.systemKeyboardHandle, *temp8); + UsbMouseSetConfiguration(UsbCompositeDevice.mouseHandle, *temp8); error = kStatus_USB_Success; break; case kUSB_DeviceEventGetConfiguration: @@ -59,9 +59,9 @@ static usb_status_t UsbDeviceCallback(usb_device_handle handle, uint32_t event, UsbCompositeDevice.currentInterfaceAlternateSetting[interface] = alternateSetting; UsbGenericHidSetInterface(UsbCompositeDevice.genericHidHandle, interface, alternateSetting); UsbBasicKeyboardSetInterface(UsbCompositeDevice.basicKeyboardHandle, interface, alternateSetting); - UsbMouseSetInterface(UsbCompositeDevice.mouseHandle, interface, alternateSetting); UsbMediaKeyboardSetInterface(UsbCompositeDevice.mediaKeyboardHandle, interface, alternateSetting); UsbSystemKeyboardSetInterface(UsbCompositeDevice.systemKeyboardHandle, interface, alternateSetting); + UsbMouseSetInterface(UsbCompositeDevice.mouseHandle, interface, alternateSetting); error = kStatus_USB_Success; } } @@ -117,9 +117,9 @@ void InitUsb(void) USB_DeviceClassInit(CONTROLLER_ID, &UsbDeviceCompositeConfigList, &UsbCompositeDevice.deviceHandle); UsbCompositeDevice.genericHidHandle = UsbDeviceCompositeConfigList.config[USB_GENERIC_HID_INTERFACE_INDEX].classHandle; UsbCompositeDevice.basicKeyboardHandle = UsbDeviceCompositeConfigList.config[USB_BASIC_KEYBOARD_INTERFACE_INDEX].classHandle; - UsbCompositeDevice.mouseHandle = UsbDeviceCompositeConfigList.config[USB_MOUSE_INTERFACE_INDEX].classHandle; UsbCompositeDevice.mediaKeyboardHandle = UsbDeviceCompositeConfigList.config[USB_MEDIA_KEYBOARD_INTERFACE_INDEX].classHandle; UsbCompositeDevice.systemKeyboardHandle = UsbDeviceCompositeConfigList.config[USB_SYSTEM_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/src/usb_descriptors/usb_descriptor_configuration.c b/right/src/usb_descriptors/usb_descriptor_configuration.c index 91017b6..175aaa1 100644 --- a/right/src/usb_descriptors/usb_descriptor_configuration.c +++ b/right/src/usb_descriptors/usb_descriptor_configuration.c @@ -89,37 +89,6 @@ uint8_t UsbConfigurationDescriptor[USB_CONFIGURATION_DESCRIPTOR_TOTAL_LENGTH] = USB_SHORT_GET_HIGH(USB_BASIC_KEYBOARD_INTERRUPT_IN_PACKET_SIZE), USB_BASIC_KEYBOARD_INTERRUPT_IN_INTERVAL, - // Mouse interface descriptor - USB_DESCRIPTOR_LENGTH_INTERFACE, - USB_DESCRIPTOR_TYPE_INTERFACE, - USB_MOUSE_INTERFACE_INDEX, - USB_INTERFACE_ALTERNATE_SETTING_NONE, - USB_MOUSE_ENDPOINT_COUNT, - USB_CLASS_HID, - USB_HID_SUBCLASS_BOOT, - USB_HID_PROTOCOL_MOUSE, - USB_STRING_DESCRIPTOR_NONE, - - // Mouse HID descriptor - USB_DESCRIPTOR_LENGTH_HID, - USB_DESCRIPTOR_TYPE_HID, - USB_SHORT_GET_LOW(USB_HID_VERSION), - USB_SHORT_GET_HIGH(USB_HID_VERSION), - USB_HID_COUNTRY_CODE_NOT_SUPPORTED, - USB_REPORT_DESCRIPTOR_COUNT_PER_HID_DEVICE, - USB_DESCRIPTOR_TYPE_HID_REPORT, - USB_SHORT_GET_LOW(USB_MOUSE_REPORT_DESCRIPTOR_LENGTH), - USB_SHORT_GET_HIGH(USB_MOUSE_REPORT_DESCRIPTOR_LENGTH), - - // Mouse endpoint descriptor - USB_DESCRIPTOR_LENGTH_ENDPOINT, - USB_DESCRIPTOR_TYPE_ENDPOINT, - USB_MOUSE_ENDPOINT_INDEX | (USB_IN << USB_DESCRIPTOR_ENDPOINT_ADDRESS_DIRECTION_SHIFT), - USB_ENDPOINT_INTERRUPT, - USB_SHORT_GET_LOW(USB_MOUSE_INTERRUPT_IN_PACKET_SIZE), - USB_SHORT_GET_HIGH(USB_MOUSE_INTERRUPT_IN_PACKET_SIZE), - USB_MOUSE_INTERRUPT_IN_INTERVAL, - // Media keyboard interface descriptor USB_DESCRIPTOR_LENGTH_INTERFACE, USB_DESCRIPTOR_TYPE_INTERFACE, @@ -181,6 +150,37 @@ uint8_t UsbConfigurationDescriptor[USB_CONFIGURATION_DESCRIPTOR_TOTAL_LENGTH] = USB_SHORT_GET_LOW(USB_SYSTEM_KEYBOARD_INTERRUPT_IN_PACKET_SIZE), USB_SHORT_GET_HIGH(USB_SYSTEM_KEYBOARD_INTERRUPT_IN_PACKET_SIZE), USB_SYSTEM_KEYBOARD_INTERRUPT_IN_INTERVAL, + + // Mouse interface descriptor + USB_DESCRIPTOR_LENGTH_INTERFACE, + USB_DESCRIPTOR_TYPE_INTERFACE, + USB_MOUSE_INTERFACE_INDEX, + USB_INTERFACE_ALTERNATE_SETTING_NONE, + USB_MOUSE_ENDPOINT_COUNT, + USB_CLASS_HID, + USB_HID_SUBCLASS_BOOT, + USB_HID_PROTOCOL_MOUSE, + USB_STRING_DESCRIPTOR_NONE, + + // Mouse HID descriptor + USB_DESCRIPTOR_LENGTH_HID, + USB_DESCRIPTOR_TYPE_HID, + USB_SHORT_GET_LOW(USB_HID_VERSION), + USB_SHORT_GET_HIGH(USB_HID_VERSION), + USB_HID_COUNTRY_CODE_NOT_SUPPORTED, + USB_REPORT_DESCRIPTOR_COUNT_PER_HID_DEVICE, + USB_DESCRIPTOR_TYPE_HID_REPORT, + USB_SHORT_GET_LOW(USB_MOUSE_REPORT_DESCRIPTOR_LENGTH), + USB_SHORT_GET_HIGH(USB_MOUSE_REPORT_DESCRIPTOR_LENGTH), + + // Mouse endpoint descriptor + USB_DESCRIPTOR_LENGTH_ENDPOINT, + USB_DESCRIPTOR_TYPE_ENDPOINT, + USB_MOUSE_ENDPOINT_INDEX | (USB_IN << USB_DESCRIPTOR_ENDPOINT_ADDRESS_DIRECTION_SHIFT), + USB_ENDPOINT_INTERRUPT, + USB_SHORT_GET_LOW(USB_MOUSE_INTERRUPT_IN_PACKET_SIZE), + USB_SHORT_GET_HIGH(USB_MOUSE_INTERRUPT_IN_PACKET_SIZE), + USB_MOUSE_INTERRUPT_IN_INTERVAL, }; usb_status_t USB_DeviceGetConfigurationDescriptor( diff --git a/right/src/usb_descriptors/usb_descriptor_hid.c b/right/src/usb_descriptors/usb_descriptor_hid.c index 85682d6..18c005f 100644 --- a/right/src/usb_descriptors/usb_descriptor_hid.c +++ b/right/src/usb_descriptors/usb_descriptor_hid.c @@ -12,9 +12,9 @@ usb_status_t USB_DeviceGetHidDescriptor( usb_status_t USB_DeviceGetHidReportDescriptor( usb_device_handle handle, usb_device_get_hid_report_descriptor_struct_t *hidReportDescriptor) { - if (USB_MOUSE_INTERFACE_INDEX == hidReportDescriptor->interfaceNumber) { - hidReportDescriptor->buffer = UsbMouseReportDescriptor; - hidReportDescriptor->length = USB_MOUSE_REPORT_DESCRIPTOR_LENGTH; + if (USB_GENERIC_HID_INTERFACE_INDEX == hidReportDescriptor->interfaceNumber) { + hidReportDescriptor->buffer = UsbGenericHidReportDescriptor; + hidReportDescriptor->length = USB_GENERIC_HID_REPORT_DESCRIPTOR_LENGTH; } else if (USB_BASIC_KEYBOARD_INTERFACE_INDEX == hidReportDescriptor->interfaceNumber) { hidReportDescriptor->buffer = UsbBasicKeyboardReportDescriptor; hidReportDescriptor->length = USB_BASIC_KEYBOARD_REPORT_DESCRIPTOR_LENGTH; @@ -24,9 +24,9 @@ usb_status_t USB_DeviceGetHidReportDescriptor( } else if (USB_SYSTEM_KEYBOARD_INTERFACE_INDEX == hidReportDescriptor->interfaceNumber) { hidReportDescriptor->buffer = UsbSystemKeyboardReportDescriptor; hidReportDescriptor->length = USB_MEDIA_KEYBOARD_REPORT_DESCRIPTOR_LENGTH; - } else if (USB_GENERIC_HID_INTERFACE_INDEX == hidReportDescriptor->interfaceNumber) { - hidReportDescriptor->buffer = UsbGenericHidReportDescriptor; - hidReportDescriptor->length = USB_GENERIC_HID_REPORT_DESCRIPTOR_LENGTH; + } else if (USB_MOUSE_INTERFACE_INDEX == hidReportDescriptor->interfaceNumber) { + hidReportDescriptor->buffer = UsbMouseReportDescriptor; + hidReportDescriptor->length = USB_MOUSE_REPORT_DESCRIPTOR_LENGTH; } else { return kStatus_USB_InvalidRequest; } diff --git a/right/src/usb_interfaces/usb_interface_media_keyboard.h b/right/src/usb_interfaces/usb_interface_media_keyboard.h index 410be13..e4c9064 100644 --- a/right/src/usb_interfaces/usb_interface_media_keyboard.h +++ b/right/src/usb_interfaces/usb_interface_media_keyboard.h @@ -9,10 +9,10 @@ // Macros: - #define USB_MEDIA_KEYBOARD_INTERFACE_INDEX 3 + #define USB_MEDIA_KEYBOARD_INTERFACE_INDEX 2 #define USB_MEDIA_KEYBOARD_INTERFACE_COUNT 1 - #define USB_MEDIA_KEYBOARD_ENDPOINT_INDEX 5 + #define USB_MEDIA_KEYBOARD_ENDPOINT_INDEX 4 #define USB_MEDIA_KEYBOARD_ENDPOINT_COUNT 1 #define USB_MEDIA_KEYBOARD_INTERRUPT_IN_PACKET_SIZE 8 diff --git a/right/src/usb_interfaces/usb_interface_mouse.h b/right/src/usb_interfaces/usb_interface_mouse.h index c79a124..4f8b05c 100644 --- a/right/src/usb_interfaces/usb_interface_mouse.h +++ b/right/src/usb_interfaces/usb_interface_mouse.h @@ -8,10 +8,10 @@ // Macros: - #define USB_MOUSE_INTERFACE_INDEX 2 + #define USB_MOUSE_INTERFACE_INDEX 4 #define USB_MOUSE_INTERFACE_COUNT 1 - #define USB_MOUSE_ENDPOINT_INDEX 4 + #define USB_MOUSE_ENDPOINT_INDEX 6 #define USB_MOUSE_ENDPOINT_COUNT 1 #define USB_MOUSE_INTERRUPT_IN_PACKET_SIZE 8 diff --git a/right/src/usb_interfaces/usb_interface_system_keyboard.h b/right/src/usb_interfaces/usb_interface_system_keyboard.h index 59592e4..7dc8108 100644 --- a/right/src/usb_interfaces/usb_interface_system_keyboard.h +++ b/right/src/usb_interfaces/usb_interface_system_keyboard.h @@ -10,10 +10,10 @@ // Macros: - #define USB_SYSTEM_KEYBOARD_INTERFACE_INDEX 4 + #define USB_SYSTEM_KEYBOARD_INTERFACE_INDEX 3 #define USB_SYSTEM_KEYBOARD_INTERFACE_COUNT 1 - #define USB_SYSTEM_KEYBOARD_ENDPOINT_INDEX 6 + #define USB_SYSTEM_KEYBOARD_ENDPOINT_INDEX 5 #define USB_SYSTEM_KEYBOARD_ENDPOINT_COUNT 1 #define USB_SYSTEM_KEYBOARD_INTERRUPT_IN_PACKET_SIZE 1