Skip to content

Commit 5e7678e

Browse files
authored
Merge pull request #68 from adafruit/rp2350
add language features for .pio_version 1
2 parents 2b21992 + 8f52bea commit 5e7678e

9 files changed

+1940
-46
lines changed

Diff for: README.rst

+5
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,11 @@ To install in a virtual environment in your current project:
5555
source .venv/bin/activate
5656
pip3 install adafruit-circuitpython-pioasm
5757
58+
CircuitPython Extensions
59+
========================
60+
61+
* ``.fifo auto``: By default, CircuitPython joins the TX and RX fifos if a PIO program only receives or transmits. The ``.fifo auto`` directive makes this explicit.
62+
5863
Usage Example
5964
=============
6065

Diff for: adafruit_pioasm.py

+294-44
Large diffs are not rendered by default.

Diff for: examples/pioasm_rp2350_fifo.py

+84
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
# SPDX-FileCopyrightText: 2024 Jeff Epler, written for Adafruit Industries
2+
#
3+
# SPDX-License-Identifier: MIT
4+
5+
"""A PIO demo that uses the FIFO in random access mode
6+
7+
Random access mode is a new feature of the PIO peripheral of the RP2350.
8+
This demo is not compatible with the original RP2040 or Raspberry Pi
9+
Pico.
10+
11+
Wiring:
12+
* LED with current limiting resistor on GP25 (Pico 2 standard location)
13+
14+
The LED will blink in several patterns depending on the values loaded in the 'rxfifo' registers
15+
"""
16+
17+
import array
18+
import time
19+
import board
20+
import rp2pio
21+
import adafruit_pioasm
22+
23+
program = adafruit_pioasm.Program(
24+
"""
25+
.pio_version 1
26+
.set 1
27+
.fifo txget
28+
29+
; LED on time taken from rxfifo[0]
30+
mov osr, rxfifo[0]
31+
mov x, osr
32+
33+
set pins, 1
34+
xloop1:
35+
jmp x--, xloop1
36+
37+
; LED off time taken from rxfifo[1]
38+
mov osr, rxfifo[1]
39+
mov x, osr
40+
41+
set pins, 0
42+
xloop2:
43+
jmp x--, xloop2
44+
"""
45+
)
46+
47+
48+
def assign_uint32s(ar, off, *args):
49+
"""Assign multiple 32-bit registers within an AddressRange"""
50+
vv = b"".join(v.to_bytes(4, "little") for v in args)
51+
ar[off : off + 4 * len(args)] = vv
52+
53+
54+
print(program.pio_kwargs)
55+
sm = rp2pio.StateMachine(
56+
program.assembled,
57+
first_set_pin=board.GP25,
58+
frequency=10_000_000,
59+
**program.pio_kwargs,
60+
)
61+
fifo = sm.rxfifo
62+
63+
# Set non-zero register entries & re-start the state machine at its offset.
64+
# this is needed because the default register value could represent a very long delay
65+
fifo[0:4] = b"\1\0\0\0"
66+
fifo[4:8] = b"\1\0\0\0"
67+
sm.run(array.array("H", [sm.offset]))
68+
69+
while True:
70+
# equal blinks
71+
assign_uint32s(fifo, 0, 2000000, 2000000)
72+
time.sleep(1)
73+
74+
# small on time
75+
assign_uint32s(fifo, 0, 1000000, 3000000)
76+
time.sleep(1)
77+
78+
# small off time
79+
assign_uint32s(fifo, 0, 3000000, 1000000)
80+
time.sleep(1)
81+
82+
# slower blinks
83+
assign_uint32s(fifo, 0, 3000000, 3000000)
84+
time.sleep(1)

0 commit comments

Comments
 (0)