@@ -139,16 +139,20 @@ static void hw_handle_buff_status(void)
139139 for (uint i = 1 ; i <= USB_HOST_INTERRUPT_ENDPOINTS && remaining_buffers ; i ++ )
140140 {
141141 // EPX is bit 0
142- // IEP1 is bit 2
143- // IEP2 is bit 4
144- // IEP3 is bit 6
142+ // IEP1 IN is bit 2
143+ // IEP1 OUT is bit 3
144+ // IEP2 IN is bit 4
145+ // IEP2 OUT is bit 5
146+ // IEP3 IN is bit 6
147+ // IEP3 OUT is bit 7
145148 // etc
146- bit = 1 << (i * 2 );
147-
148- if (remaining_buffers & bit )
149- {
150- remaining_buffers &= ~bit ;
151- _handle_buff_status_bit (bit , & ep_pool [i ]);
149+ for (int j = 0 ; j < 2 ; j ++ ){
150+ bit = 1 << (i * 2 + j );
151+ if (remaining_buffers & bit )
152+ {
153+ remaining_buffers &= ~bit ;
154+ _handle_buff_status_bit (bit , & ep_pool [i ]);
155+ }
152156 }
153157 }
154158
@@ -259,10 +263,10 @@ static struct hw_endpoint *_hw_endpoint_allocate(uint8_t transfer_type)
259263{
260264 struct hw_endpoint * ep = NULL ;
261265
262- if (transfer_type == TUSB_XFER_INTERRUPT )
266+ if (transfer_type != TUSB_XFER_CONTROL )
263267 {
264268 ep = _next_free_interrupt_ep ();
265- pico_info ("Allocate interrupt ep %d\n" , ep -> interrupt_num );
269+ pico_info ("Allocate %s ep %d\n" , tu_edpt_type_str ( transfer_type ) , ep -> interrupt_num );
266270 assert (ep );
267271 ep -> buffer_control = & usbh_dpram -> int_ep_buffer_ctrl [ep -> interrupt_num ].ctrl ;
268272 ep -> endpoint_control = & usbh_dpram -> int_ep_ctrl [ep -> interrupt_num ].ctrl ;
@@ -320,8 +324,9 @@ static void _hw_endpoint_init(struct hw_endpoint *ep, uint8_t dev_addr, uint8_t
320324 pico_trace ("endpoint control (0x%p) <- 0x%x\n" , ep -> endpoint_control , ep_reg );
321325 ep -> configured = true;
322326
323- if (bmInterval )
327+ if (ep != & epx )
324328 {
329+ // Endpoint has its own addr_endp and interrupt bits to be setup!
325330 // This is an interrupt endpoint
326331 // so need to set up interrupt endpoint address control register with:
327332 // device address
@@ -492,6 +497,9 @@ bool hcd_edpt_xfer(uint8_t rhport, uint8_t dev_addr, uint8_t ep_addr, uint8_t *
492497 // Get appropriate ep. Either EPX or interrupt endpoint
493498 struct hw_endpoint * ep = get_dev_ep (dev_addr , ep_addr );
494499 assert (ep );
500+ // Should we maybe be able to check if endpt is busy/active instead?
501+ if (ep -> active )
502+ return false;
495503
496504 // Control endpoint can change direction 0x00 <-> 0x80
497505 if ( ep_addr != ep -> ep_addr )
@@ -535,6 +543,7 @@ bool hcd_setup_send(uint8_t rhport, uint8_t dev_addr, uint8_t const setup_packet
535543
536544 // Configure EP0 struct with setup info for the trans complete
537545 struct hw_endpoint * ep = _hw_endpoint_allocate (0 );
546+ assert (ep == & epx );
538547
539548 // EP0 out
540549 _hw_endpoint_init (ep , dev_addr , 0x00 , ep -> wMaxPacketSize , 0 , 0 );
0 commit comments