diff --git a/Tlc5940.cpp b/Tlc5940.cpp index 38d2b10..fbe69d7 100644 --- a/Tlc5940.cpp +++ b/Tlc5940.cpp @@ -22,6 +22,7 @@ #include "Tlc5940.h" #include "pinouts/pin_functions.h" + int sin_pin; int sout_pin; int sclk_pin; @@ -57,6 +58,9 @@ volatile void (*tlc_onUpdateFinished)(void); the array is the same as the format of the TLC's serial interface. */ uint8_t tlc_GSData[NUM_TLCS * 24]; +/** Packed DOT Correction data, 12 bytes (16 * 6 bits) per TLC. */ +uint8_t tlc_DCData[NUM_TLCS * 12]; + /** Don't add an extra SCLK pulse after switching from dot-correction mode. */ static uint8_t firstGSInput; @@ -120,6 +124,12 @@ void IRAM_ATTR TLC5940_onTimer() } #endif +#if defined (ARDUINO_ARCH_ESP32) +// SPI to send gray-scale data +const uint32_t TLC5940_SPI_CLK = 8000000; // 8MHz +SPIClass* TLC5940_vspi = NULL; +#endif + /** \defgroup ReqVPRG_ENABLED Functions that Require VPRG_ENABLED Functions that require VPRG_ENABLED == 1. You can enable VPRG by changing @@ -341,7 +351,10 @@ uint8_t Tlc5940::update(void) firstGSInput = 0; } else { #if defined (ARDUINO_ARCH_ESP32) + TLC5940_vspi->end(); // Release SCLK pin + output_pin(sclk_pin); pulse_pin(sclk_pin); + TLC5940_vspi->begin(sclk_pin, sout_pin, sin_pin, -1); #elif pulse_pin(SCLK_PORT, SCLK_PIN); #endif @@ -447,6 +460,14 @@ void Tlc5940::updateDC(void) tlc_shift8(*p++); tlc_shift8(*p++); } + + // dot correction data latch +#if defined (ARDUINO_ARCH_ESP32) + pulse_pin(xlat_pin); +#elif + pulse_pin(XLAT_PORT, XLAT_PIN); +#endif + tlc_dcModeStop(); } @@ -498,7 +519,7 @@ void Tlc5940::setAllDC(uint8_t value) uint8_t firstByte = value << 2 | value >> 4; uint8_t secondByte = value << 4 | value >> 2; uint8_t thirdByte = value << 6 | value; - + uint8_t *p = tlc_DCData; while (p < tlc_DCData + NUM_TLCS * 12) { *p++ = firstByte; *p++ = secondByte; @@ -567,10 +588,6 @@ void tlc_shift8(uint8_t byte) /** Initializes the SPI module */ -// SPI to send gray-scale data -const uint32_t TLC5940_SPI_CLK = 8000000; // 8MHz -SPIClass* TLC5940_vspi = NULL; - void tlc_shift8_init(void) { TLC5940_vspi = new SPIClass(VSPI); diff --git a/tlc_config.h b/tlc_config.h index b8675ef..ee61ca1 100644 --- a/tlc_config.h +++ b/tlc_config.h @@ -108,7 +108,7 @@ - 1 VPRG is connected \note VPRG to GND inputs grayscale data, VPRG to Vcc inputs dot-correction data */ -#define VPRG_ENABLED 0 +#define VPRG_ENABLED 1 /** Enables/disables XERR (TLC pin 16) functionality to check for shorted/broken LEDs diff --git a/tlc_progmem_utils.h b/tlc_progmem_utils.h index a87ae28..eeed4bd 100644 --- a/tlc_progmem_utils.h +++ b/tlc_progmem_utils.h @@ -103,18 +103,15 @@ tlc_setDCfromProgmem(dcArray1); \param dcArray A progmem array of dot correction data to be shifted out. \see \link Tlc5940::setAllDC Tlc.setAllDC \endlink */ -void tlc_setDCfromProgmem(const uint8_t PROGMEM *dcArray) +void tlc_setDCfromProgmem(const uint8_t /*PROGMEM*/ *dcArray) { - tlc_dcModeStart(); - - const uint8_t PROGMEM *p = dcArray; - const uint8_t PROGMEM *dcArrayEnd = dcArray + NUM_TLCS * 12; - while (p < dcArrayEnd) { - tlc_shift8(pgm_read_byte(p++)); + const uint8_t /*PROGMEM*/ *dcArrayp = dcArray; + uint8_t *dcDatap = tlc_DCData; + while (dcDatap < tlc_DCData + NUM_TLCS * 12) { + *dcDatap++ = pgm_read_byte(dcArrayp++); + *dcDatap++ = pgm_read_byte(dcArrayp++); + *dcDatap++ = pgm_read_byte(dcArrayp++); } - pulse_pin(XLAT_PORT, XLAT_PIN); - - tlc_dcModeStop(); } /* @} */