diff --git a/right/hid_keyboard.c b/right/hid_keyboard.c index f0b6378..adb7a29 100644 --- a/right/hid_keyboard.c +++ b/right/hid_keyboard.c @@ -39,7 +39,7 @@ static usb_status_t UsbKeyboardAction(void) default: break; } - return USB_DeviceHidSend(UsbCompositeDevice->hidKeyboardHandle, USB_KEYBOARD_ENDPOINT_IN, + return USB_DeviceHidSend(UsbCompositeDevice->hidKeyboardHandle, USB_KEYBOARD_ENDPOINT_ID, UsbKeyboardDevice.buffer, USB_KEYBOARD_REPORT_LENGTH); } @@ -72,7 +72,7 @@ usb_status_t UsbKeyboardCallback(class_handle_t handle, uint32_t event, void *pa usb_status_t UsbKeyboardSetConfigure(class_handle_t handle, uint8_t configure) { - if (USB_COMPOSITE_CONFIGURE_INDEX == configure) { + if (USB_COMPOSITE_CONFIGURATION_INDEX == configure) { return UsbKeyboardAction(); } return kStatus_USB_Error; diff --git a/right/hid_mouse.c b/right/hid_mouse.c index 8cd4029..cf576eb 100644 --- a/right/hid_mouse.c +++ b/right/hid_mouse.c @@ -65,7 +65,7 @@ static usb_status_t UsbMouseAction(void) break; } - return USB_DeviceHidSend(UsbCompositeDevice->hidMouseHandle, USB_MOUSE_ENDPOINT_IN, + return USB_DeviceHidSend(UsbCompositeDevice->hidMouseHandle, USB_MOUSE_ENDPOINT_ID, UsbMouseDevice.buffer, USB_MOUSE_REPORT_LENGTH); } @@ -99,7 +99,7 @@ usb_status_t UsbMouseCallback(class_handle_t handle, uint32_t event, void *param usb_status_t UsbMouseSetConfigure(class_handle_t handle, uint8_t configure) { - if (USB_COMPOSITE_CONFIGURE_INDEX == configure) { + if (USB_COMPOSITE_CONFIGURATION_INDEX == configure) { return UsbMouseAction(); } return kStatus_USB_Error; diff --git a/right/usb_device_descriptor.c b/right/usb_device_descriptor.c index a2eefa0..bd16841 100644 --- a/right/usb_device_descriptor.c +++ b/right/usb_device_descriptor.c @@ -30,29 +30,20 @@ uint8_t UsbDeviceDescriptor[USB_DESCRIPTOR_LENGTH_DEVICE] = { USB_DEVICE_CONFIGURATION_COUNT, }; -uint8_t UsbConfigurationDescriptor[USB_DESCRIPTOR_LENGTH_CONFIGURATION_ALL] = { +uint8_t UsbConfigurationDescriptor[USB_CONFIGURATION_DESCRIPTOR_TOTAL_LENGTH] = { // Configuration descriptor USB_DESCRIPTOR_LENGTH_CONFIGURE, USB_DESCRIPTOR_TYPE_CONFIGURE, - USB_SHORT_GET_LOW(USB_DESCRIPTOR_LENGTH_CONFIGURATION_ALL), - USB_SHORT_GET_HIGH(USB_DESCRIPTOR_LENGTH_CONFIGURATION_ALL), // Total length of data returned for this configuration. + USB_SHORT_GET_LOW(USB_CONFIGURATION_DESCRIPTOR_TOTAL_LENGTH), + USB_SHORT_GET_HIGH(USB_CONFIGURATION_DESCRIPTOR_TOTAL_LENGTH), USB_COMPOSITE_INTERFACE_COUNT, - USB_COMPOSITE_CONFIGURE_INDEX, // Value to use as an argument to the SetConfiguration() request to select this configuration - 0x00U, // Index of string descriptor describing this configuration - - // Configuration characteristics - // D7: Reserved (set to one) - // D6: Self-powered - // D5: Remote Wakeup - // D4...0: Reserved (reset to zero) + USB_COMPOSITE_CONFIGURATION_INDEX, + USB_STRING_DESCRIPTOR_NONE, (USB_DESCRIPTOR_CONFIGURE_ATTRIBUTE_D7_MASK) | (USB_DEVICE_CONFIG_SELF_POWER << USB_DESCRIPTOR_CONFIGURE_ATTRIBUTE_SELF_POWERED_SHIFT) | (USB_DEVICE_CONFIG_REMOTE_WAKEUP << USB_DESCRIPTOR_CONFIGURE_ATTRIBUTE_REMOTE_WAKEUP_SHIFT), - - // Maximum power consumption of the USB device from the bus in this specific configuration - // when the device is fully operational. Expressed in 2 mA units (i.e., 50 = 100 mA). USB_DEVICE_MAX_POWER, // Mouse interface descriptor @@ -60,7 +51,7 @@ uint8_t UsbConfigurationDescriptor[USB_DESCRIPTOR_LENGTH_CONFIGURATION_ALL] = { USB_DESCRIPTOR_LENGTH_INTERFACE, USB_DESCRIPTOR_TYPE_INTERFACE, USB_MOUSE_INTERFACE_INDEX, - 0x00U, // Value used to select this alternate setting for the interface identified in the prior field + USB_INTERFACE_ALTERNATE_SETTING, USB_MOUSE_ENDPOINT_COUNT, USB_MOUSE_CLASS, USB_MOUSE_SUBCLASS, @@ -71,9 +62,10 @@ uint8_t UsbConfigurationDescriptor[USB_DESCRIPTOR_LENGTH_CONFIGURATION_ALL] = { USB_DESCRIPTOR_LENGTH_HID, USB_DESCRIPTOR_TYPE_HID, - 0x00U, 0x01U, // ID Class Specification release. - 0x00U, // Country code of the localized hardware - 0x01U, // Number of class descriptors (at least one report descriptor) + 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), @@ -82,19 +74,18 @@ uint8_t UsbConfigurationDescriptor[USB_DESCRIPTOR_LENGTH_CONFIGURATION_ALL] = { USB_DESCRIPTOR_LENGTH_ENDPOINT, USB_DESCRIPTOR_TYPE_ENDPOINT, - // The address of the endpoint on the USB device described by this descriptor. - USB_MOUSE_ENDPOINT_IN | (USB_IN << USB_DESCRIPTOR_ENDPOINT_ADDRESS_DIRECTION_SHIFT), - USB_ENDPOINT_INTERRUPT, // This field describes the endpoint's attributes - // Maximum packet size this endpoint is capable of sending or receiving when this configuration is selected. - 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, // Interval for polling endpoint for data transfers. + USB_MOUSE_ENDPOINT_ID | (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, // Keyboard interface descriptor USB_DESCRIPTOR_LENGTH_INTERFACE, USB_DESCRIPTOR_TYPE_INTERFACE, USB_KEYBOARD_INTERFACE_INDEX, - 0x00U, // Value used to select this alternate setting for the interface identified in the prior field + USB_INTERFACE_ALTERNATE_SETTING, USB_KEYBOARD_ENDPOINT_COUNT, USB_KEYBOARD_CLASS, USB_KEYBOARD_SUBCLASS, @@ -105,9 +96,10 @@ uint8_t UsbConfigurationDescriptor[USB_DESCRIPTOR_LENGTH_CONFIGURATION_ALL] = { USB_DESCRIPTOR_LENGTH_HID, USB_DESCRIPTOR_TYPE_HID, - 0x00U, 0x01U, // HID Class Specification release - 0x00U, // Country code of the localized hardware - 0x01U, // Number of class descriptors (at least one report descriptor) + 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_KEYBOARD_REPORT_DESCRIPTOR_LENGTH), USB_SHORT_GET_HIGH(USB_KEYBOARD_REPORT_DESCRIPTOR_LENGTH), @@ -116,16 +108,14 @@ uint8_t UsbConfigurationDescriptor[USB_DESCRIPTOR_LENGTH_CONFIGURATION_ALL] = { USB_DESCRIPTOR_LENGTH_ENDPOINT, USB_DESCRIPTOR_TYPE_ENDPOINT, - USB_KEYBOARD_ENDPOINT_IN | (USB_IN << USB_DESCRIPTOR_ENDPOINT_ADDRESS_DIRECTION_SHIFT), - // The address of the endpoint on the USB device described by this descriptor. - USB_ENDPOINT_INTERRUPT, // This field describes the endpoint's attributes + USB_KEYBOARD_ENDPOINT_ID | (USB_IN << USB_DESCRIPTOR_ENDPOINT_ADDRESS_DIRECTION_SHIFT), + USB_ENDPOINT_INTERRUPT, 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_INTERVAL, }; -uint8_t UsbLanguageListStringDescriptor[USB_DESCRIPTOR_LENGTH_STRING0] = { +uint8_t UsbLanguageListStringDescriptor[USB_LANGUAGE_LIST_STRING_DESCRIPTOR_LENGTH] = { sizeof(UsbLanguageListStringDescriptor), USB_DESCRIPTOR_TYPE_STRING, GET_LSB_OF_WORD(USB_LANGUAGE_ID_UNITED_STATES), @@ -213,9 +203,9 @@ usb_status_t USB_DeviceGetDeviceDescriptor( usb_status_t USB_DeviceGetConfigurationDescriptor( usb_device_handle handle, usb_device_get_configuration_descriptor_struct_t *configurationDescriptor) { - if (USB_COMPOSITE_CONFIGURE_INDEX > configurationDescriptor->configuration) { + if (USB_COMPOSITE_CONFIGURATION_INDEX > configurationDescriptor->configuration) { configurationDescriptor->buffer = UsbConfigurationDescriptor; - configurationDescriptor->length = USB_DESCRIPTOR_LENGTH_CONFIGURATION_ALL; + configurationDescriptor->length = USB_CONFIGURATION_DESCRIPTOR_TOTAL_LENGTH; return kStatus_USB_Success; } return kStatus_USB_InvalidRequest; diff --git a/right/usb_device_descriptor.h b/right/usb_device_descriptor.h index 9cce6b6..d799004 100644 --- a/right/usb_device_descriptor.h +++ b/right/usb_device_descriptor.h @@ -20,11 +20,11 @@ #define USB_DEVICE_SUBCLASS (0x00U) #define USB_DEVICE_PROTOCOL (0x00U) - #define USB_DEVICE_MAX_POWER (0x32U) + #define USB_DEVICE_MAX_POWER (50U) // Expressed in 2 mA units (2*50 = 100 mA) - #define USB_DESCRIPTOR_LENGTH_CONFIGURATION_ALL (59U) + #define USB_CONFIGURATION_DESCRIPTOR_TOTAL_LENGTH (59U) #define USB_DESCRIPTOR_LENGTH_HID (9U) - #define USB_DESCRIPTOR_LENGTH_STRING0 (4U) + #define USB_LANGUAGE_LIST_STRING_DESCRIPTOR_LENGTH (4U) #define USB_MANUFACTURER_STRING_DESCRIPTOR_LENGTH (58U) #define USB_PRODUCT_STRING_DESCRIPTOR_LENGTH (34U) @@ -32,13 +32,18 @@ #define USB_STRING_DESCRIPTOR_COUNT (5U) #define USB_DEVICE_LANGUAGE_COUNT (1U) + #define USB_STRING_DESCRIPTOR_NONE 0x00U #define USB_STRING_DESCRIPTOR_ID_SERIAL_NUMBER 0x00U #define USB_STRING_DESCRIPTOR_ID_MANUFACTURER 0x01U #define USB_STRING_DESCRIPTOR_ID_PRODUCT 0x02U #define USB_STRING_DESCRIPTOR_ID_MOUSE 0x03U #define USB_STRING_DESCRIPTOR_ID_KEYBOARD 0x04U - #define USB_COMPOSITE_CONFIGURE_INDEX (1U) + #define USB_COMPOSITE_CONFIGURATION_INDEX (1U) + #define USB_HID_COUNTRY_CODE_NOT_SUPPORTED (0x00U) + #define USB_REPORT_DESCRIPTOR_COUNT_PER_HID_DEVICE (0X01U) + #define USB_HID_VERSION (0x0100U) + #define USB_INTERFACE_ALTERNATE_SETTING (0x00U) #define USB_COMPOSITE_INTERFACE_COUNT (USB_KEYBOARD_INTERFACE_COUNT + USB_MOUSE_INTERFACE_COUNT) diff --git a/right/usb_keyboard_descriptors.c b/right/usb_keyboard_descriptors.c index f8c119f..424fe35 100644 --- a/right/usb_keyboard_descriptors.c +++ b/right/usb_keyboard_descriptors.c @@ -7,7 +7,7 @@ #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_KEYBOARD_ENDPOINT_ID | (USB_IN << USB_DESCRIPTOR_ENDPOINT_ADDRESS_DIRECTION_SHIFT), USB_ENDPOINT_INTERRUPT, USB_KEYBOARD_INTERRUPT_IN_PACKET_SIZE, }}; diff --git a/right/usb_keyboard_descriptors.h b/right/usb_keyboard_descriptors.h index 76645b7..5344c32 100644 --- a/right/usb_keyboard_descriptors.h +++ b/right/usb_keyboard_descriptors.h @@ -11,7 +11,7 @@ #define USB_KEYBOARD_INTERFACE_COUNT (1U) #define USB_KEYBOARD_INTERFACE_ALTERNATE_SETTING (0U) - #define USB_KEYBOARD_ENDPOINT_IN (2U) + #define USB_KEYBOARD_ENDPOINT_ID (2U) #define USB_KEYBOARD_ENDPOINT_COUNT (1U) #define USB_KEYBOARD_INTERRUPT_IN_PACKET_SIZE (8U) diff --git a/right/usb_mouse_descriptors.c b/right/usb_mouse_descriptors.c index c460bab..5d83ffc 100644 --- a/right/usb_mouse_descriptors.c +++ b/right/usb_mouse_descriptors.c @@ -9,7 +9,7 @@ #include "hid_keyboard.h" static usb_device_endpoint_struct_t UsbMouseEndpoints[USB_MOUSE_ENDPOINT_COUNT] = {{ - USB_MOUSE_ENDPOINT_IN | (USB_IN << USB_DESCRIPTOR_ENDPOINT_ADDRESS_DIRECTION_SHIFT), + USB_MOUSE_ENDPOINT_ID | (USB_IN << USB_DESCRIPTOR_ENDPOINT_ADDRESS_DIRECTION_SHIFT), USB_ENDPOINT_INTERRUPT, USB_MOUSE_INTERRUPT_IN_PACKET_SIZE, }}; diff --git a/right/usb_mouse_descriptors.h b/right/usb_mouse_descriptors.h index 17c58b0..61392d1 100644 --- a/right/usb_mouse_descriptors.h +++ b/right/usb_mouse_descriptors.h @@ -11,7 +11,7 @@ #define USB_MOUSE_INTERFACE_COUNT (1U) #define USB_MOUSE_INTERFACE_ALTERNATE_SETTING (0U) - #define USB_MOUSE_ENDPOINT_IN (1U) + #define USB_MOUSE_ENDPOINT_ID (1U) #define USB_MOUSE_ENDPOINT_COUNT (1U) #define USB_MOUSE_INTERRUPT_IN_PACKET_SIZE (8U)