1. SCLK additional pulse fix

2. Minor bugs
This commit is contained in:
andrey_gulyants
2023-10-27 17:13:21 +01:00
parent 94d98858ec
commit cdddb8bf42
3 changed files with 30 additions and 16 deletions

View File

@@ -22,6 +22,7 @@
#include "Tlc5940.h" #include "Tlc5940.h"
#include "pinouts/pin_functions.h" #include "pinouts/pin_functions.h"
int sin_pin; int sin_pin;
int sout_pin; int sout_pin;
int sclk_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. */ the array is the same as the format of the TLC's serial interface. */
uint8_t tlc_GSData[NUM_TLCS * 24]; 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. */ /** Don't add an extra SCLK pulse after switching from dot-correction mode. */
static uint8_t firstGSInput; static uint8_t firstGSInput;
@@ -120,6 +124,12 @@ void IRAM_ATTR TLC5940_onTimer()
} }
#endif #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 /** \defgroup ReqVPRG_ENABLED Functions that Require VPRG_ENABLED
Functions that require VPRG_ENABLED == 1. Functions that require VPRG_ENABLED == 1.
You can enable VPRG by changing You can enable VPRG by changing
@@ -341,7 +351,10 @@ uint8_t Tlc5940::update(void)
firstGSInput = 0; firstGSInput = 0;
} else { } else {
#if defined (ARDUINO_ARCH_ESP32) #if defined (ARDUINO_ARCH_ESP32)
TLC5940_vspi->end(); // Release SCLK pin
output_pin(sclk_pin);
pulse_pin(sclk_pin); pulse_pin(sclk_pin);
TLC5940_vspi->begin(sclk_pin, sout_pin, sin_pin, -1);
#elif #elif
pulse_pin(SCLK_PORT, SCLK_PIN); pulse_pin(SCLK_PORT, SCLK_PIN);
#endif #endif
@@ -447,6 +460,14 @@ void Tlc5940::updateDC(void)
tlc_shift8(*p++); tlc_shift8(*p++);
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(); tlc_dcModeStop();
} }
@@ -498,7 +519,7 @@ void Tlc5940::setAllDC(uint8_t value)
uint8_t firstByte = value << 2 | value >> 4; uint8_t firstByte = value << 2 | value >> 4;
uint8_t secondByte = value << 4 | value >> 2; uint8_t secondByte = value << 4 | value >> 2;
uint8_t thirdByte = value << 6 | value; uint8_t thirdByte = value << 6 | value;
uint8_t *p = tlc_DCData;
while (p < tlc_DCData + NUM_TLCS * 12) { while (p < tlc_DCData + NUM_TLCS * 12) {
*p++ = firstByte; *p++ = firstByte;
*p++ = secondByte; *p++ = secondByte;
@@ -567,10 +588,6 @@ void tlc_shift8(uint8_t byte)
/** Initializes the SPI module */ /** 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) void tlc_shift8_init(void)
{ {
TLC5940_vspi = new SPIClass(VSPI); TLC5940_vspi = new SPIClass(VSPI);

View File

@@ -108,7 +108,7 @@
- 1 VPRG is connected - 1 VPRG is connected
\note VPRG to GND inputs grayscale data, VPRG to Vcc inputs dot-correction \note VPRG to GND inputs grayscale data, VPRG to Vcc inputs dot-correction
data */ data */
#define VPRG_ENABLED 0 #define VPRG_ENABLED 1
/** Enables/disables XERR (TLC pin 16) functionality to check for shorted/broken /** Enables/disables XERR (TLC pin 16) functionality to check for shorted/broken
LEDs LEDs

View File

@@ -103,18 +103,15 @@ tlc_setDCfromProgmem(dcArray1);
\param dcArray A progmem array of dot correction data to be shifted out. \param dcArray A progmem array of dot correction data to be shifted out.
\see \link Tlc5940::setAllDC Tlc.setAllDC \endlink */ \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*/ *dcArrayp = dcArray;
uint8_t *dcDatap = tlc_DCData;
const uint8_t PROGMEM *p = dcArray; while (dcDatap < tlc_DCData + NUM_TLCS * 12) {
const uint8_t PROGMEM *dcArrayEnd = dcArray + NUM_TLCS * 12; *dcDatap++ = pgm_read_byte(dcArrayp++);
while (p < dcArrayEnd) { *dcDatap++ = pgm_read_byte(dcArrayp++);
tlc_shift8(pgm_read_byte(p++)); *dcDatap++ = pgm_read_byte(dcArrayp++);
} }
pulse_pin(XLAT_PORT, XLAT_PIN);
tlc_dcModeStop();
} }
/* @} */ /* @} */