Skip to content

Commit 3336fba

Browse files
authored
Merge pull request hathach#2011 from hathach/add-hid-host-ready
Add hid host send/recieve ready
2 parents 5f327dd + 6db24e0 commit 3336fba

File tree

3 files changed

+28
-11
lines changed

3 files changed

+28
-11
lines changed

src/class/hid/hid_host.c

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -331,6 +331,15 @@ static bool _hidh_set_idle(uint8_t daddr, uint8_t itf_num, uint16_t idle_rate, t
331331
// Interrupt Endpoint API
332332
//--------------------------------------------------------------------+
333333

334+
// Check if HID interface is ready to receive report
335+
bool tuh_hid_receive_ready(uint8_t dev_addr, uint8_t idx)
336+
{
337+
hidh_interface_t* p_hid = get_hid_itf(dev_addr, idx);
338+
TU_VERIFY(p_hid);
339+
340+
return !usbh_edpt_busy(dev_addr, p_hid->ep_in);
341+
}
342+
334343
bool tuh_hid_receive_report(uint8_t daddr, uint8_t idx)
335344
{
336345
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)
348357
return true;
349358
}
350359

351-
//bool tuh_n_hid_n_ready(uint8_t dev_addr, uint8_t instance)
352-
//{
353-
// TU_VERIFY(tuh_n_hid_n_mounted(dev_addr, instance));
354-
//
355-
// hidh_interface_t* hid_itf = get_instance(dev_addr, instance);
356-
// return !usbh_edpt_busy(dev_addr, hid_itf->ep_in);
357-
//}
360+
bool tuh_hid_send_ready(uint8_t dev_addr, uint8_t idx)
361+
{
362+
hidh_interface_t* p_hid = get_hid_itf(dev_addr, idx);
363+
TU_VERIFY(p_hid);
364+
365+
return !usbh_edpt_busy(dev_addr, p_hid->ep_out);
366+
}
358367

359368
bool tuh_hid_send_report(uint8_t daddr, uint8_t idx, uint8_t report_id, const void* report, uint16_t len)
360369
{

src/class/hid/hid_host.h

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ typedef struct
6262
// Interface API
6363
//--------------------------------------------------------------------+
6464

65-
// Get the number of mounted HID interfaces of a device
65+
// Get the total number of mounted HID interfaces of a device
6666
uint8_t tuh_hid_itf_get_count(uint8_t dev_addr);
6767

6868
// 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_
109109
// Interrupt Endpoint API
110110
//--------------------------------------------------------------------+
111111

112-
// Check if the interface is ready to use
113-
//bool tuh_n_hid_n_ready(uint8_t dev_addr, uint8_t idx);
112+
// Check if HID interface is ready to receive report
113+
bool tuh_hid_receive_ready(uint8_t dev_addr, uint8_t idx);
114114

115115
// Try to receive next report on Interrupt Endpoint. Immediately return
116116
// - true If succeeded, tuh_hid_report_received_cb() callback will be invoked when report is available
117117
// - false if failed to queue the transfer e.g endpoint is busy
118118
bool tuh_hid_receive_report(uint8_t dev_addr, uint8_t idx);
119119

120+
// Check if HID interface is ready to send report
121+
bool tuh_hid_send_ready(uint8_t dev_addr, uint8_t idx);
122+
120123
// Send report using interrupt endpoint
121124
// If report_id > 0 (composite), it will be sent as 1st byte, then report contents. Otherwise only report content is sent.
122125
bool tuh_hid_send_report(uint8_t dev_addr, uint8_t idx, uint8_t report_id, const void* report, uint16_t len);

src/class/vendor/vendor_device.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,9 @@ uint32_t tud_vendor_n_write_flush (uint8_t itf);
5252
uint32_t tud_vendor_n_write_available (uint8_t itf);
5353

5454
static inline uint32_t tud_vendor_n_write_str (uint8_t itf, char const* str);
55-
uint32_t tud_vendor_n_flush (uint8_t itf);
55+
56+
// backward compatible
57+
#define tud_vendor_n_flush(itf) tud_vendor_n_write_flush(itf)
5658

5759
//--------------------------------------------------------------------+
5860
// Application API (Single Port)
@@ -67,6 +69,9 @@ static inline uint32_t tud_vendor_write_str (char const* str);
6769
static inline uint32_t tud_vendor_write_available (void);
6870
static inline uint32_t tud_vendor_write_flush (void);
6971

72+
// backward compatible
73+
#define tud_vendor_flush() tud_vendor_write_flush()
74+
7075
//--------------------------------------------------------------------+
7176
// Application Callback API (weak is optional)
7277
//--------------------------------------------------------------------+

0 commit comments

Comments
 (0)