From fb146684fa9e7b960de0c52d55fc3e04d71ee13c Mon Sep 17 00:00:00 2001 From: Selene ToyKeeper Date: Mon, 3 Jul 2023 02:54:09 -0600 Subject: added Noctigon M44 sources (oops, forgot to do this earlier) (files are dated 2023-05-30) --- hwdef-noctigon-m44.c | 165 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 165 insertions(+) create mode 100644 hwdef-noctigon-m44.c (limited to 'hwdef-noctigon-m44.c') diff --git a/hwdef-noctigon-m44.c b/hwdef-noctigon-m44.c new file mode 100644 index 0000000..482ef05 --- /dev/null +++ b/hwdef-noctigon-m44.c @@ -0,0 +1,165 @@ +// hwdef for Noctigon M44 2-channel light +// Copyright (C) 2023 Selene ToyKeeper +// SPDX-License-Identifier: GPL-3.0-or-later +#pragma once + +// set new values for both channels, +// handling any possible combination +// and any before/after state +void set_pwms(uint16_t ch1_pwm, uint16_t ch2_pwm, uint16_t top) { + bool was_on = (CH1_PWM>0) | (CH2_PWM>0); + bool now_on = (ch1_pwm>0) | (ch2_pwm>0); + + if (! now_on) { + CH1_PWM = 0; + CH2_PWM = 0; + PWM_TOP = PWM_TOP_INIT; + PWM_CNT = 0; + CH1_ENABLE_PORT &= ~(1 << CH1_ENABLE_PIN); // disable opamp + CH2_ENABLE_PORT &= ~(1 << CH2_ENABLE_PIN); // disable opamp + return; + } + + if (ch1_pwm) + CH1_ENABLE_PORT |= (1 << CH1_ENABLE_PIN); // enable opamp + else + CH1_ENABLE_PORT &= ~(1 << CH1_ENABLE_PIN); // disable opamp + + if (ch2_pwm) + CH2_ENABLE_PORT |= (1 << CH2_ENABLE_PIN); // enable opamp + else + CH2_ENABLE_PORT &= ~(1 << CH2_ENABLE_PIN); // disable opamp + + CH1_PWM = ch1_pwm; + CH2_PWM = ch2_pwm; + + // manual phase sync when changing level while already on + if (was_on && now_on) while(PWM_CNT > (top - 32)) {} + + PWM_TOP = top; + + // reset phase when turning on or off + //if ((! was_on) | (! now_on)) PWM_CNT = 0; + if (! was_on) PWM_CNT = 0; +} + +void set_level_ch1(uint8_t level) { + if (0 == level) + return set_pwms(0, 0, PWM_TOP_INIT); + + level --; + uint16_t pwm = PWM_GET(pwm1_levels, level); + uint16_t top = PWM_GET(pwm_tops, level); + set_pwms(pwm, 0, top); +} + +void set_level_ch2(uint8_t level) { + if (0 == level) + return set_pwms(0, 0, PWM_TOP_INIT); + + level --; + uint16_t pwm = PWM_GET(pwm1_levels, level); + uint16_t top = PWM_GET(pwm_tops, level); + set_pwms(0, pwm, top); +} + +void set_level_both(uint8_t level) { + if (0 == level) + return set_pwms(0, 0, PWM_TOP_INIT); + + level --; + uint16_t pwm = PWM_GET(pwm1_levels, level); + uint16_t top = PWM_GET(pwm_tops, level); + set_pwms(pwm, pwm, top); +} + +void set_level_blend(uint8_t level) { + if (0 == level) + return set_pwms(0, 0, PWM_TOP_INIT); + + level --; + PWM_DATATYPE ch1_pwm, ch2_pwm; + PWM_DATATYPE brightness = PWM_GET(pwm1_levels, level); + PWM_DATATYPE top = PWM_GET(pwm_tops, level); + uint8_t blend = cfg.channel_mode_args[cfg.channel_mode]; + + calc_2ch_blend(&ch1_pwm, &ch2_pwm, brightness, top, blend); + + // don't turn off either emitter entirely while using middle blends + if ((0 == ch1_pwm) && (blend < 255)) ch1_pwm = 1; + if ((0 == ch2_pwm) && (blend > 0)) ch2_pwm = 1; + + set_pwms(ch1_pwm, ch2_pwm, top); +} + +void set_level_auto(uint8_t level) { + if (0 == level) + return set_pwms(0, 0, PWM_TOP_INIT); + + level --; + PWM_DATATYPE ch1_pwm, ch2_pwm; + PWM_DATATYPE brightness = PWM_GET(pwm1_levels, level); + PWM_DATATYPE top = PWM_GET(pwm_tops, level); + uint8_t blend = 255 * (uint16_t)level / RAMP_SIZE; + if (cfg.channel_mode_args[cfg.channel_mode] & 0b01000000) + blend = 255 - blend; + + calc_2ch_blend(&ch1_pwm, &ch2_pwm, brightness, top, blend); + + set_pwms(ch1_pwm, ch2_pwm, top); +} + + +///// bump each channel toward a target value ///// +bool gradual_adjust(uint16_t ch1_pwm, uint16_t ch2_pwm) { + GRADUAL_ADJUST_SIMPLE(ch1_pwm, CH1_PWM); + GRADUAL_ADJUST_SIMPLE(ch2_pwm, CH2_PWM); + + // check for completion + if ((ch1_pwm == CH1_PWM) + && (ch2_pwm == CH2_PWM)) { + return true; // done + } + return false; // not done yet +} + +bool gradual_tick_ch1(uint8_t gt) { + uint16_t pwm = PWM_GET(pwm1_levels, gt); + return gradual_adjust(pwm, 0); +} + +bool gradual_tick_ch2(uint8_t gt) { + uint16_t pwm = PWM_GET(pwm1_levels, gt); + return gradual_adjust(0, pwm); +} + +bool gradual_tick_both(uint8_t gt) { + uint16_t pwm = PWM_GET(pwm1_levels, gt); + return gradual_adjust(pwm, pwm); +} + +bool gradual_tick_blend(uint8_t gt) { + PWM_DATATYPE ch1_pwm, ch2_pwm; + PWM_DATATYPE brightness = PWM_GET(pwm1_levels, gt); + PWM_DATATYPE top = PWM_GET(pwm_tops, gt); + uint8_t blend = cfg.channel_mode_args[cfg.channel_mode]; + + calc_2ch_blend(&ch1_pwm, &ch2_pwm, brightness, top, blend); + + return gradual_adjust(ch1_pwm, ch2_pwm); +} + +bool gradual_tick_auto(uint8_t gt) { + PWM_DATATYPE ch1_pwm, ch2_pwm; + PWM_DATATYPE brightness = PWM_GET(pwm1_levels, gt); + PWM_DATATYPE top = PWM_GET(pwm_tops, gt); + uint8_t blend = 255 * (uint16_t)gt / RAMP_SIZE; + if (cfg.channel_mode_args[cfg.channel_mode] & 0b01000000) + blend = 255 - blend; + + calc_2ch_blend(&ch1_pwm, &ch2_pwm, brightness, top, blend); + + return gradual_adjust(ch1_pwm, ch2_pwm); +} + + -- cgit v1.2.3 From 723b5b1ffa8f12b29110a2133a8f09beaf528aad Mon Sep 17 00:00:00 2001 From: Selene ToyKeeper Date: Sun, 16 Jul 2023 16:27:44 -0600 Subject: fixed d4v2, kr4, m44, emisar-2ch (using new refactor), added RGB aux channel modes to models which didn't have it --- hwdef-noctigon-m44.c | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) (limited to 'hwdef-noctigon-m44.c') diff --git a/hwdef-noctigon-m44.c b/hwdef-noctigon-m44.c index 482ef05..3fc6abe 100644 --- a/hwdef-noctigon-m44.c +++ b/hwdef-noctigon-m44.c @@ -1,8 +1,55 @@ // hwdef for Noctigon M44 2-channel light // Copyright (C) 2023 Selene ToyKeeper // SPDX-License-Identifier: GPL-3.0-or-later + #pragma once +#include "chan-rgbaux.c" + + +void set_level_ch1(uint8_t level); +void set_level_ch2(uint8_t level); +void set_level_both(uint8_t level); +void set_level_blend(uint8_t level); +void set_level_auto(uint8_t level); + +bool gradual_tick_ch1(uint8_t gt); +bool gradual_tick_ch2(uint8_t gt); +bool gradual_tick_both(uint8_t gt); +bool gradual_tick_blend(uint8_t gt); +bool gradual_tick_auto(uint8_t gt); + + +Channel channels[] = { + { // channel 1 only + .set_level = set_level_ch1, + .gradual_tick = gradual_tick_ch1, + .has_args = 0 + }, + { // channel 2 only + .set_level = set_level_ch2, + .gradual_tick = gradual_tick_ch2, + .has_args = 0 + }, + { // both channels, tied together (max "200%" power) + .set_level = set_level_both, + .gradual_tick = gradual_tick_both, + .has_args = 0 + }, + { // both channels, manual blend (max "100%" power) + .set_level = set_level_blend, + .gradual_tick = gradual_tick_blend, + .has_args = 1 + }, + { // both channels, auto blend + .set_level = set_level_auto, + .gradual_tick = gradual_tick_auto, + .has_args = 1 + }, + RGB_AUX_CHANNELS +}; + + // set new values for both channels, // handling any possible combination // and any before/after state -- cgit v1.2.3 From 04a48e44b25d1c42dc26f837586a7503bb74b749 Mon Sep 17 00:00:00 2001 From: Selene ToyKeeper Date: Thu, 24 Aug 2023 17:08:01 -0600 Subject: added channel mode per strobe mode, and made FSM channel mode more flexible, and fixed issue in tactical mode where strobes wouldn't stop on button release --- hwdef-noctigon-m44.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'hwdef-noctigon-m44.c') diff --git a/hwdef-noctigon-m44.c b/hwdef-noctigon-m44.c index 3fc6abe..0c73005 100644 --- a/hwdef-noctigon-m44.c +++ b/hwdef-noctigon-m44.c @@ -128,7 +128,7 @@ void set_level_blend(uint8_t level) { PWM_DATATYPE ch1_pwm, ch2_pwm; PWM_DATATYPE brightness = PWM_GET(pwm1_levels, level); PWM_DATATYPE top = PWM_GET(pwm_tops, level); - uint8_t blend = cfg.channel_mode_args[cfg.channel_mode]; + uint8_t blend = cfg.channel_mode_args[channel_mode]; calc_2ch_blend(&ch1_pwm, &ch2_pwm, brightness, top, blend); @@ -148,7 +148,7 @@ void set_level_auto(uint8_t level) { PWM_DATATYPE brightness = PWM_GET(pwm1_levels, level); PWM_DATATYPE top = PWM_GET(pwm_tops, level); uint8_t blend = 255 * (uint16_t)level / RAMP_SIZE; - if (cfg.channel_mode_args[cfg.channel_mode] & 0b01000000) + if (cfg.channel_mode_args[channel_mode] & 0b01000000) blend = 255 - blend; calc_2ch_blend(&ch1_pwm, &ch2_pwm, brightness, top, blend); @@ -189,7 +189,7 @@ bool gradual_tick_blend(uint8_t gt) { PWM_DATATYPE ch1_pwm, ch2_pwm; PWM_DATATYPE brightness = PWM_GET(pwm1_levels, gt); PWM_DATATYPE top = PWM_GET(pwm_tops, gt); - uint8_t blend = cfg.channel_mode_args[cfg.channel_mode]; + uint8_t blend = cfg.channel_mode_args[channel_mode]; calc_2ch_blend(&ch1_pwm, &ch2_pwm, brightness, top, blend); @@ -201,7 +201,7 @@ bool gradual_tick_auto(uint8_t gt) { PWM_DATATYPE brightness = PWM_GET(pwm1_levels, gt); PWM_DATATYPE top = PWM_GET(pwm_tops, gt); uint8_t blend = 255 * (uint16_t)gt / RAMP_SIZE; - if (cfg.channel_mode_args[cfg.channel_mode] & 0b01000000) + if (cfg.channel_mode_args[channel_mode] & 0b01000000) blend = 255 - blend; calc_2ch_blend(&ch1_pwm, &ch2_pwm, brightness, top, blend); -- cgit v1.2.3 From 013174374f87a2c3f9a3427cc63f7211f5bf7fd5 Mon Sep 17 00:00:00 2001 From: Selene ToyKeeper Date: Sun, 17 Sep 2023 06:31:55 -0600 Subject: converted noctigon-m44 build, and greatly reduced flicker with a new ramp and some new hwdef algorithms --- hwdef-noctigon-m44.c | 84 +++++++++++++++++++++++++--------------------------- 1 file changed, 41 insertions(+), 43 deletions(-) (limited to 'hwdef-noctigon-m44.c') diff --git a/hwdef-noctigon-m44.c b/hwdef-noctigon-m44.c index 0c73005..776cb82 100644 --- a/hwdef-noctigon-m44.c +++ b/hwdef-noctigon-m44.c @@ -7,6 +7,8 @@ #include "chan-rgbaux.c" +void set_level_zero(); + void set_level_ch1(uint8_t level); void set_level_ch2(uint8_t level); void set_level_both(uint8_t level); @@ -53,26 +55,33 @@ Channel channels[] = { // set new values for both channels, // handling any possible combination // and any before/after state -void set_pwms(uint16_t ch1_pwm, uint16_t ch2_pwm, uint16_t top) { - bool was_on = (CH1_PWM>0) | (CH2_PWM>0); - bool now_on = (ch1_pwm>0) | (ch2_pwm>0); - - if (! now_on) { - CH1_PWM = 0; - CH2_PWM = 0; - PWM_TOP = PWM_TOP_INIT; - PWM_CNT = 0; - CH1_ENABLE_PORT &= ~(1 << CH1_ENABLE_PIN); // disable opamp - CH2_ENABLE_PORT &= ~(1 << CH2_ENABLE_PIN); // disable opamp - return; - } +void set_pwms(uint16_t ch1_pwm, uint16_t ch2_pwm, uint16_t top, + uint8_t ch1_on, uint8_t ch2_on) { + + bool was_on = (CH1_PWM>0) || (CH2_PWM>0) + || ( CH1_ENABLE_PORT & (1 << CH1_ENABLE_PIN) ) + || ( CH2_ENABLE_PORT & (1 << CH2_ENABLE_PIN) ); + bool now_on = (ch1_pwm>0) || (ch2_pwm>0) || ch1_on || ch2_on; + + // phase-correct PWM at zero (for flicker-free moon), + // fast PWM otherwise + if (ch1_pwm || ch2_pwm) + TCCR1B = (0< 0)) ch2_pwm = 1; - - set_pwms(ch1_pwm, ch2_pwm, top); + set_pwms(ch1_pwm, ch2_pwm, top, + blend < 255, blend > 0); } void set_level_auto(uint8_t level) { - if (0 == level) - return set_pwms(0, 0, PWM_TOP_INIT); - - level --; PWM_DATATYPE ch1_pwm, ch2_pwm; PWM_DATATYPE brightness = PWM_GET(pwm1_levels, level); PWM_DATATYPE top = PWM_GET(pwm_tops, level); @@ -153,7 +149,9 @@ void set_level_auto(uint8_t level) { calc_2ch_blend(&ch1_pwm, &ch2_pwm, brightness, top, blend); - set_pwms(ch1_pwm, ch2_pwm, top); + // don't turn off either emitter entirely + // (it blinks pretty bright when the regulator turns on mid-ramp) + set_pwms(ch1_pwm, ch2_pwm, top, 1, 1); } -- cgit v1.2.3 From 1ac0da62f1b582a2b62d07c164acc983a5c0b004 Mon Sep 17 00:00:00 2001 From: Selene ToyKeeper Date: Fri, 27 Oct 2023 05:48:14 -0600 Subject: converted noctigon-m44 to use PWM+DSM instead of PWM+PFM (dynamic PWM) (this gives better, smoother low modes and reduced flicker) --- hwdef-noctigon-m44.c | 190 ++++++++++++++++++++++++++++++++------------------- 1 file changed, 121 insertions(+), 69 deletions(-) (limited to 'hwdef-noctigon-m44.c') diff --git a/hwdef-noctigon-m44.c b/hwdef-noctigon-m44.c index 776cb82..0b7f027 100644 --- a/hwdef-noctigon-m44.c +++ b/hwdef-noctigon-m44.c @@ -1,7 +1,6 @@ // hwdef for Noctigon M44 2-channel light // Copyright (C) 2023 Selene ToyKeeper // SPDX-License-Identifier: GPL-3.0-or-later - #pragma once #include "chan-rgbaux.c" @@ -52,20 +51,39 @@ Channel channels[] = { }; +void set_level_zero() { + // disable timer 1 overflow interrupt + // (helps improve button press handling from Off state) + TIMSK &= ~(1 << TOIE1); + + // turn off all LEDs + ch1_dsm_lvl = 0; + ch2_dsm_lvl = 0; + CH1_PWM = 0; + CH2_PWM = 0; + PWM_CNT = 0; + CH1_ENABLE_PORT &= ~(1 << CH1_ENABLE_PIN); // disable opamp + CH2_ENABLE_PORT &= ~(1 << CH2_ENABLE_PIN); // disable opamp +} + + +// wrap setting the dsm vars, to get a faster response +// (just setting *_dsm_lvl doesn't work well for strobes) // set new values for both channels, // handling any possible combination // and any before/after state -void set_pwms(uint16_t ch1_pwm, uint16_t ch2_pwm, uint16_t top, - uint8_t ch1_on, uint8_t ch2_on) { +void set_hw_levels(PWM_DATATYPE ch1, PWM_DATATYPE ch2, + bool ch1_on, bool ch2_on) { bool was_on = (CH1_PWM>0) || (CH2_PWM>0) || ( CH1_ENABLE_PORT & (1 << CH1_ENABLE_PIN) ) || ( CH2_ENABLE_PORT & (1 << CH2_ENABLE_PIN) ); - bool now_on = (ch1_pwm>0) || (ch2_pwm>0) || ch1_on || ch2_on; + //bool now_on = (ch1>0) || (ch2>0) || ch1_on || ch2_on; + #if 0 // not needed any more, after switching to PWM+DSM // phase-correct PWM at zero (for flicker-free moon), // fast PWM otherwise - if (ch1_pwm || ch2_pwm) + if (ch1 || ch2) TCCR1B = (0<> 7; + CH2_PWM = ch2_pwm = ch2 >> 7; + + #if 0 // not needed any more, after switching to PWM+DSM // manual phase sync when changing level while already on if (was_on && now_on) while(PWM_CNT > (top - 32)) {} PWM_TOP = top; + #endif + + // enable timer 1 overflow interrupt so DSM can work + TIMSK |= (1 << TOIE1); // reset phase when turning on or off //if ((! was_on) | (! now_on)) PWM_CNT = 0; if (! was_on) PWM_CNT = 0; + } -void set_level_zero() { - CH1_PWM = 0; - CH2_PWM = 0; - PWM_TOP = PWM_TOP_INIT; - PWM_CNT = 0; - CH1_ENABLE_PORT &= ~(1 << CH1_ENABLE_PIN); // disable opamp - CH2_ENABLE_PORT &= ~(1 << CH2_ENABLE_PIN); // disable opamp +// delta-sigma modulation of PWM outputs +// happens on each Timer0 overflow (every 512 cpu clock cycles) +// uses 8-bit pwm w/ 7-bit dsm (0b 0PPP PPPP PDDD DDDD) +ISR(TIMER1_OVF_vect) { + // set new hardware values first, + // for best timing (reduce effect of interrupt jitter) + CH1_PWM = ch1_pwm; + CH2_PWM = ch2_pwm; + + // calculate next values, now that timing matters less + + // accumulate error + ch1_dsm += (ch1_dsm_lvl & 0x007f); + // next PWM = base PWM value + carry bit + ch1_pwm = (ch1_dsm_lvl >> 7) + (ch1_dsm > 0x7f); + // clear carry bit + ch1_dsm &= 0x7f; + + // repeat for other channels + + ch2_dsm += (ch2_dsm_lvl & 0x007f); + ch2_pwm = (ch2_dsm_lvl >> 7) + (ch2_dsm > 0x7f); + ch2_dsm &= 0x7f; } + void set_level_ch1(uint8_t level) { - uint16_t pwm = PWM_GET(pwm1_levels, level); - uint16_t top = PWM_GET(pwm_tops, level); - set_pwms(pwm, 0, top, 1, 0); + PWM_DATATYPE pwm = PWM_GET(pwm1_levels, level); + set_hw_levels(pwm, 0, + 1, 0); } void set_level_ch2(uint8_t level) { - uint16_t pwm = PWM_GET(pwm1_levels, level); - uint16_t top = PWM_GET(pwm_tops, level); - set_pwms(0, pwm, top, 0, 1); + PWM_DATATYPE pwm = PWM_GET(pwm1_levels, level); + set_hw_levels(0, pwm, + 0, 1); } void set_level_both(uint8_t level) { - uint16_t pwm = PWM_GET(pwm1_levels, level); - uint16_t top = PWM_GET(pwm_tops, level); - set_pwms(pwm, pwm, top, 1, 1); + PWM_DATATYPE pwm = PWM_GET(pwm1_levels, level); + set_hw_levels(pwm, pwm, + 1, 1); } -void set_level_blend(uint8_t level) { - PWM_DATATYPE ch1_pwm, ch2_pwm; +void blend_helper(PWM_DATATYPE *warm, PWM_DATATYPE *cool, uint8_t level) { PWM_DATATYPE brightness = PWM_GET(pwm1_levels, level); - PWM_DATATYPE top = PWM_GET(pwm_tops, level); - uint8_t blend = cfg.channel_mode_args[channel_mode]; + uint8_t blend; + if (channel_mode == CM_AUTO) { + blend = 255 * (uint16_t)level / RAMP_SIZE; + if (cfg.channel_mode_args[channel_mode] & 0b01000000) + blend = 255 - blend; + } else { + blend = cfg.channel_mode_args[channel_mode]; + } - calc_2ch_blend(&ch1_pwm, &ch2_pwm, brightness, top, blend); + calc_2ch_blend(warm, cool, brightness, DSM_TOP, blend); +} +void set_level_blend(uint8_t level) { + PWM_DATATYPE warm, cool; + uint8_t blend = cfg.channel_mode_args[channel_mode]; + blend_helper(&warm, &cool, level); // don't turn off either emitter entirely while using middle blends - set_pwms(ch1_pwm, ch2_pwm, top, - blend < 255, blend > 0); + set_hw_levels(warm, cool, + blend < 255, blend > 0); } void set_level_auto(uint8_t level) { - PWM_DATATYPE ch1_pwm, ch2_pwm; - PWM_DATATYPE brightness = PWM_GET(pwm1_levels, level); - PWM_DATATYPE top = PWM_GET(pwm_tops, level); - uint8_t blend = 255 * (uint16_t)level / RAMP_SIZE; - if (cfg.channel_mode_args[channel_mode] & 0b01000000) - blend = 255 - blend; - - calc_2ch_blend(&ch1_pwm, &ch2_pwm, brightness, top, blend); - + PWM_DATATYPE warm, cool; + blend_helper(&warm, &cool, level); // don't turn off either emitter entirely // (it blinks pretty bright when the regulator turns on mid-ramp) - set_pwms(ch1_pwm, ch2_pwm, top, 1, 1); + set_hw_levels(warm, cool, + 1, 1); } +///// "gradual tick" functions for smooth thermal regulation ///// +// (and other smooth adjustments) ///// bump each channel toward a target value ///// -bool gradual_adjust(uint16_t ch1_pwm, uint16_t ch2_pwm) { - GRADUAL_ADJUST_SIMPLE(ch1_pwm, CH1_PWM); - GRADUAL_ADJUST_SIMPLE(ch2_pwm, CH2_PWM); +bool gradual_adjust(PWM_DATATYPE ch1, PWM_DATATYPE ch2) { + // adjust multiple times based on current brightness + // (so it adjusts faster/coarser when bright, slower/finer when dim) + + // higher shift = slower/finer adjustments + const uint8_t shift = 9; // ((255 << 7) >> 9) = 63 max + uint8_t steps; + + steps = ch1_dsm_lvl >> shift; + for (uint8_t i=0; i<=steps; i++) + GRADUAL_ADJUST_SIMPLE(ch1, ch1_dsm_lvl); + + steps = ch2_dsm_lvl >> shift; + for (uint8_t i=0; i<=steps; i++) + GRADUAL_ADJUST_SIMPLE(ch2, ch2_dsm_lvl); - // check for completion - if ((ch1_pwm == CH1_PWM) - && (ch2_pwm == CH2_PWM)) { + if ((ch1 == ch1_dsm_lvl) + && (ch2 == ch2_dsm_lvl )) { return true; // done } return false; // not done yet } bool gradual_tick_ch1(uint8_t gt) { - uint16_t pwm = PWM_GET(pwm1_levels, gt); + PWM_DATATYPE pwm = PWM_GET(pwm1_levels, gt); return gradual_adjust(pwm, 0); } bool gradual_tick_ch2(uint8_t gt) { - uint16_t pwm = PWM_GET(pwm1_levels, gt); + PWM_DATATYPE pwm = PWM_GET(pwm1_levels, gt); return gradual_adjust(0, pwm); } bool gradual_tick_both(uint8_t gt) { - uint16_t pwm = PWM_GET(pwm1_levels, gt); + PWM_DATATYPE pwm = PWM_GET(pwm1_levels, gt); return gradual_adjust(pwm, pwm); } bool gradual_tick_blend(uint8_t gt) { - PWM_DATATYPE ch1_pwm, ch2_pwm; - PWM_DATATYPE brightness = PWM_GET(pwm1_levels, gt); - PWM_DATATYPE top = PWM_GET(pwm_tops, gt); - uint8_t blend = cfg.channel_mode_args[channel_mode]; - - calc_2ch_blend(&ch1_pwm, &ch2_pwm, brightness, top, blend); - - return gradual_adjust(ch1_pwm, ch2_pwm); + PWM_DATATYPE warm, cool; + blend_helper(&warm, &cool, gt); + return gradual_adjust(warm, cool); } bool gradual_tick_auto(uint8_t gt) { - PWM_DATATYPE ch1_pwm, ch2_pwm; - PWM_DATATYPE brightness = PWM_GET(pwm1_levels, gt); - PWM_DATATYPE top = PWM_GET(pwm_tops, gt); - uint8_t blend = 255 * (uint16_t)gt / RAMP_SIZE; - if (cfg.channel_mode_args[channel_mode] & 0b01000000) - blend = 255 - blend; - - calc_2ch_blend(&ch1_pwm, &ch2_pwm, brightness, top, blend); - - return gradual_adjust(ch1_pwm, ch2_pwm); + PWM_DATATYPE warm, cool; + blend_helper(&warm, &cool, gt); + return gradual_adjust(warm, cool); } -- cgit v1.2.3 From aaa760e5243cf87a43297945b20e41a448c906e4 Mon Sep 17 00:00:00 2001 From: Selene ToyKeeper Date: Sat, 28 Oct 2023 07:02:38 -0600 Subject: switched blf-lt1-t1616 from plain PWM to PWM+DSM (and made DSM interrupt definitions a bit cleaner) --- hwdef-noctigon-m44.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'hwdef-noctigon-m44.c') diff --git a/hwdef-noctigon-m44.c b/hwdef-noctigon-m44.c index 0b7f027..395a7a2 100644 --- a/hwdef-noctigon-m44.c +++ b/hwdef-noctigon-m44.c @@ -52,9 +52,9 @@ Channel channels[] = { void set_level_zero() { - // disable timer 1 overflow interrupt + // disable timer overflow interrupt // (helps improve button press handling from Off state) - TIMSK &= ~(1 << TOIE1); + DSM_INTCTRL &= ~DSM_OVF_bm; // turn off all LEDs ch1_dsm_lvl = 0; @@ -120,19 +120,19 @@ void set_hw_levels(PWM_DATATYPE ch1, PWM_DATATYPE ch2, PWM_TOP = top; #endif - // enable timer 1 overflow interrupt so DSM can work - TIMSK |= (1 << TOIE1); + // enable timer overflow interrupt so DSM can work + DSM_INTCTRL |= DSM_OVF_bm; - // reset phase when turning on or off + // reset phase when turning on //if ((! was_on) | (! now_on)) PWM_CNT = 0; if (! was_on) PWM_CNT = 0; } // delta-sigma modulation of PWM outputs -// happens on each Timer0 overflow (every 512 cpu clock cycles) +// happens on each Timer overflow (every 512 cpu clock cycles) // uses 8-bit pwm w/ 7-bit dsm (0b 0PPP PPPP PDDD DDDD) -ISR(TIMER1_OVF_vect) { +ISR(DSM_vect) { // set new hardware values first, // for best timing (reduce effect of interrupt jitter) CH1_PWM = ch1_pwm; -- cgit v1.2.3