From 720d547f4a7af774214267949dd41d3c3c6dec58 Mon Sep 17 00:00:00 2001 From: Christian Kroll Date: Sun, 25 May 2014 11:08:35 +0200 Subject: [PATCH] joystick support for lolshield (A0-up,A1-down,A2-left,A3-right,A5-fire) --- profiles/FFM-Jochen | 6 + profiles/FFM-LedBrett | 20 +++- profiles/LoL-Shield_Leonardo | 11 +- profiles/LoL-Shield_Mega2560 | 11 +- profiles/LoL-Shield_Uno-Duemilanove-Diavolino | 11 +- profiles/borg-16 | 14 ++- profiles/borg-ancient | 16 ++- profiles/borg-andre | 14 ++- profiles/borg-ls | 17 ++- profiles/borgjacke | 27 +++-- src/joystick/Makefile | 3 + src/joystick/config.in | 111 +++++++++++------- src/joystick/joystick.h | 62 +++++++++- src/joystick/lolshield_joystick.c | 89 ++++++++++++++ 14 files changed, 337 insertions(+), 75 deletions(-) create mode 100644 src/joystick/lolshield_joystick.c diff --git a/profiles/FFM-Jochen b/profiles/FFM-Jochen index f509c24..5da3e44 100644 --- a/profiles/FFM-Jochen +++ b/profiles/FFM-Jochen @@ -37,7 +37,12 @@ SCROLL_X_SPEED=10 SCROLL_Y_SPEED=20 SCROLLTEXT_TEXT="5+:<5|90>6:<6|78>:p10d50/#Labor#<5;>5|30<6;>6|40<6;p10+d50/# Borg#2d50-+/#Widerstand#ist#d50-b20p15#ZWECKLOS !" +# RFM12_SUPPORT is not set + +# +# Joystick Support +# # JOYSTICK_SUPPORT is not set +JOYSTICK_CHOICE="JOY_PARALLEL" CAN_SUPPORT=y SPI_HARDWARE=y SPI_PORTIDX=1 @@ -91,6 +97,7 @@ GOL_DELAY=12 GOL_CYCLES=180 # ANIMATION_BREAKOUT is not set # ANIMATION_MHERWEG is not set +# ANIMATION_MOIRE is not set # ANIMATION_LTN_ANT is not set ANIMATION_TIME=y TIME_MASTER_ADDR=00 @@ -99,9 +106,17 @@ TIME_UPDATE_TIMEOUT=50 # ANIMATION_LABORLOGO is not set # ANIMATION_AMPHIBIAN is not set # ANIMATION_LOGO_OOS is not set -# ANIMATION_LOGO_28C3 is not set +# ANIMATION_FAIRYDUST is not set + +# +# Fixed-point math patterns +# # ANIMATION_PLASMA is not set +FP_PLASMA_DELAY=1 # ANIMATION_PSYCHEDELIC is not set +FP_PSYCHO_DELAY=15 +# ANIMATION_BLACKHOLE is not set +# ANIMATION_SQUARES is not set ANIMATION_TESTS=y ANIMATION_OFF=y diff --git a/profiles/borgjacke b/profiles/borgjacke index 73bf84b..3468712 100644 --- a/profiles/borgjacke +++ b/profiles/borgjacke @@ -49,9 +49,12 @@ BIT_MISO=6 BIT_SCK=7 PORT_SS=PORTB BIT_SS=4 + +# +# Joystick Support +# JOYSTICK_SUPPORT=y -# PARALLEL_JOYSTICK_SUPPORT is not set -# NES_PAD_SUPPORT is not set +JOYSTICK_CHOICE=JOY_RFM12 RFM12_JOYSTICK_SUPPORT=y # CAN_SUPPORT is not set MENU_SUPPORT=y @@ -65,7 +68,7 @@ GAME_TETRIS=y # GAME_TETRIS_FP is not set GAME_SPACE_INVADERS=y GAME_SNAKE=y -# GAME_BREAKOUT is not set +GAME_BREAKOUT=y # # Animations @@ -91,14 +94,15 @@ MATRIX_STREAMER_NUM=30 MATRIX_CYCLES=500 MATRIX_DELAY=60 ANIMATION_RANDOM_BRIGHT=y -# ANIMATION_STONEFLY is not set -# ANIMATION_FLYINGDOTS is not set +ANIMATION_STONEFLY=y +ANIMATION_FLYINGDOTS=y ANIMATION_GAMEOFLIFE=y GOL_DELAY=100 GOL_CYCLES=360 -# ANIMATION_BREAKOUT is not set +ANIMATION_BREAKOUT=y # ANIMATION_MHERWEG is not set -# ANIMATION_LTN_ANT is not set +ANIMATION_MOIRE=y +ANIMATION_LTN_ANT=y # ANIMATION_TIME is not set TIME_MASTER_ADDR=0x00 TIME_UPDATE_TIMEOUT=23 @@ -107,9 +111,16 @@ ANIMATION_LABORLOGO=y # ANIMATION_AMPHIBIAN is not set # ANIMATION_LOGO_OOS is not set # ANIMATION_FAIRYDUST is not set + +# +# Fixed-point math patterns +# ANIMATION_PLASMA=y +FP_PLASMA_DELAY=1 ANIMATION_PSYCHEDELIC=y -# ANIMATION_BLACKHOLE is not set +FP_PSYCHO_DELAY=15 +ANIMATION_BLACKHOLE=y +ANIMATION_SQUARES=y ANIMATION_TESTS=y ANIMATION_OFF=y diff --git a/src/joystick/Makefile b/src/joystick/Makefile index bbbb411..6a5b92e 100644 --- a/src/joystick/Makefile +++ b/src/joystick/Makefile @@ -18,6 +18,9 @@ endif ifeq ($(HC165_JOYSTICK_SUPPORT), y) SRC = hc165_joystick.c endif +ifeq ($(LOLSHIELD_JOYSTICK_SUPPORT), y) + SRC = lolshield_joystick.c +endif ifeq ($(NULL_JOYSTICK_SUPPORT), y) SRC = null_joystick.c endif diff --git a/src/joystick/config.in b/src/joystick/config.in index 68c90df..d67c536 100644 --- a/src/joystick/config.in +++ b/src/joystick/config.in @@ -1,18 +1,36 @@ -dep_bool_menu "joystick support" JOYSTICK_SUPPORT y +mainmenu_option next_comment +comment "Joystick Support" + +bool "Joystick Support" JOYSTICK_SUPPORT n + +if [ "x$JOYSTICK_CHOICE" == "x" ] ; then + define_string JOYSTICK_CHOICE "JOY_PARALLEL" +fi if [ "$JOYSTICK_SUPPORT" = "y" ]; then -###################### Parallel joystick menu ################################# - dep_bool_menu "parallel joystick support" PARALLEL_JOYSTICK_SUPPORT y + choice 'Joystick Type' \ + "Atari-9-Pin JOY_PARALLEL \ + NES-Game-Pad JOY_NES_PAD \ + RFM12 JOY_RFM12 \ + LED-Brett JOY_LEDBRETT \ + LoL-Shield JOY_LOLSHIELD \ + None JOY_NULL" \ + 'Atari-9-Pin' JOYSTICK_CHOICE - if [ "$PARALLEL_JOYSTICK_SUPPORT" = "y" ]; then - choice 'Pin up' \ +###################### parallel joystick menu ################################# + if [ "$JOYSTICK_CHOICE" == "JOY_PARALLEL" ]; then + mainmenu_option next_comment + comment "Joystick Settings" + + define_bool PARALLEL_JOYSTICK_SUPPORT y + choice 'Pin up' \ "PINA PINA \ PINB PINB \ PINC PINC \ PIND PIND" \ 'PINB' JOYSTICK_PIN_UP - choice 'Bit up' \ + choice 'Bit up' \ "Bit0 0 \ Bit1 1 \ Bit2 2 \ @@ -23,14 +41,14 @@ if [ "$JOYSTICK_SUPPORT" = "y" ]; then Bit7 7" \ 'Bit0' JOYSTICK_BIT_UP - choice 'Pin down' \ + choice 'Pin down' \ "PINA PINA \ PINB PINB \ PINC PINC \ PIND PIND" \ 'PINB' JOYSTICK_PIN_DOWN - choice 'Bit down' \ + choice 'Bit down' \ "Bit0 0 \ Bit1 1 \ Bit2 2 \ @@ -41,14 +59,14 @@ if [ "$JOYSTICK_SUPPORT" = "y" ]; then Bit7 7" \ 'Bit1' JOYSTICK_BIT_DOWN - choice 'Pin left' \ + choice 'Pin left' \ "PINA PINA \ PINB PINB \ PINC PINC \ PIND PIND" \ 'PINB' JOYSTICK_PIN_LEFT - choice 'Bit left' \ + choice 'Bit left' \ "Bit0 0 \ Bit1 1 \ Bit2 2 \ @@ -59,14 +77,14 @@ if [ "$JOYSTICK_SUPPORT" = "y" ]; then Bit7 7" \ 'Bit2' JOYSTICK_BIT_LEFT - choice 'Pin right' \ + choice 'Pin right' \ "PINA PINA \ PINB PINB \ PINC PINC \ PIND PIND" \ 'PINB' JOYSTICK_PIN_RIGHT - choice 'Bit right' \ + choice 'Bit right' \ "Bit0 0 \ Bit1 1 \ Bit2 2 \ @@ -77,14 +95,14 @@ if [ "$JOYSTICK_SUPPORT" = "y" ]; then Bit7 7" \ 'Bit3' JOYSTICK_BIT_RIGHT - choice 'Pin fire' \ + choice 'Pin fire' \ "PINA PINA \ PINB PINB \ PINC PINC \ PIND PIND" \ 'PIND' JOYSTICK_PIN_FIRE - choice 'Bit fire' \ + choice 'Bit fire' \ "Bit0 0 \ Bit1 1 \ Bit2 2 \ @@ -94,37 +112,40 @@ if [ "$JOYSTICK_SUPPORT" = "y" ]; then Bit6 6 \ Bit7 7" \ 'Bit3' JOYSTICK_BIT_FIRE - fi - endmenu + endmenu + fi ############################################################################### -###################### NES-Pad menu ################################# - dep_bool_menu "nes-pad support" NES_PAD_SUPPORT y +###################### NES-Pad menu ########################################### + if [ "$JOYSTICK_CHOICE" == "JOY_NES_PAD" ]; then + mainmenu_option next_comment + comment "Joystick Settings" - if [ "$NES_PAD_SUPPORT" = "y" ]; then - choice 'Port clk' \ + define_bool NES_PAD_SUPPORT y + + choice 'Port clk' \ "PORTA PORTA \ PORTB PORTB \ PORTC PORTC \ PORTD PORTD" \ 'PORTB' NES_PAD_PORT_CLK - choice 'Port ds' \ + choice 'Port ds' \ "PORTA PORTA \ PORTB PORTB \ PORTC PORTC \ PORTD PORTD" \ - 'PORTB' NES_PAD_PORT_PL + 'PORTB' NES_PAD_PORT_PL - choice 'Pin pl' \ + choice 'Pin pl' \ "PORTA PORTA \ PORTB PORTB \ PORTC PORTC \ PORTD PORTD" \ 'PORTB' NES_PAD_PORT_DS - choice 'Bit clk' \ + choice 'Bit clk' \ "Bit0 0 \ Bit1 1 \ Bit2 2 \ @@ -135,7 +156,7 @@ if [ "$JOYSTICK_SUPPORT" = "y" ]; then Bit7 7" \ 'Bit0' NES_PAD_BIT_CLK - choice 'Bit pl' \ + choice 'Bit pl' \ "Bit0 0 \ Bit1 1 \ Bit2 2 \ @@ -146,7 +167,7 @@ if [ "$JOYSTICK_SUPPORT" = "y" ]; then Bit7 7" \ 'Bit1' NES_PAD_BIT_PL - choice 'Bit ds' \ + choice 'Bit ds' \ "Bit0 0 \ Bit1 1 \ Bit2 2 \ @@ -157,28 +178,31 @@ if [ "$JOYSTICK_SUPPORT" = "y" ]; then Bit7 7" \ 'Bit2' NES_PAD_BIT_DS + endmenu fi - - endmenu ############################################################################### ###################### RFM12 joystick menu #################################### - dep_bool_menu "RFM12 Joystick support" RFM12_JOYSTICK_SUPPORT y - - endmenu + if [ "$JOYSTICK_CHOICE" == "JOY_RFM12" ]; then + define_bool RFM12_JOYSTICK_SUPPORT y + fi +############################################################################### ###################### 74HC165 joystick menu ################################# - dep_bool_menu "74HC165 joystick support" HC165_JOYSTICK_SUPPORT y + if [ "$JOYSTICK_CHOICE" == "JOY_LEDBRETT" ]; then + mainmenu_option next_comment + comment "Joystick Settings" - if [ "$HC165_JOYSTICK_SUPPORT" = "y" ]; then - choice 'Port load' \ + define_bool HC165_JOYSTICK_SUPPORT y + + choice 'Port load' \ "PORTA PORTA \ PORTB PORTB \ PORTC PORTC \ PORTD PORTD" \ 'PORTD' HC165_JOYSTICK_PORT_LOAD - choice 'Bit load' \ + choice 'Bit load' \ "Bit0 0 \ Bit1 1 \ Bit2 2 \ @@ -188,16 +212,23 @@ if [ "$JOYSTICK_SUPPORT" = "y" ]; then Bit6 6 \ Bit7 7" \ 'Bit2' HC165_JOYSTICK_BIT_LOAD + + endmenu fi - - endmenu ############################################################################### -###################### null joystick menu #################################### - bool "null joystick support" NULL_JOYSTICK_SUPPORT n +###################### LoL Shield joystick menu ############################### + if [ "$JOYSTICK_CHOICE" == "JOY_NULL" ]; then + define_bool NULL_JOYSTICK_SUPPORT y + fi ############################################################################### +###################### null joystick menu ##################################### + if [ "$JOYSTICK_CHOICE" == "JOY_LOLSHIELD" ]; then + define_bool LOLSHIELD_JOYSTICK_SUPPORT y + fi +############################################################################### fi -endmenu +endmenu \ No newline at end of file diff --git a/src/joystick/joystick.h b/src/joystick/joystick.h index 0c606f4..abd0a00 100644 --- a/src/joystick/joystick.h +++ b/src/joystick/joystick.h @@ -1,6 +1,10 @@ #ifndef JOYSTICK_H #define JOYSTICK_H +#ifdef __AVR__ +# include +#endif + #include "../config.h" extern unsigned char waitForFire; @@ -49,7 +53,63 @@ void joy_init(); # define JOYISRIGHT (0) # define JOYISFIRE (0) -# else +# elif defined (LOLSHIELD_JOYSTICK_SUPPORT) + +# 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__) + /* + * A0 => PC0 => JOYISUP + * A1 => PC1 => JOYISDOWN + * A2 => PC2 => JOYISLEFT + * A3 => PC3 => JOYISRIGHT + * A4 => PC4 => NC (JOYIS2GND) + * A5 => PC5 => JOYISFIRE + */ +# define JOYISUP (!(PINC & _BV(PINC0))) +# define JOYISDOWN (!(PINC & _BV(PINC1))) +# define JOYISLEFT (!(PINC & _BV(PINC2))) +# define JOYISRIGHT (!(PINC & _BV(PINC3))) +# define JOYISFIRE (!(PINC & _BV(PINC5))) +# elif defined (__AVR_ATmega32U4__) + /* + * A0 => PF7 => JOYISUP + * A1 => PF6 => JOYISDOWN + * A2 => PF5 => JOYISLEFT + * A3 => PF4 => JOYISRIGHT + * A4 => PF1 => NC (JOYIS2GND) + * A5 => PF0 => JOYISFIRE + */ +# define JOYISUP (!(PINF & _BV(PINF7))) +# define JOYISDOWN (!(PINF & _BV(PINF6))) +# define JOYISLEFT (!(PINF & _BV(PINF5))) +# define JOYISRIGHT (!(PINF & _BV(PINF4))) +# define JOYISFIRE (!(PINF & _BV(PINF0))) +# elif defined (__AVR_ATmega1280__) || \ + defined (__AVR_ATmega2560__) + /* + * A0 => PF0 => JOYISUP + * A1 => PF1 => JOYISDOWN + * A2 => PF2 => JOYISLEFT + * A3 => PF3 => JOYISRIGHT + * A4 => PF4 => NC (JOYIS2GND) + * A5 => PF5 => JOYISFIRE + */ +# define JOYISUP (!(PINF & _BV(PINF0))) +# define JOYISDOWN (!(PINF & _BV(PINF1))) +# define JOYISLEFT (!(PINF & _BV(PINF2))) +# define JOYISRIGHT (!(PINF & _BV(PINF3))) +# define JOYISFIRE (!(PINF & _BV(PINF5))) +# else +# error "Unsupported Arduino board!" +# endif + +# elif defined (PARALLEL_JOYSTICK_SUPPORT) # define JOYISUP (!(JOYSTICK_PIN_UP & (1< + +void joy_init(){ +#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__) + /* + * A0 => PC0 => JOYISUP + * A1 => PC1 => JOYISDOWN + * A2 => PC2 => JOYISLEFT + * A3 => PC3 => JOYISRIGHT + * A4 => PC4 => NC (JOYIS2GND) + * A5 => PC5 => JOYISFIRE + */ + + // set joystick pins to input + DDRC &= ~(_BV(PINC0) | _BV(PINC1) | _BV(PINC2) | + _BV(PINC3) | _BV(PINC4) | _BV(PINC5)); + // activate pullups + PORTC |= _BV(PINC0) | _BV(PINC1) | _BV(PINC2) | + _BV(PINC3) | _BV(PINC4) | _BV(PINC5); +#elif defined (__AVR_ATmega32U4__) + /* + * A0 => PF7 => JOYISUP + * A1 => PF6 => JOYISDOWN + * A2 => PF5 => JOYISLEFT + * A3 => PF4 => JOYISRIGHT + * A4 => PF1 => NC (JOYIS2GND) + * A5 => PF0 => JOYISFIRE + */ + + // set joystick pins to input + DDRF &= ~(_BV(PINF7) | _BV(PINF6) | _BV(PINF5) | + _BV(PINF4) | _BV(PINF1) | _BV(PINF0)); + // activate pullups + PORTF |= _BV(PINF7) | _BV(PINF6) | _BV(PINF5) | _BV(PINF4) | + _BV(PINF1) | _BV(PINF0); +#elif defined (__AVR_ATmega1280__) || \ + defined (__AVR_ATmega2560__) + /* + * A0 => PF0 => JOYISUP + * A1 => PF1 => JOYISDOWN + * A2 => PF2 => JOYISLEFT + * A3 => PF3 => JOYISRIGHT + * A4 => PF4 => NC (JOYIS2GND) + * A5 => PF5 => JOYISFIRE + */ + + // set joystick pins to input + DDRF &= ~(_BV(PINF0) | _BV(PINF1) | _BV(PINF2) | + _BV(PINF3) | _BV(PINF4) | _BV(PINF5)); + // activate pullups + PORTF |= _BV(PINF0) | _BV(PINF1) | _BV(PINF2) | + _BV(PINF3) | _BV(PINF4) | _BV(PINF5); +#else +# error "Unsupported Arduino board!" +#endif +}