Extract keyboard descriptors to keyboard_descriptors.[ch]
This commit is contained in:
@@ -173,6 +173,8 @@ add_executable(dev_composite_hid_mouse_hid_keyboard_bm.elf
|
|||||||
"${SrcDir}/hid_mouse.h"
|
"${SrcDir}/hid_mouse.h"
|
||||||
"${SrcDir}/hid_keyboard.c"
|
"${SrcDir}/hid_keyboard.c"
|
||||||
"${SrcDir}/hid_keyboard.h"
|
"${SrcDir}/hid_keyboard.h"
|
||||||
|
"${SrcDir}/keyboard_descriptors.c"
|
||||||
|
"${SrcDir}/keyboard_descriptors.h"
|
||||||
"${SrcDir}/usb_device_descriptor.c"
|
"${SrcDir}/usb_device_descriptor.c"
|
||||||
"${SrcDir}/usb_device_descriptor.h"
|
"${SrcDir}/usb_device_descriptor.h"
|
||||||
"${SrcDir}/usb_device_config.h"
|
"${SrcDir}/usb_device_config.h"
|
||||||
|
|||||||
@@ -205,6 +205,16 @@
|
|||||||
<type>1</type>
|
<type>1</type>
|
||||||
<locationURI>PARENT-2-PROJECT_LOC/hid_mouse.h</locationURI>
|
<locationURI>PARENT-2-PROJECT_LOC/hid_mouse.h</locationURI>
|
||||||
</link>
|
</link>
|
||||||
|
<link>
|
||||||
|
<name>sources/keyboard_descriptors.c</name>
|
||||||
|
<type>1</type>
|
||||||
|
<locationURI>PARENT-2-PROJECT_LOC/keyboard_descriptors.c</locationURI>
|
||||||
|
</link>
|
||||||
|
<link>
|
||||||
|
<name>sources/keyboard_descriptors.h</name>
|
||||||
|
<type>1</type>
|
||||||
|
<locationURI>PARENT-2-PROJECT_LOC/keyboard_descriptors.h</locationURI>
|
||||||
|
</link>
|
||||||
<link>
|
<link>
|
||||||
<name>sources/usb_device_config.h</name>
|
<name>sources/usb_device_config.h</name>
|
||||||
<type>1</type>
|
<type>1</type>
|
||||||
|
|||||||
+2
-2
@@ -16,6 +16,7 @@
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include "fsl_common.h"
|
#include "fsl_common.h"
|
||||||
#include "include/board/pin_mux.h"
|
#include "include/board/pin_mux.h"
|
||||||
|
#include "keyboard_descriptors.h"
|
||||||
|
|
||||||
void BOARD_InitHardware(void);
|
void BOARD_InitHardware(void);
|
||||||
|
|
||||||
@@ -23,7 +24,6 @@ static usb_status_t USB_DeviceCallback(usb_device_handle handle, uint32_t event,
|
|||||||
static void USB_DeviceApplicationInit(void);
|
static void USB_DeviceApplicationInit(void);
|
||||||
|
|
||||||
extern usb_device_class_struct_t g_UsbDeviceHidMouseConfig;
|
extern usb_device_class_struct_t g_UsbDeviceHidMouseConfig;
|
||||||
extern usb_device_class_struct_t g_UsbDeviceHidKeyboardConfig;
|
|
||||||
|
|
||||||
static usb_device_composite_struct_t g_UsbDeviceComposite;
|
static usb_device_composite_struct_t g_UsbDeviceComposite;
|
||||||
|
|
||||||
@@ -31,7 +31,7 @@ usb_device_class_config_struct_t g_CompositeClassConfig[USB_COMPOSITE_INTERFACE_
|
|||||||
{
|
{
|
||||||
USB_DeviceHidKeyboardCallback,
|
USB_DeviceHidKeyboardCallback,
|
||||||
(class_handle_t)NULL,
|
(class_handle_t)NULL,
|
||||||
&g_UsbDeviceHidKeyboardConfig,
|
&UsbKeyboardClass,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
USB_DeviceHidMouseCallback,
|
USB_DeviceHidMouseCallback,
|
||||||
|
|||||||
@@ -0,0 +1,93 @@
|
|||||||
|
#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 "keyboard_descriptors.h"
|
||||||
|
|
||||||
|
static usb_device_endpoint_struct_t UsbKeyboardEndpoints[USB_HID_KEYBOARD_ENDPOINT_COUNT] =
|
||||||
|
{
|
||||||
|
{
|
||||||
|
USB_HID_KEYBOARD_ENDPOINT_IN | (USB_IN << USB_DESCRIPTOR_ENDPOINT_ADDRESS_DIRECTION_SHIFT),
|
||||||
|
USB_ENDPOINT_INTERRUPT, FS_HID_KEYBOARD_INTERRUPT_IN_PACKET_SIZE,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
static usb_device_interface_struct_t UsbKeyboardInterface[] =
|
||||||
|
{
|
||||||
|
{
|
||||||
|
USB_KEYBOARD_INTERFACE_ALTERNATE_SETTING,
|
||||||
|
{
|
||||||
|
USB_HID_KEYBOARD_ENDPOINT_COUNT,
|
||||||
|
UsbKeyboardEndpoints,
|
||||||
|
},
|
||||||
|
NULL,
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
static usb_device_interfaces_struct_t UsbKeyboardInterfaces[USB_HID_KEYBOARD_INTERFACE_COUNT] =
|
||||||
|
{
|
||||||
|
{
|
||||||
|
USB_HID_KEYBOARD_CLASS,
|
||||||
|
USB_HID_KEYBOARD_SUBCLASS,
|
||||||
|
USB_HID_KEYBOARD_PROTOCOL,
|
||||||
|
USB_HID_KEYBOARD_INTERFACE_INDEX,
|
||||||
|
UsbKeyboardInterface,
|
||||||
|
sizeof(UsbKeyboardInterface) / sizeof(usb_device_interfaces_struct_t),
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
static usb_device_interface_list_t UsbKeyboardInterfaceList[USB_DEVICE_CONFIGURATION_COUNT] =
|
||||||
|
{
|
||||||
|
{
|
||||||
|
USB_HID_KEYBOARD_INTERFACE_COUNT,
|
||||||
|
UsbKeyboardInterfaces,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
usb_device_class_struct_t UsbKeyboardClass = {
|
||||||
|
UsbKeyboardInterfaceList,
|
||||||
|
kUSB_DeviceClassTypeHid,
|
||||||
|
USB_DEVICE_CONFIGURATION_COUNT,
|
||||||
|
};
|
||||||
|
|
||||||
|
uint8_t UsbKeyboardReportDescriptor[USB_DESCRIPTOR_LENGTH_HID_KEYBOARD_REPORT] = {
|
||||||
|
0x05U, 0x01U, // Usage Page (Generic Desktop)
|
||||||
|
0x09U, 0x06U, // Usage (Keyboard)
|
||||||
|
0xA1U, 0x01U, // Collection (Application)
|
||||||
|
0x75U, 0x01U, // Report Size (1U)
|
||||||
|
0x95U, 0x08U, // Report Count (8U)
|
||||||
|
0x05U, 0x07U, // Usage Page (Key Codes)
|
||||||
|
0x19U, 0xE0U, // Usage Minimum (224U)
|
||||||
|
0x29U, 0xE7U, // Usage Maximum (231U)
|
||||||
|
|
||||||
|
0x15U, 0x00U, // Logical Minimum (0U)
|
||||||
|
0x25U, 0x01U, // Logical Maximum (1U)
|
||||||
|
0x81U, 0x02U, // Input(Data, Variable, Absolute) Modifier byte
|
||||||
|
|
||||||
|
0x95U, 0x01U, // Report count (1U)
|
||||||
|
0x75U, 0x08U, // Report Size (8U)
|
||||||
|
0x81U, 0x01U, // Input (Constant), Reserved byte
|
||||||
|
0x95U, 0x05U, // Report count (5U)
|
||||||
|
0x75U, 0x01U, // Report Size (1U)
|
||||||
|
|
||||||
|
0x05U, 0x01U, // Usage Page (Page# for LEDs)
|
||||||
|
0x19U, 0x01U, // Usage Minimum (1U)
|
||||||
|
0x29U, 0x05U, // Usage Maximum (5U)
|
||||||
|
0x91U, 0x02U, // Output (Data, Variable, Absolute) LED report
|
||||||
|
0x95U, 0x01U, // Report count (1U)
|
||||||
|
0x75U, 0x03U, // Report Size (3U)
|
||||||
|
0x91U, 0x01U, // Output (Constant), LED report padding
|
||||||
|
|
||||||
|
0x95U, 0x06U, // Report count (6U)
|
||||||
|
0x75U, 0x08U, // Report Size (8U)
|
||||||
|
0x15U, 0x00U, // Logical Minimum (0U)
|
||||||
|
0x25U, 0xFFU, // Logical Maximum (255U)
|
||||||
|
0x05U, 0x07U, // Usage Page (Key Codes)
|
||||||
|
0x19U, 0x00U, // Usage Minimum (0U)
|
||||||
|
0x29U, 0xFFU, // Usage Maximum (255U)
|
||||||
|
|
||||||
|
0x81U, 0x00U, // Input(Data, Array), Key arrays(6U bytes)
|
||||||
|
0xC0U, // End collection
|
||||||
|
};
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
#ifndef __KEYBOARD_DESCRIPTORS_H__
|
||||||
|
#define __KEYBOARD_DESCRIPTORS_H__
|
||||||
|
|
||||||
|
// Macros:
|
||||||
|
|
||||||
|
#define USB_KEYBOARD_INTERFACE_ALTERNATE_SETTING (0U)
|
||||||
|
|
||||||
|
// Function prototypes:
|
||||||
|
|
||||||
|
extern usb_device_class_struct_t UsbKeyboardClass;
|
||||||
|
extern uint8_t UsbKeyboardReportDescriptor[USB_DESCRIPTOR_LENGTH_HID_KEYBOARD_REPORT];
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -7,51 +7,7 @@
|
|||||||
#include "composite.h"
|
#include "composite.h"
|
||||||
#include "hid_mouse.h"
|
#include "hid_mouse.h"
|
||||||
#include "hid_keyboard.h"
|
#include "hid_keyboard.h"
|
||||||
|
#include "keyboard_descriptors.h"
|
||||||
// HID keyboard endpoint
|
|
||||||
usb_device_endpoint_struct_t g_UsbDeviceHidKeyboardEndpoints[USB_HID_KEYBOARD_ENDPOINT_COUNT] = {
|
|
||||||
/* HID keyboard interrupt IN pipe */
|
|
||||||
{
|
|
||||||
USB_HID_KEYBOARD_ENDPOINT_IN | (USB_IN << USB_DESCRIPTOR_ENDPOINT_ADDRESS_DIRECTION_SHIFT),
|
|
||||||
USB_ENDPOINT_INTERRUPT, FS_HID_KEYBOARD_INTERRUPT_IN_PACKET_SIZE,
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
// HID keyboard interface
|
|
||||||
usb_device_interface_struct_t g_UsbDeviceHidKeyboardInterface[] = {
|
|
||||||
{
|
|
||||||
0U, // The alternate setting of the interface
|
|
||||||
{
|
|
||||||
USB_HID_KEYBOARD_ENDPOINT_COUNT,
|
|
||||||
g_UsbDeviceHidKeyboardEndpoints,
|
|
||||||
},
|
|
||||||
NULL,
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
usb_device_interfaces_struct_t g_UsbDeviceHidKeyboardInterfaces[USB_HID_KEYBOARD_INTERFACE_COUNT] = {
|
|
||||||
{
|
|
||||||
USB_HID_KEYBOARD_CLASS,
|
|
||||||
USB_HID_KEYBOARD_SUBCLASS,
|
|
||||||
USB_HID_KEYBOARD_PROTOCOL,
|
|
||||||
USB_HID_KEYBOARD_INTERFACE_INDEX,
|
|
||||||
g_UsbDeviceHidKeyboardInterface,
|
|
||||||
sizeof(g_UsbDeviceHidKeyboardInterface) / sizeof(usb_device_interfaces_struct_t),
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
usb_device_interface_list_t g_UsbDeviceHidKeyboardInterfaceList[USB_DEVICE_CONFIGURATION_COUNT] = {
|
|
||||||
{
|
|
||||||
USB_HID_KEYBOARD_INTERFACE_COUNT,
|
|
||||||
g_UsbDeviceHidKeyboardInterfaces,
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
usb_device_class_struct_t g_UsbDeviceHidKeyboardConfig = {
|
|
||||||
g_UsbDeviceHidKeyboardInterfaceList,
|
|
||||||
kUSB_DeviceClassTypeHid,
|
|
||||||
USB_DEVICE_CONFIGURATION_COUNT,
|
|
||||||
};
|
|
||||||
|
|
||||||
// HID mouse endpoint
|
// HID mouse endpoint
|
||||||
usb_device_endpoint_struct_t g_UsbDeviceHidMouseEndpoints[USB_HID_MOUSE_ENDPOINT_COUNT] = {
|
usb_device_endpoint_struct_t g_UsbDeviceHidMouseEndpoints[USB_HID_MOUSE_ENDPOINT_COUNT] = {
|
||||||
@@ -259,47 +215,6 @@ uint8_t g_UsbDeviceHidMouseReportDescriptor[USB_DESCRIPTOR_LENGTH_HID_MOUSE_REPO
|
|||||||
0xC0U /* end collection, Close Mouse collection */
|
0xC0U /* end collection, Close Mouse collection */
|
||||||
};
|
};
|
||||||
|
|
||||||
/* HID keyboard report descriptor */
|
|
||||||
uint8_t g_UsbDeviceHidKeyboardReportDescriptor[USB_DESCRIPTOR_LENGTH_HID_KEYBOARD_REPORT] = {
|
|
||||||
0x05U, 0x01U, /* Usage Page (Generic Desktop)*/
|
|
||||||
0x09U, 0x06U, /* Usage (Keyboard) */
|
|
||||||
0xA1U, 0x01U, /* Collection (Application) */
|
|
||||||
0x75U, 0x01U, /* Report Size (1U) */
|
|
||||||
0x95U, 0x08U, /* Report Count (8U) */
|
|
||||||
0x05U, 0x07U, /* Usage Page (Key Codes) */
|
|
||||||
0x19U, 0xE0U, /* Usage Minimum (224U) */
|
|
||||||
0x29U, 0xE7U, /* Usage Maximum (231U) */
|
|
||||||
|
|
||||||
0x15U, 0x00U, /* Logical Minimum (0U) */
|
|
||||||
0x25U, 0x01U, /* Logical Maximum (1U) */
|
|
||||||
0x81U, 0x02U, /* Input(Data, Variable, Absolute) Modifier byte */
|
|
||||||
|
|
||||||
0x95U, 0x01U, /* Report count (1U) */
|
|
||||||
0x75U, 0x08U, /* Report Size (8U) */
|
|
||||||
0x81U, 0x01U, /* Input (Constant), Reserved byte */
|
|
||||||
0x95U, 0x05U, /* Report count (5U) */
|
|
||||||
0x75U, 0x01U, /* Report Size (1U) */
|
|
||||||
|
|
||||||
0x05U, 0x01U, /* Usage Page (Page# for LEDs) */
|
|
||||||
0x19U, 0x01U, /* Usage Minimum (1U) */
|
|
||||||
0x29U, 0x05U, /* Usage Maximum (5U) */
|
|
||||||
0x91U, 0x02U, /* Output (Data, Variable, Absolute) LED report */
|
|
||||||
0x95U, 0x01U, /* Report count (1U) */
|
|
||||||
0x75U, 0x03U, /* Report Size (3U) */
|
|
||||||
0x91U, 0x01U, /* Output (Constant), LED report padding */
|
|
||||||
|
|
||||||
0x95U, 0x06U, /* Report count (6U) */
|
|
||||||
0x75U, 0x08U, /* Report Size (8U) */
|
|
||||||
0x15U, 0x00U, /* logical Minimum (0U) */
|
|
||||||
0x25U, 0xFFU, /* logical Maximum (255U) */
|
|
||||||
0x05U, 0x07U, /* Usage Page (Key Codes) */
|
|
||||||
0x19U, 0x00U, /* Usage Minimum (0U) */
|
|
||||||
0x29U, 0xFFU, /* Usage Maximum (255U) */
|
|
||||||
|
|
||||||
0x81U, 0x00U, /* Input(Data, Array), Key arrays(6U bytes)*/
|
|
||||||
0xC0U, /* end collection */
|
|
||||||
};
|
|
||||||
|
|
||||||
uint8_t g_UsbDeviceString0[USB_DESCRIPTOR_LENGTH_STRING0] = {
|
uint8_t g_UsbDeviceString0[USB_DESCRIPTOR_LENGTH_STRING0] = {
|
||||||
sizeof(g_UsbDeviceString0), USB_DESCRIPTOR_TYPE_STRING, 0x09U, 0x04U,
|
sizeof(g_UsbDeviceString0), USB_DESCRIPTOR_TYPE_STRING, 0x09U, 0x04U,
|
||||||
};
|
};
|
||||||
@@ -479,7 +394,7 @@ usb_status_t USB_DeviceGetHidReportDescriptor(usb_device_handle handle,
|
|||||||
hidReportDescriptor->buffer = g_UsbDeviceHidMouseReportDescriptor;
|
hidReportDescriptor->buffer = g_UsbDeviceHidMouseReportDescriptor;
|
||||||
hidReportDescriptor->length = USB_DESCRIPTOR_LENGTH_HID_MOUSE_REPORT;
|
hidReportDescriptor->length = USB_DESCRIPTOR_LENGTH_HID_MOUSE_REPORT;
|
||||||
} else if (USB_HID_KEYBOARD_INTERFACE_INDEX == hidReportDescriptor->interfaceNumber) {
|
} else if (USB_HID_KEYBOARD_INTERFACE_INDEX == hidReportDescriptor->interfaceNumber) {
|
||||||
hidReportDescriptor->buffer = g_UsbDeviceHidKeyboardReportDescriptor;
|
hidReportDescriptor->buffer = UsbKeyboardReportDescriptor;
|
||||||
hidReportDescriptor->length = USB_DESCRIPTOR_LENGTH_HID_KEYBOARD_REPORT;
|
hidReportDescriptor->length = USB_DESCRIPTOR_LENGTH_HID_KEYBOARD_REPORT;
|
||||||
} else {
|
} else {
|
||||||
return kStatus_USB_InvalidRequest;
|
return kStatus_USB_InvalidRequest;
|
||||||
|
|||||||
Reference in New Issue
Block a user