diff options
| author | Selene ToyKeeper | 2021-11-06 00:52:59 -0600 |
|---|---|---|
| committer | Selene ToyKeeper | 2021-11-06 00:52:59 -0600 |
| commit | 4f7d9b8614f4f98359d30305523629e379fac4f3 (patch) | |
| tree | 3a525163d6b4e105ab37168bab121ebd023f6f45 | |
| parent | merged gchart's SP10 Pro branch (diff) | |
| parent | Merge TKs changes through her commit 628 (diff) | |
| download | anduril-4f7d9b8614f4f98359d30305523629e379fac4f3.tar.gz anduril-4f7d9b8614f4f98359d30305523629e379fac4f3.tar.bz2 anduril-4f7d9b8614f4f98359d30305523629e379fac4f3.zip | |
merged gchart's recent changes
| -rw-r--r-- | hwdef-Sofirn_SP10-Pro.h | 2 | ||||
| -rw-r--r-- | hwdef-thefreeman-lin16dac.h | 109 | ||||
| -rw-r--r-- | spaghetti-monster/anduril/MODELS | 111 | ||||
| -rw-r--r-- | spaghetti-monster/anduril/Makefile | 8 | ||||
| -rw-r--r-- | spaghetti-monster/anduril/anduril-manual.txt | 8 | ||||
| -rw-r--r-- | spaghetti-monster/anduril/aux-leds.c | 2 | ||||
| -rw-r--r-- | spaghetti-monster/anduril/cfg-blf-lantern.h | 4 | ||||
| -rw-r--r-- | spaghetti-monster/anduril/cfg-blf-q8-t1616.h | 4 | ||||
| -rw-r--r-- | spaghetti-monster/anduril/cfg-blf-q8.h | 4 | ||||
| -rw-r--r-- | spaghetti-monster/anduril/cfg-thefreeman-lin16dac.h | 45 | ||||
| -rwxr-xr-x | spaghetti-monster/anduril/models.py | 71 | ||||
| -rw-r--r-- | spaghetti-monster/anduril/tint-ramping.c | 2 | ||||
| -rw-r--r-- | spaghetti-monster/fsm-ramping.c | 2 |
13 files changed, 298 insertions, 74 deletions
diff --git a/hwdef-Sofirn_SP10-Pro.h b/hwdef-Sofirn_SP10-Pro.h index 4691d04..5ed716d 100644 --- a/hwdef-Sofirn_SP10-Pro.h +++ b/hwdef-Sofirn_SP10-Pro.h @@ -54,7 +54,7 @@ PA1 : Boost Enable #define USE_VOLTAGE_DIVIDER // use a dedicated pin, not VCC, because VCC input is flattened #define DUAL_VOLTAGE_FLOOR 20 // for AA/14500 boost drivers, don't indicate low voltage if below this level -#define DUAL_VOLTAGE_LOW_LOW 8 // the lower voltage range's danger zone 0.8 volts (NiMH) +#define DUAL_VOLTAGE_LOW_LOW 7 // the lower voltage range's danger zone 0.7 volts (NiMH) #define ADMUX_VOLTAGE_DIVIDER ADC_MUXPOS_AIN9_gc // which ADC channel to read // Raw ADC readings at 4.4V and 2.2V diff --git a/hwdef-thefreeman-lin16dac.h b/hwdef-thefreeman-lin16dac.h new file mode 100644 index 0000000..0999c4c --- /dev/null +++ b/hwdef-thefreeman-lin16dac.h @@ -0,0 +1,109 @@ +#ifndef HWDEF_THEFREEMAN_LIN18_H +#define HWDEF_THEFREEMAN_LIN18_H + +/* thefreeman's Linear 16 driver using DAC control + +PA6 - DAC for LED brightness control +PA7 - Op-amp enable pin +PB5 - Aux LED +PB4 - Switch pin, internal pullup +PB3 - HDR control, set High to enable the high power channel, set Low for low power +Read voltage from VCC pin, has PFET so no drop + +*/ + + +#define LAYOUT_DEFINED + +#ifdef ATTINY +#undef ATTINY +#endif +#define ATTINY 1616 +#include <avr/io.h> + +#define PWM_CHANNELS 1 +#define USE_DYN_PWM // dynamic frequency and speed + +#ifndef SWITCH_PIN +#define SWITCH_PIN PIN4_bp +#define SWITCH_PORT VPORTB.IN +#define SWITCH_ISC_REG PORTB.PIN2CTRL +#define SWITCH_VECT PORTB_PORT_vect +#define SWITCH_INTFLG VPORTB.INTFLAGS +#endif + + +#define PWM1_LVL DAC0.DATA // use this for DAC voltage output + +// PWM parameters of both channels are tied together because they share a counter +#define PWM1_TOP VREF.CTRLA // holds the TOP value for for variable-resolution PWM + +// For enabling / disabling the HDR high-range channel +#define LED_ENABLE_PIN PIN3_bp +#define LED_ENABLE_PORT PORTB_OUT +#define LED_ENABLE_PIN_LEVEL_MIN 35 +#define LED_ENABLE_PIN_LEVEL_MAX 150 + +// For turning on and off the op-amp +#define LED2_ENABLE_PIN PIN7_bp +#define LED2_ENABLE_PORT PORTA_OUT + + +// average drop across diode on this hardware +#ifndef VOLTAGE_FUDGE_FACTOR +#define VOLTAGE_FUDGE_FACTOR 0 // using a PFET so no appreciable drop +#endif + +// lighted button +#ifndef AUXLED_PIN +#define AUXLED_PIN PIN5_bp +#define AUXLED_PORT PORTB +#endif + + +// with so many pins, doing this all with #ifdefs gets awkward... +// ... so just hardcode it in each hwdef file instead +inline void hwdef_setup() { + + // set up the system clock to run at 10 MHz instead of the default 3.33 MHz + // TODO: for this DAC controlled-light, try to decrease the clock speed or use the ULP + _PROTECTED_WRITE( CLKCTRL.MCLKCTRLB, CLKCTRL_PDIV_2X_gc | CLKCTRL_PEN_bm ); + + VPORTA.DIR = PIN6_bm | PIN7_bm; + VPORTB.DIR = PIN3_bm; + //VPORTC.DIR = 0b00000000; + + // enable pullups on the input pins to reduce power + PORTA.PIN0CTRL = PORT_PULLUPEN_bm; + PORTA.PIN1CTRL = PORT_PULLUPEN_bm; + PORTA.PIN2CTRL = PORT_PULLUPEN_bm; + PORTA.PIN3CTRL = PORT_PULLUPEN_bm; + PORTA.PIN4CTRL = PORT_PULLUPEN_bm; + PORTA.PIN5CTRL = PORT_PULLUPEN_bm; + //PORTA.PIN6CTRL = PORT_PULLUPEN_bm; // DAC ouput + //PORTA.PIN7CTRL = PORT_PULLUPEN_bm; // Op-amp enable pin + + PORTB.PIN0CTRL = PORT_PULLUPEN_bm; + PORTB.PIN1CTRL = PORT_PULLUPEN_bm; + PORTB.PIN2CTRL = PORT_PULLUPEN_bm; + //PORTB.PIN3CTRL = PORT_PULLUPEN_bm; // HDR channel selection + PORTB.PIN4CTRL = PORT_PULLUPEN_bm | PORT_ISC_BOTHEDGES_gc; // switch + //PORTB.PIN5CTRL = PORT_PULLUPEN_bm; // Aux LED + + PORTC.PIN0CTRL = PORT_PULLUPEN_bm; + PORTC.PIN1CTRL = PORT_PULLUPEN_bm; + PORTC.PIN2CTRL = PORT_PULLUPEN_bm; + PORTC.PIN3CTRL = PORT_PULLUPEN_bm; + + // set up the DAC + // https://ww1.microchip.com/downloads/en/DeviceDoc/ATtiny1614-16-17-DataSheet-DS40002204A.pdf + // DAC ranges from 0V to (255 * Vref) / 256 + VREF.CTRLA |= VREF_DAC0REFSEL_2V5_gc; // also VREF_DAC0REFSEL_0V55_gc and VREF_DAC0REFSEL_1V1_gc and VREF_DAC0REFSEL_2V5_gc + VREF.CTRLB |= VREF_DAC0REFEN_bm; + DAC0.CTRLA = DAC_ENABLE_bm | DAC_OUTEN_bm; + DAC0.DATA = 255; // set the output voltage + +} + + +#endif diff --git a/spaghetti-monster/anduril/MODELS b/spaghetti-monster/anduril/MODELS index 7a2c438..317bb6a 100644 --- a/spaghetti-monster/anduril/MODELS +++ b/spaghetti-monster/anduril/MODELS @@ -1,55 +1,58 @@ -Model numbers: -0111 emisar-d4 -0112 emisar-d4-219c -0113 emisar-d4v2 -0114 emisar-d4v2-219 -0115 emisar-d4v2-nofet -0121 emisar-d1 -0122 emisar-d1s -0123 emisar-d1v2 -0131 emisar-d4s -0132 emisar-d4s-219c -0133 emisar-d4sv2 -0134 emisar-d4sv2-219 -0135 emisar-d4sv2-tintramp -0136 emisar-d4sv2-tintramp-fet -0141 emisar-d18 -0142 emisar-d18-219 -0211 noctigon-kr4 -0212 noctigon-kr4-nofet -0213 noctigon-kr4-219 -0214 noctigon-kr4-219b -0251 noctigon-k1 -0252 noctigon-k1-sbt90 -0253 noctigon-k1-12v -0261 noctigon-k9.3 -0262 noctigon-k9.3-nofet -0263 noctigon-k9.3-219 -0265 noctigon-k9.3-tintramp-nofet -0266 noctigon-k9.3-tintramp-fet -0267 noctigon-k9.3-tintramp-219 -0311 fw3a -0312 fw3a-219 -0313 fw3a-nofet -0314 fw3x-lume1 -0321 blf-gt -0322 blf-gt-mini -0411 ff-rot66 -0412 ff-rot66-219 -0413 ff-rot66g2 -0421 ff-pl47 -0422 ff-pl47-219 -0423 ff-pl47g2 -0441 ff-e01 -0511 mateminco-mf01s -0521 mateminco-mf01-mini -0611 blf-q8 -0612 sofirn-sp36 -0613 blf-q8-t1616 -0614 sofirn-sp36-t1616 -0621 blf-lantern -0622 blf-lantern-t1616 -0631 sofirn-sp10-pro -1618 gchart-fet1-t1616 +Model Name MCU +----- ---- --- +0111 emisar-d4 attiny85 +0112 emisar-d4-219c attiny85 +0113 emisar-d4v2 attiny1634 +0114 emisar-d4v2-219 attiny1634 +0115 emisar-d4v2-nofet attiny1634 +0121 emisar-d1 attiny85 +0122 emisar-d1s attiny85 +0123 emisar-d1v2 attiny1634 +0131 emisar-d4s attiny85 +0132 emisar-d4s-219c attiny85 +0133 emisar-d4sv2 attiny1634 +0134 emisar-d4sv2-219 attiny1634 +0135 emisar-d4sv2-tintramp attiny1634 +0136 emisar-d4sv2-tintramp-fet attiny1634 +0141 emisar-d18 attiny85 +0142 emisar-d18-219 attiny85 +0211 noctigon-kr4 attiny1634 +0212 noctigon-kr4-nofet attiny1634 +0213 noctigon-kr4-219 attiny1634 +0214 noctigon-kr4-219b attiny1634 +0251 noctigon-k1 attiny1634 +0252 noctigon-k1-sbt90 attiny1634 +0253 noctigon-k1-12v attiny1634 +0261 noctigon-k9.3 attiny1634 +0262 noctigon-k9.3-nofet attiny1634 +0263 noctigon-k9.3-219 attiny1634 +0265 noctigon-k9.3-tintramp-nofet attiny1634 +0266 noctigon-k9.3-tintramp-fet attiny1634 +0267 noctigon-k9.3-tintramp-219 attiny1634 +0311 fw3a attiny85 +0312 fw3a-219 attiny85 +0313 fw3a-nofet attiny85 +0314 fw3x-lume1 attiny1634 +0321 blf-gt attiny85 +0322 blf-gt-mini attiny85 +0411 ff-rot66 attiny85 +0412 ff-rot66-219 attiny85 +0413 ff-rot66g2 attiny85 +0421 ff-pl47 attiny85 +0422 ff-pl47-219 attiny85 +0423 ff-pl47g2 attiny85 +0441 ff-e01 attiny85 +0511 mateminco-mf01s attiny85 +0521 mateminco-mf01-mini attiny85 +0611 blf-q8 attiny85 +0612 sofirn-sp36 attiny85 +0613 blf-q8-t1616 attiny1616 +0614 sofirn-sp36-t1616 attiny1616 +0621 blf-lantern attiny85 +0622 blf-lantern-t1616 attiny1616 +0631 sofirn-sp10s attiny1616 +1618 gchart-fet1-t1616 attiny1616 + Duplicates: -Missing: + +Missing:
\ No newline at end of file diff --git a/spaghetti-monster/anduril/Makefile b/spaghetti-monster/anduril/Makefile index d1e6b46..332f0f3 100644 --- a/spaghetti-monster/anduril/Makefile +++ b/spaghetti-monster/anduril/Makefile @@ -8,13 +8,7 @@ todo: @egrep 'TODO:|FIXME:' *.[ch] models: - @echo -n > MODELS - @echo 'Model numbers:' >> MODELS - @grep '^#define MODEL_NUMBER' cfg-*.h | perl -ne '/cfg-(.*)\.h:#define MODEL_NUMBER "(.*)"/ && print "$$2\t$$1\n";' | sort -n >> MODELS - @echo 'Duplicates:' >> MODELS - @cat cfg-*.h | grep '^#define MODEL_NUMBER' | sort | uniq -c | grep -v ' 1 ' || true >> MODELS - @echo 'Missing:' >> MODELS - @for f in cfg-*.h ; do grep --silent '^#define MODEL_NUMBER' $$f ; if [ "$$?" = "1" ] ; then echo " $$f" ; fi ; done >> MODELS + @./models.py > MODELS @cat MODELS .phony: clean todo diff --git a/spaghetti-monster/anduril/anduril-manual.txt b/spaghetti-monster/anduril/anduril-manual.txt index a8f3730..009e95e 100644 --- a/spaghetti-monster/anduril/anduril-manual.txt +++ b/spaghetti-monster/anduril/anduril-manual.txt @@ -173,8 +173,9 @@ There are four ways to access ramping mode when the light is off: While the light is on, a few actions are available: - 1C: Turn off. - - 2C: Go to or from the ceiling level. - (or if already at ceiling, and not in Simple UI, go to/from turbo) + - 2C: Go to or from the turbo level. + (or if it has regulated down, "bump" back up to turbo) + (turbo level / behavior is configurable) - 1H: Change brightness (up). If the button was released less than a second ago, or if it's already at the ceiling, it goes down instead. - 2H: Change brightness (down). @@ -760,8 +761,7 @@ Off Any 15+C Version check Ramp Any 1C Off Ramp Any 1H Ramp (up, with reversing) Ramp Any 2H Ramp (down) -Ramp Simple 2C Go to/from ceiling -Ramp Full 2C Go to/from ceiling (or turbo if at ceil already) +Ramp Any 2C Go to/from ceiling or turbo (configurable) Ramp Full 3C Change ramp style (smooth / stepped) Ramp Any 3H Tint ramping (on some lights) Ramp Full 3H Momentary turbo (on lights without tint ramping) diff --git a/spaghetti-monster/anduril/aux-leds.c b/spaghetti-monster/anduril/aux-leds.c index 3195fdc..a0a6d7a 100644 --- a/spaghetti-monster/anduril/aux-leds.c +++ b/spaghetti-monster/anduril/aux-leds.c @@ -64,7 +64,7 @@ uint8_t voltage_to_rgb() { 255, 6, // 7, R+G+B }; uint8_t volts = voltage; - if (volts < 29) return 0; + if (volts < VOLTAGE_LOW) return 0; uint8_t i; for (i = 0; volts >= levels[i]; i += 2) {} diff --git a/spaghetti-monster/anduril/cfg-blf-lantern.h b/spaghetti-monster/anduril/cfg-blf-lantern.h index ff28a98..a989ca4 100644 --- a/spaghetti-monster/anduril/cfg-blf-lantern.h +++ b/spaghetti-monster/anduril/cfg-blf-lantern.h @@ -53,8 +53,8 @@ #define SIMPLE_UI_CEIL RAMP_DISCRETE_CEIL #define SIMPLE_UI_STEPS RAMP_DISCRETE_STEPS -// also at Sofirn's request, enable 2 click turbo -#define USE_2C_MAX_TURBO +// also at Sofirn's request, enable 2 click turbo (Anduril 1 style) +#define DEFAULT_2C_STYLE 1 #define USE_SOS_MODE #define USE_SOS_MODE_IN_BLINKY_GROUP diff --git a/spaghetti-monster/anduril/cfg-blf-q8-t1616.h b/spaghetti-monster/anduril/cfg-blf-q8-t1616.h index 340faa1..30a3368 100644 --- a/spaghetti-monster/anduril/cfg-blf-q8-t1616.h +++ b/spaghetti-monster/anduril/cfg-blf-q8-t1616.h @@ -34,8 +34,8 @@ #define SIMPLE_UI_CEIL 150 #define SIMPLE_UI_STEPS 5 -// also at Sofirn's request, enable 2 click turbo -#define USE_2C_MAX_TURBO +// also at Sofirn's request, enable 2 click turbo (Anduril 1 style) +#define DEFAULT_2C_STYLE 1 // enable SOS in the blinkies group #define USE_SOS_MODE diff --git a/spaghetti-monster/anduril/cfg-blf-q8.h b/spaghetti-monster/anduril/cfg-blf-q8.h index 00bdd8a..6a5055c 100644 --- a/spaghetti-monster/anduril/cfg-blf-q8.h +++ b/spaghetti-monster/anduril/cfg-blf-q8.h @@ -33,8 +33,8 @@ #define SIMPLE_UI_CEIL 150 #define SIMPLE_UI_STEPS 5 -// also at Sofirn's request, enable 2 click turbo -#define USE_2C_MAX_TURBO +// also at Sofirn's request, enable 2 click turbo (Anduril 1 style) +#define DEFAULT_2C_STYLE 1 // enable SOS in the blinkies group #define USE_SOS_MODE diff --git a/spaghetti-monster/anduril/cfg-thefreeman-lin16dac.h b/spaghetti-monster/anduril/cfg-thefreeman-lin16dac.h new file mode 100644 index 0000000..64dcd8c --- /dev/null +++ b/spaghetti-monster/anduril/cfg-thefreeman-lin16dac.h @@ -0,0 +1,45 @@ +// thefreeman's Linear 16 driver using DAC control +#define MODEL_NUMBER "0000" // TBD +#include "hwdef-thefreeman-lin16dac.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 +// off mode: low (1) +// lockout: blinking (3) +#define INDICATOR_LED_DEFAULT_MODE ((3<<2) + 1) + +#undef BLINK_AT_RAMP_MIDDLE + +// We're abusing the Dynamic PWM functionality to set the VREF instead of PWM TOP. +// We don't want the Gradual functionality to mess with the PWM_TOP value. +#ifdef USE_SET_LEVEL_GRADUALLY +#undef USE_SET_LEVEL_GRADUALLY +#endif + +// level_calc.py ninth 2 150 7135 1 0.03 6.4 7135 1 6.3 1600 +#define RAMP_LENGTH 150 +#define USE_DYN_PWM + +// PWM1: DAC Data, PWM Tops: VREF selector +#define PWM1_LEVELS 25,25,33,41,41,50,58,66,75,83,92,108,117,133,150,167,192,209,234,58,64,71,80,90,99,110,121,134,149,163,180,198,218,241,1,1,1,1,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,5,5,6,6,7,7,8,8,9,10,11,11,12,13,14,15,16,18,19,20,22,23,25,26,28,30,32,34,36,39,41,44,47,50,53,56,59,63,67,71,75,79,84,89,94,100,105,112,118,124,131,139,146,154,163,172,181,191,201,212,223,234,246,57,60,63,66,69,73,76,80,84,88,93,97,102,107,112,117,123,129,135,141,147,154,161,169,176,184,193,201,210,220,229,239,250,255 +#define PWM_TOPS 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18 + +#define MAX_1x7135 34 +#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 123 + +// enable 2 click turbo +#define DEFAULT_2C_STYLE 1 diff --git a/spaghetti-monster/anduril/models.py b/spaghetti-monster/anduril/models.py new file mode 100755 index 0000000..1985352 --- /dev/null +++ b/spaghetti-monster/anduril/models.py @@ -0,0 +1,71 @@ +#!/usr/bin/env python + +import os +import re + +def main(args): + """models.py: scan build targets to generate the MODELS file + """ + + models = [] + + # load all cfg-*.h files + paths = os.listdir('.') + for p in paths: + if p.startswith('cfg-') and p.endswith('.h'): + m = load_cfg(p) + models.append(m) + + # sort by model number + foo = [(m.num, m.name, m) for m in models] + foo.sort() + models = [x[-1] for x in foo] + + fmt = '%s\t%-30s\t%s' + print(fmt % ('Model', 'Name', 'MCU')) + print(fmt % ('-----', '----', '---')) + for m in models: + print(fmt % (m.num, m.name, m.attiny)) + + print('\nDuplicates:') + for i, m in enumerate(models): + for m2 in models[i+1:]: + #if (m.num == m2.num) and (m is not m2): + if m.num == m2.num: + print('%s\t%s, %s' % (m.num, m.name, m2.name)) + + print('\nMissing:') + for m in models: + if not m.num: + print(m.name) + + +class Empty: + pass + + +def load_cfg(path): + m = Empty() + m.name, m.num, m.attiny = '', '', 'attiny85' + + m.name = path.replace('cfg-', '').replace('.h', '') + + num_pat = re.compile(r'#define\s+MODEL_NUMBER\s+"(\d+)"') + mcu_pat = re.compile(r'ATTINY:\s+(\d+)') + # TODO? use C preprocessor to generate more complete file to scan + with open(path) as fp: + for line in fp: + found = num_pat.search(line) + if found: + m.num = found.group(1) + found = mcu_pat.search(line) + if found: + m.attiny = 'attiny' + found.group(1) + + return m + + +if __name__ == "__main__": + import sys + main(sys.argv[1:]) + diff --git a/spaghetti-monster/anduril/tint-ramping.c b/spaghetti-monster/anduril/tint-ramping.c index 0b077ef..aa9b1f6 100644 --- a/spaghetti-monster/anduril/tint-ramping.c +++ b/spaghetti-monster/anduril/tint-ramping.c @@ -31,7 +31,7 @@ uint8_t tint_ramping_state(Event event, uint16_t arg) { if (! arg) { tint = !tint; set_level(actual_level); - blink_once(); + //blink_once(); // unnecessary, and kind of annoying on moon } return EVENT_HANDLED; } diff --git a/spaghetti-monster/fsm-ramping.c b/spaghetti-monster/fsm-ramping.c index e8fcde7..05c2e0e 100644 --- a/spaghetti-monster/fsm-ramping.c +++ b/spaghetti-monster/fsm-ramping.c @@ -267,7 +267,9 @@ void gradual_tick() { ) { //actual_level = gt + 1; + uint8_t orig = gradual_target; set_level(gt + 1); + gradual_target = orig; } // is handled in set_level() //#ifdef USE_TINT_RAMPING |
