summaryrefslogtreecommitdiff
path: root/nuttx
diff options
context:
space:
mode:
authorGregory Nutt <gnutt@nuttx.org>2014-11-28 13:31:09 -0600
committerGregory Nutt <gnutt@nuttx.org>2014-11-28 13:31:09 -0600
commit2d5277ab849c329ae2d0fe078d703aebf20ce396 (patch)
treee5700ec0a13d9afac711c9330ca3ca198f4f0c8d /nuttx
parent27e9744a6e77e86c7b7caf4210cdcb55503ed49c (diff)
downloadnuttx-2d5277ab849c329ae2d0fe078d703aebf20ce396.tar.gz
nuttx-2d5277ab849c329ae2d0fe078d703aebf20ce396.tar.bz2
nuttx-2d5277ab849c329ae2d0fe078d703aebf20ce396.zip
STM3210E-EVAL: Add a DJoystick driver
Diffstat (limited to 'nuttx')
-rwxr-xr-xnuttx/configs/stm3210e-eval/nsh/setenv.sh41
-rw-r--r--nuttx/configs/stm3210e-eval/src/Makefile10
-rw-r--r--nuttx/configs/stm3210e-eval/src/stm3210e-eval.h13
-rw-r--r--nuttx/configs/stm3210e-eval/src/stm32_buttons.c2
-rw-r--r--nuttx/configs/stm3210e-eval/src/stm32_djoystick.c305
-rwxr-xr-xnuttx/configs/stm32f4discovery/nsh/setenv.sh2
-rw-r--r--nuttx/include/nuttx/input/djoystick.h43
7 files changed, 393 insertions, 23 deletions
diff --git a/nuttx/configs/stm3210e-eval/nsh/setenv.sh b/nuttx/configs/stm3210e-eval/nsh/setenv.sh
index ff9a4bf8a..84b8a40bf 100755
--- a/nuttx/configs/stm3210e-eval/nsh/setenv.sh
+++ b/nuttx/configs/stm3210e-eval/nsh/setenv.sh
@@ -32,16 +32,45 @@
# POSSIBILITY OF SUCH DAMAGE.
#
-if [ "$(basename $0)" = "setenv.sh" ] ; then
+if [ "$_" = "$0" ] ; then
echo "You must source this script, not run it!" 1>&2
exit 1
fi
-if [ -z "${PATH_ORIG}" ]; then export PATH_ORIG="${PATH}"; fi
-
WD=`pwd`
-export RIDE_BIN="/cygdrive/c/Program Files/Raisonance/Ride/arm-gcc/bin"
-export BUILDROOT_BIN="${WD}/../misc/buildroot/build_arm_nofpu/staging_dir/bin"
-export PATH="${BUILDROOT_BIN}:${RIDE_BIN}:/sbin:/usr/sbin:${PATH_ORIG}"
+if [ ! -x "setenv.sh" ]; then
+ echo "This script must be executed from the top-level NuttX build directory"
+ exit 1
+fi
+
+if [ -z "${PATH_ORIG}" ]; then
+ export PATH_ORIG="${PATH}"
+fi
+
+# This is the Cygwin path to the location where I installed the RIDE
+# toolchain under windows. You will also have to edit this if you install
+# the RIDE toolchain in any other location
+#export TOOLCHAIN_BIN="/cygdrive/c/Program Files (x86)/Raisonance/Ride/arm-gcc/bin"
+
+# This is the Cygwin path to the location where I installed the CodeSourcery
+# toolchain under windows. You will also have to edit this if you install
+# the CodeSourcery toolchain in any other location
+# export TOOLCHAIN_BIN="/cygdrive/c/Program Files (x86)/CodeSourcery/Sourcery G++ Lite/bin"
+#export TOOLCHAIN_BIN="/cygdrive/c/Users/MyName/MentorGraphics/Sourcery_CodeBench_Lite_for_ARM_EABI/bin"
+
+# These are the Cygwin paths to the locations where I installed the Atollic
+# toolchain under windows. You will also have to edit this if you install
+# the Atollic toolchain in any other location. /usr/bin is added before
+# the Atollic bin path because there is are binaries named gcc.exe and g++.exe
+# at those locations as well.
+#export TOOLCHAIN_BIN="/usr/bin:/cygdrive/c/Program Files (x86)/Atollic/TrueSTUDIO for ARM Pro 2.3.0/ARMTools/bin"
+#export TOOLCHAIN_BIN="/usr/bin:/cygdrive/c/Program Files (x86)/Atollic/TrueSTUDIO for STMicroelectronics STM32 Lite 2.3.0/ARMTools/bin"
+
+# This is the Cygwin path to the location where I build the buildroot
+# toolchain.
+export TOOLCHAIN_BIN="${WD}/../misc/buildroot/build_arm_nofpu/staging_dir/bin"
+
+# Add the path to the toolchain to the PATH variable
+export PATH="${TOOLCHAIN_BIN}:/sbin:/usr/sbin:${PATH_ORIG}"
echo "PATH : ${PATH}"
diff --git a/nuttx/configs/stm3210e-eval/src/Makefile b/nuttx/configs/stm3210e-eval/src/Makefile
index 2624e3a31..cc5f8c268 100644
--- a/nuttx/configs/stm3210e-eval/src/Makefile
+++ b/nuttx/configs/stm3210e-eval/src/Makefile
@@ -40,7 +40,7 @@ CFLAGS += -I$(TOPDIR)/sched
ASRCS =
AOBJS = $(ASRCS:.S=$(OBJEXT))
-CSRCS = stm32_boot.c stm32_leds.c stm32_buttons.c stm32_spi.c stm32_usbdev.c
+CSRCS = stm32_boot.c stm32_leds.c stm32_spi.c stm32_usbdev.c
ifeq ($(CONFIG_STM32_FSMC),y)
CSRCS += stm32_lcd.c stm32_extcontext.c stm32_extmem.c stm32_selectnor.c
@@ -80,9 +80,17 @@ ifeq ($(CONFIG_ARCH_CUSTOM_PMINIT),y)
CSRCS += stm32_pm.c
endif
+ifeq ($(CONFIG_ARCH_BUTTONS),y)
+CSRCS += stm32_buttons.c
+
ifeq ($(CONFIG_PM_BUTTONS),y)
CSRCS += stm32_pmbuttons.c
endif
+endif
+
+ifeq ($(CONFIG_DJOYSTICK),y)
+CSRCS += stm32_djoystick.c
+endif
ifeq ($(CONFIG_ARCH_IDLE_CUSTOM),y)
CSRCS += stm32_idle.c
diff --git a/nuttx/configs/stm3210e-eval/src/stm3210e-eval.h b/nuttx/configs/stm3210e-eval/src/stm3210e-eval.h
index ed46aeb2c..58c7f78c3 100644
--- a/nuttx/configs/stm3210e-eval/src/stm3210e-eval.h
+++ b/nuttx/configs/stm3210e-eval/src/stm3210e-eval.h
@@ -323,6 +323,17 @@ void stm32_ledpminitialize(void);
void stm32_pmbuttons(void);
#endif
+/****************************************************************************
+ * Name: stm32_djoy_initialization
+ *
+ * Description:
+ * Initialize and register the discrete joystick driver
+ *
+ ****************************************************************************/
+
+#ifdef CONFIG_DJOYSTICK
+int stm32_djoy_initialization(void);
+#endif
+
#endif /* __ASSEMBLY__ */
#endif /* __CONFIGS_STM3210E_EVAL_SRC_STM3210E_EVAL_H */
-
diff --git a/nuttx/configs/stm3210e-eval/src/stm32_buttons.c b/nuttx/configs/stm3210e-eval/src/stm32_buttons.c
index cb155feab..2ebdc8351 100644
--- a/nuttx/configs/stm3210e-eval/src/stm32_buttons.c
+++ b/nuttx/configs/stm3210e-eval/src/stm32_buttons.c
@@ -49,7 +49,7 @@
#ifdef CONFIG_ARCH_BUTTONS
/****************************************************************************
- * Definitions
+ * Pre-processor Definitions
****************************************************************************/
/****************************************************************************
diff --git a/nuttx/configs/stm3210e-eval/src/stm32_djoystick.c b/nuttx/configs/stm3210e-eval/src/stm32_djoystick.c
new file mode 100644
index 000000000..d0c8925c7
--- /dev/null
+++ b/nuttx/configs/stm3210e-eval/src/stm32_djoystick.c
@@ -0,0 +1,305 @@
+/****************************************************************************
+ * configs/stm3210e-eval/src/stm32_djoystick.c
+ *
+ * Copyright (C) 2014 Gregory Nutt. All rights reserved.
+ * Author: Gregory Nutt <gnutt@nuttx.org>
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ * 3. Neither the name NuttX nor the names of its contributors may be
+ * used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
+ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+
+#include <stdint.h>
+#include <debug.h>
+
+#include <nuttx/arch.h>
+#include <nuttx/input/djoystick.h>
+
+#include "stm32_gpio.h"
+#include "stm3210e-eval.h"
+
+#ifdef CONFIG_DJOYSTICK
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+/* Number of Joystick discretes */
+
+#define DJOY_NGPIOS 5
+
+/* Bitset of supported Joystick discretes */
+
+#define DJOY_SUPPORTED (DJOY_UP_BIT | DJOY_DOWN_BIT | DJOY_LEFT_BIT | \
+ DJOY_RIGHT_BIT | DJOY_BUTTON_SELECT_BIT)
+
+/****************************************************************************
+ * Private Types
+ ****************************************************************************/
+
+/****************************************************************************
+ * Private Function Prototypes
+ ****************************************************************************/
+
+static djoy_buttonset_t djoy_supported(FAR const struct djoy_lowerhalf_s *lower);
+static djoy_buttonset_t djoy_sample(FAR const struct djoy_lowerhalf_s *lower);
+static void djoy_enable(FAR const struct djoy_lowerhalf_s *lower,
+ djoy_buttonset_t press, djoy_buttonset_t release,
+ djoy_interrupt_t handler, FAR void *arg);
+
+static void djoy_disable(void);
+static int djoy_interrupt(int irq, FAR void *context);
+
+/****************************************************************************
+ * Private Data
+ ****************************************************************************/
+/* Pin configuration for each STM3210E-EVAL joystick "button." Index using
+ * DJOY_* definitions in include/nuttx/input/djoystick.h.
+ */
+
+static const uint16_t g_joygpio[DJOY_NGPIOS] =
+{
+ GPIO_JOY_UP, GPIO_JOY_DOWN, GPIO_JOY_LEFT, GPIO_JOY_RIGHT, GPIO_JOY_SEL
+};
+
+/* Current interrupt handler and argument */
+
+static djoy_interrupt_t g_djoyhandler;
+static FAR void *g_djoyarg;
+
+/* This is the discrete joystick lower half driver interface */
+
+static const struct djoy_lowerhalf_s g_djoylower =
+{
+ .dl_supported = djoy_supported,
+ .dl_sample = djoy_sample,
+ .dl_enable = djoy_enable,
+};
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: djoy_supported
+ *
+ * Description:
+ * Return the set of buttons supported on the discrete joystick device
+ *
+ ****************************************************************************/
+
+static djoy_buttonset_t djoy_supported(FAR const struct djoy_lowerhalf_s *lower)
+{
+ ivdbg("Supported: %02x\n", DJOY_SUPPORTED);
+ return (djoy_buttonset_t)DJOY_SUPPORTED;
+}
+
+/****************************************************************************
+ * Name: djoy_sample
+ *
+ * Description:
+ * Return the current state of all discrete joystick buttons
+ *
+ ****************************************************************************/
+
+static djoy_buttonset_t djoy_sample(FAR const struct djoy_lowerhalf_s *lower)
+{
+ djoy_buttonset_t ret = 0;
+ int i;
+
+ /* Read each joystick GPIO value */
+
+ for (i = 0; i < DJOY_NGPIOS; i++)
+ {
+ bool released = stm32_gpioread(g_joygpio[i]);
+ if (!released)
+ {
+ ret |= (1 << i);
+ }
+ }
+
+ ivdbg("Retuning: %02x\n", DJOY_SUPPORTED);
+ return ret;
+}
+
+/****************************************************************************
+ * Name: djoy_enable
+ *
+ * Description:
+ * Enable interrupts on the selected set of joystick buttons. And empty
+ * set will disable all interrupts.
+ *
+ ****************************************************************************/
+
+static void djoy_enable(FAR const struct djoy_lowerhalf_s *lower,
+ djoy_buttonset_t press, djoy_buttonset_t release,
+ djoy_interrupt_t handler, FAR void *arg)
+{
+ irqstate_t flags;
+ djoy_buttonset_t either = press | release;
+ djoy_buttonset_t bit;
+ bool rising;
+ bool falling;
+ int i;
+
+ /* Start with all interrupts disabled */
+
+ flags = irqsave();
+ djoy_disable();
+
+ illvdbg("press: %02x release: %02x handler: %p arg: %p\n",
+ press, release, handler, arg);
+
+ /* If no events are indicated or if no handler is provided, then this
+ * must really be a request to disable interrupts.
+ */
+
+ if (either && handler)
+ {
+ /* Save the new the handler and argument */
+
+ g_djoyhandler = handler;
+ g_djoyarg = arg;
+
+ /* Check each GPIO. */
+
+ for (i = 0; i < DJOY_NGPIOS; i++)
+ {
+ /* Enable interrupts on each pin that has either a press or
+ * release event associated with it.
+ */
+
+ bit = (1 << i);
+ if ((either & bit) != 0)
+ {
+ /* Active low so a press corresponds to a falling edge and
+ * a release corresponds to a rising edge.
+ */
+
+ falling = ((press & bit) != 0);
+ rising = ((release & bit) != 0);
+
+ illvdbg("GPIO %d: rising: %d falling: %d\n",
+ i, rising, falling);
+
+ (void)stm32_gpiosetevent(g_joygpio[i], rising, falling,
+ true, djoy_interrupt);
+ }
+ }
+ }
+
+ irqrestore(flags);
+}
+
+/****************************************************************************
+ * Name: djoy_disable
+ *
+ * Description:
+ * Disable all joystick interrupts
+ *
+ ****************************************************************************/
+
+static void djoy_disable(void)
+{
+ irqstate_t flags;
+ int i;
+
+ /* Disable each joystick interrupt */
+
+ flags = irqsave();
+ for (i = 0; i < DJOY_NGPIOS; i++)
+ {
+ (void)stm32_gpiosetevent(g_joygpio[i], false, false, false, NULL);
+ }
+
+ irqrestore(flags);
+
+ /* Nullify the handler and argument */
+
+ g_djoyhandler = NULL;
+ g_djoyarg = NULL;
+}
+
+/****************************************************************************
+ * Name: djoy_interrupt
+ *
+ * Description:
+ * Discrete joystick interrupt handler
+ *
+ ****************************************************************************/
+
+static int djoy_interrupt(int irq, FAR void *context)
+{
+ DEBUGASSERT(g_djoyhandler);
+ if (g_djoyhandler)
+ {
+ g_djoyhandler(&g_djoylower, g_djoyarg);
+ }
+
+ return OK;
+}
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: stm32_djoy_initialization
+ *
+ * Description:
+ * Initialize and register the discrete joystick driver
+ *
+ ****************************************************************************/
+
+int stm32_djoy_initialization(void)
+{
+ int i;
+
+ /* Configure the GPIO pins as inputs. NOTE that EXTI interrupts are
+ * configured for some pins but NOT yet set up.
+ */
+
+ for (i = 0; i < DJOY_NGPIOS; i++)
+ {
+ stm32_configgpio(g_joygpio[i]);
+ }
+
+ /* Make sure that all interrupts are disabled */
+
+ djoy_disable();
+
+ /* Register the joystick device as /dev/djoy0 */
+
+ return djoy_register("/dev/djoy0", &g_djoylower);
+}
+
+#endif /* CONFIG_DJOYSTICK */
diff --git a/nuttx/configs/stm32f4discovery/nsh/setenv.sh b/nuttx/configs/stm32f4discovery/nsh/setenv.sh
index 4c3360716..61b52ad1e 100755
--- a/nuttx/configs/stm32f4discovery/nsh/setenv.sh
+++ b/nuttx/configs/stm32f4discovery/nsh/setenv.sh
@@ -70,7 +70,7 @@ export TOOLCHAIN_BIN="/cygdrive/c/Program Files (x86)/CodeSourcery/Sourcery G++
# toolchain.
#export TOOLCHAIN_BIN="${WD}/../misc/buildroot/build_arm_nofpu/staging_dir/bin"
-# Add the path to the toolchain to the PATH varialble
+# Add the path to the toolchain to the PATH variable
export PATH="${TOOLCHAIN_BIN}:/sbin:/usr/sbin:${PATH_ORIG}"
echo "PATH : ${PATH}"
diff --git a/nuttx/include/nuttx/input/djoystick.h b/nuttx/include/nuttx/input/djoystick.h
index ca1273dc2..32f30eaeb 100644
--- a/nuttx/include/nuttx/input/djoystick.h
+++ b/nuttx/include/nuttx/input/djoystick.h
@@ -72,22 +72,38 @@
* reported in the djoy_buttonset_t bitset.
*/
-#define DJOY_UP (1 << 0) /* Bit 0: True = Joystick UP */
-#define DJOY_DOWN (1 << 1) /* Bit 1: True = Joystick DOWN */
-#define DJOY_LEFT (1 << 2) /* Bit 2: True = Joystick LEFT */
-#define DJOY_RIGHT (1 << 3) /* Bit 3: True = Joystick RIGHT */
-#define DJOY_BUTTON_1 (1 << 4) /* Bit 4: True = Button 1 pressed */
-#define DJOY_BUTTON_2 (1 << 5) /* Bit 5: True = Button 2 pressed */
-#define DJOY_BUTTON_3 (1 << 6) /* Bit 6: True = Button 3 pressed */
-#define DJOY_BUTTON_3 (1 << 7) /* Bit 7: True = Button 4 pressed */
-#define DJOY_BUTTONS_ALL 0xff /* The set of all buttons */
+#define DJOY_UP (0) /* Bit 0: Joystick UP */
+#define DJOY_DOWN (1) /* Bit 1: Joystick DOWN */
+#define DJOY_LEFT (2) /* Bit 2: Joystick LEFT */
+#define DJOY_RIGHT (3) /* Bit 3: Joystick RIGHT */
+#define DJOY_BUTTON_1 (4) /* Bit 4: Button 1 */
+#define DJOY_BUTTON_2 (5) /* Bit 5: Button 2 */
+#define DJOY_BUTTON_3 (6) /* Bit 6: Button 3 */
+#define DJOY_BUTTON_4 (7) /* Bit 7: Button 4 */
+
+#define DJOY_UP_BIT (1 << DJOY_UP) /* 1:Joystick UP selected */
+#define DJOY_DOWN_BIT (1 << DJOY_DOWN) /* 1:Joystick DOWN selected */
+#define DJOY_LEFT_BIT (1 << DJOY_LEFT) /* 1:Joystick LEFT selected */
+#define DJOY_RIGHT_BIT (1 << DJOY_RIGHT) /* 1:Joystick RIGHT selected */
+#define DJOY_BUTTONS_JOYBITS 0x0f /* Set of all joystick directions */
+#define DJOY_BUTTON_1_BIT (1 << DJOY_BUTTON_1) /* 1:Button 1 pressed */
+#define DJOY_BUTTON_2_BIT (1 << DJOY_BUTTON_2) /* 1:Button 2 pressed */
+#define DJOY_BUTTON_3_BIT (1 << DJOY_BUTTON_3) /* 1:Button 3 pressed */
+#define DJOY_BUTTON_4_BIT (1 << DJOY_BUTTON_4) /* 1:Button 4 pressed */
+#define DJOY_BUTTONS_ALLBITS 0xf0 /* Set of all buttons */
+#define DJOY_ALLBITS 0xff /* Set of all bits */
/* Typical usage */
-#define DJOY_BUTTON_SELECT DJOY_BUTTON_1
-#define DJOY_BUTTON_FIRE DJOY_BUTTON_2
-#define DJOY_BUTTON_JUMP DJOY_BUTTON_3
-#define DJOY_BUTTON_RUN DJOY_BUTTON_4
+#define DJOY_BUTTON_SELECT DJOY_BUTTON_1
+#define DJOY_BUTTON_FIRE DJOY_BUTTON_2
+#define DJOY_BUTTON_JUMP DJOY_BUTTON_3
+#define DJOY_BUTTON_RUN DJOY_BUTTON_4
+
+#define DJOY_BUTTON_SELECT_BIT DJOY_BUTTON_1_BIT
+#define DJOY_BUTTON_FIRE_BIT DJOY_BUTTON_2_BIT
+#define DJOY_BUTTON_JUMP_BIT DJOY_BUTTON_3_BIT
+#define DJOY_BUTTON_RUN_BIT DJOY_BUTTON_4_BIT
/* IOCTL commands
*
@@ -161,6 +177,7 @@ struct djoy_notify_s
* the struct djoy_lowerhalf_s enable() method.
*/
+struct djoy_lowerhalf_s;
typedef CODE void (*djoy_interrupt_t)
(FAR const struct djoy_lowerhalf_s *lower, FAR void *arg);