000000widow-hackspacecon/fw/HackSpaceCon_AS7/HSC_Wand/isr.cpp
Brooke 4d58a3df74 LEDs now operating on button push
Fixed several bugs:
- TCB wasn't running. The datasheet steps were not complete.
- TCA was waking the MCU and causing the main program to run. Added checks
  to ensure program only runs on button or TCB wakeup.
- Fixed some peculiarities with specific RGBLED programs
2025-04-28 21:07:46 -04:00

48 lines
881 B
C++

/*
hackspacecon wand firmware
interrupt routines
*/
#include <Arduino.h>
#include "rgbled.h"
extern uint8_t run_rgbprog;
// TCB0 general interrupt
ISR(TCB0_INT_vect)
{
uint8_t intflags = TCB0.INTFLAGS;
// in this program, this interrupt is only used for timing.
// we'll now return to executing loop()
rgb_run_next = 1;
// reset the INTFLAGS - necessary on this series
TCB0.INTFLAGS = intflags;
}
// button interrupt
ISR(PORTA_PORT_vect)
{
uint8_t intflags = PORTA.INTFLAGS;
// shitty debounce; this is bad practice
delay(8);
// was our pin changed?
if (intflags & PIN2_bm) {
// start or re-start running a program
if (!digitalRead(PIN_PA2)) {
run_rgbprog = 1; // run a new program
rgb_run_next = 1;
}
}
// reset the INTFLAGS - necessary on this series
PORTA.INTFLAGS = intflags;
}