summaryrefslogtreecommitdiffstatshomepage
path: root/ports/esp8266/modules/neopixel.py
diff options
context:
space:
mode:
Diffstat (limited to 'ports/esp8266/modules/neopixel.py')
-rw-r--r--ports/esp8266/modules/neopixel.py19
1 files changed, 14 insertions, 5 deletions
diff --git a/ports/esp8266/modules/neopixel.py b/ports/esp8266/modules/neopixel.py
index 9dc153372f..9ed5155c72 100644
--- a/ports/esp8266/modules/neopixel.py
+++ b/ports/esp8266/modules/neopixel.py
@@ -1,7 +1,12 @@
-# NeoPixel driver for MicroPython on ESP8266
-# MIT license; Copyright (c) 2016 Damien P. George
+# NeoPixel driver for MicroPython
+# MIT license; Copyright (c) 2016 Damien P. George, 2021 Jim Mussared
-from esp import neopixel_write
+from micropython import const
+from machine import bitstream
+
+_BITSTREAM_TYPE_HIGH_LOW = const(0)
+_TIMING_WS2818_800 = (400, 850, 800, 450)
+_TIMING_WS2818_400 = (800, 1700, 1600, 900)
class NeoPixel:
@@ -13,7 +18,11 @@ class NeoPixel:
self.bpp = bpp
self.buf = bytearray(n * bpp)
self.pin.init(pin.OUT)
- self.timing = timing
+ self.timing = (
+ (_TIMING_WS2818_800 if timing else _TIMING_WS2818_400)
+ if isinstance(timing, int)
+ else timing
+ )
def __len__(self):
return self.n
@@ -32,4 +41,4 @@ class NeoPixel:
self[i] = color
def write(self):
- neopixel_write(self.pin, self.buf, self.timing)
+ bitstream(self.pin, _BITSTREAM_TYPE_HIGH_LOW, self.timing, self.buf)