1
// Emisar D4v2 (no DD FET, 1x7135 only) PWM helper functions
2
// Copyright (C) 2017-2023 Selene ToyKeeper
3
// SPDX-License-Identifier: GPL-3.0-or-later
7
#include "chan-rgbaux.c"
11
void set_level_main(uint8_t level);
12
bool gradual_tick_main(uint8_t gt);
15
Channel channels[] = {
17
.set_level = set_level_main,
18
.gradual_tick = gradual_tick_main
24
void set_level_zero() {
26
PWM_CNT = 0; // reset phase
29
// single set of LEDs with just a 1x7135 chip, max 350 mA or ~130 lm
30
void set_level_main(uint8_t level) {
31
PWM_DATATYPE ch1_pwm = PWM_GET(pwm1_levels, level);
32
// pulse frequency modulation, a.k.a. dynamic PWM
33
uint16_t top = PWM_GET16(pwm_tops, level);
36
// wait to sync the counter and avoid flashes
37
while(actual_level && (PWM_CNT > (top - 32))) {}
39
// force reset phase when turning on from zero
40
// (because otherwise the initial response is inconsistent)
41
if (! actual_level) PWM_CNT = 0;
44
bool gradual_tick_main(uint8_t gt) {
45
PWM_DATATYPE pwm1 = PWM_GET(pwm1_levels, gt);
47
GRADUAL_ADJUST_SIMPLE (pwm1, CH1_PWM);
49
if ( (pwm1 == CH1_PWM)
53
return false; // not done yet