Skip to content
Permalink
Browse files

Add LDP8806

  • Loading branch information...
hzeller committed Jul 29, 2018
1 parent 900127a commit acf68a3c3982ead5c7ab445b9f7441bd4ba05580
Showing with 34 additions and 0 deletions.
  1. +1 −0 include/led-strip.h
  2. +33 −0 lib/led-strip.cc
@@ -102,6 +102,7 @@ class LEDStrip {
// "count" Number of LEDs.
LEDStrip *CreateWS2801Strip(MultiSPI *spi, int connector, int count);
LEDStrip *CreateLPD6803Strip(MultiSPI *spi, int connector, int count);
LEDStrip *CreateLPD8806Strip(MultiSPI *spi, int connector, int count);
LEDStrip *CreateAPA102Strip(MultiSPI *spi, int connector, int count);
}

@@ -124,6 +124,36 @@ class LPD6803LedStrip : public LEDStrip {
const int gpio_;
};

class LPD8806LedStrip : public LEDStrip {
public:
LPD8806LedStrip(MultiSPI *spi, int gpio, int count)
: LEDStrip(count), spi_(spi), gpio_(gpio) {
const size_t data_bytes = 3 * count;
const size_t latch_bytes = (count+31)/32;
const size_t bytes_needed = data_bytes + latch_bytes;
spi_->RegisterDataGPIO(gpio, bytes_needed);

for (size_t i = 0; i < bytes_needed; ++i) {
spi_->SetBufferedByte(gpio_, i, 0x00);
}

for (int pos = 0; pos < count; ++pos) {
SetPixel(pos, 0x000000); // Initialize all top-bits.
}
}

virtual void SetLinearValues(int pos, uint16_t r, uint16_t g, uint16_t b) {
spi_->SetBufferedByte(gpio_, 3 * pos + 0, (b >> 9) | 0x80);
spi_->SetBufferedByte(gpio_, 3 * pos + 1, (r >> 9) | 0x80);
spi_->SetBufferedByte(gpio_, 3 * pos + 2, (g >> 9) | 0x80);
}

private:
MultiSPI *const spi_;
const int gpio_;
};


class APA102LedStrip : public LEDStrip {
public:
APA102LedStrip(MultiSPI *spi, int gpio, int count)
@@ -192,6 +222,9 @@ LEDStrip *CreateWS2801Strip(MultiSPI *spi, int connector, int count) {
LEDStrip *CreateLPD6803Strip(MultiSPI *spi, int connector, int count) {
return new LPD6803LedStrip(spi, connector, count);
}
LEDStrip *CreateLPD8806Strip(MultiSPI *spi, int connector, int count) {
return new LPD8806LedStrip(spi, connector, count);
}
LEDStrip *CreateAPA102Strip(MultiSPI *spi, int connector, int count) {
return new APA102LedStrip(spi, connector, count);
}

0 comments on commit acf68a3

Please sign in to comment.
You can’t perform that action at this time.