From 6315455dc2b20c357a906ca653054f50de134e41 Mon Sep 17 00:00:00 2001 From: ccook21 Date: Thu, 31 Dec 2020 10:06:47 -0700 Subject: [PATCH 1/2] fix SPI setting management --- TLC5947.cpp | 9 +++++++-- TLC5947.h | 4 ++++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/TLC5947.cpp b/TLC5947.cpp index ffb383d..f5e8e62 100644 --- a/TLC5947.cpp +++ b/TLC5947.cpp @@ -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 @@ -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() @@ -201,7 +206,7 @@ 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); @@ -265,7 +270,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) diff --git a/TLC5947.h b/TLC5947.h index fb3096d..8b8fa05 100644 --- a/TLC5947.h +++ b/TLC5947.h @@ -35,6 +35,8 @@ //#include #include +#include + // LED Current OUTPUT static const float LED_CURRENT_AMPS = 0.020; @@ -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 From 95beb7c283c9d02b560227ece08af42f756cc451 Mon Sep 17 00:00:00 2001 From: Mark Harfouche Date: Fri, 2 Apr 2021 13:10:53 -0400 Subject: [PATCH 2/2] Ensure that pattern is erased when the LEDs are blanked --- TLC5947.cpp | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/TLC5947.cpp b/TLC5947.cpp index f5e8e62..4ac3319 100644 --- a/TLC5947.cpp +++ b/TLC5947.cpp @@ -188,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; } @@ -201,6 +197,13 @@ 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];