From cfb1135aac644d8cfb2afdfab5eebce5d9ca886a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A1szl=C3=B3=20Monda?= Date: Thu, 25 Feb 2016 07:54:27 +0100 Subject: [PATCH] Extract mouse descriptors and macros to usb_keyboard_descriptors.[ch] --- right/build/armgcc/CMakeLists.txt | 2 + right/build/kds/.project | 10 +++ right/composite.c | 3 +- right/usb_device_descriptor.c | 101 +-------------------------- right/usb_device_descriptor.h | 18 +---- right/usb_mouse_descriptors.c | 109 ++++++++++++++++++++++++++++++ right/usb_mouse_descriptors.h | 30 ++++++++ 7 files changed, 154 insertions(+), 119 deletions(-) create mode 100644 right/usb_mouse_descriptors.c create mode 100644 right/usb_mouse_descriptors.h diff --git a/right/build/armgcc/CMakeLists.txt b/right/build/armgcc/CMakeLists.txt index 92d12ba..3aa0481 100644 --- a/right/build/armgcc/CMakeLists.txt +++ b/right/build/armgcc/CMakeLists.txt @@ -175,6 +175,8 @@ add_executable(dev_composite_hid_mouse_hid_keyboard_bm.elf "${SrcDir}/hid_keyboard.h" "${SrcDir}/usb_keyboard_descriptors.c" "${SrcDir}/usb_keyboard_descriptors.h" +"${SrcDir}/usb_mouse_descriptors.c" +"${SrcDir}/usb_mouse_descriptors.h" "${SrcDir}/usb_device_descriptor.c" "${SrcDir}/usb_device_descriptor.h" "${SrcDir}/usb_device_config.h" diff --git a/right/build/kds/.project b/right/build/kds/.project index f3c71a7..ce76281 100644 --- a/right/build/kds/.project +++ b/right/build/kds/.project @@ -230,6 +230,16 @@ 1 PARENT-2-PROJECT_LOC/usb_keyboard_descriptors.h + + sources/usb_mouse_descriptors.c + 1 + PARENT-2-PROJECT_LOC/usb_mouse_descriptors.c + + + sources/usb_mouse_descriptors.h + 1 + PARENT-2-PROJECT_LOC/usb_mouse_descriptors.h + startup/startup_MK22F51212.S 1 diff --git a/right/composite.c b/right/composite.c index 9efd6dc..b927cd6 100644 --- a/right/composite.c +++ b/right/composite.c @@ -17,14 +17,13 @@ #include "fsl_common.h" #include "include/board/pin_mux.h" #include "usb_keyboard_descriptors.h" +#include "usb_mouse_descriptors.h" void BOARD_InitHardware(void); static usb_status_t USB_DeviceCallback(usb_device_handle handle, uint32_t event, void *param); static void USB_DeviceApplicationInit(void); -extern usb_device_class_struct_t g_UsbDeviceHidMouseConfig; - static usb_device_composite_struct_t g_UsbDeviceComposite; usb_device_class_config_struct_t g_CompositeClassConfig[USB_COMPOSITE_INTERFACE_COUNT] = { diff --git a/right/usb_device_descriptor.c b/right/usb_device_descriptor.c index 53702b4..553fbe6 100644 --- a/right/usb_device_descriptor.c +++ b/right/usb_device_descriptor.c @@ -8,49 +8,7 @@ #include "hid_mouse.h" #include "hid_keyboard.h" #include "usb_keyboard_descriptors.h" - -// HID mouse endpoint -usb_device_endpoint_struct_t g_UsbDeviceHidMouseEndpoints[USB_HID_MOUSE_ENDPOINT_COUNT] = { - // HID mouse interrupt IN pipe - { - USB_HID_MOUSE_ENDPOINT_IN | (USB_IN << USB_DESCRIPTOR_ENDPOINT_ADDRESS_DIRECTION_SHIFT), USB_ENDPOINT_INTERRUPT, - FS_HID_MOUSE_INTERRUPT_IN_PACKET_SIZE, - }, -}; - -// HID mouse interface information -usb_device_interface_struct_t g_UsbDeviceHidMouseInterface[] = {{ - 0U, // The alternate setting of the interface - { - USB_HID_MOUSE_ENDPOINT_COUNT, - g_UsbDeviceHidMouseEndpoints, - }, - NULL, -}}; - -usb_device_interfaces_struct_t g_UsbDeviceHidMouseInterfaces[USB_HID_MOUSE_INTERFACE_COUNT] = { - { - USB_HID_MOUSE_CLASS, - USB_HID_MOUSE_SUBCLASS, - USB_HID_MOUSE_PROTOCOL, - USB_HID_MOUSE_INTERFACE_INDEX, - g_UsbDeviceHidMouseInterface, - sizeof(g_UsbDeviceHidMouseInterface) / sizeof(usb_device_interfaces_struct_t), - }, -}; - -usb_device_interface_list_t g_UsbDeviceHidMouseInterfaceList[USB_DEVICE_CONFIGURATION_COUNT] = { - { - USB_HID_MOUSE_INTERFACE_COUNT, - g_UsbDeviceHidMouseInterfaces, - }, -}; - -usb_device_class_struct_t g_UsbDeviceHidMouseConfig = { - g_UsbDeviceHidMouseInterfaceList, - kUSB_DeviceClassTypeHid, - USB_DEVICE_CONFIGURATION_COUNT, -}; +#include "usb_mouse_descriptors.h" uint8_t g_UsbDeviceDescriptor[USB_DESCRIPTOR_LENGTH_DEVICE] = { USB_DESCRIPTOR_LENGTH_DEVICE, /* Size of this descriptor in bytes */ @@ -179,42 +137,6 @@ uint8_t g_UsbDeviceConfigurationDescriptor[USB_DESCRIPTOR_LENGTH_CONFIGURATION_A FS_HID_KEYBOARD_INTERRUPT_IN_INTERVAL, /* Interval for polling endpoint for data transfers. */ }; -uint8_t g_UsbDeviceHidMouseReportDescriptor[USB_DESCRIPTOR_LENGTH_HID_MOUSE_REPORT] = { - 0x05U, 0x01U, /* Usage Page (Generic Desktop)*/ - 0x09U, 0x02U, /* Usage (Mouse) */ - 0xA1U, 0x01U, /* Collection (Application) */ - 0x09U, 0x01U, /* Usage (Pointer) */ - - 0xA1U, 0x00U, /* Collection (Physical) */ - 0x05U, 0x09U, /* Usage Page (Buttons) */ - 0x19U, 0x01U, /* Usage Minimum (01U) */ - 0x29U, 0x03U, /* Usage Maximum (03U) */ - - 0x15U, 0x00U, /* logical Minimum (0U) */ - 0x25U, 0x01U, /* logical Maximum (1U) */ - 0x95U, 0x03U, /* Report Count (3U) */ - 0x75U, 0x01U, /* Report Size (1U) */ - - 0x81U, 0x02U, /* Input(Data, Variable, Absolute) 3U button bit fields */ - 0x95U, 0x01U, /* Report count (1U) */ - 0x75U, 0x05U, /* Report Size (5U) */ - 0x81U, 0x01U, /* Input (Constant), 5U constant field */ - - 0x05U, 0x01U, /* Usage Page (Generic Desktop) */ - 0x09U, 0x30U, /* Usage (X) */ - 0x09U, 0x31U, /* Usage (Y) */ - 0x09U, 0x38U, /* Usage (Z) */ - - 0x15U, 0x81U, /* Logical Minimum (-127) */ - 0x25U, 0x7FU, /* Logical Maximum (127) */ - 0x75U, 0x08U, /* Report Size (8U) */ - 0x95U, 0x03U, /* Report Count (3U) */ - - 0x81U, 0x06U, /* Input(Data, Variable, Relative), three position bytes (X & Y & Z)*/ - 0xC0U, /* end collection, Close Pointer collection*/ - 0xC0U /* end collection, Close Mouse collection */ -}; - uint8_t g_UsbDeviceString0[USB_DESCRIPTOR_LENGTH_STRING0] = { sizeof(g_UsbDeviceString0), USB_DESCRIPTOR_TYPE_STRING, 0x09U, 0x04U, }; @@ -273,27 +195,6 @@ uint8_t g_UsbDeviceString2[USB_DESCRIPTOR_LENGTH_STRING2] = { 'E', 0x00U, }; -uint8_t g_UsbDeviceString3[USB_DESCRIPTOR_LENGTH_STRING3] = { - sizeof(g_UsbDeviceString3), - USB_DESCRIPTOR_TYPE_STRING, - 'H', 0x00U, - 'I', 0x00U, - 'D', 0x00U, - ' ', 0x00U, - 'M', 0x00U, - 'O', 0x00U, - 'U', 0x00U, - 'S', 0x00U, - 'E', 0x00U, - ' ', 0x00U, - 'D', 0x00U, - 'E', 0x00U, - 'V', 0x00U, - 'I', 0x00U, - 'C', 0x00U, - 'E', 0x00U, -}; - uint32_t g_UsbDeviceStringDescriptorLength[USB_DEVICE_STRING_COUNT] = { sizeof(g_UsbDeviceString0), sizeof(g_UsbDeviceString1), sizeof(g_UsbDeviceString2), sizeof(g_UsbDeviceString3), sizeof(g_UsbKeyboardString), diff --git a/right/usb_device_descriptor.h b/right/usb_device_descriptor.h index 06307e6..892fab0 100644 --- a/right/usb_device_descriptor.h +++ b/right/usb_device_descriptor.h @@ -4,6 +4,7 @@ // Includes: #include "usb_keyboard_descriptors.h" + #include "usb_mouse_descriptors.h" // Macros: @@ -17,12 +18,10 @@ #define USB_DEVICE_MAX_POWER (0x32U) #define USB_DESCRIPTOR_LENGTH_CONFIGURATION_ALL (59U) - #define USB_DESCRIPTOR_LENGTH_HID_MOUSE_REPORT (52U) #define USB_DESCRIPTOR_LENGTH_HID (9U) #define USB_DESCRIPTOR_LENGTH_STRING0 (4U) #define USB_DESCRIPTOR_LENGTH_STRING1 (58U) #define USB_DESCRIPTOR_LENGTH_STRING2 (34U) - #define USB_DESCRIPTOR_LENGTH_STRING3 (34U) #define USB_DEVICE_CONFIGURATION_COUNT (1U) #define USB_DEVICE_STRING_COUNT (5U) @@ -30,21 +29,6 @@ #define USB_COMPOSITE_CONFIGURE_INDEX (1U) - #define USB_HID_MOUSE_INTERFACE_COUNT (1U) - #define USB_HID_MOUSE_INTERFACE_INDEX (0U) - #define USB_HID_MOUSE_IN_BUFFER_LENGTH (8U) - #define USB_HID_MOUSE_ENDPOINT_COUNT (1U) - #define USB_HID_MOUSE_ENDPOINT_IN (1U) - - #define USB_HID_MOUSE_REPORT_LENGTH (0x04U) - - #define USB_HID_MOUSE_CLASS (0x03U) - #define USB_HID_MOUSE_SUBCLASS (0x01U) - #define USB_HID_MOUSE_PROTOCOL (0x02U) - - #define FS_HID_MOUSE_INTERRUPT_IN_PACKET_SIZE (8U) - #define FS_HID_MOUSE_INTERRUPT_IN_INTERVAL (0x04U) - #define USB_COMPOSITE_INTERFACE_COUNT (USB_HID_KEYBOARD_INTERFACE_COUNT + USB_HID_MOUSE_INTERFACE_COUNT) // Function prototypes: diff --git a/right/usb_mouse_descriptors.c b/right/usb_mouse_descriptors.c new file mode 100644 index 0000000..09e5654 --- /dev/null +++ b/right/usb_mouse_descriptors.c @@ -0,0 +1,109 @@ +#include "usb_device_config.h" +#include "usb.h" +#include "usb_device.h" +#include "include/usb/usb_device_class.h" +#include "include/usb/usb_device_hid.h" +#include "usb_device_descriptor.h" +#include "composite.h" +#include "hid_mouse.h" +#include "hid_keyboard.h" + +// HID mouse endpoint +static usb_device_endpoint_struct_t g_UsbDeviceHidMouseEndpoints[USB_HID_MOUSE_ENDPOINT_COUNT] = { + // HID mouse interrupt IN pipe + { + USB_HID_MOUSE_ENDPOINT_IN | (USB_IN << USB_DESCRIPTOR_ENDPOINT_ADDRESS_DIRECTION_SHIFT), USB_ENDPOINT_INTERRUPT, + FS_HID_MOUSE_INTERRUPT_IN_PACKET_SIZE, + }, +}; + +// HID mouse interface information +static usb_device_interface_struct_t g_UsbDeviceHidMouseInterface[] = {{ + 0U, // The alternate setting of the interface + { + USB_HID_MOUSE_ENDPOINT_COUNT, + g_UsbDeviceHidMouseEndpoints, + }, + NULL, +}}; + +static usb_device_interfaces_struct_t g_UsbDeviceHidMouseInterfaces[USB_HID_MOUSE_INTERFACE_COUNT] = { + { + USB_HID_MOUSE_CLASS, + USB_HID_MOUSE_SUBCLASS, + USB_HID_MOUSE_PROTOCOL, + USB_HID_MOUSE_INTERFACE_INDEX, + g_UsbDeviceHidMouseInterface, + sizeof(g_UsbDeviceHidMouseInterface) / sizeof(usb_device_interfaces_struct_t), + }, +}; + +static usb_device_interface_list_t g_UsbDeviceHidMouseInterfaceList[USB_DEVICE_CONFIGURATION_COUNT] = { + { + USB_HID_MOUSE_INTERFACE_COUNT, + g_UsbDeviceHidMouseInterfaces, + }, +}; + +usb_device_class_struct_t g_UsbDeviceHidMouseConfig = { + g_UsbDeviceHidMouseInterfaceList, + kUSB_DeviceClassTypeHid, + USB_DEVICE_CONFIGURATION_COUNT, +}; + +uint8_t g_UsbDeviceHidMouseReportDescriptor[USB_DESCRIPTOR_LENGTH_HID_MOUSE_REPORT] = { + 0x05U, 0x01U, // Usage Page (Generic Desktop) + 0x09U, 0x02U, // Usage (Mouse) + 0xA1U, 0x01U, // Collection (Application) + 0x09U, 0x01U, // Usage (Pointer) + + 0xA1U, 0x00U, // Collection (Physical) + 0x05U, 0x09U, // Usage Page (Buttons) + 0x19U, 0x01U, // Usage Minimum (01U) + 0x29U, 0x03U, // Usage Maximum (03U) + + 0x15U, 0x00U, // Logical Minimum (0U) + 0x25U, 0x01U, // Logical Maximum (1U) + 0x95U, 0x03U, // Report Count (3U) + 0x75U, 0x01U, // Report Size (1U) + + 0x81U, 0x02U, // Input(Data, Variable, Absolute) 3U button bit fields + 0x95U, 0x01U, // Report count (1U) + 0x75U, 0x05U, // Report Size (5U) + 0x81U, 0x01U, // Input (Constant), 5U constant field + + 0x05U, 0x01U, // Usage Page (Generic Desktop) + 0x09U, 0x30U, // Usage (X) + 0x09U, 0x31U, // Usage (Y) + 0x09U, 0x38U, // Usage (Z) + + 0x15U, 0x81U, // Logical Minimum (-127) + 0x25U, 0x7FU, // Logical Maximum (127) + 0x75U, 0x08U, // Report Size (8U) + 0x95U, 0x03U, // Report Count (3U) + + 0x81U, 0x06U, // Input(Data, Variable, Relative), three position bytes (X & Y & Z) + 0xC0U, // End collection, Close Pointer collection + 0xC0U // End collection, Close Mouse collection +}; + +uint8_t g_UsbDeviceString3[USB_DESCRIPTOR_LENGTH_STRING3] = { + sizeof(g_UsbDeviceString3), + USB_DESCRIPTOR_TYPE_STRING, + 'H', 0x00U, + 'I', 0x00U, + 'D', 0x00U, + ' ', 0x00U, + 'M', 0x00U, + 'O', 0x00U, + 'U', 0x00U, + 'S', 0x00U, + 'E', 0x00U, + ' ', 0x00U, + 'D', 0x00U, + 'E', 0x00U, + 'V', 0x00U, + 'I', 0x00U, + 'C', 0x00U, + 'E', 0x00U, +}; diff --git a/right/usb_mouse_descriptors.h b/right/usb_mouse_descriptors.h new file mode 100644 index 0000000..f0de7a2 --- /dev/null +++ b/right/usb_mouse_descriptors.h @@ -0,0 +1,30 @@ +#ifndef __USB_MOUSE_DESCRIPTORS_H__ +#define __USB_MOUSE_DESCRIPTORS_H__ + +// Macros: + + #define USB_HID_MOUSE_INTERFACE_COUNT (1U) + #define USB_HID_MOUSE_INTERFACE_INDEX (0U) + #define USB_HID_MOUSE_IN_BUFFER_LENGTH (8U) + #define USB_HID_MOUSE_ENDPOINT_COUNT (1U) + #define USB_HID_MOUSE_ENDPOINT_IN (1U) + + #define USB_HID_MOUSE_REPORT_LENGTH (0x04U) + + #define USB_HID_MOUSE_CLASS (0x03U) + #define USB_HID_MOUSE_SUBCLASS (0x01U) + #define USB_HID_MOUSE_PROTOCOL (0x02U) + + #define FS_HID_MOUSE_INTERRUPT_IN_PACKET_SIZE (8U) + #define FS_HID_MOUSE_INTERRUPT_IN_INTERVAL (0x04U) + + #define USB_DESCRIPTOR_LENGTH_HID_MOUSE_REPORT (52U) + #define USB_DESCRIPTOR_LENGTH_STRING3 (34U) + +// Variables: + +extern usb_device_class_struct_t g_UsbDeviceHidMouseConfig; +extern uint8_t g_UsbDeviceHidMouseReportDescriptor[USB_DESCRIPTOR_LENGTH_HID_MOUSE_REPORT]; +extern uint8_t g_UsbDeviceString3[USB_DESCRIPTOR_LENGTH_STRING3]; + +#endif