FastLED 3.10.8
Loading...
Searching...
No Matches
ucs7604.h
Go to the documentation of this file.
1#pragma once
2
3#ifndef __INC_UCS7604_H
4#define __INC_UCS7604_H
5
6#include "pixel_controller.h"
11#include "fl/stl/bit_cast.h"
12#include "fl/stl/vector.h"
13#include "fl/math/ease.h"
14#include "fl/stl/iterator.h"
15#include "fl/stl/noexcept.h"
16
47
48#ifndef FL_UCS7604_BRIGHTNESS
49#define FL_UCS7604_BRIGHTNESS 0x0F
50#endif
51
52namespace fl {
53
55namespace ucs7604 {
58
64
72 inline void set_brightness(u8 r, u8 g, u8 b, u8 w) FL_NO_EXCEPT {
74 }
75
79
80} // namespace ucs7604
81
83template <
84 int DATA_PIN,
85 EOrder RGB_ORDER, // Color order for input pixels (converted to RGB internally)
86 fl::UCS7604Mode MODE,
87 typename CHIPSET_TIMING,
88 template<int, typename, EOrder> class CLOCKLESS_CONTROLLER
89>
91{
92private:
93 using DelegateControllerBase = CLOCKLESS_CONTROLLER<DATA_PIN, CHIPSET_TIMING, RGB>;
94
95 // Helper class to access protected methods of the delegate controller
97 friend class UCS7604ControllerT<DATA_PIN, RGB_ORDER, MODE, CHIPSET_TIMING, CLOCKLESS_CONTROLLER>;
99 DelegateControllerBase::showPixels(pixels);
100 }
101 };
102
103 DelegateController mDelegate; // Clockless controller for wire transmission (always RGB)
104
105 // Reusable byte buffer (uses PSRAM on ESP32, regular heap elsewhere)
106 // Cleared each frame but memory is reused (no reallocation after first use)
107 float mGamma = 2.8f;
109
110public:
112
114 void clearGamma() FL_NO_EXCEPT { mGamma = 2.8f; }
115
116 virtual void init() FL_NO_EXCEPT override {
117 mDelegate.init();
118 // UCS7604 is always RGBW — override any user setting.
120 }
121
122 // Access delegate controller (for testing)
123 const DelegateController& getDelegate() const FL_NO_EXCEPT {
124 return mDelegate;
125 }
126
127 DelegateController& getDelegate() FL_NO_EXCEPT {
128 return mDelegate;
129 }
130
131protected:
132
136
137 virtual void showPixels(PixelController<RGB_ORDER> &pixels) FL_NO_EXCEPT override {
138 if (pixels.size() == 0) {
139 return;
140 }
141
142 // Get current control values (recalculated each frame)
144
145 // Reorder RGB current values to match the color order (RGB_ORDER template parameter)
146 // The current control values are semantic (current.r controls RED LEDs, etc.)
147 // but need to be sent in wire order matching the pixel data reordering
148 u8 rgb_currents[3] = {current.r, current.g, current.b};
149
150 // Extract channel positions from RGB_ORDER (octal encoding: 0=R, 1=G, 2=B)
151 // Octal digits are read right-to-left in bit positions but left-to-right semantically
152 // RGB (012 octal): wire position 0=R(0), 1=G(1), 2=B(2)
153 // GRB (102 octal): wire position 0=G(1), 1=R(0), 2=B(2)
154 u8 pos0 = (static_cast<int>(RGB_ORDER) >> 6) & 0x3; // Wire position 0 (leftmost octal digit)
155 u8 pos1 = (static_cast<int>(RGB_ORDER) >> 3) & 0x3; // Wire position 1 (middle octal digit)
156 u8 pos2 = (static_cast<int>(RGB_ORDER) >> 0) & 0x3; // Wire position 2 (rightmost octal digit)
157
158 // Reorder: wire R gets current for channel at pos0, etc.
159 u8 r_current = rgb_currents[pos0]; // Wire R (position 0)
160 u8 g_current = rgb_currents[pos1]; // Wire G (position 1)
161 u8 b_current = rgb_currents[pos2]; // Wire B (position 2)
162 u8 w_current = current.w; // W always in position 3
163
164 // Create current control struct with reordered values
165 fl::UCS7604CurrentControl wire_current(r_current, g_current, b_current, w_current);
166
167 // Get gamma LUT: per-controller override or default 2.8
168 float gamma = mGamma;
170
171 // UCS7604 is always RGBW — override any user setting.
173 fl::PixelIterator pixel_iter = pixels.as_iterator(rgbw);
174
175 // Clear buffer and use encoder to fill it
176 mByteBuffer.clear();
178 MODE, wire_current, pixel_iter.get_rgbw().active(), gamma8.get());
179
180 // Reinterpret byte buffer as CRGB pixels (encoder ensures divisible by 3)
181 size_t num_pixels = mByteBuffer.size() / 3;
182 CRGB* fake_pixels = fl::bit_cast<CRGB*>(mByteBuffer.data());
183
184 // Construct PixelController and send to delegate controller
185 PixelController<RGB> pixel_data(fake_pixels, num_pixels, ColorAdjustment::noAdjustment(), DISABLE_DITHER);
186 mDelegate.callShowPixels(pixel_data);
187 }
188};
189
190// now typedef the controllers
191template <int DATA_PIN, EOrder RGB_ORDER, template<int, typename, EOrder> class CLOCKLESS_CONTROLLER>
193
194template <int DATA_PIN, EOrder RGB_ORDER, template<int, typename, EOrder> class CLOCKLESS_CONTROLLER>
196
197template <int DATA_PIN, EOrder RGB_ORDER, template<int, typename, EOrder> class CLOCKLESS_CONTROLLER>
199
200} // namespace fl
201
202#endif // __INC_UCS7604_H
#define DATA_PIN
Definition ClientReal.h:82
#define RGB_ORDER
Rgbw rgbw
CPixelLEDController(RegistrationMode mode) FL_NO_EXCEPT
Protected constructor with registration mode.
CLEDController & setRgbw(const Rgbw &arg=RgbwDefault::value()) FL_NO_EXCEPT
static fl::shared_ptr< const Gamma8 > getOrCreate(float gamma) FL_NO_EXCEPT
Definition ease.cpp.hpp:460
Rgbw get_rgbw() const FL_NO_EXCEPT
int size() FL_NO_EXCEPT
void callShowPixels(PixelController< RGB > &pixels) FL_NO_EXCEPT
Definition ucs7604.h:98
CLOCKLESS_CONTROLLER< DATA_PIN, CHIPSET_TIMING, RGB > DelegateControllerBase
Definition ucs7604.h:93
const DelegateController & getDelegate() const FL_NO_EXCEPT
Definition ucs7604.h:123
fl::span< const u8 > bytes() const FL_NO_EXCEPT
Definition ucs7604.h:133
void clearGamma() FL_NO_EXCEPT
Definition ucs7604.h:114
UCS7604ControllerT() FL_NO_EXCEPT
Definition ucs7604.h:111
virtual void showPixels(PixelController< RGB_ORDER > &pixels) FL_NO_EXCEPT override
Definition ucs7604.h:137
void setGamma(float gamma) FL_NO_EXCEPT
Definition ucs7604.h:113
DelegateController & getDelegate() FL_NO_EXCEPT
Definition ucs7604.h:127
virtual void init() FL_NO_EXCEPT override
Initialize the LED controller.
Definition ucs7604.h:116
UCS7604 controller extending CPixelLEDController.
Definition ucs7604.h:91
T * get() const FL_NO_EXCEPT
Definition shared_ptr.h:342
defines the templated version of the CLEDController class
#define DISABLE_DITHER
Disable dithering.
Definition dither_mode.h:14
UCS7604 LED chipset encoder implementation.
Non-templated low level pixel data writing class.
Centralized LED chipset timing definitions with nanosecond precision.
void set_brightness(CurrentControl current) FL_NO_EXCEPT
Set global UCS7604 brightness via current control (EXPERIMENTAL)
CurrentControl brightness() FL_NO_EXCEPT
Get current global UCS7604 brightness value.
UCS7604CurrentControl CurrentControl
Type alias for current control (defined in ucs7604_encoder.h)
Definition ucs7604.h:57
back_insert_iterator< Container > back_inserter(Container &c) FL_NO_EXCEPT
Helper function to create a back_insert_iterator.
Definition iterator.h:139
unsigned char u8
Definition stdint.h:131
u8 u8 fract8 blur_amount FL_NO_EXCEPT
Definition blur.h:186
constexpr u32 gamma(float g) FL_NO_EXCEPT
Definition gamma_lut.h:36
UCS7604ControllerT< DATA_PIN, RGB_ORDER, fl::UCS7604Mode::UCS7604_MODE_16BIT_800KHZ, fl::TIMING_UCS7604_800KHZ, CLOCKLESS_CONTROLLER > UCS7604Controller16bitT
Definition ucs7604.h:195
UCS7604Mode
UCS7604 protocol configuration modes.
Definition ucs7604.h:30
To bit_cast(const From &from) FL_NO_EXCEPT
Definition bit_cast.h:48
EOrder
RGB color channel orderings, used when instantiating controllers to determine what order the controll...
Definition eorder.h:15
void encodeUCS7604(PixelIterator &pixel_iter, size_t num_leds, OutputIterator out, UCS7604Mode mode, const UCS7604CurrentControl &current, bool is_rgbw, const Gamma8 *gamma=nullptr, bool wide_source=false) FL_NO_EXCEPT
Encode complete UCS7604 frame (preamble + padding + pixel data)
Definition ucs7604.h:273
UCS7604ControllerT< DATA_PIN, RGB_ORDER, fl::UCS7604Mode::UCS7604_MODE_8BIT_800KHZ, fl::TIMING_UCS7604_800KHZ, CLOCKLESS_CONTROLLER > UCS7604Controller8bitT
Definition ucs7604.h:192
InputGamut g
Definition rgbw.h:125
UCS7604ControllerT< DATA_PIN, RGB_ORDER, fl::UCS7604Mode::UCS7604_MODE_16BIT_1600KHZ, fl::TIMING_UCS7604_1600KHZ, CLOCKLESS_CONTROLLER > UCS7604Controller16bit1600T
Definition ucs7604.h:198
Base definition for an LED controller.
Low level pixel data writing class.
static ColorAdjustment noAdjustment() FL_NO_EXCEPT
the per-channel scale values premixed with brightness.
Pixel controller class.
Representation of an 8-bit RGB pixel (Red, Green, Blue)
Definition crgb.h:38
FASTLED_FORCE_INLINE bool active() const FL_NO_EXCEPT
Definition rgbw.h:258
static Rgbw value() FL_NO_EXCEPT
Definition rgbw.h:290
u8 g
Green channel current (0x0-0xF)
Definition ucs7604.h:39
u8 b
Blue channel current (0x0-0xF)
Definition ucs7604.h:40
u8 w
White channel current (0x0-0xF)
Definition ucs7604.h:41
u8 r
Red channel current (0x0-0xF)
Definition ucs7604.h:38
UCS7604 current control structure with 4-bit fields for each channel.
Definition ucs7604.h:37