summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorpatacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3>2013-02-13 01:33:37 +0000
committerpatacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3>2013-02-13 01:33:37 +0000
commit28cc69fa4a5d63a398a8f0ad485b95c4f373be42 (patch)
tree5f1822c3f8036f25e91cafa2111f9b99e1a4bb00
parent7d67632b167cba2ffd827849ad801f445b51064f (diff)
downloadnuttx-28cc69fa4a5d63a398a8f0ad485b95c4f373be42.tar.gz
nuttx-28cc69fa4a5d63a398a8f0ad485b95c4f373be42.tar.bz2
nuttx-28cc69fa4a5d63a398a8f0ad485b95c4f373be42.zip
Add basic LED and button support for the Open1788
git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@5648 42af7a65-404d-4744-a932-0658087f49c3
-rw-r--r--nuttx/configs/open1788/include/board.h14
-rw-r--r--nuttx/configs/open1788/src/Makefile22
-rw-r--r--nuttx/configs/open1788/src/lpc17_autoleds.c284
-rw-r--r--nuttx/configs/open1788/src/lpc17_buttons.c230
-rw-r--r--nuttx/configs/open1788/src/lpc17_userleds.c141
-rw-r--r--nuttx/configs/open1788/src/open1788.h60
6 files changed, 737 insertions, 14 deletions
diff --git a/nuttx/configs/open1788/include/board.h b/nuttx/configs/open1788/include/board.h
index 1be5ac5fb..13d75870a 100644
--- a/nuttx/configs/open1788/include/board.h
+++ b/nuttx/configs/open1788/include/board.h
@@ -198,15 +198,15 @@
#define LED_STARTED 0 /* OFF OFF OFF OFF */
#define LED_HEAPALLOCATE 1 /* ON OFF OFF OFF */
#define LED_IRQSENABLED 2 /* OFF ON OFF OFF */
-#define LED_STACKCREATED 1 /* ON ON OFF OFF */
-#define LED_INIRQ 2 /* LED3 glows, on while in interupt */
-#define LED_SIGNAL 2 /* LED3 glows, on while in signal handler */
-#define LED_ASSERTION 2 /* LED3 glows, on while in assertion */
-#define LED_PANIC 2 /* LED3 Flashes at 2Hz */
-#define LED_IDLE 3 /* LED glows, ON while sleeping */
+#define LED_STACKCREATED 3 /* ON ON OFF OFF */
+#define LED_INIRQ 4 /* LED3 glows, on while in interupt */
+#define LED_SIGNAL 4 /* LED3 glows, on while in signal handler */
+#define LED_ASSERTION 4 /* LED3 glows, on while in assertion */
+#define LED_PANIC 4 /* LED3 Flashes at 2Hz */
+#define LED_IDLE 5 /* LED4 glows, ON while sleeping */
/* Button definitions ***************************************************************/
-/* The Open1788K supports several buttons. All will read "1" when open and "0"
+/* The Open1788 supports several buttons. All will read "1" when open and "0"
* when closed
*
* USER1 -- Connected to P4[26]
diff --git a/nuttx/configs/open1788/src/Makefile b/nuttx/configs/open1788/src/Makefile
index ee4a244f3..be18b28f9 100644
--- a/nuttx/configs/open1788/src/Makefile
+++ b/nuttx/configs/open1788/src/Makefile
@@ -44,6 +44,28 @@ ifeq ($(CONFIG_LPC17_EMC_NOR),y)
CSRCS += lpc17_norinitialize.c
endif
+ifeq ($(CONFIG_LPC17_EMC_NAND),y)
+CSRCS += lpc17_nandinitialize.c
+endif
+
+ifeq ($(CONFIG_LPC17_EMC_SDRM),y)
+CSRCS += lpc17_sdraminitialize.c
+endif
+
+ifeq ($(CONFIG_NSH_ARCHINIT),y)
+CSRCS += lpc17_nsh.c
+endif
+
+ifeq ($(CONFIG_ARCH_LEDS),y)
+CSRCS += lpc17_autoleds.c
+else
+CSRCS += lpc17_userleds.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/open1788/src/lpc17_autoleds.c b/nuttx/configs/open1788/src/lpc17_autoleds.c
new file mode 100644
index 000000000..66cfc1734
--- /dev/null
+++ b/nuttx/configs/open1788/src/lpc17_autoleds.c
@@ -0,0 +1,284 @@
+/****************************************************************************
+ * configs/open1788/src/lpc17_autoleds.c
+ * arch/arm/src/board/lpc17_autoleds.c
+ *
+ * Copyright (C) 2013 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 <stdbool.h>
+#include <debug.h>
+
+#include <arch/board/board.h>
+
+#include "chip.h"
+#include "up_arch.h"
+#include "up_internal.h"
+
+#include "lpc17_gpio.h"
+#include "open1788.h"
+
+/****************************************************************************
+ * Definitions
+ ****************************************************************************/
+/* If CONFIG_ARCH_LEDS is not defined, then the user can control the LEDs in
+ * any way. The following definitions are used to access individual LEDs.
+ *
+ * LED1 -- Connected to P1[14]
+ * LED2 -- Connected to P0[16]
+ * LED3 -- Connected to P1[13]
+ * LED4 -- Connected to P4[27]
+ *
+ * These LEDs are connecte to ground so a high output value will illuminate them.
+ *
+ * If CONFIG_ARCH_LEDs is defined, then NuttX will control the four LEDs
+ * on the WaveShare Open1788K. The following definitions describe how NuttX
+ * controls the LEDs:
+ *
+ * LED1 LED2 LED3 LED4
+ * LED_STARTED 0 OFF OFF OFF OFF
+ * LED_HEAPALLOCATE 1 ON OFF OFF OFF
+ * LED_IRQSENABLED 2 OFF ON OFF OFF
+ * LED_STACKCREATED 3 ON ON OFF OFF
+ * LED_INIRQ 4 LED3 glows, on while in interupt
+ * LED_SIGNAL 4 LED3 glows, on while in signal handler
+ * LED_ASSERTION 4 LED3 glows, on while in assertion
+ * LED_PANIC 4 LED3 Flashes at 2Hz
+ * LED_IDLE 5 LED glows, ON while sleeping
+ */
+
+/* The following definitions map the encoded LED setting to GPIO settings */
+
+#define OPEN1788_LED1 (1 << 0)
+#define OPEN1788_LED2 (1 << 1)
+#define OPEN1788_LED3 (1 << 2)
+#define OPEN1788_LED4 (1 << 3)
+
+#define ON_SETBITS_SHIFT (0)
+#define ON_CLRBITS_SHIFT (4)
+#define OFF_SETBITS_SHIFT (8)
+#define OFF_CLRBITS_SHIFT (12)
+
+#define ON_BITS(v) ((v) & 0xff)
+#define OFF_BITS(v) (((v) >> 8) & 0x0ff)
+#define SETBITS(b) ((b) & 0x0f)
+#define CLRBITS(b) (((b) >> 4) & 0x0f)
+
+#define ON_SETBITS(v) (SETBITS(ON_BITS(v))
+#define ON_CLRBITS(v) (CLRBITS(ON_BITS(v))
+#define OFF_SETBITS(v) (SETBITS(OFF_BITS(v))
+#define OFF_CLRBITS(v) (CLRBITS(OFF_BITS(v))
+
+#define LED_STARTED_ON_SETBITS ((0) << ON_SETBITS_SHIFT)
+#define LED_STARTED_ON_CLRBITS ((OPEN1788_LED1|OPEN1788_LED2|OPEN1788_LED3|OPEN1788_LED4) << ON_CLRBITS_SHIFT)
+#define LED_STARTED_OFF_SETBITS (0 << OFF_SETBITS_SHIFT)
+#define LED_STARTED_OFF_CLRBITS ((OPEN1788_LED1|OPEN1788_LED2|OPEN1788_LED3|OPEN1788_LED4) << OFF_CLRBITS_SHIFT)
+
+#define LED_HEAPALLOCATE_ON_SETBITS ((OPEN1788_LED1) << ON_SETBITS_SHIFT)
+#define LED_HEAPALLOCATE_ON_CLRBITS ((OPEN1788_LED2|OPEN1788_LED3|OPEN1788_LED4) << ON_CLRBITS_SHIFT)
+#define LED_HEAPALLOCATE_OFF_SETBITS (0 << OFF_SETBITS_SHIFT)
+#define LED_HEAPALLOCATE_OFF_CLRBITS ((OPEN1788_LED1|OPEN1788_LED2|OPEN1788_LED3|OPEN1788_LED4) << OFF_CLRBITS_SHIFT)
+
+#define LED_IRQSENABLED_ON_SETBITS ((OPEN1788_LED2) << ON_SETBITS_SHIFT)
+#define LED_IRQSENABLED_ON_CLRBITS ((OPEN1788_LED1|OPEN1788_LED3|OPEN1788_LED4) << ON_CLRBITS_SHIFT)
+#define LED_IRQSENABLED_OFF_SETBITS ((OPEN1788_LED1) << OFF_SETBITS_SHIFT)
+#define LED_IRQSENABLED_OFF_CLRBITS ((OPEN1788_LED2|OPEN1788_LED3|OPEN1788_LED4) << OFF_CLRBITS_SHIFT)
+
+#define LED_STACKCREATED_ON_SETBITS ((OPEN1788_LED1|OPEN1788_LED2) << ON_SETBITS_SHIFT)
+#define LED_STACKCREATED_ON_CLRBITS ((OPEN1788_LED3|OPEN1788_LED4) << ON_CLRBITS_SHIFT)
+#define LED_STACKCREATED_OFF_SETBITS ((OPEN1788_LED2) << OFF_SETBITS_SHIFT)
+#define LED_STACKCREATED_OFF_CLRBITS ((OPEN1788_LED1|OPEN1788_LED3|OPEN1788_LED4) << OFF_CLRBITS_SHIFT)
+
+#define LED_EVENT_ON_SETBITS ((OPEN1788_LED3) << ON_SETBITS_SHIFT)
+#define LED_EVENT_ON_CLRBITS ((0) << ON_CLRBITS_SHIFT)
+#define LED_EVENT_OFF_SETBITS ((0) << OFF_SETBITS_SHIFT)
+#define LED_EVENT_OFF_CLRBITS ((OPEN1788_LED3) << OFF_CLRBITS_SHIFT)
+
+#define LED_IDLE_ON_SETBITS ((OPEN1788_LED4) << ON_SETBITS_SHIFT)
+#define LED_IDLE_ON_CLRBITS ((0) << ON_CLRBITS_SHIFT)
+#define LED_IDLE_OFF_SETBITS ((0) << OFF_SETBITS_SHIFT)
+#define LED_IDLE_OFF_CLRBITS ((OPEN1788_LED4) << OFF_CLRBITS_SHIFT)
+
+/* Enables debug output from this file (needs CONFIG_DEBUG with
+ * CONFIG_DEBUG_VERBOSE too)
+ */
+
+#undef LED_DEBUG /* Define to enable debug */
+#undef LED_VERBOSE /* Define to enable verbose debug */
+
+#ifdef LED_DEBUG
+# define leddbg lldbg
+# ifdef LED_VERBOSE
+# define ledvdbg lldbg
+# else
+# define ledvdbg(x...)
+# endif
+#else
+# undef LED_VERBOSE
+# define leddbg(x...)
+# define ledvdbg(x...)
+#endif
+
+/* Dump GPIO registers */
+
+#ifdef LED_VERBOSE
+# define led_dumpgpio(m) lpc17_dumpgpio(???, m)
+#else
+# define led_dumpgpio(m)
+#endif
+
+/****************************************************************************
+ * Private Data
+ ****************************************************************************/
+
+/****************************************************************************
+ * Private Data
+ ****************************************************************************/
+
+static const uint16_t g_ledbits[8] =
+{
+ (LED_STARTED_ON_SETBITS | LED_STARTED_ON_CLRBITS |
+ LED_STARTED_OFF_SETBITS | LED_STARTED_OFF_CLRBITS),
+
+ (LED_HEAPALLOCATE_ON_SETBITS | LED_HEAPALLOCATE_ON_CLRBITS |
+ LED_HEAPALLOCATE_OFF_SETBITS | LED_HEAPALLOCATE_OFF_CLRBITS),
+
+ (LED_IRQSENABLED_ON_SETBITS | LED_IRQSENABLED_ON_CLRBITS |
+ LED_IRQSENABLED_OFF_SETBITS | LED_IRQSENABLED_OFF_CLRBITS),
+
+ (LED_STACKCREATED_ON_SETBITS | LED_STACKCREATED_ON_CLRBITS |
+ LED_STACKCREATED_OFF_SETBITS | LED_STACKCREATED_OFF_CLRBITS),
+
+ (LED_EVENT_ON_SETBITS | LED_EVENT_ON_CLRBITS |
+ LED_EVENT_OFF_SETBITS | LED_EVENT_OFF_CLRBITS),
+
+ (LED_IDLE_ON_SETBITS | LED_IDLE_ON_CLRBITS |
+ LED_IDLE_OFF_SETBITS | LED_IDLE_OFF_CLRBITS)
+};
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+static inline void led_clrbits(unsigned int clrbits)
+{
+ if ((clrbits & OPEN1788_LED1) != 0)
+ {
+ lpc17_gpiowrite(GPIO_LED1, false);
+ }
+
+ if ((clrbits & OPEN1788_LED2) != 0)
+ {
+ lpc17_gpiowrite(GPIO_LED2, false);
+ }
+
+ if ((clrbits & OPEN1788_LED3) != 0)
+ {
+ lpc17_gpiowrite(GPIO_LED3, false);
+ }
+
+ if ((clrbits & OPEN1788_LED4) != 0)
+ {
+ lpc17_gpiowrite(GPIO_LED4, false);
+ }
+}
+
+static inline void led_setbits(unsigned int setbits)
+{
+ if ((setbits & OPEN1788_LED1) != 0)
+ {
+ lpc17_gpiowrite(GPIO_LED1, true);
+ }
+
+ if ((setbits & OPEN1788_LED2) != 0)
+ {
+ lpc17_gpiowrite(GPIO_LED2, true);
+ }
+
+ if ((setbits & OPEN1788_LED3) != 0)
+ {
+ lpc17_gpiowrite(GPIO_LED3, true);
+ }
+
+ if ((setbits & OPEN1788_LED4) != 0)
+ {
+ lpc17_gpiowrite(GPIO_LED4, true);
+ }
+}
+
+static void led_setonoff(unsigned int bits)
+{
+ led_clrbits(CLRBITS(bits));
+ led_setbits(SETBITS(bits));
+}
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: up_ledinit
+ ****************************************************************************/
+
+void up_ledinit(void)
+{
+ /* Configure LED1-4 GPIOs for output */
+
+ lpc17_configgpio(GPIO_LED1);
+ lpc17_configgpio(GPIO_LED2);
+ lpc17_configgpio(GPIO_LED3);
+ lpc17_configgpio(GPIO_LED4);
+}
+
+/****************************************************************************
+ * Name: up_ledon
+ ****************************************************************************/
+
+void up_ledon(int led)
+{
+ led_setonoff(ON_BITS(g_ledbits[led]));
+}
+
+/****************************************************************************
+ * Name: up_ledoff
+ ****************************************************************************/
+
+void up_ledoff(int led)
+{
+ led_setonoff(OFF_BITS(g_ledbits[led]));
+}
diff --git a/nuttx/configs/open1788/src/lpc17_buttons.c b/nuttx/configs/open1788/src/lpc17_buttons.c
new file mode 100644
index 000000000..38e432ee0
--- /dev/null
+++ b/nuttx/configs/open1788/src/lpc17_buttons.c
@@ -0,0 +1,230 @@
+/****************************************************************************
+ * configs/open1788/src/lpc17_buttons.c
+ *
+ * Copyright (C) 2013 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 <stdbool.h>
+
+#include <nuttx/arch.h>
+#include <nuttx/irq.h>
+
+#include <arch/board/board.h>
+
+#include "lpc17_gpio.h"
+#include "open1788.h"
+
+#ifdef CONFIG_ARCH_BUTTONS
+
+/****************************************************************************
+ * Definitions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Private Data
+ ****************************************************************************/
+/* Pin configuration for each Open1788 button. This array is indexed by
+ * the BUTTON_* and JOYSTICK_* definitions in board.h
+ */
+
+static const lpc17_pinset_t g_buttoncfg[BOARD_NUM_BUTTONS] =
+{
+ GPIO_USER1, GPIO_USER2, GPIO_WAKEUP, GPIO_USER3,
+ GPIO_JOY_A, GPIO_JOY_B, GPIO_JOY_C, GPIO_JOY_D, GPIO_JOY_CTR
+};
+
+/* 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] =
+{
+ GPIO_USER1_IRQ, GPIO_USER2_IRQ, GPIO_WAKEUP_IRQ, GPIO_USER3_IRQ,
+ GPIO_JOY_A_IRQ, GPIO_JOY_B_IRQ, GPIO_JOY_C_IRQ, GPIO_JOY_D_IRQ,
+ GPIO_JOY_CTR_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 interrupting inputs. */
+
+ for (i = 0; i < BOARD_NUM_BUTTONS; i++)
+ {
+ lpc17_configgpio(g_buttoncfg[i]);
+ }
+}
+
+/****************************************************************************
+ * Name: up_buttons
+ *
+ * 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.
+ *
+ * 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_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).
+ *
+ * Note that up_irqbutton() also enables button interrupts. Button
+ * interrupts will remain enabled after the interrupt handler is attached.
+ * Interrupts may be disabled (and detached) by calling up_irqbutton with
+ * irqhandler equal to NULL.
+ *
+ ****************************************************************************/
+
+#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;
+ int irq;
+
+ /* 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[id] = irqhandler;
+
+ /* Disable interrupts until we are done */
+
+ flags = irqsave();
+
+ /* Configure the interrupt. Either attach and enable the new
+ * interrupt or disable and detach the old interrupt handler.
+ */
+
+ irq = g_buttonirq[id];
+ if (irqhandler)
+ {
+ /* Attach then enable the new interrupt handler */
+
+ (void)irq_attach(irq, irqhandler);
+ up_enable_irq(irq);
+ }
+ else
+ {
+ /* Disable then then detach the the old interrupt handler */
+
+ up_disable_irq(irq);
+ (void)irq_detach(irq);
+ }
+
+ irqrestore(flags);
+ }
+
+ return oldhandler;
+}
+#endif
+
+#endif /* CONFIG_ARCH_BUTTONS */
diff --git a/nuttx/configs/open1788/src/lpc17_userleds.c b/nuttx/configs/open1788/src/lpc17_userleds.c
new file mode 100644
index 000000000..dacea5a1c
--- /dev/null
+++ b/nuttx/configs/open1788/src/lpc17_userleds.c
@@ -0,0 +1,141 @@
+/****************************************************************************
+ * configs/open1788/src/lpc17_userleds.c
+ * arch/arm/src/board/lpc17_userleds.c
+ *
+ * Copyright (C) 2013 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 <stdbool.h>
+#include <debug.h>
+
+#include <arch/board/board.h>
+#include <nuttx/power/pm.h>
+
+#include "chip.h"
+#include "up_arch.h"
+#include "up_internal.h"
+
+#include "lpc17_gpio.h"
+#include "open1788.h"
+
+#ifndef CONFIG_ARCH_LEDS
+
+/****************************************************************************
+ * Definitions
+ ****************************************************************************/
+
+/* Enables debug output from this file (needs CONFIG_DEBUG with
+ * CONFIG_DEBUG_VERBOSE too)
+ */
+
+#undef LED_DEBUG /* Define to enable debug */
+
+#ifdef LED_DEBUG
+# define leddbg lldbg
+# define ledvdbg llvdbg
+#else
+# define leddbg(x...)
+# define ledvdbg(x...)
+#endif
+
+/****************************************************************************
+ * Private Data
+ ****************************************************************************/
+/* This array maps an LED number to GPIO pin configuration */
+
+static uint32_t g_ledcfg[BOARD_NLEDS] =
+{
+ GPIO_LED1, GPIO_LED2, GPIO_LED3, GPIO_LED4
+};
+
+/****************************************************************************
+ * Private Function Protototypes
+ ****************************************************************************/
+
+/****************************************************************************
+ * Private Data
+ ****************************************************************************/
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: lpc17_ledinit
+ ****************************************************************************/
+
+void lpc17_ledinit(void)
+{
+ /* Configure LED1-4 GPIOs for output */
+
+ lpc17_configgpio(GPIO_LED1);
+ lpc17_configgpio(GPIO_LED2);
+ lpc17_configgpio(GPIO_LED3);
+ lpc17_configgpio(GPIO_LED4);
+}
+
+/****************************************************************************
+ * Name: lpc17_setled
+ ****************************************************************************/
+
+void lpc17_setled(int led, bool ledon)
+{
+ if ((unsigned)led < BOARD_NLEDS)
+ {
+ lpc17_gpiowrite(g_ledcfg[led], ledon);
+ }
+}
+
+/****************************************************************************
+ * Name: lpc17_setleds
+ ****************************************************************************/
+
+void lpc17_setleds(uint8_t ledset)
+{
+ lpc17_gpiowrite(GPIO_LED1, (ledset & BOARD_LED1_BIT) == 0);
+ lpc17_gpiowrite(GPIO_LED2, (ledset & BOARD_LED2_BIT) == 0);
+ lpc17_gpiowrite(GPIO_LED3, (ledset & BOARD_LED3_BIT) == 0);
+ lpc17_gpiowrite(GPIO_LED4, (ledset & BOARD_LED4_BIT) == 0);
+}
+
+#endif /* !CONFIG_ARCH_LEDS */
diff --git a/nuttx/configs/open1788/src/open1788.h b/nuttx/configs/open1788/src/open1788.h
index 7eb4f7e9c..52da9a815 100644
--- a/nuttx/configs/open1788/src/open1788.h
+++ b/nuttx/configs/open1788/src/open1788.h
@@ -1,6 +1,6 @@
/************************************************************************************
- * configs/olimex-lpc1766stk/src/lpc1766stk_internal.h
- * arch/arm/src/board/lpc1766stk_internal.n
+ * configs/open1788/src/open1788.h
+ * arch/arm/src/board/open1788.n
*
* Copyright (C) 2013 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
@@ -34,8 +34,8 @@
*
************************************************************************************/
-#ifndef _CONFIGS_OLIMEX_LPC1766STK_SRC_LPC1766STK_INTERNAL_H
-#define _CONFIGS_OLIMEX_LPC1766STK_SRC_LPC1766STK_INTERNAL_H
+#ifndef _CONFIGS_OPEN1788_SRC_OPEN1788_H
+#define _CONFIGS_OPEN1788_SRC_OPEN1788_H
/************************************************************************************
* Included Files
@@ -48,13 +48,59 @@
* Definitions
************************************************************************************/
-/* LPC1766-STK GPIO Pin Definitions *************************************************/
+/* Open1788 GPIO Pin Definitions ****************************************************/
/* GPIO P2[21] connects to the Ready/Busy pin of the NAND part. We need to
* reconfigure this pin as normal GPIO input if NAND is used.
*/
#define GPIO_NAND_RB (GPIO_INPUT | GPIO_PULLUP | GPIO_PORT2 | GPIO_PIN21)
+/* If CONFIG_ARCH_LEDS is not defined, then the user can control the LEDs in
+ * any way. The following definitions are used to access individual LEDs.
+ *
+ * LED1 -- Connected to P1[14]
+ * LED2 -- Connected to P0[16]
+ * LED3 -- Connected to P1[13]
+ * LED4 -- Connected to P4[27]
+ *
+ * These LEDs are connecte to ground so a high output value will illuminate them.
+ */
+
+#define GPIO_LED1 (GPIO_OUTPUT | GPIO_VALUE_ONE | GPIO_PORT1 | GPIO_PIN14)
+#define GPIO_LED2 (GPIO_OUTPUT | GPIO_VALUE_ONE | GPIO_PORT0 | GPIO_PIN16)
+#define GPIO_LED3 (GPIO_OUTPUT | GPIO_VALUE_ONE | GPIO_PORT1 | GPIO_PIN13)
+#define GPIO_LED4 (GPIO_OUTPUT | GPIO_VALUE_ONE | GPIO_PORT4 | GPIO_PIN27)
+
+/* Button definitions ***************************************************************/
+/* The Open1788 supports several buttons. All will read "1" when open and "0"
+ * when closed
+ *
+ * USER1 -- Connected to P4[26]
+ * USER2 -- Connected to P2[22]
+ * USER3 -- Connected to P0[10]
+ *
+ * And a Joystick
+ *
+ * JOY_A -- Connected to P2[25]
+ * JOY_B -- Connected to P2[26]
+ * JOY_C -- Connected to P2[23]
+ * JOY_D -- Connected to P2[19]
+ * JOY_CTR -- Connected to P0[14]
+ *
+ * The switches are all connected to ground and should be pulled up and sensed
+ * with a value of '0' when closed.
+ */
+
+#define GPIO_USER1 (GPIO_INTBOTH | GPIO_FLOAT | GPIO_PORT4 | GPIO_PIN26)
+#define GPIO_USER2 (GPIO_INTBOTH | GPIO_FLOAT | GPIO_PORT2 | GPIO_PIN22)
+#define GPIO_USER3 (GPIO_INTBOTH | GPIO_FLOAT | GPIO_PORT0 | GPIO_PIN10)
+
+#define GPIO_JOY_A (GPIO_INTBOTH | GPIO_FLOAT | GPIO_PORT2 | GPIO_PIN25)
+#define GPIO_JOY_B (GPIO_INTBOTH | GPIO_FLOAT | GPIO_PORT2 | GPIO_PIN26)
+#define GPIO_JOY_C (GPIO_INTBOTH | GPIO_FLOAT | GPIO_PORT2 | GPIO_PIN23)
+#define GPIO_JOY_D (GPIO_INTBOTH | GPIO_FLOAT | GPIO_PORT2 | GPIO_PIN19)
+#define GPIO_JOY_CTR (GPIO_INTBOTH | GPIO_FLOAT | GPIO_PORT0 | GPIO_PIN14)
+
/************************************************************************************
* Public Types
************************************************************************************/
@@ -73,7 +119,7 @@
* Name: lpc17_sspinitialize
*
* Description:
- * Called to configure SPI chip select GPIO pins for the Olimex LPC1766-STK board.
+ * Called to configure SPI chip select GPIO pins for the WaveShare Open1788 board.
*
************************************************************************************/
@@ -118,5 +164,5 @@ void lpc17_nand_initialize(void);
#endif /* CONFIG_LPC17_EMC */
#endif /* __ASSEMBLY__ */
-#endif /* _CONFIGS_OLIMEX_LPC1766STK_SRC_LPC1766STK_INTERNAL_H */
+#endif /* _CONFIGS_OPEN1788_SRC_OPEN1788_H */