diff --git a/README.rst b/README.rst
index a4df52f..eb66e90 100644
--- a/README.rst
+++ b/README.rst
@@ -35,9 +35,6 @@ Installing from PyPI
.. note:: This library is not available on PyPI yet. Install documentation is included
as a standard element. Stay tuned for PyPI availability!
-.. todo:: Remove the above note if PyPI version is/will be available at time of release.
- If the library is not planned for PyPI, remove the entire 'Installing from PyPI' section.
-
On supported GNU/Linux systems like the Raspberry Pi, you can install the driver locally `from
PyPI `_. To install for current user:
@@ -63,7 +60,30 @@ To install in a virtual environment in your current project:
Usage Example
=============
-.. todo:: Add a quick, simple example. It and other examples should live in the examples folder and be included in docs/examples.rst.
+.. code-block:: python
+
+ import time
+ import rp2pio
+ import board
+ import adafruit_pioasm
+
+ squarewave = """
+ .program squarewave
+ set pins 1 [1] ; Drive pin high and then delay for one cycle
+ set pins 0 ; Drive pin low
+ """
+
+ assembled = adafruit_pioasm.assemble(squarewave)
+
+ sm = rp2pio.StateMachine(
+ assembled,
+ frequency=80,
+ init=adafruit_pioasm.assemble("set pindirs 1"),
+ first_set_pin=board.LED,
+ )
+ print("real frequency", sm.frequency)
+
+ time.sleep(120)
Contributing
============
diff --git a/adafruit_pioasm.py b/adafruit_pioasm.py
index 725c0f2..d10824e 100644
--- a/adafruit_pioasm.py
+++ b/adafruit_pioasm.py
@@ -25,8 +25,10 @@
MOV_OPS = [None, "~", "::", None]
SET_DESTINATIONS = ["pins", "x", "y", None, "pindirs", None, None, None]
+
def assemble(text_program):
"""Converts pioasm text to encoded instruction bytes"""
+ # pylint: disable=too-many-branches,too-many-statements
assembled = []
program_name = None
labels = {}
@@ -60,7 +62,7 @@ def assemble(text_program):
print(instruction)
instruction = instruction.split()
delay = 0
- if instruction[-1].endswith("]"): # Delay
+ if instruction[-1].endswith("]"): # Delay
delay = int(instruction[-1].strip("[]"))
if delay > max_delay:
raise RuntimeError("Delay too long:", delay)
@@ -100,23 +102,23 @@ def assemble(text_program):
raise RuntimeError("Wait num out of range")
assembled[-1] |= num
if instruction[-1] == "rel":
- assembled[-1] |= 0x10 # Set the high bit of the irq value
+ assembled[-1] |= 0x10 # Set the high bit of the irq value
elif instruction[0] == "in":
# instr delay src count
assembled.append(0b010_00000_000_00000)
assembled[-1] |= IN_SOURCES.index(instruction[1]) << 5
count = int(instruction[-1])
- if not 1 <= count <=32:
+ if not 1 <= count <= 32:
raise RuntimeError("Count out of range")
- assembled[-1] |= (count & 0x1f) # 32 is 00000 so we mask the top
+ assembled[-1] |= count & 0x1F # 32 is 00000 so we mask the top
elif instruction[0] == "out":
# instr delay dst count
assembled.append(0b011_00000_000_00000)
assembled[-1] |= OUT_DESTINATIONS.index(instruction[1]) << 5
count = int(instruction[-1])
- if not 1 <= count <=32:
+ if not 1 <= count <= 32:
raise RuntimeError("Count out of range")
- assembled[-1] |= (count & 0x1f) # 32 is 00000 so we mask the top
+ assembled[-1] |= count & 0x1F # 32 is 00000 so we mask the top
elif instruction[0] == "push" or instruction[0] == "pull":
# instr delay d i b zero
assembled.append(0b100_00000_0_0_0_00000)
@@ -137,13 +139,13 @@ def assemble(text_program):
# instr delay z c w index
assembled.append(0b110_00000_0_0_0_00000)
if instruction[-1] == "rel":
- assembled[-1] |= 0x10 # Set the high bit of the irq value
+ assembled[-1] |= 0x10 # Set the high bit of the irq value
instruction.pop()
num = int(instruction[-1])
if not 0 <= num <= 7:
raise RuntimeError("Interrupt index out of range")
assembled[-1] |= num
- if len(instruction) == 3: # after rel has been removed
+ if len(instruction) == 3: # after rel has been removed
if instruction[1] == "wait":
assembled[-1] |= 0x20
elif instruction[1] == "clear":
@@ -154,7 +156,7 @@ def assemble(text_program):
assembled.append(0b111_00000_000_00000)
assembled[-1] |= SET_DESTINATIONS.index(instruction[1]) << 5
value = int(instruction[-1])
- if not 0 <= value <=31:
+ if not 0 <= value <= 31:
raise RuntimeError("Set value out of range")
assembled[-1] |= value
else:
diff --git a/docs/index.rst b/docs/index.rst
index b1402e7..f6ad1e4 100644
--- a/docs/index.rst
+++ b/docs/index.rst
@@ -23,14 +23,15 @@ Table of Contents
.. toctree::
:caption: Tutorials
-.. todo:: Add any Learn guide links here. If there are none, then simply delete this todo and leave
- the toctree above for use later.
+ Getting Started with Raspberry Pi Pico and CircuitPython
.. toctree::
:caption: Related Products
-.. todo:: Add any product links here. If there are none, then simply delete this todo and leave
- the toctree above for use later.
+ Adafruit ItsyBitsy RP2040
+ Adafruit Feather RP2040
+ Raspberry Pi Pico RP2040
+ Raspberry Pi Pico RP2040 with Loose Headers
.. toctree::
:caption: Other Links
diff --git a/examples/pioasm_neopixel.py b/examples/pioasm_neopixel.py
index 8042aed..a682d94 100644
--- a/examples/pioasm_neopixel.py
+++ b/examples/pioasm_neopixel.py
@@ -2,11 +2,10 @@
#
# SPDX-License-Identifier: MIT
+import time
import rp2pio
import board
-import time
import adafruit_pioasm
-import digitalio
# NeoPixels are 800khz bit streams. Zeroes are 1/3 duty cycle (~416ns) and ones
# are 2/3 duty cycle (~833ns).
@@ -26,14 +25,16 @@
assembled = adafruit_pioasm.assemble(program)
-sm = rp2pio.StateMachine(assembled,
- frequency=800000 * 6, # 800khz * 6 clocks per bit
- init=adafruit_pioasm.assemble("set pindirs 1"),
- first_set_pin=board.D12,
- first_sideset_pin=board.D12,
- auto_pull=True,
- out_shift_right=False,
- pull_threshold=8)
+sm = rp2pio.StateMachine(
+ assembled,
+ frequency=800000 * 6, # 800khz * 6 clocks per bit
+ init=adafruit_pioasm.assemble("set pindirs 1"),
+ first_set_pin=board.D12,
+ first_sideset_pin=board.D12,
+ auto_pull=True,
+ out_shift_right=False,
+ pull_threshold=8,
+)
print("real frequency", sm.frequency)
for i in range(100):
diff --git a/examples/pioasm_simpletest.py b/examples/pioasm_simpletest.py
index db4f88a..494467a 100644
--- a/examples/pioasm_simpletest.py
+++ b/examples/pioasm_simpletest.py
@@ -2,11 +2,10 @@
#
# SPDX-License-Identifier: MIT
+import time
import rp2pio
import board
-import time
import adafruit_pioasm
-import digitalio
squarewave = """
.program squarewave
@@ -16,10 +15,12 @@
assembled = adafruit_pioasm.assemble(squarewave)
-sm = rp2pio.StateMachine(assembled,
- frequency=80,
- init=adafruit_pioasm.assemble("set pindirs 1"),
- first_set_pin=board.LED)
+sm = rp2pio.StateMachine(
+ assembled,
+ frequency=80,
+ init=adafruit_pioasm.assemble("set pindirs 1"),
+ first_set_pin=board.LED,
+)
print("real frequency", sm.frequency)
time.sleep(120)