@@ -79,8 +79,13 @@ class NeoPixel_SPI(_pixelbuf.PixelBuf):
79
79
:param float brightness: Brightness of the pixels between 0.0 and 1.0 where 1.0 is full
80
80
brightness
81
81
:param bool auto_write: True if the neopixels should immediately change when set. If False,
82
- `show` must be called explicitly.
82
+ `` show` ` must be called explicitly.
83
83
:param tuple pixel_order: Set the pixel color channel order. GRBW is set by default.
84
+ :param int frequency: SPI bus frequency. For 800kHz NeoPixels, use 6400000 (default).
85
+ For 400kHz, use 3200000.
86
+ :param float reset_time: Reset low level time in seconds. Default is 80e-6.
87
+ :param byte bit0: Bit pattern to set timing for a NeoPixel 0 bit.
88
+ :param byte bit1: Bit pattern to set timing for a NeoPixel 1 bit.
84
89
85
90
Example:
86
91
@@ -93,11 +98,19 @@ class NeoPixel_SPI(_pixelbuf.PixelBuf):
93
98
pixels.fill(0xff0000)
94
99
"""
95
100
96
- FREQ = 6400000 # 800kHz * 8, actual may be different
97
- TRST = 80e-6 # Reset code low level time
98
-
99
101
def __init__ (
100
- self , spi , n , * , bpp = 3 , brightness = 1.0 , auto_write = True , pixel_order = None
102
+ self ,
103
+ spi ,
104
+ n ,
105
+ * ,
106
+ bpp = 3 ,
107
+ brightness = 1.0 ,
108
+ auto_write = True ,
109
+ pixel_order = None ,
110
+ frequency = 6400000 ,
111
+ reset_time = 80e-6 ,
112
+ bit0 = 0b11000000 ,
113
+ bit1 = 0b11110000
101
114
):
102
115
103
116
# configure bpp and pixel_order
@@ -109,17 +122,22 @@ def __init__(
109
122
order_list = [RGBW [order ] for order in pixel_order ]
110
123
pixel_order = "" .join (order_list )
111
124
125
+ # neopixel stuff
126
+ self ._bit0 = bit0
127
+ self ._bit1 = bit1
128
+ self ._trst = reset_time
129
+
112
130
# set up SPI related stuff
113
- self ._spi = SPIDevice (spi , baudrate = self . FREQ )
131
+ self ._spi = SPIDevice (spi , baudrate = frequency )
114
132
with self ._spi as spibus :
115
133
try :
116
134
# get actual SPI frequency
117
135
freq = spibus .frequency
118
136
except AttributeError :
119
137
# use nominal
120
- freq = self . FREQ
121
- self ._reset = bytes ([0 ] * round (freq * self .TRST / 8 ))
122
- self .spibuf = bytearray (8 * n * bpp )
138
+ freq = frequency
139
+ self ._reset = bytes ([0 ] * round (freq * self ._trst / 8 ))
140
+ self ._spibuf = bytearray (8 * n * bpp )
123
141
124
142
# everything else taken care of by base class
125
143
super ().__init__ (
@@ -149,7 +167,7 @@ def _transmit(self, buffer):
149
167
with self ._spi as spi :
150
168
# write out special byte sequence surrounded by RESET
151
169
# leading RESET needed for cases where MOSI rests HI
152
- spi .write (self ._reset + self .spibuf + self ._reset )
170
+ spi .write (self ._reset + self ._spibuf + self ._reset )
153
171
154
172
def _transmogrify (self , buffer ):
155
173
"""Turn every BIT of buf into a special BYTE pattern."""
@@ -158,7 +176,7 @@ def _transmogrify(self, buffer):
158
176
# MSB first
159
177
for i in range (7 , - 1 , - 1 ):
160
178
if byte >> i & 0x01 :
161
- self .spibuf [k ] = 0b11110000 # A NeoPixel 1 bit
179
+ self ._spibuf [k ] = self . _bit1 # A NeoPixel 1 bit
162
180
else :
163
- self .spibuf [k ] = 0b11000000 # A NeoPixel 0 bit
181
+ self ._spibuf [k ] = self . _bit0 # A NeoPixel 0 bit
164
182
k += 1
0 commit comments