aboutsummaryrefslogtreecommitdiff
path: root/hwdef-Sofirn_LT1S-Pro.c
diff options
context:
space:
mode:
authorSelene ToyKeeper2023-04-13 20:38:25 -0600
committerSelene ToyKeeper2023-04-13 20:38:25 -0600
commit55541be4a505da3df7d1a2b8bf3b5295b0af58f7 (patch)
treefc1e7f22ffe1c51087117b28766ff266895228e3 /hwdef-Sofirn_LT1S-Pro.c
parentmerging gchart's changes, part 1... (diff)
downloadanduril-55541be4a505da3df7d1a2b8bf3b5295b0af58f7.tar.gz
anduril-55541be4a505da3df7d1a2b8bf3b5295b0af58f7.tar.bz2
anduril-55541be4a505da3df7d1a2b8bf3b5295b0af58f7.zip
refactor progress checkpoint ... got Sofirn LT1S Pro and Emisar D4v2 working
with the new channel mode system ... but there's a lot more left to do
Diffstat (limited to 'hwdef-Sofirn_LT1S-Pro.c')
-rw-r--r--hwdef-Sofirn_LT1S-Pro.c67
1 files changed, 67 insertions, 0 deletions
diff --git a/hwdef-Sofirn_LT1S-Pro.c b/hwdef-Sofirn_LT1S-Pro.c
new file mode 100644
index 0000000..3c31c96
--- /dev/null
+++ b/hwdef-Sofirn_LT1S-Pro.c
@@ -0,0 +1,67 @@
+// BLF LT1S Pro hwdef functions
+// Copyright (C) 2023 Selene ToyKeeper
+// SPDX-License-Identifier: GPL-3.0-or-later
+
+#pragma once
+
+
+// "auto tint" channel mode
+void set_level_auto_3ch_blend(uint8_t level) {
+ BLEND_PWM_DATATYPE vpwm;
+
+ if (level == 0) {
+ vpwm = 0;
+ } else {
+ level --; // PWM array index = level - 1
+ vpwm = PWM_GET(blend_pwm_levels, level);
+ }
+
+ // tint goes from 0 (red) to 127 (warm white) to 255 (cool white)
+ uint8_t mytint;
+ mytint = 255 * (uint16_t)level / RAMP_SIZE;
+
+ BLEND_PWM_DATATYPE a, b, c;
+
+ // red is high at 0, low at 255
+ a = (((PWM_DATATYPE2)(255 - mytint)
+ * (PWM_DATATYPE2)vpwm) + 127) / 255;
+ // warm white is low at 0 and 255, high at 127
+ b = (((PWM_DATATYPE2)triangle_wave(mytint)
+ * (PWM_DATATYPE2)vpwm) + 127) / 255;
+ // cool white is low at 0, high at 255
+ c = (((PWM_DATATYPE2)mytint
+ * (PWM_DATATYPE2)vpwm) + 127) / 255;
+
+ RED_PWM_LVL = a;
+ WARM_PWM_LVL = b;
+ COOL_PWM_LVL = c;
+}
+
+
+// "white + red" channel mode
+void set_level_red_white_blend(uint8_t level) {
+ // set the warm+cool white LEDs first
+ channel_mode = CM_WHITE;
+ set_level_2ch_blend(level);
+ channel_mode = CM_WHITE_RED;
+
+ BLEND_PWM_DATATYPE vpwm;
+
+ // set the red LED as a ratio of the white output level
+ if (level == 0) {
+ vpwm = 0;
+ } else {
+ level --; // PWM array index = level - 1
+ vpwm = PWM_GET(blend_pwm_levels, level);
+ }
+
+ // 0 = no red
+ // 255 = red at 100% of white channel PWM
+ uint8_t ratio = channel_mode_args[channel_mode];
+
+ PWM_DATATYPE red_pwm;
+ red_pwm = (((PWM_DATATYPE2)ratio * (PWM_DATATYPE2)vpwm) + 127) / 255;
+
+ RED_PWM_LVL = red_pwm;
+}
+