Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

raspberrypi: Update usb_host for newer PIO resource usage #9999

Merged
merged 4 commits into from
Jan 28, 2025

Conversation

jepler
Copy link
Member

@jepler jepler commented Jan 25, 2025

Besides correcting the resource calculation, this also enables use of swapped pins (DP-1=DM) and using RP2350's "PIO2" instance.

Closes: #9958
Closes: #9998

@jepler
Copy link
Member Author

jepler commented Jan 26, 2025

Tested on metro rp2350 with import go_kbd. It works in the normal & reversed pinout; and it works on any one PIO.
(note you have to microcontroller.reset() to check a different pinout or PIO placement)

this also depends on adafruit/Pico-PIO-USB#2

content of go_kbd.py
import digitalio
import board
import usb_host
import rp2pio
import array

# Force allocation on a given state machine
# Note that StateMachine() happens to allocate in the order 2, 1, 0
# (sdk pio_claim_free_sm_and_add_program_for_gpio_range counts DOWN from MAX_PIO)
def useless_program(i): return array.array('H', [i]) * 32
sm = [rp2pio.StateMachine(useless_program(i), frequency=8000)
    for i in range(3)]
sm[0].deinit()

d = digitalio.DigitalInOut(board.USB_HOST_5V_POWER)
d.switch_to_output(True)

# Enable one line or the other, to test swapped lines
#port = usb_host.Port(board.USB_HOST_DATA_PLUS, board.USB_HOST_DATA_MINUS)
port = usb_host.Port(board.USB_HOST_DATA_MINUS, board.USB_HOST_DATA_PLUS)

for i in sm: i.deinit()

@jepler jepler requested a review from dhalbert January 28, 2025 14:02
@jepler
Copy link
Member Author

jepler commented Jan 28, 2025

also note that since #10005 the USB Host on Metro RP2350 is set up once at boot time and so different configurations are harder to test. You might need to test using a different board without predefined USB host pins.

@dhalbert
Copy link
Collaborator

@jepler is this still a draft?

@jepler jepler marked this pull request as ready for review January 28, 2025 20:21
@jepler
Copy link
Member Author

jepler commented Jan 28, 2025

belatedly marked as ready for review

Copy link
Collaborator

@dhalbert dhalbert left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tested the build artifacts on a Feather RP2040 Prop-Maker, playing I2S Audio, and a Feather RP240 DVI, doing DVI output. In both cases the PIO functionality worked fine. I did not test USB Host since you did that already, though not on an RP2040.

Thanks!

@dhalbert dhalbert merged commit c3989b2 into adafruit:main Jan 28, 2025
154 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

pico pio usb host: allow swapped dp/dm pico pio usb host: verify types of pio resources used
2 participants