FastLED 3.10.8
Loading...
Searching...
No Matches

◆ showPixels()

template<int DATA_PIN, fl::u8 CLOCK_PIN, EOrder RGB_ORDER = GRB, fl::u32 SPI_SPEED = DATA_RATE_MHZ(25)>
void HD108Controller< DATA_PIN, CLOCK_PIN, RGB_ORDER, SPI_SPEED >::showPixels ( PixelController< RGB_ORDER > & pixels)
inlineoverrideprotected

Definition at line 57 of file hd108.h.

57 {
58 mSPI.select();
59
60 // ---- Start frame: 64 bits of 0 ----
61 // HD108 requires 8 bytes (64 bits) of zeros to initialize the strip
62 // Note: Some sources mention 128 bits (16 bytes), but 64 bits works reliably
63 for (int i = 0; i < 8; i++) mSPI.writeByte(0x00);
64
65 while (pixels.has(1)) {
66 // Load and scale pixel data in OUTPUT order (respects RGB_ORDER template parameter)
68 pixels.loadAndScaleRGB(&c0_8, &c1_8, &c2_8);
69
70 // Apply gamma correction (2.8) to convert 8-bit to 16-bit for HD108
71 // This provides smooth perceptual brightness transitions across the full 65K range
72 // Note: Brightness scaling is applied by loadAndScaleRGB() before gamma correction
76
77 // Header bytes: HD108 per-channel gain control encoding
78 // f0: [1][RRRRR][GG] - marker bit, 5-bit R gain, 2 MSBs of G gain
79 // f1: [GGG][BBBBB] - 3 LSBs of G gain, 5-bit B gain
80 // Use maximum gain (31) for all channels to maximize precision
81 // Brightness control via 16-bit PWM values (already applied via loadAndScaleRGB)
82 constexpr fl::u8 r_gain = 31, g_gain = 31, b_gain = 31;
83 constexpr fl::u8 f0 = fl::u8(0x80 | ((r_gain & 0x1F) << 2) | ((g_gain >> 3) & 0x03));
84 constexpr fl::u8 f1 = fl::u8(((g_gain & 0x07) << 5) | (b_gain & 0x1F));
85
86 // Transmit LED frame: 2 header bytes + 6 color bytes (16-bit, big-endian, in RGB_ORDER)
87 mSPI.writeByte(f0);
88 mSPI.writeByte(f1);
89 mSPI.writeByte(fl::u8(c0_16 >> 8)); mSPI.writeByte(fl::u8(c0_16 & 0xFF)); // Channel 0 MSB, LSB
90 mSPI.writeByte(fl::u8(c1_16 >> 8)); mSPI.writeByte(fl::u8(c1_16 & 0xFF)); // Channel 1 MSB, LSB
91 mSPI.writeByte(fl::u8(c2_16 >> 8)); mSPI.writeByte(fl::u8(c2_16 & 0xFF)); // Channel 2 MSB, LSB
92
93 pixels.stepDithering();
94 pixels.advanceData();
95 }
96
97 // ---- End frame: 0xFF bytes to latch data into LEDs ----
98 // Formula: (num_leds / 2) + 4 provides sufficient clock pulses for 40 MHz operation
99 // This is more conservative than APA102's (num_leds + 15) / 16 formula
100 const int latch = pixels.size() / 2 + 4;
101 for (int i = 0; i < latch; i++) mSPI.writeByte(0xFF);
102 mSPI.endTransaction();
103}
VIRTUAL_IF_NOT_AVR int size() const FL_NO_EXCEPT
How many LEDs does this controller manage?
unsigned char u8
Definition stdint.h:131
u16 gamma_2_8(u8 value) FL_NO_EXCEPT
Definition ease.cpp.hpp:54

References FL_NO_EXCEPT, fl::gamma_2_8(), and mSPI.

+ Here is the call graph for this function: