forked from Makuna/NeoPixelBus
Tlc59711 (#783)
* 2Mhz max due to timing requirements with a clock based signal?!
This commit is contained in:
@@ -90,11 +90,11 @@ public:
|
||||
// data
|
||||
_wire.transmitBytes(_data, _sizeData);
|
||||
|
||||
// reset frame
|
||||
// reset frame
|
||||
_wire.transmitBytes(resetFrame, sizeof(resetFrame));
|
||||
|
||||
// end frame
|
||||
|
||||
//
|
||||
// one bit for every two pixels with no less than 1 byte
|
||||
for (size_t endFrameByte = 0; endFrameByte < _sizeEndFrame; endFrameByte++)
|
||||
{
|
||||
|
||||
@@ -0,0 +1,224 @@
|
||||
/*-------------------------------------------------------------------------
|
||||
NeoPixel library helper functions for Tlc59711
|
||||
|
||||
Written by Michael C. Miller.
|
||||
|
||||
I invest time and resources providing this open source code,
|
||||
please support me by dontating (see https://github.com/Makuna/NeoPixelBus)
|
||||
|
||||
-------------------------------------------------------------------------
|
||||
This file is part of the Makuna/NeoPixelBus library.
|
||||
|
||||
NeoPixelBus is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as
|
||||
published by the Free Software Foundation, either version 3 of
|
||||
the License, or (at your option) any later version.
|
||||
|
||||
NeoPixelBus is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with NeoPixel. If not, see
|
||||
<http://www.gnu.org/licenses/>.
|
||||
-------------------------------------------------------------------------*/
|
||||
|
||||
#pragma once
|
||||
|
||||
// must also check for arm due to Teensy incorrectly having ARDUINO_ARCH_AVR set
|
||||
#if defined(ARDUINO_ARCH_AVR) && !defined(__arm__)
|
||||
#include "TwoWireBitBangImpleAvr.h"
|
||||
#else
|
||||
#include "TwoWireBitBangImple.h"
|
||||
#include "TwoWireDebugImple.h"
|
||||
#endif
|
||||
|
||||
|
||||
template <typename T_TWOWIRE>
|
||||
class Tlc59711MethodBase
|
||||
{
|
||||
public:
|
||||
typedef typename T_TWOWIRE::SettingsObject SettingsObject;
|
||||
|
||||
Tlc59711MethodBase(uint8_t pinClock,
|
||||
uint8_t pinData,
|
||||
uint16_t pixelCount,
|
||||
size_t elementSize,
|
||||
size_t settingsSize) :
|
||||
_sizeData(NeoUtil::RoundUp(pixelCount * elementSize, c_dataPerChipSize) + settingsSize),
|
||||
_sizeSettings(settingsSize),
|
||||
_wire(pinClock, pinData)
|
||||
{
|
||||
_data = static_cast<uint8_t*>(malloc(_sizeData));
|
||||
// data cleared later in Begin()
|
||||
}
|
||||
|
||||
#if !defined(__AVR_ATtiny85__) && !defined(ARDUINO_attiny)
|
||||
Tlc59711MethodBase(uint16_t pixelCount, size_t elementSize, size_t settingsSize) :
|
||||
Tlc59711MethodBase(SCK, MOSI, pixelCount, elementSize, settingsSize)
|
||||
{
|
||||
}
|
||||
#endif
|
||||
|
||||
~Tlc59711MethodBase()
|
||||
{
|
||||
free(_data);
|
||||
}
|
||||
|
||||
bool IsReadyToUpdate() const
|
||||
{
|
||||
// need 8 clock periods plus 1.34us for the chips to all latch
|
||||
// slowest clock is 2us clock period, so 8x2+1.24 = ~17.24
|
||||
// since we don't have access to actual clock value at this level
|
||||
// the slowest will be used until a refactor can be made to allow
|
||||
// the actual wire clock (or bitbang estimate of it) at this level
|
||||
|
||||
uint32_t delta = micros() - _endTime;
|
||||
|
||||
return (delta >= 20);
|
||||
}
|
||||
|
||||
#if defined(ARDUINO_ARCH_ESP32)
|
||||
void Initialize(int8_t sck, int8_t miso, int8_t mosi, int8_t ss)
|
||||
{
|
||||
_wire.begin(sck, miso, mosi, ss);
|
||||
|
||||
_endTime = micros();
|
||||
}
|
||||
#endif
|
||||
|
||||
void Initialize()
|
||||
{
|
||||
_wire.begin();
|
||||
|
||||
_endTime = micros();
|
||||
}
|
||||
|
||||
void Update(bool)
|
||||
{
|
||||
while (!IsReadyToUpdate())
|
||||
{
|
||||
#if !defined(ARDUINO_TEEONARDU_LEO) && !defined(ARDUINO_TEEONARDU_FLORA)
|
||||
yield(); // allows for system yield if needed
|
||||
#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;
|
||||
|
||||
uint8_t reversedData[c_dataPerChipSize];
|
||||
uint16_t* pSrc = reinterpret_cast<uint16_t*>(_data + _sizeData);
|
||||
uint16_t* pSrcEnd = reinterpret_cast<uint16_t*>(_data + _sizeSettings);
|
||||
|
||||
_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);
|
||||
|
||||
// send this chips "fixed order" data
|
||||
_wire.transmitBytes(reversedData, c_dataPerChipSize);
|
||||
|
||||
// toggle settings varient for next chip
|
||||
if (pSettings == pSettingsA)
|
||||
{
|
||||
pSettings = pSettingsB;
|
||||
}
|
||||
else
|
||||
{
|
||||
pSettings = pSettingsA;
|
||||
}
|
||||
}
|
||||
|
||||
_wire.endTransaction();
|
||||
|
||||
_endTime = micros();
|
||||
}
|
||||
|
||||
bool AlwaysUpdate()
|
||||
{
|
||||
// this method requires update to be called only if changes to buffer
|
||||
return false;
|
||||
}
|
||||
|
||||
uint8_t* getData() const
|
||||
{
|
||||
return _data;
|
||||
};
|
||||
|
||||
size_t getDataSize() const
|
||||
{
|
||||
return _sizeData;
|
||||
};
|
||||
|
||||
void applySettings([[maybe_unused]] const SettingsObject& settings)
|
||||
{
|
||||
_wire.applySettings(settings);
|
||||
}
|
||||
|
||||
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
|
||||
uint32_t _endTime; // Latch timing reference
|
||||
};
|
||||
|
||||
typedef Tlc59711MethodBase<TwoWireBitBangImple> Tlc59711Method;
|
||||
|
||||
#if !defined(__AVR_ATtiny85__) && !defined(ARDUINO_attiny)
|
||||
#include "TwoWireSpiImple.h"
|
||||
typedef Tlc59711MethodBase<TwoWireSpiImple<SpiSpeed40Mhz>> Tlc59711Spi40MhzMethod;
|
||||
typedef Tlc59711MethodBase<TwoWireSpiImple<SpiSpeed20Mhz>> Tlc59711Spi20MhzMethod;
|
||||
typedef Tlc59711MethodBase<TwoWireSpiImple<SpiSpeed10Mhz>> Tlc59711Spi10MhzMethod;
|
||||
typedef Tlc59711MethodBase<TwoWireSpiImple<SpiSpeed5Mhz>> Tlc59711Spi5MhzMethod;
|
||||
typedef Tlc59711MethodBase<TwoWireSpiImple<SpiSpeed2Mhz>> Tlc59711Spi2MhzMethod;
|
||||
typedef Tlc59711MethodBase<TwoWireSpiImple<SpiSpeed1Mhz>> Tlc59711Spi1MhzMethod;
|
||||
typedef Tlc59711MethodBase<TwoWireSpiImple<SpiSpeed500Khz>> Tlc59711Spi500KhzMethod;
|
||||
typedef Tlc59711MethodBase<TwoWireSpiImple<SpiSpeedHz>> Tlc59711SpiHzMethod;
|
||||
|
||||
typedef Tlc59711Spi2MhzMethod Tlc59711SpiMethod;
|
||||
#endif
|
||||
|
||||
#if defined(ARDUINO_ARCH_ESP32)
|
||||
// Give option to use Vspi alias of Spi class if wanting to specify which SPI peripheral is used on the ESP32
|
||||
typedef Tlc59711MethodBase<TwoWireSpiImple<SpiSpeed40Mhz>> Tlc59711Esp32Vspi40MhzMethod;
|
||||
typedef Tlc59711MethodBase<TwoWireSpiImple<SpiSpeed20Mhz>> Tlc59711Esp32Vspi20MhzMethod;
|
||||
typedef Tlc59711MethodBase<TwoWireSpiImple<SpiSpeed10Mhz>> Tlc59711Esp32Vspi10MhzMethod;
|
||||
typedef Tlc59711MethodBase<TwoWireSpiImple<SpiSpeed5Mhz>> Tlc59711Esp32Vspi5MhzMethod;
|
||||
typedef Tlc59711MethodBase<TwoWireSpiImple<SpiSpeed2Mhz>> Tlc59711Esp32Vspi2MhzMethod;
|
||||
typedef Tlc59711MethodBase<TwoWireSpiImple<SpiSpeed1Mhz>> Tlc59711Esp32Vspi1MhzMethod;
|
||||
typedef Tlc59711MethodBase<TwoWireSpiImple<SpiSpeed500Khz>> Tlc59711Esp32Vspi500KhzMethod;
|
||||
typedef Tlc59711MethodBase<TwoWireSpiImple<SpiSpeedHz>> Tlc59711Esp32VspiHzMethod;
|
||||
|
||||
typedef Tlc59711Spi2MhzMethod Tlc59711Esp32VspiMethod;
|
||||
|
||||
#include "TwoWireHspiImple.h"
|
||||
typedef Tlc59711MethodBase<TwoWireHspiImple<SpiSpeed40Mhz>> Tlc59711Esp32Hspi40MhzMethod;
|
||||
typedef Tlc59711MethodBase<TwoWireHspiImple<SpiSpeed20Mhz>> Tlc59711Esp32Hspi20MhzMethod;
|
||||
typedef Tlc59711MethodBase<TwoWireHspiImple<SpiSpeed10Mhz>> Tlc59711Esp32Hspi10MhzMethod;
|
||||
typedef Tlc59711MethodBase<TwoWireHspiImple<SpiSpeed5Mhz>> Tlc59711Esp32Hspi5MhzMethod;
|
||||
typedef Tlc59711MethodBase<TwoWireHspiImple<SpiSpeed2Mhz>> Tlc59711Esp32Hspi2MhzMethod;
|
||||
typedef Tlc59711MethodBase<TwoWireHspiImple<SpiSpeed1Mhz>> Tlc59711Esp32Hspi1MhzMethod;
|
||||
typedef Tlc59711MethodBase<TwoWireHspiImple<SpiSpeed500Khz>> Tlc59711Esp32Hspi500KhzMethod;
|
||||
typedef Tlc59711MethodBase<TwoWireHspiImple<SpiSpeedHz>> Tlc59711Esp32HspiHzMethod;
|
||||
|
||||
typedef Tlc59711Esp32Hspi2MhzMethod Tlc59711Esp32HspiMethod;
|
||||
#endif
|
||||
@@ -0,0 +1,209 @@
|
||||
/*-------------------------------------------------------------------------
|
||||
NeoPixel library helper functions for DotStars using general Pins (APA102/LPD8806).
|
||||
|
||||
Written by Michael C. Miller.
|
||||
|
||||
I invest time and resources providing this open source code,
|
||||
please support me by dontating (see https://github.com/Makuna/NeoPixelBus)
|
||||
|
||||
-------------------------------------------------------------------------
|
||||
This file is part of the Makuna/NeoPixelBus library.
|
||||
|
||||
NeoPixelBus is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as
|
||||
published by the Free Software Foundation, either version 3 of
|
||||
the License, or (at your option) any later version.
|
||||
|
||||
NeoPixelBus is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with NeoPixel. If not, see
|
||||
<http://www.gnu.org/licenses/>.
|
||||
-------------------------------------------------------------------------*/
|
||||
|
||||
#pragma once
|
||||
|
||||
|
||||
class TwoWireDebugImple
|
||||
{
|
||||
public:
|
||||
typedef NeoNoSettings SettingsObject;
|
||||
|
||||
TwoWireDebugImple(uint8_t pinClock, uint8_t pinData) :
|
||||
_pinClock(pinClock),
|
||||
_pinData(pinData)
|
||||
{
|
||||
}
|
||||
|
||||
~TwoWireDebugImple()
|
||||
{
|
||||
}
|
||||
#if defined(ARDUINO_ARCH_ESP32)
|
||||
void begin(int8_t sck, int8_t miso, int8_t mosi, int8_t ss)
|
||||
{
|
||||
Serial.print("TwoWireDebugImple(sck = ");
|
||||
Serial.print(sck);
|
||||
Serial.print(", mosi = ");
|
||||
Serial.print(mosi);
|
||||
Serial.println(")");
|
||||
}
|
||||
#endif
|
||||
|
||||
void begin()
|
||||
{
|
||||
Serial.print("TwoWireDebugImple(pinClock = ");
|
||||
Serial.print(_pinClock);
|
||||
Serial.print(", pinData = ");
|
||||
Serial.print(_pinData);
|
||||
Serial.println(")");
|
||||
}
|
||||
|
||||
void beginTransaction()
|
||||
{
|
||||
Serial.println("TwoWireDebugImple beginTransaction:");
|
||||
}
|
||||
|
||||
void endTransaction()
|
||||
{
|
||||
Serial.println("TwoWireDebugImple EndTransaction:");
|
||||
Serial.println();
|
||||
}
|
||||
|
||||
void transmitBit(uint8_t bit)
|
||||
{
|
||||
Serial.print(" b");
|
||||
Serial.println(bit);
|
||||
}
|
||||
|
||||
void transmitByte(uint8_t data)
|
||||
{
|
||||
Serial.print(" 0x");
|
||||
|
||||
Serial.print(data >> 4, HEX);
|
||||
Serial.print(data & 0x0f, HEX);
|
||||
Serial.print(" b");
|
||||
|
||||
for (int bit = 7; bit >= 0; bit--)
|
||||
{
|
||||
Serial.print((data & 0x80) ? 1 : 0);
|
||||
data <<= 1;
|
||||
}
|
||||
Serial.println();
|
||||
}
|
||||
|
||||
void transmitBytes(const uint8_t* data, size_t dataSize)
|
||||
{
|
||||
const uint8_t* endData = data + dataSize;
|
||||
while (data < endData)
|
||||
{
|
||||
transmitByte(*data++);
|
||||
}
|
||||
}
|
||||
|
||||
void applySettings([[maybe_unused]] const SettingsObject& settings)
|
||||
{
|
||||
}
|
||||
|
||||
private:
|
||||
const uint8_t _pinClock; // output pin number for clock line
|
||||
const uint8_t _pinData; // output pin number for data line
|
||||
};
|
||||
|
||||
|
||||
template <typename T_TWOWIRE>
|
||||
class TwoWireDebugShimImple : public T_TWOWIRE
|
||||
{
|
||||
public:
|
||||
TwoWireDebugShimImple(uint8_t pinClock, uint8_t pinData) :
|
||||
T_TWOWIRE(pinClock, pinData),
|
||||
_pinClock(pinClock),
|
||||
_pinData(pinData)
|
||||
{
|
||||
}
|
||||
|
||||
#if defined(ARDUINO_ARCH_ESP32)
|
||||
void begin(int8_t sck, int8_t miso, int8_t mosi, int8_t ss)
|
||||
{
|
||||
Serial.print("TwoWireDebugImple(sck = ");
|
||||
Serial.print(sck);
|
||||
Serial.print(", mosi = ");
|
||||
Serial.print(mosi);
|
||||
Serial.println(")");
|
||||
|
||||
T_TWOWIRE::begin(sck, miso, mosi, ss);
|
||||
}
|
||||
#endif
|
||||
|
||||
void begin()
|
||||
{
|
||||
Serial.print("TwoWireDebugImple(pinClock = ");
|
||||
Serial.print(_pinClock);
|
||||
Serial.print(", pinData = ");
|
||||
Serial.print(_pinData);
|
||||
Serial.println(")");
|
||||
|
||||
T_TWOWIRE::begin();
|
||||
}
|
||||
|
||||
void beginTransaction()
|
||||
{
|
||||
Serial.println("TwoWireDebugImple beginTransaction:");
|
||||
|
||||
T_TWOWIRE::beginTransaction();
|
||||
}
|
||||
|
||||
void endTransaction()
|
||||
{
|
||||
Serial.println("TwoWireDebugImple EndTransaction:");
|
||||
Serial.println();
|
||||
|
||||
T_TWOWIRE::endTransaction();
|
||||
}
|
||||
|
||||
void transmitBit(uint8_t bit)
|
||||
{
|
||||
Serial.print(" b");
|
||||
Serial.println(bit);
|
||||
|
||||
T_TWOWIRE::transmitBit(bit);
|
||||
}
|
||||
|
||||
void transmitByte(uint8_t data)
|
||||
{
|
||||
Serial.print(" 0x");
|
||||
|
||||
Serial.print(data >> 4, HEX);
|
||||
Serial.print(data & 0x0f, HEX);
|
||||
Serial.print(" b");
|
||||
|
||||
uint8_t shift = data;
|
||||
|
||||
for (int bit = 7; bit >= 0; bit--)
|
||||
{
|
||||
Serial.print((shift & 0x80) ? 1 : 0);
|
||||
shift <<= 1;
|
||||
}
|
||||
Serial.println();
|
||||
|
||||
T_TWOWIRE::transmitByte(data);
|
||||
}
|
||||
|
||||
void transmitBytes(const uint8_t* data, size_t dataSize)
|
||||
{
|
||||
const uint8_t* endData = data + dataSize;
|
||||
const uint8_t* dataSrc = data;
|
||||
|
||||
while (dataSrc < endData)
|
||||
{
|
||||
transmitByte(*dataSrc++);
|
||||
}
|
||||
T_TWOWIRE::transmitBytes(data, dataSize);
|
||||
}
|
||||
|
||||
private:
|
||||
const uint8_t _pinClock; // output pin number for clock line
|
||||
const uint8_t _pinData; // output pin number for data line
|
||||
};
|
||||
@@ -36,7 +36,7 @@ public:
|
||||
|
||||
static void applySettings([[maybe_unused]] const SettingsObject& settings) {}
|
||||
|
||||
static const uint32_t Clock = 40000000L;
|
||||
static constexpr uint32_t Clock = 40000000L;
|
||||
};
|
||||
|
||||
class SpiSpeed30Mhz
|
||||
@@ -47,7 +47,7 @@ public:
|
||||
|
||||
static void applySettings([[maybe_unused]] const SettingsObject& settings) {}
|
||||
|
||||
static const uint32_t Clock = 30000000L;
|
||||
static constexpr uint32_t Clock = 30000000L;
|
||||
};
|
||||
|
||||
class SpiSpeed20Mhz
|
||||
@@ -58,7 +58,7 @@ public:
|
||||
|
||||
static void applySettings([[maybe_unused]] const SettingsObject& settings) {}
|
||||
|
||||
static const uint32_t Clock = 20000000L;
|
||||
static constexpr uint32_t Clock = 20000000L;
|
||||
};
|
||||
|
||||
class SpiSpeed15Mhz
|
||||
@@ -69,7 +69,7 @@ public:
|
||||
|
||||
static void applySettings([[maybe_unused]] const SettingsObject& settings) {}
|
||||
|
||||
static const uint32_t Clock = 15000000L;
|
||||
static constexpr uint32_t Clock = 15000000L;
|
||||
};
|
||||
|
||||
class SpiSpeed10Mhz
|
||||
@@ -80,7 +80,7 @@ public:
|
||||
|
||||
static void applySettings([[maybe_unused]] const SettingsObject& settings) {}
|
||||
|
||||
static const uint32_t Clock = 10000000L;
|
||||
static constexpr uint32_t Clock = 10000000L;
|
||||
};
|
||||
|
||||
class SpiSpeed5Mhz
|
||||
@@ -91,7 +91,7 @@ public:
|
||||
|
||||
static void applySettings([[maybe_unused]] const SettingsObject& settings) {}
|
||||
|
||||
static const uint32_t Clock = 5000000L;
|
||||
static constexpr uint32_t Clock = 5000000L;
|
||||
};
|
||||
|
||||
class SpiSpeed2Mhz
|
||||
@@ -102,7 +102,7 @@ public:
|
||||
|
||||
static void applySettings([[maybe_unused]] const SettingsObject& settings) {}
|
||||
|
||||
static const uint32_t Clock = 2000000L;
|
||||
static constexpr uint32_t Clock = 2000000L;
|
||||
};
|
||||
|
||||
class SpiSpeed1Mhz
|
||||
@@ -113,7 +113,7 @@ public:
|
||||
|
||||
static void applySettings([[maybe_unused]] const SettingsObject& settings) {}
|
||||
|
||||
static const uint32_t Clock = 1000000L;
|
||||
static constexpr uint32_t Clock = 1000000L;
|
||||
};
|
||||
|
||||
class SpiSpeed500Khz
|
||||
@@ -124,7 +124,7 @@ public:
|
||||
|
||||
static void applySettings([[maybe_unused]] const SettingsObject& settings) {}
|
||||
|
||||
static const uint32_t Clock = 500000L;
|
||||
static constexpr uint32_t Clock = 500000L;
|
||||
};
|
||||
|
||||
class NeoSpiSettings
|
||||
@@ -143,7 +143,7 @@ public:
|
||||
typedef NeoSpiSettings SettingsObject;
|
||||
|
||||
SpiSpeedHz() :
|
||||
Clock(10000000)
|
||||
Clock(SpiSpeed10Mhz::Clock)
|
||||
{};
|
||||
|
||||
void applySettings([[maybe_unused]] const SettingsObject& settings)
|
||||
@@ -154,7 +154,8 @@ public:
|
||||
uint32_t Clock;
|
||||
};
|
||||
|
||||
template<typename T_SPISPEED> class TwoWireSpiImple
|
||||
template <typename T_SPISPEED>
|
||||
class TwoWireSpiImple
|
||||
{
|
||||
public:
|
||||
typedef typename T_SPISPEED::SettingsObject SettingsObject;
|
||||
|
||||
Reference in New Issue
Block a user