add usb hid syscontrol

This commit is contained in:
hathach 2018-07-31 21:57:00 +07:00
parent ef58adacd3
commit 2c85f42330
3 changed files with 39 additions and 26 deletions

View File

@ -37,10 +37,12 @@
#endif
// 1 to enable device, 0 to disable
#define USB_HID_DEVICE_KEYBOARD 1
#define USB_HID_DEVICE_MOUSE 1
#define USB_HID_DEVICE_CONSUMER 1
#define USB_HID_DEVICE_GAMEPAD 0
#define USB_HID_DEVICE_KEYBOARD 1
#define USB_HID_DEVICE_MOUSE 1
#define USB_HID_DEVICE_CONSUMER 1
#define USB_HID_DEVICE_SYS_CONTROL 1
#define USB_HID_DEVICE_GAMEPAD 0
#define USB_HID_DEVICE_DIGITIZER 0
enum {
USB_HID_REPORT_ID_UNUSED = 0,
@ -57,12 +59,21 @@ enum {
USB_HID_REPORT_ID_CONSUMER,
#endif
#if USB_HID_DEVICE_SYS_CONTROL
USB_HID_REPORT_ID_SYS_CONTROL,
#endif
#if USB_HID_DEVICE_GAMEPAD
USB_HID_REPORT_ID_GAMEPAD,
#endif
#if USB_HID_DEVICE_DIGITIZER
USB_HID_REPORT_ID_DIGITIZER,
#endif
};
#define USB_HID_NUM_DEVICES (USB_HID_DEVICE_KEYBOARD + USB_HID_DEVICE_MOUSE + USB_HID_DEVICE_CONSUMER + USB_HID_DEVICE_GAMEPAD )
#define USB_HID_NUM_DEVICES (USB_HID_DEVICE_KEYBOARD + USB_HID_DEVICE_MOUSE + USB_HID_DEVICE_CONSUMER + \
USB_HID_REPORT_ID_SYS_CONTROL + USB_HID_DEVICE_GAMEPAD + USB_HID_DEVICE_DIGITIZER )
typedef struct {
mp_obj_base_t base;

View File

@ -32,9 +32,10 @@
#include "shared-bindings/usb_hid/Device.h"
#include "tusb.h"
#define USB_HID_REPORT_LENGTH_KEYBOARD 8
#define USB_HID_REPORT_LENGTH_MOUSE 4
#define USB_HID_REPORT_LENGTH_CONSUMER 2
#define USB_HID_REPORT_LENGTH_KEYBOARD 8
#define USB_HID_REPORT_LENGTH_MOUSE 4
#define USB_HID_REPORT_LENGTH_CONSUMER 2
#define USB_HID_REPORT_LENGTH_SYS_CONTROL 1
#if USB_HID_DEVICE_KEYBOARD
static uint8_t keyboard_report_buffer[USB_HID_REPORT_LENGTH_KEYBOARD];
@ -48,19 +49,19 @@ static uint8_t mouse_report_buffer[USB_HID_REPORT_LENGTH_MOUSE];
static uint8_t consumer_report_buffer[USB_HID_REPORT_LENGTH_CONSUMER];
#endif
#ifdef USB_HID_REPORT_ID_SYS_CONTROL
#if USB_HID_DEVICE_SYS_CONTROL
static uint8_t sys_control_report_buffer[USB_HID_REPORT_LENGTH_SYS_CONTROL];
#endif
#ifdef USB_HID_REPORT_ID_GAMEPAD
#if USB_HID_DEVICE_GAMEPAD
static uint8_t gamepad_report_buffer[USB_HID_REPORT_LENGTH_GAMEPAD];
#endif
#ifdef USB_HID_REPORT_ID_DIGITIZER
#if USB_HID_DEVICE_DIGITIZER
static uint8_t digitizer_report_buffer[USB_HID_REPORT_LENGTH_DIGITIZER];
#endif
usb_hid_device_obj_t usb_hid_devices[USB_HID_NUM_DEVICES] = {
usb_hid_device_obj_t usb_hid_devices[] = {
#if USB_HID_DEVICE_KEYBOARD
{
.base = { .type = &usb_hid_device_type },
@ -94,31 +95,32 @@ usb_hid_device_obj_t usb_hid_devices[USB_HID_NUM_DEVICES] = {
},
#endif
#ifdef USB_HID_REPORT_ID_SYS_CONTROL
#if USB_HID_DEVICE_SYS_CONTROL
{
.base = { .type = &usb_hid_device_type },
.report_buffer = sys_control_report_buffer,
.report_id = USB_HID_REPORT_ID_SYS_CONTROL,
.report_length = USB_HID_REPORT_LENGTH_SYS_CONTROL,
.usage_page = 0x01,
.usage = 0x80,
.usage_page = HID_USAGE_PAGE_DESKTOP,
.usage = HID_USAGE_DESKTOP_SYSTEM_CONTROL,
},
#endif
#ifdef USB_HID_REPORT_ID_GAMEPAD
#if USB_HID_DEVICE_GAMEPAD
{
.base = { .type = &usb_hid_device_type },
.report_buffer = gamepad_report_buffer,
.report_id = USB_HID_REPORT_ID_GAMEPAD,
.report_length = USB_HID_REPORT_LENGTH_GAMEPAD,
.usage_page = 0x01,
.usage = 0x05,
.usage_page = HID_USAGE_PAGE_DESKTOP,
.usage = HID_USAGE_DESKTOP_GAMEPAD,
},
#endif
#ifdef USB_HID_REPORT_ID_DIGITIZER
#if USB_HID_DEVICE_DIGITIZER
{
.base = { .type = &usb_hid_device_type },
.report_buffer = digitizer_report_buffer,
.endpoint = USB_HID_ENDPOINT_IN,
.report_id = USB_HID_REPORT_ID_DIGITIZER,
.report_length = USB_HID_REPORT_LENGTH_DIGITIZER,
.usage_page = 0x0D,

View File

@ -136,9 +136,6 @@ tusb_desc_device_t const usb_desc_dev =
//--------------------------------------------------------------------+
// HID Report Descriptor
//--------------------------------------------------------------------+
// TODO remove const for dynamic descriptors
uint8_t const usb_desc_hid_generic_report[] =
{
#if USB_HID_DEVICE_KEYBOARD
@ -150,15 +147,18 @@ uint8_t const usb_desc_hid_generic_report[] =
#endif
#if USB_HID_DEVICE_CONSUMER
HID_REPORT_DESC_CONSUMER( HID_REPORT_ID(USB_HID_REPORT_ID_CONSUMER), )
HID_REPORT_DESC_CONSUMER( HID_REPORT_ID(USB_HID_REPORT_ID_CONSUMER), ),
#endif
};
#if USB_HID_DEVICE_SYS_CONTROL
HID_REPORT_DESC_SYSTEM_CONTROL( HID_REPORT_ID(USB_HID_REPORT_ID_SYS_CONTROL ), ),
#endif
};
//--------------------------------------------------------------------+
// Configuration Descriptor
//--------------------------------------------------------------------+
// TODO remove const for dynamic descriptors
usb_desc_cfg_t const usb_desc_cfg =
{
.config =