summaryrefslogtreecommitdiff
path: root/src/class
diff options
context:
space:
mode:
authorhathach <[email protected]>2019-05-01 17:05:25 +0700
committerhathach <[email protected]>2019-05-01 17:06:18 +0700
commit84f81f6b213305207fa6d4d01ce6911f5ad3cf66 (patch)
treef7e1e83f199ce9cd9809fa31a49c1c7424d7e4e7 /src/class
parent0b6999a28e5dde91e1a911523e1f633f8983b504 (diff)
simplify hid keyboard & mouse report to one API each
Diffstat (limited to 'src/class')
-rw-r--r--src/class/hid/hid_device.c32
-rw-r--r--src/class/hid/hid_device.h32
2 files changed, 10 insertions, 54 deletions
diff --git a/src/class/hid/hid_device.c b/src/class/hid/hid_device.c
index 688aa7dea..46e26bd10 100644
--- a/src/class/hid/hid_device.c
+++ b/src/class/hid/hid_device.c
@@ -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
//--------------------------------------------------------------------+
diff --git a/src/class/hid/hid_device.h b/src/class/hid/hid_device.h
index 95ff9825c..c93055f06 100644
--- a/src/class/hid/hid_device.h
+++ b/src/class/hid/hid_device.h
@@ -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