diff options
| author | Gabriel Hart | 2022-04-11 09:29:31 -0500 |
|---|---|---|
| committer | Gabriel Hart | 2022-04-11 09:29:31 -0500 |
| commit | 4d558992d4cc6434ec3ee94d535cd4b61a92a128 (patch) | |
| tree | 8ffc3723da4657518aa340dca5fdd7ef7fc8ad28 | |
| parent | Tweak a few MT35Mini settings (diff) | |
| parent | revert spurious change to version.h (diff) | |
| download | anduril-4d558992d4cc6434ec3ee94d535cd4b61a92a128.tar.gz anduril-4d558992d4cc6434ec3ee94d535cd4b61a92a128.tar.bz2 anduril-4d558992d4cc6434ec3ee94d535cd4b61a92a128.zip | |
Merge from TK's main A2 branch thru Rev 647 which includes several patches for the Sofirn SP10 Pro after TK merge that branch in
Diffstat (limited to '')
42 files changed, 1322 insertions, 115 deletions
diff --git a/bin/level_calc.py b/bin/level_calc.py index 2998b44..60416db 100755 --- a/bin/level_calc.py +++ b/bin/level_calc.py @@ -65,10 +65,16 @@ def main(args): dpwm_steps = int(parts[1]) dpwn_max = int(parts[2]) dpwn_min = int(parts[3]) + dpwm_shape = 'linear' + if parts[4]: + dpwm_shape = float(parts[4]) max_pwms = [dpwn_min] * answers.num_levels for i in range(dpwm_steps): span = dpwn_max - dpwn_min - x = dpwn_min + (span * (float(dpwm_steps - i) / dpwm_steps)) + if dpwm_shape == 'linear': + x = dpwn_min + (span * (float(dpwm_steps - i) / dpwm_steps)) + else: # variable curve + x = dpwn_min + (span * ((float(dpwm_steps - i) / dpwm_steps) ** dpwm_shape)) max_pwms[i] = int(x) max_pwm = dpwn_min diff --git a/hwdef-BLF_LT1.h b/hwdef-BLF_LT1.h index d0c2821..16e1c90 100644 --- a/hwdef-BLF_LT1.h +++ b/hwdef-BLF_LT1.h @@ -14,7 +14,7 @@ #include <avr/io.h> #define PWM_CHANNELS 1 // 1 virtual channel (1 for main LEDs + 1 for 2nd LEDs) -#define PWM_BITS 8 // 0 to 255 at 15.6 kHz +#define PWM_BITS 9 // 0 to 255 at 15.6 kHz, but goes to 510 for "200%" turbo #define PWM_TOP 255 // dynamic PWM with tint ramping (not supported on attiny85) @@ -25,7 +25,7 @@ // it out to a soft brightness value, in order to handle tint ramping // (this allows smooth thermal regulation to work, and makes things // otherwise simpler and easier) -uint8_t PWM1_LVL; +uint16_t PWM1_LVL; #define PWM1_PIN PB0 // pin 5, warm tint PWM #define TINT1_LVL OCR0A // OCR0A is the output compare register for PB0 diff --git a/hwdef-Emisar_D4Sv2-tintramp.h b/hwdef-Emisar_D4Sv2-tintramp.h index 76f6097..90545f4 100644 --- a/hwdef-Emisar_D4Sv2-tintramp.h +++ b/hwdef-Emisar_D4Sv2-tintramp.h @@ -47,12 +47,15 @@ #define USE_DYN_PWM // dynamic frequency and speed #define PWM_DATATYPE2 uint32_t // only needs 32-bit if ramp values go over 255 +#ifndef SWITCH_PIN #define SWITCH_PIN PA7 // pin 20 #define SWITCH_PCINT PCINT7 // pin 20 pin change interrupt #define SWITCH_PCIE PCIE0 // PCIE1 is for PCINT[7:0] #define SWITCH_PCMSK PCMSK0 // PCMSK1 is for PCINT[7:0] #define SWITCH_PORT PINA // PINA or PINB or PINC +#define SWITCH_PUE PUEA // pullup group A #define PCINT_vect PCINT0_vect // ISR for PCINT[7:0] +#endif // usually PWM1_LVL would be a hardware register, but we need to abstract // it out to a soft brightness value, in order to handle tint ramping @@ -173,7 +176,7 @@ inline void hwdef_setup() { PWM1_TOP = PWM_TOP; // set up e-switch - PUEA = (1 << SWITCH_PIN); // pull-up for e-switch + SWITCH_PUE = (1 << SWITCH_PIN); // pull-up for e-switch SWITCH_PCMSK = (1 << SWITCH_PCINT); // enable pin change interrupt } diff --git a/hwdef-Noctigon_DM11-12V.h b/hwdef-Noctigon_DM11-12V.h new file mode 100644 index 0000000..bd24768 --- /dev/null +++ b/hwdef-Noctigon_DM11-12V.h @@ -0,0 +1,162 @@ +#ifndef HWDEF_NOCTIGON_DM11_12V_H +#define HWDEF_NOCTIGON_DM11_12V_H + +/* Noctigon DM11 (12V) driver layout (attiny1634) + * (based on Noctigon K1) + * + * Pin / Name / Function + * 1 PA6 (none) (PWM1B) (reserved for DD drivers) + * 2 PA5 R: red aux LED (PWM0B) + * 3 PA4 G: green aux LED + * 4 PA3 B: blue aux LED + * 5 PA2 L: button LED + * 6 PA1 (none) + * 7 PA0 (none) + * 8 GND GND + * 9 VCC VCC + * 10 PC5 (none) + * 11 PC4 (none) + * 12 PC3 RESET + * 13 PC2 (none) + * 14 PC1 SCK + * 15 PC0 boost PMIC enable (PWM0A not used) + * 16 PB3 main LED PWM (PWM1A) + * 17 PB2 MISO / e-switch? (PCINT10) + * 18 PB1 MOSI / battery voltage (ADC6) + * 19 PB0 Opamp power + * 20 PA7 e-switch? (PCINT7) + * ADC12 thermal sensor + * + * Main LED power uses one pin to turn the Opamp on/off, + * and one pin to control Opamp power level. + * Linear brightness control uses the power level pin, with dynamic PWM. + * The on/off pin is only used to turn the main LED on and off, + * not to change brightness. + */ + +#ifdef ATTINY +#undef ATTINY +#endif +#define ATTINY 1634 +#include <avr/io.h> + +#define PWM_CHANNELS 1 // can't use DD FET on boost drivers +#define PWM_BITS 16 // data type needs 16 bits, not 8 +#define PWM_TOP 255 // highest value used in top half of ramp +#define USE_DYN_PWM // dynamic frequency and speed + +//#define SWITCH_PIN PB2 // pin 17 +//#define SWITCH_PCINT PCINT10 // pin 17 pin change interrupt +//#define SWITCH_PCIE PCIE1 // PCIE1 is for PCINT[11:8] +//#define SWITCH_PCMSK PCMSK1 // PCMSK1 is for PCINT[11:8] +//#define SWITCH_PORT PINB // PINA or PINB or PINC +//#define PCINT_vect PCINT1_vect // ISR for PCINT[11:8] + +#define SWITCH_PIN PA7 // pin 20 +#define SWITCH_PCINT PCINT7 // pin 20 pin change interrupt +#define SWITCH_PCIE PCIE0 // PCIE0 is for PCINT[7:0] +#define SWITCH_PCMSK PCMSK0 // PCMSK0 is for PCINT[7:0] +#define SWITCH_PORT PINA // PINA or PINB or PINC + +#define PWM1_PIN PB3 // pin 16, Opamp reference +#define PWM1_LVL OCR1A // OCR1A is the output compare register for PB3 +#define PWM1_CNT TCNT1 // for dynamic PWM, reset phase + +// PWM parameters of both channels are tied together because they share a counter +#define PWM1_TOP ICR1 // holds the TOP value for for variable-resolution PWM + +#define LED_ENABLE_PIN PB0 // pin 19, Opamp power +#define LED_ENABLE_PORT PORTB // control port for PB0 + +#define LED2_ENABLE_PIN PC0 // pin 15, boost PMIC enable +#define LED2_ENABLE_PORT PORTC // control port for PC0 + + +#define USE_VOLTAGE_DIVIDER // use a dedicated pin, not VCC, because VCC input is flattened +#define VOLTAGE_PIN PB1 // Pin 18 / PB1 / ADC6 +// pin to ADC mappings are in DS table 19-4 +#define VOLTAGE_ADC ADC6D // digital input disable pin for PB1 +// DIDR0/DIDR1 mappings are in DS section 19.13.5, 19.13.6 +#define VOLTAGE_ADC_DIDR DIDR1 // DIDR channel for ADC6D +// DS tables 19-3, 19-4 +// Bit 7 6 5 4 3 2 1 0 +// REFS1 REFS0 REFEN ADC0EN MUX3 MUX2 MUX1 MUX0 +// MUX[3:0] = 0, 1, 1, 0 for ADC6 / PB1 +// divided by ... +// REFS[1:0] = 1, 0 for internal 1.1V reference +// other bits reserved +#define ADMUX_VOLTAGE_DIVIDER 0b10000110 +#define ADC_PRSCL 0x07 // clk/128 + +// Raw ADC readings at 4.4V and 2.2V +// calibrate the voltage readout here +// estimated / calculated values are: +// (voltage - D1) * (R2/(R2+R1) * 1024 / 1.1) +// D1, R1, R2 = 0, 330, 100 +#ifndef ADC_44 +//#define ADC_44 981 // raw value at 4.40V +#define ADC_44 967 // manually tweaked so 4.16V will blink out 4.2 +#endif +#ifndef ADC_22 +//#define ADC_22 489 // raw value at 2.20V +#define ADC_22 482 // manually tweaked so 4.16V will blink out 4.2 +#endif + +// this light has aux LEDs under the optic +#define AUXLED_R_PIN PA5 // pin 2 +#define AUXLED_G_PIN PA4 // pin 3 +#define AUXLED_B_PIN PA3 // pin 4 +#define AUXLED_RGB_PORT PORTA // PORTA or PORTB or PORTC +#define AUXLED_RGB_DDR DDRA // DDRA or DDRB or DDRC +#define AUXLED_RGB_PUE PUEA // PUEA or PUEB or PUEC + +#define BUTTON_LED_PIN PA2 // pin 5 +#define BUTTON_LED_PORT PORTA // for all "PA" pins +#define BUTTON_LED_DDR DDRA // for all "PA" pins +#define BUTTON_LED_PUE PUEA // for all "PA" pins + +// with so many pins, doing this all with #ifdefs gets awkward... +// ... so just hardcode it in each hwdef file instead +inline void hwdef_setup() { + // enable output ports + // boost PMIC on/off + DDRC = (1 << LED2_ENABLE_PIN); + // Opamp level and Opamp on/off + DDRB = (1 << PWM1_PIN) + | (1 << LED_ENABLE_PIN); + // aux R/G/B, button LED + DDRA = (1 << AUXLED_R_PIN) + | (1 << AUXLED_G_PIN) + | (1 << AUXLED_B_PIN) + | (1 << BUTTON_LED_PIN) + ; + + // 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 + // 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]: 0,0: PWM OC1B disabled (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) + | (0<<COM1B1) | (0<<COM1B0) // PWM 1B disabled (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 + PWM1_TOP = PWM_TOP; + + // set up e-switch + ////PORTB = (1 << SWITCH_PIN); // TODO: configure PORTA / PORTB / PORTC? + //PUEB = (1 << SWITCH_PIN); // pull-up for e-switch + //PORTA = (1 << SWITCH_PIN); // TODO: configure PORTA / PORTB / PORTC? + PUEA = (1 << SWITCH_PIN); // pull-up for e-switch + SWITCH_PCMSK = (1 << SWITCH_PCINT); // enable pin change interrupt +} + +#define LAYOUT_DEFINED + +#endif diff --git a/hwdef-Noctigon_DM11-SBT90.h b/hwdef-Noctigon_DM11-SBT90.h new file mode 100644 index 0000000..64ebe05 --- /dev/null +++ b/hwdef-Noctigon_DM11-SBT90.h @@ -0,0 +1,154 @@ +#ifndef HWDEF_NOCTIGON_DM11SBT90_H +#define HWDEF_NOCTIGON_DM11SBT90_H + +/* Noctigon DM11-SBT90.2 driver layout (attiny1634) + * (based on Noctigon K1 and DM11) + * + * Pin / Name / Function + * 1 PA6 FET PWM (direct drive) (PWM1B) + * 2 PA5 R: red aux LED (PWM0B) + * 3 PA4 G: green aux LED + * 4 PA3 B: blue aux LED + * 5 PA2 L: button LED + * 6 PA1 (none) + * 7 PA0 (none) + * 8 GND GND + * 9 VCC VCC + * 10 PC5 (none) + * 11 PC4 (none) + * 12 PC3 RESET + * 13 PC2 (none) + * 14 PC1 SCK + * 15 PC0 (none) PWM0A + * 16 PB3 main LED PWM (PWM1A) + * 17 PB2 MISO / e-switch (PCINT10) + * 18 PB1 MOSI / battery voltage (ADC6) + * 19 PB0 Opamp power + * 20 PA7 (none) (PCINT7) + * ADC12 thermal sensor + * + * Main LED power uses one pin to turn the Opamp on/off, + * and one pin to control Opamp power level. + * Linear brightness control uses the power level pin, with dynamic PWM. + * The on/off pin is only used to turn the main LED on and off, + * not to change brightness. + * Also has a direct-drive FET for turbo. + */ + +#ifdef ATTINY +#undef ATTINY +#endif +#define ATTINY 1634 +#include <avr/io.h> + +#define PWM_CHANNELS 2 // override this for the no-FET version +#define PWM_BITS 16 // data type needs 16 bits, not 8 +#define PWM_TOP 255 // highest value used in top half of ramp +#define USE_DYN_PWM // dynamic frequency and speed + +#define SWITCH_PIN PB2 // pin 17 +#define SWITCH_PCINT PCINT10 // pin 17 pin change interrupt +#define SWITCH_PCIE PCIE1 // PCIE1 is for PCINT[11:8] +#define SWITCH_PCMSK PCMSK1 // PCMSK1 is for PCINT[11:8] +#define SWITCH_PORT PINB // PINA or PINB or PINC +#define PCINT_vect PCINT1_vect // ISR for PCINT[11:8] + +#define PWM1_PIN PB3 // pin 16, Opamp reference +#define PWM1_LVL OCR1A // OCR1A is the output compare register for PB3 +#define PWM1_CNT TCNT1 // for dynamic PWM, reset phase + +#define PWM2_PIN PA6 // pin 1, DD FET PWM +#define PWM2_LVL OCR1B // OCR1B is the output compare register for PA6 + +// PWM parameters of both channels are tied together because they share a counter +#define PWM1_TOP ICR1 // holds the TOP value for for variable-resolution PWM + +#define LED_ENABLE_PIN PB0 // pin 19, Opamp power +#define LED_ENABLE_PORT PORTB // control port for PB0 + + +#define USE_VOLTAGE_DIVIDER // use a dedicated pin, not VCC, because VCC input is flattened +#define VOLTAGE_PIN PB1 // Pin 18 / PB1 / ADC6 +// pin to ADC mappings are in DS table 19-4 +#define VOLTAGE_ADC ADC6D // digital input disable pin for PB1 +// DIDR0/DIDR1 mappings are in DS section 19.13.5, 19.13.6 +#define VOLTAGE_ADC_DIDR DIDR1 // DIDR channel for ADC6D +// DS tables 19-3, 19-4 +// Bit 7 6 5 4 3 2 1 0 +// REFS1 REFS0 REFEN ADC0EN MUX3 MUX2 MUX1 MUX0 +// MUX[3:0] = 0, 1, 1, 0 for ADC6 / PB1 +// divided by ... +// REFS[1:0] = 1, 0 for internal 1.1V reference +// other bits reserved +#define ADMUX_VOLTAGE_DIVIDER 0b10000110 +#define ADC_PRSCL 0x07 // clk/128 + +// Raw ADC readings at 4.4V and 2.2V +// calibrate the voltage readout here +// estimated / calculated values are: +// (voltage - D1) * (R2/(R2+R1) * 1024 / 1.1) +// D1, R1, R2 = 0, 330, 100 +#ifndef ADC_44 +//#define ADC_44 981 // raw value at 4.40V +#define ADC_44 967 // manually tweaked so 4.16V will blink out 4.2 +#endif +#ifndef ADC_22 +//#define ADC_22 489 // raw value at 2.20V +#define ADC_22 482 // manually tweaked so 4.16V will blink out 4.2 +#endif + +// this light has aux LEDs under the optic +#define AUXLED_R_PIN PA5 // pin 2 +#define AUXLED_G_PIN PA4 // pin 3 +#define AUXLED_B_PIN PA3 // pin 4 +#define AUXLED_RGB_PORT PORTA // PORTA or PORTB or PORTC +#define AUXLED_RGB_DDR DDRA // DDRA or DDRB or DDRC +#define AUXLED_RGB_PUE PUEA // PUEA or PUEB or PUEC + +#define BUTTON_LED_PIN PA2 // pin 5 +#define BUTTON_LED_PORT PORTA // for all "PA" pins +#define BUTTON_LED_DDR DDRA // for all "PA" pins +#define BUTTON_LED_PUE PUEA // for all "PA" pins + +// with so many pins, doing this all with #ifdefs gets awkward... +// ... so just hardcode it in each hwdef file instead +inline void hwdef_setup() { + // enable output ports + // Opamp level and Opamp on/off + DDRB = (1 << PWM1_PIN) + | (1 << LED_ENABLE_PIN); + // DD FET PWM, aux R/G/B, button LED + DDRA = (1 << PWM2_PIN) + | (1 << AUXLED_R_PIN) + | (1 << AUXLED_G_PIN) + | (1 << AUXLED_B_PIN) + | (1 << BUTTON_LED_PIN) + ; + + // 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 + // 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 + PWM1_TOP = PWM_TOP; + + // set up e-switch + //PORTB = (1 << SWITCH_PIN); // TODO: configure PORTA / PORTB / PORTC? + PUEB = (1 << SWITCH_PIN); // pull-up for e-switch + SWITCH_PCMSK = (1 << SWITCH_PCINT); // enable pin change interrupt +} + +#define LAYOUT_DEFINED + +#endif diff --git a/hwdef-Noctigon_DM11.h b/hwdef-Noctigon_DM11.h new file mode 100644 index 0000000..19532e9 --- /dev/null +++ b/hwdef-Noctigon_DM11.h @@ -0,0 +1,153 @@ +#ifndef HWDEF_NOCTIGON_DM11_H +#define HWDEF_NOCTIGON_DM11_H + +/* Noctigon DM11 driver layout (attiny1634) + * (based on Noctigon K1) + * + * Pin / Name / Function + * 1 PA6 FET PWM (direct drive) (PWM1B) (on some models) + * 2 PA5 R: red aux LED (PWM0B) + * 3 PA4 G: green aux LED + * 4 PA3 B: blue aux LED + * 5 PA2 L: button LED + * 6 PA1 (none) + * 7 PA0 (none) + * 8 GND GND + * 9 VCC VCC + * 10 PC5 (none) + * 11 PC4 (none) + * 12 PC3 RESET + * 13 PC2 (none) + * 14 PC1 SCK + * 15 PC0 (none) PWM0A + * 16 PB3 main LED PWM (PWM1A) + * 17 PB2 MISO / (none) (PCINT10) + * 18 PB1 MOSI / battery voltage (ADC6) + * 19 PB0 Opamp power + * 20 PA7 e-switch (PCINT7) + * ADC12 thermal sensor + * + * Main LED power uses one pin to turn the Opamp on/off, + * and one pin to control Opamp power level. + * Linear brightness control uses the power level pin, with dynamic PWM. + * The on/off pin is only used to turn the main LED on and off, + * not to change brightness. + * Some models also have a direct-drive FET for turbo. + */ + +#ifdef ATTINY +#undef ATTINY +#endif +#define ATTINY 1634 +#include <avr/io.h> + +#define PWM_CHANNELS 2 // override this for the no-FET version +#define PWM_BITS 16 // data type needs 16 bits, not 8 +#define PWM_TOP 255 // highest value used in top half of ramp +#define USE_DYN_PWM // dynamic frequency and speed + +#define SWITCH_PIN PA7 // pin 20 +#define SWITCH_PCINT PCINT7 // pin 20 pin change interrupt +#define SWITCH_PCIE PCIE0 // PCIE0 is for PCINT[7:0] +#define SWITCH_PCMSK PCMSK0 // PCMSK0 is for PCINT[7:0] +#define SWITCH_PORT PINA // PINA or PINB or PINC + +#define PWM1_PIN PB3 // pin 16, Opamp reference +#define PWM1_LVL OCR1A // OCR1A is the output compare register for PB3 +#define PWM1_CNT TCNT1 // for dynamic PWM, reset phase + +#define PWM2_PIN PA6 // pin 1, DD FET PWM +#define PWM2_LVL OCR1B // OCR1B is the output compare register for PA6 + +// PWM parameters of both channels are tied together because they share a counter +#define PWM1_TOP ICR1 // holds the TOP value for for variable-resolution PWM + +#define LED_ENABLE_PIN PB0 // pin 19, Opamp power +#define LED_ENABLE_PORT PORTB // control port for PB0 + + +#define USE_VOLTAGE_DIVIDER // use a dedicated pin, not VCC, because VCC input is flattened +#define VOLTAGE_PIN PB1 // Pin 18 / PB1 / ADC6 +// pin to ADC mappings are in DS table 19-4 +#define VOLTAGE_ADC ADC6D // digital input disable pin for PB1 +// DIDR0/DIDR1 mappings are in DS section 19.13.5, 19.13.6 +#define VOLTAGE_ADC_DIDR DIDR1 // DIDR channel for ADC6D +// DS tables 19-3, 19-4 +// Bit 7 6 5 4 3 2 1 0 +// REFS1 REFS0 REFEN ADC0EN MUX3 MUX2 MUX1 MUX0 +// MUX[3:0] = 0, 1, 1, 0 for ADC6 / PB1 +// divided by ... +// REFS[1:0] = 1, 0 for internal 1.1V reference +// other bits reserved +#define ADMUX_VOLTAGE_DIVIDER 0b10000110 +#define ADC_PRSCL 0x07 // clk/128 + +// Raw ADC readings at 4.4V and 2.2V +// calibrate the voltage readout here +// estimated / calculated values are: +// (voltage - D1) * (R2/(R2+R1) * 1024 / 1.1) +// D1, R1, R2 = 0, 330, 100 +#ifndef ADC_44 +//#define ADC_44 981 // raw value at 4.40V +#define ADC_44 967 // manually tweaked so 4.16V will blink out 4.2 +#endif +#ifndef ADC_22 +//#define ADC_22 489 // raw value at 2.20V +#define ADC_22 482 // manually tweaked so 4.16V will blink out 4.2 +#endif + +// this light has aux LEDs under the optic +#define AUXLED_R_PIN PA5 // pin 2 +#define AUXLED_G_PIN PA4 // pin 3 +#define AUXLED_B_PIN PA3 // pin 4 +#define AUXLED_RGB_PORT PORTA // PORTA or PORTB or PORTC +#define AUXLED_RGB_DDR DDRA // DDRA or DDRB or DDRC +#define AUXLED_RGB_PUE PUEA // PUEA or PUEB or PUEC + +#define BUTTON_LED_PIN PA2 // pin 5 +#define BUTTON_LED_PORT PORTA // for all "PA" pins +#define BUTTON_LED_DDR DDRA // for all "PA" pins +#define BUTTON_LED_PUE PUEA // for all "PA" pins + +// with so many pins, doing this all with #ifdefs gets awkward... +// ... so just hardcode it in each hwdef file instead +inline void hwdef_setup() { + // enable output ports + // Opamp level and Opamp on/off + DDRB = (1 << PWM1_PIN) + | (1 << LED_ENABLE_PIN); + // DD FET PWM, aux R/G/B, button LED + DDRA = (1 << PWM2_PIN) + | (1 << AUXLED_R_PIN) + | (1 << AUXLED_G_PIN) + | (1 << AUXLED_B_PIN) + | (1 << BUTTON_LED_PIN) + ; + + // 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 + // 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 + PWM1_TOP = PWM_TOP; + + // set up e-switch + //PORTA = (1 << SWITCH_PIN); // TODO: configure PORTA / PORTB / PORTC? + PUEA = (1 << SWITCH_PIN); // pull-up for e-switch + SWITCH_PCMSK = (1 << SWITCH_PCINT); // enable pin change interrupt +} + +#define LAYOUT_DEFINED + +#endif diff --git a/hwdef-Noctigon_KR4-12V.h b/hwdef-Noctigon_KR4-12V.h new file mode 100644 index 0000000..20724a2 --- /dev/null +++ b/hwdef-Noctigon_KR4-12V.h @@ -0,0 +1,154 @@ +#ifndef HWDEF_NOCTIGON_KR4_12V_H +#define HWDEF_NOCTIGON_KR4_12V_H + +/* Noctigon KR4 (12V) driver layout (attiny1634) + * (based on Noctigon DM11-12V and KR4) + * + * Pin / Name / Function + * 1 PA6 (none) (PWM1B) (reserved for DD drivers) + * 2 PA5 R: red aux LED (PWM0B) + * 3 PA4 G: green aux LED + * 4 PA3 B: blue aux LED + * 5 PA2 L: button LED + * 6 PA1 (none) + * 7 PA0 (none) + * 8 GND GND + * 9 VCC VCC + * 10 PC5 (none) + * 11 PC4 (none) + * 12 PC3 RESET + * 13 PC2 (none) + * 14 PC1 SCK + * 15 PC0 boost PMIC enable (PWM0A not used) + * 16 PB3 main LED PWM (PWM1A) + * 17 PB2 MISO / e-switch (PCINT10) + * 18 PB1 MOSI / battery voltage (ADC6) + * 19 PB0 Opamp power + * 20 PA7 (none) (PCINT7) + * ADC12 thermal sensor + * + * Main LED power uses one pin to turn the Opamp on/off, + * and one pin to control Opamp power level. + * Linear brightness control uses the power level pin, with dynamic PWM. + * The on/off pin is only used to turn the main LED on and off, + * not to change brightness. + */ + +#ifdef ATTINY +#undef ATTINY +#endif +#define ATTINY 1634 +#include <avr/io.h> + +#define PWM_CHANNELS 1 // can't use DD FET on boost drivers +#define PWM_BITS 16 // data type needs 16 bits, not 8 +#define PWM_TOP 255 // highest value used in top half of ramp +#define USE_DYN_PWM // dynamic frequency and speed + +#define SWITCH_PIN PB2 // pin 17 +#define SWITCH_PCINT PCINT10 // pin 17 pin change interrupt +#define SWITCH_PCIE PCIE1 // PCIE1 is for PCINT[11:8] +#define SWITCH_PCMSK PCMSK1 // PCMSK1 is for PCINT[11:8] +#define SWITCH_PORT PINB // PINA or PINB or PINC +#define PCINT_vect PCINT1_vect // ISR for PCINT[11:8] + +#define PWM1_PIN PB3 // pin 16, Opamp reference +#define PWM1_LVL OCR1A // OCR1A is the output compare register for PB3 +#define PWM1_CNT TCNT1 // for dynamic PWM, reset phase + +// PWM parameters of both channels are tied together because they share a counter +#define PWM1_TOP ICR1 // holds the TOP value for for variable-resolution PWM + +#define LED_ENABLE_PIN PB0 // pin 19, Opamp power +#define LED_ENABLE_PORT PORTB // control port for PB0 + +#define LED2_ENABLE_PIN PC0 // pin 15, boost PMIC enable +#define LED2_ENABLE_PORT PORTC // control port for PC0 + + +#define USE_VOLTAGE_DIVIDER // use a dedicated pin, not VCC, because VCC input is flattened +#define VOLTAGE_PIN PB1 // Pin 18 / PB1 / ADC6 +// pin to ADC mappings are in DS table 19-4 +#define VOLTAGE_ADC ADC6D // digital input disable pin for PB1 +// DIDR0/DIDR1 mappings are in DS section 19.13.5, 19.13.6 +#define VOLTAGE_ADC_DIDR DIDR1 // DIDR channel for ADC6D +// DS tables 19-3, 19-4 +// Bit 7 6 5 4 3 2 1 0 +// REFS1 REFS0 REFEN ADC0EN MUX3 MUX2 MUX1 MUX0 +// MUX[3:0] = 0, 1, 1, 0 for ADC6 / PB1 +// divided by ... +// REFS[1:0] = 1, 0 for internal 1.1V reference +// other bits reserved +#define ADMUX_VOLTAGE_DIVIDER 0b10000110 +#define ADC_PRSCL 0x07 // clk/128 + +// Raw ADC readings at 4.4V and 2.2V +// calibrate the voltage readout here +// estimated / calculated values are: +// (voltage - D1) * (R2/(R2+R1) * 1024 / 1.1) +// D1, R1, R2 = 0, 330, 100 +#ifndef ADC_44 +//#define ADC_44 981 // raw value at 4.40V +#define ADC_44 967 // manually tweaked so 4.16V will blink out 4.2 +#endif +#ifndef ADC_22 +//#define ADC_22 489 // raw value at 2.20V +#define ADC_22 482 // manually tweaked so 4.16V will blink out 4.2 +#endif + +// this light has aux LEDs under the optic +#define AUXLED_R_PIN PA5 // pin 2 +#define AUXLED_G_PIN PA4 // pin 3 +#define AUXLED_B_PIN PA3 // pin 4 +#define AUXLED_RGB_PORT PORTA // PORTA or PORTB or PORTC +#define AUXLED_RGB_DDR DDRA // DDRA or DDRB or DDRC +#define AUXLED_RGB_PUE PUEA // PUEA or PUEB or PUEC + +#define BUTTON_LED_PIN PA2 // pin 5 +#define BUTTON_LED_PORT PORTA // for all "PA" pins +#define BUTTON_LED_DDR DDRA // for all "PA" pins +#define BUTTON_LED_PUE PUEA // for all "PA" pins + +// with so many pins, doing this all with #ifdefs gets awkward... +// ... so just hardcode it in each hwdef file instead +inline void hwdef_setup() { + // enable output ports + // boost PMIC on/off + DDRC = (1 << LED2_ENABLE_PIN); + // Opamp level and Opamp on/off + DDRB = (1 << PWM1_PIN) + | (1 << LED_ENABLE_PIN); + // aux R/G/B, button LED + DDRA = (1 << AUXLED_R_PIN) + | (1 << AUXLED_G_PIN) + | (1 << AUXLED_B_PIN) + | (1 << BUTTON_LED_PIN) + ; + + // 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 + // 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]: 0,0: PWM OC1B disabled (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) + | (0<<COM1B1) | (0<<COM1B0) // PWM 1B disabled (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 + PWM1_TOP = PWM_TOP; + + // set up e-switch + //PORTB = (1 << SWITCH_PIN); // TODO: configure PORTA / PORTB / PORTC? + PUEB = (1 << SWITCH_PIN); // pull-up for e-switch + SWITCH_PCMSK = (1 << SWITCH_PCINT); // enable pin change interrupt +} + +#define LAYOUT_DEFINED + +#endif diff --git a/hwdef-Noctigon_KR4-tintramp.h b/hwdef-Noctigon_KR4-tintramp.h new file mode 100644 index 0000000..3bd57fe --- /dev/null +++ b/hwdef-Noctigon_KR4-tintramp.h @@ -0,0 +1,46 @@ +#ifndef HWDEF_KR4_TINTRAMP_H +#define HWDEF_KR4_TINTRAMP_H + +/* Noctigon KR4 w/ tint ramping + * (same driver as D4Sv2-tintramp, but with the switch on a different pin) + * + * Pin / Name / Function + * 1 PA6 2nd LED PWM (linear) (PWM1B) + * 2 PA5 R: red aux LED (PWM0B) + * 3 PA4 G: green aux LED + * 4 PA3 B: blue aux LED + * 5 PA2 button LED + * 6 PA1 Opamp 2 enable (2nd LEDs) + * 7 PA0 Opamp 1 enable (main LEDs) + * 8 GND GND + * 9 VCC VCC + * 10 PC5 (none) + * 11 PC4 (none) + * 12 PC3 RESET + * 13 PC2 (none) + * 14 PC1 SCK + * 15 PC0 main LED PWM (FET) (PWM0A) (unused on some models because tint ramping) + * 16 PB3 main LED PWM (linear) (PWM1A) + * 17 PB2 MISO / e-switch (PCINT10) + * 18 PB1 MOSI / battery voltage (ADC6) + * 19 PB0 (none) + * 20 PA7 (none) + * ADC12 thermal sensor + */ + +#define ATTINY 1634 +#include <avr/io.h> + +// move the switch to a different pin +#define SWITCH_PIN PB2 // pin 17 +#define SWITCH_PCINT PCINT10 // pin 17 pin change interrupt +#define SWITCH_PCIE PCIE1 // PCIE1 is for PCINT[11:8] +#define SWITCH_PCMSK PCMSK1 // PCMSK1 is for PCINT[11:8] +#define SWITCH_PORT PINB // PINA or PINB or PINC +#define SWITCH_PUE PUEB // pullup group B +#define PCINT_vect PCINT1_vect // ISR for PCINT[11:8] + +// the rest of the config is the same as D4Sv2-tintramp +#include "hwdef-Emisar_D4Sv2-tintramp.h" + +#endif diff --git a/hwdef-Sofirn_SP10-Pro.h b/hwdef-Sofirn_SP10-Pro.h index 5ed716d..bb10f2f 100644 --- a/hwdef-Sofirn_SP10-Pro.h +++ b/hwdef-Sofirn_SP10-Pro.h @@ -37,17 +37,19 @@ PA1 : Boost Enable // Small channel #ifndef PWM1_PIN #define PWM1_PIN PB5 -#define PWM1_LVL TCA0.SINGLE.CMP2 // PB5 is Alternate MUX for TCA Compare 2 +#define PWM1_LVL TCA0.SINGLE.CMP2BUF // PB5 is Alternate MUX for TCA Compare 2 #endif // Big channel #ifndef PWM2_PIN #define PWM2_PIN PB0 -#define PWM2_LVL TCA0.SINGLE.CMP0 // PB0 is TCA Compare 0 +#define PWM2_LVL TCA0.SINGLE.CMP0BUF // PB0 is TCA Compare 0 #endif // PWM parameters of both channels are tied together because they share a counter -#define PWM1_TOP TCA0.SINGLE.PER // holds the TOP value for for variable-resolution PWM +#define PWM1_TOP TCA0.SINGLE.PERBUF // holds the TOP value for for variable-resolution PWM +// not necessary when double-buffered "BUF" registers are used +//#define PWM1_CNT TCA0.SINGLE.CNT // for resetting phase after each TOP adjustment #define LED_ENABLE_PIN PIN1_bp #define LED_ENABLE_PORT PORTA_OUT diff --git a/spaghetti-monster/anduril/MODELS b/spaghetti-monster/anduril/MODELS index 14392b6..0fee10c 100644 --- a/spaghetti-monster/anduril/MODELS +++ b/spaghetti-monster/anduril/MODELS @@ -1,5 +1,6 @@ Model Name MCU ----- ---- --- +0000 thefreeman-lin16dac attiny1616 0111 emisar-d4 attiny85 0112 emisar-d4-219c attiny85 0113 emisar-d4v2 attiny1634 @@ -20,6 +21,8 @@ Model Name MCU 0212 noctigon-kr4-nofet attiny1634 0213 noctigon-kr4-219 attiny1634 0214 noctigon-kr4-219b attiny1634 +0215 noctigon-kr4-tintramp attiny1634 +0216 noctigon-kr4-12v attiny1634 0251 noctigon-k1 attiny1634 0252 noctigon-k1-sbt90 attiny1634 0253 noctigon-k1-12v attiny1634 @@ -29,6 +32,10 @@ Model Name MCU 0265 noctigon-k9.3-tintramp-nofet attiny1634 0266 noctigon-k9.3-tintramp-fet attiny1634 0267 noctigon-k9.3-tintramp-219 attiny1634 +0271 noctigon-dm11 attiny1634 +0272 noctigon-dm11-nofet attiny1634 +0273 noctigon-dm11-12v attiny1634 +0274 noctigon-dm11-sbt90 attiny1634 0311 fw3a attiny85 0312 fw3a-219 attiny85 0313 fw3a-nofet attiny85 @@ -51,7 +58,7 @@ Model Name MCU 0614 sofirn-sp36-t1616 attiny1616 0621 blf-lantern attiny85 0622 blf-lantern-t1616 attiny1616 -0631 sofirn-sp10s attiny1616 +0631 sofirn-sp10-pro attiny1616 1618 gchart-fet1-t1616 attiny1616 Duplicates: diff --git a/spaghetti-monster/anduril/anduril-manual.txt b/spaghetti-monster/anduril/anduril-manual.txt index 009e95e..1873b8d 100644 --- a/spaghetti-monster/anduril/anduril-manual.txt +++ b/spaghetti-monster/anduril/anduril-manual.txt @@ -75,6 +75,7 @@ In Lockout mode with Simple UI, there are a few functions: - 1H: Momentary moon - 2H: Momentary low + - 3C: Unlock and turn off - 4C: Unlock and turn on - 4H: Unlock and turn on at low level - 5C: Unlock and turn on at high level @@ -296,6 +297,8 @@ To exit lockout mode, click 4 times. The light should blink briefly and then turn on at the memorized level. Or hold the final press to turn on at the floor level instead: + - 3C: Unlock and go to "Off" mode + - 4C: Go to ramp mode (memorized level). (uses manual mem level if there is one) @@ -692,6 +695,11 @@ Misc Config Menu Some models may have an extra config menu for settings which don't fit anywhere else. These settings are, in order: + - Tint ramp style: + + 0 = smooth (blend channels in any proportion) + 1 = toggle (only one channel active at a time) + - Jump Start level: Some lights are prone to starting up slowly at low levels, so they @@ -728,6 +736,11 @@ be warm white while dim, or cool white while bright. Or vice-versa. To access this, ramp to the end of the tint range, then keep holding until the light blinks a second time. +The misc config menu also has a setting to choose a tint ramp style. +This can be smooth, allowing the user to smoothly blend both channels in +whatever ratio they desire... or it can be "tint toggle" style, where +only one channel is active at a time. + UI Reference Table ------------------ @@ -778,6 +791,7 @@ Ramp Full 10H Ramp Extras config menu: Lockout Any 1C/1H Momentary moon (lowest floor) Lockout Any 2C/2H Momentary moon (highest floor, or manual mem level) +Lockout Any 3C Unlock (go to "Off" mode) Lockout Any 4C On (ramp mode, memorized level) Lockout Any 4H On (ramp mode, floor level) Lockout Any 5C On (ramp mode, ceiling level) @@ -819,3 +833,4 @@ Config menus Full Hold Skip current item with no changes Config menus Full Release Configure current item Number entry Full Click Add 1 to value for current item +Number entry Full Hold Add 10 to value for current item diff --git a/spaghetti-monster/anduril/cfg-blf-gt-mini.h b/spaghetti-monster/anduril/cfg-blf-gt-mini.h index af16f2c..a647ea5 100644 --- a/spaghetti-monster/anduril/cfg-blf-gt-mini.h +++ b/spaghetti-monster/anduril/cfg-blf-gt-mini.h @@ -10,3 +10,11 @@ // the button is visible while main LEDs are on #define USE_INDICATOR_LED_WHILE_RAMPING +// too big, remove stuff to make room +#undef USE_SOS_MODE +//#undef USE_RAMP_AFTER_MOON_CONFIG +//#undef USE_RAMP_SPEED_CONFIG +//#undef USE_VOLTAGE_CORRECTION +//#undef USE_2C_STYLE_CONFIG +//#undef USE_TACTICAL_STROBE_MODE + diff --git a/spaghetti-monster/anduril/cfg-blf-lantern.h b/spaghetti-monster/anduril/cfg-blf-lantern.h index a989ca4..56ed410 100644 --- a/spaghetti-monster/anduril/cfg-blf-lantern.h +++ b/spaghetti-monster/anduril/cfg-blf-lantern.h @@ -19,15 +19,20 @@ // (0 = 100% brightness, 64 = 200% brightness) //#define TINT_RAMPING_CORRECTION 26 // prototype, 140% #define TINT_RAMPING_CORRECTION 10 // production model, 115% +//#define TINT_RAMPING_CORRECTION 0 // none #ifdef RAMP_LENGTH #undef RAMP_LENGTH #endif -// level_calc.py 1 150 7135 1 30 800 +// 1-130: 0 to 100% power +// level_calc.py 3.0 1 130 7135 1 30 800 --pwm 255 +// 131-150: 101% to 200% power +// level_calc.py 8.69 1 150 7135 1 1 1600 --pwm 510 #define RAMP_LENGTH 150 -#define PWM1_LEVELS 1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,11,11,12,13,13,14,15,15,16,17,18,18,19,20,21,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,43,44,45,46,48,49,50,51,53,54,56,57,58,60,61,63,64,66,67,69,70,72,74,75,77,79,80,82,84,85,87,89,91,93,95,97,98,100,102,104,106,108,111,113,115,117,119,121,124,126,128,130,133,135,137,140,142,145,147,150,152,155,157,160,163,165,168,171,173,176,179,182,185,188,190,193,196,199,202,205,209,212,215,218,221,224,228,231,234,238,241,245,248,251,255 -#define MAX_1x7135 65 +#define PWM1_LEVELS 1,1,2,2,3,3,4,5,5,6,6,7,8,8,9,10,10,11,12,12,13,14,15,16,17,17,18,19,20,21,22,23,24,25,26,27,28,29,31,32,33,34,35,37,38,39,40,42,43,45,46,47,49,50,52,54,55,57,58,60,62,63,65,67,69,70,72,74,76,78,80,82,84,86,88,90,92,95,97,99,101,104,106,108,111,113,115,118,121,123,126,128,131,134,136,139,142,145,148,150,153,156,159,162,166,169,172,175,178,181,185,188,191,195,198,202,205,209,213,216,220,224,227,231,235,239,243,247,251,255,264,274,284,294,305,316,327,339,351,363,376,389,403,417,431,446,461,477,493,510 +#define MAX_1x7135 130 +#define DEFAULT_LEVEL 70 #define HALFSPEED_LEVEL 14 #define QUARTERSPEED_LEVEL 5 @@ -40,7 +45,7 @@ // set floor and ceiling as far apart as possible // because this lantern isn't overpowered #define RAMP_SMOOTH_FLOOR 1 -#define RAMP_SMOOTH_CEIL 150 +#define RAMP_SMOOTH_CEIL 130 #define RAMP_DISCRETE_FLOOR 10 #define RAMP_DISCRETE_CEIL RAMP_SMOOTH_CEIL #define RAMP_DISCRETE_STEPS 5 @@ -65,14 +70,15 @@ #undef USE_THERMAL_REGULATION #endif -// don't blink while ramping -#ifdef BLINK_AT_RAMP_MIDDLE -#undef BLINK_AT_RAMP_MIDDLE -#endif +// don't blink at floor #ifdef BLINK_AT_RAMP_FLOOR #undef BLINK_AT_RAMP_FLOOR #endif -// except the top... blink at the top +// blink at 100% power +#ifndef BLINK_AT_RAMP_MIDDLE +#define BLINK_AT_RAMP_MIDDLE +#endif +// blink again at the 200% power / ceil / turbo #ifndef BLINK_AT_RAMP_CEIL #define BLINK_AT_RAMP_CEIL #endif diff --git a/spaghetti-monster/anduril/cfg-blf-q8.h b/spaghetti-monster/anduril/cfg-blf-q8.h index 6a5055c..f657adb 100644 --- a/spaghetti-monster/anduril/cfg-blf-q8.h +++ b/spaghetti-monster/anduril/cfg-blf-q8.h @@ -46,3 +46,10 @@ // stop panicking at ~75% power or ~3000 lm, this light has high thermal mass #define THERM_FASTER_LEVEL (RAMP_SIZE*9/10) // throttle back faster when high +// too big, remove stuff to make room +#undef USE_SOS_MODE +//#undef USE_RAMP_AFTER_MOON_CONFIG +//#undef USE_RAMP_SPEED_CONFIG +//#undef USE_VOLTAGE_CORRECTION +//#undef USE_2C_STYLE_CONFIG +//#undef USE_TACTICAL_STROBE_MODE diff --git a/spaghetti-monster/anduril/cfg-emisar-d4sv2-tintramp-fet.h b/spaghetti-monster/anduril/cfg-emisar-d4sv2-tintramp-fet.h index 3c638a7..657e25d 100644 --- a/spaghetti-monster/anduril/cfg-emisar-d4sv2-tintramp-fet.h +++ b/spaghetti-monster/anduril/cfg-emisar-d4sv2-tintramp-fet.h @@ -14,22 +14,30 @@ // 2nd LEDs // output: unknown, 2000 lm? #define RAMP_LENGTH 150 +///// copy non-FET ramp, but add FET to the top 10 levels from 141 to 150 +/* old // level_calc.py 5.01 1 140 7135 1 0.2 2000 --pwm dyn:69:16383:511 // plus a FET segment -// level_calc.py 2 1 10 7135 5 50.0 3000 --pwm 255 // abstract ramp (power is split between both sets of LEDs) +// level_calc.py 2 1 10 7135 5 50.0 3000 --pwm 255 // append: ,500,482,456,420,374,318,252,178,94,0 -#undef PWM1_LEVELS -#define PWM1_LEVELS 1,1,1,2,2,3,3,4,5,5,6,7,8,9,10,12,13,14,16,18,19,21,23,25,27,30,32,35,37,40,43,45,48,51,54,58,61,64,67,70,74,77,80,83,86,89,92,95,97,99,101,103,105,106,106,107,106,106,104,102,100,96,92,87,81,73,65,56,45,33,35,37,39,41,43,45,47,49,52,54,57,59,62,65,68,71,74,78,81,85,89,92,96,100,105,109,114,118,123,128,133,139,144,150,156,162,168,175,181,188,195,202,210,217,225,233,242,250,259,268,278,287,297,307,318,328,339,351,362,374,386,399,412,425,438,452,466,481,496,511,500,482,456,420,374,318,252,178,94,0 +*/ +/* also old +// level_calc.py 3 1 11 7135 511 2000 5000 --pwm 1022 +// append: 549,589,633,679,728,780,836,894,957,1022 +//#undef PWM1_LEVELS +//#define PWM1_LEVELS 1,1,1,2,2,3,3,4,5,5,6,7,8,9,10,12,13,14,16,18,19,21,23,25,27,30,32,35,37,40,43,45,48,51,54,58,61,64,67,70,74,77,80,83,86,89,92,95,97,99,101,103,105,106,106,107,106,106,104,102,100,96,92,87,81,73,65,56,45,33,35,37,39,41,43,45,47,49,52,54,57,59,62,65,68,71,74,78,81,85,89,92,96,100,105,109,114,118,123,128,133,139,144,150,156,162,168,175,181,188,195,202,210,217,225,233,242,250,259,268,278,287,297,307,318,328,339,351,362,374,386,399,412,425,438,452,466,481,496,511,549,589,633,679,728,780,836,894,957,1022 // append: ,511,511,511,511,511,511,511,511,511,511 -#undef PWM_TOPS -#define PWM_TOPS 16383,13469,10296,14694,10845,14620,11496,13507,14400,11954,12507,12676,12605,12376,12036,12805,12240,11650,11882,11933,11243,11155,10988,10763,10497,10569,10223,10164,9781,9646,9475,9071,8870,8652,8422,8330,8077,7823,7569,7318,7169,6919,6676,6439,6209,5986,5770,5561,5305,5063,4834,4618,4413,4180,3925,3723,3468,3264,3016,2787,2576,2333,2111,1885,1658,1412,1189,968,734,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511 +//#undef PWM_TOPS +//#define PWM_TOPS 16383,13469,10296,14694,10845,14620,11496,13507,14400,11954,12507,12676,12605,12376,12036,12805,12240,11650,11882,11933,11243,11155,10988,10763,10497,10569,10223,10164,9781,9646,9475,9071,8870,8652,8422,8330,8077,7823,7569,7318,7169,6919,6676,6439,6209,5986,5770,5561,5305,5063,4834,4618,4413,4180,3925,3723,3468,3264,3016,2787,2576,2333,2111,1885,1658,1412,1189,968,734,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511 +*/ + // prepend: 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,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, #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,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,5,14,27,45,68,96,129,166,208,255 #undef DEFAULT_LEVEL #define DEFAULT_LEVEL 70 #undef MAX_1x7135 -#define MAX_1x7135 140 +#define MAX_1x7135 130 #undef RAMP_SMOOTH_FLOOR #define RAMP_SMOOTH_FLOOR 10 // level 1 is unreliable (?) @@ -53,9 +61,9 @@ // stop panicking at ~2000 lm #undef THERM_FASTER_LEVEL -#define THERM_FASTER_LEVEL 140 +#define THERM_FASTER_LEVEL 130 #undef MIN_THERM_STEPDOWN -#define MIN_THERM_STEPDOWN 70 // should be above highest dyn_pwm level +#define MIN_THERM_STEPDOWN 65 // should be above highest dyn_pwm level // speed up party strobe; the FET is really fast #undef PARTY_STROBE_ONTIME diff --git a/spaghetti-monster/anduril/cfg-emisar-d4sv2-tintramp.h b/spaghetti-monster/anduril/cfg-emisar-d4sv2-tintramp.h index c170645..3e54dca 100644 --- a/spaghetti-monster/anduril/cfg-emisar-d4sv2-tintramp.h +++ b/spaghetti-monster/anduril/cfg-emisar-d4sv2-tintramp.h @@ -28,10 +28,13 @@ // 2nd LEDs // output: unknown, 2000 lm? #define RAMP_LENGTH 150 -// level_calc.py 5.01 1 150 7135 1 0.2 2000 --pwm dyn:74:16383:511 // abstract ramp (power is split between both sets of LEDs) -#define PWM1_LEVELS 1,1,1,2,2,2,3,4,4,5,6,6,7,8,9,10,12,13,14,16,17,19,20,22,24,26,28,30,32,35,37,40,42,45,47,50,53,56,59,62,65,68,71,74,77,80,83,86,89,91,94,96,98,100,102,104,105,106,107,107,107,106,105,103,101,98,94,90,84,78,71,63,54,44,33,35,37,38,40,42,44,46,48,50,53,55,57,60,63,65,68,71,74,77,80,83,87,90,94,98,102,106,110,114,118,123,128,132,137,142,148,153,159,164,170,176,183,189,196,202,209,216,224,231,239,247,255,263,272,281,290,299,309,318,328,339,349,360,371,382,394,406,418,430,443,456,469,483,497,511 -#define PWM_TOPS 16383,13673,10738,15435,11908,8123,12779,14756,12240,13447,14013,11907,12263,12351,12261,12048,12926,12464,11972,12278,11704,11789,11180,11134,11013,10837,10620,10371,10100,10113,9793,9718,9376,9248,8898,8738,8560,8369,8168,7961,7749,7535,7321,7107,6895,6686,6480,6278,6080,5823,5639,5403,5178,4965,4763,4570,4346,4134,3936,3714,3507,3283,3074,2853,2648,2433,2211,2006,1776,1564,1351,1137,924,714,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511 +// 1-130: 0 to 100% power +// level_calc.py 5.01 1 130 7135 2 0.2 2000 --pwm dyn:64:16383:511 +// 131 to 150: 101% to 200% power +// level_calc.py 6.44 1 150 7135 1 0.2 2000 --pwm dyn:74:16383:1022 +#define PWM1_LEVELS 2,2,2,3,3,4,4,5,6,7,8,9,10,11,13,14,16,17,19,21,23,25,28,30,33,35,38,41,44,47,50,54,57,60,64,67,71,74,78,81,84,88,91,94,97,99,101,103,105,106,107,107,107,106,105,102,99,95,90,84,77,68,58,47,34,36,38,40,42,44,47,49,52,54,57,60,63,66,69,73,76,80,83,87,91,96,100,104,109,114,119,124,130,135,141,147,153,160,166,173,180,187,195,203,211,219,228,236,245,255,264,274,285,295,306,317,329,340,353,365,378,391,405,419,433,448,463,479,495,511,530,550,570,591,612,634,657,680,705,730,755,782,809,837,865,895,925,957,989,1022 +#define PWM_TOPS 16383,13234,9781,13826,9593,13434,9973,12021,12900,13193,13150,12899,12508,12023,12666,11982,12181,11422,11393,11247,11018,10731,10826,10434,10365,9927,9767,9565,9332,9076,8806,8693,8395,8096,7928,7626,7439,7143,6948,6665,6393,6203,5946,5700,5465,5187,4926,4681,4451,4195,3957,3700,3463,3213,2983,2718,2476,2231,1986,1742,1501,1245,997,756,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511,511 #define DEFAULT_LEVEL 70 #define MAX_1x7135 150 #define HALFSPEED_LEVEL 10 @@ -54,8 +57,8 @@ #define SIMPLE_UI_STEPS 5 // stop panicking at ~1500 lm -#define THERM_FASTER_LEVEL 140 -#define MIN_THERM_STEPDOWN 75 // should be above highest dyn_pwm level +#define THERM_FASTER_LEVEL 130 +#define MIN_THERM_STEPDOWN 65 // should be above highest dyn_pwm level // use the brightest setting for strobe #define STROBE_BRIGHTNESS MAX_LEVEL @@ -63,7 +66,7 @@ #define PARTY_STROBE_ONTIME 2 // the default of 26 looks a bit flat, so increase it -#define CANDLE_AMPLITUDE 40 +#define CANDLE_AMPLITUDE 33 // the power regulator is a bit slow, so push it harder for a quick response from off #define DEFAULT_JUMP_START_LEVEL 21 diff --git a/spaghetti-monster/anduril/cfg-ff-rot66.h b/spaghetti-monster/anduril/cfg-ff-rot66.h index 48541a7..481808a 100644 --- a/spaghetti-monster/anduril/cfg-ff-rot66.h +++ b/spaghetti-monster/anduril/cfg-ff-rot66.h @@ -42,6 +42,14 @@ #undef BLINK_AT_RAMP_CEIL // too big, remove stuff to make room +#undef USE_SOS_MODE #undef USE_RAMP_AFTER_MOON_CONFIG #undef USE_RAMP_SPEED_CONFIG +#undef USE_VOLTAGE_CORRECTION //#undef USE_2C_STYLE_CONFIG +//#undef USE_TACTICAL_STROBE_MODE + +// reduce size a bit +#ifdef USE_LOWPASS_WHILE_ASLEEP +#undef USE_LOWPASS_WHILE_ASLEEP +#endif diff --git a/spaghetti-monster/anduril/cfg-mateminco-mf01-mini.h b/spaghetti-monster/anduril/cfg-mateminco-mf01-mini.h index 86e8c26..83b2614 100644 --- a/spaghetti-monster/anduril/cfg-mateminco-mf01-mini.h +++ b/spaghetti-monster/anduril/cfg-mateminco-mf01-mini.h @@ -53,6 +53,14 @@ // too big, remove stuff to make room +#undef USE_SOS_MODE #undef USE_RAMP_AFTER_MOON_CONFIG #undef USE_RAMP_SPEED_CONFIG +#undef USE_VOLTAGE_CORRECTION //#undef USE_2C_STYLE_CONFIG + +// reduce size a bit +#ifdef USE_LOWPASS_WHILE_ASLEEP +#undef USE_LOWPASS_WHILE_ASLEEP +#endif + diff --git a/spaghetti-monster/anduril/cfg-noctigon-dm11-12v.h b/spaghetti-monster/anduril/cfg-noctigon-dm11-12v.h new file mode 100644 index 0000000..3e7c1d3 --- /dev/null +++ b/spaghetti-monster/anduril/cfg-noctigon-dm11-12v.h @@ -0,0 +1,74 @@ +// Noctigon DM11 (12V) config options for Anduril +#define MODEL_NUMBER "0273" +#include "hwdef-Noctigon_DM11-12V.h" +#include "hank-cfg.h" +// ATTINY: 1634 + +// this light has three aux LED channels: R, G, B +#define USE_AUX_RGB_LEDS +// ... and a single LED in the button +#define USE_BUTTON_LED +// don't use aux LEDs while main LED is on +#ifdef USE_INDICATOR_LED_WHILE_RAMPING +#undef USE_INDICATOR_LED_WHILE_RAMPING +#endif + + +// power channels: +// - linear: 5A? +// - DD FET: none (can't do DD on a boost driver) +#define RAMP_LENGTH 150 +#define USE_DYN_PWM + +// level_calc.py 5.01 1 149 7135 1 0.3 1740 --pwm dyn:78:16384:255 +// (plus a 0 at the beginning for moon) +#define PWM1_LEVELS 0,1,1,1,2,3,3,4,5,6,7,8,9,10,11,13,14,16,17,19,21,23,25,27,29,31,34,36,39,42,44,47,50,53,57,60,63,67,70,74,77,81,85,88,92,96,99,103,107,110,113,117,120,123,126,128,130,133,134,136,137,137,137,137,136,135,133,130,126,122,117,111,104,96,87,76,65,52,38,22,23,25,26,27,28,29,30,32,33,34,36,37,39,40,42,43,45,47,49,51,53,55,57,59,61,63,66,68,70,73,76,78,81,84,87,90,93,96,99,103,106,110,113,117,121,125,129,133,137,142,146,151,155,160,165,170,175,181,186,192,197,203,209,215,222,228,234,241,248,255 +#define PWM_TOPS 16383,16383,12404,8140,11462,14700,11041,12947,13795,14111,14124,13946,13641,13248,12791,13418,12808,13057,12385,12428,12358,12209,12000,11746,11459,11147,11158,10793,10708,10576,10173,9998,9800,9585,9527,9278,9023,8901,8634,8486,8216,8053,7881,7615,7440,7261,7009,6832,6656,6422,6196,6031,5819,5615,5419,5190,4973,4803,4571,4386,4179,3955,3745,3549,3340,3145,2940,2729,2513,2312,2109,1903,1697,1491,1286,1070,871,662,459,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,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 DEFAULT_LEVEL 70 +#define MAX_1x7135 150 +#define HALFSPEED_LEVEL 12 +#define QUARTERSPEED_LEVEL 4 + +// don't blink halfway up +#ifdef BLINK_AT_RAMP_MIDDLE +#undef BLINK_AT_RAMP_MIDDLE +#endif + +#define RAMP_SMOOTH_FLOOR 10 // low levels may be unreliable +#define RAMP_SMOOTH_CEIL 130 +// 10, 30, 50, [70], 90, 110, 130 +// Nichia B35 model: (0.56), 1.4, 8.4, 34.5, [102], 250, 500, 860, (1300) lm +#define RAMP_DISCRETE_FLOOR 10 +#define RAMP_DISCRETE_CEIL RAMP_SMOOTH_CEIL +#define RAMP_DISCRETE_STEPS 7 + +// safe limit ~75% power +#define SIMPLE_UI_FLOOR RAMP_DISCRETE_FLOOR +#define SIMPLE_UI_CEIL RAMP_DISCRETE_CEIL +#define SIMPLE_UI_STEPS 5 + +// make candle mode wobble more +#define CANDLE_AMPLITUDE 33 + +// stop panicking at ~70% power or ~600 lm +#define THERM_FASTER_LEVEL 130 +#define MIN_THERM_STEPDOWN 80 // must be > end of dynamic PWM range + +//#define THERM_RESPONSE_MAGNITUDE 32 // smaller adjustments, this host changes temperature slowly +//#define THERM_NEXT_WARNING_THRESHOLD 32 // more error tolerance before adjusting + +// slow down party strobe; this driver can't pulse for 2ms or less +#define PARTY_STROBE_ONTIME 3 + +#define THERM_CAL_OFFSET 5 + +// the power regulator seems to "jump start" the LEDs all on its own, +// so the firmware doesn't have to +// (and unfortunately the power regulator jumps it a bit too hard) +#define DEFAULT_JUMP_START_LEVEL 1 +#define BLINK_BRIGHTNESS 50 +#define BLINK_ONCE_TIME 12 + +// added for convenience +#define USE_SOFT_FACTORY_RESET diff --git a/spaghetti-monster/anduril/cfg-noctigon-dm11-nofet.h b/spaghetti-monster/anduril/cfg-noctigon-dm11-nofet.h new file mode 100644 index 0000000..5a828d6 --- /dev/null +++ b/spaghetti-monster/anduril/cfg-noctigon-dm11-nofet.h @@ -0,0 +1,42 @@ +// Noctigon DM11-noFET config options for Anduril +#include "cfg-noctigon-dm11.h" +#undef MODEL_NUMBER +#define MODEL_NUMBER "0272" +// ATTINY: 1634 + +// turn off the DD FET +#undef PWM_CHANNELS +#define PWM_CHANNELS 1 + +// level_calc.py 5.01 1 149 7135 1 0.3 1740 --pwm dyn:78:16384:255 +#undef PWM1_LEVELS +#define PWM1_LEVELS 0,1,1,1,2,3,3,4,5,6,7,8,9,10,11,13,14,16,17,19,21,23,25,27,29,31,34,36,39,42,44,47,50,53,57,60,63,67,70,74,77,81,85,88,92,96,99,103,107,110,113,117,120,123,126,128,130,133,134,136,137,137,137,137,136,135,133,130,126,122,117,111,104,96,87,76,65,52,38,22,23,25,26,27,28,29,30,32,33,34,36,37,39,40,42,43,45,47,49,51,53,55,57,59,61,63,66,68,70,73,76,78,81,84,87,90,93,96,99,103,106,110,113,117,121,125,129,133,137,142,146,151,155,160,165,170,175,181,186,192,197,203,209,215,222,228,234,241,248,255 +#undef PWM2_LEVELS +#undef PWM_TOPS +#define PWM_TOPS 16383,16383,12404,8140,11462,14700,11041,12947,13795,14111,14124,13946,13641,13248,12791,13418,12808,13057,12385,12428,12358,12209,12000,11746,11459,11147,11158,10793,10708,10576,10173,9998,9800,9585,9527,9278,9023,8901,8634,8486,8216,8053,7881,7615,7440,7261,7009,6832,6656,6422,6196,6031,5819,5615,5419,5190,4973,4803,4571,4386,4179,3955,3745,3549,3340,3145,2940,2729,2513,2312,2109,1903,1697,1491,1286,1070,871,662,459,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255 +#undef DEFAULT_LEVEL +#define DEFAULT_LEVEL 70 +#undef MAX_1x7135 +#define MAX_1x7135 150 + +// make candle mode wobble more +#ifdef CANDLE_AMPLITUDE +#undef CANDLE_AMPLITUDE +#endif +#define CANDLE_AMPLITUDE 33 + + +// slow down party strobe; this driver can't pulse for 1ms or less +// (only needed on no-FET build) +#define PARTY_STROBE_ONTIME 2 + +// jump start a bit higher than base driver +#undef DEFAULT_JUMP_START_LEVEL +#define DEFAULT_JUMP_START_LEVEL 25 + +// stop panicking at ~70% power or ~600 lm +#undef THERM_FASTER_LEVEL +#define THERM_FASTER_LEVEL 130 +#undef MIN_THERM_STEPDOWN +#define MIN_THERM_STEPDOWN 80 // must be > end of dynamic PWM range + diff --git a/spaghetti-monster/anduril/cfg-noctigon-dm11-sbt90.h b/spaghetti-monster/anduril/cfg-noctigon-dm11-sbt90.h new file mode 100644 index 0000000..9a0c8b7 --- /dev/null +++ b/spaghetti-monster/anduril/cfg-noctigon-dm11-sbt90.h @@ -0,0 +1,73 @@ +// Noctigon DM11-SBT90.2 config options for Anduril +#define MODEL_NUMBER "0274" +#include "hwdef-Noctigon_DM11-SBT90.h" +#include "hank-cfg.h" +// ATTINY: 1634 + +// this light has three aux LED channels: R, G, B +#define USE_AUX_RGB_LEDS +// ... and a single LED in the button +#define USE_BUTTON_LED +// don't use aux LEDs while main LED is on +#ifdef USE_INDICATOR_LED_WHILE_RAMPING +#undef USE_INDICATOR_LED_WHILE_RAMPING +#endif + + +// power channels: +// - linear: 5A? +// - FET: DD +#define RAMP_LENGTH 150 +#define USE_DYN_PWM + +// maxreg at 130, dynamic PWM: level_calc.py 5.01 2 149 7135 1 0.3 1740 FET 1 10 3190 --pwm dyn:64:16384:255 +// (plus one extra level at the beginning for moon) +#define PWM1_LEVELS 0,1,1,2,2,3,4,5,6,7,8,9,11,12,14,16,17,19,22,24,26,29,31,34,37,40,43,46,49,53,56,60,63,67,71,74,78,82,86,89,93,96,99,103,105,108,110,112,114,115,116,116,115,114,112,109,106,101,95,89,81,71,60,48,34,19,20,21,22,23,24,26,27,28,30,31,32,34,36,37,39,41,43,45,47,49,51,53,56,58,61,63,66,69,72,75,78,81,84,88,91,95,99,103,107,111,115,119,124,129,133,138,143,149,154,159,165,171,177,183,189,196,203,210,217,224,231,239,247,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,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,9,20,30,41,52,63,75,87,99,112,125,138,151,165,179,194,208,224,239,255 +#define PWM_TOPS 16383,16383,11750,14690,9183,12439,13615,13955,13877,13560,13093,12529,13291,12513,12756,12769,11893,11747,12085,11725,11329,11316,10851,10713,10518,10282,10016,9729,9428,9298,8971,8794,8459,8257,8043,7715,7497,7275,7052,6753,6538,6260,5994,5798,5501,5271,5006,4758,4525,4268,4030,3775,3508,3263,3010,2752,2517,2256,1998,1763,1512,1249,994,749,497,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,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 DEFAULT_LEVEL 70 +#define MAX_1x7135 130 +#define HALFSPEED_LEVEL 12 +#define QUARTERSPEED_LEVEL 4 + +// don't blink halfway up +#ifdef BLINK_AT_RAMP_MIDDLE +#undef BLINK_AT_RAMP_MIDDLE +#endif + +#define RAMP_SMOOTH_FLOOR 10 // low levels may be unreliable +#define RAMP_SMOOTH_CEIL 130 +// 10, 30, 50, [70], 90, 110, 130 +#define RAMP_DISCRETE_FLOOR 10 +#define RAMP_DISCRETE_CEIL RAMP_SMOOTH_CEIL +#define RAMP_DISCRETE_STEPS 7 + +// safe limit ~75% power +#define SIMPLE_UI_FLOOR RAMP_DISCRETE_FLOOR +#define SIMPLE_UI_CEIL RAMP_DISCRETE_CEIL +#define SIMPLE_UI_STEPS 5 + +// make candle mode wobble more +#define CANDLE_AMPLITUDE 30 + +// stop panicking at ~70% power or ~600 lm +#define THERM_FASTER_LEVEL 130 +#define MIN_THERM_STEPDOWN 66 // must be > end of dynamic PWM range + +//#define THERM_RESPONSE_MAGNITUDE 32 // smaller adjustments, this host changes temperature slowly +//#define THERM_NEXT_WARNING_THRESHOLD 32 // more error tolerance before adjusting + +// 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 THERM_CAL_OFFSET 5 + +// the power regulator is a bit slow, so push it harder for a quick response from off +#define DEFAULT_JUMP_START_LEVEL 21 +#define BLINK_BRIGHTNESS 50 +#define BLINK_ONCE_TIME 12 + +// added for convenience +#define USE_SOFT_FACTORY_RESET diff --git a/spaghetti-monster/anduril/cfg-noctigon-dm11.h b/spaghetti-monster/anduril/cfg-noctigon-dm11.h new file mode 100644 index 0000000..794ae2b --- /dev/null +++ b/spaghetti-monster/anduril/cfg-noctigon-dm11.h @@ -0,0 +1,73 @@ +// Noctigon DM11 config options for Anduril +#define MODEL_NUMBER "0271" +#include "hwdef-Noctigon_DM11.h" +#include "hank-cfg.h" +// ATTINY: 1634 + +// this light has three aux LED channels: R, G, B +#define USE_AUX_RGB_LEDS +// ... and a single LED in the button +#define USE_BUTTON_LED +// don't use aux LEDs while main LED is on +#ifdef USE_INDICATOR_LED_WHILE_RAMPING +#undef USE_INDICATOR_LED_WHILE_RAMPING +#endif + + +// power channels: +// - linear: 5A? +// - FET: DD +#define RAMP_LENGTH 150 +#define USE_DYN_PWM + +// maxreg at 130, dynamic PWM: level_calc.py 5.01 2 149 7135 1 0.3 1740 FET 1 10 3190 --pwm dyn:64:16384:255 +// (plus one extra level at the beginning for moon) +#define PWM1_LEVELS 0,1,1,2,2,3,4,5,6,7,8,9,11,12,14,16,17,19,22,24,26,29,31,34,37,40,43,46,49,53,56,60,63,67,71,74,78,82,86,89,93,96,99,103,105,108,110,112,114,115,116,116,115,114,112,109,106,101,95,89,81,71,60,48,34,19,20,21,22,23,24,26,27,28,30,31,32,34,36,37,39,41,43,45,47,49,51,53,56,58,61,63,66,69,72,75,78,81,84,88,91,95,99,103,107,111,115,119,124,129,133,138,143,149,154,159,165,171,177,183,189,196,203,210,217,224,231,239,247,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,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,9,20,30,41,52,63,75,87,99,112,125,138,151,165,179,194,208,224,239,255 +#define PWM_TOPS 16383,16383,11750,14690,9183,12439,13615,13955,13877,13560,13093,12529,13291,12513,12756,12769,11893,11747,12085,11725,11329,11316,10851,10713,10518,10282,10016,9729,9428,9298,8971,8794,8459,8257,8043,7715,7497,7275,7052,6753,6538,6260,5994,5798,5501,5271,5006,4758,4525,4268,4030,3775,3508,3263,3010,2752,2517,2256,1998,1763,1512,1249,994,749,497,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,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 DEFAULT_LEVEL 70 +#define MAX_1x7135 130 +#define HALFSPEED_LEVEL 12 +#define QUARTERSPEED_LEVEL 4 + +// don't blink halfway up +#ifdef BLINK_AT_RAMP_MIDDLE +#undef BLINK_AT_RAMP_MIDDLE +#endif + +#define RAMP_SMOOTH_FLOOR 10 // low levels may be unreliable +#define RAMP_SMOOTH_CEIL 130 +// 10, 30, 50, [70], 90, 110, 130 +#define RAMP_DISCRETE_FLOOR 10 +#define RAMP_DISCRETE_CEIL RAMP_SMOOTH_CEIL +#define RAMP_DISCRETE_STEPS 7 + +// safe limit ~75% power +#define SIMPLE_UI_FLOOR RAMP_DISCRETE_FLOOR +#define SIMPLE_UI_CEIL RAMP_DISCRETE_CEIL +#define SIMPLE_UI_STEPS 5 + +// make candle mode wobble more +#define CANDLE_AMPLITUDE 30 + +// stop panicking at ~70% power or ~600 lm +#define THERM_FASTER_LEVEL 130 +#define MIN_THERM_STEPDOWN 66 // must be > end of dynamic PWM range + +//#define THERM_RESPONSE_MAGNITUDE 32 // smaller adjustments, this host changes temperature slowly +//#define THERM_NEXT_WARNING_THRESHOLD 32 // more error tolerance before adjusting + +// 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 THERM_CAL_OFFSET 5 + +// the power regulator is a bit slow, so push it harder for a quick response from off +#define DEFAULT_JUMP_START_LEVEL 21 +#define BLINK_BRIGHTNESS 50 +#define BLINK_ONCE_TIME 12 + +// added for convenience +#define USE_SOFT_FACTORY_RESET diff --git a/spaghetti-monster/anduril/cfg-noctigon-k9.3.c b/spaghetti-monster/anduril/cfg-noctigon-k9.3.c index 5ce5c5a..d79c03f 100644 --- a/spaghetti-monster/anduril/cfg-noctigon-k9.3.c +++ b/spaghetti-monster/anduril/cfg-noctigon-k9.3.c @@ -1,3 +1,4 @@ +#error This build is broken. /* * K9.3 has unusual power channels, so it must override some of FSM's code. * There are two sets of LEDs: diff --git a/spaghetti-monster/anduril/cfg-noctigon-kr4-12v.h b/spaghetti-monster/anduril/cfg-noctigon-kr4-12v.h new file mode 100644 index 0000000..a513b3f --- /dev/null +++ b/spaghetti-monster/anduril/cfg-noctigon-kr4-12v.h @@ -0,0 +1,70 @@ +// Noctigon KR4 (12V) config options for Anduril +// (and Noctigon KR1) +#define MODEL_NUMBER "0216" +#include "hwdef-Noctigon_KR4-12V.h" +// ATTINY: 1634 + +// this light has three aux LED channels: R, G, B +#define USE_AUX_RGB_LEDS +// ... and a single LED in the button (D4v2.5 only) +#define USE_BUTTON_LED +// don't use aux LEDs while main LED is on +#ifdef USE_INDICATOR_LED_WHILE_RAMPING +#undef USE_INDICATOR_LED_WHILE_RAMPING +#endif + + +// power channels: +// - linear: 5A? +// - DD FET: none (can't do DD on a boost driver) +#define RAMP_LENGTH 150 +#define USE_DYN_PWM + +// level_calc.py 5.01 1 149 7135 1 0.3 1740 --pwm dyn:78:16384:255 +// (plus a 0 at the beginning for moon) +#define PWM1_LEVELS 0,1,1,1,2,3,3,4,5,6,7,8,9,10,11,13,14,16,17,19,21,23,25,27,29,31,34,36,39,42,44,47,50,53,57,60,63,67,70,74,77,81,85,88,92,96,99,103,107,110,113,117,120,123,126,128,130,133,134,136,137,137,137,137,136,135,133,130,126,122,117,111,104,96,87,76,65,52,38,22,23,25,26,27,28,29,30,32,33,34,36,37,39,40,42,43,45,47,49,51,53,55,57,59,61,63,66,68,70,73,76,78,81,84,87,90,93,96,99,103,106,110,113,117,121,125,129,133,137,142,146,151,155,160,165,170,175,181,186,192,197,203,209,215,222,228,234,241,248,255 +#define PWM_TOPS 16383,16383,12404,8140,11462,14700,11041,12947,13795,14111,14124,13946,13641,13248,12791,13418,12808,13057,12385,12428,12358,12209,12000,11746,11459,11147,11158,10793,10708,10576,10173,9998,9800,9585,9527,9278,9023,8901,8634,8486,8216,8053,7881,7615,7440,7261,7009,6832,6656,6422,6196,6031,5819,5615,5419,5190,4973,4803,4571,4386,4179,3955,3745,3549,3340,3145,2940,2729,2513,2312,2109,1903,1697,1491,1286,1070,871,662,459,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,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 DEFAULT_LEVEL 70 +#define MAX_1x7135 150 +#define HALFSPEED_LEVEL 12 +#define QUARTERSPEED_LEVEL 4 + +// don't blink halfway up +#ifdef BLINK_AT_RAMP_MIDDLE +#undef BLINK_AT_RAMP_MIDDLE +#endif + +#define RAMP_SMOOTH_FLOOR 10 // low levels may be unreliable +#define RAMP_SMOOTH_CEIL 130 +// 10, 30, 50, [70], 90, 110, 130 +#define RAMP_DISCRETE_FLOOR 10 +#define RAMP_DISCRETE_CEIL RAMP_SMOOTH_CEIL +#define RAMP_DISCRETE_STEPS 7 + +// safe limit ~75% power +#define SIMPLE_UI_FLOOR RAMP_DISCRETE_FLOOR +#define SIMPLE_UI_CEIL RAMP_DISCRETE_CEIL +#define SIMPLE_UI_STEPS 5 + +// make candle mode wobble more +#define CANDLE_AMPLITUDE 33 + +// stop panicking at ~70% power or ~600(?) lm +#define THERM_FASTER_LEVEL 130 +#define MIN_THERM_STEPDOWN 80 // must be > end of dynamic PWM range + +// slow down party strobe; this driver can't pulse for 2ms or less +#define PARTY_STROBE_ONTIME 3 + +#define THERM_CAL_OFFSET 5 + +// the power regulator seems to "jump start" the LEDs all on its own, +// so the firmware doesn't have to +// (and unfortunately the power regulator jumps it a bit too hard) +#define DEFAULT_JUMP_START_LEVEL 1 +#define BLINK_BRIGHTNESS 50 +#define BLINK_ONCE_TIME 12 + +// can't reset the normal way because power is connected before the button +#define USE_SOFT_FACTORY_RESET diff --git a/spaghetti-monster/anduril/cfg-noctigon-kr4-tintramp.h b/spaghetti-monster/anduril/cfg-noctigon-kr4-tintramp.h new file mode 100644 index 0000000..f19744d --- /dev/null +++ b/spaghetti-monster/anduril/cfg-noctigon-kr4-tintramp.h @@ -0,0 +1,12 @@ +// Noctigon KR4 tint-ramping config options for Anduril +// (basically the same as Emisar D4S V2 tint-ramping, +// but switch on a different pin, and no lighted button) +// ATTINY: 1634 +#include "hwdef-Noctigon_KR4-tintramp.h" +#include "cfg-emisar-d4sv2-tintramp.h" +#undef MODEL_NUMBER +#define MODEL_NUMBER "0215" + +// the button doesn't light up +#undef USE_BUTTON_LED + diff --git a/spaghetti-monster/anduril/cfg-sofirn-sp10-pro.h b/spaghetti-monster/anduril/cfg-sofirn-sp10-pro.h index 2dc0def..bcfc80e 100644 --- a/spaghetti-monster/anduril/cfg-sofirn-sp10-pro.h +++ b/spaghetti-monster/anduril/cfg-sofirn-sp10-pro.h @@ -7,32 +7,42 @@ #define USE_DYNAMIC_UNDERCLOCKING -// PWM generated by: level_calc_dyn.py ninth 1 147 7135 1 1 800 --pwm dyn:64:1024:255 -// and then three steps manually added to the front for the low channel (low channel PWM created manually) +// 1....15: level_calc.py 3.01 1 15 7135 1 0.1 2 --pwm dyn:15:64:64 +// 16..150: level_calc.py 5.01 1 135 7135 1 2 800 --pwm dyn:49:3072:255:3.0 #define RAMP_LENGTH 150 #define USE_DYN_PWM -#define PWM1_LEVELS 2,12,64,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,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 -#define PWM2_LEVELS 0,0,0,1,1,1,1,1,1,1,1,1,1,2,2,2,2,2,2,2,3,3,3,3,3,3,4,4,4,4,4,4,5,5,5,5,6,6,6,6,6,7,7,7,7,8,8,8,8,9,9,9,9,9,10,10,10,10,10,11,11,11,11,11,11,11,11,12,12,13,13,14,15,15,16,16,17,18,19,19,20,21,22,23,24,25,26,27,28,29,31,32,33,34,36,37,39,40,42,44,45,47,49,51,53,55,57,59,61,64,66,69,71,74,77,79,82,85,89,92,95,99,102,106,110,114,118,122,126,131,135,140,145,150,155,161,166,172,178,184,190,196,203,210,217,224,231,239,247,255 -#define PWM_TOPS 64,64,64,1024,966,909,851,792,733,674,614,554,493,883,815,747,679,611,543,474,816,762,709,655,602,549,745,700,655,610,566,522,652,613,575,537,625,591,557,523,491,555,525,496,467,514,487,461,436,470,447,424,402,381,406,387,367,349,332,350,334,318,303,288,275,262,250,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,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 _PWM1_LEVELS_ 1,2,4,6,9,12,15,19,23,28,34,41,48,55,64 +#define _PWM1_TOPS_ 64,64,64,64,64,64,64,64,64,64,64,64,64,64,64 +#define _PWM2_LEVELS_ 1,1,2,2,3,3,4,4,5,5,6,6,6,7,7,7,7,7,7,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,9,9,9,10,10,10,11,11,12,13,13,14,15,15,16,17,18,18,19,20,21,22,23,24,25,26,27,28,29,30,31,33,34,35,37,38,39,41,42,44,46,47,49,51,53,55,57,59,61,63,65,67,70,72,74,77,79,82,85,88,90,93,96,99,103,106,109,113,116,120,123,127,131,135,139,143,147,151,156,160,165,170,175,180,185,190,195,201,206,212,218,223,230,236,242,248,255 +#define _PWM2_TOPS_ 3072,1960,2372,1476,2097,1572,1920,1570,1777,1524,1646,1454,1286,1369,1234,1115,1011,918,837,894,823,759,702,650,603,560,522,487,455,425,398,374,351,330,310,292,275,259,280,265,251,266,253,240,252,240,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,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 PWM1_LEVELS _PWM1_LEVELS_,_PWM2_TOPS_ +#define PWM2_LEVELS 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,_PWM2_LEVELS_ +#define PWM_TOPS _PWM1_TOPS_,_PWM2_TOPS_ -//#define PWM1_LEVELS 255,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,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 -//#define PWM2_LEVELS 0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,2,2,2,2,2,2,2,2,2,2,2,2,2,2,3,3,3,3,3,3,3,3,3,4,4,4,4,4,4,5,5,5,5,6,6,6,7,7,7,8,8,8,9,9,10,10,10,11,11,12,12,13,14,14,15,16,16,17,18,18,19,20,21,22,23,24,25,26,27,28,29,30,31,33,34,35,37,38,40,41,43,45,46,48,50,52,54,56,58,60,63,65,67,70,73,75,78,81,84,87,90,93,97,100,104,107,111,115,119,123,128,132,137,141,146,151,156,162,167,173,179,185,191,197,204,210,217,224,232,239,247,255 +#define MAX_1x7135 15 +#define HALFSPEED_LEVEL 15 +#define QUARTERSPEED_LEVEL 15 +#define DEFAULT_LEVEL 75 -#define MAX_1x7135 80 -#define HALFSPEED_LEVEL 3 -#define QUARTERSPEED_LEVEL 3 - -#define RAMP_SMOOTH_FLOOR 3 -#define RAMP_SMOOTH_CEIL 120 -#define RAMP_DISCRETE_FLOOR RAMP_SMOOTH_FLOOR +#define RAMP_SMOOTH_FLOOR 1 +#define RAMP_SMOOTH_CEIL 150 +// 1 25 50 [75] 100 125 150 +#define RAMP_DISCRETE_FLOOR 1 #define RAMP_DISCRETE_CEIL RAMP_SMOOTH_CEIL #define RAMP_DISCRETE_STEPS 7 // at Sofirn's request, use max (150) for the Simple UI ceiling -#define SIMPLE_UI_FLOOR RAMP_DISCRETE_FLOOR +// 15 48 [82] 116 150 +#define SIMPLE_UI_FLOOR MAX_1x7135 #define SIMPLE_UI_CEIL 150 #define SIMPLE_UI_STEPS 5 +// turn on at ~6 lm by default (level 50/150, or ramp step 2/5 or 3/7) +// (also sets lockout mode 2H to a useful level) +#define DEFAULT_MANUAL_MEMORY 50 +// reset to default after being off for 10 minutes +#define DEFAULT_MANUAL_MEMORY_TIMER 10 + // enable SOS in the blinkies group #define USE_SOS_MODE #define USE_SOS_MODE_IN_BLINKY_GROUP @@ -46,13 +56,18 @@ // stop panicking at ~30% power #define THERM_FASTER_LEVEL 105 -#define MIN_THERM_STEPDOWN 66 // must be > end of dynamic PWM range +#define MIN_THERM_STEPDOWN 65 // must be > end of dynamic PWM range // slow down party strobe; this driver can't pulse for too short a time -#define PARTY_STROBE_ONTIME 8 +//#define PARTY_STROBE_ONTIME 8 +#define STROBE_OFF_LEVEL 1 // keep the regulator chip on between pulses // the default of 26 looks a bit flat, so increase it #define CANDLE_AMPLITUDE 50 // enable 2 click turbo (replaces USE_2C_MAX_TURBO) #define DEFAULT_2C_STYLE 1 + +// enable factory reset on 13H without loosening tailcap +#define USE_SOFT_FACTORY_RESET + diff --git a/spaghetti-monster/anduril/config-default.h b/spaghetti-monster/anduril/config-default.h index 406e98b..0e70347 100644 --- a/spaghetti-monster/anduril/config-default.h +++ b/spaghetti-monster/anduril/config-default.h @@ -166,9 +166,9 @@ // (these replace the fun strobe group, // so don't enable them at the same time as any of the above strobes) //#define USE_POLICE_STROBE_MODE -//#define USE_SOS_MODE +#define USE_SOS_MODE //#define USE_SOS_MODE_IN_FF_GROUP // put SOS in the "boring strobes" mode -//#define USE_SOS_MODE_IN_BLINKY_GROUP // put SOS in the blinkies mode group +#define USE_SOS_MODE_IN_BLINKY_GROUP // put SOS in the blinkies mode group // enable a mode for locking the light for safe carry #define USE_LOCKOUT_MODE @@ -189,5 +189,9 @@ // (defined here so config files can override it) #define USE_DYNAMIC_UNDERCLOCKING +// if the aux LEDs oscillate between "full battery" and "empty battery" +// while in "voltage" mode, enable this to reduce the amplitude of +// those oscillations +//#define USE_LOWPASS_WHILE_ASLEEP #endif diff --git a/spaghetti-monster/anduril/load-save-config-fsm.h b/spaghetti-monster/anduril/load-save-config-fsm.h index 894c344..ba3c69b 100644 --- a/spaghetti-monster/anduril/load-save-config-fsm.h +++ b/spaghetti-monster/anduril/load-save-config-fsm.h @@ -60,6 +60,7 @@ typedef enum { #endif #ifdef USE_TINT_RAMPING tint_e, + tint_style_e, #endif #ifdef USE_JUMP_START jump_start_level_e, diff --git a/spaghetti-monster/anduril/load-save-config.c b/spaghetti-monster/anduril/load-save-config.c index ee451ac..4987def 100644 --- a/spaghetti-monster/anduril/load-save-config.c +++ b/spaghetti-monster/anduril/load-save-config.c @@ -62,6 +62,7 @@ void load_config() { #endif #ifdef USE_TINT_RAMPING tint = eeprom[tint_e]; + tint_style = eeprom[tint_style_e]; #endif #ifdef USE_JUMP_START jump_start_level = eeprom[jump_start_level_e], @@ -140,6 +141,7 @@ void save_config() { #endif #ifdef USE_TINT_RAMPING eeprom[tint_e] = tint; + eeprom[tint_style_e] = tint_style; #endif #ifdef USE_JUMP_START eeprom[jump_start_level_e] = jump_start_level, diff --git a/spaghetti-monster/anduril/lockout-mode.c b/spaghetti-monster/anduril/lockout-mode.c index 8c83cff..e3e3fed 100644 --- a/spaghetti-monster/anduril/lockout-mode.c +++ b/spaghetti-monster/anduril/lockout-mode.c @@ -88,9 +88,16 @@ uint8_t lockout_state(Event event, uint16_t arg) { } #endif + // 3 clicks: exit and turn off + else if (event == EV_3clicks) { + blink_once(); + set_state(off_state, 0); + return MISCHIEF_MANAGED; + } // 4 clicks: exit and turn on else if (event == EV_4clicks) { #ifdef USE_MANUAL_MEMORY + // FIXME: memory timer is totally ignored if (manual_memory) set_state(steady_state, manual_memory); else @@ -100,7 +107,8 @@ uint8_t lockout_state(Event event, uint16_t arg) { } // 4 clicks, but hold last: exit and start at floor else if (event == EV_click4_hold) { - blink_once(); + //blink_once(); + blip(); // reset button sequence to avoid activating anything in ramp mode current_event = 0; // ... and back to ramp mode diff --git a/spaghetti-monster/anduril/ramp-mode-fsm.h b/spaghetti-monster/anduril/ramp-mode-fsm.h index 7f67d1e..1a062e9 100644 --- a/spaghetti-monster/anduril/ramp-mode-fsm.h +++ b/spaghetti-monster/anduril/ramp-mode-fsm.h @@ -47,7 +47,7 @@ #endif // include an extra config mode for random stuff which doesn't fit elsewhere -#if defined(USE_JUMP_START) +#if defined(USE_TINT_RAMPING) || defined(USE_JUMP_START) #define USE_GLOBALS_CONFIG #endif diff --git a/spaghetti-monster/anduril/ramp-mode.c b/spaghetti-monster/anduril/ramp-mode.c index ce3f473..6e8ba88 100644 --- a/spaghetti-monster/anduril/ramp-mode.c +++ b/spaghetti-monster/anduril/ramp-mode.c @@ -404,7 +404,12 @@ uint8_t steady_state(Event event, uint16_t arg) { // 3H: momentary turbo (on lights with no tint ramping) else if (event == EV_click3_hold) { if (! arg) { // first frame only, to allow thermal regulation to work + #ifdef USE_2C_STYLE_CONFIG + uint8_t tl = style_2c ? MAX_LEVEL : turbo_level; + set_level_and_therm_target(tl); + #else set_level_and_therm_target(turbo_level); + #endif } return MISCHIEF_MANAGED; } @@ -559,14 +564,21 @@ uint8_t ramp_extras_config_state(Event event, uint16_t arg) { #ifdef USE_GLOBALS_CONFIG void globals_config_save(uint8_t step, uint8_t value) { if (0) {} + #ifdef USE_TINT_RAMPING + else if (step == 1+tint_style_config_step) { + tint_style = !(!(value)); + // set tint to middle or edge depending on style being smooth or toggle + tint = tint_style ? 1 : 127; + } + #endif #ifdef USE_JUMP_START - else { jump_start_level = value; } + else if (step == 1+jump_start_config_step) { jump_start_level = value; } #endif } uint8_t globals_config_state(Event event, uint16_t arg) { // TODO: set number of steps based on how many configurable options - return config_state_base(event, arg, 1, globals_config_save); + return config_state_base(event, arg, globals_config_num_steps, globals_config_save); } #endif diff --git a/spaghetti-monster/anduril/ramp-mode.h b/spaghetti-monster/anduril/ramp-mode.h index bba6d96..ed76ed5 100644 --- a/spaghetti-monster/anduril/ramp-mode.h +++ b/spaghetti-monster/anduril/ramp-mode.h @@ -26,6 +26,7 @@ // thermal properties, if not defined per-driver #ifndef MIN_THERM_STEPDOWN +// TODO: Replace MAX_Xx7135 with MAX_CH1, MAX_CH2, MAX_REGULATED, etc #define MIN_THERM_STEPDOWN MAX_1x7135 // lowest value it'll step down to #endif #ifndef THERM_FASTER_LEVEL @@ -224,6 +225,16 @@ uint8_t ramp_stepss[] = { uint8_t ramp_discrete_step_size; // don't set this #ifdef USE_GLOBALS_CONFIG +typedef enum { + #ifdef USE_TINT_RAMPING + tint_style_config_step, + #endif + #ifdef USE_JUMP_START + jump_start_config_step, + #endif + globals_config_num_steps +} globals_config_steps_e; + void globals_config_save(uint8_t step, uint8_t value); uint8_t globals_config_state(Event event, uint16_t arg); #endif diff --git a/spaghetti-monster/anduril/strobe-modes.c b/spaghetti-monster/anduril/strobe-modes.c index d5f12c0..e8d1dbb 100644 --- a/spaghetti-monster/anduril/strobe-modes.c +++ b/spaghetti-monster/anduril/strobe-modes.c @@ -215,7 +215,7 @@ inline void party_tactical_strobe_mode_iter(uint8_t st) { nice_delay_ms(del >> 1); } #endif - set_level(0); + set_level(STROBE_OFF_LEVEL); nice_delay_ms(del); // no return check necessary on final delay } #endif diff --git a/spaghetti-monster/anduril/strobe-modes.h b/spaghetti-monster/anduril/strobe-modes.h index e2389ba..c6cfb53 100644 --- a/spaghetti-monster/anduril/strobe-modes.h +++ b/spaghetti-monster/anduril/strobe-modes.h @@ -62,6 +62,13 @@ strobe_mode_te strobe_type = 0; #endif #endif +// some drivers need to keep the regulator chip on between pulses, +// so set this to 1 to keep the light on at moon mode between pulses, +// and thus keep the regulator powered up for the next flash +#ifndef STROBE_OFF_LEVEL +#define STROBE_OFF_LEVEL 0 +#endif + // party and tactical strobes #ifdef USE_STROBE_STATE uint8_t strobe_state(Event event, uint16_t arg); diff --git a/spaghetti-monster/anduril/tint-ramping.c b/spaghetti-monster/anduril/tint-ramping.c index aa9b1f6..d270d9d 100644 --- a/spaghetti-monster/anduril/tint-ramping.c +++ b/spaghetti-monster/anduril/tint-ramping.c @@ -22,32 +22,6 @@ #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(); // unnecessary, and kind of annoying on moon - } - 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; @@ -61,6 +35,21 @@ uint8_t tint_ramping_state(Event event, uint16_t arg) { // click, click, hold: change the tint if (event == EV_click3_hold) { + ///// tint-toggle mode + // toggle once on first frame; ignore other frames + if (tint_style) { + // only respond on first frame + if (arg) return EVENT_NOT_HANDLED; + + // force tint to be 1 or 254 + if (tint != 254) { tint = 1; } + // invert between 1 and 254 + tint = tint ^ 0xFF; + set_level(actual_level); + return EVENT_HANDLED; + } + + ///// smooth tint-ramp mode // reset at beginning of movement if (! arg) { active = 1; // first frame means this is for us @@ -98,18 +87,19 @@ uint8_t tint_ramping_state(Event event, uint16_t arg) { active = 0; // ignore next hold if it wasn't meant for us // reverse tint_ramp_direction = -tint_ramp_direction; - if (tint == 0) tint_ramp_direction = 1; - else if (tint == 255) tint_ramp_direction = -1; + if (tint <= 1) tint_ramp_direction = 1; + else if (tint >= 254) tint_ramp_direction = -1; // remember tint after battery change save_config(); + // bug?: for some reason, brightness can seemingly change + // from 1/150 to 2/150 without this next line... not sure why + set_level(actual_level); return EVENT_HANDLED; } return EVENT_NOT_HANDLED; } -#endif // ifdef TINT_RAMP_TOGGLE_ONLY - #endif diff --git a/spaghetti-monster/anduril/tint-ramping.h b/spaghetti-monster/anduril/tint-ramping.h index e482999..1c5e22a 100644 --- a/spaghetti-monster/anduril/tint-ramping.h +++ b/spaghetti-monster/anduril/tint-ramping.h @@ -20,6 +20,14 @@ #ifndef TINT_RAMPING_H #define TINT_RAMPING_H +// 0: smooth tint ramp +// 1: toggle tint only between two extremes +#ifdef TINT_RAMP_TOGGLE_ONLY +uint8_t tint_style = 1; +#else +uint8_t tint_style = 0; +#endif + #ifdef USE_MANUAL_MEMORY uint8_t manual_memory_tint; #endif diff --git a/spaghetti-monster/anduril/version.h b/spaghetti-monster/anduril/version.h index d6e3f1a..1bc3984 100644 --- a/spaghetti-monster/anduril/version.h +++ b/spaghetti-monster/anduril/version.h @@ -1 +1,4 @@ -#define VERSION_NUMBER "20220124" +// this file is replaced automatically by the build script +// set your own date here if you're not using the build script +// otherwise, default to first human contact with the moon +#define VERSION_NUMBER "19690720"
\ No newline at end of file diff --git a/spaghetti-monster/fsm-adc.c b/spaghetti-monster/fsm-adc.c index 975d12e..c5401ea 100644 --- a/spaghetti-monster/fsm-adc.c +++ b/spaghetti-monster/fsm-adc.c @@ -306,10 +306,28 @@ static inline void ADC_voltage_handler() { uint16_t measurement; // latest ADC value - if (adc_reset) { // while asleep, or just after waking, don't lowpass + if (adc_reset) { // just after waking, don't lowpass measurement = adc_raw[0]; - adc_smooth[0] = measurement; // no lowpass while asleep + adc_smooth[0] = measurement; // no lowpass, just use the latest value } + #ifdef USE_LOWPASS_WHILE_ASLEEP + else if (go_to_standby) { // weaker lowpass while asleep + // occasionally the aux LED color can oscillate during standby, + // while using "voltage" mode ... so try to reduce the oscillation + uint16_t m = adc_raw[0]; + uint16_t v = adc_smooth[0]; + #if 0 + // fixed-rate lowpass, slow, more stable but takes longer to settle + if (m < v) { v -= 64; } + if (m > v) { v += 64; } + #else + // weighted lowpass, faster but less stable + v = (m>>1) + (v>>1); + #endif + adc_smooth[0] = v; + measurement = v; + } + #endif else measurement = adc_smooth[0]; // values stair-step between intervals of 64, with random variations diff --git a/spaghetti-monster/fsm-ramping.c b/spaghetti-monster/fsm-ramping.c index 6bb2390..1f575fd 100644 --- a/spaghetti-monster/fsm-ramping.c +++ b/spaghetti-monster/fsm-ramping.c @@ -102,6 +102,7 @@ void set_level(uint8_t level) { #endif } else { // enable the power channel, if relevant + #ifndef USE_TINT_RAMPING // update_tint handles this better #ifdef LED_ENABLE_PIN #ifdef LED_ENABLE_DELAY uint8_t led_enable_port_save = LED_ENABLE_PORT; @@ -137,6 +138,7 @@ void set_level(uint8_t level) { delay_4ms(LED2_ENABLE_DELAY/4); #endif #endif + #endif // ifndef USE_TINT_RAMPING // PWM array index = level - 1 level --; @@ -164,8 +166,8 @@ void set_level(uint8_t level) { // the timing of changing the TOP value (section 12.8.4)) // (but don't wait when turning on from zero, because // it'll reset the phase below anyway) - // to be safe, allow at least 64 cycles to update TOP - while(prev_level && (PWM1_CNT > (top - 64))) {} + // to be safe, allow at least 32 cycles to update TOP + while(prev_level && (PWM1_CNT > (top - 32))) {} #endif // pulse frequency modulation, a.k.a. dynamic PWM PWM1_TOP = top; @@ -173,13 +175,13 @@ void set_level(uint8_t level) { // repeat for other channels if necessary #ifdef PMW2_TOP #ifdef PWM2_CNT - while(prev_level && (PWM2_CNT > (top - 64))) {} + while(prev_level && (PWM2_CNT > (top - 32))) {} #endif PWM2_TOP = top; #endif #ifdef PMW3_TOP #ifdef PWM3_CNT - while(prev_level && (PWM3_CNT > (top - 64))) {} + while(prev_level && (PWM3_CNT > (top - 32))) {} #endif PWM3_TOP = top; #endif @@ -313,8 +315,14 @@ void update_tint() { // calculate actual PWM levels based on a single-channel ramp // and a global tint value //PWM_DATATYPE brightness = PWM_GET(pwm1_levels, level); - PWM_DATATYPE brightness = PWM1_LVL; - PWM_DATATYPE warm_PWM, cool_PWM; + uint16_t brightness = PWM1_LVL; + uint16_t warm_PWM, cool_PWM; + #ifdef USE_DYN_PWM + uint16_t top = PWM1_TOP; + //uint16_t top = PWM_GET(pwm_tops, actual_level-1); + #else + const uint16_t top = PWM_TOP; + #endif // auto-tint modes uint8_t mytint; @@ -331,29 +339,52 @@ void update_tint() { // stretch 1-254 to fit 0-255 range (hits every value except 98 and 198) else { mytint = (tint * 100 / 99) - 1; } - // middle tints sag, so correct for that effect PWM_DATATYPE2 base_PWM = brightness; - // correction is only necessary when PWM is fast #if defined(TINT_RAMPING_CORRECTION) && (TINT_RAMPING_CORRECTION > 0) + // middle tints sag, so correct for that effect + // by adding extra power which peaks at the middle tint + // (correction is only necessary when PWM is fast) if (level > HALFSPEED_LEVEL) { base_PWM = brightness + ((((PWM_DATATYPE2)brightness) * TINT_RAMPING_CORRECTION / 64) * triangle_wave(mytint) / 255); } + // fade the triangle wave out when above 100% power, + // so it won't go over 200% + if (brightness > top) { + base_PWM -= 2 * ( + ((brightness - top) * TINT_RAMPING_CORRECTION / 64) + * triangle_wave(mytint) / 255 + ); + } + // guarantee no more than 200% power + if (base_PWM > (top << 1)) { base_PWM = top << 1; } #endif cool_PWM = (((PWM_DATATYPE2)mytint * (PWM_DATATYPE2)base_PWM) + 127) / 255; warm_PWM = base_PWM - cool_PWM; + // when running at > 100% power, spill extra over to other channel + if (cool_PWM > top) { + warm_PWM += (cool_PWM - top); + cool_PWM = top; + } else if (warm_PWM > top) { + cool_PWM += (warm_PWM - top); + warm_PWM = top; + } TINT1_LVL = warm_PWM; TINT2_LVL = cool_PWM; // disable the power channel, if relevant #ifdef LED_ENABLE_PIN - if (! warm_PWM) + if (warm_PWM) + LED_ENABLE_PORT |= (1 << LED_ENABLE_PIN); + else LED_ENABLE_PORT &= ~(1 << LED_ENABLE_PIN); #endif #ifdef LED2_ENABLE_PIN - if (! cool_PWM) + if (cool_PWM) + LED2_ENABLE_PORT |= (1 << LED2_ENABLE_PIN); + else LED2_ENABLE_PORT &= ~(1 << LED2_ENABLE_PIN); #endif } diff --git a/spaghetti-monster/fsm-ramping.h b/spaghetti-monster/fsm-ramping.h index c1f6064..de090c2 100644 --- a/spaghetti-monster/fsm-ramping.h +++ b/spaghetti-monster/fsm-ramping.h @@ -48,26 +48,26 @@ void update_tint(); // auto-detect the data type for PWM tables #ifndef PWM_BITS -#define PWM_BITS 8 -#define PWM_TOP 255 + #define PWM_BITS 8 + #define PWM_TOP 255 #endif #if PWM_BITS <= 8 -#define PWM_DATATYPE uint8_t -#define PWM_DATATYPE2 uint16_t -#define PWM_TOP 255 -#define PWM_GET(x,y) pgm_read_byte(x+y) + #define PWM_DATATYPE uint8_t + #define PWM_DATATYPE2 uint16_t + #define PWM_TOP 255 + #define PWM_GET(x,y) pgm_read_byte(x+y) #else -#define PWM_DATATYPE uint16_t -#ifndef PWM_DATATYPE2 -#define PWM_DATATYPE2 uint32_t -#endif -#ifndef PWM_TOP -#define PWM_TOP 1023 // 10 bits by default -#endif -// pointer plus 2*y bytes -//#define PWM_GET(x,y) pgm_read_word(x+(2*y)) -// nope, the compiler was already doing the math correctly -#define PWM_GET(x,y) pgm_read_word(x+y) + #define PWM_DATATYPE uint16_t + #ifndef PWM_DATATYPE2 + #define PWM_DATATYPE2 uint32_t + #endif + #ifndef PWM_TOP + #define PWM_TOP 1023 // 10 bits by default + #endif + // pointer plus 2*y bytes + //#define PWM_GET(x,y) pgm_read_word(x+(2*y)) + // nope, the compiler was already doing the math correctly + #define PWM_GET(x,y) pgm_read_word(x+y) #endif // use UI-defined ramp tables if they exist diff --git a/spaghetti-monster/fsm-standby.c b/spaghetti-monster/fsm-standby.c index c450bca..0ae6a2f 100644 --- a/spaghetti-monster/fsm-standby.c +++ b/spaghetti-monster/fsm-standby.c @@ -73,7 +73,9 @@ void sleep_until_eswitch_pressed() go_to_standby = 0; } if (irq_adc) { // ADC done measuring + #ifndef USE_LOWPASS_WHILE_ASLEEP adc_reset = 1; // don't lowpass while asleep + #endif adc_deferred_enable = 1; adc_deferred(); //ADC_off(); // takes care of itself |
