summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorhathach <thach@tinyusb.org>2018-07-31 21:57:00 +0700
committerhathach <thach@tinyusb.org>2018-07-31 21:57:00 +0700
commit2c85f423307fcb0c685b949567a74e6d64c4b131 (patch)
tree55049b8b2c68377fff9a08af27f42f9fde977eaf
parentef58adacd3a37c0df37bf0f1f2b9568e70c163f8 (diff)
add usb hid syscontrol
-rw-r--r--ports/nrf/common-hal/usb_hid/Device.h21
-rw-r--r--ports/nrf/common-hal/usb_hid/__init__.c32
-rw-r--r--ports/nrf/usb/usb_desc.c12
3 files changed, 39 insertions, 26 deletions
diff --git a/ports/nrf/common-hal/usb_hid/Device.h b/ports/nrf/common-hal/usb_hid/Device.h
index b6a832f5c..98328fab9 100644
--- a/ports/nrf/common-hal/usb_hid/Device.h
+++ b/ports/nrf/common-hal/usb_hid/Device.h
@@ -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;
diff --git a/ports/nrf/common-hal/usb_hid/__init__.c b/ports/nrf/common-hal/usb_hid/__init__.c
index 536ad07fa..304c6a054 100644
--- a/ports/nrf/common-hal/usb_hid/__init__.c
+++ b/ports/nrf/common-hal/usb_hid/__init__.c
@@ -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,
diff --git a/ports/nrf/usb/usb_desc.c b/ports/nrf/usb/usb_desc.c
index 54d313367..b332ebc1b 100644
--- a/ports/nrf/usb/usb_desc.c
+++ b/ports/nrf/usb/usb_desc.c
@@ -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 =