Skip to content

Commit 7c627f5

Browse files
authored
Merge pull request hathach#1343 from Daft-Freak/patch-1
Open OUT endpoint for HID host
2 parents 8e84529 + 83b638f commit 7c627f5

File tree

2 files changed

+23
-14
lines changed

2 files changed

+23
-14
lines changed

src/class/hid/hid_host.c

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -286,28 +286,35 @@ bool hidh_open(uint8_t rhport, uint8_t dev_addr, tusb_desc_interface_t const *de
286286
hidh_device_t* hid_dev = get_dev(dev_addr);
287287
TU_ASSERT(hid_dev->inst_count < CFG_TUH_HID, 0);
288288

289-
//------------- Endpoint Descriptor -------------//
289+
hidh_interface_t* hid_itf = get_instance(dev_addr, hid_dev->inst_count);
290+
291+
//------------- Endpoint Descriptors -------------//
290292
p_desc = tu_desc_next(p_desc);
291293
tusb_desc_endpoint_t const * desc_ep = (tusb_desc_endpoint_t const *) p_desc;
292-
TU_ASSERT(TUSB_DESC_ENDPOINT == desc_ep->bDescriptorType);
293294

294-
// first endpoint may be OUT, skip to IN endpoint
295-
// TODO also open endpoint OUT
296-
if(tu_edpt_dir(desc_ep->bEndpointAddress) == TUSB_DIR_OUT)
295+
for(int i = 0; i < desc_itf->bNumEndpoints; i++)
297296
{
297+
TU_ASSERT(TUSB_DESC_ENDPOINT == desc_ep->bDescriptorType);
298+
TU_ASSERT( usbh_edpt_open(rhport, dev_addr, desc_ep) );
299+
300+
if(tu_edpt_dir(desc_ep->bEndpointAddress) == TUSB_DIR_IN)
301+
{
302+
hid_itf->ep_in = desc_ep->bEndpointAddress;
303+
hid_itf->epin_size = tu_edpt_packet_size(desc_ep);
304+
}
305+
else
306+
{
307+
hid_itf->ep_out = desc_ep->bEndpointAddress;
308+
hid_itf->epout_size = tu_edpt_packet_size(desc_ep);
309+
}
310+
298311
p_desc = tu_desc_next(p_desc);
299312
desc_ep = (tusb_desc_endpoint_t const *) p_desc;
300-
TU_ASSERT(TUSB_DESC_ENDPOINT == desc_ep->bDescriptorType);
301313
}
302314

303-
TU_ASSERT( usbh_edpt_open(rhport, dev_addr, desc_ep) );
304-
305-
hidh_interface_t* hid_itf = get_instance(dev_addr, hid_dev->inst_count);
306315
hid_dev->inst_count++;
307316

308317
hid_itf->itf_num = desc_itf->bInterfaceNumber;
309-
hid_itf->ep_in = desc_ep->bEndpointAddress;
310-
hid_itf->epin_size = tu_edpt_packet_size(desc_ep);
311318

312319
// Assume bNumDescriptors = 1
313320
hid_itf->report_desc_type = desc_hid->bReportType;

src/portable/raspberrypi/rp2040/hcd_rp2040.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -328,9 +328,11 @@ static void _hw_endpoint_init(struct hw_endpoint *ep, uint8_t dev_addr, uint8_t
328328
// endpoint number / direction
329329
// preamble
330330
uint32_t reg = dev_addr | (num << USB_ADDR_ENDP1_ENDPOINT_LSB);
331-
// Assert the interrupt endpoint is IN_TO_HOST
332-
// TODO Interrupt can also be OUT
333-
assert(dir == TUSB_DIR_IN);
331+
332+
if (dir == TUSB_DIR_OUT)
333+
{
334+
reg |= USB_ADDR_ENDP1_INTEP_DIR_BITS;
335+
}
334336

335337
if (need_pre(dev_addr))
336338
{

0 commit comments

Comments
 (0)