|
19 | 19 | import adafruit_pixelbuf
|
20 | 20 | import rp2pio
|
21 | 21 |
|
22 |
| -_PROGRAM8 = """ |
| 22 | +_PROGRAM = """ |
23 | 23 | .program piopixl8
|
24 | 24 | top:
|
25 | 25 | mov pins, null ; always-low part (last cycle is the 'pull ifempty' after wrap)
|
|
32 | 32 | bitloop:
|
33 | 33 | pull ifempty [1] ; don't start outputting HIGH unless data is available (always-low part)
|
34 | 34 | mov pins, ~ null [3] ; always-high part
|
35 |
| - out pins, 8 [4] ; variable part |
| 35 | + {} ; variable part |
36 | 36 | mov pins, null ; always-low part (last cycle is the 'pull ifempty' after wrap)
|
37 | 37 |
|
38 | 38 | jmp y--, bitloop ; always-low part
|
|
46 | 46 | jmp top
|
47 | 47 | """
|
48 | 48 |
|
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 |
| -""" |
76 |
| - |
77 |
| -_PROGRAM1 = """ |
78 |
| -.program piopixl8 |
79 |
| -top: |
80 |
| - mov pins, null ; always-low part (last cycle is the 'pull ifempty' after wrap) |
81 |
| - pull block ; wait for fresh data |
82 |
| - out y, 32 ; get count of NeoPixel bits |
83 |
| -
|
84 |
| -; NeoPixels are 800khz bit streams. We are choosing zeros as <312ns hi, 936 lo> |
85 |
| -; and ones as <700 ns hi, 546 ns lo> and a clock of 16*800kHz, so the always-high |
86 |
| -; time is 4 cycles, the variable time is 5 cycles, and the always-low time is 7 cycles |
87 |
| -bitloop: |
88 |
| - pull ifempty [1] ; don't start outputting HIGH unless data is available (always-low part) |
89 |
| - mov pins, ~ null [3] ; always-high part |
90 |
| - out pins, 1 [4] ; variable part |
91 |
| - mov pins, null ; always-low part (last cycle is the 'pull ifempty' after wrap) |
92 |
| -
|
93 |
| - jmp y--, bitloop ; always-low part |
94 |
| -
|
95 |
| -; A minimum delay is required so that the next pixel starts refreshing the front of the strands |
96 |
| - pull block |
97 |
| - out y, 32 |
98 |
| -
|
99 |
| -wait_reset: |
100 |
| - jmp y--, wait_reset |
101 |
| - jmp top |
102 |
| -""" |
103 | 49 |
|
104 | 50 | # Pixel color order constants
|
105 | 51 | RGB = "RGB"
|
@@ -199,12 +145,17 @@ def __init__(
|
199 | 145 | self._num_strands = num_strands
|
200 | 146 |
|
201 | 147 | if num_strands == 8:
|
202 |
| - assembled = adafruit_pioasm.assemble(_PROGRAM8) |
| 148 | + variable_part = "out pins, 8 [4] ; variable part" |
203 | 149 | elif num_strands == 1:
|
204 |
| - assembled = adafruit_pioasm.assemble(_PROGRAM1) |
| 150 | + variable_part = "out pins, 1 [4] ; variable part" |
205 | 151 | else:
|
206 |
| - program = _PROGRAMN.format(num_strands, 8 - num_strands) |
207 |
| - assembled = adafruit_pioasm.assemble(program) |
| 152 | + variable_part = f""" |
| 153 | + out pins, {num_strands} [3] ; variable part |
| 154 | + out x, {8-num_strands} ; variable part |
| 155 | + """ |
| 156 | + |
| 157 | + program = _PROGRAM.format(variable_part) |
| 158 | + assembled = adafruit_pioasm.assemble(program) |
208 | 159 |
|
209 | 160 | self._sm = rp2pio.StateMachine(
|
210 | 161 | assembled,
|
|
0 commit comments