apa102: added extra functionality

Exposed call to MRAA SPI frequency for those super long strips where the clock signal will degrade and introduce glitches. Slowing down will fix it without the need for extra filtering or redrivers. Batch mode also helps since only one write per frame will be required.

Added functions that control brightness only for fade effects without the need to keep an extra copy of the pixel color map.

Signed-off-by: Mihai Tudor Panu <mihai.tudor.panu@intel.com>
This commit is contained in:
Mihai Tudor Panu
2016-08-25 17:33:41 -07:00
parent 9a83bb7530
commit 2d2ee8d1f0
2 changed files with 61 additions and 4 deletions

View File

@ -96,6 +96,12 @@ APA102::setLed(uint16_t ledIdx, uint8_t brightness, uint8_t r, uint8_t g, uint8_
setLeds(ledIdx, ledIdx, brightness, r, g, b);
}
void
APA102::setLedBrightness(uint16_t ledIdx, uint8_t brightness)
{
setLedsBrightness(ledIdx, ledIdx, brightness);
}
void
APA102::setAllLeds(uint8_t brightness, uint8_t r, uint8_t g, uint8_t b)
{
@ -120,6 +126,21 @@ APA102::setLeds(uint16_t startIdx, uint16_t endIdx, uint8_t brightness, uint8_t
}
}
void
APA102::setLedsBrightness(uint16_t startIdx, uint16_t endIdx, uint8_t brightness)
{
uint16_t s_idx = (startIdx + 1) * 4;
uint16_t e_idx = (endIdx + 1) * 4;
for (uint16_t i = s_idx; i <= e_idx; i += 4) {
m_leds[i] = brightness | 224;
}
if (!m_batchMode) {
pushState();
}
}
void
APA102::setLeds(uint16_t startIdx, uint16_t endIdx, uint8_t* colors)
{
@ -131,6 +152,15 @@ APA102::setLeds(uint16_t startIdx, uint16_t endIdx, uint8_t* colors)
}
}
void
APA102::setBusSpeed(int hz)
{
if (m_spi->frequency(hz) != mraa::SUCCESS) {
throw std::runtime_error(std::string(__FUNCTION__) +
": Failed to change SPI bus speed");
}
}
void
APA102::pushState(void)
{