From b844e92ffab335cad8b6179669819975c85c1fef Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Thu, 4 Dec 2014 10:15:36 -0600 Subject: [PATCH] Nucleo-f4x1re: Add comments about pin conflicts; Fix GPIO configuration --- configs/nucleo-f4x1re/README.txt | 5 +++++ configs/nucleo-f4x1re/src/nucleo-f4x1re.h | 5 +++++ configs/nucleo-f4x1re/src/stm32_ajoystick.c | 25 +++++++++++++++++++-- 3 files changed, 33 insertions(+), 2 deletions(-) diff --git a/configs/nucleo-f4x1re/README.txt b/configs/nucleo-f4x1re/README.txt index 4b40e4ac43..2d836583c3 100644 --- a/configs/nucleo-f4x1re/README.txt +++ b/configs/nucleo-f4x1re/README.txt @@ -536,6 +536,11 @@ Shields All buttons are pulled on the shield. A sensed low value indicates when the button is pressed. + NOTE: Button F cannot be used with the default USART1 configuration + because PA9 is configured for USART1_RX by default. Use select + different USART1 pins in the board.h file or select a different + USART + Itead Joystick Signal interpretation: --------- ----------------------- --------------------------- diff --git a/configs/nucleo-f4x1re/src/nucleo-f4x1re.h b/configs/nucleo-f4x1re/src/nucleo-f4x1re.h index 90896fd114..880d1748ae 100644 --- a/configs/nucleo-f4x1re/src/nucleo-f4x1re.h +++ b/configs/nucleo-f4x1re/src/nucleo-f4x1re.h @@ -193,6 +193,11 @@ * * All buttons are pulled on the shield. A sensed low value indicates * when the button is pressed. + * + * NOTE: Button F cannot be used with the default USART1 configuration + * because PA9 is configured for USART1_RX by default. Use select + * different USART1 pins in the board.h file or select a different + * USART */ #define ADC_XOUPUT 1 /* X output is on ADC channel 1 */ diff --git a/configs/nucleo-f4x1re/src/stm32_ajoystick.c b/configs/nucleo-f4x1re/src/stm32_ajoystick.c index 69e0c209d1..37c2eead31 100644 --- a/configs/nucleo-f4x1re/src/stm32_ajoystick.c +++ b/configs/nucleo-f4x1re/src/stm32_ajoystick.c @@ -69,6 +69,10 @@ #ifdef CONFIG_AJOYSTICK +/* A no-ADC, buttons only version can be built for testing */ + +#undef NO_JOYSTICK_ADC + /* Maximum number of ADC channels */ #define MAX_ADC_CHANNELS 8 @@ -121,7 +125,7 @@ static int ajoy_interrupt(int irq, FAR void *context); static const uint32_t g_joygpio[AJOY_NGPIOS] = { GPIO_BUTTON_1, GPIO_BUTTON_2, GPIO_BUTTON_3, GPIO_BUTTON_4, - GPIO_BUTTON_5, GPIO_BUTTON_6, GPIO_BUTTON_6 + GPIO_BUTTON_5, GPIO_BUTTON_6, GPIO_BUTTON_7 }; /* This is the button joystick lower half driver interface */ @@ -134,9 +138,11 @@ static const struct ajoy_lowerhalf_s g_ajoylower = .al_enable = ajoy_enable, }; +#ifndef NO_JOYSTICK_ADC /* Descriptor for the open ADC driver */ static int g_adcfd = -1; +#endif /* Current interrupt handler and argument */ @@ -172,6 +178,7 @@ static ajoy_buttonset_t ajoy_supported(FAR const struct ajoy_lowerhalf_s *lower) static int ajoy_sample(FAR const struct ajoy_lowerhalf_s *lower, FAR struct ajoy_sample_s *sample) { +#ifndef NO_JOYSTICK_ADC struct adc_msg_s adcmsg[MAX_ADC_CHANNELS]; FAR struct adc_msg_s *ptr; ssize_t nread; @@ -243,10 +250,16 @@ static int ajoy_sample(FAR const struct ajoy_lowerhalf_s *lower, if (have != 3) { - idbg("ERROR: Could not find joystack channels\n"); + idbg("ERROR: Could not find joystick channels\n"); return -EIO; } +#else + /* ADC support is disabled */ + + sample->as_x = 0; + sample->as_y = 0; +#endif /* Sample the discrete button inputs */ @@ -420,6 +433,9 @@ int board_ajoy_initialize(void) int ret; int i; +#ifndef NO_JOYSTICK_ADC + ivdbg("Initialize ADC driver: /dev/adc0\n"); + /* Initialize ADC. We will need this to read the ADC inputs */ ret = board_adc_initialize(); @@ -438,6 +454,7 @@ int board_ajoy_initialize(void) idbg("ERROR: Failed to open /dev/adc0: %d\n", errcode); return -errcode; } +#endif /* Configure the GPIO pins as interrupting inputs. */ @@ -450,12 +467,16 @@ int board_ajoy_initialize(void) /* Register the joystick device as /dev/ajoy0 */ + ivdbg("Initialize joystick driver: /dev/ajoy0\n"); + ret = ajoy_register("/dev/ajoy0", &g_ajoylower); if (ret < 0) { idbg("ERROR: ajoy_register failed: %d\n", ret); +#ifndef NO_JOYSTICK_ADC close(g_adcfd); g_adcfd = -1; +#endif } return ret;