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.
numDrivers | The number of PCA9685 driver attached to the I2C peripheral. |
persistentBufferContents | If 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 () |
using daisy::LedDriverPca9685< numDrivers, persistentBufferContents >::DmaBuffer = PCA9685TransmitBuffer[numDrivers] |
Buffer type for the entire DMA buffer.
|
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
|
inlineconstexpr |
Returns the number of leds available from this driver.
|
inline |
Initialises the driver.
i2c | The I2C peripheral to use. |
addresses | An array of addresses for each of the driver chips. |
dma_buffer_a | The 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_b | The 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_pin | If the output enable pin is used, supply its configuration here. It will automatically be pulled low by the driver. |
|
inline |
Sets all leds to a gamma corrected brightness between 0.0f and 1.0f.
|
inline |
Sets all leds to a gamma corrected brightness between 0 and 255.
|
inline |
Sets all leds to a raw 12bit brightness between 0 and 4095.
|
inline |
Sets a single led to a gamma corrected brightness between 0.0f and 1.0f.
|
inline |
Sets a single led to a gamma corrected brightness between 0 and 255.
|
inline |
Sets a single led to a raw 12bit brightness between 0 and 4095.
|
inline |
Swaps the current draw buffer and the current transmit buffer and starts transmitting the values to all chips.