Tlc59711 tune (#785)

* a little duplication of constants

* Update Tlc59711GenericMethod.h

remove temp buffer and just send words reversed
add custom default speed that works without flicker
This commit is contained in:
Michael Miller authored and GitHub committed 2024-03-18 17:20:10 -07:00
1 parent 07ae6cf4b3
commit 8062b3a7ce
2 files changed
+47 -59

No files matched your search

+34 -35
View File
@@ -34,6 +34,19 @@ License along with NeoPixel. If not, see
#include "TwoWireDebugImple.h"
#endif
// this custom faster speed works while 3Mhz doesn't
// by works, meaning no flicker between chips
// so it used as the default when speed isn't specified in the method
class SpiSpeed3600Khz
{
public:
typedef NeoNoSettings SettingsObject;
SpiSpeed3600Khz() {};
static void applySettings([[maybe_unused]] const SettingsObject& settings) {}
static constexpr uint32_t Clock = 3600000L;
};
template <typename T_TWOWIRE>
class Tlc59711MethodBase
@@ -46,8 +59,7 @@ public:
uint16_t pixelCount,
size_t elementSize,
size_t settingsSize) :
_sizeData(NeoUtil::RoundUp(pixelCount * elementSize, c_dataPerChipSize) + settingsSize),
_sizeSettings(settingsSize),
_sizeData(NeoUtil::RoundUp(pixelCount * elementSize, Tlc69711Settings::c_dataPerChipSize) + settingsSize),
_wire(pinClock, pinData)
{
_data = static_cast<uint8_t*>(malloc(_sizeData));
@@ -104,43 +116,33 @@ public:
#endif
}
const size_t sizeSetting = (_sizeSettings / 2); // we have two variants
const uint8_t* pSettingsA = _data;
const uint8_t* pSettingsB = _data + sizeSetting;
const uint8_t* pSettings = pSettingsA;
const uint8_t* pSettings = _data; // settings at front
uint8_t reversedData[c_dataPerChipSize];
// note pSrc is pre-decremented before first use
uint16_t* pSrc = reinterpret_cast<uint16_t*>(_data + _sizeData);
uint16_t* pSrcEnd = reinterpret_cast<uint16_t*>(_data + _sizeSettings);
uint16_t* pSrcEnd = reinterpret_cast<uint16_t*>(_data + Tlc69711Settings::c_settingsPerChipSize);
_wire.beginTransaction();
while (pSrc > pSrcEnd)
{
// data needs to be in reverse order when sent
// copy it in reverse order to temp buffer reversedData
// but it is also 16 bit that retains order
uint16_t* pDest = reinterpret_cast<uint16_t*>(reversedData);
uint16_t* pDestEnd = reinterpret_cast<uint16_t*>(reversedData + c_dataPerChipSize);
while (pDest < pDestEnd)
{
*pDest++ = *(--pSrc);
}
// settings
_wire.transmitBytes(pSettings, sizeSetting);
_wire.transmitBytes(pSettings, Tlc69711Settings::c_settingsPerChipSize);
// send this chips "fixed order" data
_wire.transmitBytes(reversedData, c_dataPerChipSize);
// data needs to be in reverse order when sent
// but it is also 16 bit that retains order
// (don't go changing endian)
uint16_t dest;
uint16_t* pSrcChipEnd = pSrc - (Tlc69711Settings::c_dataPerChipSize / 2);
while (pSrc > pSrcChipEnd)
{
// note pre-decrement on pSrc
dest = *(--pSrc);
// toggle settings varient for next chip
if (pSettings == pSettingsA)
{
pSettings = pSettingsB;
}
else
{
pSettings = pSettingsA;
// send this chips "fixed order" data
_wire.transmitByte(dest >> 8);
_wire.transmitByte(dest);
}
}
@@ -171,10 +173,7 @@ public:
}
private:
static constexpr size_t c_dataPerChipSize = 24;
const size_t _sizeData; // Size of '_data' buffer below
const size_t _sizeSettings;
T_TWOWIRE _wire;
uint8_t* _data; // Holds Settings and LED color values
@@ -194,7 +193,7 @@ typedef Tlc59711MethodBase<TwoWireSpiImple<SpiSpeed1Mhz>> Tlc59711Spi1MhzMethod;
typedef Tlc59711MethodBase<TwoWireSpiImple<SpiSpeed500Khz>> Tlc59711Spi500KhzMethod;
typedef Tlc59711MethodBase<TwoWireSpiImple<SpiSpeedHz>> Tlc59711SpiHzMethod;
typedef Tlc59711Spi2MhzMethod Tlc59711SpiMethod;
typedef Tlc59711MethodBase<TwoWireSpiImple<SpiSpeed3600Khz>> Tlc59711SpiMethod;
#endif
#if defined(ARDUINO_ARCH_ESP32)
@@ -208,7 +207,7 @@ typedef Tlc59711MethodBase<TwoWireSpiImple<SpiSpeed1Mhz>> Tlc59711Esp32Vspi1MhzM
typedef Tlc59711MethodBase<TwoWireSpiImple<SpiSpeed500Khz>> Tlc59711Esp32Vspi500KhzMethod;
typedef Tlc59711MethodBase<TwoWireSpiImple<SpiSpeedHz>> Tlc59711Esp32VspiHzMethod;
typedef Tlc59711Spi2MhzMethod Tlc59711Esp32VspiMethod;
typedef Tlc59711MethodBase<TwoWireSpiImple<SpiSpeed3600Khz>> Tlc59711Esp32VspiMethod;
#include "TwoWireHspiImple.h"
typedef Tlc59711MethodBase<TwoWireHspiImple<SpiSpeed40Mhz>> Tlc59711Esp32Hspi40MhzMethod;
@@ -220,5 +219,5 @@ typedef Tlc59711MethodBase<TwoWireHspiImple<SpiSpeed1Mhz>> Tlc59711Esp32Hspi1Mhz
typedef Tlc59711MethodBase<TwoWireHspiImple<SpiSpeed500Khz>> Tlc59711Esp32Hspi500KhzMethod;
typedef Tlc59711MethodBase<TwoWireHspiImple<SpiSpeedHz>> Tlc59711Esp32HspiHzMethod;
typedef Tlc59711Esp32Hspi2MhzMethod Tlc59711Esp32HspiMethod;
typedef Tlc59711MethodBase<TwoWireHspiImple<SpiSpeed3600Khz>> Tlc59711Esp32HspiMethod;
#endif