From e163f85ee024ff366253478cfd20e3fc35e96819 Mon Sep 17 00:00:00 2001 From: hathach Date: Tue, 18 May 2021 12:32:20 +0700 Subject: clean up, rename some HID device symbol/API - add tud_hid_n_interface_protocol() - rename tud_hid_n_boot_mode() to tud_hid_n_get_protocol() - rename tud_hid_boot_mode_cb() to tud_hid_set_protocol_cb() - add HID_PROTOCOL_BOOT/REPORT to avoid magic number 0,1 - rename HID_PROTOCOL_NONE/KEYBOARD/MOUSE to HID_ITF_PROTOCOL_ to avoid confusion --- src/class/hid/hid.h | 29 ++++++++++++++++++----------- 1 file changed, 18 insertions(+), 11 deletions(-) (limited to 'src/class/hid/hid.h') diff --git a/src/class/hid/hid.h b/src/class/hid/hid.h index 351a4d600..6014e54a6 100644 --- a/src/class/hid/hid.h +++ b/src/class/hid/hid.h @@ -62,15 +62,15 @@ typedef enum { HID_SUBCLASS_NONE = 0, ///< No Subclass HID_SUBCLASS_BOOT = 1 ///< Boot Interface Subclass -}hid_subclass_type_t; +}hid_subclass_enum_t; -/// HID Protocol +/// HID Interface Protocol typedef enum { - HID_PROTOCOL_NONE = 0, ///< None - HID_PROTOCOL_KEYBOARD = 1, ///< Keyboard - HID_PROTOCOL_MOUSE = 2 ///< Mouse -}hid_protocol_type_t; + HID_ITF_PROTOCOL_NONE = 0, ///< None + HID_ITF_PROTOCOL_KEYBOARD = 1, ///< Keyboard + HID_ITF_PROTOCOL_MOUSE = 2 ///< Mouse +}hid_interface_protocol_enum_t; /// HID Descriptor Type typedef enum @@ -78,7 +78,7 @@ typedef enum HID_DESC_TYPE_HID = 0x21, ///< HID Descriptor HID_DESC_TYPE_REPORT = 0x22, ///< Report Descriptor HID_DESC_TYPE_PHYSICAL = 0x23 ///< Physical Descriptor -}hid_descriptor_type_t; +}hid_descriptor_enum_t; /// HID Request Report Type typedef enum @@ -87,7 +87,7 @@ typedef enum HID_REPORT_TYPE_INPUT, ///< Input HID_REPORT_TYPE_OUTPUT, ///< Output HID_REPORT_TYPE_FEATURE ///< Feature -}hid_report_type_t; +}hid_report_enum_t; /// HID Class Specific Control Request typedef enum @@ -98,9 +98,9 @@ typedef enum HID_REQ_CONTROL_SET_REPORT = 0x09, ///< Set Report HID_REQ_CONTROL_SET_IDLE = 0x0a, ///< Set Idle HID_REQ_CONTROL_SET_PROTOCOL = 0x0b ///< Set Protocol -}hid_request_type_t; +}hid_request_enum_t; -/// HID Country Code +/// HID Local Code typedef enum { HID_LOCAL_NotSupported = 0 , ///< NotSupported @@ -139,7 +139,14 @@ typedef enum HID_LOCAL_US , ///< US HID_LOCAL_Yugoslavia , ///< Yugoslavia HID_LOCAL_Turkish_F ///< Turkish-F -} hid_country_code_t; +} hid_local_enum_t; + +// HID protocol value used by GetProtocol / SetProtocol +enum +{ + HID_PROTOCOL_BOOT = 0, + HID_PROTOCOL_REPORT = 1 +}; /** @} */ -- cgit v1.3.1 From 7e9e682e09c2629a9575343e4efaf43d328bde33 Mon Sep 17 00:00:00 2001 From: hathach Date: Tue, 18 May 2021 12:38:11 +0700 Subject: update to use HID spec protocol value for get/set_protocol() --- src/class/hid/hid.h | 4 ++-- src/class/hid/hid_device.c | 6 +++--- src/class/hid/hid_device.h | 11 ++++++----- 3 files changed, 11 insertions(+), 10 deletions(-) (limited to 'src/class/hid/hid.h') diff --git a/src/class/hid/hid.h b/src/class/hid/hid.h index 6014e54a6..5c30f7585 100644 --- a/src/class/hid/hid.h +++ b/src/class/hid/hid.h @@ -142,11 +142,11 @@ typedef enum } hid_local_enum_t; // HID protocol value used by GetProtocol / SetProtocol -enum +typedef enum { HID_PROTOCOL_BOOT = 0, HID_PROTOCOL_REPORT = 1 -}; +} hid_protocol_mode_enum_t; /** @} */ diff --git a/src/class/hid/hid_device.c b/src/class/hid/hid_device.c index 62d63e30a..4d33c85d3 100644 --- a/src/class/hid/hid_device.c +++ b/src/class/hid/hid_device.c @@ -112,7 +112,7 @@ uint8_t tud_hid_n_interface_protocol(uint8_t instance) bool tud_hid_n_get_protocol(uint8_t instance) { - return _hidd_itf[instance].boot_mode; + return _hidd_itf[instance].boot_mode ? HID_PROTOCOL_BOOT : HID_PROTOCOL_REPORT; } bool tud_hid_n_keyboard_report(uint8_t instance, uint8_t report_id, uint8_t modifier, uint8_t keycode[6]) @@ -334,14 +334,14 @@ bool hidd_control_xfer_cb (uint8_t rhport, uint8_t stage, tusb_control_request_t case HID_REQ_CONTROL_SET_PROTOCOL: if ( stage == CONTROL_STAGE_SETUP ) { - p_hid->boot_mode = (request->wValue == HID_PROTOCOL_BOOT); tud_control_status(rhport, request); } else if ( stage == CONTROL_STAGE_ACK ) { + p_hid->boot_mode = (request->wValue == HID_PROTOCOL_BOOT); if (tud_hid_set_protocol_cb) { - tud_hid_set_protocol_cb(hid_itf, p_hid->boot_mode); + tud_hid_set_protocol_cb(hid_itf, (uint8_t) request->wValue); } } break; diff --git a/src/class/hid/hid_device.h b/src/class/hid/hid_device.h index cc34f19ac..2cc4a9546 100644 --- a/src/class/hid/hid_device.h +++ b/src/class/hid/hid_device.h @@ -60,8 +60,8 @@ bool tud_hid_n_ready(uint8_t instance); // Get interface supported protocol (bInterfaceProtocol) check out hid_interface_protocol_enum_t for possible value uint8_t tud_hid_n_interface_protocol(uint8_t instance); -// Check if active protocol is Boot (true) or Report (false) -bool tud_hid_n_get_protocol(uint8_t instance); +// Get current active protocol: HID_PROTOCOL_BOOT (0) or HID_PROTOCOL_REPORT (1) +uint8_t tud_hid_n_get_protocol(uint8_t instance); // Send report to host bool tud_hid_n_report(uint8_t instance, uint8_t report_id, void const* report, uint8_t len); @@ -83,7 +83,7 @@ bool tud_hid_n_gamepad_report(uint8_t instance, uint8_t report_id, int8_t x, int //--------------------------------------------------------------------+ static inline bool tud_hid_ready(void); static inline uint8_t tud_hid_interface_protocol(void); -static inline bool tud_hid_get_protocol(void); +static inline uint8_t tud_hid_get_protocol(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); @@ -106,8 +106,9 @@ uint16_t tud_hid_get_report_cb(uint8_t instance, uint8_t report_id, hid_report_t // received data on OUT endpoint ( Report ID = 0, Type = 0 ) void tud_hid_set_report_cb(uint8_t instance, uint8_t report_id, hid_report_type_t report_type, uint8_t const* buffer, uint16_t bufsize); -// Invoked when received SET_PROTOCOL request ( mode switch Boot <-> Report ) -TU_ATTR_WEAK void tud_hid_set_protocol_cb(uint8_t instance, bool boot_mode); +// Invoked when received SET_PROTOCOL request +// protocol is either HID_PROTOCOL_BOOT (0) or HID_PROTOCOL_REPORT (1) +TU_ATTR_WEAK void tud_hid_set_protocol_cb(uint8_t instance, uint8_t protocol); // Invoked when received SET_IDLE request. return false will stall the request // - Idle Rate = 0 : only send report if there is changes, i.e skip duplication -- cgit v1.3.1 From a26752a93e56b2fb2d683e5a9f9934b432531d9b Mon Sep 17 00:00:00 2001 From: hathach Date: Tue, 18 May 2021 12:45:59 +0700 Subject: fix build error --- src/class/hid/hid.h | 2 +- src/class/hid/hid_device.c | 2 +- src/class/hid/hid_device.h | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) (limited to 'src/class/hid/hid.h') diff --git a/src/class/hid/hid.h b/src/class/hid/hid.h index 5c30f7585..c63b6f00b 100644 --- a/src/class/hid/hid.h +++ b/src/class/hid/hid.h @@ -87,7 +87,7 @@ typedef enum HID_REPORT_TYPE_INPUT, ///< Input HID_REPORT_TYPE_OUTPUT, ///< Output HID_REPORT_TYPE_FEATURE ///< Feature -}hid_report_enum_t; +}hid_report_type_t; /// HID Class Specific Control Request typedef enum diff --git a/src/class/hid/hid_device.c b/src/class/hid/hid_device.c index 4d33c85d3..ab9ef3ad8 100644 --- a/src/class/hid/hid_device.c +++ b/src/class/hid/hid_device.c @@ -110,7 +110,7 @@ uint8_t tud_hid_n_interface_protocol(uint8_t instance) return _hidd_itf[instance].itf_protocol; } -bool tud_hid_n_get_protocol(uint8_t instance) +uint8_t tud_hid_n_get_protocol(uint8_t instance) { return _hidd_itf[instance].boot_mode ? HID_PROTOCOL_BOOT : HID_PROTOCOL_REPORT; } diff --git a/src/class/hid/hid_device.h b/src/class/hid/hid_device.h index 2cc4a9546..b3701c7e0 100644 --- a/src/class/hid/hid_device.h +++ b/src/class/hid/hid_device.h @@ -134,7 +134,7 @@ static inline uint8_t tud_hid_interface_protocol(void) return tud_hid_n_interface_protocol(0); } -static inline bool tud_hid_get_protocol(void) +static inline uint8_t tud_hid_get_protocol(void) { return tud_hid_n_get_protocol(0); } @@ -156,7 +156,7 @@ static inline bool tud_hid_mouse_report(uint8_t report_id, uint8_t buttons, int8 static inline bool tud_hid_gamepad_report(uint8_t report_id, int8_t x, int8_t y, int8_t z, int8_t rz, int8_t rx, int8_t ry, uint8_t hat, uint16_t buttons) { - return tud_hid_n_gamepad_report(0, x, y, z, rz, rx, ry, hat, buttons); + return tud_hid_n_gamepad_report(0, report_id, x, y, z, rz, rx, ry, hat, buttons); } /* --------------------------------------------------------------------+ -- cgit v1.3.1