aboutsummaryrefslogtreecommitdiff
path: root/spaghetti-monster/fsm-misc.c
diff options
context:
space:
mode:
Diffstat (limited to 'spaghetti-monster/fsm-misc.c')
-rw-r--r--spaghetti-monster/fsm-misc.c78
1 files changed, 78 insertions, 0 deletions
diff --git a/spaghetti-monster/fsm-misc.c b/spaghetti-monster/fsm-misc.c
index 15cb659..c2c1afe 100644
--- a/spaghetti-monster/fsm-misc.c
+++ b/spaghetti-monster/fsm-misc.c
@@ -110,6 +110,37 @@ uint8_t blink_num(uint8_t num) {
#ifdef USE_INDICATOR_LED
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
+ #ifdef AUXLED2_PIN // second LED mirrors the first
+ AUXLED2_PORT.DIRSET = (1 << AUXLED2_PIN); // set as output
+ AUXLED2_PORT.OUTCLR = (1 << AUXLED2_PIN); // set output low
+ #endif
+ break;
+ case 1: // indicator low
+ AUXLED_PORT.DIRCLR = (1 << AUXLED_PIN); // set as input
+ // this resolves to PORTx.PINxCTRL = PORT_PULLUPEN_bm;
+ *((uint8_t *)&AUXLED_PORT + 0x10 + AUXLED_PIN) = PORT_PULLUPEN_bm; // enable internal pull-up
+ #ifdef AUXLED2_PIN // second LED mirrors the first
+ AUXLED2_PORT.DIRCLR = (1 << AUXLED2_PIN); // set as input
+ // this resolves to PORTx.PINxCTRL = PORT_PULLUPEN_bm;
+ *((uint8_t *)&AUXLED2_PORT + 0x10 + AUXLED2_PIN) = PORT_PULLUPEN_bm; // enable internal pull-up
+ #endif
+ break;
+ default: // indicator high
+ AUXLED_PORT.DIRSET = (1 << AUXLED_PIN); // set as output
+ AUXLED_PORT.OUTSET = (1 << AUXLED_PIN); // set as high
+ #ifdef AUXLED2_PIN // second LED mirrors the first
+ AUXLED2_PORT.DIRSET = (1 << AUXLED2_PIN); // set as output
+ AUXLED2_PORT.OUTSET = (1 << AUXLED2_PIN); // set as high
+ #endif
+ break;
+
+ #else
+
case 0: // indicator off
DDRB &= 0xff ^ (1 << AUXLED_PIN);
PORTB &= 0xff ^ (1 << AUXLED_PIN);
@@ -134,6 +165,8 @@ void indicator_led(uint8_t lvl) {
PORTB |= (1 << AUXLED2_PIN);
#endif
break;
+
+ #endif // MCU type
}
}
@@ -150,6 +183,25 @@ void indicator_led_auto() {
// TODO: Refactor this and RGB LED function to merge code and save space
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
+ break;
+ case 1: // LED low
+ BUTTON_LED_PORT.DIRCLR = (1 << BUTTON_LED_PIN); // set as input
+ // this resolves to PORTx.PINxCTRL = PORT_PULLUPEN_bm;
+ *((uint8_t *)&BUTTON_LED_PORT + 0x10 + BUTTON_LED_PIN) = PORT_PULLUPEN_bm; // enable internal pull-up
+ break;
+ default: // LED high
+ BUTTON_LED_PORT.DIRSET = (1 << BUTTON_LED_PIN); // set as output
+ BUTTON_LED_PORT.OUTSET = (1 << BUTTON_LED_PIN); // set as high
+ break;
+
+ #else
+
case 0: // LED off
BUTTON_LED_DDR &= 0xff ^ (1 << BUTTON_LED_PIN);
BUTTON_LED_PUE &= 0xff ^ (1 << BUTTON_LED_PIN);
@@ -165,6 +217,8 @@ void button_led_set(uint8_t lvl) {
BUTTON_LED_PUE |= (1 << BUTTON_LED_PIN);
BUTTON_LED_PORT |= (1 << BUTTON_LED_PIN);
break;
+
+ #endif // MCU type
}
}
#endif
@@ -177,6 +231,25 @@ void rgb_led_set(uint8_t value) {
uint8_t lvl = (value >> (i<<1)) & 0x03;
uint8_t pin = pins[i];
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
+ break;
+ case 1: // LED low
+ AUXLED_RGB_PORT.DIRCLR = (1 << pin); // set as input
+ // this resolves to PORTx.PINxCTRL = PORT_PULLUPEN_bm;
+ *((uint8_t *)&AUXLED_RGB_PORT + 0x10 + pin) = PORT_PULLUPEN_bm; // enable internal pull-up
+ break;
+ default: // LED high
+ AUXLED_RGB_PORT.DIRSET = (1 << pin); // set as output
+ AUXLED_RGB_PORT.OUTSET = (1 << pin); // set as high
+ break;
+
+ #else
+
case 0: // LED off
AUXLED_RGB_DDR &= 0xff ^ (1 << pin);
AUXLED_RGB_PUE &= 0xff ^ (1 << pin);
@@ -192,6 +265,8 @@ void rgb_led_set(uint8_t value) {
AUXLED_RGB_PUE |= (1 << pin);
AUXLED_RGB_PORT |= (1 << pin);
break;
+
+ #endif // MCU type
}
}
}
@@ -217,6 +292,9 @@ void reboot() {
// reset (WDIF + WDE), no WDIE, fastest (16ms) timing (0000)
// (DS section 8.5.2 and table 8-4)
WDTCSR = 0b10001000;
+ #elif defined(AVRXMEGA3) // ATTINY816, 817, etc
+ CCP = CCP_IOREG_gc; // temporarily disable change protection
+ WDT.CTRLA = WDT_PERIOD_8CLK_gc; // Enable, timeout 8ms
#endif
sei();
wdt_reset();