Skip to content

Commit

Permalink
Enable use of pins >32 on RP2350B
Browse files Browse the repository at this point in the history
  • Loading branch information
jepler committed Dec 20, 2024
1 parent fe9133f commit 0659c52
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 23 deletions.
17 changes: 15 additions & 2 deletions src/pio_usb.c
Original file line number Diff line number Diff line change
Expand Up @@ -289,17 +289,30 @@ static void apply_config(pio_port_t *pp, const pio_usb_configuration_t *c,
pp->sm_eop = c->sm_eop;
port->pin_dp = c->pin_dp;

uint highest_pin;
if (c->pinout == PIO_USB_PINOUT_DPDM) {
port->pin_dm = c->pin_dp + 1;
highest_pin = port->pin_dm;
pp->fs_tx_program = &usb_tx_dpdm_program;
pp->fs_tx_pre_program = &usb_tx_pre_dpdm_program;
pp->ls_tx_program = &usb_tx_dmdp_program;
} else {
port->pin_dm = c->pin_dp - 1;
highest_pin = port->pin_dp;
pp->fs_tx_program = &usb_tx_dmdp_program;
pp->fs_tx_pre_program = &usb_tx_pre_dmdp_program;
pp->ls_tx_program = &usb_tx_dpdm_program;
}

#if PICO_PIO_USE_GPIO_BASE
if (highest_pin > 32) {
pio_set_gpio_base(pp->pio_usb_tx, 16);
pio_set_gpio_base(pp->pio_usb_rx, 16);
}
#else
(void)highest_pin;
#endif

port->pinout = c->pinout;

pp->debug_pin_rx = c->debug_pin_rx;
Expand Down Expand Up @@ -571,8 +584,8 @@ int pio_usb_host_add_port(uint8_t pin_dp, PIO_USB_PINOUT pinout) {
pio_gpio_init(pio_port[0].pio_usb_tx, root->pin_dm);
gpio_set_inover(pin_dp, GPIO_OVERRIDE_INVERT);
gpio_set_inover(root->pin_dm, GPIO_OVERRIDE_INVERT);
pio_sm_set_pindirs_with_mask(pio_port[0].pio_usb_tx, pio_port[0].sm_tx, 0,
(1 << pin_dp) | (1 << root->pin_dm));
pio_sm_set_pindirs_with_mask64(pio_port[0].pio_usb_tx, pio_port[0].sm_tx, 0,
(1ull << pin_dp) | (1ull << root->pin_dm));
port_pin_drive_setting(root);
root->initialized = true;

Expand Down
14 changes: 7 additions & 7 deletions src/pio_usb_host.c
Original file line number Diff line number Diff line change
Expand Up @@ -625,16 +625,16 @@ static void on_device_connect(pio_port_t *pp, root_port_t *root,
fullspeed_flag = false;
}

pio_sm_set_pins_with_mask(pp->pio_usb_tx, pp->sm_tx, 0,
(1 << root->pin_dp) | (1 << root->pin_dm));
pio_sm_set_pindirs_with_mask(pp->pio_usb_tx, pp->sm_tx,
(1 << root->pin_dp) | (1 << root->pin_dm),
(1 << root->pin_dp) | (1 << root->pin_dm));
pio_sm_set_pins_with_mask64(pp->pio_usb_tx, pp->sm_tx, 0,
(1ull << root->pin_dp) | (1ull << root->pin_dm));
pio_sm_set_pindirs_with_mask64(pp->pio_usb_tx, pp->sm_tx,
(1ull << root->pin_dp) | (1ull << root->pin_dm),
(1ull << root->pin_dp) | (1ull << root->pin_dm));

busy_wait_ms(100);

pio_sm_set_pindirs_with_mask(pp->pio_usb_tx, pp->sm_tx, 0,
(1 << root->pin_dp) | (1 << root->pin_dm));
pio_sm_set_pindirs_with_mask64(pp->pio_usb_tx, pp->sm_tx, 0,
(1ull << root->pin_dp) | (1ull << root->pin_dm));

busy_wait_us(100);

Expand Down
10 changes: 5 additions & 5 deletions src/usb_rx.pio
Original file line number Diff line number Diff line change
Expand Up @@ -182,8 +182,8 @@ static inline void usb_rx_fs_program_init(PIO pio, uint sm, uint offset, uint pi
} else {
c = usb_nrzi_decoder_debug_program_get_default_config(offset);

pio_sm_set_pins_with_mask(pio, sm, 0, 1 << pin_debug);
pio_sm_set_pindirs_with_mask(pio, sm, 1 << pin_debug, 1 << pin_debug);
pio_sm_set_pins_with_mask64(pio, sm, 0, 1ull << pin_debug);
pio_sm_set_pindirs_with_mask64(pio, sm, 1ull << pin_debug, 1ull << pin_debug);
pio_gpio_init(pio, pin_debug);
sm_config_set_sideset_pins(&c, pin_debug);
}
Expand All @@ -208,8 +208,8 @@ static inline void eop_detect_fs_program_init(PIO pio, uint sm, uint offset,
c = usb_edge_detector_program_get_default_config(offset);
} else {
c = usb_edge_detector_debug_program_get_default_config(offset);
pio_sm_set_pins_with_mask(pio, sm, 0, 1 << pin_debug);
pio_sm_set_pindirs_with_mask(pio, sm, 1 << pin_debug, 1 << pin_debug);
pio_sm_set_pins_with_mask64(pio, sm, 0, 1ull << pin_debug);
pio_sm_set_pindirs_with_mask64(pio, sm, 1ull << pin_debug, 1ull << pin_debug);
pio_gpio_init(pio, pin_debug);
sm_config_set_sideset_pins(&c, pin_debug);
}
Expand All @@ -232,4 +232,4 @@ static inline void eop_detect_fs_program_init(PIO pio, uint sm, uint offset,
pio_sm_set_enabled(pio, sm, true);
}

%}
%}
8 changes: 4 additions & 4 deletions src/usb_rx.pio.h
Original file line number Diff line number Diff line change
Expand Up @@ -195,8 +195,8 @@ static inline void usb_rx_fs_program_init(PIO pio, uint sm, uint offset, uint pi
c = usb_nrzi_decoder_program_get_default_config(offset);
} else {
c = usb_nrzi_decoder_debug_program_get_default_config(offset);
pio_sm_set_pins_with_mask(pio, sm, 0, 1 << pin_debug);
pio_sm_set_pindirs_with_mask(pio, sm, 1 << pin_debug, 1 << pin_debug);
pio_sm_set_pins_with_mask64(pio, sm, 0, 1ull << pin_debug);
pio_sm_set_pindirs_with_mask64(pio, sm, 1ull << pin_debug, 1ull << pin_debug);
pio_gpio_init(pio, pin_debug);
sm_config_set_sideset_pins(&c, pin_debug);
}
Expand All @@ -216,8 +216,8 @@ static inline void eop_detect_fs_program_init(PIO pio, uint sm, uint offset,
c = usb_edge_detector_program_get_default_config(offset);
} else {
c = usb_edge_detector_debug_program_get_default_config(offset);
pio_sm_set_pins_with_mask(pio, sm, 0, 1 << pin_debug);
pio_sm_set_pindirs_with_mask(pio, sm, 1 << pin_debug, 1 << pin_debug);
pio_sm_set_pins_with_mask64(pio, sm, 0, 1ull << pin_debug);
pio_sm_set_pindirs_with_mask64(pio, sm, 1ull << pin_debug, 1ull << pin_debug);
pio_gpio_init(pio, pin_debug);
sm_config_set_sideset_pins(&c, pin_debug);
}
Expand Down
6 changes: 3 additions & 3 deletions src/usb_tx.pio
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ set pindirs, 0b11 side FJ_LK

static inline void usb_tx_fs_program_init(PIO pio, uint sm, uint offset,
uint pin_dp, uint pin_dm) {
pio_sm_set_pins_with_mask(pio, sm, (1 << pin_dp), ((1 << pin_dp) | (1 << pin_dm)));
pio_sm_set_pins_with_mask64(pio, sm, (1ull << pin_dp), ((1ull << pin_dp) | (1ull << pin_dm)));

gpio_pull_down(pin_dp);
gpio_pull_down(pin_dm);
Expand All @@ -132,7 +132,7 @@ set pindirs, 0b11 side FJ_LK

static inline void usb_tx_ls_program_init(PIO pio, uint sm, uint offset,
uint pin_dp, uint pin_dm) {
pio_sm_set_pins_with_mask(pio, sm, (1 << pin_dm), ((1 << pin_dp) | (1 << pin_dm)));
pio_sm_set_pins_with_mask64(pio, sm, (1ull << pin_dm), ((1ull << pin_dp) | (1ull << pin_dm)));

gpio_pull_down(pin_dp);
gpio_pull_down(pin_dm);
Expand All @@ -156,4 +156,4 @@ set pindirs, 0b11 side FJ_LK
pio_sm_set_enabled(pio, sm, true);
}

%}
%}
4 changes: 2 additions & 2 deletions src/usb_tx.pio.h
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ static inline pio_sm_config usb_tx_pre_dmdp_program_get_default_config(uint offs
}
static inline void usb_tx_fs_program_init(PIO pio, uint sm, uint offset,
uint pin_dp, uint pin_dm) {
pio_sm_set_pins_with_mask(pio, sm, (1 << pin_dp), ((1 << pin_dp) | (1 << pin_dm)));
pio_sm_set_pins_with_mask64(pio, sm, (1ull << pin_dp), ((1ull << pin_dp) | (1ull << pin_dm)));
gpio_pull_down(pin_dp);
gpio_pull_down(pin_dm);
pio_gpio_init(pio, pin_dp);
Expand All @@ -170,7 +170,7 @@ static inline pio_sm_config usb_tx_pre_dmdp_program_get_default_config(uint offs
}
static inline void usb_tx_ls_program_init(PIO pio, uint sm, uint offset,
uint pin_dp, uint pin_dm) {
pio_sm_set_pins_with_mask(pio, sm, (1 << pin_dm), ((1 << pin_dp) | (1 << pin_dm)));
pio_sm_set_pins_with_mask64(pio, sm, (1ull << pin_dm), ((1ull << pin_dp) | (1ull << pin_dm)));
gpio_pull_down(pin_dp);
gpio_pull_down(pin_dm);
pio_gpio_init(pio, pin_dp);
Expand Down

0 comments on commit 0659c52

Please sign in to comment.