From 03faab34b621d6e3488f3b0aaa83d1e17429fc38 Mon Sep 17 00:00:00 2001 From: Jake Bailey <5341706+jakebailey@users.noreply.github.com> Date: Sun, 9 Aug 2026 23:28:56 -0700 Subject: [PATCH] uc8151: fix LUT timing calculations --- uc8151/uc8151.go | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/uc8151/uc8151.go b/uc8151/uc8151.go index 4367568..ff6bacd 100644 --- a/uc8151/uc8151.go +++ b/uc8151/uc8151.go @@ -412,21 +412,26 @@ func (d *Device) Invert(invert bool) { func (d *Device) SetLUT(speed Speed, flickerFree bool) error { var lut LUTSet + if speed == DEFAULT { + return nil + } + // Num. of frames for single direction change. period := 64 - p := uint8(period / (2 ^ (int(speed) - 1))) + scale := 1 << (int(speed) - 1) + p := uint8(period / scale) if p < 1 { p = 1 } // Num. of frames for back-and-forth change. - hperiod := period % 2 - hp := uint8(hperiod / (2 ^ (int(speed) - 1))) + hperiod := period / 2 + hp := uint8(hperiod / scale) if hp < 1 { hp = 1 } - if speed < FAST && !flickerFree { + if speed <= FAST && !flickerFree { // For low speed everything is charge-neutral, even WB/BW. // Phase 1: long go-inverted-color.