Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 14 additions & 6 deletions TLC5947.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ void TLC5947::init(int8_t num_latches, int8_t num_tlc_one_row, uint8_t use_2D,
_spi_mosi = spi_mosi;
_blank = blank;

mSettings = SPISettings(spi_baud_rate, MSBFIRST, SPI_MODE0);

_use_2D = use_2D;

// Initialize SPI library
Expand All @@ -71,6 +73,9 @@ void TLC5947::setSpiBaudRate(uint32_t new_baud_rate)
{
// Store old baud rate
spi_baud_rate = new_baud_rate;

// update mSettings
mSettings = SPISettings(spi_baud_rate, MSBFIRST, SPI_MODE0);
}

uint32_t TLC5947::getSpiBaudRate()
Expand Down Expand Up @@ -183,10 +188,6 @@ int TLC5947::enforceMaxCurrent(uint32_t * output_counts_ptr){
void TLC5947::updateLeds(){
uint32_t total_output_counts = 0;
int current_too_high = enforceMaxCurrent(&total_output_counts);
if (total_output_counts == 0) {
digitalWrite(_blank, HIGH);
return;
}
if (current_too_high != 0){
return;
}
Expand All @@ -196,12 +197,19 @@ void TLC5947::updateLeds(){
} else {
updateLeds_1D();
}

if (total_output_counts == 0) {
// Setting the blank to high sets the chips into a low power state avoiding
// them getting hot.
digitalWrite(_blank, HIGH);
return;
}
}
void TLC5947::updateLeds_1D(){
uint8_t buffer[3];
uint16_t pwm[2];
// ASSUMING that _grayscale_data is declared as [][LEDS_PER_CHIP][COLOR_CHANNEL_COUNT]
SPI.beginTransaction(SPISettings(spi_baud_rate, MSBFIRST, TLC5947_SPI_MODE));
SPI.beginTransaction(mSettings);
for (int latch_index = _num_latches-1; latch_index>=0; latch_index--)
{
for (int chip = _num_latches * _num_tlc_one_row - (_num_latches - latch_index);
Expand Down Expand Up @@ -265,7 +273,7 @@ void TLC5947::updateLeds_2D(){
// ASSUMING that _grayscale_data is declared as [][LEDS_PER_CHIP][COLOR_CHANNEL_COUNT]
for (int latch_index = _num_latches-1; latch_index>=0; latch_index--)
{
SPI.beginTransaction(SPISettings(spi_baud_rate, MSBFIRST, TLC5947_SPI_MODE));
SPI.beginTransaction(mSettings);
for (int chip = _num_latches * _num_tlc_one_row - (_num_latches - latch_index);
chip >= 0;
chip-=_num_latches)
Expand Down
4 changes: 4 additions & 0 deletions TLC5947.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@

//#include <Arduino.h>
#include <stdint.h>
#include <SPI.h>

// LED Current OUTPUT
static const float LED_CURRENT_AMPS = 0.020;

Expand Down Expand Up @@ -107,6 +109,8 @@ uint8_t rgb_order_default[3] = {0, 1, 2};
uint8_t _buffer;
int8_t _buffer_count = 7;
uint32_t spi_baud_rate = 1000000;

SPISettings mSettings;
};

#endif