From d92a6ca24eb271f904e3fad95d7cea50380ead03 Mon Sep 17 00:00:00 2001 From: Nathaniel Wesley Filardo Date: Thu, 4 Jun 2020 11:31:55 +0100 Subject: [PATCH] ws2812 vs gpio, take 2 Just use tmr.delay(). It's gross, but it's 350 microseconds. We should be OK. init-early: here, too blackouts: rather than have lamp-touch know what to do, push the logic over to init2 and use the same "later" mechanism to disconnect the UART from the LED array. --- init-early.lua | 1 + init2.lua | 26 +++++++++++++++++--------- lamp-touch.lua | 8 +++----- 3 files changed, 21 insertions(+), 14 deletions(-) diff --git a/init-early.lua b/init-early.lua index 3232176..56b8ebd 100644 --- a/init-early.lua +++ b/init-early.lua @@ -6,6 +6,7 @@ local fb = ws2812.newBuffer(32,3) fb:fill(0,0,0) gpio.write(3,gpio.HIGH) ws2812.write(fb) +tmr.delay(350) gpio.write(3,gpio.LOW) -- Do we have a new LFS blob? If so, install it. diff --git a/init2.lua b/init2.lua index 44f7527..0dc4a44 100644 --- a/init2.lua +++ b/init2.lua @@ -35,8 +35,6 @@ end) ws2812.init(ws2812.MODE_SINGLE) -- uses GPIO2 i2c.setup(0,2,1,i2c.SLOW) -- init i2c as per silk screen (GPIO4, GPIO5) -local inhtmr = tmr.create() - -- and now we get to the lamp stuff remotefb = ws2812.newBuffer(32,3) ledfb = remotefb -- points at whichever buffer is appropriate to draw @@ -58,17 +56,27 @@ function dodraw() -- bits after summation, so adding 127 more means that we now round up -- (i.e., by ceil), so an active channel will remain active. doublefb:mix(127,baselinefb,256/(dimfactor+1),ledfb) - gpio.write(3,gpio.HIGH) ws2812.write(doublefb) + gpio.write(3,gpio.HIGH) + ws2812.write(doublefb) else - gpio.write(3,gpio.HIGH) ws2812.write(ledfb) + gpio.write(3,gpio.HIGH) + ws2812.write(ledfb) end - -- Kick the inhibit timer to turn off the AND gate in 2 msec. That should - -- be ample time to drain the serial UART. If we get here again, we'll end - -- up resetting the timer's firing time, making this something like a - -- watchdog. Hopefully we won't crash in the interim. - inhtmr:alarm(2,tmr.ALARM_SINGLE,function() gpio.write(3,gpio.LOW) end) + -- Wait for the UART to drain and for the LED strip to latch (nominally + -- 350 usec). This isn't really OK, but we're probably not pushing the + -- 15 mSec or so that the SDK says we have? + tmr.delay(350) + gpio.write(3,gpio.LOW) end end +-- Not ideal, but at least this keeps all the gpio wibbling to this one file +function doblackout() + isblackout = true + gpio.write(3,gpio.HIGH) + ws2812.write(string.char(0):rep(32*3)) + tmr.delay(350) + gpio.write(3,gpio.LOW) +end function removeremote() local k,v diff --git a/lamp-touch.lua b/lamp-touch.lua index 5ff2e02..6554817 100644 --- a/lamp-touch.lua +++ b/lamp-touch.lua @@ -1,4 +1,5 @@ --- globals referenced: isblackout, dimfactor, isDim, dodraw, ledfb, remotefb, remotetmr, lamp_announce, tq, loaddrawfn +-- globals referenced: isblackout, doblackout, dimfactor, isDim, dodraw, ledfb, remotefb, \ +-- remotetmr, lamp_announce, tq, loaddrawfn -- -- globals asserted: touchcolor, touchlastfn -- @@ -48,10 +49,7 @@ local set0 = function(o) return bit.bor(o,0x01) end local clear0 = function(o) return bit.band(o,0xFE) end local function setblackout(nb) if nb then - isblackout = true - gpio.write(3,gpio.HIGH) - ws2812.write(string.char(0):rep(32*3)) - gpio.write(3,gpio.LOW) + doblackout() cap:mr(0x81,function(o) return bit.bor(o,0x03) end) -- breathe cap:mr(0x74,set0) -- drive cap:mr(0x72,clear0) -- unlink -- 2.50.1