aboutsummaryrefslogtreecommitdiff
path: root/hwdef-noctigon-kr4-nofet.c
diff options
context:
space:
mode:
authorSelene ToyKeeper2023-04-29 02:50:03 -0600
committerSelene ToyKeeper2023-04-29 02:50:03 -0600
commit882567cd08e15d73aee0802fd1b1c31076801a02 (patch)
tree30acf038e041d406da504d7ab713a68561bb062a /hwdef-noctigon-kr4-nofet.c
parentD4v2 can use 8-bit ramp tables too (diff)
downloadanduril-882567cd08e15d73aee0802fd1b1c31076801a02.tar.gz
anduril-882567cd08e15d73aee0802fd1b1c31076801a02.tar.bz2
anduril-882567cd08e15d73aee0802fd1b1c31076801a02.zip
converted KR4-nofet build
Diffstat (limited to 'hwdef-noctigon-kr4-nofet.c')
-rw-r--r--hwdef-noctigon-kr4-nofet.c47
1 files changed, 47 insertions, 0 deletions
diff --git a/hwdef-noctigon-kr4-nofet.c b/hwdef-noctigon-kr4-nofet.c
new file mode 100644
index 0000000..ec984df
--- /dev/null
+++ b/hwdef-noctigon-kr4-nofet.c
@@ -0,0 +1,47 @@
+// Noctigon KR4 (no DD FET) PWM helper functions
+// Copyright (C) 2020-2023 Selene ToyKeeper
+// SPDX-License-Identifier: GPL-3.0-or-later
+
+#pragma once
+
+#include "chan-rgbaux.c"
+
+// single set of LEDs with linear power channel
+void set_level_main(uint8_t level) {
+ if (level == 0) {
+ CH1_PWM = 0;
+ CH2_PWM = 0;
+ PWM_CNT = 0; // reset phase
+ CH1_ENABLE_PORT &= ~(1 << CH1_ENABLE_PIN); // disable opamp
+ return;
+ }
+
+ CH1_ENABLE_PORT |= (1 << CH1_ENABLE_PIN); // enable opamp
+
+ level --; // PWM array index = level - 1
+ PWM_DATATYPE ch1_pwm = PWM_GET(pwm1_levels, level);
+ // pulse frequency modulation, a.k.a. dynamic PWM
+ uint16_t top = PWM_GET16(pwm_tops, level);
+
+ CH1_PWM = ch1_pwm;
+ CH2_PWM = 0;
+ // 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_main(uint8_t gt) {
+ PWM_DATATYPE pwm1 = PWM_GET(pwm1_levels, gt);
+
+ GRADUAL_ADJUST_SIMPLE(pwm1, CH1_PWM);
+
+ if ( (pwm1 == CH1_PWM)
+ ) {
+ return true; // done
+ }
+ return false; // not done yet
+}
+