From c86c6c0b625f4d83588febf5251b4ff89d7376ce Mon Sep 17 00:00:00 2001 From: Jeff Epler Date: Wed, 16 Nov 2022 10:12:25 -0600 Subject: [PATCH] Support 1-pixel strips .. this calls for a different memory layout to save memory size in the 'background' buffer --- adafruit_neopxl8.py | 57 +++++++++++++++++++++++++++++++++++++++------ 1 file changed, 50 insertions(+), 7 deletions(-) diff --git a/adafruit_neopxl8.py b/adafruit_neopxl8.py index d77879b..6631a74 100644 --- a/adafruit_neopxl8.py +++ b/adafruit_neopxl8.py @@ -74,6 +74,33 @@ wait_reset: jmp top """ +_PROGRAM1 = """ +.program piopixl8 +top: + mov pins, null ; always-low part (last cycle is the 'pull ifempty' after wrap) + pull block ; wait for fresh data + out y, 32 ; get count of NeoPixel bits + +; NeoPixels are 800khz bit streams. We are choosing zeros as <312ns hi, 936 lo> +; and ones as <700 ns hi, 546 ns lo> and a clock of 16*800kHz, so the always-high +; time is 4 cycles, the variable time is 5 cycles, and the always-low time is 7 cycles +bitloop: + pull ifempty [1] ; don't start outputting HIGH unless data is available (always-low part) + mov pins, ~ null [3] ; always-high part + out pins, 1 [4] ; variable part + mov pins, null ; always-low part (last cycle is the 'pull ifempty' after wrap) + + jmp y--, bitloop ; always-low part + +; A minimum delay is required so that the next pixel starts refreshing the front of the strands + pull block + out y, 32 + +wait_reset: + jmp y--, wait_reset + jmp top +""" + # Pixel color order constants RGB = "RGB" """Red Green Blue""" @@ -150,19 +177,31 @@ class NeoPxl8(adafruit_pixelbuf.PixelBuf): n, brightness=brightness, byteorder=pixel_order, auto_write=auto_write ) - data_len = bpp * n * 8 // num_strands + if num_strands == 1: + data_len = bpp * n + pack = ">L" + osr = False + n = (8 * data_len) - 1 + else: + data_len = bpp * n * 8 // num_strands + pack = "