From dbe0aaf636ccb78a3cc1281b6a1ea6c662af6756 Mon Sep 17 00:00:00 2001 From: Gabriel Hart Date: Fri, 18 Dec 2020 15:23:31 -0600 Subject: Add AVR 1-Series and t1616 board and scripts --- spaghetti-monster/fsm-misc.c | 54 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) (limited to 'spaghetti-monster/fsm-misc.c') diff --git a/spaghetti-monster/fsm-misc.c b/spaghetti-monster/fsm-misc.c index 15cb659..7ba9b45 100644 --- a/spaghetti-monster/fsm-misc.c +++ b/spaghetti-monster/fsm-misc.c @@ -110,6 +110,33 @@ 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 = AUXLED_PIN; // set as output + AUXLED_PORT.OUTCLR = AUXLED_PIN; // set output low + #ifdef AUXLED2_PIN // second LED mirrors the first + AUXLED2_PORT.DIRSET = AUXLED2_PIN; // set as output + AUXLED2_PORT.OUTCLR = AUXLED2_PIN; // set output low + #endif + break; + case 1: // indicator low + AUXLED_PORT.DIRCLR = AUXLED_PIN; // set as input + AUXLED_PORT.AUXLED_CTRL = PORT_PULLUPEN_bm; // enable internal pull-up + #ifdef AUXLED2_PIN // second LED mirrors the first + AUXLED2_PORT.DIRCLR = AUXLE2D_PIN; // set as input + AUXLED2_PORT.AUXLED2_CTRL = PORT_PULLUPEN_bm; // enable internal pull-up + #endif + break; + default: // indicator high + AUXLED_PORT.DIRSET = AUXLED_PIN; // set as output + AUXLED_PORT.OUTSET = AUXLED_PIN; // set as high + #ifdef AUXLED2_PIN // second LED mirrors the first + AUXLED2_PORT.DIRSET = AUXLED2_PIN; // set as output + AUXLED2_PORT.OUTSET = AUXLED2_PIN; // set as high + #endif + break; + + #else case 0: // indicator off DDRB &= 0xff ^ (1 << AUXLED_PIN); PORTB &= 0xff ^ (1 << AUXLED_PIN); @@ -134,6 +161,8 @@ void indicator_led(uint8_t lvl) { PORTB |= (1 << AUXLED2_PIN); #endif break; + + #endif } } @@ -150,6 +179,23 @@ 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 = BUTTON_LED_PIN; // set as output + BUTTON_LED_PORT.OUTCLR = BUTTON_LED_PIN; // set output low + break; + case 1: // LED low + BUTTON_LED_PORT.DIRCLR = BUTTON_LED_PIN; // set as input + BUTTON_LED_PORT.BUTTON_LED_CTRL = PORT_PULLUPEN_bm; // enable internal pull-up + break; + default: // LED high + BUTTON_LED_PORT.DIRSET = BUTTON_LED_PIN; // set as output + BUTTON_LED_PORT.OUTSET = 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,11 +211,16 @@ void button_led_set(uint8_t lvl) { BUTTON_LED_PUE |= (1 << BUTTON_LED_PIN); BUTTON_LED_PORT |= (1 << BUTTON_LED_PIN); break; + + #endif } } #endif #ifdef USE_AUX_RGB_LEDS +#ifdef AVRXMEGA3 // ATTINY816, 817, etc +#error Function rgb_led_set in fsm-misc is currently not set up for the AVR 1-Series +#endif void rgb_led_set(uint8_t value) { // value: 0b00BBGGRR uint8_t pins[] = { AUXLED_R_PIN, AUXLED_G_PIN, AUXLED_B_PIN }; @@ -217,6 +268,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(); -- cgit v1.2.3 From 4dfe5e628823c478124a03e381ee6bcdcb9ca314 Mon Sep 17 00:00:00 2001 From: Gabriel Hart Date: Mon, 1 Feb 2021 10:33:43 -0600 Subject: Add RGB Aux functionality for 1-Series --- spaghetti-monster/fsm-misc.c | 63 +++++++++++++++++++++++++++++--------------- 1 file changed, 42 insertions(+), 21 deletions(-) (limited to 'spaghetti-monster/fsm-misc.c') diff --git a/spaghetti-monster/fsm-misc.c b/spaghetti-monster/fsm-misc.c index 7ba9b45..edd982a 100644 --- a/spaghetti-monster/fsm-misc.c +++ b/spaghetti-monster/fsm-misc.c @@ -112,27 +112,29 @@ void indicator_led(uint8_t lvl) { switch (lvl) { #ifdef AVRXMEGA3 // ATTINY816, 817, etc case 0: // indicator off - AUXLED_PORT.DIRSET = AUXLED_PIN; // set as output - AUXLED_PORT.OUTCLR = AUXLED_PIN; // set output low + 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 = AUXLED2_PIN; // set as output - AUXLED2_PORT.OUTCLR = AUXLED2_PIN; // set output low + 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 = AUXLED_PIN; // set as input - AUXLED_PORT.AUXLED_CTRL = PORT_PULLUPEN_bm; // enable internal pull-up + 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 = AUXLE2D_PIN; // set as input - AUXLED2_PORT.AUXLED2_CTRL = PORT_PULLUPEN_bm; // enable internal pull-up + 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 = AUXLED_PIN; // set as output - AUXLED_PORT.OUTSET = AUXLED_PIN; // set as 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 = AUXLED2_PIN; // set as output - AUXLED2_PORT.OUTSET = AUXLED2_PIN; // set as high + AUXLED2_PORT.DIRSET = (1 << AUXLED2_PIN); // set as output + AUXLED2_PORT.OUTSET = (1 << AUXLED2_PIN); // set as high #endif break; @@ -182,16 +184,17 @@ void button_led_set(uint8_t lvl) { #ifdef AVRXMEGA3 // ATTINY816, 817, etc case 0: // LED off - BUTTON_LED_PORT.DIRSET = BUTTON_LED_PIN; // set as output - BUTTON_LED_PORT.OUTCLR = BUTTON_LED_PIN; // set output low + 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 = BUTTON_LED_PIN; // set as input - BUTTON_LED_PORT.BUTTON_LED_CTRL = PORT_PULLUPEN_bm; // enable internal pull-up + 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 = BUTTON_LED_PIN; // set as output - BUTTON_LED_PORT.OUTSET = BUTTON_LED_PIN; // set as 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 @@ -218,9 +221,6 @@ void button_led_set(uint8_t lvl) { #endif #ifdef USE_AUX_RGB_LEDS -#ifdef AVRXMEGA3 // ATTINY816, 817, etc -#error Function rgb_led_set in fsm-misc is currently not set up for the AVR 1-Series -#endif void rgb_led_set(uint8_t value) { // value: 0b00BBGGRR uint8_t pins[] = { AUXLED_R_PIN, AUXLED_G_PIN, AUXLED_B_PIN }; @@ -228,6 +228,24 @@ 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); @@ -243,6 +261,9 @@ void rgb_led_set(uint8_t value) { AUXLED_RGB_PUE |= (1 << pin); AUXLED_RGB_PORT |= (1 << pin); break; + + #endif + } } } -- cgit v1.2.3 From d40369595fef086cb070425930b882705f1ac20b Mon Sep 17 00:00:00 2001 From: Selene ToyKeeper Date: Thu, 1 Apr 2021 18:29:17 -0600 Subject: touched up a bit of formatting and a note for later optimization --- spaghetti-monster/fsm-misc.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'spaghetti-monster/fsm-misc.c') 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 } } } -- cgit v1.2.3