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

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from

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()

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
1 participant