simplify hid keyboard & mouse report to one API each
This commit is contained in:
		| @@ -47,16 +47,11 @@ typedef struct | ||||
| { | ||||
|   uint8_t itf_num; | ||||
|   uint8_t ep_in; | ||||
|   uint8_t ep_out; // optional | ||||
|  | ||||
|  | ||||
|   uint8_t ep_out;        // optional | ||||
|   uint8_t boot_protocol; // Boot mouse or keyboard | ||||
|   bool    boot_mode; | ||||
|  | ||||
|   bool    boot_mode;     // default = false (Report) | ||||
|   uint8_t idle_rate;     // up to application to handle idle rate | ||||
|   uint16_t reprot_desc_len; | ||||
|   uint8_t idle_rate;     // 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). | ||||
|   uint8_t mouse_button;  // caching button for using with tud_hid_mouse_ API | ||||
|  | ||||
|   CFG_TUSB_MEM_ALIGN uint8_t report_buf[CFG_TUD_HID_BUFSIZE]; | ||||
| }hidd_interface_t; | ||||
| @@ -101,7 +96,6 @@ bool tud_hid_report(uint8_t report_id, void const* report, uint8_t len) | ||||
|     memcpy(p_hid->report_buf, report, len); | ||||
|   } | ||||
|  | ||||
|   // TODO skip duplication ? and or idle rate | ||||
|   return dcd_edpt_xfer(TUD_OPT_RHPORT, p_hid->ep_in, p_hid->report_buf, len + (report_id ? 1 : 0) ); | ||||
| } | ||||
|  | ||||
| @@ -128,7 +122,6 @@ bool tud_hid_keyboard_report(uint8_t report_id, uint8_t modifier, uint8_t keycod | ||||
|     tu_memclr(report.keycode, 6); | ||||
|   } | ||||
|  | ||||
|   // TODO skip duplication ? and or idle rate | ||||
|   return tud_hid_report(report_id, &report, sizeof(report)); | ||||
| } | ||||
|  | ||||
| @@ -146,28 +139,9 @@ bool tud_hid_mouse_report(uint8_t report_id, uint8_t buttons, int8_t x, int8_t y | ||||
|     .pan     = horizontal | ||||
|   }; | ||||
|  | ||||
|   uint8_t itf = 0; | ||||
|   _hidd_itf[itf].mouse_button = buttons; | ||||
|  | ||||
|   return tud_hid_report(report_id, &report, sizeof(report)); | ||||
| } | ||||
|  | ||||
| bool tud_hid_mouse_move(uint8_t report_id, int8_t x, int8_t y) | ||||
| { | ||||
|   uint8_t itf = 0; | ||||
|   uint8_t const button = _hidd_itf[itf].mouse_button; | ||||
|  | ||||
|   return tud_hid_mouse_report(report_id, button, x, y, 0, 0); | ||||
| } | ||||
|  | ||||
| bool tud_hid_mouse_scroll(uint8_t report_id, int8_t vertical, int8_t horizontal) | ||||
| { | ||||
|   uint8_t itf = 0; | ||||
|   uint8_t const button = _hidd_itf[itf].mouse_button; | ||||
|  | ||||
|   return tud_hid_mouse_report(report_id, button, 0, 0, vertical, horizontal); | ||||
| } | ||||
|  | ||||
| //--------------------------------------------------------------------+ | ||||
| // USBD-CLASS API | ||||
| //--------------------------------------------------------------------+ | ||||
|   | ||||
| @@ -65,42 +65,24 @@ void tud_hid_set_report_cb(uint8_t report_id, hid_report_type_t report_type, uin | ||||
| // Invoked when host switch mode Boot <-> Report via SET_PROTOCOL request | ||||
| ATTR_WEAK void tud_hid_boot_mode_cb(uint8_t boot_mode); | ||||
|  | ||||
| // Invoked when host send SET_IDLE request | ||||
| // return false will stall the request | ||||
| // Invoked when host send 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). | ||||
| ATTR_WEAK bool tud_hid_set_idle_cb(uint8_t idle_rate); | ||||
|  | ||||
| //--------------------------------------------------------------------+ | ||||
| // KEYBOARD API | ||||
| // Convenient helper to send keyboard report if application use standard/boot | ||||
| // layout report as defined by hid_keyboard_report_t | ||||
| // 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]); | ||||
|  | ||||
| static inline bool tud_hid_keyboard_key_release(uint8_t report_id) | ||||
| { | ||||
|   return tud_hid_keyboard_report(report_id, 0, NULL); | ||||
| } | ||||
|  | ||||
| //--------------------------------------------------------------------+ | ||||
| // MOUSE API | ||||
| // Convenient helper to send mouse report if application use standard/boot | ||||
| // layout report as defined by hid_mouse_report_t | ||||
| // 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_mouse_move(uint8_t report_id, int8_t x, int8_t y); | ||||
| bool tud_hid_mouse_scroll(uint8_t report_id, int8_t vertical, int8_t horizontal); | ||||
|  | ||||
| static inline bool tud_hid_mouse_button_press(uint8_t report_id, uint8_t buttons) | ||||
| { | ||||
|   return tud_hid_mouse_report(report_id, buttons, 0, 0, 0, 0); | ||||
| } | ||||
|  | ||||
| static inline bool tud_hid_mouse_button_release(uint8_t report_id) | ||||
| { | ||||
|   return tud_hid_mouse_report(report_id, 0, 0, 0, 0, 0); | ||||
| } | ||||
|  | ||||
| /* --------------------------------------------------------------------+ | ||||
|  * HID Report Descriptor Template | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 hathach
					hathach