Skip to content

Commit 0659c52

Browse files
committed
Enable use of pins >32 on RP2350B
Closes: #133
1 parent fe9133f commit 0659c52

File tree

6 files changed

+36
-23
lines changed

6 files changed

+36
-23
lines changed

src/pio_usb.c

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -289,17 +289,30 @@ static void apply_config(pio_port_t *pp, const pio_usb_configuration_t *c,
289289
pp->sm_eop = c->sm_eop;
290290
port->pin_dp = c->pin_dp;
291291

292+
uint highest_pin;
292293
if (c->pinout == PIO_USB_PINOUT_DPDM) {
293294
port->pin_dm = c->pin_dp + 1;
295+
highest_pin = port->pin_dm;
294296
pp->fs_tx_program = &usb_tx_dpdm_program;
295297
pp->fs_tx_pre_program = &usb_tx_pre_dpdm_program;
296298
pp->ls_tx_program = &usb_tx_dmdp_program;
297299
} else {
298300
port->pin_dm = c->pin_dp - 1;
301+
highest_pin = port->pin_dp;
299302
pp->fs_tx_program = &usb_tx_dmdp_program;
300303
pp->fs_tx_pre_program = &usb_tx_pre_dmdp_program;
301304
pp->ls_tx_program = &usb_tx_dpdm_program;
302305
}
306+
307+
#if PICO_PIO_USE_GPIO_BASE
308+
if (highest_pin > 32) {
309+
pio_set_gpio_base(pp->pio_usb_tx, 16);
310+
pio_set_gpio_base(pp->pio_usb_rx, 16);
311+
}
312+
#else
313+
(void)highest_pin;
314+
#endif
315+
303316
port->pinout = c->pinout;
304317

305318
pp->debug_pin_rx = c->debug_pin_rx;
@@ -571,8 +584,8 @@ int pio_usb_host_add_port(uint8_t pin_dp, PIO_USB_PINOUT pinout) {
571584
pio_gpio_init(pio_port[0].pio_usb_tx, root->pin_dm);
572585
gpio_set_inover(pin_dp, GPIO_OVERRIDE_INVERT);
573586
gpio_set_inover(root->pin_dm, GPIO_OVERRIDE_INVERT);
574-
pio_sm_set_pindirs_with_mask(pio_port[0].pio_usb_tx, pio_port[0].sm_tx, 0,
575-
(1 << pin_dp) | (1 << root->pin_dm));
587+
pio_sm_set_pindirs_with_mask64(pio_port[0].pio_usb_tx, pio_port[0].sm_tx, 0,
588+
(1ull << pin_dp) | (1ull << root->pin_dm));
576589
port_pin_drive_setting(root);
577590
root->initialized = true;
578591

src/pio_usb_host.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -625,16 +625,16 @@ static void on_device_connect(pio_port_t *pp, root_port_t *root,
625625
fullspeed_flag = false;
626626
}
627627

628-
pio_sm_set_pins_with_mask(pp->pio_usb_tx, pp->sm_tx, 0,
629-
(1 << root->pin_dp) | (1 << root->pin_dm));
630-
pio_sm_set_pindirs_with_mask(pp->pio_usb_tx, pp->sm_tx,
631-
(1 << root->pin_dp) | (1 << root->pin_dm),
632-
(1 << root->pin_dp) | (1 << root->pin_dm));
628+
pio_sm_set_pins_with_mask64(pp->pio_usb_tx, pp->sm_tx, 0,
629+
(1ull << root->pin_dp) | (1ull << root->pin_dm));
630+
pio_sm_set_pindirs_with_mask64(pp->pio_usb_tx, pp->sm_tx,
631+
(1ull << root->pin_dp) | (1ull << root->pin_dm),
632+
(1ull << root->pin_dp) | (1ull << root->pin_dm));
633633

634634
busy_wait_ms(100);
635635

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

639639
busy_wait_us(100);
640640

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)