Open Model Railroad Network (OpenMRN)
Loading...
Searching...
No Matches
Charlieplex< N, helper > Class Template Reference

Class that implements a Charlieplexing LED driver, operating N choose 2 output LEDs from N GPIO pins. More...

#include <Charlieplex.hxx>

Public Member Functions

 Charlieplex (const Gpio *const pins[N])
 Constructor.
 
void tick ()
 Switches to the next output configuration of the charlieplexing pins.
 
unsigned * payload ()
 

Private Attributes

const Gpio *const * pins_
 array of all GPIO pins to use
 
unsigned nextBit_
 LED that comes next.
 
unsigned bits_
 Desired output state of LEDs.
 

Detailed Description

template<unsigned N, class helper = CharlieplexHelper<N>>
class Charlieplex< N, helper >

Class that implements a Charlieplexing LED driver, operating N choose 2 output LEDs from N GPIO pins.

Usage:

Specify the iteration over the pairs of pins like above if you have more than 3 pins.

Create the Charlieplex instance with supplying the Gpio object pointers. The object pointers could point to flash.

Set the desired values for the individual LEDs through payload(). Bit 0 in the pointed object will be the output led 0.

From a hardware timer interrupt repeatedly call the tick() function. A rate of 100 Hz * number of LEDs is advised. It is important that the time between different calls of tick() be somewhat homogenous or else an equal intensity of the individual LEDs that are turned on cannot be guaranteed.

Definition at line 135 of file Charlieplex.hxx.

Constructor & Destructor Documentation

◆ Charlieplex()

template<unsigned N, class helper = CharlieplexHelper<N>>
Charlieplex< N, helper >::Charlieplex ( const Gpio *const  pins[N])
inline

Constructor.

Parameters
pinsan array of Gpio object pointers defining the output pins to use. This array may be in flash (.rodata).

Definition at line 143 of file Charlieplex.hxx.

Member Function Documentation

◆ payload()

template<unsigned N, class helper = CharlieplexHelper<N>>
unsigned * Charlieplex< N, helper >::payload ( )
inline
Returns
the storage representing the state of the output bits. Bit 0 is LED0, bit 1 is LED1, etc.

Definition at line 179 of file Charlieplex.hxx.

◆ tick()

template<unsigned N, class helper = CharlieplexHelper<N>>
void Charlieplex< N, helper >::tick ( )
inline

Switches to the next output configuration of the charlieplexing pins.

Call this repeatedly, for example from a hardware timer interrupt.

Definition at line 157 of file Charlieplex.hxx.

Member Data Documentation

◆ bits_

template<unsigned N, class helper = CharlieplexHelper<N>>
unsigned Charlieplex< N, helper >::bits_
private

Desired output state of LEDs.

Definition at line 187 of file Charlieplex.hxx.

◆ nextBit_

template<unsigned N, class helper = CharlieplexHelper<N>>
unsigned Charlieplex< N, helper >::nextBit_
private

LED that comes next.

Definition at line 186 of file Charlieplex.hxx.

◆ pins_

template<unsigned N, class helper = CharlieplexHelper<N>>
const Gpio* const* Charlieplex< N, helper >::pins_
private

array of all GPIO pins to use

Definition at line 185 of file Charlieplex.hxx.


The documentation for this class was generated from the following file: