drivers/neopixel: Optimize fill() for speed.

This makes fill() about 7x faster (PYBV11 and PYBD_SF6) for the cost of +40
bytes of bytecode (or 120 bytes text).

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
This commit is contained in:
Jim Mussared 2021-08-20 21:33:15 +10:00 committed by Damien George
parent a3ce8f08ec
commit d63b287c85
1 changed files with 5 additions and 2 deletions

View File

@ -37,8 +37,11 @@ class NeoPixel:
return tuple(self.buf[offset + self.ORDER[i]] for i in range(self.bpp))
def fill(self, color):
for i in range(self.n):
self[i] = color
for i in range(self.bpp):
c = color[i]
b = self.buf
for j in range(self.ORDER[i], len(self.buf), self.bpp):
b[j] = c
def write(self):
bitstream(self.pin, _BITSTREAM_TYPE_HIGH_LOW, self.timing, self.buf)