aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSelene ToyKeeper2023-04-28 03:06:22 -0600
committerSelene ToyKeeper2023-04-28 03:06:22 -0600
commitbecb1525aadc1039a99ecdc6f7ae5cf3a1beb2fb (patch)
treec016f1674e11d4c1f5d6e665b550307375079d51
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)
-rw-r--r--hwdef-emisar-d4v2.c45
-rw-r--r--hwdef-emisar-d4v2.h (renamed from hwdef-Emisar_D4v2.h)90
-rw-r--r--spaghetti-monster/anduril/cfg-emisar-d4v2.h60
-rw-r--r--spaghetti-monster/chan-rgbaux.c19
-rw-r--r--spaghetti-monster/chan-rgbaux.h11
5 files changed, 190 insertions, 35 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;
+}
+
diff --git a/hwdef-Emisar_D4v2.h b/hwdef-emisar-d4v2.h
index 2864cd4..96d4052 100644
--- a/hwdef-Emisar_D4v2.h
+++ b/hwdef-emisar-d4v2.h
@@ -28,22 +28,45 @@
* ADC12 thermal sensor
*/
-#ifdef ATTINY
-#undef ATTINY
-#endif
#define ATTINY 1634
#include <avr/io.h>
-// TODO: add aux red and aux blue as disabled channel modes,
-// so they can be used for the police strobe?
-#define NUM_CHANNEL_MODES 1
+#define HWDEF_C_FILE hwdef-emisar-d4v2.c
+
+// allow using aux LEDs as extra channel modes
+#include "chan-rgbaux.h"
+
+// channel modes:
+// * 0. FET+7135 stacked
+// * 1. aux red
+// * 2. aux green
+// * 3. aux blue
+#define NUM_CHANNEL_MODES 4
+#define CM_MAIN 0
+#define CM_AUXRED 1
+#define CM_AUXGRN 2
+#define CM_AUXBLU 3
+
#define DEFAULT_CHANNEL_MODE 0
-#define SET_LEVEL_MODES set_level_2ch_stacked
-#define GRADUAL_TICK_MODES gradual_tick_2ch_stacked
-// no special handlers needed, can use common handlers
-#define USE_SET_LEVEL_2CH_STACKED
-#define USE_GRADUAL_TICK_2CH_STACKED
+#define CHANNEL_MODES_ENABLED 0b00000001
+#define CHANNEL_HAS_ARGS 0b00000000
+// _, _, _, 128=middle CCT, 0=warm-to-cool
+//#define CHANNEL_MODE_ARGS 0,0,0,0
+
+#define USE_CHANNEL_MODES
+//#define USE_CHANNEL_MODE_ARGS
+#define SET_LEVEL_MODES set_level_stacked, \
+ set_level_auxred, \
+ set_level_auxgrn, \
+ set_level_auxblu
+// gradual ticking for thermal regulation
+#define GRADUAL_TICK_MODES gradual_tick_stacked, \
+ gradual_tick_null, \
+ gradual_tick_null, \
+ gradual_tick_null
+
+// TODO: remove this when possible
#define PWM_CHANNELS 2
#define SWITCH_PIN PA2 // pin 5
@@ -52,17 +75,23 @@
#define SWITCH_PCMSK PCMSK0 // PCMSK0 is for PCINT[7:0]
#define SWITCH_PORT PINA // PINA or PINB or PINC
+#define PWM_GET PWM_GET16
+#define PWM_BITS 16
+#define PWM_DATATYPE uint16_t
+#define PWM_DATATYPE2 uint32_t // only needs 32-bit if ramp values go over 255
+#define PWM1_DATATYPE uint16_t
+#define PWM2_DATATYPE uint16_t
+
+// dynamic PWM
+#define PWM_TOP_INIT 255
+#define PWM_TOP ICR1 // holds the TOP value for for variable-resolution PWM
+#define PWM_CNT TCNT1 // for dynamic PWM, reset phase
+
#define LOW_PWM_PIN PB3 // pin 16, 1x7135 PWM
#define LOW_PWM_LVL OCR1A // OCR1A is the output compare register for PB3
-#define PWM1_BITS 8
#define HIGH_PWM_PIN PA6 // pin 1, FET PWM
#define HIGH_PWM_LVL OCR1B // OCR1B is the output compare register for PB1
-#define PWM2_BITS 8
-
-// only using 8-bit on this light
-#define PWM_GET PWM_GET8
-#define PWM_DATATYPE uint8_t
#define ADC_PRSCL 0x07 // clk/128
@@ -95,6 +124,12 @@
#undef USE_INDICATOR_LED_WHILE_RAMPING
#endif
+// custom channel modes
+void set_level_stacked(uint8_t level);
+
+bool gradual_tick_stacked(uint8_t gt);
+
+
inline void hwdef_setup() {
// enable output ports
// 7135
@@ -110,6 +145,26 @@ inline void hwdef_setup() {
// configure PWM
// Setup PWM. F_pwm = F_clkio / 2 / N / TOP, where N = prescale factor, TOP = top of counter
// pre-scale for timer: N = 1
+ // Linear opamp PWM for both main and 2nd LEDs (10-bit)
+ // WGM1[3:0]: 1,0,1,0: PWM, Phase Correct, adjustable (DS table 12-5)
+ // CS1[2:0]: 0,0,1: clk/1 (No prescaling) (DS table 12-6)
+ // COM1A[1:0]: 1,0: PWM OC1A in the normal direction (DS table 12-4)
+ // COM1B[1:0]: 1,0: PWM OC1B in the normal direction (DS table 12-4)
+ TCCR1A = (1<<WGM11) | (0<<WGM10) // adjustable PWM (TOP=ICR1) (DS table 12-5)
+ | (1<<COM1A1) | (0<<COM1A0) // PWM 1A in normal direction (DS table 12-4)
+ | (1<<COM1B1) | (0<<COM1B0) // PWM 1B in normal direction (DS table 12-4)
+ ;
+ TCCR1B = (0<<CS12) | (0<<CS11) | (1<<CS10) // clk/1 (no prescaling) (DS table 12-6)
+ | (1<<WGM13) | (0<<WGM12) // phase-correct adjustable PWM (DS table 12-5)
+ ;
+
+ // set PWM resolution
+ PWM_TOP = PWM_TOP_INIT;
+
+ #if 0 // old 8-bit PWM setup
+ // configure PWM
+ // Setup PWM. F_pwm = F_clkio / 2 / N / TOP, where N = prescale factor, TOP = top of counter
+ // pre-scale for timer: N = 1
TCCR1A = (0<<WGM11) | (1<<WGM10) // 8-bit (TOP=0xFF) (DS table 12-5)
| (1<<COM1A1) | (0<<COM1A0) // PWM 1A in normal direction (DS table 12-4)
| (1<<COM1B1) | (0<<COM1B0) // PWM 1B in normal direction (DS table 12-4)
@@ -117,6 +172,7 @@ inline void hwdef_setup() {
TCCR1B = (0<<CS12) | (0<<CS11) | (1<<CS10) // clk/1 (no prescaling) (DS table 12-6)
| (0<<WGM13) | (0<<WGM12) // phase-correct PWM (DS table 12-5)
;
+ #endif
// set up e-switch
//PORTA = (1 << SWITCH_PIN); // TODO: configure PORTA / PORTB / PORTC?
diff --git a/spaghetti-monster/anduril/cfg-emisar-d4v2.h b/spaghetti-monster/anduril/cfg-emisar-d4v2.h
index 670482c..5ebf5e0 100644
--- a/spaghetti-monster/anduril/cfg-emisar-d4v2.h
+++ b/spaghetti-monster/anduril/cfg-emisar-d4v2.h
@@ -4,34 +4,58 @@
#pragma once
#define MODEL_NUMBER "0113"
-#include "hwdef-Emisar_D4v2.h"
+#include "hwdef-emisar-d4v2.h"
#include "hank-cfg.h"
// ATTINY: 1634
-// copied from original D4, since it's also a FET+1 and has the same host
-// ../../bin/level_calc.py 1 65 7135 1 0.8 150
-// ... mixed with this:
-// ../../bin/level_calc.py 2 150 7135 4 0.33 150 FET 1 10 1500
#define RAMP_SIZE 150
-#define LOW_PWM_LEVELS 1,1,2,2,3,3,4,4,5,6,7,8,9,10,12,13,14,15,17,19,20,22,24,26,29,31,34,36,39,42,45,48,51,55,59,62,66,70,75,79,84,89,93,99,104,110,115,121,127,134,140,147,154,161,168,176,184,192,200,209,217,226,236,245,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,0
-#define HIGH_PWM_LEVELS 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,3,4,5,7,8,9,11,12,14,15,17,19,20,22,24,25,27,29,31,33,35,37,39,41,43,45,48,50,52,55,57,59,62,64,67,70,72,75,78,81,84,87,90,93,96,99,102,105,109,112,115,119,122,126,129,133,137,141,144,148,152,156,160,165,169,173,177,182,186,191,195,200,205,209,214,219,224,229,234,239,244,250,255
-#define MAX_1x7135 65
-#define HALFSPEED_LEVEL 14
-#define QUARTERSPEED_LEVEL 6
+
+// 7135 at 65/150
+//// level_calc.py 4.2905 2 150 7135 1 0.1 130 FET 1 10 3000 --pwm dyn:64:4096:255:3
+//#define PWM1_LEVELS 1,1,3,4,5,7,8,10,12,14,17,19,21,24,27,30,32,35,38,41,44,48,51,54,57,60,63,65,68,71,73,76,79,81,83,85,88,90,92,94,96,99,101,103,106,109,112,115,119,123,127,132,138,144,150,157,165,173,182,193,204,216,228,241,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,0
+//#define PWM2_LEVELS 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,2,3,4,4,5,6,7,8,9,10,11,12,13,14,15,16,18,19,20,22,23,25,26,28,29,31,33,35,36,38,40,42,44,47,49,51,53,56,58,61,63,66,69,72,74,77,80,84,87,90,93,97,100,104,108,112,115,119,124,128,132,136,141,146,150,155,160,165,170,175,181,186,192,198,203,209,216,222,228,235,241,248,255
+//#define PWM_TOPS 4095,2008,3646,3292,2938,3156,2761,2752,2665,2539,2555,2382,2214,2150,2067,1975,1820,1731,1641,1553,1468,1417,1336,1260,1188,1120,1057,982,928,877,818,775,734,687,644,605,575,541,509,480,453,432,409,387,370,354,339,324,313,303,292,285,279,273,267,263,260,258,256,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255
+
+// 7135 at 75/150
+// level_calc.py 5.7895 2 150 7135 1 0.1 130 FET 1 10 3000 --pwm dyn:74:4096:255:3
+// (with some manual tweaks)
+#define PWM1_LEVELS 1,1,2,3,3,4,5,6,7,8,9,11,12,13,15,16,18,19,21,23,26,27,28,30,32,34,36,38,40,42,44,46,48,50,52,54,56,58,60,62,64,66,68,70,71,74,76,78,80,82,85,87,90,93,96,100,103,107,112,116,122,127,133,140,147,154,163,171,182,192,203,215,228,241,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,0
+#define PWM2_LEVELS 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,2,3,4,5,5,6,7,8,9,10,11,13,14,15,16,18,19,20,22,24,25,27,29,30,32,34,36,39,41,43,45,48,50,53,56,58,61,64,67,71,74,77,81,84,88,92,96,100,104,109,113,118,123,128,133,138,144,149,155,161,167,173,180,186,193,200,207,215,222,230,238,247,255
+#define PWM_TOPS 4095,2701,3200,3586,2518,2778,2834,2795,2705,2587,2455,2582,2412,2247,2256,2091,2062,1907,1860,1802,1737,1605,1542,1477,1412,1347,1284,1222,1162,1105,1050,997,946,898,853,810,768,730,693,658,625,594,564,536,503,485,462,439,418,398,384,366,353,340,327,319,307,298,292,284,280,273,269,266,263,260,258,256,256,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255
+
+//#define LOW_PWM_LEVELS 1,1,2,2,3,3,4,4,5,6,7,8,9,10,12,13,14,15,17,19,20,22,24,26,29,31,34,36,39,42,45,48,51,55,59,62,66,70,75,79,84,89,93,99,104,110,115,121,127,134,140,147,154,161,168,176,184,192,200,209,217,226,236,245,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,0
+//#define HIGH_PWM_LEVELS 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,3,4,5,7,8,9,11,12,14,15,17,19,20,22,24,25,27,29,31,33,35,37,39,41,43,45,48,50,52,55,57,59,62,64,67,70,72,75,78,81,84,87,90,93,96,99,102,105,109,112,115,119,122,126,129,133,137,141,144,148,152,156,160,165,169,173,177,182,186,191,195,200,205,209,214,219,224,229,234,239,244,250,255
+#define MAX_1x7135 75
+#define MIN_THERM_STEPDOWN 70 // should be above highest dyn_pwm level
+#define HALFSPEED_LEVEL 20
+#define QUARTERSPEED_LEVEL 5
#define RAMP_SMOOTH_FLOOR 1
-#define RAMP_SMOOTH_CEIL 120
-// 10, 28, 46, [65], 83, 101, 120
-#define RAMP_DISCRETE_FLOOR 10
+#define RAMP_SMOOTH_CEIL 130
+// 20, 38, 56, [75], 93, 111, 130
+#define RAMP_DISCRETE_FLOOR 20
#define RAMP_DISCRETE_CEIL RAMP_SMOOTH_CEIL
#define RAMP_DISCRETE_STEPS 7
-// safe limit ~20% power
-#define SIMPLE_UI_FLOOR RAMP_DISCRETE_FLOOR
-#define SIMPLE_UI_CEIL 95
+// 20, 40, 60, 80, 100
+#define SIMPLE_UI_FLOOR 20
+#define SIMPLE_UI_CEIL 100
#define SIMPLE_UI_STEPS 5
-// stop panicking at ~30% power or ~1200 lm
-#define THERM_FASTER_LEVEL 105
+// stop panicking at ~25% power or ~1000 lm
+#define THERM_FASTER_LEVEL 110
#define THERM_CAL_OFFSET 5
+
+// use aux red + aux blue for police strobe
+#define USE_POLICE_COLOR_STROBE_MODE
+#define POLICE_STROBE_USES_AUX
+#define POLICE_COLOR_STROBE_CH1 CM_AUXRED
+#define POLICE_COLOR_STROBE_CH2 CM_AUXBLU
+
+// the default of 26 looks a bit rough, so increase it to make it smoother
+#define CANDLE_AMPLITUDE 33
+
+// show each channel while it scroll by in the menu
+#define USE_CONFIG_COLORS
+
diff --git a/spaghetti-monster/chan-rgbaux.c b/spaghetti-monster/chan-rgbaux.c
new file mode 100644
index 0000000..355f246
--- /dev/null
+++ b/spaghetti-monster/chan-rgbaux.c
@@ -0,0 +1,19 @@
+// channel modes for RGB aux LEDs
+// Copyright (C) 2023 Selene ToyKeeper
+// SPDX-License-Identifier: GPL-3.0-or-later
+#pragma once
+
+void set_level_auxred(uint8_t level) {
+ rgb_led_set(!(!(level)) << 1); // red, high (or off)
+}
+
+void set_level_auxgrn(uint8_t level) {
+ rgb_led_set(!(!(level)) << 3); // green, high (or off)
+}
+
+void set_level_auxblu(uint8_t level) {
+ rgb_led_set(!(!(level)) << 5); // blue, high (or off)
+}
+
+bool gradual_tick_null(uint8_t gt) { return true; } // do nothing
+
diff --git a/spaghetti-monster/chan-rgbaux.h b/spaghetti-monster/chan-rgbaux.h
new file mode 100644
index 0000000..5c1c5c3
--- /dev/null
+++ b/spaghetti-monster/chan-rgbaux.h
@@ -0,0 +1,11 @@
+// channel modes for RGB aux LEDs
+// Copyright (C) 2023 Selene ToyKeeper
+// SPDX-License-Identifier: GPL-3.0-or-later
+#pragma once
+
+void set_level_auxred(uint8_t level);
+void set_level_auxgrn(uint8_t level);
+void set_level_auxblu(uint8_t level);
+
+bool gradual_tick_null(uint8_t gt);
+