aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSelene ToyKeeper2020-10-14 23:17:27 -0600
committerSelene ToyKeeper2020-10-14 23:17:27 -0600
commitdb1c7ef28405c123faaaadb25c8c9b2edeea0d43 (patch)
tree80d41bd8e68c8d9eccc759ae21ebd3515a570b4d
parentconfigured K9.3 cfg (mostly), assigned a model number, fixed typo in hwdef (diff)
downloadanduril-db1c7ef28405c123faaaadb25c8c9b2edeea0d43.tar.gz
anduril-db1c7ef28405c123faaaadb25c8c9b2edeea0d43.tar.bz2
anduril-db1c7ef28405c123faaaadb25c8c9b2edeea0d43.zip
got K9.3 2nd LEDs working (and modified FSM to allow this sort of thing)
added a way to include per-model code overrides added an override mechanism for logic inside set_level() wrote K9.3's set_level() function added TINT_RAMP_TOGGLE_ONLY mode for tint ramping
-rw-r--r--hwdef-Noctigon_K9.3.h2
-rw-r--r--spaghetti-monster/anduril/anduril.c6
-rw-r--r--spaghetti-monster/anduril/cfg-noctigon-k9.3.c36
-rw-r--r--spaghetti-monster/anduril/cfg-noctigon-k9.3.h11
-rw-r--r--spaghetti-monster/anduril/tint-ramping.c28
-rw-r--r--spaghetti-monster/fsm-ramping.c5
6 files changed, 86 insertions, 2 deletions
diff --git a/hwdef-Noctigon_K9.3.h b/hwdef-Noctigon_K9.3.h
index d48623a..6032b4c 100644
--- a/hwdef-Noctigon_K9.3.h
+++ b/hwdef-Noctigon_K9.3.h
@@ -40,7 +40,7 @@
#define ATTINY 1634
#include <avr/io.h>
-#define PWM_CHANNELS 2 // 3 actually, but only 2 for main LEDs
+#define PWM_CHANNELS 3 // 2 for main LEDs, 1 for 2nd LEDs
#define PWM_BITS 10 // 0 to 1023 at 4 kHz, not 0 to 255 at 16 kHz
#define PWM_TOP 1023
diff --git a/spaghetti-monster/anduril/anduril.c b/spaghetti-monster/anduril/anduril.c
index f632229..549fe46 100644
--- a/spaghetti-monster/anduril/anduril.c
+++ b/spaghetti-monster/anduril/anduril.c
@@ -85,12 +85,16 @@
// (include this one last)
#include "load-save-config-fsm.h"
-
/********* bring in FSM / SpaghettiMonster *********/
#define USE_IDLE_MODE // reduce power use while awake and no tasks are pending
#include "spaghetti-monster.h"
+/********* does this build target have special code to include? *********/
+#ifdef OVERRIDES_FILE
+#include incfile(OVERRIDES_FILE)
+#endif
+
/********* Include all the regular app headers *********/
diff --git a/spaghetti-monster/anduril/cfg-noctigon-k9.3.c b/spaghetti-monster/anduril/cfg-noctigon-k9.3.c
new file mode 100644
index 0000000..5e3350a
--- /dev/null
+++ b/spaghetti-monster/anduril/cfg-noctigon-k9.3.c
@@ -0,0 +1,36 @@
+#ifdef USE_SET_LEVEL_GRADUALLY
+//#undef USE_SET_LEVEL_GRADUALLY
+#endif
+
+inline void set_level_override(uint8_t level) {
+ if (level == 0) {
+ PWM1_LVL = 0;
+ PWM2_LVL = 0;
+ PWM3_LVL = 0;
+ // disable the power channel
+ LED_ENABLE_PORT &= ~(1 << LED_ENABLE_PIN);
+ LED2_ENABLE_PORT &= ~(1 << LED2_ENABLE_PIN);
+ } else {
+ level --;
+
+ if (! tint) { // main LEDs
+ // enable this power channel
+ LED_ENABLE_PORT |= (1 << LED_ENABLE_PIN);
+ // disable other power channel
+ 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);
+ PWM3_LVL = 0;
+ } else { // 2nd LEDs
+ // disable other power channel
+ LED_ENABLE_PORT &= ~(1 << LED_ENABLE_PIN);
+ // enable this power channel
+ LED2_ENABLE_PORT |= (1 << LED2_ENABLE_PIN);
+ // set levels
+ PWM1_LVL = 0;
+ PWM2_LVL = 0;
+ PWM3_LVL = PWM_GET(pwm3_levels, level);
+ }
+ }
+}
diff --git a/spaghetti-monster/anduril/cfg-noctigon-k9.3.h b/spaghetti-monster/anduril/cfg-noctigon-k9.3.h
index 8276ec8..123dabe 100644
--- a/spaghetti-monster/anduril/cfg-noctigon-k9.3.h
+++ b/spaghetti-monster/anduril/cfg-noctigon-k9.3.h
@@ -2,6 +2,11 @@
#define MODEL_NUMBER "0261"
#include "hwdef-Noctigon_K9.3.h"
// ATTINY: 1634
+// this model requires some special code
+#define OVERRIDES_FILE cfg-noctigon-k9.3.c
+#define OVERRIDE_SET_LEVEL
+inline void set_level_override(uint8_t level);
+
// this light has three aux LED channels: R, G, B
#define USE_AUX_RGB_LEDS
@@ -20,6 +25,10 @@
#define TICK_DURING_STANDBY
#define STANDBY_TICK_SPEED 3 // every 0.128 s
+// has two channels of independent LEDs
+#define USE_TINT_RAMPING
+// ... but it doesn't make sense to ramp between; only toggle
+#define TINT_RAMP_TOGGLE_ONLY
// main LEDs
// max regulated: ~1750 lm
@@ -35,6 +44,7 @@
#define PWM3_LEVELS 0,0,1,1,2,2,3,3,4,4,5,5,6,7,8,9,10,11,12,13,15,16,17,18,20,21,23,24,26,27,29,31,33,35,37,39,41,43,45,48,50,53,55,58,61,63,66,69,72,75,79,82,85,89,92,96,100,104,108,112,116,120,125,129,134,138,143,148,153,158,163,169,174,180,185,191,197,203,209,215,222,228,235,242,248,255,263,270,277,285,292,300,308,316,324,333,341,350,359,368,377,386,395,405,414,424,434,444,454,465,475,486,497,508,519,531,542,554,566,578,590,603,615,628,641,654,667,680,694,708,722,736,750,765,779,794,809,825,840,856,872,888,904,920,937,954,971,988,1005,1023
#define DEFAULT_LEVEL 46
#define MAX_1x7135 120
+#define MAX_Nx7135 MAX_1x7135
#define HALFSPEED_LEVEL 10
#define QUARTERSPEED_LEVEL 2
@@ -64,3 +74,4 @@
// for consistency with KR4 (not otherwise necessary though)
#define USE_SOFT_FACTORY_RESET
+
diff --git a/spaghetti-monster/anduril/tint-ramping.c b/spaghetti-monster/anduril/tint-ramping.c
index 0196bc7..0b077ef 100644
--- a/spaghetti-monster/anduril/tint-ramping.c
+++ b/spaghetti-monster/anduril/tint-ramping.c
@@ -22,6 +22,32 @@
#include "tint-ramping.h"
+#ifdef TINT_RAMP_TOGGLE_ONLY
+
+uint8_t tint_ramping_state(Event event, uint16_t arg) {
+ // click, click, hold: change the tint
+ if (event == EV_click3_hold) {
+ // toggle once on first frame; ignore other frames
+ if (! arg) {
+ tint = !tint;
+ set_level(actual_level);
+ blink_once();
+ }
+ return EVENT_HANDLED;
+ }
+
+ // click, click, hold, release: save config
+ else if (event == EV_click3_hold_release) {
+ // remember tint after battery change
+ save_config();
+ return EVENT_HANDLED;
+ }
+
+ return EVENT_NOT_HANDLED;
+}
+
+#else // no TINT_RAMP_TOGGLE_ONLY
+
uint8_t tint_ramping_state(Event event, uint16_t arg) {
static int8_t tint_ramp_direction = 1;
static uint8_t prev_tint = 0;
@@ -82,6 +108,8 @@ uint8_t tint_ramping_state(Event event, uint16_t arg) {
return EVENT_NOT_HANDLED;
}
+#endif // ifdef TINT_RAMP_TOGGLE_ONLY
+
#endif
diff --git a/spaghetti-monster/fsm-ramping.c b/spaghetti-monster/fsm-ramping.c
index 5ea4a47..16bffe3 100644
--- a/spaghetti-monster/fsm-ramping.c
+++ b/spaghetti-monster/fsm-ramping.c
@@ -54,6 +54,10 @@ void set_level(uint8_t level) {
#endif
#endif
+ #ifdef OVERRIDE_SET_LEVEL
+ set_level_override(level);
+ #else
+
//TCCR0A = PHASE;
if (level == 0) {
#if PWM_CHANNELS >= 1
@@ -139,6 +143,7 @@ void set_level(uint8_t level) {
#endif // ifdef USE_TINT_RAMPING
}
+ #endif // ifdef OVERRIDE_SET_LEVEL
#ifdef USE_DYNAMIC_UNDERCLOCKING
auto_clock_speed();
#endif