From dbe0aaf636ccb78a3cc1281b6a1ea6c662af6756 Mon Sep 17 00:00:00 2001 From: Gabriel Hart Date: Fri, 18 Dec 2020 15:23:31 -0600 Subject: Add AVR 1-Series and t1616 board and scripts --- spaghetti-monster/anduril/BRANDS | 1 + spaghetti-monster/anduril/MODELS | 1 + spaghetti-monster/anduril/cfg-gchart-fet1-t16.h | 39 ++++++++++++++++++ spaghetti-monster/anduril/version.h | 5 +-- spaghetti-monster/fsm-adc.c | 53 +++++++++++++++++++++++- spaghetti-monster/fsm-main.c | 9 ++++- spaghetti-monster/fsm-misc.c | 54 +++++++++++++++++++++++++ spaghetti-monster/fsm-pcint.c | 9 +++++ spaghetti-monster/fsm-wdt.c | 20 +++++++++ 9 files changed, 185 insertions(+), 6 deletions(-) create mode 100644 spaghetti-monster/anduril/cfg-gchart-fet1-t16.h (limited to 'spaghetti-monster') diff --git a/spaghetti-monster/anduril/BRANDS b/spaghetti-monster/anduril/BRANDS index b74ddab..acd385e 100644 --- a/spaghetti-monster/anduril/BRANDS +++ b/spaghetti-monster/anduril/BRANDS @@ -7,3 +7,4 @@ Lumintop 0300 - 0399 Fireflies 0400 - 0499 Mateminco 0500 - 0599 Sofirn 0600 - 0699 +gChart 1600 - 1699 \ No newline at end of file diff --git a/spaghetti-monster/anduril/MODELS b/spaghetti-monster/anduril/MODELS index 84d6795..4ad4635 100644 --- a/spaghetti-monster/anduril/MODELS +++ b/spaghetti-monster/anduril/MODELS @@ -36,5 +36,6 @@ Model numbers: 0611 blf-q8 0612 sofirn-sp36 0621 blf-lantern +1618 gchart-fet1-t16 Duplicates: Missing: diff --git a/spaghetti-monster/anduril/cfg-gchart-fet1-t16.h b/spaghetti-monster/anduril/cfg-gchart-fet1-t16.h new file mode 100644 index 0000000..42333a4 --- /dev/null +++ b/spaghetti-monster/anduril/cfg-gchart-fet1-t16.h @@ -0,0 +1,39 @@ +// gChart's custom FET+1 driver config options for Anduril +#define MODEL_NUMBER "1618" // Golden Ratio... because I can +#include "hwdef-gchart-fet1-t16.h" +// ATTINY: 1616 + +// the button lights up +#define USE_INDICATOR_LED +// the button is visible while main LEDs are on +#define USE_INDICATOR_LED_WHILE_RAMPING +// enable blinking indicator LED while off +#define TICK_DURING_STANDBY + +#undef BLINK_AT_RAMP_MIDDLE + +// battery readout style (pick one) +#define BATTCHECK_VpT +//#define BATTCHECK_8bars // FIXME: breaks build +//#define BATTCHECK_4bars // FIXME: breaks build + +//#undef USE_DYNAMIC_UNDERCLOCKING +#define USE_DYNAMIC_UNDERCLOCKING + +// Mostly borrowed from the D4 for now +#define RAMP_LENGTH 150 +#define PWM1_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 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,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 + +#define RAMP_SMOOTH_FLOOR 1 +#define RAMP_SMOOTH_CEIL 120 +// 10, 28, 46, [65], 83, 101, 120 +#define RAMP_DISCRETE_FLOOR 10 +#define RAMP_DISCRETE_CEIL RAMP_SMOOTH_CEIL +#define RAMP_DISCRETE_STEPS 7 + +// stop panicking at ~30% power +#define THERM_FASTER_LEVEL 105 \ No newline at end of file diff --git a/spaghetti-monster/anduril/version.h b/spaghetti-monster/anduril/version.h index 8cf3c90..5ecfc65 100644 --- a/spaghetti-monster/anduril/version.h +++ b/spaghetti-monster/anduril/version.h @@ -1,4 +1 @@ -// 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" +#define VERSION_NUMBER "20201218" diff --git a/spaghetti-monster/fsm-adc.c b/spaghetti-monster/fsm-adc.c index 71ecf65..2818731 100644 --- a/spaghetti-monster/fsm-adc.c +++ b/spaghetti-monster/fsm-adc.c @@ -37,6 +37,9 @@ static inline void set_admux_therm() { #elif (ATTINY == 841) // FIXME: not tested ADMUXA = ADMUXA_THERM; ADMUXB = ADMUXB_THERM; + #elif defined(AVRXMEGA3) // ATTINY816, 817, etc + ADC0.MUXPOS = ADC_MUXPOS_TEMPSENSE_gc; // read temperature + ADC0.CTRLC = ADC_SAMPCAP_bm | ADC_PRESC_DIV64_gc | ADC_REFSEL_INTREF_gc; // Internal ADC reference #else #error Unrecognized MCU type #endif @@ -66,6 +69,15 @@ inline void set_admux_voltage() { ADMUXA = ADMUXA_VCC; ADMUXB = ADMUXB_VCC; #endif + #elif defined(AVRXMEGA3) // ATTINY816, 817, etc + #ifdef USE_VOLTAGE_DIVIDER // 1.1V / ADC input pin + // verify that this is correct!!! untested + ADC0.MUXPOS = ADMUX_VOLTAGE_DIVIDER; // read the requested ADC pin + ADC0.CTRLC = ADC_SAMPCAP_bm | ADC_PRESC_DIV64_gc | ADC_REFSEL_INTREF_gc; // Use internal ADC reference + #else // VCC / 1.1V reference + ADC0.MUXPOS = ADC_MUXPOS_INTREF_gc; // read internal reference + ADC0.CTRLC = ADC_SAMPCAP_bm | ADC_PRESC_DIV64_gc | ADC_REFSEL_VDDREF_gc; // Vdd (Vcc) be ADC reference + #endif #else #error Unrecognized MCU type #endif @@ -77,6 +89,9 @@ inline void set_admux_voltage() { inline void ADC_start_measurement() { #if (ATTINY == 25) || (ATTINY == 45) || (ATTINY == 85) || (ATTINY == 841) || (ATTINY == 1634) ADCSRA |= (1 << ADSC) | (1 << ADIE); + #elif defined(AVRXMEGA3) // ATTINY816, 817, etc + ADC0.INTCTRL |= ADC_RESRDY_bm; // enable interrupt + ADC0.COMMAND |= ADC_STCONV_bm; // Start the ADC conversions #else #error unrecognized MCU type #endif @@ -108,13 +123,22 @@ inline void ADC_on() // enable, start, auto-retrigger, prescale ADCSRA = (1 << ADEN) | (1 << ADSC) | (1 << ADATE) | ADC_PRSCL; //ADCSRA |= (1 << ADSC); // start measuring + #elif defined(AVRXMEGA3) // ATTINY816, 817, etc + set_admux_voltage(); + VREF.CTRLA |= VREF_ADC0REFSEL_1V1_gc; // Set Vbg ref to 1.1V + ADC0.CTRLA = ADC_ENABLE_bm | ADC_FREERUN_bm; // Enabled, free-running (aka, auto-retrigger) + ADC0.COMMAND |= ADC_STCONV_bm; // Start the ADC conversions #else #error Unrecognized MCU type #endif } inline void ADC_off() { - ADCSRA &= ~(1<>= 8; // Divide result to get Kelvin + m = (temp << 6); // left align it + } + else { m = (ADC0.RES << 6); } // voltage, force left-alignment + + #else m = ADC; + #endif adc_raw[channel] = m; // lowpass the value @@ -181,8 +228,12 @@ void adc_deferred() { // real-world entropy makes this a true random, not pseudo // Why here instead of the ISR? Because it makes the time-critical ISR // code a few cycles faster and we don't need crypto-grade randomness. + #ifdef AVRXMEGA3 // ATTINY816, 817, etc + pseudo_rand_seed += ADC0.RESL; // right aligned, not left... so should be equivalent? + #else pseudo_rand_seed += (ADCL >> 6) + (ADCH << 2); #endif + #endif // the ADC triggers repeatedly when it's on, but we only need to run the // voltage and temperature regulation stuff once in a while...so disable diff --git a/spaghetti-monster/fsm-main.c b/spaghetti-monster/fsm-main.c index b96bce8..f3c319c 100644 --- a/spaghetti-monster/fsm-main.c +++ b/spaghetti-monster/fsm-main.c @@ -23,6 +23,9 @@ #include "fsm-main.h" #if PWM_CHANNELS == 4 +#ifdef AVRXMEGA3 // ATTINY816, 817, etc +#error 4-channel PWM not currently set up for the AVR 1-Series +#endif // 4th PWM channel requires manually turning the pin on/off via interrupt :( ISR(TIMER1_OVF_vect) { //bitClear(PORTB, 3); @@ -68,7 +71,7 @@ static inline void hw_setup() { PORTB = (1 << SWITCH_PIN); // e-switch is the only input PCMSK = (1 << SWITCH_PIN); // pin change interrupt uses this pin } -#elif (ATTINY == 1634) +#elif (ATTINY == 1634) || defined(AVRXMEGA3) // ATTINY816, 817, etc static inline void hw_setup() { // this gets tricky with so many pins... // ... so punt it to the hwdef file @@ -82,7 +85,11 @@ static inline void hw_setup() { //#ifdef USE_REBOOT static inline void prevent_reboot_loop() { // prevent WDT from rebooting MCU again + #ifdef AVRXMEGA3 // ATTINY816, 817, etc + RSTCTRL.RSTFR &= ~(RSTCTRL_WDRF_bm); // reset status flag + #else MCUSR &= ~(1< #include +// *** Note for the AVRXMEGA3 (1-Series, eg 816 and 817), the WDT +// is not used for time-based interrupts. A new peripheral, the +// Periodic Interrupt Timer ("PIT") is used for this purpose. + void WDT_on() { #if (ATTINY == 25) || (ATTINY == 45) || (ATTINY == 85) @@ -35,6 +39,10 @@ void WDT_on() #elif (ATTINY == 1634) wdt_reset(); // Reset the WDT WDTCSR = (1< 0) {} // make sure the register is ready to be updated + RTC.PITCTRLA = RTC_PERIOD_CYC512_gc | RTC_PITEN_bm; // Period = 16ms, enable the PI Timer #else #error Unrecognized MCU type #endif @@ -53,6 +61,10 @@ inline void WDT_slow() #elif (ATTINY == 1634) wdt_reset(); // Reset the WDT WDTCSR = (1< 0) {} // make sure the register is ready to be updated + RTC.PITCTRLA = RTC_PERIOD_CYC16384_gc | RTC_PITEN_bm; // Period = 0.5s, enable the PI Timer #else #error Unrecognized MCU type #endif @@ -75,13 +87,21 @@ inline void WDT_off() CCP = 0xD8; // enable config changes WDTCSR = 0; // disable and clear all WDT settings sei(); + #elif defined(AVRXMEGA3) // ATTINY816, 817, etc + while (RTC.PITSTATUS > 0) {} // make sure the register is ready to be updated + RTC.PITCTRLA = 0; // Disable the PI Timer #else #error Unrecognized MCU type #endif } // clock tick -- this runs every 16ms (62.5 fps) +#ifdef AVRXMEGA3 // ATTINY816, 817, etc +ISR(RTC_PIT_vect) { + RTC.PITINTFLAGS = RTC_PI_bm; // clear the PIT interrupt flag +#else ISR(WDT_vect) { +#endif irq_wdt = 1; // WDT event happened } -- cgit v1.2.3 From 8b67b3a6e21342aefb1fffef72469588ecab2614 Mon Sep 17 00:00:00 2001 From: Gabriel Hart Date: Sun, 20 Dec 2020 12:27:05 -0600 Subject: Fix 1-Series standby tick speed, use 2C Turbo --- spaghetti-monster/anduril/cfg-gchart-fet1-t16.h | 5 ++++- spaghetti-monster/anduril/version.h | 2 +- spaghetti-monster/fsm-wdt.c | 2 +- 3 files changed, 6 insertions(+), 3 deletions(-) (limited to 'spaghetti-monster') diff --git a/spaghetti-monster/anduril/cfg-gchart-fet1-t16.h b/spaghetti-monster/anduril/cfg-gchart-fet1-t16.h index 42333a4..c8727ae 100644 --- a/spaghetti-monster/anduril/cfg-gchart-fet1-t16.h +++ b/spaghetti-monster/anduril/cfg-gchart-fet1-t16.h @@ -36,4 +36,7 @@ #define RAMP_DISCRETE_STEPS 7 // stop panicking at ~30% power -#define THERM_FASTER_LEVEL 105 \ No newline at end of file +#define THERM_FASTER_LEVEL 105 + +// enable 2 click turbo +#define USE_2C_MAX_TURBO diff --git a/spaghetti-monster/anduril/version.h b/spaghetti-monster/anduril/version.h index 5ecfc65..8cc1e77 100644 --- a/spaghetti-monster/anduril/version.h +++ b/spaghetti-monster/anduril/version.h @@ -1 +1 @@ -#define VERSION_NUMBER "20201218" +#define VERSION_NUMBER "20201219" diff --git a/spaghetti-monster/fsm-wdt.c b/spaghetti-monster/fsm-wdt.c index 7bb8acc..ea2efac 100644 --- a/spaghetti-monster/fsm-wdt.c +++ b/spaghetti-monster/fsm-wdt.c @@ -64,7 +64,7 @@ inline void WDT_slow() #elif defined(AVRXMEGA3) // ATTINY816, 817, etc RTC.PITINTCTRL = RTC_PI_bm; // enable the Periodic Interrupt while (RTC.PITSTATUS > 0) {} // make sure the register is ready to be updated - RTC.PITCTRLA = RTC_PERIOD_CYC16384_gc | RTC_PITEN_bm; // Period = 0.5s, enable the PI Timer + RTC.PITCTRLA = (1<<6) | (STANDBY_TICK_SPEED<<3) | RTC_PITEN_bm; // Set period, enable the PI Timer #else #error Unrecognized MCU type #endif -- cgit v1.2.3 From d8f58fcbd5f35d9d2140a4bcaa6589e1c2962198 Mon Sep 17 00:00:00 2001 From: Gabriel Hart Date: Tue, 12 Jan 2021 13:12:57 -0600 Subject: Add Sofirn SP10S (adapter) and dual-voltage logic --- spaghetti-monster/anduril/MODELS | 1 + spaghetti-monster/anduril/cfg-sofirn-sp10s.h | 30 ++++++++++++++++++++++++++++ spaghetti-monster/anduril/version.h | 2 +- spaghetti-monster/fsm-adc.c | 4 ++++ 4 files changed, 36 insertions(+), 1 deletion(-) create mode 100644 spaghetti-monster/anduril/cfg-sofirn-sp10s.h (limited to 'spaghetti-monster') diff --git a/spaghetti-monster/anduril/MODELS b/spaghetti-monster/anduril/MODELS index 4ad4635..0972e8b 100644 --- a/spaghetti-monster/anduril/MODELS +++ b/spaghetti-monster/anduril/MODELS @@ -36,6 +36,7 @@ Model numbers: 0611 blf-q8 0612 sofirn-sp36 0621 blf-lantern +0622 sofirn-sp10s 1618 gchart-fet1-t16 Duplicates: Missing: diff --git a/spaghetti-monster/anduril/cfg-sofirn-sp10s.h b/spaghetti-monster/anduril/cfg-sofirn-sp10s.h new file mode 100644 index 0000000..5747cc4 --- /dev/null +++ b/spaghetti-monster/anduril/cfg-sofirn-sp10s.h @@ -0,0 +1,30 @@ +// gChart's custom SP10S driver config options for Anduril +#define MODEL_NUMBER "0622" +#include "hwdef-Sofirn-SP10S.h" +// ATTINY: 1616 + +#undef BLINK_AT_RAMP_MIDDLE + +#define BATTCHECK_VpT + +#define USE_DYNAMIC_UNDERCLOCKING + +#define RAMP_LENGTH 150 +#define PWM1_LEVELS 20,30,41,54,69,87,106,128,152,179,209,242,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,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,1,1,1,1,1,1,2,2,2,2,3,3,3,4,4,4,5,5,5,6,6,7,7,8,8,9,9,10,10,11,12,12,13,14,14,15,16,17,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,33,34,35,36,38,39,41,42,43,45,46,48,50,51,53,55,56,58,60,62,64,66,68,70,72,74,76,78,80,83,85,87,90,92,94,97,99,102,105,107,110,113,116,119,121,124,127,130,133,137,140,143,146,150,153,156,160,164,167,171,174,178,182,186,190,194,198,202,206,210,214,219,223,227,232,236,241,246,250,255 + +#define MAX_1x7135 13 +#define HALFSPEED_LEVEL 14 +#define QUARTERSPEED_LEVEL 6 + +#define RAMP_SMOOTH_FLOOR 1 +#define RAMP_SMOOTH_CEIL 120 +#define RAMP_DISCRETE_FLOOR 10 +#define RAMP_DISCRETE_CEIL RAMP_SMOOTH_CEIL +#define RAMP_DISCRETE_STEPS 7 + +// stop panicking at ~30% power +#define THERM_FASTER_LEVEL 105 + +// enable 2 click turbo +#define USE_2C_MAX_TURBO diff --git a/spaghetti-monster/anduril/version.h b/spaghetti-monster/anduril/version.h index 8cc1e77..5afe62a 100644 --- a/spaghetti-monster/anduril/version.h +++ b/spaghetti-monster/anduril/version.h @@ -1 +1 @@ -#define VERSION_NUMBER "20201219" +#define VERSION_NUMBER "20210112" diff --git a/spaghetti-monster/fsm-adc.c b/spaghetti-monster/fsm-adc.c index 2818731..975d12e 100644 --- a/spaghetti-monster/fsm-adc.c +++ b/spaghetti-monster/fsm-adc.c @@ -341,7 +341,11 @@ static inline void ADC_voltage_handler() { if (lvp_timer) { lvp_timer --; } else { // it has been long enough since the last warning + #ifdef DUAL_VOLTAGE_FLOOR + if (((voltage < VOLTAGE_LOW) && (voltage > DUAL_VOLTAGE_FLOOR)) || (voltage < DUAL_VOLTAGE_LOW_LOW)) { + #else if (voltage < VOLTAGE_LOW) { + #endif // send out a warning emit(EV_voltage_low, 0); // reset rate-limit counter -- cgit v1.2.3 From 0b95725665525f5dbc77e988fd3a632ca2b2b68a Mon Sep 17 00:00:00 2001 From: Gabriel Hart Date: Tue, 12 Jan 2021 13:22:57 -0600 Subject: Rename SP10Ss hwdef file to align with others --- spaghetti-monster/anduril/cfg-sofirn-sp10s.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'spaghetti-monster') diff --git a/spaghetti-monster/anduril/cfg-sofirn-sp10s.h b/spaghetti-monster/anduril/cfg-sofirn-sp10s.h index 5747cc4..873b4b3 100644 --- a/spaghetti-monster/anduril/cfg-sofirn-sp10s.h +++ b/spaghetti-monster/anduril/cfg-sofirn-sp10s.h @@ -1,6 +1,6 @@ // gChart's custom SP10S driver config options for Anduril #define MODEL_NUMBER "0622" -#include "hwdef-Sofirn-SP10S.h" +#include "hwdef-Sofirn_SP10S.h" // ATTINY: 1616 #undef BLINK_AT_RAMP_MIDDLE -- cgit v1.2.3 From 90ac16199d08a17b9a46f913fb363321026a7328 Mon Sep 17 00:00:00 2001 From: Gabriel Hart Date: Tue, 12 Jan 2021 14:19:47 -0600 Subject: Add hwdef for BLF Q8 with t1616 and cfg files for the Q8, Lantern, and SP36 --- spaghetti-monster/anduril/MODELS | 3 + spaghetti-monster/anduril/cfg-blf-lantern-t1616.h | 89 +++++++++++++++++++++++ spaghetti-monster/anduril/cfg-blf-q8-t1616.h | 42 +++++++++++ spaghetti-monster/anduril/cfg-sofirn-sp36-t1616.h | 32 ++++++++ 4 files changed, 166 insertions(+) create mode 100644 spaghetti-monster/anduril/cfg-blf-lantern-t1616.h create mode 100644 spaghetti-monster/anduril/cfg-blf-q8-t1616.h create mode 100644 spaghetti-monster/anduril/cfg-sofirn-sp36-t1616.h (limited to 'spaghetti-monster') diff --git a/spaghetti-monster/anduril/MODELS b/spaghetti-monster/anduril/MODELS index 0972e8b..78453a9 100644 --- a/spaghetti-monster/anduril/MODELS +++ b/spaghetti-monster/anduril/MODELS @@ -37,6 +37,9 @@ Model numbers: 0612 sofirn-sp36 0621 blf-lantern 0622 sofirn-sp10s +0631 blf-q8-t1616 +0632 sofirn-sp36-t1616 +0633 blf-lantern-t1616 1618 gchart-fet1-t16 Duplicates: Missing: diff --git a/spaghetti-monster/anduril/cfg-blf-lantern-t1616.h b/spaghetti-monster/anduril/cfg-blf-lantern-t1616.h new file mode 100644 index 0000000..6d0a192 --- /dev/null +++ b/spaghetti-monster/anduril/cfg-blf-lantern-t1616.h @@ -0,0 +1,89 @@ +// BLF Lantern config options for Anduril using the Attiny1616 +#define MODEL_NUMBER "0633" +/* BLF Lantern pinout + * PB0 is 5000K channel + * PB1 is 3000K channel + */ + +// basically the same as a Q8... sort of +#include "hwdef-BLF_Q8-T1616.h" + +// the button lights up +#define USE_INDICATOR_LED +// the button is visible while main LEDs are on +#define USE_INDICATOR_LED_WHILE_RAMPING +// enable blinking indicator LED while off +#define TICK_DURING_STANDBY +#define STANDBY_TICK_SPEED 3 // every 0.128 s +#define USE_FANCIER_BLINKING_INDICATOR +// off mode: high (2) +// lockout: blinking (3) +#define INDICATOR_LED_DEFAULT_MODE ((3<<2) + 2) + +// the lantern has two PWM channels, but they drive different sets of emitters +// (one channel for warm emitters, one channel for cold) +// so enable a special ramping mode which changes tint instead of brightness +#define USE_TINT_RAMPING +// how much to increase total brightness at middle tint +// (0 = 100% brightness, 64 = 200% brightness) +//#define TINT_RAMPING_CORRECTION 26 // prototype, 140% +#define TINT_RAMPING_CORRECTION 10 // production model, 115% + +#ifdef RAMP_LENGTH +#undef RAMP_LENGTH +#endif + +// level_calc.py 1 150 7135 1 30 800 +#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 HALFSPEED_LEVEL 14 +#define QUARTERSPEED_LEVEL 5 + +// the default of 26 looks a bit flat, so increase it +#define CANDLE_AMPLITUDE 40 + +// override default ramp style +#undef RAMP_STYLE +#define RAMP_STYLE 1 // 0 = smooth, 1 = stepped +// 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_DISCRETE_FLOOR 10 +#define RAMP_DISCRETE_CEIL RAMP_SMOOTH_CEIL +#define RAMP_DISCRETE_STEPS 5 + +// LT1 can handle heat well, so don't limit simple mode +#define SIMPLE_UI_FLOOR RAMP_DISCRETE_FLOOR +#define SIMPLE_UI_CEIL RAMP_DISCRETE_CEIL +#define SIMPLE_UI_STEPS RAMP_DISCRETE_STEPS + +#define USE_SOS_MODE +#define USE_SOS_MODE_IN_BLINKY_GROUP + +// the sensor (attiny85) is nowhere near the emitters +// so thermal regulation can't work +#ifdef USE_THERMAL_REGULATION +#undef USE_THERMAL_REGULATION +#endif + +// also, the set_level_gradually() thing isn't compatible with tint ramping +// (but unsetting it here doesn't actually do anything, because the thermal +// regulation define enables it later... so this is mostly just a note to +// make this compatibility issue explicit) +#ifdef USE_SET_LEVEL_GRADUALLY +#undef USE_SET_LEVEL_GRADUALLY +#endif + +// don't blink while ramping +#ifdef BLINK_AT_RAMP_MIDDLE +#undef BLINK_AT_RAMP_MIDDLE +#endif +#ifdef BLINK_AT_RAMP_FLOOR +#undef BLINK_AT_RAMP_FLOOR +#endif +// except the top... blink at the top +#ifndef BLINK_AT_RAMP_CEIL +#define BLINK_AT_RAMP_CEIL +#endif diff --git a/spaghetti-monster/anduril/cfg-blf-q8-t1616.h b/spaghetti-monster/anduril/cfg-blf-q8-t1616.h new file mode 100644 index 0000000..a6e9517 --- /dev/null +++ b/spaghetti-monster/anduril/cfg-blf-q8-t1616.h @@ -0,0 +1,42 @@ +// BLF Q8 config options for Anduril using the Attiny1616 +#define MODEL_NUMBER "0631" +#include "hwdef-BLF_Q8-T1616.h" + +// the button lights up +#define USE_INDICATOR_LED +// the button is visible while main LEDs are on +#define USE_INDICATOR_LED_WHILE_RAMPING +// enable blinking indicator LED while off +#define TICK_DURING_STANDBY +#define STANDBY_TICK_SPEED 3 // every 0.128 s +#define USE_FANCIER_BLINKING_INDICATOR +// off mode: high (2) +// lockout: blinking (3) +#define INDICATOR_LED_DEFAULT_MODE ((3<<2) + 2) + +// copied from Emisar D4 ramp +// ../../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_LENGTH 150 +#define PWM1_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 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,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 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_DISCRETE_CEIL RAMP_SMOOTH_CEIL +#define RAMP_DISCRETE_STEPS 7 + +// safe limit ~50% power +#define SIMPLE_UI_FLOOR RAMP_DISCRETE_FLOOR +#define SIMPLE_UI_CEIL RAMP_DISCRETE_CEIL +#define SIMPLE_UI_STEPS 5 + +// 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 + diff --git a/spaghetti-monster/anduril/cfg-sofirn-sp36-t1616.h b/spaghetti-monster/anduril/cfg-sofirn-sp36-t1616.h new file mode 100644 index 0000000..29410dc --- /dev/null +++ b/spaghetti-monster/anduril/cfg-sofirn-sp36-t1616.h @@ -0,0 +1,32 @@ +// Sofirn SP36 (small Q8) config options for Anduril using the Attiny1616 +// same as the BLF Q8, mostly +#include "cfg-blf-q8-t1616.h" +#undef MODEL_NUMBER +#define MODEL_NUMBER "0632" + +// voltage readings were a little high with the Q8 value +#undef VOLTAGE_FUDGE_FACTOR +#define VOLTAGE_FUDGE_FACTOR 5 // add 0.25V, not 0.35V + +// the high button LED mode on this light uses too much power +// off mode: low (1) +// lockout: blinking (3) +#ifdef INDICATOR_LED_DEFAULT_MODE +#undef INDICATOR_LED_DEFAULT_MODE +#define INDICATOR_LED_DEFAULT_MODE ((3<<2) + 1) +#endif + +// don't blink during the ramp; the button LED brightness is sufficient +// to indicate which power channel(s) are being used +#ifdef BLINK_AT_RAMP_MIDDLE +#undef BLINK_AT_RAMP_MIDDLE +#endif +#ifdef BLINK_AT_RAMP_CEIL +#undef BLINK_AT_RAMP_CEIL +#endif + +// stop panicking at ~60% power or ~3000 lm +#ifdef THERM_FASTER_LEVEL +#undef THERM_FASTER_LEVEL +#endif +#define THERM_FASTER_LEVEL 130 -- cgit v1.2.3 From 266b3db0048ad4938b8ab52209e22b77955748ee Mon Sep 17 00:00:00 2001 From: Gabriel Hart Date: Tue, 12 Jan 2021 14:28:18 -0600 Subject: Add the override of ATTINY setting to 1616 for the new T1616 config files --- spaghetti-monster/anduril/cfg-blf-lantern-t1616.h | 1 + spaghetti-monster/anduril/cfg-blf-q8-t1616.h | 1 + spaghetti-monster/anduril/cfg-sofirn-sp36-t1616.h | 1 + 3 files changed, 3 insertions(+) (limited to 'spaghetti-monster') diff --git a/spaghetti-monster/anduril/cfg-blf-lantern-t1616.h b/spaghetti-monster/anduril/cfg-blf-lantern-t1616.h index 6d0a192..7905eee 100644 --- a/spaghetti-monster/anduril/cfg-blf-lantern-t1616.h +++ b/spaghetti-monster/anduril/cfg-blf-lantern-t1616.h @@ -7,6 +7,7 @@ // basically the same as a Q8... sort of #include "hwdef-BLF_Q8-T1616.h" +// ATTINY: 1616 // the button lights up #define USE_INDICATOR_LED diff --git a/spaghetti-monster/anduril/cfg-blf-q8-t1616.h b/spaghetti-monster/anduril/cfg-blf-q8-t1616.h index a6e9517..e1e1598 100644 --- a/spaghetti-monster/anduril/cfg-blf-q8-t1616.h +++ b/spaghetti-monster/anduril/cfg-blf-q8-t1616.h @@ -1,6 +1,7 @@ // BLF Q8 config options for Anduril using the Attiny1616 #define MODEL_NUMBER "0631" #include "hwdef-BLF_Q8-T1616.h" +// ATTINY: 1616 // the button lights up #define USE_INDICATOR_LED diff --git a/spaghetti-monster/anduril/cfg-sofirn-sp36-t1616.h b/spaghetti-monster/anduril/cfg-sofirn-sp36-t1616.h index 29410dc..8eb7a5d 100644 --- a/spaghetti-monster/anduril/cfg-sofirn-sp36-t1616.h +++ b/spaghetti-monster/anduril/cfg-sofirn-sp36-t1616.h @@ -3,6 +3,7 @@ #include "cfg-blf-q8-t1616.h" #undef MODEL_NUMBER #define MODEL_NUMBER "0632" +// ATTINY: 1616 // voltage readings were a little high with the Q8 value #undef VOLTAGE_FUDGE_FACTOR -- cgit v1.2.3 From 5d9b92928efd390ae77aa1f9f134f77e029ab183 Mon Sep 17 00:00:00 2001 From: Gabriel Hart Date: Tue, 12 Jan 2021 14:45:04 -0600 Subject: Clean up a couple unnecessary #defines in gchart fet1 config file --- spaghetti-monster/anduril/cfg-gchart-fet1-t16.h | 8 -------- 1 file changed, 8 deletions(-) (limited to 'spaghetti-monster') diff --git a/spaghetti-monster/anduril/cfg-gchart-fet1-t16.h b/spaghetti-monster/anduril/cfg-gchart-fet1-t16.h index c8727ae..a6434b8 100644 --- a/spaghetti-monster/anduril/cfg-gchart-fet1-t16.h +++ b/spaghetti-monster/anduril/cfg-gchart-fet1-t16.h @@ -12,14 +12,6 @@ #undef BLINK_AT_RAMP_MIDDLE -// battery readout style (pick one) -#define BATTCHECK_VpT -//#define BATTCHECK_8bars // FIXME: breaks build -//#define BATTCHECK_4bars // FIXME: breaks build - -//#undef USE_DYNAMIC_UNDERCLOCKING -#define USE_DYNAMIC_UNDERCLOCKING - // Mostly borrowed from the D4 for now #define RAMP_LENGTH 150 #define PWM1_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 -- cgit v1.2.3 From 9bfd94497cdcd04da1412b0c17e4bbad145f063e Mon Sep 17 00:00:00 2001 From: Gabriel Hart Date: Mon, 1 Feb 2021 08:45:44 -0600 Subject: Updated the Sofirn SP10S Anduril board --- spaghetti-monster/anduril/cfg-sofirn-sp10s.h | 2 -- spaghetti-monster/anduril/version.h | 2 +- 2 files changed, 1 insertion(+), 3 deletions(-) (limited to 'spaghetti-monster') diff --git a/spaghetti-monster/anduril/cfg-sofirn-sp10s.h b/spaghetti-monster/anduril/cfg-sofirn-sp10s.h index 873b4b3..054b1db 100644 --- a/spaghetti-monster/anduril/cfg-sofirn-sp10s.h +++ b/spaghetti-monster/anduril/cfg-sofirn-sp10s.h @@ -5,8 +5,6 @@ #undef BLINK_AT_RAMP_MIDDLE -#define BATTCHECK_VpT - #define USE_DYNAMIC_UNDERCLOCKING #define RAMP_LENGTH 150 diff --git a/spaghetti-monster/anduril/version.h b/spaghetti-monster/anduril/version.h index 5afe62a..e896823 100644 --- a/spaghetti-monster/anduril/version.h +++ b/spaghetti-monster/anduril/version.h @@ -1 +1 @@ -#define VERSION_NUMBER "20210112" +#define VERSION_NUMBER "20210117" -- cgit v1.2.3 From 4dfe5e628823c478124a03e381ee6bcdcb9ca314 Mon Sep 17 00:00:00 2001 From: Gabriel Hart Date: Mon, 1 Feb 2021 10:33:43 -0600 Subject: Add RGB Aux functionality for 1-Series --- spaghetti-monster/anduril/version.h | 2 +- spaghetti-monster/fsm-misc.c | 63 ++++++++++++++++++++++++------------- 2 files changed, 43 insertions(+), 22 deletions(-) (limited to 'spaghetti-monster') diff --git a/spaghetti-monster/anduril/version.h b/spaghetti-monster/anduril/version.h index e896823..14502aa 100644 --- a/spaghetti-monster/anduril/version.h +++ b/spaghetti-monster/anduril/version.h @@ -1 +1 @@ -#define VERSION_NUMBER "20210117" +#define VERSION_NUMBER "20210201" diff --git a/spaghetti-monster/fsm-misc.c b/spaghetti-monster/fsm-misc.c index 7ba9b45..edd982a 100644 --- a/spaghetti-monster/fsm-misc.c +++ b/spaghetti-monster/fsm-misc.c @@ -112,27 +112,29 @@ void indicator_led(uint8_t lvl) { switch (lvl) { #ifdef AVRXMEGA3 // ATTINY816, 817, etc case 0: // indicator off - AUXLED_PORT.DIRSET = AUXLED_PIN; // set as output - AUXLED_PORT.OUTCLR = AUXLED_PIN; // set output low + AUXLED_PORT.DIRSET = (1 << AUXLED_PIN); // set as output + AUXLED_PORT.OUTCLR = (1 << AUXLED_PIN); // set output low #ifdef AUXLED2_PIN // second LED mirrors the first - AUXLED2_PORT.DIRSET = AUXLED2_PIN; // set as output - AUXLED2_PORT.OUTCLR = AUXLED2_PIN; // set output low + AUXLED2_PORT.DIRSET = (1 << AUXLED2_PIN); // set as output + AUXLED2_PORT.OUTCLR = (1 << AUXLED2_PIN); // set output low #endif break; case 1: // indicator low - AUXLED_PORT.DIRCLR = AUXLED_PIN; // set as input - AUXLED_PORT.AUXLED_CTRL = PORT_PULLUPEN_bm; // enable internal pull-up + AUXLED_PORT.DIRCLR = (1 << AUXLED_PIN); // set as input + // this resolves to PORTx.PINxCTRL = PORT_PULLUPEN_bm; + *((uint8_t *)&AUXLED_PORT + 0x10 + AUXLED_PIN) = PORT_PULLUPEN_bm; // enable internal pull-up #ifdef AUXLED2_PIN // second LED mirrors the first - AUXLED2_PORT.DIRCLR = AUXLE2D_PIN; // set as input - AUXLED2_PORT.AUXLED2_CTRL = PORT_PULLUPEN_bm; // enable internal pull-up + AUXLED2_PORT.DIRCLR = (1 << AUXLED2_PIN); // set as input + // this resolves to PORTx.PINxCTRL = PORT_PULLUPEN_bm; + *((uint8_t *)&AUXLED2_PORT + 0x10 + AUXLED2_PIN) = PORT_PULLUPEN_bm; // enable internal pull-up #endif break; default: // indicator high - AUXLED_PORT.DIRSET = AUXLED_PIN; // set as output - AUXLED_PORT.OUTSET = AUXLED_PIN; // set as high + AUXLED_PORT.DIRSET = (1 << AUXLED_PIN); // set as output + AUXLED_PORT.OUTSET = (1 << AUXLED_PIN); // set as high #ifdef AUXLED2_PIN // second LED mirrors the first - AUXLED2_PORT.DIRSET = AUXLED2_PIN; // set as output - AUXLED2_PORT.OUTSET = AUXLED2_PIN; // set as high + AUXLED2_PORT.DIRSET = (1 << AUXLED2_PIN); // set as output + AUXLED2_PORT.OUTSET = (1 << AUXLED2_PIN); // set as high #endif break; @@ -182,16 +184,17 @@ void button_led_set(uint8_t lvl) { #ifdef AVRXMEGA3 // ATTINY816, 817, etc case 0: // LED off - BUTTON_LED_PORT.DIRSET = BUTTON_LED_PIN; // set as output - BUTTON_LED_PORT.OUTCLR = BUTTON_LED_PIN; // set output low + BUTTON_LED_PORT.DIRSET = (1 << BUTTON_LED_PIN); // set as output + BUTTON_LED_PORT.OUTCLR = (1 << BUTTON_LED_PIN); // set output low break; case 1: // LED low - BUTTON_LED_PORT.DIRCLR = BUTTON_LED_PIN; // set as input - BUTTON_LED_PORT.BUTTON_LED_CTRL = PORT_PULLUPEN_bm; // enable internal pull-up + BUTTON_LED_PORT.DIRCLR = (1 << BUTTON_LED_PIN); // set as input + // this resolves to PORTx.PINxCTRL = PORT_PULLUPEN_bm; + *((uint8_t *)&BUTTON_LED_PORT + 0x10 + BUTTON_LED_PIN) = PORT_PULLUPEN_bm; // enable internal pull-up break; default: // LED high - BUTTON_LED_PORT.DIRSET = BUTTON_LED_PIN; // set as output - BUTTON_LED_PORT.OUTSET = BUTTON_LED_PIN; // set as high + BUTTON_LED_PORT.DIRSET = (1 << BUTTON_LED_PIN); // set as output + BUTTON_LED_PORT.OUTSET = (1 << BUTTON_LED_PIN); // set as high break; #else @@ -218,9 +221,6 @@ void button_led_set(uint8_t lvl) { #endif #ifdef USE_AUX_RGB_LEDS -#ifdef AVRXMEGA3 // ATTINY816, 817, etc -#error Function rgb_led_set in fsm-misc is currently not set up for the AVR 1-Series -#endif void rgb_led_set(uint8_t value) { // value: 0b00BBGGRR uint8_t pins[] = { AUXLED_R_PIN, AUXLED_G_PIN, AUXLED_B_PIN }; @@ -228,6 +228,24 @@ void rgb_led_set(uint8_t value) { uint8_t lvl = (value >> (i<<1)) & 0x03; uint8_t pin = pins[i]; switch (lvl) { + + #ifdef AVRXMEGA3 // ATTINY816, 817, etc + case 0: // LED off + AUXLED_RGB_PORT.DIRSET = (1 << pin); // set as output + AUXLED_RGB_PORT.OUTCLR = (1 << pin); // set output low + break; + case 1: // LED low + AUXLED_RGB_PORT.DIRCLR = (1 << pin); // set as input + // this resolves to PORTx.PINxCTRL = PORT_PULLUPEN_bm; + *((uint8_t *)&AUXLED_RGB_PORT + 0x10 + pin) = PORT_PULLUPEN_bm; // enable internal pull-up + break; + default: // LED high + AUXLED_RGB_PORT.DIRSET = (1 << pin); // set as output + AUXLED_RGB_PORT.OUTSET = (1 << pin); // set as high + break; + + #else + case 0: // LED off AUXLED_RGB_DDR &= 0xff ^ (1 << pin); AUXLED_RGB_PUE &= 0xff ^ (1 << pin); @@ -243,6 +261,9 @@ void rgb_led_set(uint8_t value) { AUXLED_RGB_PUE |= (1 << pin); AUXLED_RGB_PORT |= (1 << pin); break; + + #endif + } } } -- cgit v1.2.3