6
6
7
7
The NeoPixelBackground class defined here is largely compatible with the
8
8
standard NeoPixel class, except that the ``show()`` method returns immediately,
9
- writing data to the LEDs in the background.
9
+ writing data to the LEDs in the background, and setting `auto_write` to true
10
+ causes the data to be continuously sent to the LEDs all the time.
10
11
11
12
Writing the LED data in the background will allow more time for your
12
13
Python code to run, so it may be possible to slightly increase the refresh
43
44
.side_set 1 opt
44
45
.wrap_target
45
46
pull block side 0
46
- out y, 16 side 0 ; get count of NeoPixel bits
47
+ out y, 32 side 0 ; get count of NeoPixel bits
47
48
48
49
bitloop:
49
50
pull ifempty side 0 ; drive low
56
57
jmp y--, bitloop side 0 [4] ; drive low for a zero (short pulse)
57
58
58
59
end_sequence:
59
- pull block side 0 ; get fresh 16 bit delay value
60
- out y, 16 side 0 ; get delay count
60
+ pull block side 0 ; get fresh delay value
61
+ out y, 32 side 0 ; get delay count
61
62
wait_reset:
62
63
jmp y--, wait_reset side 0 ; wait until delay elapses
63
64
.wrap
@@ -79,21 +80,18 @@ def __init__(
79
80
80
81
byte_count = bpp * n
81
82
bit_count = byte_count * 8
82
- padding_count = byte_count % 2
83
+ padding_count = - byte_count % 4
83
84
84
- if bit_count > 65536 :
85
- raise ValueError ("Too many pixels" )
86
-
87
- # backwards, so that ulab byteswap corrects it!
88
- header = struct .pack (">H" , (bit_count - 1 ) & 0xFFFF )
89
- trailer = b"\0 " * padding_count + struct .pack (">H" , 3840 )
85
+ # backwards, so that dma byteswap corrects it!
86
+ header = struct .pack (">L" , bit_count - 1 )
87
+ trailer = b"\0 " * padding_count + struct .pack (">L" , 3840 )
90
88
91
89
self ._sm = StateMachine (
92
90
_program .assembled ,
93
91
auto_pull = False ,
94
92
first_sideset_pin = pin ,
95
93
out_shift_right = False ,
96
- pull_threshold = 16 ,
94
+ pull_threshold = 32 ,
97
95
frequency = 12_800_000 ,
98
96
** _program .pio_kwargs ,
99
97
)
@@ -128,10 +126,10 @@ def auto_write(self, value):
128
126
def _transmit (self , buf ):
129
127
if self ._auto_write :
130
128
if not self ._auto_writing :
131
- self ._sm .background_write (loop = memoryview (buf ).cast ("H " ), swap = True )
129
+ self ._sm .background_write (loop = memoryview (buf ).cast ("L " ), swap = True )
132
130
self ._auto_writing = True
133
131
else :
134
- self ._sm .background_write (memoryview (buf ).cast ("H " ), swap = True )
132
+ self ._sm .background_write (memoryview (buf ).cast ("L " ), swap = True )
135
133
136
134
137
135
if __name__ == "__main__" :
0 commit comments