MCPcopy Create free account
hub / github.com/FastLED/FastLED / hsv2rgb_raw_avr

Function hsv2rgb_raw_avr

src/hsv2rgb.cpp.hpp:141–232  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

139
140#if defined(FL_IS_AVR) && !defined(FL_IS_AVR_ATTINY)
141void hsv2rgb_raw_avr(const CHSV & hsv, CRGB & rgb)
142{
143 fl::u8 hue, saturation, value;
144
145 hue = hsv.hue;
146 saturation = hsv.sat;
147 value = hsv.val;
148
149 // Saturation more useful the other way around
150 saturation = 255 - saturation;
151 fl::u8 invsat = APPLY_DIMMING( saturation ); // cppcheck-suppress selfAssignment
152
153 // Apply dimming curves
154 value = APPLY_DIMMING( value ); // cppcheck-suppress selfAssignment
155
156 // The brightness floor is minimum number that all of
157 // R, G, and B will be set to, which is value * invsat
158 fl::u8 brightness_floor;
159
160 asm volatile(
161 "mul %[value], %[invsat] \n"
162 "mov %[brightness_floor], r1 \n"
163 : [brightness_floor] "=r" (brightness_floor)
164 : [value] "r" (value),
165 [invsat] "r" (invsat)
166 : "r0", "r1"
167 );
168
169 // The color amplitude is the maximum amount of R, G, and B
170 // that will be added on top of the brightness_floor to
171 // create the specific hue desired.
172 fl::u8 color_amplitude = value - brightness_floor;
173
174 // Figure how far we are offset into the section of the
175 // color wheel that we're in
176 fl::u8 offset = hsv.hue & (HSV_SECTION_3 - 1); // 0..63
177 fl::u8 rampup = offset * 4; // 0..252
178
179
180 // compute color-amplitude-scaled-down versions of rampup and rampdown
181 fl::u8 rampup_amp_adj;
182 fl::u8 rampdown_amp_adj;
183
184 asm volatile(
185 "mul %[rampup], %[color_amplitude] \n"
186 "mov %[rampup_amp_adj], r1 \n"
187 "com %[rampup] \n"
188 "mul %[rampup], %[color_amplitude] \n"
189 "mov %[rampdown_amp_adj], r1 \n"
190 : [rampup_amp_adj] "=&r" (rampup_amp_adj),
191 [rampdown_amp_adj] "=&r" (rampdown_amp_adj),
192 [rampup] "+r" (rampup)
193 : [color_amplitude] "r" (color_amplitude)
194 : "r0", "r1"
195 );
196
197
198 // add brightness_floor offset to everything

Callers 1

hsv2rgb_rawFunction · 0.85

Calls 1

cleanup_R1Function · 0.50

Tested by

no test coverage detected