Skip to content

Commit 676ad9e

Browse files
committed
going for v0.3.0
1 parent 4e6ed50 commit 676ad9e

File tree

2 files changed

+13
-22
lines changed

2 files changed

+13
-22
lines changed

experiments/picopio/pio_neo_blink.py

Lines changed: 8 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# https://docs.micropython.org/en/latest/library/rp2.html
1+
# PIO reference: https://docs.micropython.org/en/latest/library/rp2.html
22

33
import time
44
import rp2
@@ -18,6 +18,8 @@
1818
# - 1: 16 cycles high + 9 cycles low
1919
# afterward, delay for 300us
2020

21+
22+
NUM_PIXELS = 4
2123
NEO_PIXELS_IN_PIN = 22
2224

2325
@rp2.asm_pio(set_init=rp2.PIO.OUT_LOW, out_shiftdir=rp2.PIO.SHIFT_LEFT) # SHIFT_LEFT: i.e. most significant bit first
@@ -26,10 +28,10 @@ def neo_prog():
2628
mov(y, osr) # y <= number of pixels - 1
2729
label("loop_pixel")
2830
mov(isr, y) # isr (pixel counter) <= y
29-
pull() # sor <= 24 bits GRB
31+
pull() # osr <= 24 bits GRB
3032
set(x, 23) # x (bit counter) <= 23
3133
label("loop_pixel_bit")
32-
out(y, 1) # y <= left-most 1 bit of sor
34+
out(y, 1) # y <= left-most 1 bit of osr
3335
jmp(not_y, "bit_0")
3436
set(pins, 1).delay(15) # 1: high (16 cycles)
3537
set(pins, 0).delay(8) # 1: low (9 cycles)
@@ -41,15 +43,11 @@ def neo_prog():
4143
jmp(x_dec, "loop_pixel_bit") # x is bit counter
4244
mov(y, isr) # y <= isr (pixel counter)
4345
jmp(y_dec, "loop_pixel") # y is pixel counter
44-
# label("debug")
45-
# set(y, 8)
46-
# label("debug_2")
47-
# mov(isr, y)
48-
# push()
4946

5047
sm = rp2.StateMachine(0, neo_prog, freq=20_000_000, set_base=Pin(NEO_PIXELS_IN_PIN))
5148
sm.active(1)
5249

50+
5351
def ShowNeoPixels(*pixels):
5452
'''
5553
each pixel is the tuple (r, g, b)
@@ -63,25 +61,14 @@ def ShowNeoPixels(*pixels):
6361
else:
6462
(r, g, b) = (0, 0, 0)
6563
grb = (g << 16) + (r << 8) + b # the order is G R B
66-
#print(f". [{i}] = {pixel} ({grb})")
6764
sm.put(grb, 8) # a word is 32 bits, so, pre-shift out (discard) 8 bits, leaving 24 bits of the GRB
6865
time.sleep_us(300) # make sure the NeoPixels is reset for the next round
69-
# res = sm.get()
70-
# print(f"got result {res}")
7166

7267

73-
NUM_PIXELS = 4
7468
Pixels = []
7569
for i in range(NUM_PIXELS):
7670
Pixels.append(None)
7771

78-
# Pixels[0] = (128, 0, 0)
79-
# Pixels[1] = (0, 128, 0)
80-
# Pixels[2] = (0, 0, 128)
81-
# Pixels[3] = (32, 32, 32)
82-
# ShowNeoPixels(*Pixels)
83-
84-
8572
rgb = 0
8673
i = 0
8774
while True:
@@ -97,4 +84,5 @@ def ShowNeoPixels(*pixels):
9784
Pixels[i] = None
9885
ShowNeoPixels(*Pixels)
9986
rgb = (rgb + 1) % 3
100-
i = (i + 1) % NUM_PIXELS
87+
i = (i + 1) % NUM_PIXELS
88+

samples/neopixels/main.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66

77
try:
88

9+
if False:
10+
raise Exception("I don't want to use PIO")
11+
912
import rp2
1013
from machine import Pin
1114

@@ -28,10 +31,10 @@ def neo_prog():
2831
mov(y, osr) # y <= number of pixels - 1
2932
label("loop_pixel")
3033
mov(isr, y) # isr (pixel counter) <= y
31-
pull() # sor <= 24 bits GRB
34+
pull() # osr <= 24 bits GRB
3235
set(x, 23) # x (bit counter) <= 23
3336
label("loop_pixel_bit")
34-
out(y, 1) # y <= left-most 1 bit of sor
37+
out(y, 1) # y <= left-most 1 bit of osr
3538
jmp(not_y, "bit_0")
3639
set(pins, 1).delay(15) # 1: high (16 cycles)
3740
set(pins, 0).delay(8) # 1: low (9 cycles)

0 commit comments

Comments
 (0)