From 5e8b820a52dfbc2a10ccdf477481c7ffcd157e25 Mon Sep 17 00:00:00 2001 From: Scott Shawcroft Date: Thu, 21 Jan 2021 15:26:20 -0800 Subject: [PATCH 1/3] Black --- adafruit_pioasm.py | 19 ++++++++++--------- examples/pioasm_neopixel.py | 18 ++++++++++-------- examples/pioasm_simpletest.py | 10 ++++++---- 3 files changed, 26 insertions(+), 21 deletions(-) diff --git a/adafruit_pioasm.py b/adafruit_pioasm.py index 725c0f2..1995137 100644 --- a/adafruit_pioasm.py +++ b/adafruit_pioasm.py @@ -25,6 +25,7 @@ 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""" assembled = [] @@ -60,7 +61,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 +101,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 +138,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 +155,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/examples/pioasm_neopixel.py b/examples/pioasm_neopixel.py index 8042aed..cb2ab4e 100644 --- a/examples/pioasm_neopixel.py +++ b/examples/pioasm_neopixel.py @@ -26,14 +26,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..ffed8c0 100644 --- a/examples/pioasm_simpletest.py +++ b/examples/pioasm_simpletest.py @@ -16,10 +16,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) From 7fc8625aeaaf9abb8ac05e199a485cfff07b6b66 Mon Sep 17 00:00:00 2001 From: Scott Shawcroft Date: Thu, 21 Jan 2021 15:35:45 -0800 Subject: [PATCH 2/3] Lint --- adafruit_pioasm.py | 1 + 1 file changed, 1 insertion(+) diff --git a/adafruit_pioasm.py b/adafruit_pioasm.py index 1995137..d10824e 100644 --- a/adafruit_pioasm.py +++ b/adafruit_pioasm.py @@ -28,6 +28,7 @@ def assemble(text_program): """Converts pioasm text to encoded instruction bytes""" + # pylint: disable=too-many-branches,too-many-statements assembled = [] program_name = None labels = {} From 7dc5992975d90e1babf264a27754a76233bd8869 Mon Sep 17 00:00:00 2001 From: Scott Shawcroft Date: Thu, 21 Jan 2021 15:50:02 -0800 Subject: [PATCH 3/3] Example lint and doc TODOs --- README.rst | 28 ++++++++++++++++++++++++---- docs/index.rst | 9 +++++---- examples/pioasm_neopixel.py | 3 +-- examples/pioasm_simpletest.py | 3 +-- 4 files changed, 31 insertions(+), 12 deletions(-) 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/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 cb2ab4e..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). diff --git a/examples/pioasm_simpletest.py b/examples/pioasm_simpletest.py index ffed8c0..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