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