From 0d69c2d209173a85693b508580456003f24aafb2 Mon Sep 17 00:00:00 2001 From: Christian Kroll Date: Sun, 14 Sep 2014 18:37:50 +0200 Subject: [PATCH] added UART support for the LoL Shield (except for Arduino Leonardo) --- profiles/LoL-Shield_Leonardo | 10 ++++- profiles/LoL-Shield_Mega1280 | 10 ++++- profiles/LoL-Shield_Mega2560 | 10 ++++- profiles/LoL-Shield_Uno-Duemilanove-Diavolino | 10 ++++- src/borg_hw/borg_hw_lolshield.c | 24 +++++++++++ src/borg_hw/config_lolshield.in | 17 +++++++- src/config.h | 4 +- src/uart/uart.c | 4 ++ src/uart/uart.h | 4 ++ src/uart/uart_commands.c | 43 +++++++++++-------- 10 files changed, 108 insertions(+), 28 deletions(-) diff --git a/profiles/LoL-Shield_Leonardo b/profiles/LoL-Shield_Leonardo index efee960..e0be406 100644 --- a/profiles/LoL-Shield_Leonardo +++ b/profiles/LoL-Shield_Leonardo @@ -20,8 +20,11 @@ BORG_HW=HW_LOLSHIELD # lolshield setup # USER_TIMER0_FOR_WAIT=1 -BRIGHTNESS=127 +LOLSHIELD=y +BRIGHTNESS=120 FRAMERATE=80 +# UART_SUPPORT is not set +UART_BAUDRATE_SETTING=19200 # # Features @@ -54,7 +57,10 @@ GAME_TETRIS=y # GAME_TETRIS_FP is not set # GAME_SPACE_INVADERS is not set GAME_SNAKE=y +# SNAKE_POV_CONTROL is not set +SNAKE_GAME_DELAY=200 GAME_BREAKOUT=y +# GAME_KART is not set # # Animations @@ -64,7 +70,6 @@ ANIMATION_SPIRAL=y SPIRAL_DELAY=5 ANIMATION_JOERN1=y ANIMATION_SNAKE=y -SNAKE_GAME_DELAY=200 SNAKE_ANIM_DELAY=100 SNAKE_TERMINATION_DELAY=60 SNAKE_MAX_LENGTH=64 @@ -107,6 +112,7 @@ FP_PLASMA_DELAY=10 ANIMATION_PSYCHEDELIC=y FP_PSYCHO_DELAY=25 # ANIMATION_BLACKHOLE is not set +# ANIMATION_DNA is not set ANIMATION_SQUARES=y # ANIMATION_TESTS is not set # ANIMATION_OFF is not set diff --git a/profiles/LoL-Shield_Mega1280 b/profiles/LoL-Shield_Mega1280 index 40604e0..379cd59 100644 --- a/profiles/LoL-Shield_Mega1280 +++ b/profiles/LoL-Shield_Mega1280 @@ -20,8 +20,11 @@ BORG_HW=HW_LOLSHIELD # lolshield setup # USER_TIMER0_FOR_WAIT=1 -BRIGHTNESS=127 +LOLSHIELD=y +BRIGHTNESS=120 FRAMERATE=80 +# UART_SUPPORT is not set +UART_BAUDRATE_SETTING=19200 # # Features @@ -54,7 +57,10 @@ GAME_BASTET=y # GAME_TETRIS_FP is not set GAME_SPACE_INVADERS=y GAME_SNAKE=y +# SNAKE_POV_CONTROL is not set +SNAKE_GAME_DELAY=200 GAME_BREAKOUT=y +# GAME_KART is not set # # Animations @@ -64,7 +70,6 @@ ANIMATION_SPIRAL=y SPIRAL_DELAY=5 ANIMATION_JOERN1=y ANIMATION_SNAKE=y -SNAKE_GAME_DELAY=200 SNAKE_ANIM_DELAY=100 SNAKE_TERMINATION_DELAY=60 SNAKE_MAX_LENGTH=64 @@ -107,6 +112,7 @@ FP_PLASMA_DELAY=10 ANIMATION_PSYCHEDELIC=y FP_PSYCHO_DELAY=25 ANIMATION_BLACKHOLE=y +# ANIMATION_DNA is not set ANIMATION_SQUARES=y ANIMATION_TESTS=y ANIMATION_OFF=y diff --git a/profiles/LoL-Shield_Mega2560 b/profiles/LoL-Shield_Mega2560 index f5f03c2..3661c02 100644 --- a/profiles/LoL-Shield_Mega2560 +++ b/profiles/LoL-Shield_Mega2560 @@ -20,8 +20,11 @@ BORG_HW=HW_LOLSHIELD # lolshield setup # USER_TIMER0_FOR_WAIT=1 -BRIGHTNESS=127 +LOLSHIELD=y +BRIGHTNESS=120 FRAMERATE=80 +# UART_SUPPORT is not set +UART_BAUDRATE_SETTING=19200 # # Features @@ -54,7 +57,10 @@ GAME_BASTET=y # GAME_TETRIS_FP is not set GAME_SPACE_INVADERS=y GAME_SNAKE=y +# SNAKE_POV_CONTROL is not set +SNAKE_GAME_DELAY=200 GAME_BREAKOUT=y +# GAME_KART is not set # # Animations @@ -64,7 +70,6 @@ ANIMATION_SPIRAL=y SPIRAL_DELAY=5 ANIMATION_JOERN1=y ANIMATION_SNAKE=y -SNAKE_GAME_DELAY=200 SNAKE_ANIM_DELAY=100 SNAKE_TERMINATION_DELAY=60 SNAKE_MAX_LENGTH=64 @@ -107,6 +112,7 @@ FP_PLASMA_DELAY=10 ANIMATION_PSYCHEDELIC=y FP_PSYCHO_DELAY=25 ANIMATION_BLACKHOLE=y +# ANIMATION_DNA is not set ANIMATION_SQUARES=y ANIMATION_TESTS=y ANIMATION_OFF=y diff --git a/profiles/LoL-Shield_Uno-Duemilanove-Diavolino b/profiles/LoL-Shield_Uno-Duemilanove-Diavolino index ff8ae2e..0477418 100644 --- a/profiles/LoL-Shield_Uno-Duemilanove-Diavolino +++ b/profiles/LoL-Shield_Uno-Duemilanove-Diavolino @@ -20,8 +20,11 @@ BORG_HW=HW_LOLSHIELD # lolshield setup # USER_TIMER0_FOR_WAIT=1 -BRIGHTNESS=127 +LOLSHIELD=y +BRIGHTNESS=120 FRAMERATE=80 +# UART_SUPPORT is not set +UART_BAUDRATE_SETTING=19200 # # Features @@ -54,7 +57,10 @@ GAME_TETRIS=y # GAME_TETRIS_FP is not set # GAME_SPACE_INVADERS is not set GAME_SNAKE=y +# SNAKE_POV_CONTROL is not set +SNAKE_GAME_DELAY=200 GAME_BREAKOUT=y +# GAME_KART is not set # # Animations @@ -64,7 +70,6 @@ ANIMATION_SPIRAL=y SPIRAL_DELAY=5 ANIMATION_JOERN1=y ANIMATION_SNAKE=y -SNAKE_GAME_DELAY=200 SNAKE_ANIM_DELAY=100 SNAKE_TERMINATION_DELAY=60 SNAKE_MAX_LENGTH=64 @@ -107,6 +112,7 @@ FP_PLASMA_DELAY=10 ANIMATION_PSYCHEDELIC=y FP_PSYCHO_DELAY=25 ANIMATION_BLACKHOLE=y +# ANIMATION_DNA is not set ANIMATION_SQUARES=y # ANIMATION_TESTS is not set # ANIMATION_OFF is not set diff --git a/src/borg_hw/borg_hw_lolshield.c b/src/borg_hw/borg_hw_lolshield.c index c37beaa..48f0b44 100644 --- a/src/borg_hw/borg_hw_lolshield.c +++ b/src/borg_hw/borg_hw_lolshield.c @@ -973,3 +973,27 @@ void borg_hw_init() { wdt_reset(); wdt_enable(WDTO_15MS); // 15ms watchdog } + +void timer0_off() { + cli(); +#if defined (__AVR_ATmega48__) || \ + defined (__AVR_ATmega48P__) || \ + defined (__AVR_ATmega88__) || \ + defined (__AVR_ATmega88P__) || \ + defined (__AVR_ATmega168__) || \ + defined (__AVR_ATmega168P__) || \ + defined (__AVR_ATmega328__) || \ + defined (__AVR_ATmega328P__) || \ + defined (__AVR_ATmega1280__) || \ + defined (__AVR_ATmega2560__) + TCCR2A = 0x00; + TCCR2B = 0x00; +#elif defined (__AVR_ATmega8__) || \ + defined (__AVR_ATmega128__) + TCCR2 = 0x00; +#elif defined (__AVR_ATmega32U4__) + TCCR1A = 0x00; + TCCR1B = 0x00; +#endif + sei(); +} diff --git a/src/borg_hw/config_lolshield.in b/src/borg_hw/config_lolshield.in index e238766..eba6f66 100644 --- a/src/borg_hw/config_lolshield.in +++ b/src/borg_hw/config_lolshield.in @@ -2,8 +2,23 @@ mainmenu_option next_comment comment "lolshield setup" define_int USER_TIMER0_FOR_WAIT 1 +define_bool LOLSHIELD y -uint "Brightness (0-127)" BRIGHTNESS 127 +uint "Brightness (0-127)" BRIGHTNESS 120 uint "Framerate (default 80)" FRAMERATE 80 +bool "UART Support" UART_SUPPORT n +choice 'Baud Rate' \ + "2400 2400 \ + 4800 4800 \ + 9600 9600 \ + 14400 14400 \ + 19200 19200 \ + 28800 28800 \ + 38400 38400 \ + 57600 57600 \ + 76800 76800 \ + 115200 115200" \ + '19200' UART_BAUDRATE_SETTING + endmenu diff --git a/src/config.h b/src/config.h index 31b754b..31d29e8 100644 --- a/src/config.h +++ b/src/config.h @@ -33,6 +33,8 @@ #define INIT_EEPROM -//#define UART_BAUD_RATE 115200L +#if defined(UART_SUPPORT) && defined(LOLSHIELD) && defined(__AVR_ATmega32U4__) +# error UART not supported on Arduino Leonardo +#endif #endif /* CONFIG_H_ */ diff --git a/src/uart/uart.c b/src/uart/uart.c index 4cce60d..b93e014 100644 --- a/src/uart/uart.c +++ b/src/uart/uart.c @@ -565,6 +565,9 @@ Purpose: called when the UART1 is ready to transmit the next byte } + +#if defined USE_UART1 || defined DOXYGEN + /************************************************************************* Function: uart1_init() Purpose: initialize UART1 and set baudrate @@ -685,5 +688,6 @@ void uart1_puts_p(const char *progmem_s ) }/* uart1_puts_p */ +#endif // defined USE_UART1 || defined DOXYGEN #endif diff --git a/src/uart/uart.h b/src/uart/uart.h index 3e0ebd5..d39d5e0 100644 --- a/src/uart/uart.h +++ b/src/uart/uart.h @@ -50,6 +50,7 @@ LICENSE: /**@{*/ +#include "../config.h" #if (__GNUC__ * 100 + __GNUC_MINOR__) < 304 #error "This library requires AVR-GCC 3.4 or later, update to newer AVR-GCC compiler !" @@ -181,6 +182,7 @@ extern void uart_puts_p(const char *s ); #define uart_puts_P(__s) uart_puts_p(PSTR(__s)) +#if defined USE_UART1 || defined DOXYGEN /** @brief Initialize USART1 (only available on selected ATmegas) * @see uart_init @@ -216,4 +218,6 @@ extern void uart1_puts_p(const char *s ); /**@}*/ +#endif // defined USE_UART1 || defined DOXYGEN + #endif // UART_H diff --git a/src/uart/uart_commands.c b/src/uart/uart_commands.c index 99e9797..ff91bb4 100644 --- a/src/uart/uart_commands.c +++ b/src/uart/uart_commands.c @@ -17,6 +17,13 @@ #include "uart.h" #include "uart_commands.h" +#ifndef USE_UART1 +# define UART_PUTS_P(STR) uart_puts_p(STR) +# define UART_GETC uart_getc +#else +# define UART_PUTS_P(STR) uart1_puts_p(STR) +# define UART_GETC uart1_getc +#endif #define UART_BUFFER_SIZE (SCROLLTEXT_BUFFER_SIZE + 8) char g_rx_buffer[UART_BUFFER_SIZE]; @@ -101,7 +108,7 @@ static void uartcmd_erase_eeprom(void) { eeprom_update_block(eeclear, ee, E2PAGESIZE); } #else - uart_puts_p(UART_STR_NOTIMPL); + UART_PUTS_P(UART_STR_NOTIMPL); #endif } @@ -121,7 +128,7 @@ static void uartcmd_simple_message(void) { scrolltext(&g_rx_buffer[1]); #ifdef JOYSTICK_SUPPORT } else { - uart_puts_p(UART_STR_GAMETX_ERR); + UART_PUTS_P(UART_STR_GAMETX_ERR); } #endif @@ -140,7 +147,7 @@ static void uartcmd_scroll_message(void) { scrolltext(&g_rx_buffer[7]); #ifdef JOYSTICK_SUPPORT } else { - uart_puts_p(UART_STR_GAMETX_ERR); + UART_PUTS_P(UART_STR_GAMETX_ERR); } #endif } @@ -153,12 +160,12 @@ static void uartcmd_next_anim(void) { #ifdef JOYSTICK_SUPPORT if (waitForFire) { #endif - uart_puts_p(UART_STR_PROMPT); + UART_PUTS_P(UART_STR_PROMPT); uartcmd_clear_buffer(); longjmp(newmode_jmpbuf, mode); #ifdef JOYSTICK_SUPPORT } else { - uart_puts_p(UART_STR_GAMEMO_ERR); + UART_PUTS_P(UART_STR_GAMEMO_ERR); } #endif } @@ -172,12 +179,12 @@ static void uartcmd_prev_anim(void) { if (waitForFire) { #endif reverseMode = mode - 2; - uart_puts_p(UART_STR_PROMPT); + UART_PUTS_P(UART_STR_PROMPT); uartcmd_clear_buffer(); longjmp(newmode_jmpbuf, mode - 2); #ifdef JOYSTICK_SUPPORT } else { - uart_puts_p(UART_STR_GAMEMO_ERR); + UART_PUTS_P(UART_STR_GAMEMO_ERR); } #endif } @@ -211,16 +218,16 @@ static void uartcmd_read_mode(void) { #ifdef JOYSTICK_SUPPORT if (waitForFire) { #endif - uart_puts_p(UART_STR_PROMPT); + UART_PUTS_P(UART_STR_PROMPT); uartcmd_clear_buffer(); longjmp(newmode_jmpbuf, res); #ifdef JOYSTICK_SUPPORT } else { - uart_puts_p(UART_STR_GAMEMO_ERR); + UART_PUTS_P(UART_STR_GAMEMO_ERR); } #endif } else { - uart_puts_p(UART_STR_MODE_ERR); + UART_PUTS_P(UART_STR_MODE_ERR); } } @@ -254,7 +261,7 @@ static bool uartcmd_read_until_enter(void) { case '\177': // DEL if (g_rx_index != 0) { g_rx_buffer[--g_rx_index] = 0; - uart_puts_p(UART_STR_BACKSPACE); + UART_PUTS_P(UART_STR_BACKSPACE); } break; case 27: // ignore Esc @@ -266,8 +273,8 @@ static bool uartcmd_read_until_enter(void) { } } else if ((uart_result & 0xFF00u) != UART_NO_DATA) { uartcmd_clear_buffer(); - uart_puts_p(UART_STR_UART_ERR); - uart_puts_p(UART_STR_PROMPT); + UART_PUTS_P(UART_STR_UART_ERR); + UART_PUTS_P(UART_STR_PROMPT); break; } else { break; @@ -276,8 +283,8 @@ static bool uartcmd_read_until_enter(void) { if (g_rx_index >= (UART_BUFFER_SIZE - 1)) { uartcmd_clear_buffer(); - uart_puts_p(UART_STR_TOOLONG); - uart_puts_p(UART_STR_PROMPT); + UART_PUTS_P(UART_STR_TOOLONG); + UART_PUTS_P(UART_STR_PROMPT); } return false; } @@ -290,7 +297,7 @@ void uartcmd_process(void) { if (!strncmp_P(g_rx_buffer, UART_CMD_ERASE, UART_BUFFER_SIZE)) { uartcmd_erase_eeprom(); } else if (!strncmp_P(g_rx_buffer, UART_CMD_HELP, UART_BUFFER_SIZE)) { - uart_puts_p(UART_STR_HELP); + UART_PUTS_P(UART_STR_HELP); } else if (!strncmp_P(g_rx_buffer, UART_CMD_MODE, UART_BUFFER_SIZE) || !strncmp_P(g_rx_buffer, UART_CMD_MODE_ARG, UART_BUFFER_SIZE)) { uartcmd_print_mode(); @@ -307,9 +314,9 @@ void uartcmd_process(void) { } else if (!strncmp_P(g_rx_buffer, UART_CMD_SCROLL, 7)) { uartcmd_scroll_message(); } else { - uart_puts_p(UART_STR_UNKNOWN); + UART_PUTS_P(UART_STR_UNKNOWN); } - uart_puts_p(UART_STR_PROMPT); + UART_PUTS_P(UART_STR_PROMPT); uartcmd_clear_buffer(); } }