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 fl::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/stl/int.h"
19#include "fl/stl/allocator.h"
20#include "fl/stl/flat_map.h"
21#include "fl/stl/unique_ptr.h"
22#include "fl/stl/vector.h"
23#include "fl/stl/strstream.h"
24#include "fl/stl/noexcept.h"
25
26namespace fl {
27
28struct DrawItem {
29 DrawItem() FL_NOEXCEPT = default;
30 DrawItem(u8 pin, u16 numLeds, bool is_rgbw);
31
32 // Rule of 5 for POD data
33 DrawItem(const DrawItem &other) FL_NOEXCEPT = default;
34 DrawItem &operator=(const DrawItem &other) = default;
35 DrawItem(DrawItem &&other) FL_NOEXCEPT = default;
36 DrawItem &operator=(DrawItem &&other) FL_NOEXCEPT = default;
37
38 u8 mPin = 0;
39 u32 mNumBytes = 0;
40 bool mIsRgbw = false;
41 bool operator!=(const DrawItem &other) const {
42 return mPin != other.mPin || mNumBytes != other.mNumBytes ||
43 mIsRgbw != other.mIsRgbw;
44 }
45};
46
48 public:
49
58
60 bool clear_first = true);
61
62 // Safe to call multiple times before calling queue() once. Returns true on
63 // the first call, false after.
64 bool onQueuingStart();
65 void queue(const DrawItem &item);
66
67 // Compiles the RectangularBuffer if necessary.
68 // Safe to call multiple times before calling onQueueingStart() again.
69 // Returns true on the first call, false after.
70 bool onQueuingDone();
71
72 // Valid after onQueueDone:
73 u32 getMaxBytesInStrip() const;
74 u32 getTotalBytes() const;
75 void getBlockInfo(u32 *num_strips, u32 *bytes_per_strip,
76 u32 *total_bytes) const;
77
78// protected:
80 // We manually manage the memory for the buffer of all LEDs so that it can
81 // go into psram on ESP32S3, which is managed by fl::PSRamAllocator.
82 // Use PSRamDeleter to properly free memory allocated with PSRamAllocator.
89
92};
93
94} // namespace fl
fl::vector< DrawItem > DrawList
fl::flat_map< u8, fl::span< u8 > > mPinToLedSegment
fl::span< u8 > getLedsBufferBytesForPin(u8 pin, bool clear_first=true)
unique_ptr< u8[], PSRamDeleter< u8 > > mAllLedsBufferUint8
void getBlockInfo(u32 *num_strips, u32 *bytes_per_strip, u32 *total_bytes) const
~RectangularDrawBuffer() FL_NOEXCEPT=default
unsigned char u8
Definition stdint.h:131
Base definition for an LED controller.
Definition crgb.hpp:179
#define FL_NOEXCEPT
DrawItem() FL_NOEXCEPT=default