aboutsummaryrefslogtreecommitdiff
path: root/hwdef-emisar-d4v2.c
diff options
context:
space:
mode:
authorSelene ToyKeeper2023-04-28 03:06:22 -0600
committerSelene ToyKeeper2023-04-28 03:06:22 -0600
commitbecb1525aadc1039a99ecdc6f7ae5cf3a1beb2fb (patch)
treec016f1674e11d4c1f5d6e665b550307375079d51 /hwdef-emisar-d4v2.c
parentRGB aux: always preview in high mode, and show voltage during 3-second post-o... (diff)
downloadanduril-becb1525aadc1039a99ecdc6f7ae5cf3a1beb2fb.tar.gz
anduril-becb1525aadc1039a99ecdc6f7ae5cf3a1beb2fb.tar.bz2
anduril-becb1525aadc1039a99ecdc6f7ae5cf3a1beb2fb.zip
D4v2 FET+1 model: works again, and now uses dynamic PWM (lower lows)
(also added generic channel modes for RGB aux LEDs)
Diffstat (limited to '')
-rw-r--r--hwdef-emisar-d4v2.c45
1 files changed, 45 insertions, 0 deletions
diff --git a/hwdef-emisar-d4v2.c b/hwdef-emisar-d4v2.c
new file mode 100644
index 0000000..dce6c92
--- /dev/null
+++ b/hwdef-emisar-d4v2.c
@@ -0,0 +1,45 @@
+// Emisar D4v2 PWM helper functions
+// Copyright (C) 2017-2023 Selene ToyKeeper
+// SPDX-License-Identifier: GPL-3.0-or-later
+
+#pragma once
+
+#include "chan-rgbaux.c"
+
+// single set of LEDs with 2 stacked power channels, DDFET+1 or DDFET+linear
+void set_level_stacked(uint8_t level) {
+ if (level == 0) {
+ LOW_PWM_LVL = 0;
+ HIGH_PWM_LVL = 0;
+ PWM_CNT = 0; // reset phase
+ } else {
+ level --; // PWM array index = level - 1
+ LOW_PWM_LVL = PWM_GET(pwm1_levels, level);
+ HIGH_PWM_LVL = PWM_GET(pwm2_levels, level);
+ // pulse frequency modulation, a.k.a. dynamic PWM
+ uint16_t top = PWM_GET(pwm_tops, level);
+ // wait to sync the counter and avoid flashes
+ while(actual_level && (PWM_CNT > (top - 32))) {}
+ PWM_TOP = top;
+ // force reset phase when turning on from zero
+ // (because otherwise the initial response is inconsistent)
+ if (! actual_level) PWM_CNT = 0;
+ }
+}
+
+bool gradual_tick_stacked(uint8_t gt) {
+ GRADUAL_TICK_SETUP();
+
+ GRADUAL_ADJUST(pwm1_levels, LOW_PWM_LVL, PWM_TOP_INIT);
+ GRADUAL_ADJUST_1CH(pwm2_levels, HIGH_PWM_LVL);
+
+ // did we go far enough to hit the next defined ramp level?
+ // if so, update the main ramp level tracking var
+ if ( (LOW_PWM_LVL == PWM_GET(pwm1_levels, gt))
+ && (HIGH_PWM_LVL == PWM_GET(pwm2_levels, gt))
+ ) {
+ return true;
+ }
+ return false;
+}
+