aboutsummaryrefslogtreecommitdiff
path: root/spaghetti-monster
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--spaghetti-monster/anduril/cfg-noctigon-k9.3.c79
-rw-r--r--spaghetti-monster/anduril/cfg-noctigon-k9.3.h8
-rw-r--r--spaghetti-monster/anduril/misc.c5
-rw-r--r--spaghetti-monster/fsm-ramping.c4
4 files changed, 87 insertions, 9 deletions
diff --git a/spaghetti-monster/anduril/cfg-noctigon-k9.3.c b/spaghetti-monster/anduril/cfg-noctigon-k9.3.c
index 5e3350a..5cb027a 100644
--- a/spaghetti-monster/anduril/cfg-noctigon-k9.3.c
+++ b/spaghetti-monster/anduril/cfg-noctigon-k9.3.c
@@ -1,13 +1,28 @@
-#ifdef USE_SET_LEVEL_GRADUALLY
+/*
+ * K9.3 has unusual power channels, so it must override some of FSM's code.
+ * There are two sets of LEDs:
+ * 1. Main LEDs: (9 x white LEDs)
+ * PWM1 (10-bit, linear)
+ * PWM2 (8-bit, FET, only used on some K9.3 models)
+ * 2. 2nd LEDs: (3 x white or color LEDs)
+ * PWM3 (10-bit, linear)
+ *
+ * The two sets are not used at the same time... just one or the other,
+ * depending on the "tint" variable. (0 = main LEDs, other value = 2nd LEDs)
+ */
+// if the gradual adjustment mechanism doesn't work, disable it here:
+//#ifdef USE_SET_LEVEL_GRADUALLY
//#undef USE_SET_LEVEL_GRADUALLY
-#endif
+//#endif
+// this is inserted into fsm-ramping.c :: set_level()
+// (it overrides part of the function, but not all of it)
inline void set_level_override(uint8_t level) {
- if (level == 0) {
+ if (level == 0) { // off
PWM1_LVL = 0;
PWM2_LVL = 0;
PWM3_LVL = 0;
- // disable the power channel
+ // disable both power channels
LED_ENABLE_PORT &= ~(1 << LED_ENABLE_PIN);
LED2_ENABLE_PORT &= ~(1 << LED2_ENABLE_PIN);
} else {
@@ -20,7 +35,9 @@ inline void set_level_override(uint8_t level) {
LED2_ENABLE_PORT &= ~(1 << LED2_ENABLE_PIN);
// set levels
PWM1_LVL = PWM_GET(pwm1_levels, level);
- PWM2_LVL = (uint8_t)(PWM_GET(pwm2_levels, level) >> 2);
+ #ifndef K93_NO_FET
+ PWM2_LVL = (uint8_t)(PWM_GET(pwm2_levels, level) >> 2); // 8 bits
+ #endif
PWM3_LVL = 0;
} else { // 2nd LEDs
// disable other power channel
@@ -34,3 +51,55 @@ inline void set_level_override(uint8_t level) {
}
}
}
+
+// override fsm-ramping.c :: gradual_tick()
+// (because the power handling on this light is weird)
+// call this every frame or every few frames to change brightness very smoothly
+void gradual_tick() {
+ // go by only one ramp level at a time instead of directly to the target
+ uint8_t gt = gradual_target;
+ if (gt < actual_level) gt = actual_level - 1;
+ else if (gt > actual_level) gt = actual_level + 1;
+
+ gt --; // convert 1-based number to 0-based
+
+ PWM_DATATYPE target;
+
+ if (! tint) { // main LED channel
+ target = PWM_GET(pwm1_levels, gt);
+ if ((gt < actual_level) // special case for FET-only turbo
+ && (PWM1_LVL == 0) // (bypass adjustment period for first step)
+ && (target == PWM_TOP)) PWM1_LVL = PWM_TOP;
+ else if (PWM1_LVL < target) PWM1_LVL ++;
+ else if (PWM1_LVL > target) PWM1_LVL --;
+
+ #ifndef K93_NO_FET // skip this on E21A model
+ target = PWM_GET(pwm2_levels, gt) >> 2; // 8 bits, not 10
+ if (PWM2_LVL < target) PWM2_LVL ++;
+ else if (PWM2_LVL > target) PWM2_LVL --;
+ #endif
+
+ // did we go far enough to hit the next defined ramp level?
+ // if so, update the main ramp level tracking var
+ if ((PWM1_LVL == PWM_GET(pwm1_levels, gt))
+ #ifndef K93_NO_FET
+ && (PWM2_LVL == (PWM_GET(pwm2_levels, gt) >> 2))
+ #endif
+ )
+ { actual_level = gt + 1; }
+ } else { // 2nd LED channel
+ target = PWM_GET(pwm3_levels, gt);
+ if (PWM3_LVL < target) PWM3_LVL ++;
+ else if (PWM3_LVL > target) PWM3_LVL --;
+
+ // did we go far enough to hit the next defined ramp level?
+ // if so, update the main ramp level tracking var
+ if ( PWM3_LVL == PWM_GET(pwm3_levels, gt) )
+ { actual_level = gt + 1; }
+ }
+
+ #ifdef USE_DYNAMIC_UNDERCLOCKING
+ auto_clock_speed();
+ #endif
+}
+
diff --git a/spaghetti-monster/anduril/cfg-noctigon-k9.3.h b/spaghetti-monster/anduril/cfg-noctigon-k9.3.h
index 123dabe..e4524ec 100644
--- a/spaghetti-monster/anduril/cfg-noctigon-k9.3.h
+++ b/spaghetti-monster/anduril/cfg-noctigon-k9.3.h
@@ -5,6 +5,7 @@
// this model requires some special code
#define OVERRIDES_FILE cfg-noctigon-k9.3.c
#define OVERRIDE_SET_LEVEL
+#define OVERRIDE_GRADUAL_TICK
inline void set_level_override(uint8_t level);
@@ -66,9 +67,12 @@ inline void set_level_override(uint8_t level);
//#define THERM_NEXT_WARNING_THRESHOLD 16 // accumulate less error before adjusting
//#define THERM_RESPONSE_MAGNITUDE 128 // bigger adjustments
+// use the brightest setting for strobe
+#define STROBE_BRIGHTNESS MAX_LEVEL
// slow down party strobe; this driver can't pulse for 1ms or less
-// (only needed on no-FET build)
-//#define PARTY_STROBE_ONTIME 2
+#define PARTY_STROBE_ONTIME 2
+
+#define BLINK_ONCE_TIME 12 // longer blink, since main LEDs are slow
#define THERM_CAL_OFFSET 5
diff --git a/spaghetti-monster/anduril/misc.c b/spaghetti-monster/anduril/misc.c
index 63b8f48..523bbf0 100644
--- a/spaghetti-monster/anduril/misc.c
+++ b/spaghetti-monster/anduril/misc.c
@@ -38,13 +38,16 @@ void blink_confirm(uint8_t num) {
// make a short, visible pulse
// (either brighter or darker, depending on current brightness)
+#ifndef BLINK_ONCE_TIME
+#define BLINK_ONCE_TIME 10
+#endif
void blink_once() {
uint8_t brightness = actual_level;
uint8_t bump = brightness + (MAX_LEVEL/6);
if (bump > MAX_LEVEL) bump = 0;
set_level(bump);
- delay_4ms(10/4);
+ delay_4ms(BLINK_ONCE_TIME/4);
set_level(brightness);
}
diff --git a/spaghetti-monster/fsm-ramping.c b/spaghetti-monster/fsm-ramping.c
index 16bffe3..f092204 100644
--- a/spaghetti-monster/fsm-ramping.c
+++ b/spaghetti-monster/fsm-ramping.c
@@ -154,6 +154,7 @@ inline void set_level_gradually(uint8_t lvl) {
gradual_target = lvl;
}
+#ifndef OVERRIDE_GRADUAL_TICK
// call this every frame or every few frames to change brightness very smoothly
void gradual_tick() {
// go by only one ramp level at a time instead of directly to the target
@@ -209,7 +210,8 @@ void gradual_tick() {
auto_clock_speed();
#endif
}
-#endif
+#endif // ifdef OVERRIDE_GRADUAL_TICK
+#endif // ifdef USE_SET_LEVEL_GRADUALLY
#endif // ifdef USE_RAMPING
#endif