Skip to content

Commit a7d2b61

Browse files
committed
Enable use of pins >32 on RP2350B
Closes: #133
1 parent d17f8ef commit a7d2b61

File tree

5 files changed

+29
-16
lines changed

5 files changed

+29
-16
lines changed

src/pio_usb.c

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -291,17 +291,30 @@ static void apply_config(pio_port_t *pp, const pio_usb_configuration_t *c,
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 PICO_PIO_USE_GPIO_BASE
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;
@@ -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

src/usb_rx.pio

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -182,8 +182,8 @@ static inline void usb_rx_fs_program_init(PIO pio, uint sm, uint offset, uint pi
182182
} else {
183183
c = usb_nrzi_decoder_debug_program_get_default_config(offset);
184184

185-
pio_sm_set_pins_with_mask(pio, sm, 0, 1 << pin_debug);
186-
pio_sm_set_pindirs_with_mask(pio, sm, 1 << pin_debug, 1 << pin_debug);
185+
pio_sm_set_pins_with_mask64(pio, sm, 0, 1ull << pin_debug);
186+
pio_sm_set_pindirs_with_mask64(pio, sm, 1ull << pin_debug, 1ull << pin_debug);
187187
pio_gpio_init(pio, pin_debug);
188188
sm_config_set_sideset_pins(&c, pin_debug);
189189
}
@@ -208,8 +208,8 @@ static inline void eop_detect_fs_program_init(PIO pio, uint sm, uint offset,
208208
c = usb_edge_detector_program_get_default_config(offset);
209209
} else {
210210
c = usb_edge_detector_debug_program_get_default_config(offset);
211-
pio_sm_set_pins_with_mask(pio, sm, 0, 1 << pin_debug);
212-
pio_sm_set_pindirs_with_mask(pio, sm, 1 << pin_debug, 1 << pin_debug);
211+
pio_sm_set_pins_with_mask64(pio, sm, 0, 1ull << pin_debug);
212+
pio_sm_set_pindirs_with_mask64(pio, sm, 1ull << pin_debug, 1ull << pin_debug);
213213
pio_gpio_init(pio, pin_debug);
214214
sm_config_set_sideset_pins(&c, pin_debug);
215215
}
@@ -232,4 +232,4 @@ static inline void eop_detect_fs_program_init(PIO pio, uint sm, uint offset,
232232
pio_sm_set_enabled(pio, sm, true);
233233
}
234234

235-
%}
235+
%}

src/usb_rx.pio.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -195,8 +195,8 @@ static inline void usb_rx_fs_program_init(PIO pio, uint sm, uint offset, uint pi
195195
c = usb_nrzi_decoder_program_get_default_config(offset);
196196
} else {
197197
c = usb_nrzi_decoder_debug_program_get_default_config(offset);
198-
pio_sm_set_pins_with_mask(pio, sm, 0, 1 << pin_debug);
199-
pio_sm_set_pindirs_with_mask(pio, sm, 1 << pin_debug, 1 << pin_debug);
198+
pio_sm_set_pins_with_mask64(pio, sm, 0, 1ull << pin_debug);
199+
pio_sm_set_pindirs_with_mask64(pio, sm, 1ull << pin_debug, 1ull << pin_debug);
200200
pio_gpio_init(pio, pin_debug);
201201
sm_config_set_sideset_pins(&c, pin_debug);
202202
}
@@ -216,8 +216,8 @@ static inline void eop_detect_fs_program_init(PIO pio, uint sm, uint offset,
216216
c = usb_edge_detector_program_get_default_config(offset);
217217
} else {
218218
c = usb_edge_detector_debug_program_get_default_config(offset);
219-
pio_sm_set_pins_with_mask(pio, sm, 0, 1 << pin_debug);
220-
pio_sm_set_pindirs_with_mask(pio, sm, 1 << pin_debug, 1 << pin_debug);
219+
pio_sm_set_pins_with_mask64(pio, sm, 0, 1ull << pin_debug);
220+
pio_sm_set_pindirs_with_mask64(pio, sm, 1ull << pin_debug, 1ull << pin_debug);
221221
pio_gpio_init(pio, pin_debug);
222222
sm_config_set_sideset_pins(&c, pin_debug);
223223
}

src/usb_tx.pio

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ set pindirs, 0b11 side FJ_LK
106106

107107
static inline void usb_tx_fs_program_init(PIO pio, uint sm, uint offset,
108108
uint pin_dp, uint pin_dm) {
109-
pio_sm_set_pins_with_mask(pio, sm, (1 << pin_dp), ((1 << pin_dp) | (1 << pin_dm)));
109+
pio_sm_set_pins_with_mask64(pio, sm, (1ull << pin_dp), ((1ull << pin_dp) | (1ull << pin_dm)));
110110

111111
gpio_pull_down(pin_dp);
112112
gpio_pull_down(pin_dm);
@@ -132,7 +132,7 @@ set pindirs, 0b11 side FJ_LK
132132

133133
static inline void usb_tx_ls_program_init(PIO pio, uint sm, uint offset,
134134
uint pin_dp, uint pin_dm) {
135-
pio_sm_set_pins_with_mask(pio, sm, (1 << pin_dm), ((1 << pin_dp) | (1 << pin_dm)));
135+
pio_sm_set_pins_with_mask64(pio, sm, (1ull << pin_dm), ((1ull << pin_dp) | (1ull << pin_dm)));
136136

137137
gpio_pull_down(pin_dp);
138138
gpio_pull_down(pin_dm);
@@ -156,4 +156,4 @@ set pindirs, 0b11 side FJ_LK
156156
pio_sm_set_enabled(pio, sm, true);
157157
}
158158

159-
%}
159+
%}

src/usb_tx.pio.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ static inline pio_sm_config usb_tx_pre_dmdp_program_get_default_config(uint offs
151151
}
152152
static inline void usb_tx_fs_program_init(PIO pio, uint sm, uint offset,
153153
uint pin_dp, uint pin_dm) {
154-
pio_sm_set_pins_with_mask(pio, sm, (1 << pin_dp), ((1 << pin_dp) | (1 << pin_dm)));
154+
pio_sm_set_pins_with_mask64(pio, sm, (1ull << pin_dp), ((1ull << pin_dp) | (1ull << pin_dm)));
155155
gpio_pull_down(pin_dp);
156156
gpio_pull_down(pin_dm);
157157
pio_gpio_init(pio, pin_dp);
@@ -170,7 +170,7 @@ static inline pio_sm_config usb_tx_pre_dmdp_program_get_default_config(uint offs
170170
}
171171
static inline void usb_tx_ls_program_init(PIO pio, uint sm, uint offset,
172172
uint pin_dp, uint pin_dm) {
173-
pio_sm_set_pins_with_mask(pio, sm, (1 << pin_dm), ((1 << pin_dp) | (1 << pin_dm)));
173+
pio_sm_set_pins_with_mask64(pio, sm, (1ull << pin_dm), ((1ull << pin_dp) | (1ull << pin_dm)));
174174
gpio_pull_down(pin_dp);
175175
gpio_pull_down(pin_dm);
176176
pio_gpio_init(pio, pin_dp);

0 commit comments

Comments
 (0)