Skip to content

Commit

Permalink
Keybow 2040: use local scope for a small speedup.
Browse files Browse the repository at this point in the history
Bring references to the output buffer and address lookup into the hot path,
gives around a .7ms speedup by using optimised (local scope first) qstr lookups.

Signed-off-by: Phil Howard <github@gadgetoid.com>
  • Loading branch information
Gadgetoid committed Jun 11, 2024
1 parent bfbf0d0 commit 281b027
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions boards/pimoroni/keybow_2040/keybow_2040_rgb.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,16 @@ def __init__(self, size: int = 16): # Kept for backward compatibility
i2c.write(bytes([_SHUTDOWN_REGISTER, 0x01])) # 0 == shutdown, 1 == normal

def _transmit(self, buffer):
# Bring these into local scope for a tiny perf improvement ~.7ms
pixel_addr = self._pixel_addr
out = self.out_buffer
# Shuffle the 16 pixel PixelBuf buffer into our 144 LED
# display native format.
for x in range(self._pixels):
r, g, b = self._pixel_addr[x]
self.out_buffer[r] = buffer[x * 3 + 0]
self.out_buffer[g] = buffer[x * 3 + 1]
self.out_buffer[b] = buffer[x * 3 + 2]
r, g, b = pixel_addr[x]
out[r] = buffer[x * 3 + 0]
out[g] = buffer[x * 3 + 1]
out[b] = buffer[x * 3 + 2]

with self.i2c_device as i2c:
# Switch to our new (not currently visible) frame
Expand Down

0 comments on commit 281b027

Please sign in to comment.