summaryrefslogtreecommitdiff
path: root/src/class/hid/hid_device.h
diff options
context:
space:
mode:
authorHa Thach <[email protected]>2020-10-09 00:28:13 +0700
committerGitHub <[email protected]>2020-10-09 00:28:13 +0700
commitc2a061288574a714679a996cd8dd086edfda55b2 (patch)
treee7898ad884ff11c0a8754de98190ecbe89ae0c0a /src/class/hid/hid_device.h
parent30c23719f6f2c10cb298bea3e5f4b0d5bbaeee70 (diff)
parenta4ba1f08275bc6fe8ce1f73d24f353861839cce7 (diff)
Merge pull request #524 from zlittell/f_MultipleHIDInterfaces
Feature multiple hid interfaces
Diffstat (limited to 'src/class/hid/hid_device.h')
-rw-r--r--src/class/hid/hid_device.h65
1 files changed, 57 insertions, 8 deletions
diff --git a/src/class/hid/hid_device.h b/src/class/hid/hid_device.h
index 1e584e4c9..4b8cb17d5 100644
--- a/src/class/hid/hid_device.h
+++ b/src/class/hid/hid_device.h
@@ -1,4 +1,4 @@
-/*
+/*
* The MIT License (MIT)
*
* Copyright (c) 2019 Ha Thach (tinyusb.org)
@@ -50,25 +50,35 @@
#endif
//--------------------------------------------------------------------+
-// Application API
+// Application API (Multiple Ports)
+// CFG_TUD_HID > 1
//--------------------------------------------------------------------+
// Check if the interface is ready to use
-bool tud_hid_ready(void);
+bool tud_hid_n_ready(uint8_t itf);
// Check if current mode is Boot (true) or Report (false)
-bool tud_hid_boot_mode(void);
+bool tud_hid_n_boot_mode(uint8_t itf);
// Send report to host
-bool tud_hid_report(uint8_t report_id, void const* report, uint8_t len);
+bool tud_hid_n_report(uint8_t itf, uint8_t report_id, void const* report, uint8_t len);
// KEYBOARD: convenient helper to send keyboard report if application
// use template layout report as defined by hid_keyboard_report_t
-bool tud_hid_keyboard_report(uint8_t report_id, uint8_t modifier, uint8_t keycode[6]);
+bool tud_hid_n_keyboard_report(uint8_t itf, uint8_t report_id, uint8_t modifier, uint8_t keycode[6]);
// MOUSE: convenient helper to send mouse report if application
// use template layout report as defined by hid_mouse_report_t
-bool tud_hid_mouse_report(uint8_t report_id, uint8_t buttons, int8_t x, int8_t y, int8_t vertical, int8_t horizontal);
+bool tud_hid_n_mouse_report(uint8_t itf, uint8_t report_id, uint8_t buttons, int8_t x, int8_t y, int8_t vertical, int8_t horizontal);
+
+//--------------------------------------------------------------------+
+// Application API (Single Port)
+//--------------------------------------------------------------------+
+static inline bool tud_hid_ready(void);
+static inline bool tud_hid_boot_mode(void);
+static inline bool tud_hid_report(uint8_t report_id, void const* report, uint8_t len);
+static inline bool tud_hid_keyboard_report(uint8_t report_id, uint8_t modifier, uint8_t keycode[6]);
+static inline bool tud_hid_mouse_report(uint8_t report_id, uint8_t buttons, int8_t x, int8_t y, int8_t vertical, int8_t horizontal);
//--------------------------------------------------------------------+
// Callbacks (Weak is optional)
@@ -76,16 +86,28 @@ bool tud_hid_mouse_report(uint8_t report_id, uint8_t buttons, int8_t x, int8_t y
// Invoked when received GET HID REPORT DESCRIPTOR request
// Application return pointer to descriptor, whose contents must exist long enough for transfer to complete
+#if CFG_TUD_HID>1
+uint8_t const * tud_hid_n_descriptor_report_cb(uint8_t itf);
+#else
uint8_t const * tud_hid_descriptor_report_cb(void);
+#endif
// Invoked when received GET_REPORT control request
// Application must fill buffer report's content and return its length.
// Return zero will cause the stack to STALL request
+#if CFG_TUD_HID>1
+uint16_t tud_hid_n_get_report_cb(uint8_t itf, uint8_t report_id, hid_report_type_t report_type, uint8_t* buffer, uint16_t reqlen);
+#else
uint16_t tud_hid_get_report_cb(uint8_t report_id, hid_report_type_t report_type, uint8_t* buffer, uint16_t reqlen);
+#endif
// Invoked when received SET_REPORT control request or
// received data on OUT endpoint ( Report ID = 0, Type = 0 )
+#if CFG_TUD_HID>1
+void tud_hid_n_set_report_cb(uint8_t itf, uint8_t report_id, hid_report_type_t report_type, uint8_t const* buffer, uint16_t bufsize);
+#else
void tud_hid_set_report_cb(uint8_t report_id, hid_report_type_t report_type, uint8_t const* buffer, uint16_t bufsize);
+#endif
// Invoked when received SET_PROTOCOL request ( mode switch Boot <-> Report )
TU_ATTR_WEAK void tud_hid_boot_mode_cb(uint8_t boot_mode);
@@ -95,6 +117,34 @@ TU_ATTR_WEAK void tud_hid_boot_mode_cb(uint8_t boot_mode);
// - Idle Rate > 0 : skip duplication, but send at least 1 report every idle rate (in unit of 4 ms).
TU_ATTR_WEAK bool tud_hid_set_idle_cb(uint8_t idle_rate);
+//--------------------------------------------------------------------+
+// Inline Functions
+//--------------------------------------------------------------------+
+static inline bool tud_hid_ready(void)
+{
+ return tud_hid_n_ready(0);
+}
+
+static inline bool tud_hid_boot_mode(void)
+{
+ return tud_hid_n_boot_mode(0);
+}
+
+static inline bool tud_hid_report(uint8_t report_id, void const* report, uint8_t len)
+{
+ return tud_hid_n_report(0, report_id, report, len);
+}
+
+static inline bool tud_hid_keyboard_report(uint8_t report_id, uint8_t modifier, uint8_t keycode[6])
+{
+ return tud_hid_n_keyboard_report(0, report_id, modifier, keycode);
+}
+
+static inline bool tud_hid_mouse_report(uint8_t report_id, uint8_t buttons, int8_t x, int8_t y, int8_t vertical, int8_t horizontal)
+{
+ return tud_hid_n_mouse_report(0, report_id, buttons, x, y, vertical, horizontal);
+}
+
/* --------------------------------------------------------------------+
* HID Report Descriptor Template
*
@@ -318,4 +368,3 @@ bool hidd_xfer_cb (uint8_t rhport, uint8_t ep_addr, xfer_result_t e
#endif
#endif /* _TUSB_HID_DEVICE_H_ */
-