25
25
26
26
* Adafruit's Bus Device library: https://github.com/adafruit/Adafruit_CircuitPython_BusDevice
27
27
"""
28
+ try :
29
+ from typing import Optional , Tuple , Union
28
30
29
- import adafruit_pixelbuf
31
+ from busio import SPI
32
+ except ImportError :
33
+ pass
30
34
35
+ import adafruit_pixelbuf
31
36
from adafruit_bus_device .spi_device import SPIDevice
32
37
33
-
34
38
__version__ = "0.0.0+auto.0"
35
39
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_NeoPixel_SPI.git"
36
40
37
41
# Pixel color order constants
38
- RGB = "RGB"
42
+ RGB : str = "RGB"
39
43
"""Red Green Blue"""
40
- GRB = "GRB"
44
+ GRB : str = "GRB"
41
45
"""Green Red Blue"""
42
- RGBW = "RGBW"
46
+ RGBW : str = "RGBW"
43
47
"""Red Green Blue White"""
44
- GRBW = "GRBW"
48
+ GRBW : str = "GRBW"
45
49
"""Green Red Blue White"""
46
50
47
51
@@ -57,6 +61,7 @@ class NeoPixel_SPI(adafruit_pixelbuf.PixelBuf):
57
61
:param bool auto_write: True if the neopixels should immediately change when set. If False,
58
62
``show`` must be called explicitly.
59
63
:param tuple pixel_order: Set the pixel color channel order. GRBW is set by default.
64
+ pixel_order may be a string or a tuple of integers with values between 0 and 3.
60
65
:param int frequency: SPI bus frequency. For 800kHz NeoPixels, use 6400000 (default).
61
66
For 400kHz, use 3200000.
62
67
:param float reset_time: Reset low level time in seconds. Default is 80e-6.
@@ -76,19 +81,18 @@ class NeoPixel_SPI(adafruit_pixelbuf.PixelBuf):
76
81
77
82
def __init__ (
78
83
self ,
79
- spi ,
80
- n ,
84
+ spi : SPI ,
85
+ n : int ,
81
86
* ,
82
- bpp = 3 ,
83
- brightness = 1.0 ,
84
- auto_write = True ,
85
- pixel_order = None ,
86
- frequency = 6400000 ,
87
- reset_time = 80e-6 ,
88
- bit0 = 0b11000000 ,
89
- bit1 = 0b11110000
90
- ):
91
-
87
+ bpp : int = 3 ,
88
+ brightness : float = 1.0 ,
89
+ auto_write : bool = True ,
90
+ pixel_order : Optional [Union [str , Tuple [int , ...]]] = None ,
91
+ frequency : int = 6400000 ,
92
+ reset_time : float = 80e-6 ,
93
+ bit0 : int = 0b11000000 ,
94
+ bit1 : int = 0b11110000
95
+ ) -> None :
92
96
# configure bpp and pixel_order
93
97
if not pixel_order :
94
98
pixel_order = GRB if bpp == 3 else GRBW
@@ -117,25 +121,25 @@ def __init__(
117
121
118
122
# everything else taken care of by base class
119
123
super ().__init__ (
120
- n , brightness = brightness , byteorder = pixel_order , auto_write = auto_write
124
+ size = n , brightness = brightness , byteorder = pixel_order , auto_write = auto_write
121
125
)
122
126
123
- def deinit (self ):
127
+ def deinit (self ) -> None :
124
128
"""Blank out the NeoPixels."""
125
129
self .fill (0 )
126
130
self .show ()
127
131
128
- def __repr__ (self ):
132
+ def __repr__ (self ) -> str :
129
133
return "[" + ", " .join ([str (x ) for x in self ]) + "]"
130
134
131
135
@property
132
- def n (self ):
136
+ def n (self ) -> int :
133
137
"""
134
138
The number of neopixels in the chain (read-only)
135
139
"""
136
140
return len (self )
137
141
138
- def _transmit (self , buffer ) :
142
+ def _transmit (self , buffer : bytearray ) -> None :
139
143
"""Shows the new colors on the pixels themselves if they haven't already
140
144
been autowritten."""
141
145
self ._transmogrify (buffer )
@@ -145,7 +149,7 @@ def _transmit(self, buffer):
145
149
# leading RESET needed for cases where MOSI rests HI
146
150
spi .write (self ._reset + self ._spibuf + self ._reset )
147
151
148
- def _transmogrify (self , buffer ) :
152
+ def _transmogrify (self , buffer : bytearray ) -> None :
149
153
"""Turn every BIT of buf into a special BYTE pattern."""
150
154
k = 0
151
155
for byte in buffer :
0 commit comments