diff --git a/fw/HackSpaceCon/src/isr.cpp b/fw/HackSpaceCon/src/isr.cpp new file mode 100644 index 0000000..896eeba --- /dev/null +++ b/fw/HackSpaceCon/src/isr.cpp @@ -0,0 +1,37 @@ +#include + + +extern uint8_t run_rgb_program; + + +// TCB0 general interrupt +ISR(TCB0_INT_vect) +{ + // reset the INTFLAGS - necessary on this series + uint8_t intflags = TCB0.INTFLAGS; + TCB0.INTFLAGS = intflags; + + // in this program, this interrupt is only used for timing. + // we'll now return to executing loop() +} + +// button interrupt +ISR(PORTA_PORT_vect) +{ + // reset the INTFLAGS - necessary on this series + uint8_t intflags = PORTA.INTFLAGS; + PORTA.INTFLAGS = intflags; + + // was our pin changed? + if (intflags & PIN3_bm) { + // is the pin low? + if (!digitalRead(PIN_PA3)) { + // start running a program if one isn't running already + if (!run_rgb_program) run_rgb_program = 1; + } else if (run_rgb_program == 2) { + // if we're running a program when the button is released (likely), + // then skip this interrupt + run_rgb_program++; + } + } +} \ No newline at end of file diff --git a/fw/HackSpaceCon/src/main.cpp b/fw/HackSpaceCon/src/main.cpp index be526d0..8c61625 100644 --- a/fw/HackSpaceCon/src/main.cpp +++ b/fw/HackSpaceCon/src/main.cpp @@ -71,14 +71,14 @@ void idle_cpu() __asm("sleep"); } -inline void sleep_cpu() +void sleep_cpu() { SLPCTRL.CTRLA = SLPCTRL_SMODE_STDBY_gc | SLPCTRL_SEN_bm; __asm("sleep"); } - +// mcu init void setup() { // configure PA3 as both edge interrupt input for button // note: only PA2 and PA6 support async wakeup and thus we can't check for @@ -105,6 +105,7 @@ void setup() { sei(); } +// mcu program loop void loop() { switch (run_rgb_program) { case RGB_PROG_INIT: { // just started running a program @@ -153,24 +154,3 @@ void loop() { } } } - -// button interrupt -ISR(PORTA_PORT_vect) -{ - // reset the INTFLAGS - necessary on this series - uint8_t intflags = PORTA.INTFLAGS; - PORTA.INTFLAGS = intflags; - - // was our pin changed? - if (intflags & PIN3_bm) { - // is the pin low? - if (!digitalRead(PIN_PA3)) { - // start running a program if one isn't running already - if (!run_rgb_program) run_rgb_program = 1; - } else if (run_rgb_program == 2) { - // if we're running a program when the button is released (likely), - // then skip this interrupt - run_rgb_program++; - } - } -} \ No newline at end of file diff --git a/fw/HackSpaceCon/src/rgbled.cpp b/fw/HackSpaceCon/src/rgbled.cpp index 8974901..9920eef 100644 --- a/fw/HackSpaceCon/src/rgbled.cpp +++ b/fw/HackSpaceCon/src/rgbled.cpp @@ -37,15 +37,9 @@ void conf_rgb_timer() TCB0.CNT = 0; } -ISR(TCB0_INT_vect) -{ - // reset the INTFLAGS - necessary on this series - uint8_t intflags = TCB0.INTFLAGS; - TCB0.INTFLAGS = intflags; - // we don't care why we interrupted. - // we'll now return to executing loop() -} +// globals for all rgb programs +uint16_t prog_timeout; // rgb program 0: rainbow puke @@ -56,7 +50,6 @@ ISR(TCB0_INT_vect) #define RAINBOW_VAL 0x40 // value (brightness); keep low enough to keep average current down uint16_t rainbow_hue = 0; -uint16_t rainbow_timeout; uint8_t rgbp_rainbow(uint8_t init) { @@ -66,10 +59,10 @@ uint8_t rgbp_rainbow(uint8_t init) // set our timer when initializing. otherwise every call is identical if (init) { - rainbow_timeout = RAINBOW_TIMEOUT; + prog_timeout = RAINBOW_TIMEOUT; } - if (--rainbow_timeout) { + if (--prog_timeout) { // copy stored hue to working hue hue = rainbow_hue;