diff options
| author | hathach <[email protected]> | 2018-07-24 20:51:50 +0700 |
|---|---|---|
| committer | hathach <[email protected]> | 2018-07-24 20:51:50 +0700 |
| commit | a6fede4962fb65bfb353c3a4a4f927c3fc501eb2 (patch) | |
| tree | 773885e9dc2a04c1e9d6b56addc1364154a5c2d4 /src | |
| parent | b370283174fbdb066bc662f8885956dbf947559b (diff) | |
improve tud_hid_mouse API()
Diffstat (limited to 'src')
| -rw-r--r-- | src/class/hid/hid_device.c | 31 | ||||
| -rw-r--r-- | src/class/hid/hid_device.h | 15 |
2 files changed, 43 insertions, 3 deletions
diff --git a/src/class/hid/hid_device.c b/src/class/hid/hid_device.c index 292024a61..59bf24256 100644 --- a/src/class/hid/hid_device.c +++ b/src/class/hid/hid_device.c @@ -188,6 +188,37 @@ static bool hidd_mouse_report(hid_mouse_report_t const *p_report) return dcd_edpt_xfer(TUD_OPT_RHPORT, p_hid->ep_in, p_hid->report_buf, sizeof(hid_mouse_report_t));
}
+
+bool tud_hid_mouse_data(uint8_t buttons, int8_t x, int8_t y, int8_t scroll, int8_t pan)
+{
+ hid_mouse_report_t report =
+ {
+ .buttons = buttons,
+ .x = x,
+ .y = y,
+ .wheel = scroll,
+// .pan = pan
+ };
+
+ return hidd_mouse_report( &report );
+}
+
+bool tud_hid_mouse_move(int8_t x, int8_t y)
+{
+ hidd_interface_t * p_hid = &_mse_itf;
+ uint8_t prev_buttons = p_hid->report_buf[0];
+
+ return tud_hid_mouse_data(prev_buttons, x, y, 0, 0);
+}
+
+bool tud_hid_mouse_scroll(int8_t vertical, int8_t horizontal)
+{
+ hidd_interface_t * p_hid = &_mse_itf;
+ uint8_t prev_buttons = p_hid->report_buf[0];
+
+ return tud_hid_mouse_data(prev_buttons, 0, 0, vertical, horizontal);
+}
+
#endif
static inline hidd_interface_t* get_interface_by_edpt(uint8_t ep_addr)
diff --git a/src/class/hid/hid_device.h b/src/class/hid/hid_device.h index ba8a5a4a1..659981a48 100644 --- a/src/class/hid/hid_device.h +++ b/src/class/hid/hid_device.h @@ -122,10 +122,19 @@ ATTR_WEAK void tud_hid_keyboard_set_report_cb(hid_report_type_t report_type, uin bool tud_hid_mouse_ready(void);
bool tud_hid_mouse_data(uint8_t buttons, int8_t x, int8_t y, int8_t scroll, int8_t pan);
-bool tud_hid_mouse_move(int8_t x, int8_t y, int8_t scroll, int8_t pan);
-bool tud_hid_mouse_button_press(uint8_t buttons);
-bool tud_hid_mouse_button_release(uint8_t buttons);
+bool tud_hid_mouse_move(int8_t x, int8_t y);
+bool tud_hid_mouse_scroll(int8_t vertical, int8_t horizontal);
+
+static inline bool tud_hid_mouse_button_press(uint8_t buttons)
+{
+ return tud_hid_mouse_data(buttons, 0, 0, 0, 0);
+}
+
+static inline bool tud_hid_mouse_button_release(void)
+{
+ return tud_hid_mouse_data(0, 0, 0, 0, 0);
+}
/*------------- Callbacks -------------*/
|
