hardware/led_controller.h

Addressable-RGB square-highlight framebuffer + driver seam.

Under each of the 64 squares sits a ring of 8 SK6805 addressable RGB LEDs (512 LEDs total, one continuous data chain). This module owns the logical framebuffer, the square->LED “snake” (boustrophedon) mapping, and the hard <=16-lit-squares current-budget invariant. It knows nothing about chess.

The wire itself lives behind ILedDriver so the whole layer is off-Pi testable (SimLedDriver) and the Pi-5/RP1 PWM mechanism can be swapped in without touching anything above the driver. Mirrors the DisplayController / BoardScanner simulation-mode pattern.

See docs/led-docs/PLAN.md (§2-§5) for the design rationale.

struct Rgb
#include <led_controller.h>

Public Functions

inline bool isBlack() const
inline bool operator==(const Rgb &o) const
inline bool operator!=(const Rgb &o) const

Public Members

uint8_t r = 0
uint8_t g = 0
uint8_t b = 0
class ILedDriver
#include <led_controller.h>

Subclassed by SimLedDriver

Public Functions

virtual ~ILedDriver() = default
virtual bool init() = 0
virtual bool writeFrame(const uint8_t *grb, size_t ledCount) = 0
virtual bool isReady() const = 0
class SimLedDriver : public ILedDriver
#include <led_controller.h>

Public Functions

inline virtual bool init() override
virtual bool writeFrame(const uint8_t *grb, size_t ledCount) override
inline virtual bool isReady() const override
inline size_t lastLedCount() const
inline int frameCount() const
int grbByte(size_t index) const

Private Members

uint8_t lastFrame[MAX_BYTES] = {0}
size_t frameLeds = 0
int frames = 0
bool ready = false

Private Static Attributes

static constexpr size_t MAX_BYTES = 512 * 3
class LedController
#include <led_controller.h>

Public Functions

explicit LedController(ILedDriver &driver)
inline bool init()
inline bool isReady() const
bool setSquare(int square, Rgb color)
bool clearSquare(int square)
void clear()
bool show()
inline void setBrightness(uint8_t b)
inline uint8_t getBrightness() const
Rgb squareColor(int square) const
bool isSquareLit(int square) const
int litSquareCount() const

Public Static Functions

static int ledBaseForSquare(int square)

Public Static Attributes

static constexpr int NUM_SQUARES = 64
static constexpr int LEDS_PER_SQUARE = 8
static constexpr int NUM_LEDS = NUM_SQUARES * LEDS_PER_SQUARE
static constexpr int MAX_LIT_SQUARES = 16

Private Members

ILedDriver &driver
Rgb squares[NUM_SQUARES]
uint8_t brightness = 255

Private Static Functions

static uint8_t scale(uint8_t channel, uint8_t bright)