Skip to content

Commit 25618d8

Browse files
authored
Merge pull request #1 from tannewt/fix-ci
All the linty things to fix CI
2 parents 4cd0064 + 7dc5992 commit 25618d8

File tree

5 files changed

+58
-33
lines changed

5 files changed

+58
-33
lines changed

README.rst

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,6 @@ Installing from PyPI
3535
.. note:: This library is not available on PyPI yet. Install documentation is included
3636
as a standard element. Stay tuned for PyPI availability!
3737

38-
.. todo:: Remove the above note if PyPI version is/will be available at time of release.
39-
If the library is not planned for PyPI, remove the entire 'Installing from PyPI' section.
40-
4138
On supported GNU/Linux systems like the Raspberry Pi, you can install the driver locally `from
4239
PyPI <https://pypi.org/project/adafruit-circuitpython-pioasm/>`_. To install for current user:
4340

@@ -63,7 +60,30 @@ To install in a virtual environment in your current project:
6360
Usage Example
6461
=============
6562

66-
.. todo:: Add a quick, simple example. It and other examples should live in the examples folder and be included in docs/examples.rst.
63+
.. code-block:: python
64+
65+
import time
66+
import rp2pio
67+
import board
68+
import adafruit_pioasm
69+
70+
squarewave = """
71+
.program squarewave
72+
set pins 1 [1] ; Drive pin high and then delay for one cycle
73+
set pins 0 ; Drive pin low
74+
"""
75+
76+
assembled = adafruit_pioasm.assemble(squarewave)
77+
78+
sm = rp2pio.StateMachine(
79+
assembled,
80+
frequency=80,
81+
init=adafruit_pioasm.assemble("set pindirs 1"),
82+
first_set_pin=board.LED,
83+
)
84+
print("real frequency", sm.frequency)
85+
86+
time.sleep(120)
6787
6888
Contributing
6989
============

adafruit_pioasm.py

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,10 @@
2525
MOV_OPS = [None, "~", "::", None]
2626
SET_DESTINATIONS = ["pins", "x", "y", None, "pindirs", None, None, None]
2727

28+
2829
def assemble(text_program):
2930
"""Converts pioasm text to encoded instruction bytes"""
31+
# pylint: disable=too-many-branches,too-many-statements
3032
assembled = []
3133
program_name = None
3234
labels = {}
@@ -60,7 +62,7 @@ def assemble(text_program):
6062
print(instruction)
6163
instruction = instruction.split()
6264
delay = 0
63-
if instruction[-1].endswith("]"): # Delay
65+
if instruction[-1].endswith("]"): # Delay
6466
delay = int(instruction[-1].strip("[]"))
6567
if delay > max_delay:
6668
raise RuntimeError("Delay too long:", delay)
@@ -100,23 +102,23 @@ def assemble(text_program):
100102
raise RuntimeError("Wait num out of range")
101103
assembled[-1] |= num
102104
if instruction[-1] == "rel":
103-
assembled[-1] |= 0x10 # Set the high bit of the irq value
105+
assembled[-1] |= 0x10 # Set the high bit of the irq value
104106
elif instruction[0] == "in":
105107
# instr delay src count
106108
assembled.append(0b010_00000_000_00000)
107109
assembled[-1] |= IN_SOURCES.index(instruction[1]) << 5
108110
count = int(instruction[-1])
109-
if not 1 <= count <=32:
111+
if not 1 <= count <= 32:
110112
raise RuntimeError("Count out of range")
111-
assembled[-1] |= (count & 0x1f) # 32 is 00000 so we mask the top
113+
assembled[-1] |= count & 0x1F # 32 is 00000 so we mask the top
112114
elif instruction[0] == "out":
113115
# instr delay dst count
114116
assembled.append(0b011_00000_000_00000)
115117
assembled[-1] |= OUT_DESTINATIONS.index(instruction[1]) << 5
116118
count = int(instruction[-1])
117-
if not 1 <= count <=32:
119+
if not 1 <= count <= 32:
118120
raise RuntimeError("Count out of range")
119-
assembled[-1] |= (count & 0x1f) # 32 is 00000 so we mask the top
121+
assembled[-1] |= count & 0x1F # 32 is 00000 so we mask the top
120122
elif instruction[0] == "push" or instruction[0] == "pull":
121123
# instr delay d i b zero
122124
assembled.append(0b100_00000_0_0_0_00000)
@@ -137,13 +139,13 @@ def assemble(text_program):
137139
# instr delay z c w index
138140
assembled.append(0b110_00000_0_0_0_00000)
139141
if instruction[-1] == "rel":
140-
assembled[-1] |= 0x10 # Set the high bit of the irq value
142+
assembled[-1] |= 0x10 # Set the high bit of the irq value
141143
instruction.pop()
142144
num = int(instruction[-1])
143145
if not 0 <= num <= 7:
144146
raise RuntimeError("Interrupt index out of range")
145147
assembled[-1] |= num
146-
if len(instruction) == 3: # after rel has been removed
148+
if len(instruction) == 3: # after rel has been removed
147149
if instruction[1] == "wait":
148150
assembled[-1] |= 0x20
149151
elif instruction[1] == "clear":
@@ -154,7 +156,7 @@ def assemble(text_program):
154156
assembled.append(0b111_00000_000_00000)
155157
assembled[-1] |= SET_DESTINATIONS.index(instruction[1]) << 5
156158
value = int(instruction[-1])
157-
if not 0 <= value <=31:
159+
if not 0 <= value <= 31:
158160
raise RuntimeError("Set value out of range")
159161
assembled[-1] |= value
160162
else:

docs/index.rst

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,15 @@ Table of Contents
2323
.. toctree::
2424
:caption: Tutorials
2525

26-
.. todo:: Add any Learn guide links here. If there are none, then simply delete this todo and leave
27-
the toctree above for use later.
26+
Getting Started with Raspberry Pi Pico and CircuitPython <https://learn.adafruit.com/getting-started-with-raspberry-pi-pico-circuitpython>
2827

2928
.. toctree::
3029
:caption: Related Products
3130

32-
.. todo:: Add any product links here. If there are none, then simply delete this todo and leave
33-
the toctree above for use later.
31+
Adafruit ItsyBitsy RP2040 <https://www.adafruit.com/product/4888>
32+
Adafruit Feather RP2040 <https://www.adafruit.com/product/4884>
33+
Raspberry Pi Pico RP2040 <https://www.adafruit.com/product/4864>
34+
Raspberry Pi Pico RP2040 with Loose Headers <https://www.adafruit.com/product/4883>
3435

3536
.. toctree::
3637
:caption: Other Links

examples/pioasm_neopixel.py

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,10 @@
22
#
33
# SPDX-License-Identifier: MIT
44

5+
import time
56
import rp2pio
67
import board
7-
import time
88
import adafruit_pioasm
9-
import digitalio
109

1110
# NeoPixels are 800khz bit streams. Zeroes are 1/3 duty cycle (~416ns) and ones
1211
# are 2/3 duty cycle (~833ns).
@@ -26,14 +25,16 @@
2625

2726
assembled = adafruit_pioasm.assemble(program)
2827

29-
sm = rp2pio.StateMachine(assembled,
30-
frequency=800000 * 6, # 800khz * 6 clocks per bit
31-
init=adafruit_pioasm.assemble("set pindirs 1"),
32-
first_set_pin=board.D12,
33-
first_sideset_pin=board.D12,
34-
auto_pull=True,
35-
out_shift_right=False,
36-
pull_threshold=8)
28+
sm = rp2pio.StateMachine(
29+
assembled,
30+
frequency=800000 * 6, # 800khz * 6 clocks per bit
31+
init=adafruit_pioasm.assemble("set pindirs 1"),
32+
first_set_pin=board.D12,
33+
first_sideset_pin=board.D12,
34+
auto_pull=True,
35+
out_shift_right=False,
36+
pull_threshold=8,
37+
)
3738
print("real frequency", sm.frequency)
3839

3940
for i in range(100):

examples/pioasm_simpletest.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,10 @@
22
#
33
# SPDX-License-Identifier: MIT
44

5+
import time
56
import rp2pio
67
import board
7-
import time
88
import adafruit_pioasm
9-
import digitalio
109

1110
squarewave = """
1211
.program squarewave
@@ -16,10 +15,12 @@
1615

1716
assembled = adafruit_pioasm.assemble(squarewave)
1817

19-
sm = rp2pio.StateMachine(assembled,
20-
frequency=80,
21-
init=adafruit_pioasm.assemble("set pindirs 1"),
22-
first_set_pin=board.LED)
18+
sm = rp2pio.StateMachine(
19+
assembled,
20+
frequency=80,
21+
init=adafruit_pioasm.assemble("set pindirs 1"),
22+
first_set_pin=board.LED,
23+
)
2324
print("real frequency", sm.frequency)
2425

2526
time.sleep(120)

0 commit comments

Comments
 (0)