Add generic HID interface.
This commit is contained in:
@@ -185,6 +185,16 @@
|
||||
<type>1</type>
|
||||
<locationURI>PARENT-2-PROJECT_LOC/composite.h</locationURI>
|
||||
</link>
|
||||
<link>
|
||||
<name>sources/hid_generic.c</name>
|
||||
<type>1</type>
|
||||
<locationURI>PARENT-2-PROJECT_LOC/hid_generic.c</locationURI>
|
||||
</link>
|
||||
<link>
|
||||
<name>sources/hid_generic.h</name>
|
||||
<type>1</type>
|
||||
<locationURI>PARENT-2-PROJECT_LOC/hid_generic.h</locationURI>
|
||||
</link>
|
||||
<link>
|
||||
<name>sources/hid_keyboard.c</name>
|
||||
<type>1</type>
|
||||
@@ -225,6 +235,16 @@
|
||||
<type>1</type>
|
||||
<locationURI>PARENT-2-PROJECT_LOC/usb_device_descriptor.h</locationURI>
|
||||
</link>
|
||||
<link>
|
||||
<name>sources/usb_generic_hid_descriptors.c</name>
|
||||
<type>1</type>
|
||||
<locationURI>PARENT-2-PROJECT_LOC/usb_generic_hid_descriptors.c</locationURI>
|
||||
</link>
|
||||
<link>
|
||||
<name>sources/usb_generic_hid_descriptors.h</name>
|
||||
<type>1</type>
|
||||
<locationURI>PARENT-2-PROJECT_LOC/usb_generic_hid_descriptors.h</locationURI>
|
||||
</link>
|
||||
<link>
|
||||
<name>sources/usb_keyboard_descriptors.c</name>
|
||||
<type>1</type>
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
#include "composite.h"
|
||||
#include "hid_keyboard.h"
|
||||
#include "hid_mouse.h"
|
||||
#include "hid_generic.h"
|
||||
#include "fsl_device_registers.h"
|
||||
#include "include/board/clock_config.h"
|
||||
#include "include/board/board.h"
|
||||
@@ -18,13 +19,15 @@
|
||||
#include "include/board/pin_mux.h"
|
||||
#include "usb_keyboard_descriptors.h"
|
||||
#include "usb_mouse_descriptors.h"
|
||||
#include "usb_generic_hid_descriptors.h"
|
||||
|
||||
static usb_status_t UsbDeviceCallback(usb_device_handle handle, uint32_t event, void *param);
|
||||
usb_device_composite_struct_t UsbCompositeDevice;
|
||||
|
||||
usb_device_class_config_struct_t UsbDeviceCompositeClassConfig[USB_COMPOSITE_INTERFACE_COUNT] = {
|
||||
{UsbKeyboardCallback, (class_handle_t)NULL, &UsbKeyboardClass},
|
||||
{UsbMouseCallback, (class_handle_t)NULL, &UsbMouseClass}
|
||||
{UsbKeyboardCallback, (class_handle_t)NULL, &UsbKeyboardClass},
|
||||
{UsbMouseCallback, (class_handle_t)NULL, &UsbMouseClass},
|
||||
{UsbGenericHidCallback, (class_handle_t)NULL, &UsbGenericHidClass}
|
||||
};
|
||||
|
||||
usb_device_class_config_list_struct_t UsbDeviceCompositeConfigList = {
|
||||
@@ -66,8 +69,7 @@ static usb_status_t UsbDeviceCallback(usb_device_handle handle, uint32_t event,
|
||||
if (interface < USB_COMPOSITE_INTERFACE_COUNT) {
|
||||
UsbCompositeDevice.currentInterfaceAlternateSetting[interface] = alternateSetting;
|
||||
UsbMouseSetInterface(UsbCompositeDevice.mouseHandle, interface, alternateSetting);
|
||||
UsbKeyboardSetInterface(UsbCompositeDevice.keyboardHandle, interface,
|
||||
alternateSetting);
|
||||
UsbKeyboardSetInterface(UsbCompositeDevice.keyboardHandle, interface, alternateSetting);
|
||||
error = kStatus_USB_Success;
|
||||
}
|
||||
}
|
||||
@@ -122,6 +124,7 @@ static void USB_DeviceApplicationInit(void)
|
||||
USB_DeviceClassInit(CONTROLLER_ID, &UsbDeviceCompositeConfigList, &UsbCompositeDevice.deviceHandle);
|
||||
UsbCompositeDevice.keyboardHandle = UsbDeviceCompositeConfigList.config[0].classHandle;
|
||||
UsbCompositeDevice.mouseHandle = UsbDeviceCompositeConfigList.config[1].classHandle;
|
||||
UsbCompositeDevice.genericHidHandle = UsbDeviceCompositeConfigList.config[2].classHandle;
|
||||
|
||||
NVIC_SetPriority((IRQn_Type)irqNumber, USB_DEVICE_INTERRUPT_PRIORITY);
|
||||
NVIC_EnableIRQ((IRQn_Type)irqNumber);
|
||||
@@ -134,6 +137,20 @@ void main(void)
|
||||
BOARD_InitPins();
|
||||
BOARD_BootClockHSRUN();
|
||||
BOARD_InitDebugConsole();
|
||||
|
||||
gpio_pin_config_t led_config = {
|
||||
kGPIO_DigitalOutput, 0,
|
||||
};
|
||||
|
||||
// Init output LED GPIO.
|
||||
GPIO_PinInit(BOARD_LED_RED_GPIO, BOARD_LED_RED_GPIO_PIN, &led_config);
|
||||
GPIO_PinInit(BOARD_LED_GREEN_GPIO, BOARD_LED_GREEN_GPIO_PIN, &led_config);
|
||||
GPIO_PinInit(BOARD_LED_BLUE_GPIO, BOARD_LED_BLUE_GPIO_PIN, &led_config);
|
||||
|
||||
GPIO_SetPinsOutput(BOARD_LED_RED_GPIO, 1U << BOARD_LED_RED_GPIO_PIN);
|
||||
GPIO_SetPinsOutput(BOARD_LED_GREEN_GPIO, 1U << BOARD_LED_GREEN_GPIO_PIN);
|
||||
GPIO_SetPinsOutput(BOARD_LED_BLUE_GPIO, 1U << BOARD_LED_BLUE_GPIO_PIN);
|
||||
|
||||
USB_DeviceApplicationInit();
|
||||
|
||||
while (1U) {
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
usb_device_handle deviceHandle;
|
||||
class_handle_t mouseHandle;
|
||||
class_handle_t keyboardHandle;
|
||||
class_handle_t genericHidHandle;
|
||||
uint8_t speed;
|
||||
uint8_t attach;
|
||||
uint8_t currentConfiguration;
|
||||
|
||||
89
right/hid_generic.c
Normal file
89
right/hid_generic.c
Normal file
@@ -0,0 +1,89 @@
|
||||
#include "include/board/board.h"
|
||||
#include "fsl_gpio.h"
|
||||
#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 "include/usb/usb_device_ch9.h"
|
||||
#include "usb_device_descriptor.h"
|
||||
#include "composite.h"
|
||||
#include "scancodes.h"
|
||||
#include "hid_generic.h"
|
||||
|
||||
static usb_device_generic_hid_struct_t UsbGenericHidDevice;
|
||||
|
||||
usb_status_t UsbGenericHidCallback(class_handle_t handle, uint32_t event, void *param)
|
||||
{
|
||||
usb_status_t error = kStatus_USB_Error;
|
||||
|
||||
switch (event)
|
||||
{
|
||||
case kUSB_DeviceHidEventSendResponse:
|
||||
break;
|
||||
case kUSB_DeviceHidEventRecvResponse:
|
||||
GPIO_SetPinsOutput(BOARD_LED_RED_GPIO, 1U << BOARD_LED_RED_GPIO_PIN);
|
||||
GPIO_SetPinsOutput(BOARD_LED_GREEN_GPIO, 1U << BOARD_LED_GREEN_GPIO_PIN);
|
||||
GPIO_SetPinsOutput(BOARD_LED_BLUE_GPIO, 1U << BOARD_LED_BLUE_GPIO_PIN);
|
||||
|
||||
uint8_t* cp = (uint8_t*)&UsbGenericHidDevice.buffer[UsbGenericHidDevice.bufferIndex][0];
|
||||
uint8_t c = *(cp+0);
|
||||
if (c == 'r') {
|
||||
GPIO_ClearPinsOutput(BOARD_LED_RED_GPIO, 1U << BOARD_LED_RED_GPIO_PIN);
|
||||
}
|
||||
if (c == 'g') {
|
||||
GPIO_ClearPinsOutput(BOARD_LED_GREEN_GPIO, 1U << BOARD_LED_GREEN_GPIO_PIN);
|
||||
}
|
||||
if (c == 'b') {
|
||||
GPIO_ClearPinsOutput(BOARD_LED_BLUE_GPIO, 1U << BOARD_LED_BLUE_GPIO_PIN);
|
||||
}
|
||||
|
||||
USB_DeviceHidSend(UsbCompositeDevice.genericHidHandle, USB_GENERIC_HID_ENDPOINT_IN_ID,
|
||||
(uint8_t *)&UsbGenericHidDevice.buffer[UsbGenericHidDevice.bufferIndex][0],
|
||||
USB_GENERIC_HID_OUT_BUFFER_LENGTH);
|
||||
UsbGenericHidDevice.bufferIndex ^= 1U;
|
||||
return USB_DeviceHidRecv(UsbCompositeDevice.genericHidHandle, USB_GENERIC_HID_ENDPOINT_OUT_ID,
|
||||
(uint8_t *)&UsbGenericHidDevice.buffer[UsbGenericHidDevice.bufferIndex][0],
|
||||
USB_GENERIC_HID_OUT_BUFFER_LENGTH);
|
||||
break;
|
||||
case kUSB_DeviceHidEventGetReport:
|
||||
case kUSB_DeviceHidEventSetReport:
|
||||
case kUSB_DeviceHidEventRequestReportBuffer:
|
||||
error = kStatus_USB_InvalidRequest;
|
||||
break;
|
||||
case kUSB_DeviceHidEventGetIdle:
|
||||
case kUSB_DeviceHidEventGetProtocol:
|
||||
case kUSB_DeviceHidEventSetIdle:
|
||||
case kUSB_DeviceHidEventSetProtocol:
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return error;
|
||||
}
|
||||
usb_status_t UsbGenericHidSetConfigure(class_handle_t handle, uint8_t configuration)
|
||||
{
|
||||
if (USB_COMPOSITE_CONFIGURATION_INDEX == configuration) {
|
||||
return USB_DeviceHidRecv(
|
||||
UsbCompositeDevice.genericHidHandle, USB_GENERIC_HID_ENDPOINT_OUT_ID,
|
||||
(uint8_t *)&UsbGenericHidDevice.buffer[UsbGenericHidDevice.bufferIndex][0],
|
||||
USB_GENERIC_HID_OUT_BUFFER_LENGTH);
|
||||
}
|
||||
return kStatus_USB_Error;
|
||||
}
|
||||
|
||||
usb_status_t UsbGenericHidSetInterface(class_handle_t handle, uint8_t interface, uint8_t alternateSetting)
|
||||
{
|
||||
if (USB_KEYBOARD_INTERFACE_INDEX == interface) {
|
||||
UsbCompositeDevice.currentInterfaceAlternateSetting[interface] = alternateSetting;
|
||||
if (alternateSetting == 0U)
|
||||
{
|
||||
return USB_DeviceHidRecv(
|
||||
UsbCompositeDevice.genericHidHandle, USB_GENERIC_HID_ENDPOINT_OUT_ID,
|
||||
(uint8_t *)&UsbGenericHidDevice.buffer[UsbGenericHidDevice.bufferIndex][0],
|
||||
USB_GENERIC_HID_OUT_BUFFER_LENGTH);
|
||||
}
|
||||
}
|
||||
return kStatus_USB_Error;
|
||||
}
|
||||
23
right/hid_generic.h
Normal file
23
right/hid_generic.h
Normal file
@@ -0,0 +1,23 @@
|
||||
#ifndef __HID_GENERIC_H__
|
||||
#define __HID_GENERIC_H__
|
||||
|
||||
// Macros:
|
||||
|
||||
#define USB_GENERIC_HID_IN_BUFFER_LENGTH (64U)
|
||||
#define USB_GENERIC_HID_OUT_BUFFER_LENGTH (64U)
|
||||
|
||||
// Typedefs:
|
||||
|
||||
typedef struct _usb_device_generic_hid_struct {
|
||||
uint32_t buffer[2][USB_GENERIC_HID_IN_BUFFER_LENGTH >> 2];
|
||||
uint8_t bufferIndex;
|
||||
uint8_t idleRate;
|
||||
} usb_device_generic_hid_struct_t;
|
||||
|
||||
// Functions:
|
||||
|
||||
extern usb_status_t UsbGenericHidCallback(class_handle_t handle, uint32_t event, void *param);
|
||||
extern usb_status_t UsbGenericHidSetConfigure(class_handle_t handle, uint8_t configuration);
|
||||
extern usb_status_t UsbGenericHidSetInterface(class_handle_t handle, uint8_t interface, uint8_t alternateSetting);
|
||||
|
||||
#endif
|
||||
@@ -49,4 +49,13 @@ void BOARD_InitPins(void)
|
||||
// Set up SW3.
|
||||
CLOCK_EnableClock(kCLOCK_PortB);
|
||||
PORT_SetPinConfig(BOARD_SW3_PORT, BOARD_SW3_GPIO_PIN, &switchConfig);
|
||||
|
||||
// Enable LED port clock
|
||||
CLOCK_EnableClock(kCLOCK_PortA);
|
||||
CLOCK_EnableClock(kCLOCK_PortD);
|
||||
|
||||
// Led pin mux Configuration
|
||||
PORT_SetPinMux(BOARD_LED_RED_GPIO_PORT, BOARD_LED_RED_GPIO_PIN, kPORT_MuxAsGpio);
|
||||
PORT_SetPinMux(BOARD_LED_GREEN_GPIO_PORT, BOARD_LED_GREEN_GPIO_PIN, kPORT_MuxAsGpio);
|
||||
PORT_SetPinMux(BOARD_LED_BLUE_GPIO_PORT, BOARD_LED_BLUE_GPIO_PIN, kPORT_MuxAsGpio);
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
#define USB_DEVICE_CONFIG_NUM (1U)
|
||||
|
||||
/*! @brief HID instance count */
|
||||
#define USB_DEVICE_CONFIG_HID (2U)
|
||||
#define USB_DEVICE_CONFIG_HID (3U)
|
||||
|
||||
/*! @brief Whether device is self power. 1U supported, 0U not supported */
|
||||
#define USB_DEVICE_CONFIG_SELF_POWER (1U)
|
||||
@@ -17,7 +17,7 @@
|
||||
#define USB_DEVICE_CONFIG_REMOTE_WAKEUP (0U)
|
||||
|
||||
/*! @brief How many endpoints are supported in the stack. */
|
||||
#define USB_DEVICE_CONFIG_ENDPOINTS (4U)
|
||||
#define USB_DEVICE_CONFIG_ENDPOINTS (6U)
|
||||
|
||||
/*! @brief The MAX buffer length for the KHCI DMA workaround.*/
|
||||
#define USB_DEVICE_CONFIG_KHCI_DMA_ALIGN_BUFFER_LENGTH (64U)
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
#include "composite.h"
|
||||
#include "hid_keyboard.h"
|
||||
#include "hid_mouse.h"
|
||||
#include "hid_generic.h"
|
||||
|
||||
uint8_t UsbDeviceDescriptor[USB_DESCRIPTOR_LENGTH_DEVICE] = {
|
||||
USB_DESCRIPTOR_LENGTH_DEVICE,
|
||||
@@ -112,6 +113,50 @@ uint8_t UsbConfigurationDescriptor[USB_CONFIGURATION_DESCRIPTOR_TOTAL_LENGTH] =
|
||||
USB_SHORT_GET_LOW(USB_KEYBOARD_INTERRUPT_IN_PACKET_SIZE),
|
||||
USB_SHORT_GET_HIGH(USB_KEYBOARD_INTERRUPT_IN_PACKET_SIZE),
|
||||
USB_KEYBOARD_INTERRUPT_IN_INTERVAL,
|
||||
|
||||
// Generic HID interface descriptor
|
||||
|
||||
USB_DESCRIPTOR_LENGTH_INTERFACE,
|
||||
USB_DESCRIPTOR_TYPE_INTERFACE,
|
||||
USB_GENERIC_HID_INTERFACE_INDEX,
|
||||
USB_INTERFACE_ALTERNATE_SETTING_NONE,
|
||||
USB_GENERIC_HID_ENDPOINT_COUNT,
|
||||
USB_GENERIC_HID_CLASS,
|
||||
USB_GENERIC_HID_SUBCLASS,
|
||||
USB_GENERIC_HID_PROTOCOL,
|
||||
USB_STRING_DESCRIPTOR_ID_GENERIC_HID,
|
||||
|
||||
// Generic HID descriptor
|
||||
|
||||
USB_HID_DESCRIPTOR_LENGTH,
|
||||
USB_DESCRIPTOR_TYPE_HID,
|
||||
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_GENERIC_HID_REPORT_DESCRIPTOR_LENGTH),
|
||||
USB_SHORT_GET_HIGH(USB_GENERIC_HID_REPORT_DESCRIPTOR_LENGTH),
|
||||
|
||||
// Generic HID IN endpoint descriptor
|
||||
|
||||
USB_DESCRIPTOR_LENGTH_ENDPOINT,
|
||||
USB_DESCRIPTOR_TYPE_ENDPOINT,
|
||||
USB_GENERIC_HID_ENDPOINT_IN_ID | (USB_IN << USB_DESCRIPTOR_ENDPOINT_ADDRESS_DIRECTION_SHIFT),
|
||||
USB_ENDPOINT_INTERRUPT,
|
||||
USB_SHORT_GET_LOW(USB_GENERIC_HID_INTERRUPT_IN_PACKET_SIZE),
|
||||
USB_SHORT_GET_HIGH(USB_GENERIC_HID_INTERRUPT_IN_PACKET_SIZE),
|
||||
USB_GENERIC_HID_INTERRUPT_IN_INTERVAL,
|
||||
|
||||
// Generic HID OUT endpoint descriptor
|
||||
|
||||
USB_DESCRIPTOR_LENGTH_ENDPOINT,
|
||||
USB_DESCRIPTOR_TYPE_ENDPOINT,
|
||||
USB_GENERIC_HID_ENDPOINT_OUT_ID | (USB_OUT << USB_DESCRIPTOR_ENDPOINT_ADDRESS_DIRECTION_SHIFT),
|
||||
USB_ENDPOINT_INTERRUPT,
|
||||
USB_SHORT_GET_LOW(USB_GENERIC_HID_INTERRUPT_OUT_PACKET_SIZE),
|
||||
USB_SHORT_GET_HIGH(USB_GENERIC_HID_INTERRUPT_OUT_PACKET_SIZE),
|
||||
USB_GENERIC_HID_INTERRUPT_IN_INTERVAL,
|
||||
};
|
||||
|
||||
uint8_t UsbLanguageListStringDescriptor[USB_LANGUAGE_LIST_STRING_DESCRIPTOR_LENGTH] = {
|
||||
@@ -181,6 +226,7 @@ uint32_t UsbStringDescriptorLengths[USB_STRING_DESCRIPTOR_COUNT] = {
|
||||
sizeof(UsbProductString),
|
||||
sizeof(UsbMouseString),
|
||||
sizeof(UsbKeyboardString),
|
||||
sizeof(UsbGenericHidString),
|
||||
};
|
||||
|
||||
uint8_t *UsbStringDescriptors[USB_STRING_DESCRIPTOR_COUNT] = {
|
||||
@@ -189,6 +235,7 @@ uint8_t *UsbStringDescriptors[USB_STRING_DESCRIPTOR_COUNT] = {
|
||||
UsbProductString,
|
||||
UsbMouseString,
|
||||
UsbKeyboardString,
|
||||
UsbGenericHidString,
|
||||
};
|
||||
|
||||
usb_status_t USB_DeviceGetDeviceDescriptor(
|
||||
@@ -242,6 +289,9 @@ usb_status_t USB_DeviceGetHidReportDescriptor(
|
||||
} else if (USB_KEYBOARD_INTERFACE_INDEX == hidReportDescriptor->interfaceNumber) {
|
||||
hidReportDescriptor->buffer = UsbKeyboardReportDescriptor;
|
||||
hidReportDescriptor->length = USB_KEYBOARD_REPORT_DESCRIPTOR_LENGTH;
|
||||
} else if (USB_GENERIC_HID_INTERFACE_INDEX == hidReportDescriptor->interfaceNumber) {
|
||||
hidReportDescriptor->buffer = UsbGenericHidReportDescriptor;
|
||||
hidReportDescriptor->length = USB_GENERIC_HID_REPORT_DESCRIPTOR_LENGTH;
|
||||
} else {
|
||||
return kStatus_USB_InvalidRequest;
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
|
||||
#include "usb_keyboard_descriptors.h"
|
||||
#include "usb_mouse_descriptors.h"
|
||||
#include "usb_generic_hid_descriptors.h"
|
||||
|
||||
// Macros:
|
||||
|
||||
@@ -23,7 +24,7 @@
|
||||
#define USB_DEVICE_CONFIGURATION_COUNT (1U)
|
||||
#define USB_REPORT_DESCRIPTOR_COUNT_PER_HID_DEVICE (1U)
|
||||
#define USB_DEVICE_MAX_POWER (50U) // Expressed in 2mA units
|
||||
#define USB_COMPOSITE_INTERFACE_COUNT (USB_KEYBOARD_INTERFACE_COUNT + USB_MOUSE_INTERFACE_COUNT)
|
||||
#define USB_COMPOSITE_INTERFACE_COUNT (USB_KEYBOARD_INTERFACE_COUNT + USB_MOUSE_INTERFACE_COUNT + USB_GENERIC_HID_INTERFACE_COUNT)
|
||||
|
||||
#define USB_LANGUAGE_ID_UNITED_STATES (0x0409U)
|
||||
#define USB_HID_COUNTRY_CODE_NOT_SUPPORTED (0x00U)
|
||||
@@ -33,11 +34,11 @@
|
||||
// Descriptor lengths
|
||||
|
||||
#define USB_HID_DESCRIPTOR_LENGTH (9U)
|
||||
#define USB_CONFIGURATION_DESCRIPTOR_TOTAL_LENGTH (59U)
|
||||
#define USB_CONFIGURATION_DESCRIPTOR_TOTAL_LENGTH (91U)
|
||||
|
||||
// String descriptors
|
||||
|
||||
#define USB_STRING_DESCRIPTOR_COUNT (5U)
|
||||
#define USB_STRING_DESCRIPTOR_COUNT (6U)
|
||||
|
||||
#define USB_LANGUAGE_LIST_STRING_DESCRIPTOR_LENGTH (4U)
|
||||
#define USB_MANUFACTURER_STRING_DESCRIPTOR_LENGTH (58U)
|
||||
@@ -48,6 +49,7 @@
|
||||
#define USB_STRING_DESCRIPTOR_ID_PRODUCT 2U
|
||||
#define USB_STRING_DESCRIPTOR_ID_MOUSE 3U
|
||||
#define USB_STRING_DESCRIPTOR_ID_KEYBOARD 4U
|
||||
#define USB_STRING_DESCRIPTOR_ID_GENERIC_HID 5U
|
||||
|
||||
// Functions:
|
||||
|
||||
|
||||
92
right/usb_generic_hid_descriptors.c
Normal file
92
right/usb_generic_hid_descriptors.c
Normal file
@@ -0,0 +1,92 @@
|
||||
#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 "usb_generic_hid_descriptors.h"
|
||||
|
||||
static usb_device_endpoint_struct_t UsbGenericHidEndpoints[USB_GENERIC_HID_ENDPOINT_COUNT] =
|
||||
{
|
||||
{
|
||||
USB_GENERIC_HID_ENDPOINT_IN_ID | (USB_IN << USB_DESCRIPTOR_ENDPOINT_ADDRESS_DIRECTION_SHIFT),
|
||||
USB_ENDPOINT_INTERRUPT,
|
||||
USB_GENERIC_HID_INTERRUPT_IN_PACKET_SIZE,
|
||||
},
|
||||
{
|
||||
USB_GENERIC_HID_ENDPOINT_OUT_ID | (USB_OUT << USB_DESCRIPTOR_ENDPOINT_ADDRESS_DIRECTION_SHIFT),
|
||||
USB_ENDPOINT_INTERRUPT,
|
||||
USB_GENERIC_HID_INTERRUPT_OUT_PACKET_SIZE,
|
||||
}
|
||||
};
|
||||
|
||||
static usb_device_interface_struct_t UsbGenericHidInterface[] = {{
|
||||
USB_KEYBOARD_INTERFACE_ALTERNATE_SETTING,
|
||||
{USB_GENERIC_HID_ENDPOINT_COUNT, UsbGenericHidEndpoints},
|
||||
NULL,
|
||||
}};
|
||||
|
||||
static usb_device_interfaces_struct_t UsbGenericHidInterfaces[USB_GENERIC_HID_INTERFACE_COUNT] = {{
|
||||
USB_GENERIC_HID_CLASS,
|
||||
USB_GENERIC_HID_SUBCLASS,
|
||||
USB_GENERIC_HID_PROTOCOL,
|
||||
USB_GENERIC_HID_INTERFACE_INDEX,
|
||||
UsbGenericHidInterface,
|
||||
sizeof(UsbGenericHidInterface) / sizeof(usb_device_interfaces_struct_t),
|
||||
}};
|
||||
|
||||
static usb_device_interface_list_t UsbGenericHidInterfaceList[USB_DEVICE_CONFIGURATION_COUNT] = {{
|
||||
USB_GENERIC_HID_INTERFACE_COUNT,
|
||||
UsbGenericHidInterfaces,
|
||||
}};
|
||||
|
||||
usb_device_class_struct_t UsbGenericHidClass = {
|
||||
UsbGenericHidInterfaceList,
|
||||
kUSB_DeviceClassTypeHid,
|
||||
USB_DEVICE_CONFIGURATION_COUNT,
|
||||
};
|
||||
|
||||
uint8_t UsbGenericHidReportDescriptor[USB_GENERIC_HID_REPORT_DESCRIPTOR_LENGTH] = {
|
||||
0x05U, 0x81U, /* Usage Page (Vendor defined)*/
|
||||
0x09U, 0x82U, /* Usage (Vendor defined) */
|
||||
0xA1U, 0x01U, /* Collection (Application) */
|
||||
0x09U, 0x83U, /* Usage (Vendor defined) */
|
||||
|
||||
0x09U, 0x84U, /* Usage (Vendor defined) */
|
||||
0x15U, 0x80U, /* Logical Minimum (-128) */
|
||||
0x25U, 0x7FU, /* Logical Maximum (127) */
|
||||
0x75U, 0x08U, /* Report Size (8U) */
|
||||
0x95U, 0x08U, /* Report Count (8U) */
|
||||
0x81U, 0x02U, /* Input(Data, Variable, Absolute) */
|
||||
|
||||
0x09U, 0x84U, /* Usage (Vendor defined) */
|
||||
0x15U, 0x80U, /* logical Minimum (-128) */
|
||||
0x25U, 0x7FU, /* logical Maximum (127) */
|
||||
0x75U, 0x08U, /* Report Size (8U) */
|
||||
0x95U, 0x08U, /* Report Count (8U) */
|
||||
0x91U, 0x02U, /* Input (Data, Variable, Absolute) */
|
||||
0xC0U, /* End collection */
|
||||
};
|
||||
|
||||
uint8_t UsbGenericHidString[USB_GENERIC_HID_STRING_DESCRIPTOR_LENGTH] = {
|
||||
sizeof(UsbGenericHidString),
|
||||
USB_DESCRIPTOR_TYPE_STRING,
|
||||
'H', 0x00U,
|
||||
'I', 0x00U,
|
||||
'D', 0x00U,
|
||||
' ', 0x00U,
|
||||
'G', 0x00U,
|
||||
'E', 0x00U,
|
||||
'N', 0x00U,
|
||||
'E', 0x00U,
|
||||
'R', 0x00U,
|
||||
'I', 0x00U,
|
||||
'C', 0x00U,
|
||||
' ', 0x00U,
|
||||
'D', 0x00U,
|
||||
'E', 0x00U,
|
||||
'V', 0x00U,
|
||||
'I', 0x00U,
|
||||
'C', 0x00U,
|
||||
'E', 0x00U,
|
||||
};
|
||||
32
right/usb_generic_hid_descriptors.h
Normal file
32
right/usb_generic_hid_descriptors.h
Normal file
@@ -0,0 +1,32 @@
|
||||
#ifndef __USB_GENERIC_HID_DESCRIPTORS_H__
|
||||
#define __USB_GENERIC_HID_DESCRIPTORS_H__
|
||||
|
||||
// Macros:
|
||||
|
||||
#define USB_GENERIC_HID_CLASS (0x03U)
|
||||
#define USB_GENERIC_HID_SUBCLASS (0x00U)
|
||||
#define USB_GENERIC_HID_PROTOCOL (0x00U)
|
||||
|
||||
#define USB_GENERIC_HID_INTERFACE_INDEX (2U)
|
||||
#define USB_GENERIC_HID_INTERFACE_COUNT (1U)
|
||||
#define USB_GENERIC_HID_INTERFACE_ALTERNATE_SETTING (0U)
|
||||
|
||||
#define USB_GENERIC_HID_ENDPOINT_IN_ID (3U)
|
||||
#define USB_GENERIC_HID_ENDPOINT_OUT_ID (4U)
|
||||
#define USB_GENERIC_HID_ENDPOINT_COUNT (2U)
|
||||
|
||||
#define USB_GENERIC_HID_INTERRUPT_IN_PACKET_SIZE (64U)
|
||||
#define USB_GENERIC_HID_INTERRUPT_IN_INTERVAL (0x04U)
|
||||
#define USB_GENERIC_HID_INTERRUPT_OUT_PACKET_SIZE (64U)
|
||||
#define USB_GENERIC_HID_INTERRUPT_OUT_INTERVAL (0x04U)
|
||||
|
||||
#define USB_GENERIC_HID_REPORT_DESCRIPTOR_LENGTH (33U)
|
||||
#define USB_GENERIC_HID_STRING_DESCRIPTOR_LENGTH (38U)
|
||||
|
||||
// Variables:
|
||||
|
||||
extern usb_device_class_struct_t UsbGenericHidClass;
|
||||
extern uint8_t UsbGenericHidReportDescriptor[USB_GENERIC_HID_REPORT_DESCRIPTOR_LENGTH];
|
||||
extern uint8_t UsbGenericHidString[USB_GENERIC_HID_STRING_DESCRIPTOR_LENGTH];
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user