libDaisy
Hardware Library for Daisy
Loading...
Searching...
No Matches
daisy::LedDriverPca9685< numDrivers, persistentBufferContents > Class Template Reference

Detailed Description

template<int numDrivers, bool persistentBufferContents = true>
class daisy::LedDriverPca9685< numDrivers, persistentBufferContents >

LED driver for one or multiple PCA9685 12bit PWM chips connected to a single I2C peripheral. It includes gamma correction from 8bit brightness values but it can also be supplied with raw 12bit values. This driver uses two buffers - one for drawing, one for transmitting. Multiple LedDriverPca9685 instances can be used at the same time.

Parameters
numDriversThe number of PCA9685 driver attached to the I2C peripheral.
persistentBufferContentsIf set to true, the current draw buffer contents will be copied to the next draw buffer during SwapBuffersAndTransmit(). Use this, if you plan to write single leds at a time. If you will alway update all leds before calling SwapBuffersAndTransmit(), you can set this to false and safe some cycles.

#include <leddriver.h>

Public Types

using DmaBuffer = PCA9685TransmitBuffer[numDrivers]
 

Public Member Functions

struct __attribute__ ((packed)) PCA9685TransmitBuffer
 
void Init (I2CHandle i2c, const uint8_t(&addresses)[numDrivers], DmaBuffer dma_buffer_a, DmaBuffer dma_buffer_b, Pin oe_pin=Pin(PORTX, 0))
 
constexpr int GetNumLeds () const
 
void SetAllTo (float brightness)
 
void SetAllTo (uint8_t brightness)
 
void SetAllToRaw (uint16_t rawBrightness)
 
void SetLed (int ledIndex, float brightness)
 
void SetLed (int ledIndex, uint8_t brightness)
 
void SetLedRaw (int ledIndex, uint16_t rawBrightness)
 
void SwapBuffersAndTransmit ()
 

Member Typedef Documentation

◆ DmaBuffer

template<int numDrivers, bool persistentBufferContents = true>
using daisy::LedDriverPca9685< numDrivers, persistentBufferContents >::DmaBuffer = PCA9685TransmitBuffer[numDrivers]

Buffer type for the entire DMA buffer.

Member Function Documentation

◆ __attribute__()

template<int numDrivers, bool persistentBufferContents = true>
struct daisy::LedDriverPca9685< numDrivers, persistentBufferContents >::__attribute__ ( (packed )
inline

Buffer Type for a single PCA9685 driver chip.

register address

cycle at which to switch on the led

cycle at which to switch off the led

full size in bytes

◆ GetNumLeds()

template<int numDrivers, bool persistentBufferContents = true>
constexpr int daisy::LedDriverPca9685< numDrivers, persistentBufferContents >::GetNumLeds ( ) const
inlineconstexpr

Returns the number of leds available from this driver.

◆ Init()

template<int numDrivers, bool persistentBufferContents = true>
void daisy::LedDriverPca9685< numDrivers, persistentBufferContents >::Init ( I2CHandle  i2c,
const uint8_t(&)  addresses[numDrivers],
DmaBuffer  dma_buffer_a,
DmaBuffer  dma_buffer_b,
Pin  oe_pin = Pin(PORTX, 0) 
)
inline

Initialises the driver.

Parameters
i2cThe I2C peripheral to use.
addressesAn array of addresses for each of the driver chips.
dma_buffer_aThe first buffer for the DMA. This must be placed in D2 memory by adding the DMA_BUFFER_MEM_SECTION attribute like this: LedDriverPca9685<2>::DmaBuffer DMA_BUFFER_MEM_SECTION bufferA;
dma_buffer_bThe second buffer for the DMA. This must be placed in D2 memory by adding the DMA_BUFFER_MEM_SECTION attribute like this: LedDriverPca9685<2>::DmaBuffer DMA_BUFFER_MEM_SECTION bufferB;
oe_pinIf the output enable pin is used, supply its configuration here. It will automatically be pulled low by the driver.

◆ SetAllTo() [1/2]

template<int numDrivers, bool persistentBufferContents = true>
void daisy::LedDriverPca9685< numDrivers, persistentBufferContents >::SetAllTo ( float  brightness)
inline

Sets all leds to a gamma corrected brightness between 0.0f and 1.0f.

◆ SetAllTo() [2/2]

template<int numDrivers, bool persistentBufferContents = true>
void daisy::LedDriverPca9685< numDrivers, persistentBufferContents >::SetAllTo ( uint8_t  brightness)
inline

Sets all leds to a gamma corrected brightness between 0 and 255.

◆ SetAllToRaw()

template<int numDrivers, bool persistentBufferContents = true>
void daisy::LedDriverPca9685< numDrivers, persistentBufferContents >::SetAllToRaw ( uint16_t  rawBrightness)
inline

Sets all leds to a raw 12bit brightness between 0 and 4095.

◆ SetLed() [1/2]

template<int numDrivers, bool persistentBufferContents = true>
void daisy::LedDriverPca9685< numDrivers, persistentBufferContents >::SetLed ( int  ledIndex,
float  brightness 
)
inline

Sets a single led to a gamma corrected brightness between 0.0f and 1.0f.

◆ SetLed() [2/2]

template<int numDrivers, bool persistentBufferContents = true>
void daisy::LedDriverPca9685< numDrivers, persistentBufferContents >::SetLed ( int  ledIndex,
uint8_t  brightness 
)
inline

Sets a single led to a gamma corrected brightness between 0 and 255.

◆ SetLedRaw()

template<int numDrivers, bool persistentBufferContents = true>
void daisy::LedDriverPca9685< numDrivers, persistentBufferContents >::SetLedRaw ( int  ledIndex,
uint16_t  rawBrightness 
)
inline

Sets a single led to a raw 12bit brightness between 0 and 4095.

◆ SwapBuffersAndTransmit()

template<int numDrivers, bool persistentBufferContents = true>
void daisy::LedDriverPca9685< numDrivers, persistentBufferContents >::SwapBuffersAndTransmit ( )
inline

Swaps the current draw buffer and the current transmit buffer and starts transmitting the values to all chips.


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