summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGregory Nutt <gnutt@nuttx.org>2014-12-03 14:33:00 -0600
committerGregory Nutt <gnutt@nuttx.org>2014-12-03 14:33:00 -0600
commit6ffc5d24ec7bb1afb7ad2e7b1cb694ed96e358e8 (patch)
tree3bedbc1e8f933d7f5d126fbb8eaca982a7eb3c09
parenta8f3916dc112d98c0a45916dd2d9e6fb71539f0c (diff)
downloadnuttx-6ffc5d24ec7bb1afb7ad2e7b1cb694ed96e358e8.tar.gz
nuttx-6ffc5d24ec7bb1afb7ad2e7b1cb694ed96e358e8.tar.bz2
nuttx-6ffc5d24ec7bb1afb7ad2e7b1cb694ed96e358e8.zip
SAMA5D3 Xplained: A few fixes for the AJoystick driver (still not working)
-rw-r--r--apps/examples/ajoystick/ajoy_main.c20
-rw-r--r--nuttx/configs/sama5d3-xplained/README.txt8
-rw-r--r--nuttx/configs/sama5d3-xplained/src/sam_ajoystick.c19
-rw-r--r--nuttx/configs/sama5d3-xplained/src/sama5d3-xplained.h6
4 files changed, 29 insertions, 24 deletions
diff --git a/apps/examples/ajoystick/ajoy_main.c b/apps/examples/ajoystick/ajoy_main.c
index 85eec977c..c65866a0d 100644
--- a/apps/examples/ajoystick/ajoy_main.c
+++ b/apps/examples/ajoystick/ajoy_main.c
@@ -112,10 +112,10 @@ static b16_t g_ybslope;
/* Joystick button names */
-static const char *g_ajoynames[AJOY_NBUTTONS] =
+static const char *g_ajoynames[AJOY_NBUTTONS] =
{
- "SELECT", "FIRE", "JUMP", "BUTTON 3",
- "BUTTON 4", "BUTTON 5", "BUTTON 6", "BUTTON 7",
+ "SELECT", "FIRE", "JUMP", "BUTTON 4",
+ "BUTTON 5", "BUTTON 6", "BUTTON 7", "BUTTON 8",
};
/****************************************************************************
@@ -178,7 +178,7 @@ static void show_joystick(FAR const struct ajoy_sample_s *sample)
{
x = tmp * g_xrslope;
}
-
+
tmp = sample->as_y - g_ycenter;
if ((g_fispositive && tmp >= 0) ||
(!g_fispositive && tmp < 0))
@@ -205,14 +205,14 @@ static int ajoy_wait(int fd, FAR const struct timespec *timeout)
(void)sigemptyset(&sigset);
(void)sigaddset(&sigset, CONFIG_EXAMPLES_AJOYSTICK_SIGNO);
- ret = sigwaitinfo(&sigset, &value);
+ ret = sigtimedwait(&sigset, &value, timeout);
if (ret < 0)
{
int errcode = errno;
if (!timeout || errcode != EAGAIN)
{
- fprintf(stderr, "ERROR: sigwaitinfo() failed: %d\n", errcode);
+ fprintf(stderr, "ERROR: sigtimedwait() failed: %d\n", errcode);
return -errcode;
}
@@ -250,7 +250,7 @@ static int ajoy_read(int fd, FAR struct ajoy_sample_s *sample)
(long)nread, sizeof(struct ajoy_sample_s));
return -EIO;
}
-
+
/* Show the joystick position and set buttons accompanying the signal */
/* Show the set of joystick buttons that we just read */
@@ -324,7 +324,7 @@ static int ajoy_calibrate(int fd)
g_lispositive = (sample.as_x > g_xcenter);
g_xlslope = ajoy_slope(sample.as_x - g_xcenter, FULL_RANGE);
-
+
printf("Move the joystick to the far LEFT and press any button\n");
ret = ajoy_waitread(fd, NULL, &sample);
if (ret < 0)
@@ -347,7 +347,7 @@ static int ajoy_calibrate(int fd)
g_fispositive = (sample.as_y > g_ycenter);
g_yfslope = ajoy_slope(sample.as_y - g_ycenter, FULL_RANGE);
-
+
printf("Move the joystick to the far BACKWARD and press any button\n");
ret = ajoy_waitread(fd, NULL, &sample);
if (ret < 0)
@@ -357,7 +357,7 @@ static int ajoy_calibrate(int fd)
}
g_ybslope = ajoy_slope(sample.as_y - g_ycenter, -FULL_RANGE);
-
+
printf("Calibrated:\n");
g_calibrated = true;
diff --git a/nuttx/configs/sama5d3-xplained/README.txt b/nuttx/configs/sama5d3-xplained/README.txt
index e5417c22c..43ab3c7f7 100644
--- a/nuttx/configs/sama5d3-xplained/README.txt
+++ b/nuttx/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/nuttx/configs/sama5d3-xplained/src/sam_ajoystick.c b/nuttx/configs/sama5d3-xplained/src/sam_ajoystick.c
index 4be9aef0a..f1911e236 100644
--- a/nuttx/configs/sama5d3-xplained/src/sam_ajoystick.c
+++ b/nuttx/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/nuttx/configs/sama5d3-xplained/src/sama5d3-xplained.h b/nuttx/configs/sama5d3-xplained/src/sama5d3-xplained.h
index 154fc564f..f33b1ba11 100644
--- a/nuttx/configs/sama5d3-xplained/src/sama5d3-xplained.h
+++ b/nuttx/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.
*
************************************************************************************/