34#ifndef _UTILS_CHARLIEPLEXING_HXX_
35#define _UTILS_CHARLIEPLEXING_HXX_
47 static const uint8_t pinlist[];
58 return pinlist[bit << 1];
64 return pinlist[(bit << 1) | 1];
81 static const uint8_t pinlist[];
92 return pinlist[bit << 1];
98 return pinlist[(bit << 1) | 1];
135template <
unsigned N,
class helper = CharlieplexHelper<N>>
class Charlieplex
148 for (
unsigned i = 0; i < N; ++i)
160 Gpio::Direction::DINPUT);
163 if (
nextBit_ >= helper::num_bits()) {
169 Gpio::Direction::DOUTPUT);
172 Gpio::Direction::DOUTPUT);
205 for (
unsigned i = 0; i < N; ++i)
209 for (
unsigned i = 0; i < helper::num_bits(); ++i) {
221 Gpio::Direction::DINPUT);
224 if (
nextBit_ >= helper::num_bits()) {
245 Gpio::Direction::DOUTPUT);
248 Gpio::Direction::DOUTPUT);
268 static constexpr Fixed16 EWMA_RATIO{0, 0xF000};
269 static constexpr Fixed16 EWMA_SUM{16, 0};
278template<
unsigned N,
typename helper>
Class that implements a Charlieplexing LED driver, operating N choose 2 output LEDs from N GPIO pins.
unsigned nextBit_
LED that comes next.
const Gpio *const * pins_
array of all GPIO pins to use
unsigned bits_
Desired output state of LEDs.
void tick()
Switches to the next output configuration of the charlieplexing pins.
Charlieplex(const Gpio *const pins[N])
Constructor.
OS-independent abstraction for GPIO.
virtual void clr() const =0
Clears the GPIO output pin to low.
virtual void set_direction(Direction dir) const =0
Sets the GPIO direction.
virtual void set() const =0
Sets the GPIO output pin to high.
Variant of the Charlieplex class that allows intensity to be set for each individual pin.
uint8_t desiredIntensity_[helper::num_bits()]
Partial lighting of each output.
const Gpio *const * pins_
array of all GPIO pins to use
unsigned nextBit_
LED that comes next.
void tick()
Switches to the next output configuration of the charlieplexing pins.
uninitialized< Fixed16 > actualIntensity_[helper::num_bits()]
How much we actually lit a given pin.
uint8_t * desired_intensity()
WeightedCharlieplex(const Gpio *const pins[helper::num_bits()])
Constructor.
unsigned bits_
Desired output state of LEDs.
Template class that allows allocating storage for an object but not calling its constructor.
T & emplace(Args &&... args)
Constructs the embedded object.
static unsigned num_bits()
static unsigned pin_low(unsigned bit)
Which pin to drive low for a given LED.
static unsigned pin_high(unsigned bit)
Which pin to drive high for a given LED.
static unsigned pin_low(unsigned bit)
Which pin to drive low for a given LED.
static constexpr unsigned num_bits()
static unsigned pin_high(unsigned bit)
Which pin to drive high for a given LED.