diff options
| author | hathach <thach@tinyusb.org> | 2018-07-31 21:06:24 +0700 |
|---|---|---|
| committer | hathach <thach@tinyusb.org> | 2018-07-31 21:06:24 +0700 |
| commit | fd661c1d57ebf4090e8fd37db9a6a01358ce6a46 (patch) | |
| tree | 4d4120d4beb5f5f815cbc136c6191675c475d213 | |
| parent | 27b2a9fe5959893a87f83944f7f6755298333e52 (diff) | |
improve usb hid
| -rw-r--r-- | ports/nrf/common-hal/usb_hid/Device.h | 30 | ||||
| -rw-r--r-- | ports/nrf/common-hal/usb_hid/__init__.c | 40 | ||||
| -rw-r--r-- | ports/nrf/usb/usb_desc.c | 9 |
3 files changed, 55 insertions, 24 deletions
diff --git a/ports/nrf/common-hal/usb_hid/Device.h b/ports/nrf/common-hal/usb_hid/Device.h index 291bc963c..a0d26fd31 100644 --- a/ports/nrf/common-hal/usb_hid/Device.h +++ b/ports/nrf/common-hal/usb_hid/Device.h @@ -36,11 +36,33 @@ extern "C" { #endif -#define USB_HID_NUM_DEVICES 2 +// 1 to enable device, 0 to disable +#define USB_HID_DEVICE_KEYBOARD 1 +#define USB_HID_DEVICE_MOUSE 1 +#define USB_HID_DEVICE_CONSUMER 0 +#define USB_HID_DEVICE_GAMEPAD 0 -#define USB_HID_REPORT_ID_KEYBOARD 1 -#define USB_HID_REPORT_ID_MOUSE 2 -//#define USB_HID_REPORT_ID_CONSUMER 3 +enum { + USB_HID_REPORT_ID_UNUSED = 0, + +#if USB_HID_DEVICE_KEYBOARD + USB_HID_REPORT_ID_KEYBOARD, +#endif + +#if USB_HID_DEVICE_MOUSE + USB_HID_REPORT_ID_MOUSE, +#endif + +#if USB_HID_DEVICE_CONSUMER + USB_HID_REPORT_ID_CONSUMER, +#endif + +#if USB_HID_DEVICE_GAMEPAD + USB_HID_REPORT_ID_GAMEPAD, +#endif +}; + +#define USB_HID_NUM_DEVICES (USB_HID_DEVICE_KEYBOARD + USB_HID_DEVICE_MOUSE + USB_HID_DEVICE_CONSUMER + USB_HID_DEVICE_GAMEPAD ) typedef struct { mp_obj_base_t base; diff --git a/ports/nrf/common-hal/usb_hid/__init__.c b/ports/nrf/common-hal/usb_hid/__init__.c index 9ebf041ab..0c637e63c 100644 --- a/ports/nrf/common-hal/usb_hid/__init__.c +++ b/ports/nrf/common-hal/usb_hid/__init__.c @@ -31,53 +31,58 @@ #include "common-hal/usb_hid/Device.h" #include "shared-bindings/usb_hid/Device.h" -#define USB_HID_REPORT_LENGTH_KEYBOARD 8 -#define USB_HID_REPORT_LENGTH_MOUSE 4 +#define USB_HID_REPORT_LENGTH_KEYBOARD 8 +#define USB_HID_REPORT_LENGTH_MOUSE 4 +#define USB_HID_REPORT_LENGTH_CONSUMER 2 -// Buffers are report size + 1 to include the Report ID prefix byte if needed. -#ifdef USB_HID_REPORT_ID_KEYBOARD -static uint8_t keyboard_report_buffer[USB_HID_REPORT_LENGTH_KEYBOARD + 1]; +#if USB_HID_DEVICE_KEYBOARD +static uint8_t keyboard_report_buffer[USB_HID_REPORT_LENGTH_KEYBOARD]; #endif -#ifdef USB_HID_REPORT_ID_MOUSE -static uint8_t mouse_report_buffer[USB_HID_REPORT_LENGTH_MOUSE + 1]; + +#if USB_HID_DEVICE_MOUSE +static uint8_t mouse_report_buffer[USB_HID_REPORT_LENGTH_MOUSE]; #endif -#ifdef USB_HID_REPORT_ID_CONSUMER -static uint8_t consumer_report_buffer[USB_HID_REPORT_LENGTH_CONSUMER + 1]; + +#if USB_HID_DEVICE_CONSUMER +static uint8_t consumer_report_buffer[USB_HID_REPORT_LENGTH_CONSUMER]; #endif + #ifdef USB_HID_REPORT_ID_SYS_CONTROL -static uint8_t sys_control_report_buffer[USB_HID_REPORT_LENGTH_SYS_CONTROL + 1]; +static uint8_t sys_control_report_buffer[USB_HID_REPORT_LENGTH_SYS_CONTROL]; #endif + #ifdef USB_HID_REPORT_ID_GAMEPAD -static uint8_t gamepad_report_buffer[USB_HID_REPORT_LENGTH_GAMEPAD + 1]; +static uint8_t gamepad_report_buffer[USB_HID_REPORT_LENGTH_GAMEPAD]; #endif + #ifdef USB_HID_REPORT_ID_DIGITIZER -static uint8_t digitizer_report_buffer[USB_HID_REPORT_LENGTH_DIGITIZER + 1]; +static uint8_t digitizer_report_buffer[USB_HID_REPORT_LENGTH_DIGITIZER]; #endif usb_hid_device_obj_t usb_hid_devices[USB_HID_NUM_DEVICES] = { -#ifdef USB_HID_REPORT_ID_KEYBOARD +#if USB_HID_DEVICE_KEYBOARD { .base = { .type = &usb_hid_device_type }, .report_buffer = keyboard_report_buffer, -// .endpoint = USB_HID_ENDPOINT_IN, .report_id = USB_HID_REPORT_ID_KEYBOARD, .report_length = USB_HID_REPORT_LENGTH_KEYBOARD, .usage_page = 0x01, .usage = 0x06, }, #endif -#ifdef USB_HID_REPORT_ID_MOUSE + +#if USB_HID_DEVICE_MOUSE { .base = { .type = &usb_hid_device_type }, .report_buffer = mouse_report_buffer, -// .endpoint = USB_HID_ENDPOINT_IN, .report_id = USB_HID_REPORT_ID_MOUSE, .report_length = USB_HID_REPORT_LENGTH_MOUSE, .usage_page = 0x01, .usage = 0x02, }, #endif -#ifdef USB_HID_REPORT_ID_CONSUMER + +#if USB_HID_DEVICE_CONSUMER { .base = { .type = &usb_hid_device_type }, .report_buffer = consumer_report_buffer, @@ -88,6 +93,7 @@ usb_hid_device_obj_t usb_hid_devices[USB_HID_NUM_DEVICES] = { .usage = 0x01, }, #endif + #ifdef USB_HID_REPORT_ID_SYS_CONTROL { .base = { .type = &usb_hid_device_type }, diff --git a/ports/nrf/usb/usb_desc.c b/ports/nrf/usb/usb_desc.c index 1e3e8b2c2..07d8c837d 100644 --- a/ports/nrf/usb/usb_desc.c +++ b/ports/nrf/usb/usb_desc.c @@ -141,14 +141,17 @@ tusb_desc_device_t const usb_desc_dev = uint8_t const usb_desc_hid_generic_report[] = { -#if USB_HID_REPORT_ID_KEYBOARD +#if USB_HID_DEVICE_KEYBOARD HID_REPORT_DESC_KEYBOARD( HID_REPORT_ID(USB_HID_REPORT_ID_KEYBOARD), ), #endif -#if USB_HID_REPORT_ID_MOUSE - HID_REPORT_DESC_MOUSE( HID_REPORT_ID(USB_HID_REPORT_ID_MOUSE), ) +#if USB_HID_DEVICE_MOUSE + HID_REPORT_DESC_MOUSE( HID_REPORT_ID(USB_HID_REPORT_ID_MOUSE), ), #endif +#if USB_HID_DEVICE_CONSUMER + HID_REPORT_DESC_MOUSE( HID_REPORT_ID(USB_HID_REPORT_ID_CONSUMER), ) +#endif }; |
