summaryrefslogtreecommitdiffstatshomepage
path: root/ports/esp8266/modules/neopixel.py
diff options
context:
space:
mode:
authorJim Mussared <jim.mussared@gmail.com>2021-08-11 15:14:46 +1000
committerDamien George <damien@micropython.org>2021-08-19 22:50:32 +1000
commit39e9c0788fd533d8712d2b19ae93ab8efa56c599 (patch)
treeafdec4da2d0b30e8808f980e30ce75b0ac2b697b /ports/esp8266/modules/neopixel.py
parent71f4faac2732d932dcc03bdbc9f80434e5757edb (diff)
downloadmicropython-39e9c0788fd533d8712d2b19ae93ab8efa56c599.tar.gz
micropython-39e9c0788fd533d8712d2b19ae93ab8efa56c599.zip
esp8266: Replace esp.neopixel with machine.bitstream.
Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
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)