broke out interrupts into isr.cpp
This commit is contained in:
parent
b5bf65fead
commit
9413b9997a
|
@ -0,0 +1,37 @@
|
||||||
|
#include <Arduino.h>
|
||||||
|
|
||||||
|
|
||||||
|
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++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -71,14 +71,14 @@ void idle_cpu()
|
||||||
__asm("sleep");
|
__asm("sleep");
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void sleep_cpu()
|
void sleep_cpu()
|
||||||
{
|
{
|
||||||
SLPCTRL.CTRLA = SLPCTRL_SMODE_STDBY_gc | SLPCTRL_SEN_bm;
|
SLPCTRL.CTRLA = SLPCTRL_SMODE_STDBY_gc | SLPCTRL_SEN_bm;
|
||||||
__asm("sleep");
|
__asm("sleep");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// mcu init
|
||||||
void setup() {
|
void setup() {
|
||||||
// configure PA3 as both edge interrupt input for button
|
// configure PA3 as both edge interrupt input for button
|
||||||
// note: only PA2 and PA6 support async wakeup and thus we can't check for
|
// note: only PA2 and PA6 support async wakeup and thus we can't check for
|
||||||
|
@ -105,6 +105,7 @@ void setup() {
|
||||||
sei();
|
sei();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// mcu program loop
|
||||||
void loop() {
|
void loop() {
|
||||||
switch (run_rgb_program) {
|
switch (run_rgb_program) {
|
||||||
case RGB_PROG_INIT: { // just started running a 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++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -37,15 +37,9 @@ void conf_rgb_timer()
|
||||||
TCB0.CNT = 0;
|
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.
|
// globals for all rgb programs
|
||||||
// we'll now return to executing loop()
|
uint16_t prog_timeout;
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// rgb program 0: rainbow puke
|
// 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
|
#define RAINBOW_VAL 0x40 // value (brightness); keep low enough to keep average current down
|
||||||
|
|
||||||
uint16_t rainbow_hue = 0;
|
uint16_t rainbow_hue = 0;
|
||||||
uint16_t rainbow_timeout;
|
|
||||||
|
|
||||||
uint8_t rgbp_rainbow(uint8_t init)
|
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
|
// set our timer when initializing. otherwise every call is identical
|
||||||
if (init) {
|
if (init) {
|
||||||
rainbow_timeout = RAINBOW_TIMEOUT;
|
prog_timeout = RAINBOW_TIMEOUT;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (--rainbow_timeout) {
|
if (--prog_timeout) {
|
||||||
// copy stored hue to working hue
|
// copy stored hue to working hue
|
||||||
hue = rainbow_hue;
|
hue = rainbow_hue;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue