Sm168xx settings refactoring (#570)

* refactor gains

* const refactoring
This commit is contained in:
Michael Miller
2022-05-12 15:22:08 -07:00
committed by GitHub
parent 7ae0cc31aa
commit 3661d983a4
3 changed files with 91 additions and 77 deletions

View File

@@ -159,21 +159,6 @@ void IRAM_ATTR NeoEspBitBangBase_send_pixels_inv(uint8_t* pixels, uint8_t* end,
uint32_t cyclesStart = 0; // trigger emediately uint32_t cyclesStart = 0; // trigger emediately
uint32_t cyclesNext = 0; uint32_t cyclesNext = 0;
#if defined(ARDUINO_ARCH_ESP8266)
// compensation for if (pin == ...)
t0h -= 3;
t1h -= 3;
uint32_t gpio_clear = 0;
uint32_t gpio_set = 0;
if (pin == 16)
{
// reading and writing RTC_GPIO_OUT is too slow inside the loop
gpio_clear = (READ_PERI_REG(RTC_GPIO_OUT) & (uint32)0xfffffffe);
gpio_set = gpio_clear | 1;
}
#endif
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

View File

@@ -39,9 +39,9 @@ public:
{ {
} }
uint16_t RedTenthMilliAmpere; // in 1/10th ma const uint16_t RedTenthMilliAmpere; // in 1/10th ma
uint16_t GreenTenthMilliAmpere; // in 1/10th ma const uint16_t GreenTenthMilliAmpere; // in 1/10th ma
uint16_t BlueTenthMilliAmpere; // in 1/10th ma const uint16_t BlueTenthMilliAmpere; // in 1/10th ma
}; };
class NeoRgbwCurrentSettings class NeoRgbwCurrentSettings
@@ -55,8 +55,8 @@ public:
{ {
} }
uint16_t RedTenthMilliAmpere; // in 1/10th ma const uint16_t RedTenthMilliAmpere; // in 1/10th ma
uint16_t GreenTenthMilliAmpere; // in 1/10th ma const uint16_t GreenTenthMilliAmpere; // in 1/10th ma
uint16_t BlueTenthMilliAmpere; // in 1/10th ma const uint16_t BlueTenthMilliAmpere; // in 1/10th ma
uint16_t WhiteTenthMilliAmpere; // in 1/10th ma const uint16_t WhiteTenthMilliAmpere; // in 1/10th ma
}; };

View File

@@ -39,29 +39,40 @@ SM16824E 60~350mA
class NeoSm168x3SettingsBase : public NeoRgbCurrentSettings class NeoSm168x3SettingsBase : public NeoRgbCurrentSettings
{ {
public: public:
NeoSm168x3SettingsBase() : NeoSm168x3SettingsBase(uint8_t redGain,
NeoRgbCurrentSettings(0,0,0), uint8_t greenGain,
Encoded{0} {} uint8_t blueGain,
uint16_t redCurrent,
uint16_t greenCurrent,
uint16_t blueCurrent) :
NeoRgbCurrentSettings(redCurrent, greenCurrent, blueCurrent),
RedGain(redGain & 0x0f),
GreenGain(greenGain & 0x0f),
BlueGain(blueGain & 0x0f) {}
uint8_t Encoded[2]; const uint8_t RedGain : 4;
const uint8_t GreenGain : 4;
const uint8_t BlueGain : 4;
}; };
class NeoSm16803pbSettings : public NeoSm168x3SettingsBase class NeoSm16803pbSettings : public NeoSm168x3SettingsBase
{ {
public: public:
NeoSm16803pbSettings(uint8_t redGain, uint8_t greenGain, uint8_t blueGain) NeoSm16803pbSettings(uint8_t redGain, uint8_t greenGain, uint8_t blueGain) :
NeoSm168x3SettingsBase(redGain,
greenGain,
blueGain,
CurrentLookup[redGain],
CurrentLookup[greenGain],
CurrentLookup[blueGain])
{ {
redGain &= 0x0f; }
greenGain &= 0x0f;
blueGain &= 0x0f;
RedTenthMilliAmpere = CurrentLookup[redGain];
GreenTenthMilliAmpere = CurrentLookup[greenGain];
BlueTenthMilliAmpere = CurrentLookup[blueGain];
void Encode(uint8_t* encoded) const
{
// 0RGB 4 bits each // 0RGB 4 bits each
Encoded[0] = redGain; encoded[0] = RedGain;
Encoded[1] = greenGain << 4 | blueGain; encoded[1] = GreenGain << 4 | BlueGain;
} }
protected: protected:
@@ -74,19 +85,21 @@ class NeoSm16823eSettings : public NeoSm168x3SettingsBase
{ {
public: public:
NeoSm16823eSettings(uint8_t redGain, uint8_t greenGain, uint8_t blueGain, uint16_t resisterOhms) : NeoSm16823eSettings(uint8_t redGain, uint8_t greenGain, uint8_t blueGain, uint16_t resisterOhms) :
NeoSm168x3SettingsBase(redGain,
greenGain,
blueGain,
calcCurrent(resisterOhms, redGain),
calcCurrent(resisterOhms, greenGain),
calcCurrent(resisterOhms, blueGain)),
extROhms(resisterOhms) extROhms(resisterOhms)
{ {
redGain &= 0x0f; }
greenGain &= 0x0f;
blueGain &= 0x0f;
RedTenthMilliAmpere = calcCurrent(extROhms, redGain);
GreenTenthMilliAmpere = calcCurrent(extROhms, greenGain);
BlueTenthMilliAmpere = calcCurrent(extROhms, blueGain);
void Encode(uint8_t* encoded) const
{
// RGB0 4 bits each // RGB0 4 bits each
Encoded[0] = redGain << 4 | greenGain; encoded[0] = RedGain << 4 | GreenGain;
Encoded[1] = blueGain << 4; encoded[1] = BlueGain << 4;
} }
protected: protected:
@@ -97,7 +110,6 @@ protected:
uint16_t mA = (967 * (240 + (gain * 32)) / ohms); // from spec sheet, gain 0-15 instead uint16_t mA = (967 * (240 + (gain * 32)) / ohms); // from spec sheet, gain 0-15 instead
return mA * 10; // return tenths of mA return mA * 10; // return tenths of mA
} }
}; };
// RGBW versions // RGBW versions
@@ -105,31 +117,46 @@ protected:
class NeoSm168x4SettingsBase : public NeoRgbwCurrentSettings class NeoSm168x4SettingsBase : public NeoRgbwCurrentSettings
{ {
public: public:
NeoSm168x4SettingsBase() : NeoSm168x4SettingsBase(uint8_t redGain,
NeoRgbwCurrentSettings(0,0,0,0), uint8_t greenGain,
Encoded{ 0 } {} uint8_t blueGain,
uint8_t whiteGain,
uint16_t redCurrent,
uint16_t greenCurrent,
uint16_t blueCurrent,
uint16_t whiteCurrent) :
NeoRgbwCurrentSettings(redCurrent, greenCurrent, blueCurrent, whiteCurrent),
RedGain(redGain & 0x0f),
GreenGain(greenGain & 0x0f),
BlueGain(blueGain & 0x0f),
WhiteGain(whiteGain & 0x0f) {}
uint8_t Encoded[2]; const uint8_t RedGain : 4;
const uint8_t GreenGain : 4;
const uint8_t BlueGain : 4;
const uint8_t WhiteGain : 4;
}; };
class NeoSm16804ebSettings : public NeoSm168x4SettingsBase class NeoSm16804ebSettings : public NeoSm168x4SettingsBase
{ {
public: public:
NeoSm16804ebSettings(uint8_t redGain, uint8_t greenGain, uint8_t blueGain, uint8_t whiteGain) NeoSm16804ebSettings(uint8_t redGain, uint8_t greenGain, uint8_t blueGain, uint8_t whiteGain) :
NeoSm168x4SettingsBase(redGain,
greenGain,
blueGain,
whiteGain,
CurrentLookup[redGain],
CurrentLookup[greenGain],
CurrentLookup[blueGain],
CurrentLookup[whiteGain])
{ {
redGain &= 0x0f; }
greenGain &= 0x0f;
blueGain &= 0x0f;
whiteGain &= 0x0f;
RedTenthMilliAmpere = CurrentLookup[redGain];
GreenTenthMilliAmpere = CurrentLookup[greenGain];
BlueTenthMilliAmpere = CurrentLookup[blueGain];
WhiteTenthMilliAmpere = CurrentLookup[whiteGain];
void Encode(uint8_t* encoded) const
{
// RGBW 4 bits each // RGBW 4 bits each
Encoded[0] = redGain << 4 | greenGain; encoded[0] = RedGain << 4 | GreenGain;
Encoded[1] = blueGain << 4 | whiteGain; encoded[1] = BlueGain << 4 | WhiteGain;
} }
protected: protected:
@@ -142,21 +169,23 @@ class NeoSm16824eSettings : public NeoSm168x4SettingsBase
{ {
public: public:
NeoSm16824eSettings(uint8_t redGain, uint8_t greenGain, uint8_t blueGain, uint8_t whiteGain, uint16_t resisterOhms) : NeoSm16824eSettings(uint8_t redGain, uint8_t greenGain, uint8_t blueGain, uint8_t whiteGain, uint16_t resisterOhms) :
NeoSm168x4SettingsBase(redGain,
greenGain,
blueGain,
whiteGain,
calcCurrent(resisterOhms, redGain),
calcCurrent(resisterOhms, greenGain),
calcCurrent(resisterOhms, blueGain),
calcCurrent(resisterOhms, whiteGain)),
extROhms(resisterOhms) extROhms(resisterOhms)
{ {
redGain &= 0x0f; }
greenGain &= 0x0f;
blueGain &= 0x0f;
whiteGain &= 0x0f;
RedTenthMilliAmpere = calcCurrent(extROhms, redGain);
GreenTenthMilliAmpere = calcCurrent(extROhms, greenGain);
BlueTenthMilliAmpere = calcCurrent(extROhms, blueGain);
WhiteTenthMilliAmpere = calcCurrent(extROhms, whiteGain);
void Encode(uint8_t* encoded) const
{
// RGBW 4 bits each // RGBW 4 bits each
Encoded[0] = redGain << 4 | greenGain; encoded[0] = RedGain << 4 | GreenGain;
Encoded[1] = blueGain << 4 | whiteGain; encoded[1] = BlueGain << 4 | WhiteGain;
} }
protected: protected:
@@ -180,8 +209,8 @@ public:
{ {
// settings are at the end of the data stream // settings are at the end of the data stream
uint8_t* pDest = pData + sizeData - SettingsSize; uint8_t* pDest = pData + sizeData - SettingsSize;
// copy by bytes to avoid endianess
memcpy(pDest, &settings.Encoded, SettingsSize); settings.Encode(pDest);
} }
static uint8_t* pixels([[maybe_unused]] uint8_t* pData, [[maybe_unused]] size_t sizeData) static uint8_t* pixels([[maybe_unused]] uint8_t* pData, [[maybe_unused]] size_t sizeData)
@@ -241,8 +270,8 @@ public:
{ {
// settings are at the end of the data stream // settings are at the end of the data stream
uint8_t* pDest = pData + sizeData - SettingsSize; uint8_t* pDest = pData + sizeData - SettingsSize;
// copy by bytes to avoid endianess
memcpy(pDest, &settings.Encoded, SettingsSize); settings.Encode(pDest);
} }
static uint8_t* pixels([[maybe_unused]] uint8_t* pData, [[maybe_unused]] size_t sizeData) static uint8_t* pixels([[maybe_unused]] uint8_t* pData, [[maybe_unused]] size_t sizeData)