mirror of
https://github.com/apache/nuttx.git
synced 2026-06-06 08:36:24 +08:00
Add button logic
git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@3030 42af7a65-404d-4744-a932-0658087f49c3
This commit is contained in:
@@ -157,6 +157,10 @@ AVR32DEV1 Configuration Options
|
|||||||
|
|
||||||
Individual subsystems can be enabled:
|
Individual subsystems can be enabled:
|
||||||
|
|
||||||
|
CONFIG_AVR32_GPIOIRQ - GPIO interrupt support
|
||||||
|
CONFIG_AVR32_GPIOIRQSETA - Set of GPIOs on PORTA that support interrupts
|
||||||
|
CONFIG_AVR32_GPIOIRQSETB - Set of GPIOs on PORTB that support interrupts
|
||||||
|
|
||||||
CONFIG_AVR32_USARTn - Enable support for USARTn
|
CONFIG_AVR32_USARTn - Enable support for USARTn
|
||||||
CONFIG_AVR32_USARTn_RS232 - Configure USARTn as an RS232 interface.
|
CONFIG_AVR32_USARTn_RS232 - Configure USARTn as an RS232 interface.
|
||||||
CONFIG_AVR32_USARTn_SPI - Configure USARTn as an SPI interface.
|
CONFIG_AVR32_USARTn_SPI - Configure USARTn as an SPI interface.
|
||||||
|
|||||||
@@ -43,6 +43,9 @@
|
|||||||
|
|
||||||
#include <nuttx/config.h>
|
#include <nuttx/config.h>
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <nuttx/irq.h>
|
||||||
|
|
||||||
/************************************************************************************
|
/************************************************************************************
|
||||||
* Definitions
|
* Definitions
|
||||||
************************************************************************************/
|
************************************************************************************/
|
||||||
@@ -135,6 +138,10 @@ EXTERN void avr32_boardinitialize(void);
|
|||||||
* returns an 8-bit bit set with each bit associated with a button. See the
|
* returns an 8-bit bit set with each bit associated with a button. See the
|
||||||
* BUTTON* definitions above for the meaning of each bit in the returned value.
|
* BUTTON* definitions above for the meaning of each bit in the returned value.
|
||||||
*
|
*
|
||||||
|
* NOTE: Nothing in the "base" NuttX code calls up_buttoninit(). If you want button
|
||||||
|
* support in an application, your application startup code must call up_buttoninit()
|
||||||
|
* prior to calling any of the other button interfaces.
|
||||||
|
*
|
||||||
************************************************************************************/
|
************************************************************************************/
|
||||||
|
|
||||||
#ifdef CONFIG_ARCH_BUTTONS
|
#ifdef CONFIG_ARCH_BUTTONS
|
||||||
@@ -161,9 +168,15 @@ EXTERN uint8_t up_buttons(void);
|
|||||||
* called when BUTTON1/2 is depressed. The previous interrupt handler value is
|
* called when BUTTON1/2 is depressed. The previous interrupt handler value is
|
||||||
* returned (so that it may restored, if so desired).
|
* returned (so that it may restored, if so desired).
|
||||||
*
|
*
|
||||||
|
* Configuration Notes:
|
||||||
|
* Configuration CONFIG_AVR32_GPIOIRQ must be selected to enable the overall GPIO
|
||||||
|
* IRQ feature and CONFIG_AVR32_GPIOIRQSETA and/or CONFIG_AVR32_GPIOIRQSETB must
|
||||||
|
* be enabled to select GPIOs to support interrupts on. For button support, bits
|
||||||
|
* 2 and 3 must be set in CONFIG_AVR32_GPIOIRQSETB (PB2 and PB3).
|
||||||
|
*
|
||||||
************************************************************************************/
|
************************************************************************************/
|
||||||
|
|
||||||
#ifdef CONFIG_GPIOB_IRQ
|
#ifdef CONFIG_AVR32_GPIOIRQ
|
||||||
EXTERN xcpt_t up_irqbutton1(xcpt_t irqhandler);
|
EXTERN xcpt_t up_irqbutton1(xcpt_t irqhandler);
|
||||||
EXTERN xcpt_t up_irqbutton2(xcpt_t irqhandler);
|
EXTERN xcpt_t up_irqbutton2(xcpt_t irqhandler);
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -89,7 +89,7 @@ CONFIG_ARCH_INTERRUPTSTACK=n
|
|||||||
CONFIG_ARCH_STACKDUMP=y
|
CONFIG_ARCH_STACKDUMP=y
|
||||||
CONFIG_ARCH_BOOTLOADER=n
|
CONFIG_ARCH_BOOTLOADER=n
|
||||||
CONFIG_ARCH_LEDS=y
|
CONFIG_ARCH_LEDS=y
|
||||||
CONFIG_ARCH_BUTTONS=n
|
CONFIG_ARCH_BUTTONS=y
|
||||||
CONFIG_ARCH_CALIBRATION=n
|
CONFIG_ARCH_CALIBRATION=n
|
||||||
CONFIG_ARCH_DMA=n
|
CONFIG_ARCH_DMA=n
|
||||||
|
|
||||||
@@ -103,6 +103,10 @@ CONFIG_AVR32_AVRTOOLSL=n
|
|||||||
#
|
#
|
||||||
# Individual subsystems can be enabled:
|
# Individual subsystems can be enabled:
|
||||||
#
|
#
|
||||||
|
# CONFIG_AVR32_GPIOIRQ - GPIO interrupt support
|
||||||
|
# CONFIG_AVR32_GPIOIRQSETA - Set of GPIOs on PORTA that support interrupts
|
||||||
|
# CONFIG_AVR32_GPIOIRQSETB - Set of GPIOs on PORTB that support interrupts
|
||||||
|
#
|
||||||
# CONFIG_AVR32_USARTn - Enable support for USARTn
|
# CONFIG_AVR32_USARTn - Enable support for USARTn
|
||||||
# CONFIG_AVR32_USARTn_RS232 - Configure USARTn as an RS232 interface.
|
# CONFIG_AVR32_USARTn_RS232 - Configure USARTn as an RS232 interface.
|
||||||
# CONFIG_AVR32_USARTn_SPI - Configure USARTn as an SPI interface.
|
# CONFIG_AVR32_USARTn_SPI - Configure USARTn as an SPI interface.
|
||||||
@@ -113,6 +117,10 @@ CONFIG_AVR32_AVRTOOLSL=n
|
|||||||
# CONFIG_AVR32_USARTn_ISO786 - Configure USARTn as an ISO786 interface.
|
# CONFIG_AVR32_USARTn_ISO786 - Configure USARTn as an ISO786 interface.
|
||||||
#
|
#
|
||||||
|
|
||||||
|
CONFIG_AVR32_GPIOIRQ=y
|
||||||
|
CONFIG_AVR32_GPIOIRQSETA=0
|
||||||
|
CONFIG_AVR32_GPIOIRQSETB=0x0000000c
|
||||||
|
|
||||||
CONFIG_AVR32_USART0=n
|
CONFIG_AVR32_USART0=n
|
||||||
CONFIG_AVR32_USART0_RS232=n
|
CONFIG_AVR32_USART0_RS232=n
|
||||||
CONFIG_AVR32_USART0_SPI=n
|
CONFIG_AVR32_USART0_SPI=n
|
||||||
|
|||||||
@@ -43,11 +43,22 @@
|
|||||||
|
|
||||||
#include <nuttx/config.h>
|
#include <nuttx/config.h>
|
||||||
#include <nuttx/compiler.h>
|
#include <nuttx/compiler.h>
|
||||||
|
#include "at91uc3_config.h"
|
||||||
|
|
||||||
/************************************************************************************
|
/************************************************************************************
|
||||||
* Definitions
|
* Definitions
|
||||||
************************************************************************************/
|
************************************************************************************/
|
||||||
|
|
||||||
|
/* Configuration ********************************************************************/
|
||||||
|
|
||||||
|
#if (CONFIG_AVR32_GPIOIRQSETB & 4) == 1
|
||||||
|
# define CONFIG_AVR32DEV_BUTTON1_IRQ 1
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if (CONFIG_AVR32_GPIOIRQSETB & 8) == 1
|
||||||
|
# define CONFIG_AVR32DEV_BUTTON2_IRQ 1
|
||||||
|
#endif
|
||||||
|
|
||||||
/* AVRDEV1 GPIO Pin Definitions *****************************************************/
|
/* AVRDEV1 GPIO Pin Definitions *****************************************************/
|
||||||
/* LEDs
|
/* LEDs
|
||||||
*
|
*
|
||||||
@@ -68,8 +79,23 @@
|
|||||||
* PIN 25 PB3 KEY2
|
* PIN 25 PB3 KEY2
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#define PINMUX_GPIO_BUTTON1 (GPIO_ENABLE | GPIO_INPUT | GPIO_PORTB | 2)
|
#if CONFIG_AVR32DEV_BUTTON1_IRQ
|
||||||
#define PINMUX_GPIO_BUTTON2 (GPIO_ENABLE | GPIO_INPUT | GPIO_PORTB | 3)
|
# define PINMUX_GPIO_BUTTON1 (GPIO_ENABLE | GPIO_INPUT | GPIO_INTR | \
|
||||||
|
GPIO_INTMODE_BOTH | GPIO_GLITCH | GPIO_PORTB | 2)
|
||||||
|
# define GPIO_BUTTON1_IRQ AVR32_IRQ_GPIO_PB2
|
||||||
|
#else
|
||||||
|
# define PINMUX_GPIO_BUTTON1 (GPIO_ENABLE | GPIO_INPUT | GPIO_GLITCH | \
|
||||||
|
GPIO_PORTB | 2)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if CONFIG_AVR32DEV_BUTTON2_IRQ
|
||||||
|
# define PINMUX_GPIO_BUTTON2 (GPIO_ENABLE | GPIO_INPUT | GPIO_INTR | \
|
||||||
|
GPIO_INTMODE_BOTH | GPIO_GLITCH | GPIO_PORTB | 3)
|
||||||
|
# define GPIO_BUTTON2_IRQ AVR32_IRQ_GPIO_PB3
|
||||||
|
#else
|
||||||
|
# define PINMUX_GPIO_BUTTON2 (GPIO_ENABLE | GPIO_INPUT | GPIO_GLITCH | \
|
||||||
|
GPIO_PORTB | 3)
|
||||||
|
#endif
|
||||||
|
|
||||||
/************************************************************************************
|
/************************************************************************************
|
||||||
* Public Types
|
* Public Types
|
||||||
|
|||||||
@@ -38,7 +38,9 @@
|
|||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
#include <nuttx/config.h>
|
#include <nuttx/config.h>
|
||||||
|
#include "at91uc3_config.h"
|
||||||
|
|
||||||
|
#include <sys/types.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
#include <nuttx/irq.h>
|
#include <nuttx/irq.h>
|
||||||
@@ -59,9 +61,6 @@
|
|||||||
* Private Data
|
* Private Data
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
static xcpt_t g_irqbutton1;
|
|
||||||
static xcpt_t g_irqbutton2;
|
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* Private Functions
|
* Private Functions
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
@@ -89,7 +88,7 @@ uint8_t up_buttons(void)
|
|||||||
uint8_t retval;
|
uint8_t retval;
|
||||||
|
|
||||||
retval = at91uc3_gpioread(PINMUX_GPIO_BUTTON1) ? 0 : BUTTON1;
|
retval = at91uc3_gpioread(PINMUX_GPIO_BUTTON1) ? 0 : BUTTON1;
|
||||||
retval |= sat91uc3_gpioread(PINMUX_GPIO_BUTTON2) ? 0 : BUTTON2;
|
retval |= at91uc3_gpioread(PINMUX_GPIO_BUTTON2) ? 0 : BUTTON2;
|
||||||
|
|
||||||
return retval;
|
return retval;
|
||||||
}
|
}
|
||||||
@@ -98,30 +97,33 @@ uint8_t up_buttons(void)
|
|||||||
* Name: up_irqbutton1
|
* Name: up_irqbutton1
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
#ifdef CONFIG_GPIOB_IRQ
|
#ifdef CONFIG_AVR32_GPIOIRQ
|
||||||
xcpt_t up_irqbutton1(xcpt_t irqhandler)
|
xcpt_t up_irqbutton1(xcpt_t irqhandler)
|
||||||
{
|
{
|
||||||
|
#ifdef CONFIG_AVR32DEV_BUTTON1_IRQ
|
||||||
xcpt_t oldhandler;
|
xcpt_t oldhandler;
|
||||||
irqstate_t flags;
|
|
||||||
|
|
||||||
/* Disable interrupts until we are done */
|
/* Attach the handler */
|
||||||
|
|
||||||
flags = irqsave();
|
gpio_irqattach(GPIO_BUTTON1_IRQ, irqhandler, &oldhandler);
|
||||||
|
|
||||||
/* Get the old button interrupt handler and save the new one */
|
/* Enable/disable the interrupt */
|
||||||
|
|
||||||
oldhandler = g_irqbutton1;
|
if (irqhandler)
|
||||||
g_irqbutton1 = irqhandler;
|
{
|
||||||
|
gpio_irqenable(GPIO_BUTTON1_IRQ);
|
||||||
/* Configure and enable the interrupt */
|
}
|
||||||
|
else
|
||||||
#warning "Missing Logic"
|
{
|
||||||
|
gpio_irqdisable(GPIO_BUTTON1_IRQ);
|
||||||
irqrestore(flags);
|
}
|
||||||
|
|
||||||
/* Return the old button handler (so that it can be restored) */
|
/* Return the old button handler (so that it can be restored) */
|
||||||
|
|
||||||
return oldhandler;
|
return oldhandler;
|
||||||
|
#else
|
||||||
|
return NULL;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@@ -129,30 +131,33 @@ xcpt_t up_irqbutton1(xcpt_t irqhandler)
|
|||||||
* Name: up_irqbutton2
|
* Name: up_irqbutton2
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
#ifdef CONFIG_GPIOB_IRQ
|
#ifdef CONFIG_AVR32_GPIOIRQ
|
||||||
xcpt_t up_irqbutton2(xcpt_t irqhandler)
|
xcpt_t up_irqbutton2(xcpt_t irqhandler)
|
||||||
{
|
{
|
||||||
|
#ifdef CONFIG_AVR32DEV_BUTTON2_IRQ
|
||||||
xcpt_t oldhandler;
|
xcpt_t oldhandler;
|
||||||
irqstate_t flags;
|
|
||||||
|
|
||||||
/* Disable interrupts until we are done */
|
/* Attach the handler */
|
||||||
|
|
||||||
flags = irqsave();
|
gpio_irqattach(GPIO_BUTTON2_IRQ, irqhandler, &oldhandler);
|
||||||
|
|
||||||
/* Get the old button interrupt handler and save the new one */
|
/* Enable/disable the interrupt */
|
||||||
|
|
||||||
oldhandler = g_irqbutton2;
|
if (irqhandler)
|
||||||
g_irqbutton2 = irqhandler;
|
{
|
||||||
|
gpio_irqenable(GPIO_BUTTON2_IRQ);
|
||||||
/* Configure and enable the interrupt */
|
}
|
||||||
|
else
|
||||||
#warning "Missing Logic"
|
{
|
||||||
|
gpio_irqdisable(GPIO_BUTTON2_IRQ);
|
||||||
irqrestore(flags);
|
}
|
||||||
|
|
||||||
/* Return the old button handler (so that it can be restored) */
|
/* Return the old button handler (so that it can be restored) */
|
||||||
|
|
||||||
return oldhandler;
|
return oldhandler;
|
||||||
|
#else
|
||||||
|
return NULL;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user