Fix button interrupt logic for Open1788; Add button test as option to configs/open1788/nsh

This commit is contained in:
Gregory Nutt 2013-04-08 08:26:49 -06:00
parent d43857d54f
commit 40d10b47eb
4 changed files with 98 additions and 50 deletions

View File

@ -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

View File

@ -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

View File

@ -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 */
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.
/* Get the IRQ number for the button; A value of zero indicates that
* the button does not support the interrupt function.
*/
irq = g_buttonirq[id];
if (irqhandler)
if (irq > 0)
{
/* Attach then enable the new interrupt handler */
/* Disable interrupts until we are done */
(void)irq_attach(irq, irqhandler);
up_enable_irq(irq);
flags = irqsave();
/* Return the current button handler and set the new interrupt handler */
oldhandler = g_buttonisr[id];
g_buttonisr[id] = irqhandler;
/* Configure the interrupt. Either attach and enable the new
* interrupt or disable and detach the old interrupt handler.
*/
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);
}
else
{
/* Disable then then detach the the old interrupt handler */
up_disable_irq(irq);
(void)irq_detach(irq);
}
irqrestore(flags);
}
return oldhandler;

View File

@ -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 **************************************************************/
/* -------------- -------------------- ------------ --------------