10#include "platforms/shared/spi_pixel_writer.h"
35 fl::u32 START_FRAME = 0x00000000,
40 fl::u32 END_FRAME = 0xFFFFFFFF
43 typedef fl::SPIOutput<DATA_PIN, CLOCK_PIN, SPI_SPEED>
SPI;
47 mSPI.writeWord(START_FRAME >> 16);
48 mSPI.writeWord(START_FRAME & 0xFFFF);
51 int nDWords = (nLeds/32);
65#ifdef FASTLED_SPI_BYTE_ONLY
71 fl::u16 b = 0xE000 | (
brightness << 8) | (fl::u16)b0;
80#ifdef FASTLED_SPI_BYTE_ONLY
84 mSPI.writeWord(fl::u16(b1) << 8 | b2);
90 #if defined(FL_IS_ESP32)
104 switch (GAMMA_CORRECTION_MODE) {
121#if FASTLED_HD_COLOR_MIXING
123 pixels.loadRGBScaleAndBrightness(out_s0, out_s1, out_s2, &
brightness);
125 static fl::u16 map(fl::u16
x, fl::u16 in_min, fl::u16 in_max, fl::u16 out_min, fl::u16 out_max)
FL_NO_EXCEPT {
126 const fl::u16 run = in_max - in_min;
127 const fl::u16 rise = out_max - out_min;
128 const fl::u16 delta =
x - in_min;
129 return (delta * rise) / run + out_min;
133 fl::u16 bri = Math::map(
brightness, 0, 255, 0, 31);
138 *out_brightness =
static_cast<fl::u8>(bri);
142 pixels.loadAndScaleRGB(&s0, &s1, &s2);
143#if FASTLED_USE_GLOBAL_BRIGHTNESS == 1
145 const fl::u16 maxBrightness = 0x1F;
147 fl::u8 max_s01 = (s0 > s1) ? s0 : s1;
148 fl::u8 max_component = (max_s01 > s2) ? max_s01 : s2;
149 fl::u16
brightness = ((((fl::u16)max_component + 1) * maxBrightness - 1) >> 8) + 1;
166 fl::u8 s0, s1, s2, global_brightness;
169 while (pixels.has(1)) {
171 pixels.loadAndScaleRGB(&c0, &c1, &c2);
172 writeLed(global_brightness, c0, c1, c2);
173 pixels.stepDithering();
174 pixels.advanceData();
178 mSPI.endTransaction();
181 mSPI.finalizeTransmission();
185 static constexpr fl::u16 kBatchSize = 8;
186 const fl::u16 n =
static_cast<fl::u16
>(pixels.size());
189 fl::u8 scale_r, scale_g, scale_b, global_brightness;
190 #if FASTLED_HD_COLOR_MIXING
191 pixels.loadRGBScaleAndBrightness(&scale_r, &scale_g, &scale_b, &global_brightness);
193 pixels.loadAndScaleRGB(&scale_r, &scale_g, &scale_b);
194 global_brightness = 255;
196 const CRGB colors_scale(scale_r, scale_g, scale_b);
207 fl::u16 remaining = n;
208 while (remaining > 0) {
209 const fl::u16 batch = (remaining < kBatchSize) ? remaining : kBatchSize;
210 CRGB input_buf[kBatchSize];
214 for (fl::u16 i = 0; i < batch; ++i) {
215 const fl::u8* raw = pixels.getRawPixelData();
216 input_buf[i] =
CRGB(raw[0], raw[1], raw[2]);
217 pixels.advanceData();
224 for (fl::u16 i = 0; i < batch; ++i) {
226 writeLed(gamma_buf[i].brightness_5bit,
227 rgb.raw[b0_index], rgb.raw[b1_index], rgb.raw[b2_index]);
234 mSPI.endTransaction();
235 mSPI.finalizeTransmission();
252 static const fl::u8 frame[] = {
276 return 4 + (num_leds * 4) + (4 * ((num_leds / 32) + 1));
309 fl::FiveBitGammaCorrectionMode::kFiveBitGammaCorrectionMode_BitShift,
311 fl::u32(0xFFFFFFFF)> {
333 fl::FiveBitGammaCorrectionMode::kFiveBitGammaCorrectionMode_Null,
355 fl::FiveBitGammaCorrectionMode::kFiveBitGammaCorrectionMode_BitShift,
373 fl::FiveBitGammaCorrectionMode::kFiveBitGammaCorrectionMode_Null,
fl::UISlider brightness("Brightness", BRIGHTNESS, 0, 255)
void showPixelsDefault(PixelController< RGB_ORDER > &pixels) FL_NO_EXCEPT
void endBoundary(int nLeds) FL_NO_EXCEPT
static void getGlobalBrightnessAndScalingFactors(PixelController< RGB_ORDER > &pixels, fl::u8 *out_s0, fl::u8 *out_s1, fl::u8 *out_s2, fl::u8 *out_brightness) FL_NO_EXCEPT
static fl::span< const fl::u8 > getPaddingLEDFrame() FL_NO_EXCEPT
Get padding LED frame for synchronized latching in quad-SPI Returns a black LED frame to prepend to s...
FASTLED_FORCE_INLINE void writeLed(fl::u8 brightness, fl::u8 b0, fl::u8 b1, fl::u8 b2) FL_NO_EXCEPT
APA102Controller() FL_NO_EXCEPT
void startBoundary() FL_NO_EXCEPT
virtual void init() FL_NO_EXCEPT override
Initialize the LED controller.
static constexpr fl::u8 getPaddingByte() FL_NO_EXCEPT
Get the protocol-safe padding byte for APA102 Used for quad-SPI lane padding when strips have differe...
void showPixelsGammaBitShift(PixelController< RGB_ORDER > &pixels) FL_NO_EXCEPT
static constexpr fl::u32 getStartFrame() FL_NO_EXCEPT
Get the configured start frame DWord.
fl::SPIOutput< DATA_PIN, CLOCK_PIN, SPI_SPEED > SPI
static constexpr size_t calculateBytes(size_t num_leds) FL_NO_EXCEPT
Calculate total byte count for APA102 protocol Used for quad-SPI buffer pre-allocation.
FASTLED_FORCE_INLINE void write2Bytes(fl::u8 b1, fl::u8 b2) FL_NO_EXCEPT
virtual void showPixels(PixelController< RGB_ORDER > &pixels) FL_NO_EXCEPT override
Send the LED data to the strip.
static constexpr size_t getPaddingLEDFrameSize() FL_NO_EXCEPT
Get size of padding LED frame in bytes.
static constexpr fl::u32 getEndFrame() FL_NO_EXCEPT
Get the configured end frame DWord.
APA102ControllerHD() FL_NO_EXCEPT=default
CPixelLEDController(RegistrationMode mode) FL_NO_EXCEPT
HD107 is just the APA102 with a default 40Mhz clock rate.
HD107HD is just the APA102HD with a default 40Mhz clock rate.
CLEDController & setSpiBus(Esp32SpiBus bus) FL_NO_EXCEPT
Select an ESP-IDF SPI host for this clocked controller before init().
fl::CLEDController CLEDController
#define FASTLED_FORCE_INLINE
defines the templated version of the CLEDController class
Serial peripheral interface (SPI) definitions per platform.
Declares functions for five-bit gamma correction.
Esp32SpiBus
ESP-IDF SPI host selection for an individual clocked LED controller.
FiveBitGammaCorrectionMode
@ kFiveBitGammaCorrectionMode_Null
@ kFiveBitGammaCorrectionMode_BitShift
FL_OPTIMIZE_FUNCTION void five_bit_hd_gamma_bitshift(fl::span< const CRGB > colors, CRGB colors_scale, u8 global_brightness, fl::span< CRGB > out_colors, fl::span< u8 > out_power_5bit) FL_NO_EXCEPT
Base definition for an LED controller.