FastLED 3.9.15
Loading...
Searching...
No Matches
rectangular_draw_buffer.h
Go to the documentation of this file.
1
2#pragma once
3
4// Takes multiple CRGB arrays[] of different sizes and generates one CRGB
5// array of size MAX(WIDTH) * NUM_OF_STRIPS that contains them all.
6
7// This allows the flexible LED array usage in FastLED for block renderers.
8
9// Needed by controllers that require a compact, rectangular buffer of pixel
10// data. Namely, ObjectFLED and the I2S controllers. This class handles using
11// multiple independent strips of LEDs, each with their own buffer of pixel
12// data. The strips are not necessarily contiguous in memory. One or more
13// DrawItems containing the pin number and number are queued up. When the
14// queue-ing is done, the buffers are compacted into the rectangular buffer.
15// Data access is achieved through a span<u8> representing the pixel data
16// for that pin.
17
18#include "fl/stdint.h"
19
20#include "fl/int.h"
21#include "fl/map.h"
22#include "fl/namespace.h"
23#include "fl/scoped_array.h"
24#include "fl/span.h"
25#include "fl/vector.h"
26
27namespace fl {
28
29struct DrawItem {
30 DrawItem() = default;
31 DrawItem(u8 pin, u16 numLeds, bool is_rgbw);
32
33 // Rule of 5 for POD data
34 DrawItem(const DrawItem &other) = default;
35 DrawItem &operator=(const DrawItem &other) = default;
36 DrawItem(DrawItem &&other) noexcept = default;
37 DrawItem &operator=(DrawItem &&other) noexcept = default;
38
39 u8 mPin = 0;
40 u32 mNumBytes = 0;
41 bool mIsRgbw = false;
42 bool operator!=(const DrawItem &other) const {
43 return mPin != other.mPin || mNumBytes != other.mNumBytes ||
44 mIsRgbw != other.mIsRgbw;
45 }
46};
47
48
50 public:
51
52
55
57 bool clear_first = true);
58
59 // Safe to call multiple times before calling queue() once. Returns true on
60 // the first call, false after.
61 bool onQueuingStart();
62 void queue(const DrawItem &item);
63
64 // Compiles the RectangularBuffer if necessary.
65 // Safe to call multiple times before calling onQueueingStart() again.
66 // Returns true on the first call, false after.
67 bool onQueuingDone();
68
69 // Valid after onQueueDone:
70 u32 getMaxBytesInStrip() const;
71 u32 getTotalBytes() const;
72 void getBlockInfo(u32 *num_strips, u32 *bytes_per_strip,
73 u32 *total_bytes) const;
74
75// protected:
77 // We manually manage the memory for the buffer of all LEDs so that it can
78 // go into psram on ESP32S3, which is managed by fl::PSRamAllocator.
85
88};
89
90} // namespace fl
fl::HeapVector< DrawItem > DrawList
fl::span< u8 > getLedsBufferBytesForPin(u8 pin, bool clear_first=true)
fl::FixedMap< u8, fl::span< u8 >, 50 > mPinToLedSegment
void getBlockInfo(u32 *num_strips, u32 *bytes_per_strip, u32 *total_bytes) const
void queue(const DrawItem &item)
Implements the FastLED namespace macros.
unsigned char u8
Definition int.h:17
Slice< T > span
Definition span.h:8
IMPORTANT!
Definition crgb.h:20
DrawItem(const DrawItem &other)=default
DrawItem()=default
DrawItem & operator=(DrawItem &&other) noexcept=default
DrawItem(DrawItem &&other) noexcept=default
bool operator!=(const DrawItem &other) const
DrawItem & operator=(const DrawItem &other)=default