FastLED 3.10.8
Loading...
Searching...
No Matches
ws2801.h
Go to the documentation of this file.
1#pragma once
2
3#include "pixeltypes.h"
4#include "pixel_iterator.h"
5#include "crgb.h"
6#include "eorder.h"
7// IWYU pragma: begin_keep
8#include "platforms/shared/spi_pixel_writer.h" // ok platform headers
9// IWYU pragma: end_keep
10#include "platforms/spi_output_template.h"
11#include "fl/stl/noexcept.h"
12
14//
15// WS2801 definition - takes data/clock/select pin values (N.B. should take an SPI definition?)
16//
18
24template <int DATA_PIN, fl::u8 CLOCK_PIN, EOrder RGB_ORDER = RGB, fl::u32 SPI_SPEED = DATA_RATE_MHZ(1)>
25class WS2801Controller : public CPixelLEDController<RGB_ORDER> {
26 typedef fl::SPIOutput<DATA_PIN, CLOCK_PIN, SPI_SPEED> SPI;
29
30public:
32 #if defined(FL_IS_ESP32)
34 mSPI.setBus(bus);
35 return *this;
36 }
37 #endif
38
40 virtual void init() FL_NO_EXCEPT {
41 mSPI.init();
42 mWaitDelay.mark();
43 }
44
45protected:
46
49 mWaitDelay.wait();
50 fl::writePixelsToSPI<0, DATA_NOP, RGB_ORDER>(pixels, mSPI, nullptr);
51 mWaitDelay.mark();
52 }
53
54public:
58 static constexpr fl::u8 getPaddingByte() FL_NO_EXCEPT { return 0x00; }
59
63 static fl::span<const fl::u8> getPaddingLEDFrame() FL_NO_EXCEPT { // okay static in header
64 static const fl::u8 frame[] = { // okay static in header
65 0x00, // Red = 0
66 0x00, // Green = 0
67 0x00 // Blue = 0
68 };
69 return fl::span<const fl::u8>(frame, 3);
70 }
71
74 static constexpr size_t getPaddingLEDFrameSize() FL_NO_EXCEPT {
75 return 3;
76 }
77
82 static constexpr size_t calculateBytes(size_t num_leds) FL_NO_EXCEPT {
83 // WS2801 protocol:
84 // - LED data: 3 bytes per LED (RGB)
85 // - No frame overhead (latch is timing-based, not data-based)
86 return num_leds * 3;
87 }
88};
89
92template <int DATA_PIN, fl::u8 CLOCK_PIN, EOrder RGB_ORDER = RGB, fl::u32 SPI_SPEED = DATA_RATE_MHZ(25)>
93class WS2803Controller : public WS2801Controller<DATA_PIN, CLOCK_PIN, RGB_ORDER, SPI_SPEED> {};
Class to ensure that a minimum amount of time has kicked since the last time run - and delay if not e...
CPixelLEDController(RegistrationMode mode) FL_NO_EXCEPT
virtual void showPixels(PixelController< RGB_ORDER > &pixels) FL_NO_EXCEPT
Send the LED data to the strip.
Definition ws2801.h:48
fl::SPIOutput< DATA_PIN, CLOCK_PIN, SPI_SPEED > SPI
Definition ws2801.h:26
static constexpr size_t calculateBytes(size_t num_leds) FL_NO_EXCEPT
Calculate total byte count for WS2801 protocol Used for quad-SPI buffer pre-allocation.
Definition ws2801.h:82
static constexpr fl::u8 getPaddingByte() FL_NO_EXCEPT
Get the protocol-safe padding byte for WS2801 Used for quad-SPI lane padding when strips have differe...
Definition ws2801.h:58
static constexpr size_t getPaddingLEDFrameSize() FL_NO_EXCEPT
Get the size of the padding LED frame in bytes.
Definition ws2801.h:74
virtual void init() FL_NO_EXCEPT
Initialize the controller.
Definition ws2801.h:40
WS2801Controller() FL_NO_EXCEPT
Definition ws2801.h:31
CMinWait< 1000 > mWaitDelay
Definition ws2801.h:28
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 ws2801.h:63
WS2803 controller class.
Definition ws2801.h:93
CLEDController & setSpiBus(Esp32SpiBus bus) FL_NO_EXCEPT
Select an ESP-IDF SPI host for this clocked controller before init().
fl::CLEDController CLEDController
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.