From 69fcd1c048d0979f1ba75520d64bd003f52a4df0 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Wed, 3 Dec 2014 14:33:00 -0600 Subject: [PATCH] SAMA5D3 Xplained: A few fixes for the AJoystick driver (still not working) --- configs/sama5d3-xplained/README.txt | 8 +++++++- configs/sama5d3-xplained/src/sam_ajoystick.c | 19 ++++++++----------- .../sama5d3-xplained/src/sama5d3-xplained.h | 6 ++++-- 3 files changed, 19 insertions(+), 14 deletions(-) diff --git a/configs/sama5d3-xplained/README.txt b/configs/sama5d3-xplained/README.txt index e5417c22ce..43ab3c7f79 100644 --- a/configs/sama5d3-xplained/README.txt +++ b/configs/sama5d3-xplained/README.txt @@ -2605,6 +2605,9 @@ Shields A1 Joystick X Output J17 pin 2 PD21 AD1 (function 1) --------- ----------------- ---------- ---------------------- + All buttons are pulled on the shield. A sensed low value indicates + when the button is pressed. + Possible conflicts: ---- ----- -------------------------------------------------- @@ -2672,8 +2675,11 @@ Shields Library routines CONFIG_SCHED_WORKQUEUE=y : Work queue support is needed - This enables the analog joystick example at apps/examples/ajoystick: + There is nothing in the configuration that currently uses the joystick. + For testing, you can add the following configuration options to enable the + analog joystick example at apps/examples/ajoystick: + CONFIG_NSH_ARCHINIT=y CONFIG_EXAMPLES_AJOYSTICK=y CONFIG_EXAMPLES_AJOYSTICK_DEVNAME="/dev/ajoy0" CONFIG_EXAMPLES_AJOYSTICK_SIGNO=13 diff --git a/configs/sama5d3-xplained/src/sam_ajoystick.c b/configs/sama5d3-xplained/src/sam_ajoystick.c index 4be9aef0a0..f1911e2360 100644 --- a/configs/sama5d3-xplained/src/sam_ajoystick.c +++ b/configs/sama5d3-xplained/src/sam_ajoystick.c @@ -157,7 +157,7 @@ static FAR void *g_ajoyarg; * Name: ajoy_supported * * Description: - * Return the set of buttons supported on the button joystick device + * Return the set of buttons supported on the button joystick device * ****************************************************************************/ @@ -260,22 +260,19 @@ static int ajoy_sample(FAR const struct ajoy_lowerhalf_s *lower, static ajoy_buttonset_t ajoy_buttons(FAR const struct ajoy_lowerhalf_s *lower) { ajoy_buttonset_t ret = 0; - ajoy_buttonset_t bit; - bool released; int i; /* Read each joystick GPIO value */ for (i = 0; i < AJOY_NGPIOS; i++) { - bit = (1 << i); - if ((bit & AJOY_SUPPORTED) != 0) + /* Button outputs are pulled high. So a sensed low level means that the + * button is pressed. + */ + + if (!sam_pioread(g_joypio[i])) { - released = sam_pioread(g_joypio[i]); - if (!released) - { - ret |= bit; - } + ret |= (1 << i); } } @@ -336,7 +333,7 @@ static void ajoy_enable(FAR const struct ajoy_lowerhalf_s *lower, * interrupts. */ - sam_pioirqenable(g_joypio[i]); + sam_pioirqenable(g_joyirq[i]); } } } diff --git a/configs/sama5d3-xplained/src/sama5d3-xplained.h b/configs/sama5d3-xplained/src/sama5d3-xplained.h index 154fc564f9..f33b1ba112 100644 --- a/configs/sama5d3-xplained/src/sama5d3-xplained.h +++ b/configs/sama5d3-xplained/src/sama5d3-xplained.h @@ -506,6 +506,9 @@ * A0 Joystick Y Output J17 pin 1 PC18 AD0 (function 4) * A1 Joystick X Output J17 pin 2 PD21 AD1 (function 1) * --------- ----------------- ---------- ---------------------- + * + * All buttons are pulled on the shield. A sensed low value indicates + * when the button is pressed. */ #define ADC_XOUPUT 1 /* X output is on ADC channel 1 */ @@ -570,7 +573,6 @@ #define PIO_JUMP PIO_BUTTON_3 #define IRQ_JUMP IRQ_BUTTON_3 - /************************************************************************************ * Public Types ************************************************************************************/ @@ -697,7 +699,7 @@ bool sam_writeprotected(int slotno); * Name: sam_usbinitialize * * Description: - * Called from sam_usbinitialize very early in inialization to setup USB-related + * Called from sam_usbinitialize very early in initialization to setup USB-related * PIO pins for the SAMA5D3-Xplained board. * ************************************************************************************/