FastLED 3.9.15
Loading...
Searching...
No Matches
lpd880x.h
Go to the documentation of this file.
1#pragma once
2
3#include "pixeltypes.h"
5#include "pixel_iterator.h"
6#include "crgb.h"
7#include "eorder.h"
8// IWYU pragma: begin_keep
9#include "platforms/shared/spi_pixel_writer.h" // ok platform headers
10// IWYU pragma: end_keep
11#include "platforms/spi_output_template.h"
12#include "fl/stl/noexcept.h"
13
16
18//
19// LPD8806 controller class - takes data/clock/select pin values (N.B. should take an SPI definition?)
20//
22
28template <int DATA_PIN, fl::u8 CLOCK_PIN, EOrder RGB_ORDER = RGB, fl::u32 SPI_SPEED = DATA_RATE_MHZ(12) >
29class LPD8806Controller : public CPixelLEDController<RGB_ORDER> {
30 typedef fl::SPIOutput<DATA_PIN, CLOCK_PIN, SPI_SPEED> SPI;
31
33 public:
34 // LPD8806 spec wants the high bit of every rgb data byte sent out to be set.
35 FASTLED_FORCE_INLINE static fl::u8 adjust(FASTLED_REGISTER fl::u8 data) { return ((data>>1) | 0x80) + ((data && (data<254)) & 0x01); }
36 FASTLED_FORCE_INLINE static void postBlock(int len, void* context = nullptr) {
37 SPI* pSPI = static_cast<SPI*>(context);
38 pSPI->writeBytesValueRaw(0, ((len*3+63)>>6));
39 }
40
41 };
42
44
45public:
47 virtual void init() {
48 mSPI.init();
49 }
50
51protected:
52
54 virtual void showPixels(PixelController<RGB_ORDER> & pixels) {
55 fl::writePixelsToSPI<0, LPD8806_ADJUST, RGB_ORDER>(pixels, mSPI, &mSPI);
56 }
57
58public:
62 static constexpr fl::u8 getPaddingByte() { return 0x00; }
63
67 static fl::span<const fl::u8> getPaddingLEDFrame() { // okay static in header
68 static const fl::u8 frame[] = { // okay static in header
69 0x80, // Green = 0 (with MSB=1)
70 0x80, // Red = 0 (with MSB=1)
71 0x80 // Blue = 0 (with MSB=1)
72 };
73 return fl::span<const fl::u8>(frame, 3);
74 }
75
78 static constexpr size_t getPaddingLEDFrameSize() {
79 return 3;
80 }
81
86 static constexpr size_t calculateBytes(size_t num_leds) {
87 // LPD8806 protocol:
88 // - LED data: 3 bytes per LED (GRB with high bit set)
89 // - Latch: ((num_leds * 3 + 63) / 64) bytes of 0x00
90 return (num_leds * 3) + ((num_leds * 3 + 63) / 64);
91 }
92};
93
102template <int DATA_PIN, fl::u8 CLOCK_PIN, EOrder RGB_ORDER = RGB, fl::u32 SPI_SPEED = DATA_RATE_MHZ(12)>
103class LPD6803Controller : public CPixelLEDController<RGB_ORDER> {
104 typedef fl::SPIOutput<DATA_PIN, CLOCK_PIN, SPI_SPEED> SPI;
106
107 void startBoundary() { mSPI.writeByte(0); mSPI.writeByte(0); mSPI.writeByte(0); mSPI.writeByte(0); }
108 void endBoundary(int nLeds) { int nDWords = (nLeds/32); do { mSPI.writeByte(0xFF); mSPI.writeByte(0x00); mSPI.writeByte(0x00); mSPI.writeByte(0x00); } while(nDWords--); }
109
110public:
112
113 virtual void init() {
114 mSPI.init();
115 }
116
117protected:
119 virtual void showPixels(PixelController<RGB_ORDER> & pixels) {
120 mSPI.select();
121
123 while(pixels.has(1)) {
124 FASTLED_REGISTER fl::u16 command;
125 command = 0x8000;
126 command |= (pixels.loadAndScale0() & 0xF8) << 7; // red is the high 5 bits
127 command |= (pixels.loadAndScale1() & 0xF8) << 2; // green is the middle 5 bits
128 mSPI.writeByte((command >> 8) & 0xFF);
129 command |= pixels.loadAndScale2() >> 3 ; // blue is the low 5 bits
130 mSPI.writeByte(command & 0xFF);
131
132 pixels.stepDithering();
133 pixels.advanceData();
134 }
135 endBoundary(pixels.size());
136 mSPI.endTransaction();
137 }
138
139};
140
CPixelLEDController(RegistrationMode mode)
fl::SPIOutput< DATA_PIN, CLOCK_PIN, SPI_SPEED > SPI
Definition lpd880x.h:104
virtual void showPixels(PixelController< RGB_ORDER > &pixels)
Send the LED data to the strip.
Definition lpd880x.h:119
void startBoundary()
Definition lpd880x.h:107
virtual void init()
Initialize the LED controller.
Definition lpd880x.h:113
void endBoundary(int nLeds)
Definition lpd880x.h:108
LPD6803Controller() FL_NOEXCEPT
Definition lpd880x.h:111
static FASTLED_FORCE_INLINE fl::u8 adjust(FASTLED_REGISTER fl::u8 data)
Definition lpd880x.h:35
static FASTLED_FORCE_INLINE void postBlock(int len, void *context=nullptr)
Definition lpd880x.h:36
virtual void showPixels(PixelController< RGB_ORDER > &pixels)
Send the LED data to the strip.
Definition lpd880x.h:54
static constexpr size_t getPaddingLEDFrameSize()
Get the size of the padding LED frame in bytes.
Definition lpd880x.h:78
static fl::span< const fl::u8 > getPaddingLEDFrame()
Get a black LED frame for synchronized latching Used for quad-SPI lane padding to ensure all strips l...
Definition lpd880x.h:67
static constexpr size_t calculateBytes(size_t num_leds)
Calculate total byte count for LPD8806 protocol Used for quad-SPI buffer pre-allocation.
Definition lpd880x.h:86
fl::SPIOutput< DATA_PIN, CLOCK_PIN, SPI_SPEED > SPI
Definition lpd880x.h:30
virtual void init()
Initialize the LED controller.
Definition lpd880x.h:47
static constexpr fl::u8 getPaddingByte()
Get the protocol-safe padding byte for LPD8806 Used for quad-SPI lane padding when strips have differ...
Definition lpd880x.h:62
LPD8806Controller() FL_NOEXCEPT
Definition lpd880x.h:46
unsigned char u8
Definition stdint.h:131
Includes defintions for RGB and HSV pixels.
#define FASTLED_REGISTER
#define FASTLED_FORCE_INLINE
#define FL_DISABLE_WARNING_PUSH
#define FL_DISABLE_WARNING_POP
#define FL_DISABLE_WARNING_DEPRECATED_REGISTER
#define FL_NOEXCEPT
FASTLED_FORCE_INLINE int size() const
Get the length of the LED strip.
FASTLED_FORCE_INLINE fl::u8 loadAndScale0(int lane, fl::u8 scale)
non-template alias of loadAndScale<0>()
FASTLED_FORCE_INLINE void advanceData()
Advance the data pointer forward, adjust position counter.
FASTLED_FORCE_INLINE fl::u8 loadAndScale1(int lane, fl::u8 scale)
non-template alias of loadAndScale<1>()
FASTLED_FORCE_INLINE bool has(int n)
Do we have n pixels left to process?
FASTLED_FORCE_INLINE void stepDithering()
Step the dithering forward - creates triangular wave that toggles between pixels.
FASTLED_FORCE_INLINE fl::u8 loadAndScale2(int lane, fl::u8 scale)
non-template alias of loadAndScale<2>()
Pixel controller class.