Browse Source

added UART support for the LoL Shield (except for Arduino Leonardo)

feature/2015
Christian Kroll 10 years ago
parent
commit
0d69c2d209
  1. 10
      profiles/LoL-Shield_Leonardo
  2. 10
      profiles/LoL-Shield_Mega1280
  3. 10
      profiles/LoL-Shield_Mega2560
  4. 10
      profiles/LoL-Shield_Uno-Duemilanove-Diavolino
  5. 24
      src/borg_hw/borg_hw_lolshield.c
  6. 17
      src/borg_hw/config_lolshield.in
  7. 4
      src/config.h
  8. 4
      src/uart/uart.c
  9. 4
      src/uart/uart.h
  10. 43
      src/uart/uart_commands.c

10
profiles/LoL-Shield_Leonardo

@ -20,8 +20,11 @@ BORG_HW=HW_LOLSHIELD
# lolshield setup # lolshield setup
# #
USER_TIMER0_FOR_WAIT=1 USER_TIMER0_FOR_WAIT=1
BRIGHTNESS=127 LOLSHIELD=y
BRIGHTNESS=120
FRAMERATE=80 FRAMERATE=80
# UART_SUPPORT is not set
UART_BAUDRATE_SETTING=19200
# #
# Features # Features
@ -54,7 +57,10 @@ GAME_TETRIS=y
# GAME_TETRIS_FP is not set # GAME_TETRIS_FP is not set
# GAME_SPACE_INVADERS is not set # GAME_SPACE_INVADERS is not set
GAME_SNAKE=y GAME_SNAKE=y
# SNAKE_POV_CONTROL is not set
SNAKE_GAME_DELAY=200
GAME_BREAKOUT=y GAME_BREAKOUT=y
# GAME_KART is not set
# #
# Animations # Animations
@ -64,7 +70,6 @@ ANIMATION_SPIRAL=y
SPIRAL_DELAY=5 SPIRAL_DELAY=5
ANIMATION_JOERN1=y ANIMATION_JOERN1=y
ANIMATION_SNAKE=y ANIMATION_SNAKE=y
SNAKE_GAME_DELAY=200
SNAKE_ANIM_DELAY=100 SNAKE_ANIM_DELAY=100
SNAKE_TERMINATION_DELAY=60 SNAKE_TERMINATION_DELAY=60
SNAKE_MAX_LENGTH=64 SNAKE_MAX_LENGTH=64
@ -107,6 +112,7 @@ FP_PLASMA_DELAY=10
ANIMATION_PSYCHEDELIC=y ANIMATION_PSYCHEDELIC=y
FP_PSYCHO_DELAY=25 FP_PSYCHO_DELAY=25
# ANIMATION_BLACKHOLE is not set # ANIMATION_BLACKHOLE is not set
# ANIMATION_DNA is not set
ANIMATION_SQUARES=y ANIMATION_SQUARES=y
# ANIMATION_TESTS is not set # ANIMATION_TESTS is not set
# ANIMATION_OFF is not set # ANIMATION_OFF is not set

10
profiles/LoL-Shield_Mega1280

@ -20,8 +20,11 @@ BORG_HW=HW_LOLSHIELD
# lolshield setup # lolshield setup
# #
USER_TIMER0_FOR_WAIT=1 USER_TIMER0_FOR_WAIT=1
BRIGHTNESS=127 LOLSHIELD=y
BRIGHTNESS=120
FRAMERATE=80 FRAMERATE=80
# UART_SUPPORT is not set
UART_BAUDRATE_SETTING=19200
# #
# Features # Features
@ -54,7 +57,10 @@ GAME_BASTET=y
# GAME_TETRIS_FP is not set # GAME_TETRIS_FP is not set
GAME_SPACE_INVADERS=y GAME_SPACE_INVADERS=y
GAME_SNAKE=y GAME_SNAKE=y
# SNAKE_POV_CONTROL is not set
SNAKE_GAME_DELAY=200
GAME_BREAKOUT=y GAME_BREAKOUT=y
# GAME_KART is not set
# #
# Animations # Animations
@ -64,7 +70,6 @@ ANIMATION_SPIRAL=y
SPIRAL_DELAY=5 SPIRAL_DELAY=5
ANIMATION_JOERN1=y ANIMATION_JOERN1=y
ANIMATION_SNAKE=y ANIMATION_SNAKE=y
SNAKE_GAME_DELAY=200
SNAKE_ANIM_DELAY=100 SNAKE_ANIM_DELAY=100
SNAKE_TERMINATION_DELAY=60 SNAKE_TERMINATION_DELAY=60
SNAKE_MAX_LENGTH=64 SNAKE_MAX_LENGTH=64
@ -107,6 +112,7 @@ FP_PLASMA_DELAY=10
ANIMATION_PSYCHEDELIC=y ANIMATION_PSYCHEDELIC=y
FP_PSYCHO_DELAY=25 FP_PSYCHO_DELAY=25
ANIMATION_BLACKHOLE=y ANIMATION_BLACKHOLE=y
# ANIMATION_DNA is not set
ANIMATION_SQUARES=y ANIMATION_SQUARES=y
ANIMATION_TESTS=y ANIMATION_TESTS=y
ANIMATION_OFF=y ANIMATION_OFF=y

10
profiles/LoL-Shield_Mega2560

@ -20,8 +20,11 @@ BORG_HW=HW_LOLSHIELD
# lolshield setup # lolshield setup
# #
USER_TIMER0_FOR_WAIT=1 USER_TIMER0_FOR_WAIT=1
BRIGHTNESS=127 LOLSHIELD=y
BRIGHTNESS=120
FRAMERATE=80 FRAMERATE=80
# UART_SUPPORT is not set
UART_BAUDRATE_SETTING=19200
# #
# Features # Features
@ -54,7 +57,10 @@ GAME_BASTET=y
# GAME_TETRIS_FP is not set # GAME_TETRIS_FP is not set
GAME_SPACE_INVADERS=y GAME_SPACE_INVADERS=y
GAME_SNAKE=y GAME_SNAKE=y
# SNAKE_POV_CONTROL is not set
SNAKE_GAME_DELAY=200
GAME_BREAKOUT=y GAME_BREAKOUT=y
# GAME_KART is not set
# #
# Animations # Animations
@ -64,7 +70,6 @@ ANIMATION_SPIRAL=y
SPIRAL_DELAY=5 SPIRAL_DELAY=5
ANIMATION_JOERN1=y ANIMATION_JOERN1=y
ANIMATION_SNAKE=y ANIMATION_SNAKE=y
SNAKE_GAME_DELAY=200
SNAKE_ANIM_DELAY=100 SNAKE_ANIM_DELAY=100
SNAKE_TERMINATION_DELAY=60 SNAKE_TERMINATION_DELAY=60
SNAKE_MAX_LENGTH=64 SNAKE_MAX_LENGTH=64
@ -107,6 +112,7 @@ FP_PLASMA_DELAY=10
ANIMATION_PSYCHEDELIC=y ANIMATION_PSYCHEDELIC=y
FP_PSYCHO_DELAY=25 FP_PSYCHO_DELAY=25
ANIMATION_BLACKHOLE=y ANIMATION_BLACKHOLE=y
# ANIMATION_DNA is not set
ANIMATION_SQUARES=y ANIMATION_SQUARES=y
ANIMATION_TESTS=y ANIMATION_TESTS=y
ANIMATION_OFF=y ANIMATION_OFF=y

10
profiles/LoL-Shield_Uno-Duemilanove-Diavolino

@ -20,8 +20,11 @@ BORG_HW=HW_LOLSHIELD
# lolshield setup # lolshield setup
# #
USER_TIMER0_FOR_WAIT=1 USER_TIMER0_FOR_WAIT=1
BRIGHTNESS=127 LOLSHIELD=y
BRIGHTNESS=120
FRAMERATE=80 FRAMERATE=80
# UART_SUPPORT is not set
UART_BAUDRATE_SETTING=19200
# #
# Features # Features
@ -54,7 +57,10 @@ GAME_TETRIS=y
# GAME_TETRIS_FP is not set # GAME_TETRIS_FP is not set
# GAME_SPACE_INVADERS is not set # GAME_SPACE_INVADERS is not set
GAME_SNAKE=y GAME_SNAKE=y
# SNAKE_POV_CONTROL is not set
SNAKE_GAME_DELAY=200
GAME_BREAKOUT=y GAME_BREAKOUT=y
# GAME_KART is not set
# #
# Animations # Animations
@ -64,7 +70,6 @@ ANIMATION_SPIRAL=y
SPIRAL_DELAY=5 SPIRAL_DELAY=5
ANIMATION_JOERN1=y ANIMATION_JOERN1=y
ANIMATION_SNAKE=y ANIMATION_SNAKE=y
SNAKE_GAME_DELAY=200
SNAKE_ANIM_DELAY=100 SNAKE_ANIM_DELAY=100
SNAKE_TERMINATION_DELAY=60 SNAKE_TERMINATION_DELAY=60
SNAKE_MAX_LENGTH=64 SNAKE_MAX_LENGTH=64
@ -107,6 +112,7 @@ FP_PLASMA_DELAY=10
ANIMATION_PSYCHEDELIC=y ANIMATION_PSYCHEDELIC=y
FP_PSYCHO_DELAY=25 FP_PSYCHO_DELAY=25
ANIMATION_BLACKHOLE=y ANIMATION_BLACKHOLE=y
# ANIMATION_DNA is not set
ANIMATION_SQUARES=y ANIMATION_SQUARES=y
# ANIMATION_TESTS is not set # ANIMATION_TESTS is not set
# ANIMATION_OFF is not set # ANIMATION_OFF is not set

24
src/borg_hw/borg_hw_lolshield.c

@ -973,3 +973,27 @@ void borg_hw_init() {
wdt_reset(); wdt_reset();
wdt_enable(WDTO_15MS); // 15ms watchdog 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();
}

17
src/borg_hw/config_lolshield.in

@ -2,8 +2,23 @@ mainmenu_option next_comment
comment "lolshield setup" comment "lolshield setup"
define_int USER_TIMER0_FOR_WAIT 1 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 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 endmenu

4
src/config.h

@ -33,6 +33,8 @@
#define INIT_EEPROM #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_ */ #endif /* CONFIG_H_ */

4
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() Function: uart1_init()
Purpose: initialize UART1 and set baudrate Purpose: initialize UART1 and set baudrate
@ -685,5 +688,6 @@ void uart1_puts_p(const char *progmem_s )
}/* uart1_puts_p */ }/* uart1_puts_p */
#endif // defined USE_UART1 || defined DOXYGEN
#endif #endif

4
src/uart/uart.h

@ -50,6 +50,7 @@ LICENSE:
/**@{*/ /**@{*/
#include "../config.h"
#if (__GNUC__ * 100 + __GNUC_MINOR__) < 304 #if (__GNUC__ * 100 + __GNUC_MINOR__) < 304
#error "This library requires AVR-GCC 3.4 or later, update to newer AVR-GCC compiler !" #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)) #define uart_puts_P(__s) uart_puts_p(PSTR(__s))
#if defined USE_UART1 || defined DOXYGEN
/** @brief Initialize USART1 (only available on selected ATmegas) /** @brief Initialize USART1 (only available on selected ATmegas)
* @see uart_init * @see uart_init
@ -216,4 +218,6 @@ extern void uart1_puts_p(const char *s );
/**@}*/ /**@}*/
#endif // defined USE_UART1 || defined DOXYGEN
#endif // UART_H #endif // UART_H

43
src/uart/uart_commands.c

@ -17,6 +17,13 @@
#include "uart.h" #include "uart.h"
#include "uart_commands.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) #define UART_BUFFER_SIZE (SCROLLTEXT_BUFFER_SIZE + 8)
char g_rx_buffer[UART_BUFFER_SIZE]; char g_rx_buffer[UART_BUFFER_SIZE];
@ -101,7 +108,7 @@ static void uartcmd_erase_eeprom(void) {
eeprom_update_block(eeclear, ee, E2PAGESIZE); eeprom_update_block(eeclear, ee, E2PAGESIZE);
} }
#else #else
uart_puts_p(UART_STR_NOTIMPL); UART_PUTS_P(UART_STR_NOTIMPL);
#endif #endif
} }
@ -121,7 +128,7 @@ static void uartcmd_simple_message(void) {
scrolltext(&g_rx_buffer[1]); scrolltext(&g_rx_buffer[1]);
#ifdef JOYSTICK_SUPPORT #ifdef JOYSTICK_SUPPORT
} else { } else {
uart_puts_p(UART_STR_GAMETX_ERR); UART_PUTS_P(UART_STR_GAMETX_ERR);
} }
#endif #endif
@ -140,7 +147,7 @@ static void uartcmd_scroll_message(void) {
scrolltext(&g_rx_buffer[7]); scrolltext(&g_rx_buffer[7]);
#ifdef JOYSTICK_SUPPORT #ifdef JOYSTICK_SUPPORT
} else { } else {
uart_puts_p(UART_STR_GAMETX_ERR); UART_PUTS_P(UART_STR_GAMETX_ERR);
} }
#endif #endif
} }
@ -153,12 +160,12 @@ static void uartcmd_next_anim(void) {
#ifdef JOYSTICK_SUPPORT #ifdef JOYSTICK_SUPPORT
if (waitForFire) { if (waitForFire) {
#endif #endif
uart_puts_p(UART_STR_PROMPT); UART_PUTS_P(UART_STR_PROMPT);
uartcmd_clear_buffer(); uartcmd_clear_buffer();
longjmp(newmode_jmpbuf, mode); longjmp(newmode_jmpbuf, mode);
#ifdef JOYSTICK_SUPPORT #ifdef JOYSTICK_SUPPORT
} else { } else {
uart_puts_p(UART_STR_GAMEMO_ERR); UART_PUTS_P(UART_STR_GAMEMO_ERR);
} }
#endif #endif
} }
@ -172,12 +179,12 @@ static void uartcmd_prev_anim(void) {
if (waitForFire) { if (waitForFire) {
#endif #endif
reverseMode = mode - 2; reverseMode = mode - 2;
uart_puts_p(UART_STR_PROMPT); UART_PUTS_P(UART_STR_PROMPT);
uartcmd_clear_buffer(); uartcmd_clear_buffer();
longjmp(newmode_jmpbuf, mode - 2); longjmp(newmode_jmpbuf, mode - 2);
#ifdef JOYSTICK_SUPPORT #ifdef JOYSTICK_SUPPORT
} else { } else {
uart_puts_p(UART_STR_GAMEMO_ERR); UART_PUTS_P(UART_STR_GAMEMO_ERR);
} }
#endif #endif
} }
@ -211,16 +218,16 @@ static void uartcmd_read_mode(void) {
#ifdef JOYSTICK_SUPPORT #ifdef JOYSTICK_SUPPORT
if (waitForFire) { if (waitForFire) {
#endif #endif
uart_puts_p(UART_STR_PROMPT); UART_PUTS_P(UART_STR_PROMPT);
uartcmd_clear_buffer(); uartcmd_clear_buffer();
longjmp(newmode_jmpbuf, res); longjmp(newmode_jmpbuf, res);
#ifdef JOYSTICK_SUPPORT #ifdef JOYSTICK_SUPPORT
} else { } else {
uart_puts_p(UART_STR_GAMEMO_ERR); UART_PUTS_P(UART_STR_GAMEMO_ERR);
} }
#endif #endif
} else { } 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 case '\177': // DEL
if (g_rx_index != 0) { if (g_rx_index != 0) {
g_rx_buffer[--g_rx_index] = 0; g_rx_buffer[--g_rx_index] = 0;
uart_puts_p(UART_STR_BACKSPACE); UART_PUTS_P(UART_STR_BACKSPACE);
} }
break; break;
case 27: // ignore Esc case 27: // ignore Esc
@ -266,8 +273,8 @@ static bool uartcmd_read_until_enter(void) {
} }
} else if ((uart_result & 0xFF00u) != UART_NO_DATA) { } else if ((uart_result & 0xFF00u) != UART_NO_DATA) {
uartcmd_clear_buffer(); uartcmd_clear_buffer();
uart_puts_p(UART_STR_UART_ERR); UART_PUTS_P(UART_STR_UART_ERR);
uart_puts_p(UART_STR_PROMPT); UART_PUTS_P(UART_STR_PROMPT);
break; break;
} else { } else {
break; break;
@ -276,8 +283,8 @@ static bool uartcmd_read_until_enter(void) {
if (g_rx_index >= (UART_BUFFER_SIZE - 1)) { if (g_rx_index >= (UART_BUFFER_SIZE - 1)) {
uartcmd_clear_buffer(); uartcmd_clear_buffer();
uart_puts_p(UART_STR_TOOLONG); UART_PUTS_P(UART_STR_TOOLONG);
uart_puts_p(UART_STR_PROMPT); UART_PUTS_P(UART_STR_PROMPT);
} }
return false; return false;
} }
@ -290,7 +297,7 @@ void uartcmd_process(void) {
if (!strncmp_P(g_rx_buffer, UART_CMD_ERASE, UART_BUFFER_SIZE)) { if (!strncmp_P(g_rx_buffer, UART_CMD_ERASE, UART_BUFFER_SIZE)) {
uartcmd_erase_eeprom(); uartcmd_erase_eeprom();
} else if (!strncmp_P(g_rx_buffer, UART_CMD_HELP, UART_BUFFER_SIZE)) { } 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) || } 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)) { !strncmp_P(g_rx_buffer, UART_CMD_MODE_ARG, UART_BUFFER_SIZE)) {
uartcmd_print_mode(); uartcmd_print_mode();
@ -307,9 +314,9 @@ void uartcmd_process(void) {
} else if (!strncmp_P(g_rx_buffer, UART_CMD_SCROLL, 7)) { } else if (!strncmp_P(g_rx_buffer, UART_CMD_SCROLL, 7)) {
uartcmd_scroll_message(); uartcmd_scroll_message();
} else { } 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(); uartcmd_clear_buffer();
} }
} }

Loading…
Cancel
Save