summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGregory Nutt <gnutt@nuttx.org>2013-04-08 08:26:49 -0600
committerGregory Nutt <gnutt@nuttx.org>2013-04-08 08:26:49 -0600
commit56cde073f2f253ece6ec667158e274dc0c7779ed (patch)
treed3ac1122cd09cdc0cbdbb3f2ea1defd067915130
parentc6423a5341a1b0987b1070cbe0e2b1ec60511e93 (diff)
downloadnuttx-56cde073f2f253ece6ec667158e274dc0c7779ed.tar.gz
nuttx-56cde073f2f253ece6ec667158e274dc0c7779ed.tar.bz2
nuttx-56cde073f2f253ece6ec667158e274dc0c7779ed.zip
Fix button interrupt logic for Open1788; Add button test as option to configs/open1788/nsh
-rw-r--r--nuttx/configs/open1788/README.txt26
-rw-r--r--nuttx/configs/open1788/include/board.h13
-rw-r--r--nuttx/configs/open1788/src/lpc17_buttons.c53
-rw-r--r--nuttx/configs/open1788/src/open1788.h52
4 files changed, 96 insertions, 48 deletions
diff --git a/nuttx/configs/open1788/README.txt b/nuttx/configs/open1788/README.txt
index c828a1812..35d7cace4 100644
--- a/nuttx/configs/open1788/README.txt
+++ b/nuttx/configs/open1788/README.txt
@@ -560,6 +560,32 @@ CONFIGURATION
CONFIG_DEBUG_VERBOSE=y
CONFIG_DEBUG_INPUT=y
+ 7. The button test (apps/examples/buttons) can be built-in by adding
+ the following options. See apps/examples/README.txt for further
+ information about the button test.
+
+ System Type:
+ CONFIG_GPIO_IRQ=y
+
+ Board Selection:
+ CONFIG_ARCH_BUTTONS=y
+ CONFIG_ARCH_IRQBUTTONS=y
+
+ Application Configuration:
+ CONFIG_EXAMPLES_BUTTONS=y
+ CONFIG_EXAMPLES_BUTTONS_MIN=0
+ CONFIG_EXAMPLES_BUTTONS_MAX=7
+ CONFIG_EXAMPLES_IRQBUTTONS_MIN=1
+ CONFIG_EXAMPLES_IRQBUTTONS_MAX=7
+ CONFIG_EXAMPLES_BUTTONS_NAME0="USER1"
+ CONFIG_EXAMPLES_BUTTONS_NAME1="USER2"
+ CONFIG_EXAMPLES_BUTTONS_NAME2="USER3"
+ CONFIG_EXAMPLES_BUTTONS_NAME3="JOYSTICK_A"
+ CONFIG_EXAMPLES_BUTTONS_NAME4="JOYSTICK_B"
+ CONFIG_EXAMPLES_BUTTONS_NAME5="JOYSTICK_C"
+ CONFIG_EXAMPLES_BUTTONS_NAME6="JOYSTICK_D"
+ CONFIG_EXAMPLES_BUTTONS_NAME7="JOYSTICK_CTR"
+
nxlines
-------
Configures the graphics example located at examples/nsh. This
diff --git a/nuttx/configs/open1788/include/board.h b/nuttx/configs/open1788/include/board.h
index 2283f93d2..641cc99fe 100644
--- a/nuttx/configs/open1788/include/board.h
+++ b/nuttx/configs/open1788/include/board.h
@@ -258,8 +258,10 @@
* OFF while sleeping */
/* Button definitions ***************************************************************/
-/* The Open1788 supports several buttons. All will read "1" when open and "0"
- * when closed
+/* The Open1788 supports several buttons. All must be pulled up by the Open1788.
+ * When closed, the pins will be pulled to ground. So the buttons will read "1"
+ * when open and "0" when closed. All except USER1 are capable of generating
+ * interrupts.
*
* USER1 -- Connected to P4[26]
* USER2 -- Connected to P2[22]
@@ -271,12 +273,13 @@
* JOY_B -- Connected to P2[26]
* JOY_C -- Connected to P2[23]
* JOY_D -- Connected to P2[19]
- * JOY_CTR -- Connected to P0[14]
+ * JOY_CTR -- Connected to P0[14] (shared with SSP1 SSEL)
*
- * The switches are all connected to ground and should be pulled up and sensed
- * with a value of '0' when closed.
+ * For the interrupting buttons, interrupts are generated on both edges (press and
+ * release).
*/
+
#define BOARD_BUTTON_USER1 0
#define BOARD_BUTTON_USER2 1
#define BOARD_BUTTON_USER3 2
diff --git a/nuttx/configs/open1788/src/lpc17_buttons.c b/nuttx/configs/open1788/src/lpc17_buttons.c
index 474924510..c820e01f5 100644
--- a/nuttx/configs/open1788/src/lpc17_buttons.c
+++ b/nuttx/configs/open1788/src/lpc17_buttons.c
@@ -101,7 +101,7 @@ static xcpt_t g_buttonisr[BOARD_NUM_BUTTONS];
static uint8_t g_buttonirq[BOARD_NUM_BUTTONS] =
{
- GPIO_USER1_IRQ, GPIO_USER2_IRQ, GPIO_USER3_IRQ, GPIO_JOY_A_IRQ,
+ 0, GPIO_USER2_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
@@ -209,36 +209,43 @@ xcpt_t up_irqbutton(int id, xcpt_t irqhandler)
if ((unsigned)id < BOARD_NUM_BUTTONS)
{
- /* Return the current button handler and set the new interrupt handler */
+ /* Get the IRQ number for the button; A value of zero indicates that
+ * the button does not support the interrupt function.
+ */
- oldhandler = g_buttonisr[id];
- g_buttonisr[id] = irqhandler;
+ irq = g_buttonirq[id];
+ if (irq > 0)
+ {
+ /* Disable interrupts until we are done */
- /* Disable interrupts until we are done */
+ flags = irqsave();
- flags = irqsave();
+ /* Return the current button handler and set the new interrupt handler */
- /* Configure the interrupt. Either attach and enable the new
- * interrupt or disable and detach the old interrupt handler.
- */
+ oldhandler = g_buttonisr[id];
+ g_buttonisr[id] = irqhandler;
- irq = g_buttonirq[id];
- if (irqhandler)
- {
- /* Attach then enable the new interrupt handler */
+ /* Configure the interrupt. Either attach and enable the new
+ * interrupt or disable and detach the old interrupt handler.
+ */
- (void)irq_attach(irq, irqhandler);
- up_enable_irq(irq);
- }
- else
- {
- /* Disable then then detach the the old interrupt handler */
+ if (irqhandler)
+ {
+ /* Attach then enable the new interrupt handler */
- up_disable_irq(irq);
- (void)irq_detach(irq);
- }
+ (void)irq_attach(irq, irqhandler);
+ up_enable_irq(irq);
+ }
+ else
+ {
+ /* Disable then then detach the the old interrupt handler */
- irqrestore(flags);
+ up_disable_irq(irq);
+ (void)irq_detach(irq);
+ }
+
+ irqrestore(flags);
+ }
}
return oldhandler;
diff --git a/nuttx/configs/open1788/src/open1788.h b/nuttx/configs/open1788/src/open1788.h
index e70eebe5d..3bceee1ec 100644
--- a/nuttx/configs/open1788/src/open1788.h
+++ b/nuttx/configs/open1788/src/open1788.h
@@ -53,7 +53,7 @@
* reconfigure this pin as normal GPIO input if NAND is used.
*/
-#define GPIO_NAND_RB (GPIO_INPUT | GPIO_PULLUP | GPIO_PORT2 | GPIO_PIN21)
+#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.
@@ -66,14 +66,16 @@
* 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)
+#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
+/* The Open1788 supports several buttons. All must be pulled up by the Open1788.
+ * When closed, the pins will be pulled to ground. So the buttons will read "1"
+ * when open and "0" when closed. All except USER1 are capable of generating
+ * interrupts.
*
* USER1 -- Connected to P4[26]
* USER2 -- Connected to P2[22]
@@ -85,21 +87,31 @@
* JOY_B -- Connected to P2[26]
* JOY_C -- Connected to P2[23]
* JOY_D -- Connected to P2[19]
- * JOY_CTR -- Connected to P0[14]
+ * JOY_CTR -- Connected to P0[14] (shared with SSP1 SSEL)
*
- * The switches are all connected to ground and should be pulled up and sensed
- * with a value of '0' when closed.
+ * For the interrupting buttons, interrupts are generated on both edges (press and
+ * release).
*/
-#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_USER1 (GPIO_INPUT | GPIO_PULLUP | GPIO_PORT4 | GPIO_PIN26)
+#define GPIO_USER2 (GPIO_INTBOTH | GPIO_PULLUP | GPIO_PORT2 | GPIO_PIN22)
+#define GPIO_USER3 (GPIO_INTBOTH | GPIO_PULLUP | 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)
+#define GPIO_JOY_A (GPIO_INTBOTH | GPIO_PULLUP | GPIO_PORT2 | GPIO_PIN25)
+#define GPIO_JOY_B (GPIO_INTBOTH | GPIO_PULLUP | GPIO_PORT2 | GPIO_PIN26)
+#define GPIO_JOY_C (GPIO_INTBOTH | GPIO_PULLUP | GPIO_PORT2 | GPIO_PIN23)
+#define GPIO_JOY_D (GPIO_INTBOTH | GPIO_PULLUP | GPIO_PORT2 | GPIO_PIN19)
+#define GPIO_JOY_CTR (GPIO_INTBOTH | GPIO_PULLUP | GPIO_PORT0 | GPIO_PIN14)
+
+/* IRQ numbers for the buttons that do support interrrupts */
+
+#define GPIO_USER2_IRQ LPC17_IRQ_P2p22
+#define GPIO_USER3_IRQ LPC17_IRQ_P0p10
+#define GPIO_JOY_A_IRQ LPC17_IRQ_P2p25
+#define GPIO_JOY_B_IRQ LPC17_IRQ_P2p26
+#define GPIO_JOY_C_IRQ LPC17_IRQ_P2p23
+#define GPIO_JOY_D_IRQ LPC17_IRQ_P2p19
+#define GPIO_JOY_CTR_IRQ LPC17_IRQ_P0p14
/* SD Card **************************************************************************/
/* The SD card detect (CD) signal is on P0[13]. This signal is shared. It is also
@@ -109,12 +121,12 @@
* The CD pin is interrupting:
*/
-#define GPIO_SD_CD (GPIO_INTBOTH | GPIO_PULLUP | GPIO_PORT0 | GPIO_PIN13)
+#define GPIO_SD_CD (GPIO_INTBOTH | GPIO_PULLUP | GPIO_PORT0 | GPIO_PIN13)
/* LCD ******************************************************************************/
/* Backlight enable, P2[1]. Initial state is OFF (zero) */
-#define GPIO_LCD_BL (GPIO_OUTPUT | GPIO_VALUE_ZERO | GPIO_PORT2 | GPIO_PIN1)
+#define GPIO_LCD_BL (GPIO_OUTPUT | GPIO_VALUE_ZERO | GPIO_PORT2 | GPIO_PIN1)
/* XPT2046 Touchscreen **************************************************************/
/* -------------- -------------------- ------------ --------------