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

Function analogWrite

src/fl/system/pin.cpp.hpp:227–247  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

225// ============================================================================
226
227void analogWrite(int pin, u16 val) {
228 pwm_state::PwmPinState* ch = pwm_state::findByPin(pin);
229
230 if (ch && ch->backend == pwm_state::PwmBackend::IsrSoftware) {
231 // Route to ISR duty cycle update (scale 8-bit val to duty)
232 u8 duty = (val > 255) ? 255 : static_cast<u8>(val);
233 fl::isr::critical_section cs;
234 ch->duty_cycle = duty;
235 ch->high_ticks = (static_cast<u32>(ch->period_ticks) * duty) / 256;
236 return;
237 }
238
239 if (ch && ch->backend == pwm_state::PwmBackend::Native) {
240 // Native backend — forward to platform (frequency already configured)
241 platforms::analogWrite(pin, val);
242 return;
243 }
244
245 // No setPwmFrequency called — forward to platform as before
246 platforms::analogWrite(pin, val);
247}
248
249void setPwm16(int pin, u16 val) {
250 pwm_state::PwmPinState* ch = pwm_state::findByPin(pin);

Callers 1

FL_TEST_FILEFunction · 0.50

Calls 1

findByPinFunction · 0.85

Tested by

no test coverage detected