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
This commit is contained in:
		| @@ -55,34 +55,39 @@ | ||||
| //--------------------------------------------------------------------+ | ||||
|  | ||||
| // Check if the interface is ready to use | ||||
| bool tud_hid_n_ready(uint8_t itf); | ||||
| bool tud_hid_n_ready(uint8_t instance); | ||||
|  | ||||
| // Check if current mode is Boot (true) or Report (false) | ||||
| bool tud_hid_n_boot_mode(uint8_t itf); | ||||
| // 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); | ||||
|  | ||||
| // Send report to host | ||||
| bool tud_hid_n_report(uint8_t itf, uint8_t report_id, void const* report, uint8_t len); | ||||
| bool tud_hid_n_report(uint8_t instance, 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_n_keyboard_report(uint8_t itf, uint8_t report_id, uint8_t modifier, uint8_t keycode[6]); | ||||
| bool tud_hid_n_keyboard_report(uint8_t instance, 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_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); | ||||
| bool tud_hid_n_mouse_report(uint8_t instance, uint8_t report_id, uint8_t buttons, int8_t x, int8_t y, int8_t vertical, int8_t horizontal); | ||||
|  | ||||
| // Gamepad: convenient helper to send mouse report if application | ||||
| // use template layout report TUD_HID_REPORT_DESC_GAMEPAD | ||||
| bool tud_hid_n_gamepad_report(uint8_t itf, 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); | ||||
| bool tud_hid_n_gamepad_report(uint8_t instance, 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); | ||||
|  | ||||
| //--------------------------------------------------------------------+ | ||||
| // 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); | ||||
| 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 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); | ||||
| 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); | ||||
|  | ||||
| //--------------------------------------------------------------------+ | ||||
| // Callbacks (Weak is optional) | ||||
| @@ -90,29 +95,29 @@ static inline bool tud_hid_mouse_report(uint8_t report_id, uint8_t buttons, int8 | ||||
|  | ||||
| // Invoked when received GET HID REPORT DESCRIPTOR request | ||||
| // Application return pointer to descriptor, whose contents must exist long enough for transfer to complete | ||||
| uint8_t const * tud_hid_descriptor_report_cb(uint8_t itf); | ||||
| uint8_t const * tud_hid_descriptor_report_cb(uint8_t instance); | ||||
|  | ||||
| // 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 | ||||
| uint16_t tud_hid_get_report_cb(uint8_t itf, uint8_t report_id, hid_report_type_t report_type, uint8_t* buffer, uint16_t reqlen); | ||||
| uint16_t tud_hid_get_report_cb(uint8_t instance, uint8_t report_id, hid_report_type_t report_type, uint8_t* buffer, uint16_t reqlen); | ||||
|  | ||||
| // Invoked when received SET_REPORT control request or | ||||
| // received data on OUT endpoint ( Report ID = 0, Type = 0 ) | ||||
| void tud_hid_set_report_cb(uint8_t itf, uint8_t report_id, hid_report_type_t report_type, uint8_t const* buffer, uint16_t bufsize); | ||||
| 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_boot_mode_cb(uint8_t itf, uint8_t boot_mode); | ||||
| TU_ATTR_WEAK void tud_hid_set_protocol_cb(uint8_t instance, bool boot_mode); | ||||
|  | ||||
| // 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 | ||||
| // - 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 itf, uint8_t idle_rate); | ||||
| TU_ATTR_WEAK bool tud_hid_set_idle_cb(uint8_t instance, uint8_t idle_rate); | ||||
|  | ||||
| // Invoked when sent REPORT successfully to host | ||||
| // Application can use this to send the next report | ||||
| // Note: For composite reports, report[0] is report ID | ||||
| TU_ATTR_WEAK void tud_hid_report_complete_cb(uint8_t itf, uint8_t const* report, uint8_t len); | ||||
| TU_ATTR_WEAK void tud_hid_report_complete_cb(uint8_t instance, uint8_t const* report, uint8_t len); | ||||
|  | ||||
|  | ||||
| //--------------------------------------------------------------------+ | ||||
| @@ -123,9 +128,14 @@ static inline bool tud_hid_ready(void) | ||||
|   return tud_hid_n_ready(0); | ||||
| } | ||||
|  | ||||
| static inline bool tud_hid_boot_mode(void) | ||||
| static inline uint8_t tud_hid_interface_protocol(void) | ||||
| { | ||||
|   return tud_hid_n_boot_mode(0); | ||||
|   return tud_hid_n_interface_protocol(0); | ||||
| } | ||||
|  | ||||
| static inline bool tud_hid_get_protocol(void) | ||||
| { | ||||
|   return tud_hid_n_get_protocol(0); | ||||
| } | ||||
|  | ||||
| static inline bool tud_hid_report(uint8_t report_id, void const* report, uint8_t len) | ||||
| @@ -143,6 +153,11 @@ static inline bool tud_hid_mouse_report(uint8_t report_id, uint8_t buttons, int8 | ||||
|   return tud_hid_n_mouse_report(0, report_id, buttons, x, y, vertical, horizontal); | ||||
| } | ||||
|  | ||||
| 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); | ||||
| } | ||||
|  | ||||
| /* --------------------------------------------------------------------+ | ||||
|  * HID Report Descriptor Template | ||||
|  * | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 hathach
					hathach