@@ -283,25 +283,38 @@ static void configure_tx_channel(uint8_t ch, PIO pio, uint sm) {
283283
284284static void apply_config (pio_port_t * pp , const pio_usb_configuration_t * c ,
285285 root_port_t * port ) {
286- pp -> pio_usb_tx = c -> pio_tx_num == 0 ? pio0 : pio1 ;
286+ pp -> pio_usb_tx = pio_get_instance ( c -> pio_tx_num ) ;
287287 pp -> sm_tx = c -> sm_tx ;
288288 pp -> tx_ch = c -> tx_ch ;
289- pp -> pio_usb_rx = c -> pio_rx_num == 0 ? pio0 : pio1 ;
289+ pp -> pio_usb_rx = pio_get_instance ( c -> pio_rx_num ) ;
290290 pp -> sm_rx = c -> sm_rx ;
291291 pp -> sm_eop = c -> sm_eop ;
292292 port -> pin_dp = c -> pin_dp ;
293293
294+ uint highest_pin ;
294295 if (c -> pinout == PIO_USB_PINOUT_DPDM ) {
295296 port -> pin_dm = c -> pin_dp + 1 ;
297+ highest_pin = port -> pin_dm ;
296298 pp -> fs_tx_program = & usb_tx_dpdm_program ;
297299 pp -> fs_tx_pre_program = & usb_tx_pre_dpdm_program ;
298300 pp -> ls_tx_program = & usb_tx_dmdp_program ;
299301 } else {
300302 port -> pin_dm = c -> pin_dp - 1 ;
303+ highest_pin = port -> pin_dp ;
301304 pp -> fs_tx_program = & usb_tx_dmdp_program ;
302305 pp -> fs_tx_pre_program = & usb_tx_pre_dmdp_program ;
303306 pp -> ls_tx_program = & usb_tx_dpdm_program ;
304307 }
308+
309+ #if defined(PICO_PIO_USE_GPIO_BASE ) && PICO_PIO_USE_GPIO_BASE + 0
310+ if (highest_pin > 32 ) {
311+ pio_set_gpio_base (pp -> pio_usb_tx , 16 );
312+ pio_set_gpio_base (pp -> pio_usb_rx , 16 );
313+ }
314+ #else
315+ (void )highest_pin ;
316+ #endif
317+
305318 port -> pinout = c -> pinout ;
306319
307320 pp -> debug_pin_rx = c -> debug_pin_rx ;
@@ -323,7 +336,7 @@ void pio_usb_bus_init(pio_port_t *pp, const pio_usb_configuration_t *c,
323336 root_port_t * root ) {
324337 memset (root , 0 , sizeof (root_port_t ));
325338
326- pp -> pio_usb_tx = c -> pio_tx_num == 0 ? pio0 : pio1 ;
339+ pp -> pio_usb_tx = pio_get_instance ( c -> pio_tx_num ) ;
327340 dma_claim_mask (1 <<c -> tx_ch );
328341 configure_tx_channel (c -> tx_ch , pp -> pio_usb_tx , c -> sm_tx );
329342
@@ -573,8 +586,8 @@ int pio_usb_host_add_port(uint8_t pin_dp, PIO_USB_PINOUT pinout) {
573586 pio_gpio_init (pio_port [0 ].pio_usb_tx , root -> pin_dm );
574587 gpio_set_inover (pin_dp , GPIO_OVERRIDE_INVERT );
575588 gpio_set_inover (root -> pin_dm , GPIO_OVERRIDE_INVERT );
576- pio_sm_set_pindirs_with_mask (pio_port [0 ].pio_usb_tx , pio_port [0 ].sm_tx , 0 ,
577- (1 << pin_dp ) | (1 << root -> pin_dm ));
589+ pio_sm_set_pindirs_with_mask64 (pio_port [0 ].pio_usb_tx , pio_port [0 ].sm_tx , 0 ,
590+ (1ull << pin_dp ) | (1ull << root -> pin_dm ));
578591 port_pin_drive_setting (root );
579592 root -> initialized = true;
580593
0 commit comments