|
19 | 19 | import adafruit_pixelbuf
|
20 | 20 | import rp2pio
|
21 | 21 |
|
22 |
| -_PROGRAM = """ |
| 22 | +_PROGRAM8 = """ |
23 | 23 | .program piopixl8
|
24 | 24 | top:
|
25 | 25 | mov pins, null ; always-low part (last cycle is the 'pull ifempty' after wrap)
|
|
46 | 46 | jmp top
|
47 | 47 | """
|
48 | 48 |
|
49 |
| -_ASSEMBLED = adafruit_pioasm.assemble(_PROGRAM) |
| 49 | +_PROGRAMN = """ |
| 50 | +.program piopixl8 |
| 51 | +top: |
| 52 | + mov pins, null ; always-low part (last cycle is the 'pull ifempty' after wrap) |
| 53 | + pull block ; wait for fresh data |
| 54 | + out y, 32 ; get count of NeoPixel bits |
| 55 | +
|
| 56 | +; NeoPixels are 800khz bit streams. We are choosing zeros as <312ns hi, 936 lo> |
| 57 | +; and ones as <700 ns hi, 546 ns lo> and a clock of 16*800kHz, so the always-high |
| 58 | +; time is 4 cycles, the variable time is 5 cycles, and the always-low time is 7 cycles |
| 59 | +bitloop: |
| 60 | + pull ifempty [1] ; don't start outputting HIGH unless data is available (always-low part) |
| 61 | + mov pins, ~ null [3] ; always-high part |
| 62 | + out pins, {} [3] ; variable part |
| 63 | + out x, {} ; variable part |
| 64 | + mov pins, null ; always-low part (last cycle is the 'pull ifempty' after wrap) |
| 65 | +
|
| 66 | + jmp y--, bitloop ; always-low part |
| 67 | +
|
| 68 | +; A minimum delay is required so that the next pixel starts refreshing the front of the strands |
| 69 | + pull block |
| 70 | + out y, 32 |
| 71 | +
|
| 72 | +wait_reset: |
| 73 | + jmp y--, wait_reset |
| 74 | + jmp top |
| 75 | +""" |
50 | 76 |
|
51 | 77 | # Pixel color order constants
|
52 | 78 | RGB = "RGB"
|
@@ -135,11 +161,19 @@ def __init__(
|
135 | 161 |
|
136 | 162 | self._num_strands = num_strands
|
137 | 163 |
|
| 164 | + if num_strands == 8: |
| 165 | + assembled = adafruit_pioasm.assemble(_PROGRAM8) |
| 166 | + else: |
| 167 | + program = _PROGRAMN.format(num_strands, 8 - num_strands) |
| 168 | + print(program) |
| 169 | + assembled = adafruit_pioasm.assemble(program) |
| 170 | + |
| 171 | + print("num strands is", num_strands) |
138 | 172 | self._sm = rp2pio.StateMachine(
|
139 |
| - _ASSEMBLED, |
| 173 | + assembled, |
140 | 174 | frequency=800_000 * 16,
|
141 | 175 | first_out_pin=data0,
|
142 |
| - out_pin_count=8, |
| 176 | + out_pin_count=num_strands, |
143 | 177 | first_set_pin=data0,
|
144 | 178 | auto_pull=False,
|
145 | 179 | out_shift_right=True,
|
|
0 commit comments