FastLED 3.9.12
Loading...
Searching...
No Matches
rectangular_draw_buffer.h
1
2#pragma once
3
4#include <stdint.h>
5
6#include "fl/map.h"
7#include "fl/scoped_ptr.h"
8#include "fl/slice.h"
9#include "fl/vector.h"
10#include "fl/namespace.h"
11
12namespace fl {
13
14struct DrawItem {
15 DrawItem() = default;
16 DrawItem(uint8_t pin, uint16_t numLeds, bool is_rgbw);
17 uint8_t mPin = 0;
18 uint32_t mNumBytes = 0;
19 bool mIsRgbw = false;
20 bool operator!=(const DrawItem &other) const {
21 return mPin != other.mPin || mNumBytes != other.mNumBytes ||
22 mIsRgbw != other.mIsRgbw;
23 }
24};
25
26// Needed by controllers that require a compact, rectangular buffer of pixel data.
27// Namely, ObjectFLED and the I2S controllers.
28// This class handles using multiple independent strips of LEDs, each with their own
29// buffer of pixel data. The strips are not necessarily contiguous in memory.
30// One or more DrawItems containing the pin number and number are queued
31// up. When the queue-ing is done, the buffers are compacted into the rectangular buffer.
32// Data access is achieved through a Slice<uint8_t> representing the pixel data for that pin.
34 public:
36 // We manually manage the memory for the buffer of all LEDs so that it can go
37 // into psram on ESP32S3, which is managed by fl::LargeBlockAllocator.
38 scoped_array<uint8_t> mAllLedsBufferUint8;
39 uint32_t mAllLedsBufferUint8Size = 0;
40 fl::FixedMap<uint8_t, fl::Slice<uint8_t>, 50> mPinToLedSegment;
41 DrawList mDrawList;
42 DrawList mPrevDrawList;
43 bool mDrawListChangedThisFrame = false;
44
45 enum QueueState { IDLE, QUEUEING, QUEUE_DONE };
46 QueueState mQueueState = IDLE;
47
48 RectangularDrawBuffer() = default;
49 ~RectangularDrawBuffer() = default;
50
51 fl::Slice<uint8_t> getLedsBufferBytesForPin(uint8_t pin, bool clear_first=true);
52
53 // Safe to call multiple times before calling queue() once. Returns true on the first call, false after.
54 bool onQueuingStart();
55 void queue(const DrawItem &item);
56
57 // Safe to call multiple times before calling onQueueingStart() again. Returns true on the first call, false after.
58 bool onQueuingDone();
59 uint32_t getMaxBytesInStrip() const;
60 uint32_t getTotalBytes() const;
61 void getBlockInfo(uint32_t *num_strips, uint32_t *bytes_per_strip,
62 uint32_t *total_bytes) const;
63};
64
65} // namespace fl
Implements the FastLED namespace macros.
Implements a simple red square effect for 2D LED grids.
Definition crgb.h:16