Extract mouse descriptors and macros to usb_keyboard_descriptors.[ch]
This commit is contained in:
@@ -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"
|
||||
|
||||
@@ -230,6 +230,16 @@
|
||||
<type>1</type>
|
||||
<locationURI>PARENT-2-PROJECT_LOC/usb_keyboard_descriptors.h</locationURI>
|
||||
</link>
|
||||
<link>
|
||||
<name>sources/usb_mouse_descriptors.c</name>
|
||||
<type>1</type>
|
||||
<locationURI>PARENT-2-PROJECT_LOC/usb_mouse_descriptors.c</locationURI>
|
||||
</link>
|
||||
<link>
|
||||
<name>sources/usb_mouse_descriptors.h</name>
|
||||
<type>1</type>
|
||||
<locationURI>PARENT-2-PROJECT_LOC/usb_mouse_descriptors.h</locationURI>
|
||||
</link>
|
||||
<link>
|
||||
<name>startup/startup_MK22F51212.S</name>
|
||||
<type>1</type>
|
||||
|
||||
@@ -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] = {
|
||||
|
||||
@@ -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),
|
||||
|
||||
@@ -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:
|
||||
|
||||
109
right/usb_mouse_descriptors.c
Normal file
109
right/usb_mouse_descriptors.c
Normal file
@@ -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,
|
||||
};
|
||||
30
right/usb_mouse_descriptors.h
Normal file
30
right/usb_mouse_descriptors.h
Normal file
@@ -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
|
||||
Reference in New Issue
Block a user