summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHa Thach <[email protected]>2023-04-06 12:16:17 +0700
committerGitHub <[email protected]>2023-04-06 12:16:17 +0700
commit3336fbafe4ab6613f4effd298ed7eac5cb11e88e (patch)
tree1cd601cf1ea662c30ed31f2301e21d4e59f12622
parent5f327dd49fea1ae2cf73e1d371a8e9e37ac1e12f (diff)
parent6db24e0dbae248c865ec3ed0e5febcf341b489d4 (diff)
Merge pull request #2011 from hathach/add-hid-host-ready
Add hid host send/recieve ready
-rw-r--r--src/class/hid/hid_host.c23
-rw-r--r--src/class/hid/hid_host.h9
-rw-r--r--src/class/vendor/vendor_device.h7
3 files changed, 28 insertions, 11 deletions
diff --git a/src/class/hid/hid_host.c b/src/class/hid/hid_host.c
index a0032aeba..d95d3ef35 100644
--- a/src/class/hid/hid_host.c
+++ b/src/class/hid/hid_host.c
@@ -331,6 +331,15 @@ static bool _hidh_set_idle(uint8_t daddr, uint8_t itf_num, uint16_t idle_rate, t
// Interrupt Endpoint API
//--------------------------------------------------------------------+
+// Check if HID interface is ready to receive report
+bool tuh_hid_receive_ready(uint8_t dev_addr, uint8_t idx)
+{
+ hidh_interface_t* p_hid = get_hid_itf(dev_addr, idx);
+ TU_VERIFY(p_hid);
+
+ return !usbh_edpt_busy(dev_addr, p_hid->ep_in);
+}
+
bool tuh_hid_receive_report(uint8_t daddr, uint8_t idx)
{
hidh_interface_t* p_hid = get_hid_itf(daddr, idx);
@@ -348,13 +357,13 @@ bool tuh_hid_receive_report(uint8_t daddr, uint8_t idx)
return true;
}
-//bool tuh_n_hid_n_ready(uint8_t dev_addr, uint8_t instance)
-//{
-// TU_VERIFY(tuh_n_hid_n_mounted(dev_addr, instance));
-//
-// hidh_interface_t* hid_itf = get_instance(dev_addr, instance);
-// return !usbh_edpt_busy(dev_addr, hid_itf->ep_in);
-//}
+bool tuh_hid_send_ready(uint8_t dev_addr, uint8_t idx)
+{
+ hidh_interface_t* p_hid = get_hid_itf(dev_addr, idx);
+ TU_VERIFY(p_hid);
+
+ return !usbh_edpt_busy(dev_addr, p_hid->ep_out);
+}
bool tuh_hid_send_report(uint8_t daddr, uint8_t idx, uint8_t report_id, const void* report, uint16_t len)
{
diff --git a/src/class/hid/hid_host.h b/src/class/hid/hid_host.h
index c0c727e6a..08ad421d2 100644
--- a/src/class/hid/hid_host.h
+++ b/src/class/hid/hid_host.h
@@ -62,7 +62,7 @@ typedef struct
// Interface API
//--------------------------------------------------------------------+
-// Get the number of mounted HID interfaces of a device
+// Get the total number of mounted HID interfaces of a device
uint8_t tuh_hid_itf_get_count(uint8_t dev_addr);
// Get all mounted interfaces across devices
@@ -109,14 +109,17 @@ bool tuh_hid_set_report(uint8_t dev_addr, uint8_t idx, uint8_t report_id, uint8_
// Interrupt Endpoint API
//--------------------------------------------------------------------+
-// Check if the interface is ready to use
-//bool tuh_n_hid_n_ready(uint8_t dev_addr, uint8_t idx);
+// Check if HID interface is ready to receive report
+bool tuh_hid_receive_ready(uint8_t dev_addr, uint8_t idx);
// Try to receive next report on Interrupt Endpoint. Immediately return
// - true If succeeded, tuh_hid_report_received_cb() callback will be invoked when report is available
// - false if failed to queue the transfer e.g endpoint is busy
bool tuh_hid_receive_report(uint8_t dev_addr, uint8_t idx);
+// Check if HID interface is ready to send report
+bool tuh_hid_send_ready(uint8_t dev_addr, uint8_t idx);
+
// Send report using interrupt endpoint
// If report_id > 0 (composite), it will be sent as 1st byte, then report contents. Otherwise only report content is sent.
bool tuh_hid_send_report(uint8_t dev_addr, uint8_t idx, uint8_t report_id, const void* report, uint16_t len);
diff --git a/src/class/vendor/vendor_device.h b/src/class/vendor/vendor_device.h
index 7afd49cc1..d239406b4 100644
--- a/src/class/vendor/vendor_device.h
+++ b/src/class/vendor/vendor_device.h
@@ -52,7 +52,9 @@ uint32_t tud_vendor_n_write_flush (uint8_t itf);
uint32_t tud_vendor_n_write_available (uint8_t itf);
static inline uint32_t tud_vendor_n_write_str (uint8_t itf, char const* str);
-uint32_t tud_vendor_n_flush (uint8_t itf);
+
+// backward compatible
+#define tud_vendor_n_flush(itf) tud_vendor_n_write_flush(itf)
//--------------------------------------------------------------------+
// Application API (Single Port)
@@ -67,6 +69,9 @@ static inline uint32_t tud_vendor_write_str (char const* str);
static inline uint32_t tud_vendor_write_available (void);
static inline uint32_t tud_vendor_write_flush (void);
+// backward compatible
+#define tud_vendor_flush() tud_vendor_write_flush()
+
//--------------------------------------------------------------------+
// Application Callback API (weak is optional)
//--------------------------------------------------------------------+