FastLED 3.10.8
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() FL_NO_EXCEPT { 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 #if defined(FL_IS_ESP32)
41 mSPI.setBus(bus);
42 return *this;
43 }
44 #endif
45
46 virtual void init() FL_NO_EXCEPT {
47 mSPI.init();
48 }
49
50protected:
53 mSPI.select();
54
56 while(pixels.has(1)) {
57 writeLed(pixels.loadAndScale0(), pixels.loadAndScale1(), pixels.loadAndScale2());
58 pixels.advanceData();
59 pixels.stepDithering();
60 }
62
63 mSPI.endTransaction();
64 }
65
66public:
70 static constexpr fl::u8 getPaddingByte() FL_NO_EXCEPT { return 0x00; }
71
75 static fl::span<const fl::u8> getPaddingLEDFrame() FL_NO_EXCEPT { // okay static in header
76 static const fl::u8 frame[] = { // okay static in header
77 0xFF, // Flag byte for RGB=0,0,0
78 0x00, // Blue = 0
79 0x00, // Green = 0
80 0x00 // Red = 0
81 };
82 return fl::span<const fl::u8>(frame, 4);
83 }
84
87 static constexpr size_t getPaddingLEDFrameSize() FL_NO_EXCEPT {
88 return 4;
89 }
90
95 static constexpr size_t calculateBytes(size_t num_leds) FL_NO_EXCEPT {
96 // P9813 protocol:
97 // - Start boundary: 4 bytes (0x00000000)
98 // - LED data: 4 bytes per LED (flag byte + BGR)
99 // - End boundary: 4 bytes (0x00000000)
100 return 4 + (num_leds * 4) + 4;
101 }
102};
103
CPixelLEDController(RegistrationMode mode) FL_NO_EXCEPT
virtual void showPixels(PixelController< RGB_ORDER > &pixels) FL_NO_EXCEPT
Send the LED data to the strip.
Definition p9813.h:52
static fl::span< const fl::u8 > getPaddingLEDFrame() FL_NO_EXCEPT
Get a black LED frame for synchronized latching Used for quad-SPI lane padding to ensure all strips l...
Definition p9813.h:75
static constexpr fl::u8 getPaddingByte() FL_NO_EXCEPT
Get the protocol-safe padding byte for P9813 Used for quad-SPI lane padding when strips have differen...
Definition p9813.h:70
void writeBoundary() FL_NO_EXCEPT
Definition p9813.h:30
FASTLED_FORCE_INLINE void writeLed(fl::u8 r, fl::u8 g, fl::u8 b) FL_NO_EXCEPT
Definition p9813.h:32
virtual void init() FL_NO_EXCEPT
Initialize the LED controller.
Definition p9813.h:46
static constexpr size_t getPaddingLEDFrameSize() FL_NO_EXCEPT
Get the size of the padding LED frame in bytes.
Definition p9813.h:87
P9813Controller() FL_NO_EXCEPT
Definition p9813.h:38
static constexpr size_t calculateBytes(size_t num_leds) FL_NO_EXCEPT
Calculate total byte count for P9813 protocol Used for quad-SPI buffer pre-allocation.
Definition p9813.h:95
fl::SPIOutput< DATA_PIN, CLOCK_PIN, SPI_SPEED > SPI
Definition p9813.h:27
CLEDController & setSpiBus(Esp32SpiBus bus) FL_NO_EXCEPT
Select an ESP-IDF SPI host for this clocked controller before init().
fl::CLEDController CLEDController
#define FASTLED_REGISTER
Helper macro to replace the deprecated 'register' keyword if we're using modern C++ where it's been r...
#define FASTLED_FORCE_INLINE
#define FL_DISABLE_WARNING_PUSH
#define FL_DISABLE_WARNING_POP
#define FL_DISABLE_WARNING_DEPRECATED_REGISTER
unsigned char u8
Definition stdint.h:131
Esp32SpiBus
ESP-IDF SPI host selection for an individual clocked LED controller.
Definition spi_bus.h:18
Includes defintions for RGB and HSV pixels.
#define FL_NO_EXCEPT
Pixel controller class.