Skip to content

Commit 5e8b820

Browse files
committed
Black
1 parent 4cd0064 commit 5e8b820

File tree

3 files changed

+26
-21
lines changed

3 files changed

+26
-21
lines changed

adafruit_pioasm.py

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
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"""
3031
assembled = []
@@ -60,7 +61,7 @@ def assemble(text_program):
6061
print(instruction)
6162
instruction = instruction.split()
6263
delay = 0
63-
if instruction[-1].endswith("]"): # Delay
64+
if instruction[-1].endswith("]"): # Delay
6465
delay = int(instruction[-1].strip("[]"))
6566
if delay > max_delay:
6667
raise RuntimeError("Delay too long:", delay)
@@ -100,23 +101,23 @@ def assemble(text_program):
100101
raise RuntimeError("Wait num out of range")
101102
assembled[-1] |= num
102103
if instruction[-1] == "rel":
103-
assembled[-1] |= 0x10 # Set the high bit of the irq value
104+
assembled[-1] |= 0x10 # Set the high bit of the irq value
104105
elif instruction[0] == "in":
105106
# instr delay src count
106107
assembled.append(0b010_00000_000_00000)
107108
assembled[-1] |= IN_SOURCES.index(instruction[1]) << 5
108109
count = int(instruction[-1])
109-
if not 1 <= count <=32:
110+
if not 1 <= count <= 32:
110111
raise RuntimeError("Count out of range")
111-
assembled[-1] |= (count & 0x1f) # 32 is 00000 so we mask the top
112+
assembled[-1] |= count & 0x1F # 32 is 00000 so we mask the top
112113
elif instruction[0] == "out":
113114
# instr delay dst count
114115
assembled.append(0b011_00000_000_00000)
115116
assembled[-1] |= OUT_DESTINATIONS.index(instruction[1]) << 5
116117
count = int(instruction[-1])
117-
if not 1 <= count <=32:
118+
if not 1 <= count <= 32:
118119
raise RuntimeError("Count out of range")
119-
assembled[-1] |= (count & 0x1f) # 32 is 00000 so we mask the top
120+
assembled[-1] |= count & 0x1F # 32 is 00000 so we mask the top
120121
elif instruction[0] == "push" or instruction[0] == "pull":
121122
# instr delay d i b zero
122123
assembled.append(0b100_00000_0_0_0_00000)
@@ -137,13 +138,13 @@ def assemble(text_program):
137138
# instr delay z c w index
138139
assembled.append(0b110_00000_0_0_0_00000)
139140
if instruction[-1] == "rel":
140-
assembled[-1] |= 0x10 # Set the high bit of the irq value
141+
assembled[-1] |= 0x10 # Set the high bit of the irq value
141142
instruction.pop()
142143
num = int(instruction[-1])
143144
if not 0 <= num <= 7:
144145
raise RuntimeError("Interrupt index out of range")
145146
assembled[-1] |= num
146-
if len(instruction) == 3: # after rel has been removed
147+
if len(instruction) == 3: # after rel has been removed
147148
if instruction[1] == "wait":
148149
assembled[-1] |= 0x20
149150
elif instruction[1] == "clear":
@@ -154,7 +155,7 @@ def assemble(text_program):
154155
assembled.append(0b111_00000_000_00000)
155156
assembled[-1] |= SET_DESTINATIONS.index(instruction[1]) << 5
156157
value = int(instruction[-1])
157-
if not 0 <= value <=31:
158+
if not 0 <= value <= 31:
158159
raise RuntimeError("Set value out of range")
159160
assembled[-1] |= value
160161
else:

examples/pioasm_neopixel.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,16 @@
2626

2727
assembled = adafruit_pioasm.assemble(program)
2828

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)
29+
sm = rp2pio.StateMachine(
30+
assembled,
31+
frequency=800000 * 6, # 800khz * 6 clocks per bit
32+
init=adafruit_pioasm.assemble("set pindirs 1"),
33+
first_set_pin=board.D12,
34+
first_sideset_pin=board.D12,
35+
auto_pull=True,
36+
out_shift_right=False,
37+
pull_threshold=8,
38+
)
3739
print("real frequency", sm.frequency)
3840

3941
for i in range(100):

examples/pioasm_simpletest.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,12 @@
1616

1717
assembled = adafruit_pioasm.assemble(squarewave)
1818

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

2527
time.sleep(120)

0 commit comments

Comments
 (0)