diff options
| -rw-r--r-- | README | 54 | ||||
| -rwxr-xr-x | bin/build.sh | 11 | ||||
| -rwxr-xr-x | bin/flash-tiny1616.sh | 13 | ||||
| -rw-r--r-- | hwdef-BLF_Q8-T1616.h | 19 | ||||
| -rw-r--r-- | hwdef-Sofirn_SP10S.h | 20 | ||||
| -rw-r--r-- | hwdef-gchart-fet1-t1616.h (renamed from hwdef-gchart-fet1-t16.h) | 26 | ||||
| -rw-r--r-- | spaghetti-monster/anduril/BRANDS | 2 | ||||
| -rw-r--r-- | spaghetti-monster/anduril/MODELS | 10 | ||||
| -rw-r--r-- | spaghetti-monster/anduril/anduril-manual.txt | 2 | ||||
| -rw-r--r-- | spaghetti-monster/anduril/cfg-blf-lantern-t1616.h | 2 | ||||
| -rw-r--r-- | spaghetti-monster/anduril/cfg-blf-q8-t1616.h | 2 | ||||
| -rw-r--r-- | spaghetti-monster/anduril/cfg-gchart-fet1-t1616.h (renamed from spaghetti-monster/anduril/cfg-gchart-fet1-t16.h) | 7 | ||||
| -rw-r--r-- | spaghetti-monster/anduril/cfg-sofirn-sp10s.h | 2 | ||||
| -rw-r--r-- | spaghetti-monster/anduril/cfg-sofirn-sp36-t1616.h | 2 | ||||
| -rw-r--r-- | spaghetti-monster/anduril/off-mode.c | 5 | ||||
| -rw-r--r-- | spaghetti-monster/anduril/version.h | 5 | ||||
| -rw-r--r-- | spaghetti-monster/fsm-misc.c | 11 | ||||
| -rw-r--r-- | spaghetti-monster/fsm-pcint.c | 26 | ||||
| -rw-r--r-- | tk-attiny.h | 1 |
19 files changed, 153 insertions, 67 deletions
@@ -115,3 +115,57 @@ build Crescendo for an attiny25-based driver and then flash it: ../../bin/flash-tiny25.sh crescendo.hex Other useful tools are in bin/ too, so they might be worth a look. + + +ATtiny Series 1 (tiny1616) Support +================================== + +As of early 2021, the Debian packages for gcc-avr and avrdude do not include +support for the Tiny1 series chips. Extra steps are required to get these +working. + + - Download the Atmel ATtiny Series Device Support pack: + http://packs.download.atmel.com/ + + - Unzip the pack somewhere on your build computer + + - Set ATTINY_DFP=/path/to/where/you/unzipped/the/pack + (either in your shell, or in this repo's bin/build.sh script) + + export ATTINY_DFP=$HOME/src/torches/atmel/attiny-dfp + + - Make sure you're using gcc-avr 1:5.4.0+Atmel3.6.2 or newer. + 3.6.1 will not work. It gives errors like: + /usr/lib/gcc/avr/5.4.0/../../../avr/bin/ld: address 0x80381e of anduril.elf section `.data' is not within region `data' + This requires debian/bullseye or newer; buster has 3.6.1. + +This should at least allow the code to compile. + +Some extra steps are also needed to make flashing (avrdude) work: + + - Get an AVR jtag2 device. + The one I'm using is: "HWAYEH AVR JTAG ICE Version 2.0" + Connect the cables: + - GND = - + - Vtref = + + - nSRST = R (reset/UPDI) + + - Flash the jtag2 device with the relevant firmware: + https://github.com/ElTangas/jtag2updi/tree/master/tools/avrjtagicev2 + + - Get an avrdude.conf which supports jtag2updi: + + - Download avrdude.conf from https://github.com/ElTangas/jtag2updi + and put it in /etc + + - Or grab the source and set an environment variable: + + cd ~/src/torches/avrdude + git clone https://github.com/ElTangas/jtag2updi + export AVRDUDE_CONF="-C$HOME/src/torches/avrdude/jtag2updi/avrdude.conf" + + - Maybe configure which USB serial port to use too: + export AVRDUDE_TTYUSB="/dev/ttyUSB2" + +Afterward, flashing should work. You may need to unplug and replug the jtag2 +USB device between uses though, since it may stop responding after each use. diff --git a/bin/build.sh b/bin/build.sh index 6c21e30..c733320 100755 --- a/bin/build.sh +++ b/bin/build.sh @@ -11,12 +11,17 @@ fi export ATTINY=$1 ; shift export PROGRAM=$1 ; shift + +# path to the Atmel ATtiny device family pack: (for attiny1616 support) +# http://packs.download.atmel.com/ +if [ -z "$ATTINY_DFP" ]; then export ATTINY_DFP=~/avr/attiny_dfp ; fi + export MCU=attiny$ATTINY -export DFP=~/avr/attiny_dfp export CC=avr-gcc export OBJCOPY=avr-objcopy -export CFLAGS="-Wall -g -Os -mmcu=$MCU -c -std=gnu99 -fgnu89-inline -fwhole-program -DATTINY=$ATTINY -I.. -I../.. -I../../.. -fshort-enums -B $DFP/gcc/dev/$MCU/ -I $DFP/include/" -export OFLAGS="-Wall -g -Os -mmcu=$MCU -B $DFP/gcc/dev/$MCU/ -I $DFP/include/" +export DFPFLAGS="-B $ATTINY_DFP/gcc/dev/$MCU/ -I $ATTINY_DFP/include/" +export CFLAGS="-Wall -g -Os -mmcu=$MCU -c -std=gnu99 -fgnu89-inline -fwhole-program -DATTINY=$ATTINY -I.. -I../.. -I../../.. -fshort-enums $DFPFLAGS" +export OFLAGS="-Wall -g -Os -mmcu=$MCU $DFPFLAGS" export LDFLAGS="-fgnu89-inline" export OBJCOPYFLAGS='--set-section-flags=.eeprom=alloc,load --change-section-lma .eeprom=0 --no-change-warnings -O ihex' export OBJS=$PROGRAM.o diff --git a/bin/flash-tiny1616.sh b/bin/flash-tiny1616.sh index 31c8406..44d716c 100755 --- a/bin/flash-tiny1616.sh +++ b/bin/flash-tiny1616.sh @@ -1,3 +1,14 @@ #/bin/sh FIRMWARE=$1 -avrdude -c jtag2updi -P /dev/ttyUSB0 -p t1616 -u -Uflash:w:$FIRMWARE
\ No newline at end of file +if [ -z "$AVRDUDE_TTYUSB" ]; then AVRDUDE_TTYUSB=/dev/ttyUSB0 ; fi + +# In your shell config: +# from https://github.com/ElTangas/jtag2updi ... +# export AVRDUDE_CONF="-C$HOME/path/to/jtag2updi/avrdude.conf" +# export AVRDUDE_TTYUSB="/dev/ttyUSB2" + +avrdude $AVRDUDE_CONF \ + -c jtag2updi \ + -P $AVRDUDE_TTYUSB \ + -p t1616 \ + -u -Uflash:w:$FIRMWARE diff --git a/hwdef-BLF_Q8-T1616.h b/hwdef-BLF_Q8-T1616.h index 6dfb4ab..2a0e6ff 100644 --- a/hwdef-BLF_Q8-T1616.h +++ b/hwdef-BLF_Q8-T1616.h @@ -24,7 +24,7 @@ Driver pinout: #define PWM_CHANNELS 2 #ifndef SWITCH_PIN -#define SWITCH_PIN PIN5_bp +#define SWITCH_PIN PIN5_bp #define SWITCH_PORT VPORTA.IN #define SWITCH_ISC_REG PORTA.PIN2CTRL #define SWITCH_VECT PORTA_PORT_vect @@ -34,13 +34,13 @@ Driver pinout: // 7135 channel #ifndef PWM1_PIN -#define PWM1_PIN PB1 // +#define PWM1_PIN PB1 // #define PWM1_LVL TCA0.SINGLE.CMP1 // CMP1 is the output compare register for PB1 #endif // FET channel #ifndef PWM2_PIN -#define PWM2_PIN PB0 // +#define PWM2_PIN PB0 // #define PWM2_LVL TCA0.SINGLE.CMP0 // CMP0 is the output compare register for PB0 #endif @@ -61,8 +61,8 @@ Driver pinout: // ... so just hardcode it in each hwdef file instead inline void hwdef_setup() { - // set up the system clock to run at 5 MHz instead of the default 3.33 MHz - _PROTECTED_WRITE( CLKCTRL.MCLKCTRLB, CLKCTRL_PDIV_4X_gc | CLKCTRL_PEN_bm ); + // set up the system clock to run at 5 MHz instead of the default 3.33 MHz + _PROTECTED_WRITE( CLKCTRL.MCLKCTRLB, CLKCTRL_PDIV_4X_gc | CLKCTRL_PEN_bm ); //VPORTA.DIR = ...; VPORTB.DIR = PIN0_bm | PIN1_bm | PIN5_bm; // Outputs: Aux LED and PWMs @@ -77,20 +77,21 @@ inline void hwdef_setup() { PORTA.PIN5CTRL = PORT_PULLUPEN_bm | PORT_ISC_BOTHEDGES_gc; // eSwitch PORTA.PIN6CTRL = PORT_PULLUPEN_bm; PORTA.PIN7CTRL = PORT_PULLUPEN_bm; - + //PORTB.PIN0CTRL = PORT_PULLUPEN_bm; // FET channel //PORTB.PIN1CTRL = PORT_PULLUPEN_bm; // 7135 channel PORTB.PIN2CTRL = PORT_PULLUPEN_bm; PORTB.PIN3CTRL = PORT_PULLUPEN_bm; PORTB.PIN4CTRL = PORT_PULLUPEN_bm; //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 PWM + + // set up the PWM + // TODO: add references to MCU documentation TCA0.SINGLE.CTRLB = TCA_SINGLE_CMP0EN_bm | TCA_SINGLE_CMP1EN_bm | TCA_SINGLE_WGMODE_SINGLESLOPE_gc; TCA0.SINGLE.PER = 255; TCA0.SINGLE.CTRLA = TCA_SINGLE_CLKSEL_DIV1_gc | TCA_SINGLE_ENABLE_bm; diff --git a/hwdef-Sofirn_SP10S.h b/hwdef-Sofirn_SP10S.h index 75d79a1..0ee3332 100644 --- a/hwdef-Sofirn_SP10S.h +++ b/hwdef-Sofirn_SP10S.h @@ -1,6 +1,8 @@ #ifndef HWDEF_SOFIRN_SP10S_H #define HWDEF_SOFIRN_SP10S_H +// TODO: rename to sofirn-sp10s-gchart? + /* gChart's PIC12 to ATTINY1616 v1 adapter for the SP10S https://oshpark.com/shared_projects/b4IZEGSy @@ -34,7 +36,7 @@ ATTINY1616 Mapping: #include <avr/io.h> #ifndef SWITCH_PIN -#define SWITCH_PIN 3 +#define SWITCH_PIN 3 #define SWITCH_PORT VPORTB.IN #define SWITCH_ISC_REG PORTB.PIN3CTRL #define SWITCH_VECT PORTB_PORT_vect @@ -81,14 +83,13 @@ ATTINY1616 Mapping: // ... so just hardcode it in each hwdef file instead inline void hwdef_setup() { - // set up the system clock to run at 5 MHz instead of the default 3.33 MHz - _PROTECTED_WRITE( CLKCTRL.MCLKCTRLB, CLKCTRL_PDIV_4X_gc | CLKCTRL_PEN_bm ); + // set up the system clock to run at 5 MHz instead of the default 3.33 MHz + _PROTECTED_WRITE( CLKCTRL.MCLKCTRLB, CLKCTRL_PDIV_4X_gc | CLKCTRL_PEN_bm ); VPORTA.DIR = PIN1_bm; // Boost enable pin VPORTB.DIR = PIN0_bm | PIN5_bm; // PWM pins as output //VPORTC.DIR = ...; - // enable pullups on the input pins to reduce power PORTA.PIN0CTRL = PORT_PULLUPEN_bm; //PORTA.PIN1CTRL = PORT_PULLUPEN_bm; // Boost enable pin @@ -98,21 +99,22 @@ inline void hwdef_setup() { PORTA.PIN5CTRL = PORT_PULLUPEN_bm; PORTA.PIN6CTRL = PORT_PULLUPEN_bm; PORTA.PIN7CTRL = PORT_PULLUPEN_bm; - + //PORTB.PIN0CTRL = PORT_PULLUPEN_bm; // Big PWM channel PORTB.PIN1CTRL = PORT_PULLUPEN_bm; PORTB.PIN2CTRL = PORT_PULLUPEN_bm; PORTB.PIN3CTRL = PORT_PULLUPEN_bm | PORT_ISC_BOTHEDGES_gc; // Switch //PORTB.PIN4CTRL = PORT_PULLUPEN_bm; // Voltage divider //PORTB.PIN5CTRL = PORT_PULLUPEN_bm; // Small PWM channel - + //PORTC.PIN0CTRL = PORT_PULLUPEN_bm; connected to the ADC via airwire PORTC.PIN1CTRL = PORT_PULLUPEN_bm; PORTC.PIN2CTRL = PORT_PULLUPEN_bm; PORTC.PIN3CTRL = PORT_PULLUPEN_bm; - - // set up the PWM - PORTMUX.CTRLC = PORTMUX_TCA02_ALTERNATE_gc; // Use alternate pin for TCA0:WO2 + + // set up the PWM + // TODO: add references to MCU documentation + PORTMUX.CTRLC = PORTMUX_TCA02_ALTERNATE_gc; // Use alternate pin for TCA0:WO2 TCA0.SINGLE.CTRLB = TCA_SINGLE_CMP0EN_bm | TCA_SINGLE_CMP2EN_bm | TCA_SINGLE_WGMODE_SINGLESLOPE_gc; TCA0.SINGLE.PER = 255; TCA0.SINGLE.CTRLA = TCA_SINGLE_CLKSEL_DIV1_gc | TCA_SINGLE_ENABLE_bm; diff --git a/hwdef-gchart-fet1-t16.h b/hwdef-gchart-fet1-t1616.h index e8fd11c..365ecd7 100644 --- a/hwdef-gchart-fet1-t16.h +++ b/hwdef-gchart-fet1-t1616.h @@ -1,5 +1,5 @@ -#ifndef HWDEF_GCH_FET1_T16_H -#define HWDEF_GCH_FET1_T16_H +#ifndef HWDEF_GCH_FET1_T1616_H +#define HWDEF_GCH_FET1_T1616_H /* gChart's custom FET+1 driver layout @@ -23,7 +23,7 @@ Read voltage from VCC pin, has diode with ~0.4v drop #define PWM_CHANNELS 2 #ifndef SWITCH_PIN -#define SWITCH_PIN PIN2_bp +#define SWITCH_PIN PIN2_bp #define SWITCH_PORT VPORTB.IN #define SWITCH_ISC_REG PORTB.PIN2CTRL #define SWITCH_VECT PORTB_PORT_vect @@ -33,13 +33,13 @@ Read voltage from VCC pin, has diode with ~0.4v drop // 7135 channel #ifndef PWM1_PIN -#define PWM1_PIN PB1 // +#define PWM1_PIN PB1 // #define PWM1_LVL TCA0.SINGLE.CMP1 // CMP1 is the output compare register for PB1 #endif // FET channel #ifndef PWM2_PIN -#define PWM2_PIN PB0 // +#define PWM2_PIN PB0 // #define PWM2_LVL TCA0.SINGLE.CMP0 // CMP0 is the output compare register for PB0 #endif @@ -60,8 +60,8 @@ Read voltage from VCC pin, has diode with ~0.4v drop // ... so just hardcode it in each hwdef file instead inline void hwdef_setup() { - // set up the system clock to run at 5 MHz instead of the default 3.33 MHz - _PROTECTED_WRITE( CLKCTRL.MCLKCTRLB, CLKCTRL_PDIV_4X_gc | CLKCTRL_PEN_bm ); + // set up the system clock to run at 5 MHz instead of the default 3.33 MHz + _PROTECTED_WRITE( CLKCTRL.MCLKCTRLB, CLKCTRL_PDIV_4X_gc | CLKCTRL_PEN_bm ); //VPORTA.DIR = 0b00000010; VPORTB.DIR = PIN0_bm | PIN1_bm | PIN3_bm; @@ -76,20 +76,24 @@ inline void hwdef_setup() { PORTA.PIN5CTRL = PORT_PULLUPEN_bm; PORTA.PIN6CTRL = PORT_PULLUPEN_bm; PORTA.PIN7CTRL = PORT_PULLUPEN_bm; - + //PORTB.PIN0CTRL = PORT_PULLUPEN_bm; // FET channel //PORTB.PIN1CTRL = PORT_PULLUPEN_bm; // 7135 channel PORTB.PIN2CTRL = PORT_PULLUPEN_bm | PORT_ISC_BOTHEDGES_gc; // switch //PORTB.PIN3CTRL = PORT_PULLUPEN_bm; // Aux LED PORTB.PIN4CTRL = PORT_PULLUPEN_bm; PORTB.PIN5CTRL = PORT_PULLUPEN_bm; - + PORTC.PIN0CTRL = PORT_PULLUPEN_bm; PORTC.PIN1CTRL = PORT_PULLUPEN_bm; PORTC.PIN2CTRL = PORT_PULLUPEN_bm; PORTC.PIN3CTRL = PORT_PULLUPEN_bm; - - // set up the PWM + + // set up the PWM + // TODO: add references to MCU documentation + // TODO: measure 5 MHz fast PWM vs 10 MHz phase-correct, to see if it + // still has issues at 0/255 and 255/255 like older models did + // (and maybe switch to phase-correct@10MHz) TCA0.SINGLE.CTRLB = TCA_SINGLE_CMP0EN_bm | TCA_SINGLE_CMP1EN_bm | TCA_SINGLE_WGMODE_SINGLESLOPE_gc; TCA0.SINGLE.PER = 255; TCA0.SINGLE.CTRLA = TCA_SINGLE_CLKSEL_DIV1_gc | TCA_SINGLE_ENABLE_bm; diff --git a/spaghetti-monster/anduril/BRANDS b/spaghetti-monster/anduril/BRANDS index acd385e..4e73002 100644 --- a/spaghetti-monster/anduril/BRANDS +++ b/spaghetti-monster/anduril/BRANDS @@ -7,4 +7,4 @@ Lumintop 0300 - 0399 Fireflies 0400 - 0499 Mateminco 0500 - 0599 Sofirn 0600 - 0699 -gChart 1600 - 1699
\ No newline at end of file +gChart 1600 - 1699 diff --git a/spaghetti-monster/anduril/MODELS b/spaghetti-monster/anduril/MODELS index 4dda62f..13ce2e4 100644 --- a/spaghetti-monster/anduril/MODELS +++ b/spaghetti-monster/anduril/MODELS @@ -37,11 +37,11 @@ Model numbers: 0521 mateminco-mf01-mini 0611 blf-q8 0612 sofirn-sp36 +0613 blf-q8-t1616 +0614 sofirn-sp36-t1616 0621 blf-lantern -0622 sofirn-sp10s -0631 blf-q8-t1616 -0632 sofirn-sp36-t1616 -0633 blf-lantern-t1616 -1618 gchart-fet1-t16 +0622 blf-lantern-t1616 +0631 sofirn-sp10s +1618 gchart-fet1-t1616 Duplicates: Missing: diff --git a/spaghetti-monster/anduril/anduril-manual.txt b/spaghetti-monster/anduril/anduril-manual.txt index b3a1cef..e3b3cf5 100644 --- a/spaghetti-monster/anduril/anduril-manual.txt +++ b/spaghetti-monster/anduril/anduril-manual.txt @@ -691,7 +691,7 @@ Ramp Simple 2C Go to/from ceiling Ramp Full 2C Go to/from ceiling (or turbo if at ceil already) Ramp Full 3C Change ramp style (smooth / stepped) Ramp Any 3H Tint ramping (on some lights) -Ramp Any 3H Momentary turbo (on lights without tint ramping) +Ramp Full 3H Momentary turbo (on lights without tint ramping) Ramp Any 4C Lockout mode Ramp Full 5C Momentary mode Ramp Full 5H Sunset timer on, and add 5 minutes diff --git a/spaghetti-monster/anduril/cfg-blf-lantern-t1616.h b/spaghetti-monster/anduril/cfg-blf-lantern-t1616.h index 7905eee..d602641 100644 --- a/spaghetti-monster/anduril/cfg-blf-lantern-t1616.h +++ b/spaghetti-monster/anduril/cfg-blf-lantern-t1616.h @@ -1,5 +1,5 @@ // BLF Lantern config options for Anduril using the Attiny1616 -#define MODEL_NUMBER "0633" +#define MODEL_NUMBER "0622" /* BLF Lantern pinout * PB0 is 5000K channel * PB1 is 3000K channel diff --git a/spaghetti-monster/anduril/cfg-blf-q8-t1616.h b/spaghetti-monster/anduril/cfg-blf-q8-t1616.h index e1e1598..73702a9 100644 --- a/spaghetti-monster/anduril/cfg-blf-q8-t1616.h +++ b/spaghetti-monster/anduril/cfg-blf-q8-t1616.h @@ -1,5 +1,5 @@ // BLF Q8 config options for Anduril using the Attiny1616 -#define MODEL_NUMBER "0631" +#define MODEL_NUMBER "0613" #include "hwdef-BLF_Q8-T1616.h" // ATTINY: 1616 diff --git a/spaghetti-monster/anduril/cfg-gchart-fet1-t16.h b/spaghetti-monster/anduril/cfg-gchart-fet1-t1616.h index a6434b8..101f25a 100644 --- a/spaghetti-monster/anduril/cfg-gchart-fet1-t16.h +++ b/spaghetti-monster/anduril/cfg-gchart-fet1-t1616.h @@ -1,6 +1,6 @@ // 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" +#include "hwdef-gchart-fet1-t1616.h" // ATTINY: 1616 // the button lights up @@ -9,6 +9,11 @@ #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: low (1) +// lockout: blinking (3) +#define INDICATOR_LED_DEFAULT_MODE ((3<<2) + 1) #undef BLINK_AT_RAMP_MIDDLE diff --git a/spaghetti-monster/anduril/cfg-sofirn-sp10s.h b/spaghetti-monster/anduril/cfg-sofirn-sp10s.h index 054b1db..99ed17d 100644 --- a/spaghetti-monster/anduril/cfg-sofirn-sp10s.h +++ b/spaghetti-monster/anduril/cfg-sofirn-sp10s.h @@ -1,5 +1,5 @@ // gChart's custom SP10S driver config options for Anduril -#define MODEL_NUMBER "0622" +#define MODEL_NUMBER "0631" #include "hwdef-Sofirn_SP10S.h" // ATTINY: 1616 diff --git a/spaghetti-monster/anduril/cfg-sofirn-sp36-t1616.h b/spaghetti-monster/anduril/cfg-sofirn-sp36-t1616.h index 8eb7a5d..ce1c04a 100644 --- a/spaghetti-monster/anduril/cfg-sofirn-sp36-t1616.h +++ b/spaghetti-monster/anduril/cfg-sofirn-sp36-t1616.h @@ -2,7 +2,7 @@ // same as the BLF Q8, mostly #include "cfg-blf-q8-t1616.h" #undef MODEL_NUMBER -#define MODEL_NUMBER "0632" +#define MODEL_NUMBER "0614" // ATTINY: 1616 // voltage readings were a little high with the Q8 value diff --git a/spaghetti-monster/anduril/off-mode.c b/spaghetti-monster/anduril/off-mode.c index 34d9e6d..e37f08d 100644 --- a/spaghetti-monster/anduril/off-mode.c +++ b/spaghetti-monster/anduril/off-mode.c @@ -157,9 +157,12 @@ uint8_t off_state(Event event, uint16_t arg) { } // click, hold: momentary at ceiling or turbo else if (event == EV_click2_hold) { + #ifdef USE_SIMPLE_UI if (simple_ui_active) { set_level(nearest_level(MAX_LEVEL)); - } else { + } else + #endif + { set_level(MAX_LEVEL); } return MISCHIEF_MANAGED; diff --git a/spaghetti-monster/anduril/version.h b/spaghetti-monster/anduril/version.h index 14502aa..8cf3c90 100644 --- a/spaghetti-monster/anduril/version.h +++ b/spaghetti-monster/anduril/version.h @@ -1 +1,4 @@ -#define VERSION_NUMBER "20210201" +// 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" diff --git a/spaghetti-monster/fsm-misc.c b/spaghetti-monster/fsm-misc.c index edd982a..c2c1afe 100644 --- a/spaghetti-monster/fsm-misc.c +++ b/spaghetti-monster/fsm-misc.c @@ -111,6 +111,7 @@ uint8_t blink_num(uint8_t num) { void indicator_led(uint8_t lvl) { switch (lvl) { #ifdef AVRXMEGA3 // ATTINY816, 817, etc + case 0: // indicator off AUXLED_PORT.DIRSET = (1 << AUXLED_PIN); // set as output AUXLED_PORT.OUTCLR = (1 << AUXLED_PIN); // set output low @@ -139,6 +140,7 @@ void indicator_led(uint8_t lvl) { break; #else + case 0: // indicator off DDRB &= 0xff ^ (1 << AUXLED_PIN); PORTB &= 0xff ^ (1 << AUXLED_PIN); @@ -164,7 +166,7 @@ void indicator_led(uint8_t lvl) { #endif break; - #endif + #endif // MCU type } } @@ -183,6 +185,7 @@ void button_led_set(uint8_t lvl) { switch (lvl) { #ifdef AVRXMEGA3 // ATTINY816, 817, etc + case 0: // LED off BUTTON_LED_PORT.DIRSET = (1 << BUTTON_LED_PIN); // set as output BUTTON_LED_PORT.OUTCLR = (1 << BUTTON_LED_PIN); // set output low @@ -215,7 +218,7 @@ void button_led_set(uint8_t lvl) { BUTTON_LED_PORT |= (1 << BUTTON_LED_PIN); break; - #endif + #endif // MCU type } } #endif @@ -230,6 +233,7 @@ void rgb_led_set(uint8_t value) { 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 @@ -262,8 +266,7 @@ void rgb_led_set(uint8_t value) { AUXLED_RGB_PORT |= (1 << pin); break; - #endif - + #endif // MCU type } } } diff --git a/spaghetti-monster/fsm-pcint.c b/spaghetti-monster/fsm-pcint.c index 4a3c193..4ada5b8 100644 --- a/spaghetti-monster/fsm-pcint.c +++ b/spaghetti-monster/fsm-pcint.c @@ -69,24 +69,20 @@ inline void PCINT_off() { //void button_change_interrupt() { #if (ATTINY == 25) || (ATTINY == 45) || (ATTINY == 85) || (ATTINY == 1634) -//EMPTY_INTERRUPT(PCINT0_vect); -#ifdef PCINT_vect -ISR(PCINT_vect) { -#else -ISR(PCINT0_vect) { -#endif - irq_pcint = 1; -} + #ifdef PCINT_vect + ISR(PCINT_vect) { + #else + ISR(PCINT0_vect) { + #endif #elif defined(AVRXMEGA3) // ATTINY816, 817, etc) -ISR(SWITCH_VECT) { - SWITCH_INTFLG |= (1 << SWITCH_PIN); // Write a '1' to clear the interrupt flag - irq_pcint = 1; -} + ISR(SWITCH_VECT) { + // Write a '1' to clear the interrupt flag + SWITCH_INTFLG |= (1 << SWITCH_PIN); #else #error Unrecognized MCU type #endif -/* -ISR(PCINT0_vect) { + + irq_pcint = 1; // let deferred code know an interrupt happened //DEBUG_FLASH; @@ -95,9 +91,7 @@ ISR(PCINT0_vect) { // noisy / bouncy switch (so the content of this function has been // moved to a separate function, called from WDT only) // PCINT_inner(button_is_pressed()); - } -*/ // should only be called from PCINT and/or WDT // (is a separate function to reduce code duplication) diff --git a/tk-attiny.h b/tk-attiny.h index 441f177..ae70afd 100644 --- a/tk-attiny.h +++ b/tk-attiny.h @@ -156,6 +156,7 @@ typedef enum { // Actual clock is 20 MHz, but assume that 5 MHz is the top speed and work from there + // TODO: measure PWM speed and power use at 1.25/2.5/5/10 MHz, to determine which speeds are optimal clock_div_1 = (CLKCTRL_PDIV_4X_gc | CLKCTRL_PEN_bm), // 5 MHz clock_div_2 = (CLKCTRL_PDIV_8X_gc | CLKCTRL_PEN_bm), // 2.5 MHz clock_div_4 = (CLKCTRL_PDIV_16X_gc | CLKCTRL_PEN_bm), // 1.25 MHz |
