FastLED 3.9.15
Loading...
Searching...
No Matches
p9813.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#include "platforms/spi_output_template.h"
9#include "fl/stl/noexcept.h"
10
13
15//
16// P9813 definition - takes data/clock/select pin values (N.B. should take an SPI definition?)
17//
19
25template <int DATA_PIN, fl::u8 CLOCK_PIN, EOrder RGB_ORDER = RGB, fl::u32 SPI_SPEED = DATA_RATE_MHZ(10)>
26class P9813Controller : public CPixelLEDController<RGB_ORDER> {
27 typedef fl::SPIOutput<DATA_PIN, CLOCK_PIN, SPI_SPEED> SPI;
29
30 void writeBoundary() { mSPI.writeWord(0); mSPI.writeWord(0); }
31
33 FASTLED_REGISTER fl::u8 top = 0xC0 | ((~b & 0xC0) >> 2) | ((~g & 0xC0) >> 4) | ((~r & 0xC0) >> 6);
34 mSPI.writeByte(top); mSPI.writeByte(b); mSPI.writeByte(g); mSPI.writeByte(r);
35 }
36
37public:
39
40 virtual void init() {
41 mSPI.init();
42 }
43
44protected:
46 virtual void showPixels(PixelController<RGB_ORDER> & pixels) {
47 mSPI.select();
48
50 while(pixels.has(1)) {
51 writeLed(pixels.loadAndScale0(), pixels.loadAndScale1(), pixels.loadAndScale2());
52 pixels.advanceData();
53 pixels.stepDithering();
54 }
56
57 mSPI.endTransaction();
58 }
59
60public:
64 static constexpr fl::u8 getPaddingByte() { return 0x00; }
65
69 static fl::span<const fl::u8> getPaddingLEDFrame() { // okay static in header
70 static const fl::u8 frame[] = { // okay static in header
71 0xFF, // Flag byte for RGB=0,0,0
72 0x00, // Blue = 0
73 0x00, // Green = 0
74 0x00 // Red = 0
75 };
76 return fl::span<const fl::u8>(frame, 4);
77 }
78
81 static constexpr size_t getPaddingLEDFrameSize() {
82 return 4;
83 }
84
89 static constexpr size_t calculateBytes(size_t num_leds) {
90 // P9813 protocol:
91 // - Start boundary: 4 bytes (0x00000000)
92 // - LED data: 4 bytes per LED (flag byte + BGR)
93 // - End boundary: 4 bytes (0x00000000)
94 return 4 + (num_leds * 4) + 4;
95 }
96};
97
CPixelLEDController(RegistrationMode mode)
void writeBoundary()
Definition p9813.h:30
static constexpr fl::u8 getPaddingByte()
Get the protocol-safe padding byte for P9813 Used for quad-SPI lane padding when strips have differen...
Definition p9813.h:64
static constexpr size_t calculateBytes(size_t num_leds)
Calculate total byte count for P9813 protocol Used for quad-SPI buffer pre-allocation.
Definition p9813.h:89
FASTLED_FORCE_INLINE void writeLed(fl::u8 r, fl::u8 g, fl::u8 b)
Definition p9813.h:32
virtual void showPixels(PixelController< RGB_ORDER > &pixels)
Send the LED data to the strip.
Definition p9813.h:46
static constexpr size_t getPaddingLEDFrameSize()
Get the size of the padding LED frame in bytes.
Definition p9813.h:81
P9813Controller() FL_NOEXCEPT
Definition p9813.h:38
virtual void init()
Initialize the LED controller.
Definition p9813.h:40
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 p9813.h:69
fl::SPIOutput< DATA_PIN, CLOCK_PIN, SPI_SPEED > SPI
Definition p9813.h:27
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 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.