From 6294e39746e7cbc95477e44c128959b0178700d3 Mon Sep 17 00:00:00 2001 From: "D.R.racer" Date: Fri, 22 Oct 2021 13:46:01 +0200 Subject: [PATCH] Avoid repeated writes into the shift register May reduce flickering of LEDs on some boards --- src/modules/leds.cpp | 6 ++++-- src/modules/leds.h | 3 +++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/modules/leds.cpp b/src/modules/leds.cpp index fc7ac97..5d58415 100644 --- a/src/modules/leds.cpp +++ b/src/modules/leds.cpp @@ -49,8 +49,10 @@ void LEDs::Step() { result <<= 1; result |= leds[i].Step(oddPeriod); } - - hal::shr16::shr16.SetLED(result); + if (result != cachedState) { + hal::shr16::shr16.SetLED(result); + cachedState = result; + } } } // namespace leds diff --git a/src/modules/leds.h b/src/modules/leds.h index 93a2e82..c2afcb0 100644 --- a/src/modules/leds.h +++ b/src/modules/leds.h @@ -130,6 +130,9 @@ private: /// [8] - green LED slot 4 /// [9] - red LED slot 4 LED leds[ledPairs * 2]; + + /// Cache for avoiding duplicit writes into the shift registers (may reduce LED flickering on some boards) + uint16_t cachedState = 0; }; /// The one and only instance of FINDA in the FW