Skip to content

add language features for .pio_version 1 #68

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

Merged
merged 26 commits into from
Sep 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
a8fa218
Recognize .pio_version directive (integer arguments only)
jepler Sep 5, 2024
3da0f6c
Add .fifo directive
jepler Sep 5, 2024
cfee88e
Add .mov_status
jepler Sep 5, 2024
cfa7400
Improve line splitting
jepler Sep 5, 2024
9874ce3
Start to consolidate argument range checking
jepler Sep 5, 2024
ff1f57d
Check directives that must come before an instruction
jepler Sep 5, 2024
4deafa6
Add and test .in directive
jepler Sep 5, 2024
5659a26
Improve error handling of origin & mov_status directives
jepler Sep 5, 2024
ed74947
Add .out directive
jepler Sep 5, 2024
e9858c3
Add .set
jepler Sep 5, 2024
4f98480
Add irq prev/next
jepler Sep 6, 2024
895f8eb
add mov rxfifo
jepler Sep 7, 2024
7acebc6
Add mov pindirs
jepler Sep 7, 2024
86f02e8
Add wait jmppin & wait irq prev/next
jepler Sep 8, 2024
b379f05
Merge mov_status_count & _param into mov_status_n
jepler Sep 10, 2024
8a97f71
More piov2 updates
jepler Sep 10, 2024
eaa8bb0
fix markup
jepler Sep 10, 2024
919d075
Fix checking fifo mode for mov rxfifo instructions
jepler Sep 13, 2024
3159513
Add an example using the RP2350 "mov ,txfifo[]" feature
jepler Sep 13, 2024
bdc9fe8
Update based on review comments
jepler Sep 13, 2024
403da52
Adjust condition in which ".out 16" is accepted syntax
jepler Sep 13, 2024
87bf9a7
remove a debug print
jepler Sep 13, 2024
89fc1a1
Add (failing) test comparing "all" instructions to sdk pioasm
jepler Sep 13, 2024
679feb8
Fix assembly of irq & mov rxfifo[] instructions to match sdk pioasm
jepler Sep 13, 2024
ce01b8c
add Program.from_file
jepler Sep 15, 2024
8f52bea
Rename this file to emphasize it's for generating test cases
jepler Sep 18, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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