From 1dcbeab4f4dfc5c42a208577c2ecc9ddbc030dd7 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Fri, 28 Nov 2014 12:05:08 -0600 Subject: [PATCH] STM3210E-EVAL: Don't treat joystick as buttons if the DJOYSTICK driver is enabled --- configs/stm3210e-eval/include/board.h | 62 +++++++++++--------- configs/stm3210e-eval/src/stm3210e-eval.h | 65 ++++++++++++--------- configs/stm3210e-eval/src/stm32_buttons.c | 13 ++++- configs/stm3210e-eval/src/stm32_pmbuttons.c | 14 +++-- 4 files changed, 93 insertions(+), 61 deletions(-) diff --git a/configs/stm3210e-eval/include/board.h b/configs/stm3210e-eval/include/board.h index e134954032..25cbcd4020 100644 --- a/configs/stm3210e-eval/include/board.h +++ b/configs/stm3210e-eval/include/board.h @@ -167,41 +167,51 @@ /* The STM3210E-EVAL supports several buttons * - * Reset -- Connected to NRST - * Wakeup -- Connected to PA.0 - * Tamper -- Connected to PC.13 - * Key -- Connected to PG.8 + * Reset -- Connected to NRST + * Wakeup -- Connected to PA.0 + * Tamper -- Connected to PC.13 + * Key -- Connected to PG.8 * * And a Joystick * - * Joystick center -- Connected to PG.7 - * Joystick down -- Connected to PD.3 - * Joystick left -- Connected to PG.14 - * Joystick right -- Connected to PG.13 - * Joystick up -- Connected to PG.15 + * Joystick center -- Connected to PG.7 + * Joystick down -- Connected to PD.3 + * Joystick left -- Connected to PG.14 + * Joystick right -- Connected to PG.13 + * Joystick up -- Connected to PG.15 + * + * The Joystick is treated like the other buttons unless CONFIG_DJOYSTICK + * is defined, then it is assumed that they should be used by the discrete + * joystick driver. */ -#define BUTTON_WAKEUP 0 -#define BUTTON_TAMPER 1 -#define BUTTON_KEY 2 +#define BUTTON_WAKEUP 0 +#define BUTTON_TAMPER 1 +#define BUTTON_KEY 2 -#define JOYSTICK_SEL 3 -#define JOYSTICK_DOWN 4 -#define JOYSTICK_LEFT 5 -#define JOYSTICK_RIGHT 6 -#define JOYSTICK_UP 7 +#ifdef CONFIG_DJOYSTICK +# define NUM_BUTTONS 3 +#else +# define JOYSTICK_SEL 3 +# define JOYSTICK_DOWN 4 +# define JOYSTICK_LEFT 5 +# define JOYSTICK_RIGHT 6 +# define JOYSTICK_UP 7 -#define NUM_BUTTONS 8 +# define NUM_BUTTONS 8 +#endif -#define BUTTON_WAKEUP_BIT (1 << BUTTON_WAKEUP) -#define BUTTON_TAMPER_BIT (1 << BUTTON_TAMPER) -#define BUTTON_KEY_BIT (1 << BUTTON_KEY) +#define BUTTON_WAKEUP_BIT (1 << BUTTON_WAKEUP) +#define BUTTON_TAMPER_BIT (1 << BUTTON_TAMPER) +#define BUTTON_KEY_BIT (1 << BUTTON_KEY) -#define JOYSTICK_SEL_BIT (1 << JOYSTICK_SEL) -#define JOYSTICK_DOWN_BIT (1 << JOYSTICK_DOWN) -#define JOYSTICK_LEFT_BIT (1 << JOYSTICK_LEFT) -#define JOYSTICK_RIGHT_BIT (1 << JOYSTICK_RIGHT) -#define JOYSTICK_UP_BIT (1 << JOYSTICK_UP) +#ifdef CONFIG_DJOYSTICK +# define JOYSTICK_SEL_BIT (1 << JOYSTICK_SEL) +# define JOYSTICK_DOWN_BIT (1 << JOYSTICK_DOWN) +# define JOYSTICK_LEFT_BIT (1 << JOYSTICK_LEFT) +# define JOYSTICK_RIGHT_BIT (1 << JOYSTICK_RIGHT) +# define JOYSTICK_UP_BIT (1 << JOYSTICK_UP) +#endif /************************************************************************************ * Public Data diff --git a/configs/stm3210e-eval/src/stm3210e-eval.h b/configs/stm3210e-eval/src/stm3210e-eval.h index a210def03f..ed46aeb2c9 100644 --- a/configs/stm3210e-eval/src/stm3210e-eval.h +++ b/configs/stm3210e-eval/src/stm3210e-eval.h @@ -68,42 +68,49 @@ /* STM3210E-EVAL GPIOs **************************************************************/ /* LEDs */ -#define GPIO_LED1 (GPIO_OUTPUT|GPIO_CNF_OUTPP|GPIO_MODE_50MHz|\ - GPIO_OUTPUT_CLEAR|GPIO_PORTF|GPIO_PIN6) -#define GPIO_LED2 (GPIO_OUTPUT|GPIO_CNF_OUTPP|GPIO_MODE_50MHz|\ - GPIO_OUTPUT_CLEAR|GPIO_PORTF|GPIO_PIN7) -#define GPIO_LED3 (GPIO_OUTPUT|GPIO_CNF_OUTPP|GPIO_MODE_50MHz|\ - GPIO_OUTPUT_CLEAR|GPIO_PORTF|GPIO_PIN8) -#define GPIO_LED4 (GPIO_OUTPUT|GPIO_CNF_OUTPP|GPIO_MODE_50MHz|\ - GPIO_OUTPUT_CLEAR|GPIO_PORTF|GPIO_PIN9) +#define GPIO_LED1 (GPIO_OUTPUT|GPIO_CNF_OUTPP|GPIO_MODE_50MHz|\ + GPIO_OUTPUT_CLEAR|GPIO_PORTF|GPIO_PIN6) +#define GPIO_LED2 (GPIO_OUTPUT|GPIO_CNF_OUTPP|GPIO_MODE_50MHz|\ + GPIO_OUTPUT_CLEAR|GPIO_PORTF|GPIO_PIN7) +#define GPIO_LED3 (GPIO_OUTPUT|GPIO_CNF_OUTPP|GPIO_MODE_50MHz|\ + GPIO_OUTPUT_CLEAR|GPIO_PORTF|GPIO_PIN8) +#define GPIO_LED4 (GPIO_OUTPUT|GPIO_CNF_OUTPP|GPIO_MODE_50MHz|\ + GPIO_OUTPUT_CLEAR|GPIO_PORTF|GPIO_PIN9) /* BUTTONS -- NOTE that some have EXTI interrupts configured */ -#define MIN_IRQBUTTON BUTTON_KEY -#define MAX_IRQBUTTON JOYSTICK_UP -#define NUM_IRQBUTTONS (JOYSTICK_UP - BUTTON_KEY + 1) +#ifdef CONFIG_DJOYSTICK +# define MIN_IRQBUTTON BUTTON_KEY +# define MAX_IRQBUTTON BUTTON_KEY +# define NUM_IRQBUTTONS (1) +#else +# define MIN_IRQBUTTON BUTTON_KEY +# define MAX_IRQBUTTON JOYSTICK_UP +# define NUM_IRQBUTTONS (JOYSTICK_UP - BUTTON_KEY + 1) +#endif -#define GPIO_BTN_WAKEUP (GPIO_INPUT|GPIO_CNF_INFLOAT|GPIO_MODE_INPUT|\ - GPIO_PORTA|GPIO_PIN0) -#define GPIO_BTN_TAMPER (GPIO_INPUT|GPIO_CNF_INFLOAT|GPIO_MODE_INPUT|\ - GPIO_PORTC|GPIO_PIN13) -#define GPIO_BTN_KEY (GPIO_INPUT|GPIO_CNF_INFLOAT|GPIO_MODE_INPUT|\ - GPIO_EXTI|GPIO_PORTG|GPIO_PIN8) -#define GPIO_JOY_SEL (GPIO_INPUT|GPIO_CNF_INFLOAT|GPIO_MODE_INPUT|\ - GPIO_EXTI|GPIO_PORTG|GPIO_PIN7) -#define GPIO_JOY_DOWN (GPIO_INPUT|GPIO_CNF_INFLOAT|GPIO_MODE_INPUT|\ - GPIO_EXTI|GPIO_PORTD|GPIO_PIN3) -#define GPIO_JOY_LEFT (GPIO_INPUT|GPIO_CNF_INFLOAT|GPIO_MODE_INPUT|\ - GPIO_EXTI|GPIO_PORTG|GPIO_PIN14) -#define GPIO_JOY_RIGHT (GPIO_INPUT|GPIO_CNF_INFLOAT|GPIO_MODE_INPUT|\ - GPIO_EXTI|GPIO_PORTG|GPIO_PIN13) -#define GPIO_JOY_UP (GPIO_INPUT|GPIO_CNF_INFLOAT|GPIO_MODE_INPUT|\ - GPIO_EXTI|GPIO_PORTG|GPIO_PIN15) +#define GPIO_BTN_WAKEUP (GPIO_INPUT|GPIO_CNF_INFLOAT|GPIO_MODE_INPUT|\ + GPIO_PORTA|GPIO_PIN0) +#define GPIO_BTN_TAMPER (GPIO_INPUT|GPIO_CNF_INFLOAT|GPIO_MODE_INPUT|\ + GPIO_PORTC|GPIO_PIN13) +#define GPIO_BTN_KEY (GPIO_INPUT|GPIO_CNF_INFLOAT|GPIO_MODE_INPUT|\ + GPIO_EXTI|GPIO_PORTG|GPIO_PIN8) + +#define GPIO_JOY_SEL (GPIO_INPUT|GPIO_CNF_INFLOAT|GPIO_MODE_INPUT|\ + GPIO_EXTI|GPIO_PORTG|GPIO_PIN7) +#define GPIO_JOY_DOWN (GPIO_INPUT|GPIO_CNF_INFLOAT|GPIO_MODE_INPUT|\ + GPIO_EXTI|GPIO_PORTD|GPIO_PIN3) +#define GPIO_JOY_LEFT (GPIO_INPUT|GPIO_CNF_INFLOAT|GPIO_MODE_INPUT|\ + GPIO_EXTI|GPIO_PORTG|GPIO_PIN14) +#define GPIO_JOY_RIGHT (GPIO_INPUT|GPIO_CNF_INFLOAT|GPIO_MODE_INPUT|\ + GPIO_EXTI|GPIO_PORTG|GPIO_PIN13) +#define GPIO_JOY_UP (GPIO_INPUT|GPIO_CNF_INFLOAT|GPIO_MODE_INPUT|\ + GPIO_EXTI|GPIO_PORTG|GPIO_PIN15) /* SPI FLASH chip select: PA.4 */ -#define GPIO_FLASH_CS (GPIO_OUTPUT|GPIO_CNF_OUTPP|GPIO_MODE_50MHz|\ - GPIO_OUTPUT_SET|GPIO_PORTB|GPIO_PIN2) +#define GPIO_FLASH_CS (GPIO_OUTPUT|GPIO_CNF_OUTPP|GPIO_MODE_50MHz|\ + GPIO_OUTPUT_SET|GPIO_PORTB|GPIO_PIN2) /* Backlight control: PA.8 * diff --git a/configs/stm3210e-eval/src/stm32_buttons.c b/configs/stm3210e-eval/src/stm32_buttons.c index 845eb54361..cb155feab2 100644 --- a/configs/stm3210e-eval/src/stm32_buttons.c +++ b/configs/stm3210e-eval/src/stm32_buttons.c @@ -61,8 +61,16 @@ static const uint16_t g_buttons[NUM_BUTTONS] = { - GPIO_BTN_WAKEUP, GPIO_BTN_TAMPER, GPIO_BTN_KEY, GPIO_JOY_SEL, - GPIO_JOY_DOWN, GPIO_JOY_LEFT, GPIO_JOY_RIGHT, GPIO_JOY_UP + GPIO_BTN_WAKEUP, GPIO_BTN_TAMPER, GPIO_BTN_KEY, + + /* The Joystick is treated like the other buttons unless CONFIG_DJOYSTICK + * is defined, then it is assumed that they should be used by the discrete + * joystick driver. + */ + +#ifndef CONFIG_DJOYSTICK + GPIO_JOY_SEL, GPIO_JOY_DOWN, GPIO_JOY_LEFT, GPIO_JOY_RIGHT, GPIO_JOY_UP +#endif }; /**************************************************************************** @@ -166,6 +174,7 @@ xcpt_t board_button_irq(int id, xcpt_t irqhandler) { oldhandler = stm32_gpiosetevent(g_buttons[id], true, true, true, irqhandler); } + return oldhandler; } #endif diff --git a/configs/stm3210e-eval/src/stm32_pmbuttons.c b/configs/stm3210e-eval/src/stm32_pmbuttons.c index a042a54e62..6b7677aca2 100644 --- a/configs/stm3210e-eval/src/stm32_pmbuttons.c +++ b/configs/stm3210e-eval/src/stm32_pmbuttons.c @@ -63,8 +63,11 @@ # error "CONFIG_ARCH_BUTTONS is not defined in the configuration" #endif -#define BUTTON_MIN 0 -#define BUTTON_MAX 7 +#define BUTTON_MIN 0 +#ifdef CONFIG_DJOYSTICK +# define BUTTON_MAX 2 +# define BUTTON_MAX 7 +#endif #ifndef CONFIG_PM_BUTTONS_MIN # define CONFIG_PM_BUTTONS_MIN BUTTON_MIN @@ -76,8 +79,9 @@ #if CONFIG_PM_BUTTONS_MIN > CONFIG_PM_BUTTONS_MAX # error "CONFIG_PM_BUTTONS_MIN > CONFIG_PM_BUTTONS_MAX" #endif -#if CONFIG_PM_BUTTONS_MAX > 7 -# error "CONFIG_PM_BUTTONS_MAX > 7" + +#if CONFIG_PM_BUTTONS_MAX > BUTTON_MAX +# error "CONFIG_PM_BUTTONS_MAX > BUTTON_MAX" #endif #ifndef CONFIG_ARCH_IRQBUTTONS @@ -87,6 +91,7 @@ #ifndef CONFIG_PM_IRQBUTTONS_MIN # define CONFIG_PM_IRQBUTTONS_MIN CONFIG_PM_BUTTONS_MIN #endif + #ifndef CONFIG_PM_IRQBUTTONS_MAX # define CONFIG_PM_IRQBUTTONS_MAX CONFIG_PM_BUTTONS_MAX #endif @@ -94,6 +99,7 @@ #if CONFIG_PM_IRQBUTTONS_MIN > CONFIG_PM_IRQBUTTONS_MAX # error "CONFIG_PM_IRQBUTTONS_MIN > CONFIG_PM_IRQBUTTONS_MAX" #endif + #if CONFIG_PM_IRQBUTTONS_MAX > 7 # error "CONFIG_PM_IRQBUTTONS_MAX > 7" #endif