Thanks to visit codestin.com
Credit goes to github.com

Skip to content

All the linty things to fix CI #1

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 3 commits into from
Jan 22, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
28 changes: 24 additions & 4 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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 <https://pypi.org/project/adafruit-circuitpython-pioasm/>`_. To install for current user:

Expand All @@ -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
============
Expand Down
20 changes: 11 additions & 9 deletions adafruit_pioasm.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {}
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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":
Expand All @@ -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:
Expand Down
9 changes: 5 additions & 4 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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 <https://learn.adafruit.com/getting-started-with-raspberry-pi-pico-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 <https://www.adafruit.com/product/4888>
Adafruit Feather RP2040 <https://www.adafruit.com/product/4884>
Raspberry Pi Pico RP2040 <https://www.adafruit.com/product/4864>
Raspberry Pi Pico RP2040 with Loose Headers <https://www.adafruit.com/product/4883>

.. toctree::
:caption: Other Links
Expand Down
21 changes: 11 additions & 10 deletions examples/pioasm_neopixel.py
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand All @@ -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):
Expand Down
13 changes: 7 additions & 6 deletions examples/pioasm_simpletest.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@
#
# SPDX-License-Identifier: MIT

import time
import rp2pio
import board
import time
import adafruit_pioasm
import digitalio

squarewave = """
.program squarewave
Expand All @@ -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)