Skip to content

Commit

Permalink
Merge pull request #68 from adafruit/rp2350
Browse files Browse the repository at this point in the history
add language features for .pio_version 1
  • Loading branch information
tannewt authored Sep 19, 2024
2 parents 2b21992 + 8f52bea commit 5e7678e
Show file tree
Hide file tree
Showing 9 changed files with 1,940 additions and 46 deletions.
5 changes: 5 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,11 @@ To install in a virtual environment in your current project:
source .venv/bin/activate
pip3 install adafruit-circuitpython-pioasm
CircuitPython Extensions
========================

* ``.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.

Usage Example
=============

Expand Down
338 changes: 294 additions & 44 deletions adafruit_pioasm.py

Large diffs are not rendered by default.

84 changes: 84 additions & 0 deletions examples/pioasm_rp2350_fifo.py
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)
Loading

0 comments on commit 5e7678e

Please sign in to comment.