forked from Makuna/NeoPixelBus
remove tabs (#370)
This commit is contained in:
@ -37,20 +37,20 @@ License along with NeoPixel. If not, see
|
||||
template<typename T_TWOWIRE> class DotStarMethodBase
|
||||
{
|
||||
public:
|
||||
DotStarMethodBase(uint8_t pinClock, uint8_t pinData, uint16_t pixelCount, size_t elementSize, size_t settingsSize) :
|
||||
DotStarMethodBase(uint8_t pinClock, uint8_t pinData, uint16_t pixelCount, size_t elementSize, size_t settingsSize) :
|
||||
_sizeData(pixelCount * elementSize + settingsSize),
|
||||
_sizeEndFrame((pixelCount + 15) / 16), // 16 = div 2 (bit for every two pixels) div 8 (bits to bytes)
|
||||
_wire(pinClock, pinData)
|
||||
_sizeEndFrame((pixelCount + 15) / 16), // 16 = div 2 (bit for every two pixels) div 8 (bits to bytes)
|
||||
_wire(pinClock, pinData)
|
||||
{
|
||||
_data = static_cast<uint8_t*>(malloc(_sizeData));
|
||||
memset(_data, 0, _sizeData);
|
||||
}
|
||||
|
||||
#if !defined(__AVR_ATtiny85__) && !defined(ARDUINO_attiny)
|
||||
DotStarMethodBase(uint16_t pixelCount, size_t elementSize, size_t settingsSize) :
|
||||
DotStarMethodBase(SCK, MOSI, pixelCount, elementSize, settingsSize)
|
||||
{
|
||||
}
|
||||
DotStarMethodBase(uint16_t pixelCount, size_t elementSize, size_t settingsSize) :
|
||||
DotStarMethodBase(SCK, MOSI, pixelCount, elementSize, settingsSize)
|
||||
{
|
||||
}
|
||||
#endif
|
||||
|
||||
~DotStarMethodBase()
|
||||
@ -64,42 +64,42 @@ public:
|
||||
}
|
||||
|
||||
#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);
|
||||
}
|
||||
void Initialize(int8_t sck, int8_t miso, int8_t mosi, int8_t ss)
|
||||
{
|
||||
_wire.begin(sck, miso, mosi, ss);
|
||||
}
|
||||
#endif
|
||||
|
||||
void Initialize()
|
||||
{
|
||||
_wire.begin();
|
||||
_wire.begin();
|
||||
}
|
||||
|
||||
void Update(bool)
|
||||
{
|
||||
const uint8_t startFrame[4] = { 0x00 };
|
||||
const uint8_t resetFrame[4] = { 0x00 };
|
||||
|
||||
_wire.beginTransaction();
|
||||
const uint8_t startFrame[4] = { 0x00 };
|
||||
const uint8_t resetFrame[4] = { 0x00 };
|
||||
|
||||
_wire.beginTransaction();
|
||||
|
||||
// start frame
|
||||
_wire.transmitBytes(startFrame, sizeof(startFrame));
|
||||
_wire.transmitBytes(startFrame, sizeof(startFrame));
|
||||
|
||||
// data
|
||||
_wire.transmitBytes(_data, _sizeData);
|
||||
_wire.transmitBytes(_data, _sizeData);
|
||||
|
||||
// reset frame
|
||||
_wire.transmitBytes(resetFrame, sizeof(resetFrame));
|
||||
_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++)
|
||||
{
|
||||
_wire.transmitByte(0x00);
|
||||
}
|
||||
|
||||
_wire.endTransaction();
|
||||
// one bit for every two pixels with no less than 1 byte
|
||||
for (size_t endFrameByte = 0; endFrameByte < _sizeEndFrame; endFrameByte++)
|
||||
{
|
||||
_wire.transmitByte(0x00);
|
||||
}
|
||||
|
||||
_wire.endTransaction();
|
||||
}
|
||||
|
||||
uint8_t* getData() const
|
||||
@ -113,10 +113,10 @@ public:
|
||||
};
|
||||
|
||||
private:
|
||||
const size_t _sizeData; // Size of '_data' buffer below
|
||||
const size_t _sizeEndFrame;
|
||||
const size_t _sizeData; // Size of '_data' buffer below
|
||||
const size_t _sizeEndFrame;
|
||||
|
||||
T_TWOWIRE _wire;
|
||||
T_TWOWIRE _wire;
|
||||
uint8_t* _data; // Holds LED color values
|
||||
};
|
||||
|
||||
|
@ -114,38 +114,38 @@ public:
|
||||
class Lpd8806BrgFeature : public Lpd88063Elements
|
||||
{
|
||||
public:
|
||||
static void applyPixelColor(uint8_t* pPixels, uint16_t indexPixel, ColorObject color)
|
||||
{
|
||||
uint8_t* p = getPixelAddress(pPixels, indexPixel);
|
||||
static void applyPixelColor(uint8_t* pPixels, uint16_t indexPixel, ColorObject color)
|
||||
{
|
||||
uint8_t* p = getPixelAddress(pPixels, indexPixel);
|
||||
|
||||
*p++ = (color.B >> 1) | 0x80;
|
||||
*p++ = (color.R >> 1) | 0x80;
|
||||
*p = (color.G >> 1) | 0x80;
|
||||
}
|
||||
*p++ = (color.B >> 1) | 0x80;
|
||||
*p++ = (color.R >> 1) | 0x80;
|
||||
*p = (color.G >> 1) | 0x80;
|
||||
}
|
||||
|
||||
static ColorObject retrievePixelColor(const uint8_t* pPixels, uint16_t indexPixel)
|
||||
{
|
||||
ColorObject color;
|
||||
const uint8_t* p = getPixelAddress(pPixels, indexPixel);
|
||||
static ColorObject retrievePixelColor(const uint8_t* pPixels, uint16_t indexPixel)
|
||||
{
|
||||
ColorObject color;
|
||||
const uint8_t* p = getPixelAddress(pPixels, indexPixel);
|
||||
|
||||
color.B = (*p++) << 1;
|
||||
color.R = (*p++) << 1;
|
||||
color.G = (*p) << 1;
|
||||
color.B = (*p++) << 1;
|
||||
color.R = (*p++) << 1;
|
||||
color.G = (*p) << 1;
|
||||
|
||||
return color;
|
||||
}
|
||||
return color;
|
||||
}
|
||||
|
||||
static ColorObject retrievePixelColor_P(PGM_VOID_P pPixels, uint16_t indexPixel)
|
||||
{
|
||||
ColorObject color;
|
||||
const uint8_t* p = getPixelAddress((const uint8_t*)pPixels, indexPixel);
|
||||
static ColorObject retrievePixelColor_P(PGM_VOID_P pPixels, uint16_t indexPixel)
|
||||
{
|
||||
ColorObject color;
|
||||
const uint8_t* p = getPixelAddress((const uint8_t*)pPixels, indexPixel);
|
||||
|
||||
color.B = (pgm_read_byte(p++)) << 1;
|
||||
color.R = (pgm_read_byte(p++)) << 1;
|
||||
color.G = (pgm_read_byte(p)) << 1;
|
||||
color.B = (pgm_read_byte(p++)) << 1;
|
||||
color.R = (pgm_read_byte(p++)) << 1;
|
||||
color.G = (pgm_read_byte(p)) << 1;
|
||||
|
||||
return color;
|
||||
}
|
||||
return color;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
|
@ -37,20 +37,20 @@ License along with NeoPixel. If not, see
|
||||
template<typename T_TWOWIRE> class Lpd8806MethodBase
|
||||
{
|
||||
public:
|
||||
Lpd8806MethodBase(uint8_t pinClock, uint8_t pinData, uint16_t pixelCount, size_t elementSize, size_t settingsSize) :
|
||||
Lpd8806MethodBase(uint8_t pinClock, uint8_t pinData, uint16_t pixelCount, size_t elementSize, size_t settingsSize) :
|
||||
_sizeData(pixelCount * elementSize + settingsSize),
|
||||
_sizeFrame((pixelCount + 31) / 32),
|
||||
_wire(pinClock, pinData)
|
||||
_sizeFrame((pixelCount + 31) / 32),
|
||||
_wire(pinClock, pinData)
|
||||
{
|
||||
_data = static_cast<uint8_t*>(malloc(_sizeData));
|
||||
memset(_data, 0, _sizeData);
|
||||
}
|
||||
|
||||
#if !defined(__AVR_ATtiny85__) && !defined(ARDUINO_attiny)
|
||||
Lpd8806MethodBase(uint16_t pixelCount, size_t elementSize, size_t settingsSize) :
|
||||
Lpd8806MethodBase(SCK, MOSI, pixelCount, elementSize, settingsSize)
|
||||
{
|
||||
}
|
||||
Lpd8806MethodBase(uint16_t pixelCount, size_t elementSize, size_t settingsSize) :
|
||||
Lpd8806MethodBase(SCK, MOSI, pixelCount, elementSize, settingsSize)
|
||||
{
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
@ -65,37 +65,37 @@ public:
|
||||
}
|
||||
|
||||
#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);
|
||||
}
|
||||
void Initialize(int8_t sck, int8_t miso, int8_t mosi, int8_t ss)
|
||||
{
|
||||
_wire.begin(sck, miso, mosi, ss);
|
||||
}
|
||||
#endif
|
||||
|
||||
void Initialize()
|
||||
{
|
||||
_wire.begin();
|
||||
_wire.begin();
|
||||
}
|
||||
|
||||
void Update(bool)
|
||||
{
|
||||
_wire.beginTransaction();
|
||||
_wire.beginTransaction();
|
||||
|
||||
// start frame
|
||||
for (size_t frameByte = 0; frameByte < _sizeFrame; frameByte++)
|
||||
{
|
||||
_wire.transmitByte(0x00);
|
||||
}
|
||||
for (size_t frameByte = 0; frameByte < _sizeFrame; frameByte++)
|
||||
{
|
||||
_wire.transmitByte(0x00);
|
||||
}
|
||||
|
||||
// data
|
||||
_wire.transmitBytes(_data, _sizeData);
|
||||
_wire.transmitBytes(_data, _sizeData);
|
||||
|
||||
// end frame
|
||||
for (size_t frameByte = 0; frameByte < _sizeFrame; frameByte++)
|
||||
{
|
||||
_wire.transmitByte(0xff);
|
||||
}
|
||||
|
||||
_wire.endTransaction();
|
||||
for (size_t frameByte = 0; frameByte < _sizeFrame; frameByte++)
|
||||
{
|
||||
_wire.transmitByte(0xff);
|
||||
}
|
||||
|
||||
_wire.endTransaction();
|
||||
}
|
||||
|
||||
uint8_t* getData() const
|
||||
@ -109,10 +109,10 @@ public:
|
||||
};
|
||||
|
||||
private:
|
||||
const size_t _sizeData; // Size of '_data' buffer below
|
||||
const size_t _sizeFrame;
|
||||
const size_t _sizeData; // Size of '_data' buffer below
|
||||
const size_t _sizeFrame;
|
||||
|
||||
T_TWOWIRE _wire;
|
||||
T_TWOWIRE _wire;
|
||||
uint8_t* _data; // Holds LED color values
|
||||
};
|
||||
|
||||
|
@ -154,10 +154,10 @@ public:
|
||||
class NeoArmMk20dxSpeedPropsApa106
|
||||
{
|
||||
public:
|
||||
static const uint32_t CyclesT0h = (F_CPU / 4000000);
|
||||
static const uint32_t CyclesT1h = (F_CPU / 913750);
|
||||
static const uint32_t Cycles = (F_CPU / 584800);
|
||||
static const uint32_t ResetTimeUs = 50;
|
||||
static const uint32_t CyclesT0h = (F_CPU / 4000000);
|
||||
static const uint32_t CyclesT1h = (F_CPU / 913750);
|
||||
static const uint32_t Cycles = (F_CPU / 584800);
|
||||
static const uint32_t ResetTimeUs = 50;
|
||||
};
|
||||
|
||||
template<typename T_SPEEDPROPS> class NeoArmMk20dxSpeedBase
|
||||
@ -591,32 +591,32 @@ public:
|
||||
uint8_t bitMask = 0x80;
|
||||
|
||||
#if defined(ARDUINO_STM32_FEATHER)
|
||||
uint32_t pinMask = BIT(PIN_MAP[pin].gpio_bit);
|
||||
uint32_t pinMask = BIT(PIN_MAP[pin].gpio_bit);
|
||||
|
||||
volatile uint16_t* set = &(PIN_MAP[pin].gpio_device->regs->BSRRL);
|
||||
volatile uint16_t* clr = &(PIN_MAP[pin].gpio_device->regs->BSRRH);
|
||||
volatile uint16_t* set = &(PIN_MAP[pin].gpio_device->regs->BSRRL);
|
||||
volatile uint16_t* clr = &(PIN_MAP[pin].gpio_device->regs->BSRRH);
|
||||
|
||||
#elif defined(ARDUINO_ARCH_STM32F4)
|
||||
uint32_t pinMask = BIT(pin & 0x0f);
|
||||
uint32_t pinMask = BIT(pin & 0x0f);
|
||||
|
||||
volatile uint16_t* set = &(PIN_MAP[pin].gpio_device->regs->BSRRL);
|
||||
volatile uint16_t* clr = &(PIN_MAP[pin].gpio_device->regs->BSRRH);
|
||||
volatile uint16_t* set = &(PIN_MAP[pin].gpio_device->regs->BSRRL);
|
||||
volatile uint16_t* clr = &(PIN_MAP[pin].gpio_device->regs->BSRRH);
|
||||
|
||||
#elif defined(ARDUINO_ARCH_STM32F1)
|
||||
|
||||
uint32_t pinMask = BIT(PIN_MAP[pin].gpio_bit);
|
||||
uint32_t pinMask = BIT(PIN_MAP[pin].gpio_bit);
|
||||
|
||||
volatile uint32_t* set = &(PIN_MAP[pin].gpio_device->regs->BRR);
|
||||
volatile uint32_t* clr = &(PIN_MAP[pin].gpio_device->regs->BSRR);
|
||||
volatile uint32_t* set = &(PIN_MAP[pin].gpio_device->regs->BRR);
|
||||
volatile uint32_t* clr = &(PIN_MAP[pin].gpio_device->regs->BSRR);
|
||||
|
||||
#elif defined(ARDUINO_ARCH_STM32L4)
|
||||
|
||||
uint32_t pinMask = g_APinDescription[pin].bit;
|
||||
uint32_t pinMask = g_APinDescription[pin].bit;
|
||||
|
||||
GPIO_TypeDef* GPIO = static_cast<GPIO_TypeDef*>(g_APinDescription[pin].GPIO);
|
||||
GPIO_TypeDef* GPIO = static_cast<GPIO_TypeDef*>(g_APinDescription[pin].GPIO);
|
||||
|
||||
volatile uint32_t* set = &(GPIO->BRR);
|
||||
volatile uint32_t* clr = &(GPIO->BSRR);
|
||||
volatile uint32_t* set = &(GPIO->BRR);
|
||||
volatile uint32_t* clr = &(GPIO->BSRR);
|
||||
|
||||
#endif
|
||||
for (;;)
|
||||
|
@ -282,7 +282,7 @@ public:
|
||||
int16_t hSrc,
|
||||
LayoutMapCallback layoutMap)
|
||||
{
|
||||
NeoShaderNop<typename T_COLOR_FEATURE::ColorObject> shaderNop;
|
||||
NeoShaderNop<typename T_COLOR_FEATURE::ColorObject> shaderNop;
|
||||
|
||||
Render<NeoShaderNop<typename T_COLOR_FEATURE::ColorObject>>(destBuffer,
|
||||
shaderNop,
|
||||
|
@ -39,7 +39,7 @@ const uint16_t c_dmaBytesPerPixelBytes = 4;
|
||||
class NeoEsp32I2sSpeedWs2812x
|
||||
{
|
||||
public:
|
||||
const static uint32_t I2sSampleRate = 100000;
|
||||
const static uint32_t I2sSampleRate = 100000;
|
||||
const static uint16_t ByteSendTimeUs = 10;
|
||||
const static uint16_t ResetTimeUs = 300;
|
||||
};
|
||||
@ -47,8 +47,8 @@ public:
|
||||
class NeoEsp32I2sSpeedSk6812
|
||||
{
|
||||
public:
|
||||
const static uint32_t I2sSampleRate = 100000;
|
||||
const static uint16_t ByteSendTimeUs = 10;
|
||||
const static uint32_t I2sSampleRate = 100000;
|
||||
const static uint16_t ByteSendTimeUs = 10;
|
||||
const static uint16_t ResetTimeUs = 80;
|
||||
};
|
||||
|
||||
@ -63,25 +63,25 @@ public:
|
||||
class NeoEsp32I2sSpeed800Kbps
|
||||
{
|
||||
public:
|
||||
const static uint32_t I2sSampleRate = 100000;
|
||||
const static uint16_t ByteSendTimeUs = 10;
|
||||
const static uint32_t I2sSampleRate = 100000;
|
||||
const static uint16_t ByteSendTimeUs = 10;
|
||||
const static uint16_t ResetTimeUs = 50;
|
||||
};
|
||||
|
||||
class NeoEsp32I2sSpeed400Kbps
|
||||
{
|
||||
public:
|
||||
const static uint32_t I2sSampleRate = 50000;
|
||||
const static uint16_t ByteSendTimeUs = 20;
|
||||
const static uint32_t I2sSampleRate = 50000;
|
||||
const static uint16_t ByteSendTimeUs = 20;
|
||||
const static uint16_t ResetTimeUs = 50;
|
||||
};
|
||||
|
||||
class NeoEsp32I2sSpeedApa106
|
||||
{
|
||||
public:
|
||||
const static uint32_t I2sSampleRate = 76000;
|
||||
const static uint16_t ByteSendTimeUs = 14;
|
||||
const static uint16_t ResetTimeUs = 50;
|
||||
const static uint32_t I2sSampleRate = 76000;
|
||||
const static uint16_t ByteSendTimeUs = 14;
|
||||
const static uint16_t ResetTimeUs = 50;
|
||||
};
|
||||
|
||||
class NeoEsp32I2sBusZero
|
||||
@ -99,13 +99,13 @@ public:
|
||||
class NeoEsp32I2sNotInverted
|
||||
{
|
||||
public:
|
||||
const static bool Inverted = false;
|
||||
const static bool Inverted = false;
|
||||
};
|
||||
|
||||
class NeoEsp32I2sInverted
|
||||
{
|
||||
public:
|
||||
const static bool Inverted = true;
|
||||
const static bool Inverted = true;
|
||||
};
|
||||
|
||||
template<typename T_SPEED, typename T_BUS, typename T_INVERT> class NeoEsp32I2sMethodBase
|
||||
@ -117,7 +117,7 @@ public:
|
||||
{
|
||||
uint16_t dmaSettingsSize = c_dmaBytesPerPixelBytes * settingsSize;
|
||||
uint16_t dmaPixelSize = c_dmaBytesPerPixelBytes * elementSize;
|
||||
uint16_t resetSize = c_dmaBytesPerPixelBytes * T_SPEED::ResetTimeUs / T_SPEED::ByteSendTimeUs;
|
||||
uint16_t resetSize = c_dmaBytesPerPixelBytes * T_SPEED::ResetTimeUs / T_SPEED::ByteSendTimeUs;
|
||||
|
||||
_i2sBufferSize = pixelCount * dmaPixelSize + dmaSettingsSize + resetSize;
|
||||
|
||||
@ -155,7 +155,7 @@ public:
|
||||
|
||||
void Initialize()
|
||||
{
|
||||
size_t dmaCount = (_i2sBufferSize + I2S_DMA_MAX_DATA_LEN - 1) / I2S_DMA_MAX_DATA_LEN;
|
||||
size_t dmaCount = (_i2sBufferSize + I2S_DMA_MAX_DATA_LEN - 1) / I2S_DMA_MAX_DATA_LEN;
|
||||
i2sInit(T_BUS::I2sBusNumber, 16, T_SPEED::I2sSampleRate, I2S_CHAN_STEREO, I2S_FIFO_16BIT_DUAL, dmaCount, 0);
|
||||
i2sSetPins(T_BUS::I2sBusNumber, _pin, T_INVERT::Inverted);
|
||||
}
|
||||
|
@ -84,27 +84,27 @@ protected:
|
||||
class NeoEsp32RmtSpeedBase : public NeoEsp32RmtSpeed
|
||||
{
|
||||
public:
|
||||
// this is used rather than the rmt_item32_t as you can't correctly initialize
|
||||
// this is used rather than the rmt_item32_t as you can't correctly initialize
|
||||
// it as a static constexpr within the template
|
||||
inline constexpr static uint32_t Item32Val(uint16_t nsHigh, uint16_t nsLow)
|
||||
{
|
||||
return (FromNs(nsLow) << 16) | (1 << 15) | (FromNs(nsHigh));
|
||||
}
|
||||
inline constexpr static uint32_t Item32Val(uint16_t nsHigh, uint16_t nsLow)
|
||||
{
|
||||
return (FromNs(nsLow) << 16) | (1 << 15) | (FromNs(nsHigh));
|
||||
}
|
||||
|
||||
const static rmt_idle_level_t IdleLevel = RMT_IDLE_LEVEL_LOW;
|
||||
const static rmt_idle_level_t IdleLevel = RMT_IDLE_LEVEL_LOW;
|
||||
};
|
||||
|
||||
class NeoEsp32RmtInvertedSpeedBase : public NeoEsp32RmtSpeed
|
||||
{
|
||||
public:
|
||||
// this is used rather than the rmt_item32_t as you can't correctly initialize
|
||||
// it as a static constexpr within the template
|
||||
inline constexpr static uint32_t Item32Val(uint16_t nsHigh, uint16_t nsLow)
|
||||
{
|
||||
return (FromNs(nsLow) << 16) | (1 << 31) | (FromNs(nsHigh));
|
||||
}
|
||||
// this is used rather than the rmt_item32_t as you can't correctly initialize
|
||||
// it as a static constexpr within the template
|
||||
inline constexpr static uint32_t Item32Val(uint16_t nsHigh, uint16_t nsLow)
|
||||
{
|
||||
return (FromNs(nsLow) << 16) | (1 << 31) | (FromNs(nsHigh));
|
||||
}
|
||||
|
||||
const static rmt_idle_level_t IdleLevel = RMT_IDLE_LEVEL_HIGH;
|
||||
const static rmt_idle_level_t IdleLevel = RMT_IDLE_LEVEL_HIGH;
|
||||
};
|
||||
|
||||
class NeoEsp32RmtSpeedWs2811 : public NeoEsp32RmtSpeedBase
|
||||
@ -125,9 +125,9 @@ public:
|
||||
class NeoEsp32RmtSpeedWs2812x : public NeoEsp32RmtSpeedBase
|
||||
{
|
||||
public:
|
||||
const static DRAM_ATTR uint32_t RmtBit0 = Item32Val(400, 850);
|
||||
const static DRAM_ATTR uint32_t RmtBit1 = Item32Val(800, 450);
|
||||
const static DRAM_ATTR uint16_t RmtDurationReset = FromNs(300000); // 300us
|
||||
const static DRAM_ATTR uint32_t RmtBit0 = Item32Val(400, 850);
|
||||
const static DRAM_ATTR uint32_t RmtBit1 = Item32Val(800, 450);
|
||||
const static DRAM_ATTR uint16_t RmtDurationReset = FromNs(300000); // 300us
|
||||
|
||||
static void IRAM_ATTR Translate(const void* src,
|
||||
rmt_item32_t* dest,
|
||||
@ -201,9 +201,9 @@ public:
|
||||
class NeoEsp32RmtSpeedApa106 : public NeoEsp32RmtSpeedBase
|
||||
{
|
||||
public:
|
||||
const static DRAM_ATTR uint32_t RmtBit0 = Item32Val(400, 1250);
|
||||
const static DRAM_ATTR uint32_t RmtBit1 = Item32Val(1250, 400);
|
||||
const static DRAM_ATTR uint16_t RmtDurationReset = FromNs(50000); // 50us
|
||||
const static DRAM_ATTR uint32_t RmtBit0 = Item32Val(400, 1250);
|
||||
const static DRAM_ATTR uint32_t RmtBit1 = Item32Val(1250, 400);
|
||||
const static DRAM_ATTR uint16_t RmtDurationReset = FromNs(50000); // 50us
|
||||
|
||||
static void IRAM_ATTR Translate(const void* src,
|
||||
rmt_item32_t* dest,
|
||||
@ -216,9 +216,9 @@ public:
|
||||
class NeoEsp32RmtInvertedSpeedWs2811 : public NeoEsp32RmtInvertedSpeedBase
|
||||
{
|
||||
public:
|
||||
const static DRAM_ATTR uint32_t RmtBit0 = Item32Val(300, 950);
|
||||
const static DRAM_ATTR uint32_t RmtBit1 = Item32Val(900, 350);
|
||||
const static DRAM_ATTR uint16_t RmtDurationReset = FromNs(300000); // 300us
|
||||
const static DRAM_ATTR uint32_t RmtBit0 = Item32Val(300, 950);
|
||||
const static DRAM_ATTR uint32_t RmtBit1 = Item32Val(900, 350);
|
||||
const static DRAM_ATTR uint16_t RmtDurationReset = FromNs(300000); // 300us
|
||||
|
||||
static void IRAM_ATTR Translate(const void* src,
|
||||
rmt_item32_t* dest,
|
||||
@ -231,9 +231,9 @@ public:
|
||||
class NeoEsp32RmtInvertedSpeedWs2812x : public NeoEsp32RmtInvertedSpeedBase
|
||||
{
|
||||
public:
|
||||
const static DRAM_ATTR uint32_t RmtBit0 = Item32Val(400, 850);
|
||||
const static DRAM_ATTR uint32_t RmtBit1 = Item32Val(800, 450);
|
||||
const static DRAM_ATTR uint16_t RmtDurationReset = FromNs(300000); // 300us
|
||||
const static DRAM_ATTR uint32_t RmtBit0 = Item32Val(400, 850);
|
||||
const static DRAM_ATTR uint32_t RmtBit1 = Item32Val(800, 450);
|
||||
const static DRAM_ATTR uint16_t RmtDurationReset = FromNs(300000); // 300us
|
||||
|
||||
static void IRAM_ATTR Translate(const void* src,
|
||||
rmt_item32_t* dest,
|
||||
@ -246,9 +246,9 @@ public:
|
||||
class NeoEsp32RmtInvertedSpeedSk6812 : public NeoEsp32RmtInvertedSpeedBase
|
||||
{
|
||||
public:
|
||||
const static DRAM_ATTR uint32_t RmtBit0 = Item32Val(400, 850);
|
||||
const static DRAM_ATTR uint32_t RmtBit1 = Item32Val(800, 450);
|
||||
const static DRAM_ATTR uint16_t RmtDurationReset = FromNs(80000); // 80us
|
||||
const static DRAM_ATTR uint32_t RmtBit0 = Item32Val(400, 850);
|
||||
const static DRAM_ATTR uint32_t RmtBit1 = Item32Val(800, 450);
|
||||
const static DRAM_ATTR uint16_t RmtDurationReset = FromNs(80000); // 80us
|
||||
|
||||
static void IRAM_ATTR Translate(const void* src,
|
||||
rmt_item32_t* dest,
|
||||
@ -277,9 +277,9 @@ public:
|
||||
class NeoEsp32RmtInvertedSpeed800Kbps : public NeoEsp32RmtInvertedSpeedBase
|
||||
{
|
||||
public:
|
||||
const static DRAM_ATTR uint32_t RmtBit0 = Item32Val(400, 850);
|
||||
const static DRAM_ATTR uint32_t RmtBit1 = Item32Val(800, 450);
|
||||
const static DRAM_ATTR uint16_t RmtDurationReset = FromNs(50000); // 50us
|
||||
const static DRAM_ATTR uint32_t RmtBit0 = Item32Val(400, 850);
|
||||
const static DRAM_ATTR uint32_t RmtBit1 = Item32Val(800, 450);
|
||||
const static DRAM_ATTR uint16_t RmtDurationReset = FromNs(50000); // 50us
|
||||
|
||||
static void IRAM_ATTR Translate(const void* src,
|
||||
rmt_item32_t* dest,
|
||||
@ -292,9 +292,9 @@ public:
|
||||
class NeoEsp32RmtInvertedSpeed400Kbps : public NeoEsp32RmtInvertedSpeedBase
|
||||
{
|
||||
public:
|
||||
const static DRAM_ATTR uint32_t RmtBit0 = Item32Val(800, 1700);
|
||||
const static DRAM_ATTR uint32_t RmtBit1 = Item32Val(1600, 900);
|
||||
const static DRAM_ATTR uint16_t RmtDurationReset = FromNs(50000); // 50us
|
||||
const static DRAM_ATTR uint32_t RmtBit0 = Item32Val(800, 1700);
|
||||
const static DRAM_ATTR uint32_t RmtBit1 = Item32Val(1600, 900);
|
||||
const static DRAM_ATTR uint16_t RmtDurationReset = FromNs(50000); // 50us
|
||||
|
||||
static void IRAM_ATTR Translate(const void* src,
|
||||
rmt_item32_t* dest,
|
||||
@ -307,9 +307,9 @@ public:
|
||||
class NeoEsp32RmtInvertedSpeedApa106 : public NeoEsp32RmtInvertedSpeedBase
|
||||
{
|
||||
public:
|
||||
const static DRAM_ATTR uint32_t RmtBit0 = Item32Val(400, 1250);
|
||||
const static DRAM_ATTR uint32_t RmtBit1 = Item32Val(1250, 400);
|
||||
const static DRAM_ATTR uint16_t RmtDurationReset = FromNs(50000); // 50us
|
||||
const static DRAM_ATTR uint32_t RmtBit0 = Item32Val(400, 1250);
|
||||
const static DRAM_ATTR uint32_t RmtBit1 = Item32Val(1250, 400);
|
||||
const static DRAM_ATTR uint16_t RmtDurationReset = FromNs(50000); // 50us
|
||||
|
||||
static void IRAM_ATTR Translate(const void* src,
|
||||
rmt_item32_t* dest,
|
||||
|
@ -68,37 +68,37 @@ struct slc_queue_item
|
||||
class NeoEsp8266DmaSpeedBase
|
||||
{
|
||||
public:
|
||||
static const uint8_t Level = 0x00;
|
||||
static uint16_t Convert(uint8_t value)
|
||||
{
|
||||
const uint16_t bitpatterns[16] =
|
||||
{
|
||||
0b1000100010001000, 0b1000100010001110, 0b1000100011101000, 0b1000100011101110,
|
||||
0b1000111010001000, 0b1000111010001110, 0b1000111011101000, 0b1000111011101110,
|
||||
0b1110100010001000, 0b1110100010001110, 0b1110100011101000, 0b1110100011101110,
|
||||
0b1110111010001000, 0b1110111010001110, 0b1110111011101000, 0b1110111011101110,
|
||||
};
|
||||
static const uint8_t Level = 0x00;
|
||||
static uint16_t Convert(uint8_t value)
|
||||
{
|
||||
const uint16_t bitpatterns[16] =
|
||||
{
|
||||
0b1000100010001000, 0b1000100010001110, 0b1000100011101000, 0b1000100011101110,
|
||||
0b1000111010001000, 0b1000111010001110, 0b1000111011101000, 0b1000111011101110,
|
||||
0b1110100010001000, 0b1110100010001110, 0b1110100011101000, 0b1110100011101110,
|
||||
0b1110111010001000, 0b1110111010001110, 0b1110111011101000, 0b1110111011101110,
|
||||
};
|
||||
|
||||
return bitpatterns[value];
|
||||
}
|
||||
return bitpatterns[value];
|
||||
}
|
||||
};
|
||||
|
||||
class NeoEsp8266DmaInvertedSpeedBase
|
||||
{
|
||||
public:
|
||||
static const uint8_t Level = 0xFF;
|
||||
static uint16_t Convert(uint8_t value)
|
||||
{
|
||||
const uint16_t bitpatterns[16] =
|
||||
{
|
||||
0b0111011101110111, 0b0111011101110001, 0b0111011100010111, 0b0111011100010001,
|
||||
0b0111000101110111, 0b0111000101110001, 0b0111000100010111, 0b0111000100010001,
|
||||
0b0001011101110111, 0b0001011101110001, 0b0001011100010111, 0b0001011100010001,
|
||||
0b0001000101110111, 0b0001000101110001, 0b0001000100010111, 0b0001000100010001,
|
||||
};
|
||||
static const uint8_t Level = 0xFF;
|
||||
static uint16_t Convert(uint8_t value)
|
||||
{
|
||||
const uint16_t bitpatterns[16] =
|
||||
{
|
||||
0b0111011101110111, 0b0111011101110001, 0b0111011100010111, 0b0111011100010001,
|
||||
0b0111000101110111, 0b0111000101110001, 0b0111000100010111, 0b0111000100010001,
|
||||
0b0001011101110111, 0b0001011101110001, 0b0001011100010111, 0b0001011100010001,
|
||||
0b0001000101110111, 0b0001000101110001, 0b0001000100010111, 0b0001000100010001,
|
||||
};
|
||||
|
||||
return bitpatterns[value];
|
||||
}
|
||||
return bitpatterns[value];
|
||||
}
|
||||
};
|
||||
|
||||
class NeoEsp8266DmaSpeed800KbpsBase : public NeoEsp8266DmaSpeedBase
|
||||
@ -145,10 +145,10 @@ public:
|
||||
class NeoEsp8266DmaSpeedApa106 : public NeoEsp8266DmaSpeedBase
|
||||
{
|
||||
public:
|
||||
const static uint32_t I2sClockDivisor = 4;
|
||||
const static uint32_t I2sBaseClockDivisor = 16;
|
||||
const static uint32_t ByteSendTimeUs = 17; // us it takes to send a single pixel element
|
||||
const static uint32_t ResetTimeUs = 50;
|
||||
const static uint32_t I2sClockDivisor = 4;
|
||||
const static uint32_t I2sBaseClockDivisor = 16;
|
||||
const static uint32_t ByteSendTimeUs = 17; // us it takes to send a single pixel element
|
||||
const static uint32_t ResetTimeUs = 50;
|
||||
};
|
||||
|
||||
|
||||
@ -156,21 +156,21 @@ public:
|
||||
class NeoEsp8266DmaInvertedSpeed800KbpsBase : public NeoEsp8266DmaInvertedSpeedBase
|
||||
{
|
||||
public:
|
||||
const static uint32_t I2sClockDivisor = 3;
|
||||
const static uint32_t I2sBaseClockDivisor = 16;
|
||||
const static uint32_t ByteSendTimeUs = 10; // us it takes to send a single pixel element at 800khz speed
|
||||
const static uint32_t I2sClockDivisor = 3;
|
||||
const static uint32_t I2sBaseClockDivisor = 16;
|
||||
const static uint32_t ByteSendTimeUs = 10; // us it takes to send a single pixel element at 800khz speed
|
||||
};
|
||||
|
||||
class NeoEsp8266DmaInvertedSpeedWs2812x : public NeoEsp8266DmaInvertedSpeed800KbpsBase
|
||||
{
|
||||
public:
|
||||
const static uint32_t ResetTimeUs = 300;
|
||||
const static uint32_t ResetTimeUs = 300;
|
||||
};
|
||||
|
||||
class NeoEsp8266DmaInvertedSpeedSk6812 : public NeoEsp8266DmaInvertedSpeed800KbpsBase
|
||||
{
|
||||
public:
|
||||
const static uint32_t ResetTimeUs = 80;
|
||||
const static uint32_t ResetTimeUs = 80;
|
||||
};
|
||||
|
||||
class NeoEsp8266DmaSpeedTm1814 : public NeoEsp8266DmaInvertedSpeed800KbpsBase
|
||||
@ -182,25 +182,25 @@ public:
|
||||
class NeoEsp8266DmaInvertedSpeed800Kbps : public NeoEsp8266DmaInvertedSpeed800KbpsBase
|
||||
{
|
||||
public:
|
||||
const static uint32_t ResetTimeUs = 50;
|
||||
const static uint32_t ResetTimeUs = 50;
|
||||
};
|
||||
|
||||
class NeoEsp8266DmaInvertedSpeed400Kbps : public NeoEsp8266DmaInvertedSpeedBase
|
||||
{
|
||||
public:
|
||||
const static uint32_t I2sClockDivisor = 6;
|
||||
const static uint32_t I2sBaseClockDivisor = 16;
|
||||
const static uint32_t ByteSendTimeUs = 20; // us it takes to send a single pixel element at 400khz speed
|
||||
const static uint32_t ResetTimeUs = 50;
|
||||
const static uint32_t I2sClockDivisor = 6;
|
||||
const static uint32_t I2sBaseClockDivisor = 16;
|
||||
const static uint32_t ByteSendTimeUs = 20; // us it takes to send a single pixel element at 400khz speed
|
||||
const static uint32_t ResetTimeUs = 50;
|
||||
};
|
||||
|
||||
class NeoEsp8266DmaInvertedSpeedApa106 : public NeoEsp8266DmaInvertedSpeedBase
|
||||
{
|
||||
public:
|
||||
const static uint32_t I2sClockDivisor = 4;
|
||||
const static uint32_t I2sBaseClockDivisor = 16;
|
||||
const static uint32_t ByteSendTimeUs = 17; // us it takes to send a single pixel element
|
||||
const static uint32_t ResetTimeUs = 50;
|
||||
const static uint32_t I2sClockDivisor = 4;
|
||||
const static uint32_t I2sBaseClockDivisor = 16;
|
||||
const static uint32_t ByteSendTimeUs = 17; // us it takes to send a single pixel element
|
||||
const static uint32_t ResetTimeUs = 50;
|
||||
};
|
||||
|
||||
enum NeoDmaState
|
||||
|
@ -93,14 +93,14 @@ protected:
|
||||
// clear all invert bits
|
||||
USC0(uartNum) &= ~((1 << UCDTRI) | (1 << UCRTSI) | (1 << UCTXI) | (1 << UCDSRI) | (1 << UCCTSI) | (1 << UCRXI));
|
||||
|
||||
if (!invert)
|
||||
{
|
||||
// For normal operations,
|
||||
// Invert the TX voltage associated with logic level so:
|
||||
// - A logic level 0 will generate a Vcc signal
|
||||
// - A logic level 1 will generate a Gnd signal
|
||||
USC0(uartNum) |= (1 << UCTXI);
|
||||
}
|
||||
if (!invert)
|
||||
{
|
||||
// For normal operations,
|
||||
// Invert the TX voltage associated with logic level so:
|
||||
// - A logic level 0 will generate a Vcc signal
|
||||
// - A logic level 1 will generate a Gnd signal
|
||||
USC0(uartNum) |= (1 << UCTXI);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@ -324,21 +324,21 @@ public:
|
||||
class NeoEsp8266UartSpeedApa106
|
||||
{
|
||||
public:
|
||||
static const uint32_t ByteSendTimeUs = 14; // us it takes to send a single pixel element at 400khz speed
|
||||
static const uint32_t UartBaud = 2339181; // APA106 pulse cycle of 1.71us, 4 serial bytes per NeoByte
|
||||
static const uint32_t ResetTimeUs = 50; // us between data send bursts to reset for next update
|
||||
static const uint32_t ByteSendTimeUs = 14; // us it takes to send a single pixel element at 400khz speed
|
||||
static const uint32_t UartBaud = 2339181; // APA106 pulse cycle of 1.71us, 4 serial bytes per NeoByte
|
||||
static const uint32_t ResetTimeUs = 50; // us between data send bursts to reset for next update
|
||||
};
|
||||
|
||||
class NeoEsp8266UartNotInverted
|
||||
{
|
||||
public:
|
||||
const static bool Inverted = false;
|
||||
const static bool Inverted = false;
|
||||
};
|
||||
|
||||
class NeoEsp8266UartInverted
|
||||
{
|
||||
public:
|
||||
const static bool Inverted = true;
|
||||
const static bool Inverted = true;
|
||||
};
|
||||
|
||||
// NeoEsp8266UartMethodBase is a light shell arround NeoEsp8266Uart or NeoEsp8266AsyncUart that
|
||||
|
@ -42,9 +42,9 @@ License along with NeoPixel. If not, see
|
||||
class NeoEspSpeedWs2811
|
||||
{
|
||||
public:
|
||||
const static uint32_t T0H = (F_CPU / 3333333 - CYCLES_LOOPTEST); // 0.3us
|
||||
const static uint32_t T1H = (F_CPU / 1052632 - CYCLES_LOOPTEST); // 0.95us
|
||||
const static uint32_t Period = (F_CPU / 800000 - CYCLES_LOOPTEST); // 1.25us per bit
|
||||
const static uint32_t T0H = (F_CPU / 3333333 - CYCLES_LOOPTEST); // 0.3us
|
||||
const static uint32_t T1H = (F_CPU / 1052632 - CYCLES_LOOPTEST); // 0.95us
|
||||
const static uint32_t Period = (F_CPU / 800000 - CYCLES_LOOPTEST); // 1.25us per bit
|
||||
};
|
||||
|
||||
class NeoEspSpeedTm1814
|
||||
@ -58,119 +58,119 @@ public:
|
||||
class NeoEspSpeed800Mhz
|
||||
{
|
||||
public:
|
||||
const static uint32_t T0H = (F_CPU / 2500000 - CYCLES_LOOPTEST); // 0.4us
|
||||
const static uint32_t T1H = (F_CPU / 1250000 - CYCLES_LOOPTEST); // 0.8us
|
||||
const static uint32_t Period = (F_CPU / 800000 - CYCLES_LOOPTEST); // 1.25us per bit
|
||||
const static uint32_t T0H = (F_CPU / 2500000 - CYCLES_LOOPTEST); // 0.4us
|
||||
const static uint32_t T1H = (F_CPU / 1250000 - CYCLES_LOOPTEST); // 0.8us
|
||||
const static uint32_t Period = (F_CPU / 800000 - CYCLES_LOOPTEST); // 1.25us per bit
|
||||
};
|
||||
|
||||
class NeoEspSpeed400Mhz
|
||||
{
|
||||
public:
|
||||
const static uint32_t T0H = (F_CPU / 2000000 - CYCLES_LOOPTEST);
|
||||
const static uint32_t T1H = (F_CPU / 833333 - CYCLES_LOOPTEST);
|
||||
const static uint32_t Period = (F_CPU / 400000 - CYCLES_LOOPTEST);
|
||||
const static uint32_t T0H = (F_CPU / 2000000 - CYCLES_LOOPTEST);
|
||||
const static uint32_t T1H = (F_CPU / 833333 - CYCLES_LOOPTEST);
|
||||
const static uint32_t Period = (F_CPU / 400000 - CYCLES_LOOPTEST);
|
||||
};
|
||||
|
||||
class NeoEspPinset
|
||||
{
|
||||
public:
|
||||
const static uint8_t IdleLevel = LOW;
|
||||
const static uint8_t IdleLevel = LOW;
|
||||
|
||||
inline static void setPin(const uint32_t pinRegister)
|
||||
{
|
||||
inline static void setPin(const uint32_t pinRegister)
|
||||
{
|
||||
#if defined(ARDUINO_ARCH_ESP32)
|
||||
GPIO.out_w1ts = pinRegister;
|
||||
GPIO.out_w1ts = pinRegister;
|
||||
#else
|
||||
GPIO_REG_WRITE(GPIO_OUT_W1TS_ADDRESS, pinRegister);
|
||||
GPIO_REG_WRITE(GPIO_OUT_W1TS_ADDRESS, pinRegister);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
inline static void resetPin(const uint32_t pinRegister)
|
||||
{
|
||||
inline static void resetPin(const uint32_t pinRegister)
|
||||
{
|
||||
#if defined(ARDUINO_ARCH_ESP32)
|
||||
GPIO.out_w1tc = pinRegister;
|
||||
GPIO.out_w1tc = pinRegister;
|
||||
#else
|
||||
GPIO_REG_WRITE(GPIO_OUT_W1TC_ADDRESS, pinRegister);
|
||||
GPIO_REG_WRITE(GPIO_OUT_W1TC_ADDRESS, pinRegister);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
class NeoEspPinsetInverted
|
||||
{
|
||||
public:
|
||||
const static uint8_t IdleLevel = HIGH;
|
||||
const static uint8_t IdleLevel = HIGH;
|
||||
|
||||
inline static void setPin(const uint32_t pinRegister)
|
||||
{
|
||||
inline static void setPin(const uint32_t pinRegister)
|
||||
{
|
||||
#if defined(ARDUINO_ARCH_ESP32)
|
||||
GPIO.out_w1tc = pinRegister;
|
||||
GPIO.out_w1tc = pinRegister;
|
||||
#else
|
||||
GPIO_REG_WRITE(GPIO_OUT_W1TC_ADDRESS, pinRegister);
|
||||
GPIO_REG_WRITE(GPIO_OUT_W1TC_ADDRESS, pinRegister);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
inline static void resetPin(const uint32_t pinRegister)
|
||||
{
|
||||
inline static void resetPin(const uint32_t pinRegister)
|
||||
{
|
||||
#if defined(ARDUINO_ARCH_ESP32)
|
||||
GPIO.out_w1ts = pinRegister;
|
||||
GPIO.out_w1ts = pinRegister;
|
||||
#else
|
||||
GPIO_REG_WRITE(GPIO_OUT_W1TS_ADDRESS, pinRegister);
|
||||
GPIO_REG_WRITE(GPIO_OUT_W1TS_ADDRESS, pinRegister);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
template<typename T_SPEED, typename T_PINSET> class NeoEspBitBangBase
|
||||
{
|
||||
public:
|
||||
__attribute__((noinline)) static void ICACHE_RAM_ATTR send_pixels(uint8_t* pixels, uint8_t* end, uint8_t pin)
|
||||
{
|
||||
const uint32_t pinRegister = _BV(pin);
|
||||
uint8_t mask = 0x80;
|
||||
uint8_t subpix = *pixels++;
|
||||
uint32_t cyclesStart = 0; // trigger emediately
|
||||
uint32_t cyclesNext = 0;
|
||||
{
|
||||
const uint32_t pinRegister = _BV(pin);
|
||||
uint8_t mask = 0x80;
|
||||
uint8_t subpix = *pixels++;
|
||||
uint32_t cyclesStart = 0; // trigger emediately
|
||||
uint32_t cyclesNext = 0;
|
||||
|
||||
for (;;)
|
||||
{
|
||||
// do the checks here while we are waiting on time to pass
|
||||
uint32_t cyclesBit = T_SPEED::T0H;
|
||||
if (subpix & mask)
|
||||
{
|
||||
cyclesBit = T_SPEED::T1H;
|
||||
}
|
||||
for (;;)
|
||||
{
|
||||
// do the checks here while we are waiting on time to pass
|
||||
uint32_t cyclesBit = T_SPEED::T0H;
|
||||
if (subpix & mask)
|
||||
{
|
||||
cyclesBit = T_SPEED::T1H;
|
||||
}
|
||||
|
||||
// after we have done as much work as needed for this next bit
|
||||
// now wait for the HIGH
|
||||
while (((cyclesStart = getCycleCount()) - cyclesNext) < T_SPEED::Period);
|
||||
// after we have done as much work as needed for this next bit
|
||||
// now wait for the HIGH
|
||||
while (((cyclesStart = getCycleCount()) - cyclesNext) < T_SPEED::Period);
|
||||
|
||||
// set pin state
|
||||
T_PINSET::setPin(pinRegister);
|
||||
// set pin state
|
||||
T_PINSET::setPin(pinRegister);
|
||||
|
||||
// wait for the LOW
|
||||
while ((getCycleCount() - cyclesStart) < cyclesBit);
|
||||
// wait for the LOW
|
||||
while ((getCycleCount() - cyclesStart) < cyclesBit);
|
||||
|
||||
// reset pin start
|
||||
T_PINSET::resetPin(pinRegister);
|
||||
// reset pin start
|
||||
T_PINSET::resetPin(pinRegister);
|
||||
|
||||
cyclesNext = cyclesStart;
|
||||
cyclesNext = cyclesStart;
|
||||
|
||||
// next bit
|
||||
mask >>= 1;
|
||||
if (mask == 0)
|
||||
{
|
||||
// no more bits to send in this byte
|
||||
// check for another byte
|
||||
if (pixels >= end)
|
||||
{
|
||||
// no more bytes to send so stop
|
||||
break;
|
||||
}
|
||||
// reset mask to first bit and get the next byte
|
||||
mask = 0x80;
|
||||
subpix = *pixels++;
|
||||
}
|
||||
}
|
||||
}
|
||||
// next bit
|
||||
mask >>= 1;
|
||||
if (mask == 0)
|
||||
{
|
||||
// no more bits to send in this byte
|
||||
// check for another byte
|
||||
if (pixels >= end)
|
||||
{
|
||||
// no more bytes to send so stop
|
||||
break;
|
||||
}
|
||||
// reset mask to first bit and get the next byte
|
||||
mask = 0x80;
|
||||
subpix = *pixels++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected:
|
||||
static inline uint32_t getCycleCount(void)
|
||||
@ -184,7 +184,7 @@ protected:
|
||||
class NeoEspBitBangSpeedWs2811 : public NeoEspBitBangBase<NeoEspSpeedWs2811, NeoEspPinset>
|
||||
{
|
||||
public:
|
||||
static const uint32_t ResetTimeUs = 300;
|
||||
static const uint32_t ResetTimeUs = 300;
|
||||
};
|
||||
|
||||
class NeoEspBitBangSpeedWs2812x : public NeoEspBitBangBase<NeoEspSpeed800Mhz, NeoEspPinset>
|
||||
@ -222,19 +222,19 @@ public:
|
||||
class NeoEspBitBangInvertedSpeedWs2811 : public NeoEspBitBangBase<NeoEspSpeedWs2811, NeoEspPinsetInverted>
|
||||
{
|
||||
public:
|
||||
static const uint32_t ResetTimeUs = 300;
|
||||
static const uint32_t ResetTimeUs = 300;
|
||||
};
|
||||
|
||||
class NeoEspBitBangInvertedSpeedWs2812x : public NeoEspBitBangBase<NeoEspSpeed800Mhz, NeoEspPinsetInverted>
|
||||
{
|
||||
public:
|
||||
static const uint32_t ResetTimeUs = 300;
|
||||
static const uint32_t ResetTimeUs = 300;
|
||||
};
|
||||
|
||||
class NeoEspBitBangInvertedSpeedSk6812 : public NeoEspBitBangBase<NeoEspSpeed800Mhz, NeoEspPinsetInverted>
|
||||
{
|
||||
public:
|
||||
static const uint32_t ResetTimeUs = 80;
|
||||
static const uint32_t ResetTimeUs = 80;
|
||||
};
|
||||
|
||||
// normal is inverted signal, so inverted is normal
|
||||
@ -247,13 +247,13 @@ public:
|
||||
class NeoEspBitBangInvertedSpeed800Kbps : public NeoEspBitBangBase<NeoEspSpeed800Mhz, NeoEspPinsetInverted>
|
||||
{
|
||||
public:
|
||||
static const uint32_t ResetTimeUs = 50;
|
||||
static const uint32_t ResetTimeUs = 50;
|
||||
};
|
||||
|
||||
class NeoEspBitBangInvertedSpeed400Kbps : public NeoEspBitBangBase<NeoEspSpeed400Mhz, NeoEspPinsetInverted>
|
||||
{
|
||||
public:
|
||||
static const uint32_t ResetTimeUs = 50;
|
||||
static const uint32_t ResetTimeUs = 50;
|
||||
};
|
||||
|
||||
template<typename T_SPEED, typename T_PINSET> class NeoEspBitBangMethodBase
|
||||
@ -303,10 +303,10 @@ public:
|
||||
yield(); // allows for system yield if needed
|
||||
}
|
||||
|
||||
// Need 100% focus on instruction timing
|
||||
// Need 100% focus on instruction timing
|
||||
#if defined(ARDUINO_ARCH_ESP32)
|
||||
delay(1); // required
|
||||
portMUX_TYPE updateMux = portMUX_INITIALIZER_UNLOCKED;
|
||||
delay(1); // required
|
||||
portMUX_TYPE updateMux = portMUX_INITIALIZER_UNLOCKED;
|
||||
|
||||
portENTER_CRITICAL(&updateMux);
|
||||
#else
|
||||
@ -314,7 +314,7 @@ public:
|
||||
#endif
|
||||
|
||||
T_SPEED::send_pixels(_data, _data + _sizeData, _pin);
|
||||
|
||||
|
||||
#if defined(ARDUINO_ARCH_ESP32)
|
||||
portEXIT_CRITICAL(&updateMux);
|
||||
#else
|
||||
|
@ -37,20 +37,20 @@ License along with NeoPixel. If not, see
|
||||
template<typename T_TWOWIRE> class P9813MethodBase
|
||||
{
|
||||
public:
|
||||
P9813MethodBase(uint8_t pinClock, uint8_t pinData, uint16_t pixelCount, size_t elementSize, size_t settingsSize) :
|
||||
P9813MethodBase(uint8_t pinClock, uint8_t pinData, uint16_t pixelCount, size_t elementSize, size_t settingsSize) :
|
||||
_sizeData(pixelCount * elementSize + settingsSize),
|
||||
_sizeEndFrame((pixelCount + 15) / 16), // 16 = div 2 (bit for every two pixels) div 8 (bits to bytes)
|
||||
_wire(pinClock, pinData)
|
||||
_sizeEndFrame((pixelCount + 15) / 16), // 16 = div 2 (bit for every two pixels) div 8 (bits to bytes)
|
||||
_wire(pinClock, pinData)
|
||||
{
|
||||
_data = static_cast<uint8_t*>(malloc(_sizeData));
|
||||
memset(_data, 0, _sizeData);
|
||||
}
|
||||
|
||||
#if !defined(__AVR_ATtiny85__) && !defined(ARDUINO_attiny)
|
||||
P9813MethodBase(uint16_t pixelCount, size_t elementSize, size_t settingsSize) :
|
||||
P9813MethodBase(SCK, MOSI, pixelCount, elementSize, settingsSize)
|
||||
{
|
||||
}
|
||||
P9813MethodBase(uint16_t pixelCount, size_t elementSize, size_t settingsSize) :
|
||||
P9813MethodBase(SCK, MOSI, pixelCount, elementSize, settingsSize)
|
||||
{
|
||||
}
|
||||
#endif
|
||||
|
||||
~P9813MethodBase()
|
||||
@ -64,34 +64,34 @@ public:
|
||||
}
|
||||
|
||||
#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);
|
||||
}
|
||||
void Initialize(int8_t sck, int8_t miso, int8_t mosi, int8_t ss)
|
||||
{
|
||||
_wire.begin(sck, miso, mosi, ss);
|
||||
}
|
||||
#endif
|
||||
|
||||
void Initialize()
|
||||
{
|
||||
_wire.begin();
|
||||
_wire.begin();
|
||||
}
|
||||
|
||||
void Update(bool)
|
||||
{
|
||||
const uint8_t startFrame[4] = { 0x00 };
|
||||
const uint8_t endFrame[4] = { 0x00 };
|
||||
|
||||
_wire.beginTransaction();
|
||||
const uint8_t startFrame[4] = { 0x00 };
|
||||
const uint8_t endFrame[4] = { 0x00 };
|
||||
|
||||
_wire.beginTransaction();
|
||||
|
||||
// start frame
|
||||
_wire.transmitBytes(startFrame, sizeof(startFrame));
|
||||
_wire.transmitBytes(startFrame, sizeof(startFrame));
|
||||
|
||||
// data
|
||||
_wire.transmitBytes(_data, _sizeData);
|
||||
_wire.transmitBytes(_data, _sizeData);
|
||||
|
||||
// end frame
|
||||
_wire.transmitBytes(endFrame, sizeof(endFrame));
|
||||
|
||||
_wire.endTransaction();
|
||||
_wire.transmitBytes(endFrame, sizeof(endFrame));
|
||||
|
||||
_wire.endTransaction();
|
||||
}
|
||||
|
||||
uint8_t* getData() const
|
||||
@ -105,10 +105,10 @@ public:
|
||||
};
|
||||
|
||||
private:
|
||||
const size_t _sizeData; // Size of '_data' buffer below
|
||||
const size_t _sizeEndFrame;
|
||||
const size_t _sizeData; // Size of '_data' buffer below
|
||||
const size_t _sizeEndFrame;
|
||||
|
||||
T_TWOWIRE _wire;
|
||||
T_TWOWIRE _wire;
|
||||
uint8_t* _data; // Holds LED color values
|
||||
};
|
||||
|
||||
|
@ -160,7 +160,7 @@ RgbColor::RgbColor(const HsbColor& color)
|
||||
|
||||
uint8_t RgbColor::CalculateBrightness() const
|
||||
{
|
||||
return (uint8_t)(((uint16_t)R + (uint16_t)G + (uint16_t)B) / 3);
|
||||
return (uint8_t)(((uint16_t)R + (uint16_t)G + (uint16_t)B) / 3);
|
||||
}
|
||||
|
||||
RgbColor RgbColor::Dim(uint8_t ratio) const
|
||||
@ -177,69 +177,69 @@ RgbColor RgbColor::Brighten(uint8_t ratio) const
|
||||
|
||||
void RgbColor::Darken(uint8_t delta)
|
||||
{
|
||||
if (R > delta)
|
||||
{
|
||||
R -= delta;
|
||||
}
|
||||
else
|
||||
{
|
||||
R = 0;
|
||||
}
|
||||
if (R > delta)
|
||||
{
|
||||
R -= delta;
|
||||
}
|
||||
else
|
||||
{
|
||||
R = 0;
|
||||
}
|
||||
|
||||
if (G > delta)
|
||||
{
|
||||
G -= delta;
|
||||
}
|
||||
else
|
||||
{
|
||||
G = 0;
|
||||
}
|
||||
if (G > delta)
|
||||
{
|
||||
G -= delta;
|
||||
}
|
||||
else
|
||||
{
|
||||
G = 0;
|
||||
}
|
||||
|
||||
if (B > delta)
|
||||
{
|
||||
B -= delta;
|
||||
}
|
||||
else
|
||||
{
|
||||
B = 0;
|
||||
}
|
||||
if (B > delta)
|
||||
{
|
||||
B -= delta;
|
||||
}
|
||||
else
|
||||
{
|
||||
B = 0;
|
||||
}
|
||||
}
|
||||
|
||||
void RgbColor::Lighten(uint8_t delta)
|
||||
{
|
||||
if (R < 255 - delta)
|
||||
{
|
||||
R += delta;
|
||||
}
|
||||
else
|
||||
{
|
||||
R = 255;
|
||||
}
|
||||
if (R < 255 - delta)
|
||||
{
|
||||
R += delta;
|
||||
}
|
||||
else
|
||||
{
|
||||
R = 255;
|
||||
}
|
||||
|
||||
if (G < 255 - delta)
|
||||
{
|
||||
G += delta;
|
||||
}
|
||||
else
|
||||
{
|
||||
G = 255;
|
||||
}
|
||||
if (G < 255 - delta)
|
||||
{
|
||||
G += delta;
|
||||
}
|
||||
else
|
||||
{
|
||||
G = 255;
|
||||
}
|
||||
|
||||
if (B < 255 - delta)
|
||||
{
|
||||
B += delta;
|
||||
}
|
||||
else
|
||||
{
|
||||
B = 255;
|
||||
}
|
||||
if (B < 255 - delta)
|
||||
{
|
||||
B += delta;
|
||||
}
|
||||
else
|
||||
{
|
||||
B = 255;
|
||||
}
|
||||
}
|
||||
|
||||
RgbColor RgbColor::LinearBlend(const RgbColor& left, const RgbColor& right, float progress)
|
||||
{
|
||||
return RgbColor( left.R + ((right.R - left.R) * progress),
|
||||
left.G + ((right.G - left.G) * progress),
|
||||
left.B + ((right.B - left.B) * progress));
|
||||
return RgbColor( left.R + ((right.R - left.R) * progress),
|
||||
left.G + ((right.G - left.G) * progress),
|
||||
left.B + ((right.B - left.B) * progress));
|
||||
}
|
||||
|
||||
RgbColor RgbColor::BilinearBlend(const RgbColor& c00,
|
||||
|
@ -104,7 +104,7 @@ uint8_t SevenSegDigit::CalculateBrightness() const
|
||||
sum += Segment[iSegment];
|
||||
}
|
||||
|
||||
return (uint8_t)(sum / SegmentCount);
|
||||
return (uint8_t)(sum / SegmentCount);
|
||||
}
|
||||
|
||||
void SevenSegDigit::Darken(uint8_t delta)
|
||||
|
@ -30,63 +30,63 @@ License along with NeoPixel. If not, see
|
||||
class TwoWireBitBangImple
|
||||
{
|
||||
public:
|
||||
TwoWireBitBangImple(uint8_t pinClock, uint8_t pinData) :
|
||||
_pinClock(pinClock),
|
||||
_pinData(pinData)
|
||||
{
|
||||
pinMode(pinClock, OUTPUT);
|
||||
pinMode(pinData, OUTPUT);
|
||||
}
|
||||
TwoWireBitBangImple(uint8_t pinClock, uint8_t pinData) :
|
||||
_pinClock(pinClock),
|
||||
_pinData(pinData)
|
||||
{
|
||||
pinMode(pinClock, OUTPUT);
|
||||
pinMode(pinData, OUTPUT);
|
||||
}
|
||||
|
||||
~TwoWireBitBangImple()
|
||||
{
|
||||
pinMode(_pinClock, INPUT);
|
||||
pinMode(_pinData, INPUT);
|
||||
}
|
||||
~TwoWireBitBangImple()
|
||||
{
|
||||
pinMode(_pinClock, INPUT);
|
||||
pinMode(_pinData, INPUT);
|
||||
}
|
||||
|
||||
void begin()
|
||||
{
|
||||
digitalWrite(_pinClock, LOW);
|
||||
digitalWrite(_pinData, LOW);
|
||||
}
|
||||
void begin()
|
||||
{
|
||||
digitalWrite(_pinClock, LOW);
|
||||
digitalWrite(_pinData, LOW);
|
||||
}
|
||||
|
||||
void beginTransaction()
|
||||
{
|
||||
void beginTransaction()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
void endTransaction()
|
||||
{
|
||||
digitalWrite(_pinData, LOW);
|
||||
}
|
||||
void endTransaction()
|
||||
{
|
||||
digitalWrite(_pinData, LOW);
|
||||
}
|
||||
|
||||
void transmitByte(uint8_t data)
|
||||
{
|
||||
for (int bit = 7; bit >= 0; bit--)
|
||||
{
|
||||
// set data bit on pin
|
||||
digitalWrite(_pinData, (data & 0x80) == 0x80 ? HIGH : LOW);
|
||||
void transmitByte(uint8_t data)
|
||||
{
|
||||
for (int bit = 7; bit >= 0; bit--)
|
||||
{
|
||||
// set data bit on pin
|
||||
digitalWrite(_pinData, (data & 0x80) == 0x80 ? HIGH : LOW);
|
||||
|
||||
// set clock high as data is ready
|
||||
digitalWrite(_pinClock, HIGH);
|
||||
// set clock high as data is ready
|
||||
digitalWrite(_pinClock, HIGH);
|
||||
|
||||
data <<= 1;
|
||||
data <<= 1;
|
||||
|
||||
// set clock low as data pin is changed
|
||||
digitalWrite(_pinClock, LOW);
|
||||
}
|
||||
}
|
||||
// set clock low as data pin is changed
|
||||
digitalWrite(_pinClock, LOW);
|
||||
}
|
||||
}
|
||||
|
||||
void transmitBytes(const uint8_t* data, size_t dataSize)
|
||||
{
|
||||
const uint8_t* endData = data + dataSize;
|
||||
while (data < endData)
|
||||
{
|
||||
transmitByte(*data++);
|
||||
}
|
||||
}
|
||||
void transmitBytes(const uint8_t* data, size_t dataSize)
|
||||
{
|
||||
const uint8_t* endData = data + dataSize;
|
||||
while (data < endData)
|
||||
{
|
||||
transmitByte(*data++);
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
const uint8_t _pinClock; // output pin number for clock line
|
||||
const uint8_t _pinData; // output pin number for data line
|
||||
const uint8_t _pinClock; // output pin number for clock line
|
||||
const uint8_t _pinData; // output pin number for data line
|
||||
};
|
@ -30,83 +30,83 @@ License along with NeoPixel. If not, see
|
||||
class TwoWireBitBangImple
|
||||
{
|
||||
public:
|
||||
TwoWireBitBangImple(uint8_t pinClock, uint8_t pinData) :
|
||||
_pinClock(pinClock),
|
||||
_pinData(pinData)
|
||||
{
|
||||
pinMode(pinClock, OUTPUT);
|
||||
pinMode(pinData, OUTPUT);
|
||||
TwoWireBitBangImple(uint8_t pinClock, uint8_t pinData) :
|
||||
_pinClock(pinClock),
|
||||
_pinData(pinData)
|
||||
{
|
||||
pinMode(pinClock, OUTPUT);
|
||||
pinMode(pinData, OUTPUT);
|
||||
|
||||
_portClock = portOutputRegister(digitalPinToPort(_pinClock));
|
||||
_pinMaskClock = digitalPinToBitMask(_pinClock);
|
||||
_portData = portOutputRegister(digitalPinToPort(_pinData));
|
||||
_pinMaskData = digitalPinToBitMask(_pinData);
|
||||
}
|
||||
_portClock = portOutputRegister(digitalPinToPort(_pinClock));
|
||||
_pinMaskClock = digitalPinToBitMask(_pinClock);
|
||||
_portData = portOutputRegister(digitalPinToPort(_pinData));
|
||||
_pinMaskData = digitalPinToBitMask(_pinData);
|
||||
}
|
||||
|
||||
~TwoWireBitBangImple()
|
||||
{
|
||||
pinMode(_pinClock, INPUT);
|
||||
pinMode(_pinData, INPUT);
|
||||
}
|
||||
~TwoWireBitBangImple()
|
||||
{
|
||||
pinMode(_pinClock, INPUT);
|
||||
pinMode(_pinData, INPUT);
|
||||
}
|
||||
|
||||
void begin()
|
||||
{
|
||||
digitalWrite(_pinClock, LOW);
|
||||
digitalWrite(_pinData, LOW);
|
||||
}
|
||||
void begin()
|
||||
{
|
||||
digitalWrite(_pinClock, LOW);
|
||||
digitalWrite(_pinData, LOW);
|
||||
}
|
||||
|
||||
void beginTransaction()
|
||||
{
|
||||
void beginTransaction()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
void endTransaction()
|
||||
{
|
||||
digitalWrite(_pinData, LOW);
|
||||
}
|
||||
void endTransaction()
|
||||
{
|
||||
digitalWrite(_pinData, LOW);
|
||||
}
|
||||
|
||||
void transmitByte(uint8_t data)
|
||||
{
|
||||
for (int bit = 7; bit >= 0; bit--)
|
||||
{
|
||||
// set data bit on pin
|
||||
// digitalWrite(_pinData, (data & 0x80) == 0x80 ? HIGH : LOW);
|
||||
if (data & 0x80)
|
||||
{
|
||||
*_portData |= _pinMaskData;
|
||||
}
|
||||
else
|
||||
{
|
||||
*_portData &= ~_pinMaskData;
|
||||
}
|
||||
void transmitByte(uint8_t data)
|
||||
{
|
||||
for (int bit = 7; bit >= 0; bit--)
|
||||
{
|
||||
// set data bit on pin
|
||||
// digitalWrite(_pinData, (data & 0x80) == 0x80 ? HIGH : LOW);
|
||||
if (data & 0x80)
|
||||
{
|
||||
*_portData |= _pinMaskData;
|
||||
}
|
||||
else
|
||||
{
|
||||
*_portData &= ~_pinMaskData;
|
||||
}
|
||||
|
||||
// set clock high as data is ready
|
||||
// digitalWrite(_pinClock, HIGH);
|
||||
*_portClock |= _pinMaskClock;
|
||||
// set clock high as data is ready
|
||||
// digitalWrite(_pinClock, HIGH);
|
||||
*_portClock |= _pinMaskClock;
|
||||
|
||||
data <<= 1;
|
||||
data <<= 1;
|
||||
|
||||
// set clock low as data pin is changed
|
||||
// digitalWrite(_pinClock, LOW);
|
||||
*_portClock &= ~_pinMaskClock;
|
||||
}
|
||||
}
|
||||
// set clock low as data pin is changed
|
||||
// digitalWrite(_pinClock, LOW);
|
||||
*_portClock &= ~_pinMaskClock;
|
||||
}
|
||||
}
|
||||
|
||||
void transmitBytes(const uint8_t* data, size_t dataSize)
|
||||
{
|
||||
const uint8_t* endData = data + dataSize;
|
||||
while (data < endData)
|
||||
{
|
||||
transmitByte(*data++);
|
||||
}
|
||||
}
|
||||
void transmitBytes(const uint8_t* data, size_t dataSize)
|
||||
{
|
||||
const uint8_t* endData = data + dataSize;
|
||||
while (data < endData)
|
||||
{
|
||||
transmitByte(*data++);
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
const uint8_t _pinClock; // output pin number for clock line
|
||||
const uint8_t _pinData; // output pin number for data line
|
||||
const uint8_t _pinClock; // output pin number for clock line
|
||||
const uint8_t _pinData; // output pin number for data line
|
||||
|
||||
volatile uint8_t* _portData; // Output PORT register
|
||||
uint8_t _pinMaskData; // Output PORT bitmask
|
||||
volatile uint8_t* _portClock; // Output PORT register
|
||||
uint8_t _pinMaskClock; // Output PORT bitmask
|
||||
volatile uint8_t* _portData; // Output PORT register
|
||||
uint8_t _pinMaskData; // Output PORT bitmask
|
||||
volatile uint8_t* _portClock; // Output PORT register
|
||||
uint8_t _pinMaskClock; // Output PORT bitmask
|
||||
};
|
@ -37,79 +37,79 @@ public:
|
||||
class SpiSpeed20Mhz
|
||||
{
|
||||
public:
|
||||
static const uint32_t Clock = 20000000L;
|
||||
static const uint32_t Clock = 20000000L;
|
||||
};
|
||||
|
||||
class SpiSpeed10Mhz
|
||||
{
|
||||
public:
|
||||
static const uint32_t Clock = 10000000L;
|
||||
static const uint32_t Clock = 10000000L;
|
||||
};
|
||||
|
||||
class SpiSpeed2Mhz
|
||||
{
|
||||
public:
|
||||
static const uint32_t Clock = 2000000L;
|
||||
static const uint32_t Clock = 2000000L;
|
||||
};
|
||||
|
||||
template<typename T_SPISPEED> class TwoWireSpiImple
|
||||
{
|
||||
public:
|
||||
TwoWireSpiImple(uint8_t, uint8_t) // clock and data pins ignored for hardware SPI
|
||||
{
|
||||
}
|
||||
TwoWireSpiImple(uint8_t, uint8_t) // clock and data pins ignored for hardware SPI
|
||||
{
|
||||
}
|
||||
|
||||
~TwoWireSpiImple()
|
||||
{
|
||||
SPI.end();
|
||||
}
|
||||
~TwoWireSpiImple()
|
||||
{
|
||||
SPI.end();
|
||||
}
|
||||
|
||||
#if defined(ARDUINO_ARCH_ESP32)
|
||||
// for cases where hardware SPI can have pins changed
|
||||
void begin(int8_t sck, int8_t miso, int8_t mosi, int8_t ss)
|
||||
{
|
||||
SPI.begin(sck, miso, mosi, ss);
|
||||
}
|
||||
// for cases where hardware SPI can have pins changed
|
||||
void begin(int8_t sck, int8_t miso, int8_t mosi, int8_t ss)
|
||||
{
|
||||
SPI.begin(sck, miso, mosi, ss);
|
||||
}
|
||||
#endif
|
||||
|
||||
void begin()
|
||||
{
|
||||
SPI.begin();
|
||||
}
|
||||
void begin()
|
||||
{
|
||||
SPI.begin();
|
||||
}
|
||||
|
||||
void beginTransaction()
|
||||
{
|
||||
SPI.beginTransaction(SPISettings(T_SPISPEED::Clock, MSBFIRST, SPI_MODE0));
|
||||
}
|
||||
void beginTransaction()
|
||||
{
|
||||
SPI.beginTransaction(SPISettings(T_SPISPEED::Clock, MSBFIRST, SPI_MODE0));
|
||||
}
|
||||
|
||||
void endTransaction()
|
||||
{
|
||||
SPI.endTransaction();
|
||||
}
|
||||
void endTransaction()
|
||||
{
|
||||
SPI.endTransaction();
|
||||
}
|
||||
|
||||
void transmitByte(uint8_t data)
|
||||
{
|
||||
SPI.transfer(data);
|
||||
}
|
||||
void transmitByte(uint8_t data)
|
||||
{
|
||||
SPI.transfer(data);
|
||||
}
|
||||
|
||||
void transmitBytes(const uint8_t* data, size_t dataSize)
|
||||
{
|
||||
void transmitBytes(const uint8_t* data, size_t dataSize)
|
||||
{
|
||||
#if defined(ARDUINO_ARCH_ESP8266) || defined(ARDUINO_ARCH_ESP32)
|
||||
// ESPs have a method to write without inplace overwriting the send buffer
|
||||
// since we don't care what gets received, use it for performance
|
||||
// FIX: but for what ever reason on Esp32, its not const
|
||||
SPI.writeBytes(const_cast<uint8_t*>(data), dataSize);
|
||||
// ESPs have a method to write without inplace overwriting the send buffer
|
||||
// since we don't care what gets received, use it for performance
|
||||
// FIX: but for what ever reason on Esp32, its not const
|
||||
SPI.writeBytes(const_cast<uint8_t*>(data), dataSize);
|
||||
|
||||
#else
|
||||
// default ARDUINO transfer inplace overwrites the send buffer
|
||||
// which is bad in this case, so we have to send one byte at a time
|
||||
const uint8_t* endData = data + dataSize;
|
||||
while (data < endData)
|
||||
{
|
||||
SPI.transfer(*data++);
|
||||
}
|
||||
// default ARDUINO transfer inplace overwrites the send buffer
|
||||
// which is bad in this case, so we have to send one byte at a time
|
||||
const uint8_t* endData = data + dataSize;
|
||||
while (data < endData)
|
||||
{
|
||||
SPI.transfer(*data++);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
};
|
@ -37,19 +37,19 @@ License along with NeoPixel. If not, see
|
||||
template<typename T_TWOWIRE> class Ws2801MethodBase
|
||||
{
|
||||
public:
|
||||
Ws2801MethodBase(uint8_t pinClock, uint8_t pinData, uint16_t pixelCount, size_t elementSize, size_t settingsSize) :
|
||||
Ws2801MethodBase(uint8_t pinClock, uint8_t pinData, uint16_t pixelCount, size_t elementSize, size_t settingsSize) :
|
||||
_sizeData(pixelCount * elementSize + settingsSize),
|
||||
_wire(pinClock, pinData)
|
||||
_wire(pinClock, pinData)
|
||||
{
|
||||
_data = static_cast<uint8_t*>(malloc(_sizeData));
|
||||
memset(_data, 0, _sizeData);
|
||||
}
|
||||
|
||||
#if !defined(__AVR_ATtiny85__) && !defined(ARDUINO_attiny)
|
||||
Ws2801MethodBase(uint16_t pixelCount, size_t elementSize, size_t settingsSize) :
|
||||
Ws2801MethodBase(SCK, MOSI, pixelCount, elementSize, settingsSize)
|
||||
{
|
||||
}
|
||||
Ws2801MethodBase(uint16_t pixelCount, size_t elementSize, size_t settingsSize) :
|
||||
Ws2801MethodBase(SCK, MOSI, pixelCount, elementSize, settingsSize)
|
||||
{
|
||||
}
|
||||
#endif
|
||||
|
||||
~Ws2801MethodBase()
|
||||
@ -65,15 +65,15 @@ public:
|
||||
}
|
||||
|
||||
#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);
|
||||
}
|
||||
void Initialize(int8_t sck, int8_t miso, int8_t mosi, int8_t ss)
|
||||
{
|
||||
_wire.begin(sck, miso, mosi, ss);
|
||||
}
|
||||
#endif
|
||||
|
||||
void Initialize()
|
||||
{
|
||||
_wire.begin();
|
||||
_wire.begin();
|
||||
|
||||
_endTime = micros();
|
||||
}
|
||||
@ -87,12 +87,12 @@ public:
|
||||
#endif
|
||||
}
|
||||
|
||||
_wire.beginTransaction();
|
||||
_wire.beginTransaction();
|
||||
|
||||
// data
|
||||
_wire.transmitBytes(_data, _sizeData);
|
||||
_wire.transmitBytes(_data, _sizeData);
|
||||
|
||||
_wire.endTransaction();
|
||||
_wire.endTransaction();
|
||||
|
||||
// save EOD time for latch on next call
|
||||
_endTime = micros();
|
||||
|
Reference in New Issue
Block a user