Skip to content

Commit f4e50b2

Browse files
authored
Merge pull request #1 from adafruit/rp2350b
Enable use of pins >32 on RP2350B
2 parents 7902e9f + 445ca64 commit f4e50b2

13 files changed

+62
-772
lines changed

.github/workflows/build.yml

+1-2
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ jobs:
1616
fail-fast: false
1717
matrix:
1818
sdk_version:
19+
- '2.1.0'
1920
- '2.0.0'
2021
- '1.5.1'
2122
runs-on: ubuntu-latest
@@ -56,7 +57,5 @@ jobs:
5657
path: |
5758
examples/build/usb_device/usb_device.uf2
5859
examples/build/usb_device/usb_device.hex
59-
examples/build/capture_hid_report/capture_hid_report.uf2
60-
examples/build/capture_hid_report/capture_hid_report.hex
6160
examples/build/host_hid_to_device_cdc/host_hid_to_device_cdc.uf2
6261
examples/build/host_hid_to_device_cdc/host_hid_to_device_cdc.hex

README.md

+1-2
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,8 @@ https://user-images.githubusercontent.com/43873124/146642806-bdf34af6-4342-4a95-
2020

2121
## Examples
2222

23-
- [capture_hid_report.c](examples/capture_hid_report/capture_hid_report.c) is a USB host sample program which print HID reports received from device. Open serial port and connect devices to pico. Default D+/D- is gp0/gp1. Call `pio_usb_add_port()` to use additional ports.
23+
- [host_hid_to_device_cdc.c](examples/host_hid_to_device_cdc/host_hid_to_device_cdc.c) which print mouse/keyboard report from host port to device port's cdc. TinyUSB is used to manage both device (native usb) and host (pio usb) stack.
2424
- [usb_device.c](examples/usb_device/usb_device.c) is a HID USB FS device sample which moves mouse cursor every 0.5s. External 1.5kohm pull-up register is necessary to D+ pin (Default is gp0).
25-
- [host_hid_to_device_cdc.c](examples/host_hid_to_device_cdc/host_hid_to_device_cdc.c) is similar to **capture_hid_report.c** which print mouse/keyboard report from host port to device port's cdc. TinyUSB is used to manage both device (native usb) and host (pio usb) stack.
2625

2726
```bash
2827
cd examples

examples/CMakeLists.txt

-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ set(PICO_PIO_USB_DIR "${CMAKE_CURRENT_LIST_DIR}/../")
1111
# a subdirectory, it's out of tree.
1212
add_subdirectory(${PICO_PIO_USB_DIR} pico_pio_usb)
1313

14-
add_subdirectory(capture_hid_report)
1514
add_subdirectory(usb_device)
1615
add_subdirectory(host_hid_to_device_cdc)
1716
add_subdirectory(test_ll)

examples/capture_hid_report/CMakeLists.txt

-15
This file was deleted.

examples/capture_hid_report/capture_hid_report.c

-77
This file was deleted.

library.properties

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name=Pico PIO USB
2-
version=0.6.0
2+
version=0.6.1
33
author=sekigon-gonnoc
44
maintainer=sekigon-gonnoc
55
sentence=Pico PIO USB library for Arduino

src/pio_usb.c

+21-5
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,8 @@ int __no_inline_not_in_flash_func(pio_usb_bus_receive_packet_and_handshake)(
178178
bool crc_match = false;
179179
int16_t t = 240;
180180
uint16_t idx = 0;
181+
uint16_t nak_timeout = 10000;
182+
const uint16_t rx_buf_len = sizeof(pp->usb_rx_buffer) / sizeof(pp->usb_rx_buffer[0]);
181183

182184
while (t--) {
183185
if (pio_sm_get_rx_fifo_level(pp->pio_usb_rx, pp->sm_rx)) {
@@ -192,7 +194,7 @@ int __no_inline_not_in_flash_func(pio_usb_bus_receive_packet_and_handshake)(
192194
// timing critical start
193195
if (t > 0) {
194196
if (handshake == USB_PID_ACK) {
195-
while ((pp->pio_usb_rx->irq & IRQ_RX_COMP_MASK) == 0) {
197+
while ((pp->pio_usb_rx->irq & IRQ_RX_COMP_MASK) == 0 && idx < rx_buf_len - 1) {
196198
if (pio_sm_get_rx_fifo_level(pp->pio_usb_rx, pp->sm_rx)) {
197199
uint8_t data = pio_sm_get(pp->pio_usb_rx, pp->sm_rx) >> 24;
198200
crc_prev2 = crc_prev;
@@ -212,7 +214,7 @@ int __no_inline_not_in_flash_func(pio_usb_bus_receive_packet_and_handshake)(
212214
}
213215
} else {
214216
// just discard received data since we NAK/STALL anyway
215-
while ((pp->pio_usb_rx->irq & IRQ_RX_COMP_MASK) == 0) {
217+
while ((pp->pio_usb_rx->irq & IRQ_RX_COMP_MASK) == 0 && nak_timeout--) {
216218
continue;
217219
}
218220
pio_sm_clear_fifos(pp->pio_usb_rx, pp->sm_rx);
@@ -289,17 +291,30 @@ static void apply_config(pio_port_t *pp, const pio_usb_configuration_t *c,
289291
pp->sm_eop = c->sm_eop;
290292
port->pin_dp = c->pin_dp;
291293

294+
uint highest_pin;
292295
if (c->pinout == PIO_USB_PINOUT_DPDM) {
293296
port->pin_dm = c->pin_dp + 1;
297+
highest_pin = port->pin_dm;
294298
pp->fs_tx_program = &usb_tx_dpdm_program;
295299
pp->fs_tx_pre_program = &usb_tx_pre_dpdm_program;
296300
pp->ls_tx_program = &usb_tx_dmdp_program;
297301
} else {
298302
port->pin_dm = c->pin_dp - 1;
303+
highest_pin = port->pin_dp;
299304
pp->fs_tx_program = &usb_tx_dmdp_program;
300305
pp->fs_tx_pre_program = &usb_tx_pre_dmdp_program;
301306
pp->ls_tx_program = &usb_tx_dpdm_program;
302307
}
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+
303318
port->pinout = c->pinout;
304319

305320
pp->debug_pin_rx = c->debug_pin_rx;
@@ -458,12 +473,13 @@ uint8_t __no_inline_not_in_flash_func(pio_usb_ll_encode_tx_data)(
458473
encoded_data[byte_idx] |= PIO_USB_TX_ENCODED_DATA_COMP;
459474
bit_idx++;
460475

476+
// terminate buffers with K
461477
do {
462478
byte_idx = bit_idx >> 2;
463479
encoded_data[byte_idx] <<= 2;
464480
encoded_data[byte_idx] |= PIO_USB_TX_ENCODED_DATA_K;
465481
bit_idx++;
466-
} while (bit_idx & 0x07);
482+
} while (bit_idx & 0x03);
467483

468484
byte_idx = bit_idx >> 2;
469485
return byte_idx;
@@ -570,8 +586,8 @@ int pio_usb_host_add_port(uint8_t pin_dp, PIO_USB_PINOUT pinout) {
570586
pio_gpio_init(pio_port[0].pio_usb_tx, root->pin_dm);
571587
gpio_set_inover(pin_dp, GPIO_OVERRIDE_INVERT);
572588
gpio_set_inover(root->pin_dm, GPIO_OVERRIDE_INVERT);
573-
pio_sm_set_pindirs_with_mask(pio_port[0].pio_usb_tx, pio_port[0].sm_tx, 0,
574-
(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));
575591
port_pin_drive_setting(root);
576592
root->initialized = true;
577593

0 commit comments

Comments
 (0)