summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--nuttx/ChangeLog5
-rwxr-xr-xnuttx/configs/olimex-lpc1766stk/include/board.h76
-rwxr-xr-xnuttx/configs/olimex-lpc1766stk/src/Makefile7
-rwxr-xr-xnuttx/configs/olimex-lpc1766stk/src/lpc1766stk_internal.h40
-rw-r--r--nuttx/configs/olimex-lpc1766stk/src/up_buttons.c201
5 files changed, 307 insertions, 22 deletions
diff --git a/nuttx/ChangeLog b/nuttx/ChangeLog
index 895aa6d8b..f179381fb 100644
--- a/nuttx/ChangeLog
+++ b/nuttx/ChangeLog
@@ -2309,3 +2309,8 @@
for the PIC32MX family.
* arch/arm/src/stm32/stm32_gpio.c: Correct an error in some of the GPIO
initialization logic. Fix submitted by Mike Smith.
+ * configs/olimex-lpc1766stk/src/up_leds.c: Add new interfaces so that is
+ CONFIG_ARCH_LEDS are not set, the LEDs may be controlled from application
+ logic.
+ *configs/olimex-lpc1766stk/src/up_buttons.c: Add support form the buttons
+ on the Olimex LPC1766-STK board.
diff --git a/nuttx/configs/olimex-lpc1766stk/include/board.h b/nuttx/configs/olimex-lpc1766stk/include/board.h
index de630b4bc..2d99fe40a 100755
--- a/nuttx/configs/olimex-lpc1766stk/include/board.h
+++ b/nuttx/configs/olimex-lpc1766stk/include/board.h
@@ -43,6 +43,10 @@
#include <nuttx/config.h>
+#if defined(CONFIG_ARCH_IRQBUTTONS) && defined(CONFIG_GPIO_IRQ)
+# include <nuttx/irq.h>
+#endif
+
/************************************************************************************
* Definitions
************************************************************************************/
@@ -183,10 +187,10 @@
#define BOARD_BUTTON_WAKEUP 2
#define BOARD_JOYSTICK_CENTER 3
-#define BOARD_JOYSTICK_DOWN 4
-#define BOARD_JOYSTICK_LEFT 5
-#define BOARD_JOYSTICK_RIGHT 6
-#define BOARD_JOYSTICK_UP 7
+#define BOARD_JOYSTICK_UP 4
+#define BOARD_JOYSTICK_DOWN 5
+#define BOARD_JOYSTICK_LEFT 6
+#define BOARD_JOYSTICK_RIGHT 7
#define BOARD_NUM_BUTTONS 8
@@ -195,10 +199,10 @@
#define BOARD_BUTTON_WAKEUP_BIT (1 << BOARD_BUTTON_WAKEUP)
#define BOARD_JOYSTICK_CENTER_BIT (1 << BOARD_JOYSTICK_CENTER)
+#define BOARD_JOYSTICK_UP_BIT (1 << BOARD_JOYSTICK_UP)
#define BOARD_JOYSTICK_DOWN_BIT (1 << BOARD_JOYSTICK_DOWN)
#define BOARD_JOYSTICK_LEFT_BIT (1 << BOARD_JOYSTICK_LEFT)
#define BOARD_JOYSTICK_RIGHT_BIT (1 << BOARD_JOYSTICK_RIGHT)
-#define BOARD_JOYSTICK_UP_BIT (1 << BOARD_JOYSTICK_UP)
/* Alternate pin selections *********************************************************/
@@ -368,21 +372,21 @@ extern "C" {
* Name: lpc17_boardinitialize
*
* Description:
- * All LPC17xx architectures must provide the following entry point. This entry point
- * is called early in the intitialization -- after all memory has been configured
- * and mapped but before any devices have been initialized.
+ * All LPC17xx architectures must provide the following entry point. This entry
+ * point is called early in the intitialization -- after all memory has been
+ * configured and mapped but before any devices have been initialized.
*
************************************************************************************/
EXTERN void lpc17_boardinitialize(void);
-/****************************************************************************
+/************************************************************************************
* Name: lpc17_ledinit and lpc17_setled
*
* Description:
- * If CONFIG_ARCH_LEDS is defined, then NuttX will control the on-board
- * LEDs. If CONFIG_ARCH_LEDS is not defined, then the following interfaces
- * are available to control the LEDs from user applications.
+ * If CONFIG_ARCH_LEDS is defined, then NuttX will control the on-board LEDs. If
+ * CONFIG_ARCH_LEDS is not defined, then the following interfacesare available to
+ * control the LEDs from user applications.
*
****************************************************************************/
@@ -392,6 +396,54 @@ EXTERN void lpc17_setled(int led, bool ledon);
EXTERN void lpc17_setleds(uint8_t ledset);
#endif
+/************************************************************************************
+ * Name: up_buttoninit
+ *
+ * Description:
+ * up_buttoninit() must be called to initialize button resources. After that,
+ * up_buttons() may be called to collect the current state of all buttons or
+ * up_irqbutton() may be called to register button interrupt handlers.
+ *
+ ****************************************************************************/
+
+#ifdef CONFIG_ARCH_BUTTONS
+EXTERN void up_buttoninit(void);
+
+/************************************************************************************
+ * Name: up_buttons
+ *
+ * Description:
+ * After up_buttoninit() has been called, up_buttons() may be called to collect
+ * the state of all buttons. up_buttons() returns an 8-bit bit set with each bit
+ * associated with a button. See the BOARD_BUTTON_*_BIT and BOARD_JOYSTICK_*_BIT
+ * definitions above for the meaning of each bit.
+ *
+ ****************************************************************************/
+
+EXTERN uint8_t up_buttons(void);
+
+/************************************************************************************
+ * Button support.
+ *
+ * Description:
+ * up_buttoninit() must be called to initialize button resources. After that,
+ * up_buttons() may be called to collect the current state of all buttons or
+ * up_irqbutton() may be called to register button interrupt handlers.
+ *
+ * up_irqbutton() may be called to register an interrupt handler that will be called
+ * when a button is depressed or released. The ID value is a button enumeration
+ * value that uniquely identifies a button resource. See the BOARD_BUTTON_* and
+ * BOARD_JOYSTICK_* definitions in above for the meaning of enumeration values
+ * The previous interrupt handler address is returned (so that it may restored, if
+ * so desired).
+ *
+ ************************************************************************************/
+
+#if defined(CONFIG_ARCH_IRQBUTTONS) && defined(CONFIG_GPIO_IRQ)
+EXTERN xcpt_t up_irqbutton(int id, xcpt_t irqhandler);
+#endif
+#endif /* CONFIG_ARCH_BUTTONS */
+
#undef EXTERN
#if defined(__cplusplus)
}
diff --git a/nuttx/configs/olimex-lpc1766stk/src/Makefile b/nuttx/configs/olimex-lpc1766stk/src/Makefile
index 981a4b4df..f006461bc 100755
--- a/nuttx/configs/olimex-lpc1766stk/src/Makefile
+++ b/nuttx/configs/olimex-lpc1766stk/src/Makefile
@@ -39,16 +39,23 @@ CFLAGS += -I$(TOPDIR)/sched
ASRCS =
CSRCS = up_boot.c up_leds.c up_ssp.c
+
ifeq ($(CONFIG_NSH_ARCHINIT),y)
CSRCS += up_nsh.c
endif
+
ifeq ($(CONFIG_USBSTRG),y)
CSRCS += up_usbstrg.c
endif
+
ifeq ($(CONFIG_NX_LCDDRIVER),y)
CSRCS += up_lcd.c
endif
+ifeq ($(CONFIG_ARCH_BUTTONS),y)
+CSRCS += up_buttons.c
+endif
+
AOBJS = $(ASRCS:.S=$(OBJEXT))
COBJS = $(CSRCS:.c=$(OBJEXT))
diff --git a/nuttx/configs/olimex-lpc1766stk/src/lpc1766stk_internal.h b/nuttx/configs/olimex-lpc1766stk/src/lpc1766stk_internal.h
index db9915eef..4fa082369 100755
--- a/nuttx/configs/olimex-lpc1766stk/src/lpc1766stk_internal.h
+++ b/nuttx/configs/olimex-lpc1766stk/src/lpc1766stk_internal.h
@@ -2,7 +2,7 @@
* configs/olimex-lpc1766stk/src/lpc1766stk_internal.h
* arch/arm/src/board/lpc1766stk_internal.n
*
- * Copyright (C) 2010 Gregory Nutt. All rights reserved.
+ * Copyright (C) 2010-2011 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* Redistribution and use in source and binary forms, with or without
@@ -137,11 +137,20 @@
* P2[12]/#EINT2/I2STX_WS 51 WAKE-UP
* P0[23]/AD0[0]/I2SRX_CLK/CAP3[0] 9 BUT1
* P2[13]/#EINT3/I2STX_SDA 50 BUT2
+ *
+ * Pull-ups are not required because the pins are already pulled-up by through
+ * resistors on the board.
*/
-#define LPC1766STK_WAKE_UP (GPIO_INPUT | GPIO_PULLUP | GPIO_PORT2 | GPIO_PIN12)
-#define LPC1766STK_BUT1 (GPIO_INPUT | GPIO_PULLUP | GPIO_PORT0 | GPIO_PIN23)
-#define LPC1766STK_BUT2 (GPIO_INPUT | GPIO_PULLUP | GPIO_PORT2 | GPIO_PIN13)
+#define LPC1766STK_BUT1 (GPIO_INPUT | GPIO_FLOAT | GPIO_PORT0 | GPIO_PIN23)
+#define LPC1766STK_BUT2 (GPIO_INPUT | GPIO_FLOAT | GPIO_PORT2 | GPIO_PIN13)
+#define LPC1766STK_WAKEUP (GPIO_INPUT | GPIO_FLOAT | GPIO_PORT2 | GPIO_PIN12)
+
+/* Button IRQ numbers */
+
+#define LPC1766STK_BUT1_IRQ LPC17_IRQ_P0p23
+#define LPC1766STK_BUT2_IRQ LPC17_IRQ_P2p13
+#define LPC1766STK_WAKEUP_IRQ LPC17_IRQ_P2p12
/* Joystick GPIO PIN SIGNAL NAME
* -------------------------------- ---- --------------
@@ -150,13 +159,24 @@
* P2[1]/PWM1[2]/RXD1 74 DOWN
* P2[7]/RD2/RTS1 66 LEFT
* P2[8]/TD2/TXD2 65 RIGHT
+ *
+ * Pull-ups are not required because the pins are already pulled-up by through
+ * resistors on the board.
*/
-#define LPC1766STK_CENTER (GPIO_INPUT | GPIO_PULLUP | GPIO_PORT0 | GPIO_PIN5)
-#define LPC1766STK_UP (GPIO_INPUT | GPIO_PULLUP | GPIO_PORT2 | GPIO_PIN0)
-#define LPC1766STK_DOWN (GPIO_INPUT | GPIO_PULLUP | GPIO_PORT2 | GPIO_PIN1)
-#define LPC1766STK_LEFT (GPIO_INPUT | GPIO_PULLUP | GPIO_PORT2 | GPIO_PIN7)
-#define LPC1766STK_RIGHT (GPIO_INPUT | GPIO_PULLUP | GPIO_PORT2 | GPIO_PIN8)
+#define LPC1766STK_CENTER (GPIO_INPUT | GPIO_FLOAT | GPIO_PORT0 | GPIO_PIN5)
+#define LPC1766STK_UP (GPIO_INPUT | GPIO_FLOAT | GPIO_PORT2 | GPIO_PIN0)
+#define LPC1766STK_DOWN (GPIO_INPUT | GPIO_FLOAT | GPIO_PORT2 | GPIO_PIN1)
+#define LPC1766STK_LEFT (GPIO_INPUT | GPIO_FLOAT | GPIO_PORT2 | GPIO_PIN7)
+#define LPC1766STK_RIGHT (GPIO_INPUT | GPIO_FLOAT | GPIO_PORT2 | GPIO_PIN8)
+
+/* Joystick IRQ numbers */
+
+#define LPC1766STK_CENTER_IRQ LPC17_IRQ_P0p5
+#define LPC1766STK_UP_IRQ LPC17_IRQ_P2p0
+#define LPC1766STK_DOWN_IRQ LPC17_IRQ_P2p1
+#define LPC1766STK_LEFT_IRQ LPC17_IRQ_P2p7
+#define LPC1766STK_RIGHT_IRQ LPC17_IRQ_P2p8
/* Nokia LCD GPIO PIN SIGNAL NAME
* -------------------------------- ---- --------------
@@ -228,7 +248,7 @@
*
************************************************************************************/
-extern void weak_function lpc17_sspinitialize(void);
+void weak_function lpc17_sspinitialize(void);
#endif /* __ASSEMBLY__ */
#endif /* _CONFIGS_OLIMEX_LPC1766STK_SRC_LPC1766STK_INTERNAL_H */
diff --git a/nuttx/configs/olimex-lpc1766stk/src/up_buttons.c b/nuttx/configs/olimex-lpc1766stk/src/up_buttons.c
new file mode 100644
index 000000000..65fe89dfc
--- /dev/null
+++ b/nuttx/configs/olimex-lpc1766stk/src/up_buttons.c
@@ -0,0 +1,201 @@
+/****************************************************************************
+ * configs/olimex-lpc1766stk/src/up_buttons.c
+ *
+ * Copyright (C) 2011 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 <nuttx/irq.h>
+
+#include <arch/board/board.h>
+#include "lpc1766stk_internal.h"
+
+#ifdef CONFIG_ARCH_BUTTONS
+
+/****************************************************************************
+ * Definitions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Private Data
+ ****************************************************************************/
+/* Pin configuration for each STM3210E-EVAL button. This array is indexed by
+ * the BUTTON_* and JOYSTICK_* definitions in board.h
+ */
+
+static const uint16_t g_buttoncfg[BOARD_NUM_BUTTONS] =
+{
+ LPC1766STK_BUT1, LPC1766STK_BUT2, LPC1766STK_WAKEUP, LPC1766STK_CENTER,
+ LPC1766STK_UP, LPC1766STK_DOWN, LPC1766STK_LEFT, LPC1766STK_RIGHT
+};
+
+/* This array defines all of the interupt handlers current attached to
+ * button events.
+ */
+
+#if defined(CONFIG_ARCH_IRQBUTTONS) && defined(CONFIG_GPIO_IRQ)
+static xcpt_t g_buttonisr[BOARD_NUM_BUTTONS];
+
+/* This array provides the mapping from button ID numbers to button IRQ
+ * numbers.
+ */
+
+static uint8_t g_buttonirq[BOARD_NUM_BUTTONS] =
+{
+ LPC1766STK_BUT1_IRQ, LPC1766STK_BUT2_IRQ, LPC1766STK_WAKEUP_IRQ,
+ LPC1766STK_CENTER_IRQ, LPC1766STK_UP_IRQ, LPC1766STK_DOWN_IRQ,
+ LPC1766STK_LEFT_IRQ, LPC1766STK_RIGHT_IRQ
+};
+#endif
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: up_buttoninit
+ *
+ * Description:
+ * up_buttoninit() must be called to initialize button resources. After
+ * that, up_buttons() may be called to collect the current state of all
+ * buttons or up_irqbutton() may be called to register button interrupt
+ * handlers.
+ *
+ ****************************************************************************/
+
+void up_buttoninit(void)
+{
+ int i;
+
+ /* Configure the GPIO pins as inputs. */
+
+ for (i = 0; i < BOARD_NUM_BUTTONS; i++)
+ {
+ lpc17_configgpio(g_buttoncfg[i]);
+ }
+}
+
+/****************************************************************************
+ * Name: up_buttons
+ *
+ * Description:
+ * up_buttons() may be called at any time to harvest the state of every
+ * button. The state of the buttons is returned as a bitset with one
+ * bit corresponding to each button: If the bit is set, then the button
+ * is pressed. See the BOARD_BUTTON_*_BIT and BOARD_JOYSTICK_*_BIT
+ * definitions in board.h for the meaning of each bit.
+ *
+ ****************************************************************************/
+
+uint8_t up_buttons(void)
+{
+ uint8_t ret = 0;
+ int i;
+
+ /* Check that state of each key */
+
+ for (i = 0; i < BOARD_NUM_BUTTONS; i++)
+ {
+ /* A LOW value means that the key is pressed. */
+
+ bool released = lpc17_gpioread(g_buttoncfg[i]);
+
+ /* Accumulate the set of depressed (not released) keys */
+
+ if (!released)
+ {
+ ret |= (1 << i);
+ }
+ }
+
+ return ret;
+}
+
+/************************************************************************************
+ * Button support.
+ *
+ * Description:
+ * up_buttoninit() must be called to initialize button resources. After
+ * that, up_buttons() may be called to collect the current state of all
+ * buttons or up_irqbutton() may be called to register button interrupt
+ * handlers.
+ *
+ * up_irqbutton() may be called to register an interrupt handler that will
+ * be called when a button is depressed or released. The ID value is a
+ * button enumeration value that uniquely identifies a button resource. See the
+ * BOARD_BUTTON_* and BOARD_JOYSTICK_* definitions in board.h for the meaning
+ * of enumeration values. The previous interrupt handler address is returned
+ * (so that it may restored, if so desired).
+ *
+ ************************************************************************************/
+
+#if defined(CONFIG_ARCH_IRQBUTTONS) && defined(CONFIG_GPIO_IRQ)
+xcpt_t up_irqbutton(int id, xcpt_t irqhandler)
+{
+ xcpt_t oldhandler = NULL;
+ irqstate_t flags;
+
+ /* Verify that the button ID is within range */
+
+ if ((unsigned)id < BOARD_NUM_BUTTONS)
+ {
+ /* Return the current button handler and set the new interrupt handler */
+
+ oldhandler = g_buttonisr[id];
+ g_buttonisr = irqhandler;
+
+ /* Disable interrupts until we are done */
+
+ flags = irqsave();
+
+ /* Configure the interrupt */
+
+ (void)irq_attach(g_buttonirq[id], irqhandler);
+ up_enable_irq(g_buttonirq[id]);
+ irqrestore(flags);
+ }
+ return oldhandler;
+}
+#endif
+
+#endif /* CONFIG_ARCH_BUTTONS */