Add usb_keyboard_descriptors.[ch] which I forgot to add.

This commit is contained in:
László Monda
2016-02-25 07:56:47 +01:00
parent cfb1135aac
commit 08239ac72d
2 changed files with 144 additions and 0 deletions

View File

@@ -0,0 +1,117 @@
#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_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
};
uint8_t g_UsbKeyboardString[USB_KEYBOARD_STRING_DESCRIPTOR_LENGTH] = {
sizeof(g_UsbKeyboardString),
USB_DESCRIPTOR_TYPE_STRING,
'H', 0x00U,
'I', 0x00U,
'D', 0x00U,
' ', 0x00U,
'K', 0x00U,
'E', 0x00U,
'Y', 0x00U,
'B', 0x00U,
'O', 0x00U,
'A', 0x00U,
'R', 0x00U,
'D', 0x00U,
' ', 0x00U,
'D', 0x00U,
'E', 0x00U,
'V', 0x00U,
'I', 0x00U,
'C', 0x00U,
'E', 0x00U,
};

View File

@@ -0,0 +1,27 @@
#ifndef __USB_KEYBOARD_DESCRIPTORS_H__
#define __USB_KEYBOARD_DESCRIPTORS_H__
// Macros:
#define USB_HID_KEYBOARD_INTERFACE_COUNT (1U)
#define USB_DESCRIPTOR_LENGTH_HID_KEYBOARD_REPORT (63U)
#define USB_KEYBOARD_STRING_DESCRIPTOR_LENGTH (40U)
#define USB_KEYBOARD_INTERFACE_ALTERNATE_SETTING (0U)
#define USB_HID_KEYBOARD_ENDPOINT_IN (2U)
#define FS_HID_KEYBOARD_INTERRUPT_IN_PACKET_SIZE (8U)
#define USB_HID_KEYBOARD_ENDPOINT_COUNT (1U)
#define USB_HID_KEYBOARD_CLASS (0x03U)
#define USB_HID_KEYBOARD_SUBCLASS (0x01U)
#define USB_HID_KEYBOARD_PROTOCOL (0x01U)
#define USB_HID_KEYBOARD_INTERFACE_INDEX (1U)
#define USB_HID_KEYBOARD_IN_BUFFER_LENGTH (8U)
#define FS_HID_KEYBOARD_INTERRUPT_IN_INTERVAL (0x04U)
#define USB_HID_KEYBOARD_REPORT_LENGTH (0x08U)
// Variables:
extern uint8_t g_UsbKeyboardString[USB_KEYBOARD_STRING_DESCRIPTOR_LENGTH];
extern usb_device_class_struct_t UsbKeyboardClass;
extern uint8_t UsbKeyboardReportDescriptor[USB_DESCRIPTOR_LENGTH_HID_KEYBOARD_REPORT];
#endif