summaryrefslogtreecommitdiff
path: root/src/class/hid
diff options
context:
space:
mode:
authorPeter Lawrence <[email protected]>2019-12-22 18:18:54 -0600
committerPeter Lawrence <[email protected]>2019-12-28 14:27:32 -0600
commitff0e7d2bed64592c16e73e83cead8d76eda66f36 (patch)
treea2cfedf2c3bd3f05e1ba2865264a6639eafc5660 /src/class/hid
parenta601f59df5e61801cbbe87467c70a48b740d4bfd (diff)
implement multiple interfaces support
Diffstat (limited to 'src/class/hid')
-rw-r--r--src/class/hid/hid_device.c27
1 files changed, 21 insertions, 6 deletions
diff --git a/src/class/hid/hid_device.c b/src/class/hid/hid_device.c
index 8527fa5d6..7cb35f1ce 100644
--- a/src/class/hid/hid_device.c
+++ b/src/class/hid/hid_device.c
@@ -162,9 +162,18 @@ bool hidd_open(uint8_t rhport, tusb_desc_interface_t const * desc_itf, uint16_t
{
uint8_t const *p_desc = (uint8_t const *) desc_itf;
- // TODO support multiple HID interface
- uint8_t const itf = 0;
- hidd_interface_t * p_hid = &_hidd_itf[itf];
+ // Find available interface
+ hidd_interface_t * p_hid = NULL;
+ uint8_t hid_id;
+ for(hid_id=0; hid_id<CFG_TUD_HID; hid_id++)
+ {
+ if ( _hidd_itf[hid_id].ep_in == 0 )
+ {
+ p_hid = &_hidd_itf[hid_id];
+ break;
+ }
+ }
+ TU_ASSERT(p_hid);
//------------- HID descriptor -------------//
p_desc = tu_desc_next(p_desc);
@@ -309,9 +318,15 @@ bool hidd_xfer_cb(uint8_t rhport, uint8_t ep_addr, xfer_result_t result, uint32_
{
(void) result;
- // TODO support multiple HID interface
- uint8_t const itf = 0;
- hidd_interface_t * p_hid = &_hidd_itf[itf];
+ uint8_t itf = 0;
+ hidd_interface_t * p_hid = _hidd_itf;
+
+ for ( ; ; itf++, p_hid++)
+ {
+ if (itf >= TU_ARRAY_SIZE(_hidd_itf)) return false;
+
+ if ( ep_addr == p_hid->ep_out ) break;
+ }
if (ep_addr == p_hid->ep_out)
{