FastLED 3.9.15
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
34 virtual void init() {
35 mSPI.init();
36 mWaitDelay.mark();
37 }
38
39protected:
40
42 virtual void showPixels(PixelController<RGB_ORDER> & pixels) {
43 mWaitDelay.wait();
44 fl::writePixelsToSPI<0, DATA_NOP, RGB_ORDER>(pixels, mSPI, nullptr);
45 mWaitDelay.mark();
46 }
47
48public:
52 static constexpr fl::u8 getPaddingByte() { return 0x00; }
53
57 static fl::span<const fl::u8> getPaddingLEDFrame() { // okay static in header
58 static const fl::u8 frame[] = { // okay static in header
59 0x00, // Red = 0
60 0x00, // Green = 0
61 0x00 // Blue = 0
62 };
63 return fl::span<const fl::u8>(frame, 3);
64 }
65
68 static constexpr size_t getPaddingLEDFrameSize() {
69 return 3;
70 }
71
76 static constexpr size_t calculateBytes(size_t num_leds) {
77 // WS2801 protocol:
78 // - LED data: 3 bytes per LED (RGB)
79 // - No frame overhead (latch is timing-based, not data-based)
80 return num_leds * 3;
81 }
82};
83
86template <int DATA_PIN, fl::u8 CLOCK_PIN, EOrder RGB_ORDER = RGB, fl::u32 SPI_SPEED = DATA_RATE_MHZ(25)>
87class 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)
virtual void showPixels(PixelController< RGB_ORDER > &pixels)
Send the LED data to the strip.
Definition ws2801.h:42
fl::SPIOutput< DATA_PIN, CLOCK_PIN, SPI_SPEED > SPI
Definition ws2801.h:26
WS2801Controller() FL_NOEXCEPT
Definition ws2801.h:31
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 ws2801.h:57
static constexpr size_t calculateBytes(size_t num_leds)
Calculate total byte count for WS2801 protocol Used for quad-SPI buffer pre-allocation.
Definition ws2801.h:76
static constexpr size_t getPaddingLEDFrameSize()
Get the size of the padding LED frame in bytes.
Definition ws2801.h:68
virtual void init()
Initialize the controller.
Definition ws2801.h:34
CMinWait< 1000 > mWaitDelay
Definition ws2801.h:28
static constexpr fl::u8 getPaddingByte()
Get the protocol-safe padding byte for WS2801 Used for quad-SPI lane padding when strips have differe...
Definition ws2801.h:52
WS2803 controller class.
Definition ws2801.h:87
unsigned char u8
Definition stdint.h:131
Includes defintions for RGB and HSV pixels.
#define FL_NOEXCEPT
Pixel controller class.