-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #68 from adafruit/rp2350
add language features for .pio_version 1
- Loading branch information
Showing
9 changed files
with
1,940 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
# SPDX-FileCopyrightText: 2024 Jeff Epler, written for Adafruit Industries | ||
# | ||
# SPDX-License-Identifier: MIT | ||
|
||
"""A PIO demo that uses the FIFO in random access mode | ||
Random access mode is a new feature of the PIO peripheral of the RP2350. | ||
This demo is not compatible with the original RP2040 or Raspberry Pi | ||
Pico. | ||
Wiring: | ||
* LED with current limiting resistor on GP25 (Pico 2 standard location) | ||
The LED will blink in several patterns depending on the values loaded in the 'rxfifo' registers | ||
""" | ||
|
||
import array | ||
import time | ||
import board | ||
import rp2pio | ||
import adafruit_pioasm | ||
|
||
program = adafruit_pioasm.Program( | ||
""" | ||
.pio_version 1 | ||
.set 1 | ||
.fifo txget | ||
; LED on time taken from rxfifo[0] | ||
mov osr, rxfifo[0] | ||
mov x, osr | ||
set pins, 1 | ||
xloop1: | ||
jmp x--, xloop1 | ||
; LED off time taken from rxfifo[1] | ||
mov osr, rxfifo[1] | ||
mov x, osr | ||
set pins, 0 | ||
xloop2: | ||
jmp x--, xloop2 | ||
""" | ||
) | ||
|
||
|
||
def assign_uint32s(ar, off, *args): | ||
"""Assign multiple 32-bit registers within an AddressRange""" | ||
vv = b"".join(v.to_bytes(4, "little") for v in args) | ||
ar[off : off + 4 * len(args)] = vv | ||
|
||
|
||
print(program.pio_kwargs) | ||
sm = rp2pio.StateMachine( | ||
program.assembled, | ||
first_set_pin=board.GP25, | ||
frequency=10_000_000, | ||
**program.pio_kwargs, | ||
) | ||
fifo = sm.rxfifo | ||
|
||
# Set non-zero register entries & re-start the state machine at its offset. | ||
# this is needed because the default register value could represent a very long delay | ||
fifo[0:4] = b"\1\0\0\0" | ||
fifo[4:8] = b"\1\0\0\0" | ||
sm.run(array.array("H", [sm.offset])) | ||
|
||
while True: | ||
# equal blinks | ||
assign_uint32s(fifo, 0, 2000000, 2000000) | ||
time.sleep(1) | ||
|
||
# small on time | ||
assign_uint32s(fifo, 0, 1000000, 3000000) | ||
time.sleep(1) | ||
|
||
# small off time | ||
assign_uint32s(fifo, 0, 3000000, 1000000) | ||
time.sleep(1) | ||
|
||
# slower blinks | ||
assign_uint32s(fifo, 0, 3000000, 3000000) | ||
time.sleep(1) |
Oops, something went wrong.