diff --git a/right/composite.c b/right/composite.c index 16b4247..9ea4791 100644 --- a/right/composite.c +++ b/right/composite.c @@ -35,7 +35,7 @@ usb_device_class_config_struct_t g_CompositeClassConfig[USB_COMPOSITE_INTERFACE_ { USB_DeviceHidMouseCallback, (class_handle_t)NULL, - &UsbDeviceMouseConfig, + &UsbDeviceMouseClass, } }; diff --git a/right/usb_device_descriptor.c b/right/usb_device_descriptor.c index 6650d88..dbe5e81 100644 --- a/right/usb_device_descriptor.c +++ b/right/usb_device_descriptor.c @@ -75,8 +75,8 @@ uint8_t UsbConfigurationDescriptor[USB_DESCRIPTOR_LENGTH_CONFIGURATION_ALL] = { 0x00U, // Country code of the localized hardware 0x01U, // Number of class descriptors (at least one report descriptor) USB_DESCRIPTOR_TYPE_HID_REPORT, - USB_SHORT_GET_LOW(USB_DESCRIPTOR_LENGTH_MOUSE_REPORT), - USB_SHORT_GET_HIGH(USB_DESCRIPTOR_LENGTH_MOUSE_REPORT), + USB_SHORT_GET_LOW(USB_MOUSE_REPORT_DESCRIPTOR_LENGTH), + USB_SHORT_GET_HIGH(USB_MOUSE_REPORT_DESCRIPTOR_LENGTH), // Mouse endpoint descriptor @@ -109,8 +109,8 @@ uint8_t UsbConfigurationDescriptor[USB_DESCRIPTOR_LENGTH_CONFIGURATION_ALL] = { 0x00U, // Country code of the localized hardware 0x01U, // Number of class descriptors (at least one report descriptor) USB_DESCRIPTOR_TYPE_HID_REPORT, - USB_SHORT_GET_LOW(USB_DESCRIPTOR_LENGTH_KEYBOARD_REPORT), - USB_SHORT_GET_HIGH(USB_DESCRIPTOR_LENGTH_KEYBOARD_REPORT), + USB_SHORT_GET_LOW(USB_KEYBOARD_REPORT_DESCRIPTOR_LENGTH), + USB_SHORT_GET_HIGH(USB_KEYBOARD_REPORT_DESCRIPTOR_LENGTH), // Keyboard endpoint descriptor @@ -122,7 +122,7 @@ uint8_t UsbConfigurationDescriptor[USB_DESCRIPTOR_LENGTH_CONFIGURATION_ALL] = { USB_SHORT_GET_LOW(USB_KEYBOARD_INTERRUPT_IN_PACKET_SIZE), USB_SHORT_GET_HIGH(USB_KEYBOARD_INTERRUPT_IN_PACKET_SIZE), // Maximum packet size this endpoint is capable of sending or receiving when this configuration is selected. - USB_KEYBOARD_INTERRUPT_IN_POLL_INTERVAL, + USB_KEYBOARD_INTERRUPT_IN_INTERVAL, }; uint8_t g_UsbDeviceString0[USB_DESCRIPTOR_LENGTH_STRING0] = { @@ -257,11 +257,11 @@ 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 = UsbDeviceMouseReportDescriptor; - hidReportDescriptor->length = USB_DESCRIPTOR_LENGTH_MOUSE_REPORT; + hidReportDescriptor->buffer = UsbMouseReportDescriptor; + hidReportDescriptor->length = USB_MOUSE_REPORT_DESCRIPTOR_LENGTH; } else if (USB_KEYBOARD_INTERFACE_INDEX == hidReportDescriptor->interfaceNumber) { hidReportDescriptor->buffer = UsbKeyboardReportDescriptor; - hidReportDescriptor->length = USB_DESCRIPTOR_LENGTH_KEYBOARD_REPORT; + hidReportDescriptor->length = USB_KEYBOARD_REPORT_DESCRIPTOR_LENGTH; } else { return kStatus_USB_InvalidRequest; } diff --git a/right/usb_keyboard_descriptors.c b/right/usb_keyboard_descriptors.c index f38787b..a1d4565 100644 --- a/right/usb_keyboard_descriptors.c +++ b/right/usb_keyboard_descriptors.c @@ -6,46 +6,31 @@ #include "usb_device_descriptor.h" #include "usb_keyboard_descriptors.h" -static usb_device_endpoint_struct_t UsbKeyboardEndpoints[USB_KEYBOARD_ENDPOINT_COUNT] = -{ - { - USB_KEYBOARD_ENDPOINT_IN | (USB_IN << USB_DESCRIPTOR_ENDPOINT_ADDRESS_DIRECTION_SHIFT), - USB_ENDPOINT_INTERRUPT, - USB_KEYBOARD_INTERRUPT_IN_PACKET_SIZE, - }, -}; +static usb_device_endpoint_struct_t UsbKeyboardEndpoints[USB_KEYBOARD_ENDPOINT_COUNT] = {{ + USB_KEYBOARD_ENDPOINT_IN | (USB_IN << USB_DESCRIPTOR_ENDPOINT_ADDRESS_DIRECTION_SHIFT), + USB_ENDPOINT_INTERRUPT, + USB_KEYBOARD_INTERRUPT_IN_PACKET_SIZE, +}}; -static usb_device_interface_struct_t UsbKeyboardInterface[] = -{ - { - USB_KEYBOARD_INTERFACE_ALTERNATE_SETTING, - { - USB_KEYBOARD_ENDPOINT_COUNT, - UsbKeyboardEndpoints, - }, - NULL, - } -}; +static usb_device_interface_struct_t UsbKeyboardInterface[] = {{ + USB_KEYBOARD_INTERFACE_ALTERNATE_SETTING, + {USB_KEYBOARD_ENDPOINT_COUNT, UsbKeyboardEndpoints}, + NULL, +}}; -static usb_device_interfaces_struct_t UsbKeyboardInterfaces[USB_KEYBOARD_INTERFACE_COUNT] = -{ - { - USB_KEYBOARD_CLASS, - USB_KEYBOARD_SUBCLASS, - USB_KEYBOARD_PROTOCOL, - USB_KEYBOARD_INTERFACE_INDEX, - UsbKeyboardInterface, - sizeof(UsbKeyboardInterface) / sizeof(usb_device_interfaces_struct_t), - }, -}; +static usb_device_interfaces_struct_t UsbKeyboardInterfaces[USB_KEYBOARD_INTERFACE_COUNT] = {{ + USB_KEYBOARD_CLASS, + USB_KEYBOARD_SUBCLASS, + USB_KEYBOARD_PROTOCOL, + USB_KEYBOARD_INTERFACE_INDEX, + UsbKeyboardInterface, + sizeof(UsbKeyboardInterface) / sizeof(usb_device_interfaces_struct_t), +}}; -static usb_device_interface_list_t UsbKeyboardInterfaceList[USB_DEVICE_CONFIGURATION_COUNT] = -{ - { - USB_KEYBOARD_INTERFACE_COUNT, - UsbKeyboardInterfaces, - }, -}; +static usb_device_interface_list_t UsbKeyboardInterfaceList[USB_DEVICE_CONFIGURATION_COUNT] = {{ + USB_KEYBOARD_INTERFACE_COUNT, + UsbKeyboardInterfaces, +}}; usb_device_class_struct_t UsbKeyboardClass = { UsbKeyboardInterfaceList, @@ -53,7 +38,7 @@ usb_device_class_struct_t UsbKeyboardClass = { USB_DEVICE_CONFIGURATION_COUNT, }; -uint8_t UsbKeyboardReportDescriptor[USB_DESCRIPTOR_LENGTH_KEYBOARD_REPORT] = { +uint8_t UsbKeyboardReportDescriptor[USB_KEYBOARD_REPORT_DESCRIPTOR_LENGTH] = { 0x05U, 0x01U, // Usage Page (Generic Desktop) 0x09U, 0x06U, // Usage (Keyboard) 0xA1U, 0x01U, // Collection (Application) diff --git a/right/usb_keyboard_descriptors.h b/right/usb_keyboard_descriptors.h index ad65829..76645b7 100644 --- a/right/usb_keyboard_descriptors.h +++ b/right/usb_keyboard_descriptors.h @@ -3,25 +3,28 @@ // Macros: - #define USB_KEYBOARD_INTERFACE_COUNT (1U) - #define USB_DESCRIPTOR_LENGTH_KEYBOARD_REPORT (63U) - #define USB_KEYBOARD_STRING_DESCRIPTOR_LENGTH (40U) - #define USB_KEYBOARD_INTERFACE_ALTERNATE_SETTING (0U) - #define USB_KEYBOARD_ENDPOINT_IN (2U) - #define USB_KEYBOARD_INTERRUPT_IN_PACKET_SIZE (8U) - #define USB_KEYBOARD_ENDPOINT_COUNT (1U) #define USB_KEYBOARD_CLASS (0x03U) #define USB_KEYBOARD_SUBCLASS (0x01U) #define USB_KEYBOARD_PROTOCOL (0x01U) + #define USB_KEYBOARD_INTERFACE_INDEX (1U) - #define USB_KEYBOARD_IN_BUFFER_LENGTH (8U) - #define USB_KEYBOARD_INTERRUPT_IN_POLL_INTERVAL (0x04U) + #define USB_KEYBOARD_INTERFACE_COUNT (1U) + #define USB_KEYBOARD_INTERFACE_ALTERNATE_SETTING (0U) + + #define USB_KEYBOARD_ENDPOINT_IN (2U) + #define USB_KEYBOARD_ENDPOINT_COUNT (1U) + + #define USB_KEYBOARD_INTERRUPT_IN_PACKET_SIZE (8U) + #define USB_KEYBOARD_INTERRUPT_IN_INTERVAL (0x04U) + #define USB_KEYBOARD_REPORT_LENGTH (0x08U) + #define USB_KEYBOARD_REPORT_DESCRIPTOR_LENGTH (63U) + #define USB_KEYBOARD_STRING_DESCRIPTOR_LENGTH (40U) // Variables: - extern uint8_t UsbKeyboardString[USB_KEYBOARD_STRING_DESCRIPTOR_LENGTH]; extern usb_device_class_struct_t UsbKeyboardClass; - extern uint8_t UsbKeyboardReportDescriptor[USB_DESCRIPTOR_LENGTH_KEYBOARD_REPORT]; + extern uint8_t UsbKeyboardReportDescriptor[USB_KEYBOARD_REPORT_DESCRIPTOR_LENGTH]; + extern uint8_t UsbKeyboardString[USB_KEYBOARD_STRING_DESCRIPTOR_LENGTH]; #endif diff --git a/right/usb_mouse_descriptors.c b/right/usb_mouse_descriptors.c index 3b30d9b..54848c3 100644 --- a/right/usb_mouse_descriptors.c +++ b/right/usb_mouse_descriptors.c @@ -8,54 +8,39 @@ #include "hid_mouse.h" #include "hid_keyboard.h" -static usb_device_endpoint_struct_t g_UsbDeviceHidMouseEndpoints[USB_MOUSE_ENDPOINT_COUNT] = -{ - { - USB_MOUSE_ENDPOINT_IN | (USB_IN << USB_DESCRIPTOR_ENDPOINT_ADDRESS_DIRECTION_SHIFT), - USB_ENDPOINT_INTERRUPT, - USB_MOUSE_INTERRUPT_IN_PACKET_SIZE, - }, -}; +static usb_device_endpoint_struct_t UsbMouseEndpoints[USB_MOUSE_ENDPOINT_COUNT] = {{ + USB_MOUSE_ENDPOINT_IN | (USB_IN << USB_DESCRIPTOR_ENDPOINT_ADDRESS_DIRECTION_SHIFT), + USB_ENDPOINT_INTERRUPT, + USB_MOUSE_INTERRUPT_IN_PACKET_SIZE, +}}; -static usb_device_interface_struct_t g_UsbDeviceHidMouseInterface[] = -{ - { - USB_MOUSE_INTERFACE_ALTERNATE_SETTING, - { - USB_MOUSE_ENDPOINT_COUNT, - g_UsbDeviceHidMouseEndpoints, - }, - NULL, - } -}; +static usb_device_interface_struct_t UsbMouseInterface[] = {{ + USB_MOUSE_INTERFACE_ALTERNATE_SETTING, + {USB_MOUSE_ENDPOINT_COUNT, UsbMouseEndpoints}, + NULL, +}}; -static usb_device_interfaces_struct_t g_UsbDeviceHidMouseInterfaces[USB_MOUSE_INTERFACE_COUNT] = -{ - { - USB_MOUSE_CLASS, - USB_MOUSE_SUBCLASS, - USB_MOUSE_PROTOCOL, - USB_MOUSE_INTERFACE_INDEX, - g_UsbDeviceHidMouseInterface, - sizeof(g_UsbDeviceHidMouseInterface) / sizeof(usb_device_interfaces_struct_t), - }, -}; +static usb_device_interfaces_struct_t UsbMouseInterfaces[USB_MOUSE_INTERFACE_COUNT] = {{ + USB_MOUSE_CLASS, + USB_MOUSE_SUBCLASS, + USB_MOUSE_PROTOCOL, + USB_MOUSE_INTERFACE_INDEX, + UsbMouseInterface, + sizeof(UsbMouseInterface) / sizeof(usb_device_interfaces_struct_t), +}}; -static usb_device_interface_list_t g_UsbDeviceHidMouseInterfaceList[USB_DEVICE_CONFIGURATION_COUNT] = -{ - { - USB_MOUSE_INTERFACE_COUNT, - g_UsbDeviceHidMouseInterfaces, - }, -}; +static usb_device_interface_list_t UsbMouseInterfaceList[USB_DEVICE_CONFIGURATION_COUNT] = {{ + USB_MOUSE_INTERFACE_COUNT, + UsbMouseInterfaces, +}}; -usb_device_class_struct_t UsbDeviceMouseConfig = { - g_UsbDeviceHidMouseInterfaceList, +usb_device_class_struct_t UsbDeviceMouseClass = { + UsbMouseInterfaceList, kUSB_DeviceClassTypeHid, USB_DEVICE_CONFIGURATION_COUNT, }; -uint8_t UsbDeviceMouseReportDescriptor[USB_DESCRIPTOR_LENGTH_MOUSE_REPORT] = { +uint8_t UsbMouseReportDescriptor[USB_MOUSE_REPORT_DESCRIPTOR_LENGTH] = { 0x05U, 0x01U, // Usage Page (Generic Desktop) 0x09U, 0x02U, // Usage (Mouse) 0xA1U, 0x01U, // Collection (Application) diff --git a/right/usb_mouse_descriptors.h b/right/usb_mouse_descriptors.h index dc6e1e3..2f7b084 100644 --- a/right/usb_mouse_descriptors.h +++ b/right/usb_mouse_descriptors.h @@ -3,29 +3,28 @@ // Macros: - #define USB_MOUSE_INTERFACE_COUNT (1U) - #define USB_MOUSE_INTERFACE_INDEX (0U) - #define USB_MOUSE_IN_BUFFER_LENGTH (8U) - #define USB_MOUSE_ENDPOINT_COUNT (1U) - #define USB_MOUSE_ENDPOINT_IN (1U) - #define USB_MOUSE_INTERFACE_ALTERNATE_SETTING (0U) - - #define USB_MOUSE_REPORT_LENGTH (0x04U) - #define USB_MOUSE_CLASS (0x03U) #define USB_MOUSE_SUBCLASS (0x01U) #define USB_MOUSE_PROTOCOL (0x02U) + #define USB_MOUSE_INTERFACE_INDEX (0U) + #define USB_MOUSE_INTERFACE_COUNT (1U) + #define USB_MOUSE_INTERFACE_ALTERNATE_SETTING (0U) + + #define USB_MOUSE_ENDPOINT_IN (1U) + #define USB_MOUSE_ENDPOINT_COUNT (1U) + #define USB_MOUSE_INTERRUPT_IN_PACKET_SIZE (8U) #define USB_MOUSE_INTERRUPT_IN_INTERVAL (0x04U) - #define USB_DESCRIPTOR_LENGTH_MOUSE_REPORT (52U) + #define USB_MOUSE_REPORT_LENGTH (0x04U) + #define USB_MOUSE_REPORT_DESCRIPTOR_LENGTH (52U) #define USB_MOUSE_STRING_DESCRIPTOR_LENGTH (34U) // Variables: - extern usb_device_class_struct_t UsbDeviceMouseConfig; - extern uint8_t UsbDeviceMouseReportDescriptor[USB_DESCRIPTOR_LENGTH_MOUSE_REPORT]; + extern usb_device_class_struct_t UsbDeviceMouseClass; + extern uint8_t UsbMouseReportDescriptor[USB_MOUSE_REPORT_DESCRIPTOR_LENGTH]; extern uint8_t UsbMouseString[USB_MOUSE_STRING_DESCRIPTOR_LENGTH]; #endif