diff options
| author | Selene ToyKeeper | 2019-11-25 18:46:03 -0700 |
|---|---|---|
| committer | Selene ToyKeeper | 2019-11-25 18:46:03 -0700 |
| commit | 2cf2c42678a5cd92bbfa3096101ceaea984df1dd (patch) | |
| tree | 32931a8fd5f65b5ba93a972c43d35f160372b8ce | |
| parent | increased Noctigon K1's default temperature limit to 55 C (diff) | |
| parent | enabled muggle mode again in all build targets, since it fits now (diff) | |
| download | anduril-2cf2c42678a5cd92bbfa3096101ceaea984df1dd.tar.gz anduril-2cf2c42678a5cd92bbfa3096101ceaea984df1dd.tar.bz2 anduril-2cf2c42678a5cd92bbfa3096101ceaea984df1dd.zip | |
merged upstream fsm branch
Diffstat (limited to '')
| -rwxr-xr-x | bin/build.sh | 2 | ||||
| -rw-r--r-- | hwdef-Emisar_D4v2.h | 10 | ||||
| -rw-r--r-- | spaghetti-monster/anduril/anduril.c | 33 | ||||
| -rw-r--r-- | spaghetti-monster/anduril/cfg-blf-q8.h | 5 | ||||
| -rw-r--r-- | spaghetti-monster/anduril/cfg-emisar-d18.h | 6 | ||||
| -rw-r--r-- | spaghetti-monster/anduril/cfg-emisar-d4v2.h | 4 | ||||
| -rw-r--r-- | spaghetti-monster/anduril/cfg-mateminco-mf01-mini.h | 6 | ||||
| -rw-r--r-- | spaghetti-monster/anduril/cfg-mateminco-mf01s.h | 6 | ||||
| -rw-r--r-- | spaghetti-monster/fsm-misc.c | 23 | ||||
| -rw-r--r-- | spaghetti-monster/fsm-misc.h | 6 | ||||
| -rw-r--r-- | spaghetti-monster/fsm-ramping.c | 3 |
11 files changed, 73 insertions, 31 deletions
diff --git a/bin/build.sh b/bin/build.sh index fbb24ea..3992c38 100755 --- a/bin/build.sh +++ b/bin/build.sh @@ -14,7 +14,7 @@ export PROGRAM=$1 ; shift export MCU=attiny$ATTINY export CC=avr-gcc export OBJCOPY=avr-objcopy -export CFLAGS="-Wall -g -Os -mmcu=$MCU -c -std=gnu99 -fgnu89-inline -DATTINY=$ATTINY -I.. -I../.. -I../../.. -fshort-enums" +export CFLAGS="-Wall -g -Os -mmcu=$MCU -c -std=gnu99 -fgnu89-inline -fwhole-program -DATTINY=$ATTINY -I.. -I../.. -I../../.. -fshort-enums" export OFLAGS="-Wall -g -Os -mmcu=$MCU" export LDFLAGS="-fgnu89-inline" export OBJCOPYFLAGS='--set-section-flags=.eeprom=alloc,load --change-section-lma .eeprom=0 --no-change-warnings -O ihex' diff --git a/hwdef-Emisar_D4v2.h b/hwdef-Emisar_D4v2.h index 0460fad..addf429 100644 --- a/hwdef-Emisar_D4v2.h +++ b/hwdef-Emisar_D4v2.h @@ -9,7 +9,7 @@ * 3 PA4 green aux LED * 4 PA3 blue aux LED * 5 PA2 e-switch - * 6 PA1 (none) + * 6 PA1 button LED * 7 PA0 (none) * 8 GND GND * 9 VCC VCC @@ -65,17 +65,23 @@ #define AUXLED_RGB_DDR DDRA // DDRA or DDRB or DDRC #define AUXLED_RGB_PUE PUEA // PUEA or PUEB or PUEC +#define BUTTON_LED_PIN PA1 // pin 6 +#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 // 7135 DDRB = (1 << PWM1_PIN); - // FET, aux R/G/B + // FET, 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 diff --git a/spaghetti-monster/anduril/anduril.c b/spaghetti-monster/anduril/anduril.c index 5c5a6ee..580609b 100644 --- a/spaghetti-monster/anduril/anduril.c +++ b/spaghetti-monster/anduril/anduril.c @@ -2366,7 +2366,13 @@ void rgb_led_update(uint8_t mode, uint8_t arg) { // turn off aux LEDs when battery is empty // (but if voltage==0, that means we just booted and don't know yet) uint8_t volts = voltage; // save a few bytes by caching volatile value - if ((volts) && (volts < VOLTAGE_LOW)) { rgb_led_set(0); return; } + if ((volts) && (volts < VOLTAGE_LOW)) { + rgb_led_set(0); + #ifdef USE_BUTTON_LED + button_led_set(0); + #endif + return; + } uint8_t pattern = (mode>>4); // off, low, high, blinking, ... more? uint8_t color = mode & 0x0f; @@ -2411,17 +2417,34 @@ void rgb_led_update(uint8_t mode, uint8_t arg) { frame = (frame + 1) % sizeof(animation); pattern = animation[frame]; } + uint8_t result; + #ifdef USE_BUTTON_LED + uint8_t button_led_result; + #endif switch (pattern) { case 0: // off - rgb_led_set(0); + result = 0; + #ifdef USE_BUTTON_LED + button_led_result = 0; + #endif break; case 1: // low - rgb_led_set(actual_color); + result = actual_color; + #ifdef USE_BUTTON_LED + button_led_result = 1; + #endif break; - case 2: // high - rgb_led_set(actual_color << 1); + default: // high + result = (actual_color << 1); + #ifdef USE_BUTTON_LED + button_led_result = 2; + #endif break; } + rgb_led_set(result); + #ifdef USE_BUTTON_LED + button_led_set(button_led_result); + #endif } void rgb_led_voltage_readout(uint8_t bright) { diff --git a/spaghetti-monster/anduril/cfg-blf-q8.h b/spaghetti-monster/anduril/cfg-blf-q8.h index 31c22ff..970fedb 100644 --- a/spaghetti-monster/anduril/cfg-blf-q8.h +++ b/spaghetti-monster/anduril/cfg-blf-q8.h @@ -13,11 +13,6 @@ // lockout: blinking (3) #define INDICATOR_LED_DEFAULT_MODE ((3<<2) + 2) -// doesn't quite fit -//#ifdef USE_MUGGLE_MODE -//#undef USE_MUGGLE_MODE -//#endif - // copied from Emisar D4 ramp // ../../bin/level_calc.py 1 65 7135 1 0.8 150 // ... mixed with this: diff --git a/spaghetti-monster/anduril/cfg-emisar-d18.h b/spaghetti-monster/anduril/cfg-emisar-d18.h index 02e8f01..16fbacd 100644 --- a/spaghetti-monster/anduril/cfg-emisar-d18.h +++ b/spaghetti-monster/anduril/cfg-emisar-d18.h @@ -16,12 +16,6 @@ #define USE_TENCLICK_THERMAL_CONFIG -// save space, and remove a mode which doesn't make much sense on this light -#ifdef USE_MUGGLE_MODE -#undef USE_MUGGLE_MODE -#endif - - // level_calc.py seventh 3 150 7135 1 1.4 117.99 7135 6 1 1706.86 FET 3 10 13000 // (designed to make 1x hit at level 50, and Nx hit at level 100) #define RAMP_LENGTH 150 diff --git a/spaghetti-monster/anduril/cfg-emisar-d4v2.h b/spaghetti-monster/anduril/cfg-emisar-d4v2.h index 0db1062..3da877e 100644 --- a/spaghetti-monster/anduril/cfg-emisar-d4v2.h +++ b/spaghetti-monster/anduril/cfg-emisar-d4v2.h @@ -4,7 +4,11 @@ // this light has three aux LED channels: R, G, B #define USE_AUX_RGB_LEDS +// it also has an independent LED in the button +#define USE_BUTTON_LED // the aux LEDs are front-facing, so turn them off while main LEDs are on +// TODO: the whole "indicator LED" thing needs to be refactored into +// "aux LED(s)" and "button LED(s)" since they work a bit differently #ifdef USE_INDICATOR_LED_WHILE_RAMPING #undef USE_INDICATOR_LED_WHILE_RAMPING #endif diff --git a/spaghetti-monster/anduril/cfg-mateminco-mf01-mini.h b/spaghetti-monster/anduril/cfg-mateminco-mf01-mini.h index a1d366d..bbf751b 100644 --- a/spaghetti-monster/anduril/cfg-mateminco-mf01-mini.h +++ b/spaghetti-monster/anduril/cfg-mateminco-mf01-mini.h @@ -15,12 +15,6 @@ #define INDICATOR_LED_DEFAULT_MODE ((3<<2) + 1) -// doesn't quite fit -#ifdef USE_MUGGLE_MODE -#undef USE_MUGGLE_MODE -#endif - - // don't blink during ramp, it's irrelevant and annoying on this light #define BLINK_AT_RAMP_CEILING #undef BLINK_AT_RAMP_MIDDLE diff --git a/spaghetti-monster/anduril/cfg-mateminco-mf01s.h b/spaghetti-monster/anduril/cfg-mateminco-mf01s.h index 22b497b..0585b38 100644 --- a/spaghetti-monster/anduril/cfg-mateminco-mf01s.h +++ b/spaghetti-monster/anduril/cfg-mateminco-mf01s.h @@ -14,12 +14,6 @@ #define INDICATOR_LED_DEFAULT_MODE ((3<<2) + 1) -// doesn't quite fit -//#ifdef USE_MUGGLE_MODE -//#undef USE_MUGGLE_MODE -//#endif - - // don't blink during ramp, it's irrelevant and annoying on this light #define BLINK_AT_RAMP_CEILING #undef BLINK_AT_RAMP_MIDDLE diff --git a/spaghetti-monster/fsm-misc.c b/spaghetti-monster/fsm-misc.c index 0a3cdca..8da7b5b 100644 --- a/spaghetti-monster/fsm-misc.c +++ b/spaghetti-monster/fsm-misc.c @@ -148,6 +148,29 @@ void indicator_led_auto() { */ #endif // USE_INDICATOR_LED +#ifdef USE_BUTTON_LED +// TODO: Refactor this and RGB LED function to merge code and save space +void button_led_set(uint8_t lvl) { + switch (lvl) { + case 0: // LED off + BUTTON_LED_DDR &= 0xff ^ (1 << BUTTON_LED_PIN); + BUTTON_LED_PUE &= 0xff ^ (1 << BUTTON_LED_PIN); + BUTTON_LED_PORT &= 0xff ^ (1 << BUTTON_LED_PIN); + break; + case 1: // LED low + BUTTON_LED_DDR &= 0xff ^ (1 << BUTTON_LED_PIN); + BUTTON_LED_PUE |= (1 << BUTTON_LED_PIN); + BUTTON_LED_PORT |= (1 << BUTTON_LED_PIN); + break; + default: // LED high + BUTTON_LED_DDR |= (1 << BUTTON_LED_PIN); + BUTTON_LED_PUE |= (1 << BUTTON_LED_PIN); + BUTTON_LED_PORT |= (1 << BUTTON_LED_PIN); + break; + } +} +#endif + #ifdef USE_AUX_RGB_LEDS void rgb_led_set(uint8_t value) { // value: 0b00BBGGRR diff --git a/spaghetti-monster/fsm-misc.h b/spaghetti-monster/fsm-misc.h index a39d31a..66d31ba 100644 --- a/spaghetti-monster/fsm-misc.h +++ b/spaghetti-monster/fsm-misc.h @@ -43,10 +43,16 @@ uint8_t blink(uint8_t num, uint8_t speed); */ #ifdef USE_INDICATOR_LED +// FIXME: Remove this, replace with button_led() // lvl: 0=off, 1=low, 2=high void indicator_led(uint8_t lvl); #endif +#ifdef USE_BUTTON_LED +// lvl: 0=off, 1=low, 2=high +void button_led_set(uint8_t lvl); +#endif + #ifdef USE_AUX_RGB_LEDS // value: 0b00BBGGRR // each pair of bits: 0=off, 1=low, 2=high diff --git a/spaghetti-monster/fsm-ramping.c b/spaghetti-monster/fsm-ramping.c index 7bee07e..ca93350 100644 --- a/spaghetti-monster/fsm-ramping.c +++ b/spaghetti-monster/fsm-ramping.c @@ -46,6 +46,9 @@ void set_level(uint8_t level) { #endif #ifdef USE_AUX_RGB_LEDS rgb_led_set(0); + #ifdef USE_BUTTON_LED + button_led_set((level > 0) + (level > MAX_1x7135)); + #endif #endif } #endif |
