diff options
Diffstat (limited to 'nuttx/configs/avr32dev1/src')
-rwxr-xr-x | nuttx/configs/avr32dev1/src/avr32dev1_internal.h | 30 | ||||
-rwxr-xr-x | nuttx/configs/avr32dev1/src/up_buttons.c | 65 |
2 files changed, 63 insertions, 32 deletions
diff --git a/nuttx/configs/avr32dev1/src/avr32dev1_internal.h b/nuttx/configs/avr32dev1/src/avr32dev1_internal.h index f46ed5516..1d3343127 100755 --- a/nuttx/configs/avr32dev1/src/avr32dev1_internal.h +++ b/nuttx/configs/avr32dev1/src/avr32dev1_internal.h @@ -43,11 +43,22 @@ #include <nuttx/config.h>
#include <nuttx/compiler.h>
+#include "at91uc3_config.h"
/************************************************************************************
* 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 *****************************************************/
/* LEDs
*
@@ -68,8 +79,23 @@ * PIN 25 PB3 KEY2
*/
-#define PINMUX_GPIO_BUTTON1 (GPIO_ENABLE | GPIO_INPUT | GPIO_PORTB | 2)
-#define PINMUX_GPIO_BUTTON2 (GPIO_ENABLE | GPIO_INPUT | GPIO_PORTB | 3)
+#if CONFIG_AVR32DEV_BUTTON1_IRQ
+# 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
diff --git a/nuttx/configs/avr32dev1/src/up_buttons.c b/nuttx/configs/avr32dev1/src/up_buttons.c index 37434d656..b891d8698 100755 --- a/nuttx/configs/avr32dev1/src/up_buttons.c +++ b/nuttx/configs/avr32dev1/src/up_buttons.c @@ -38,7 +38,9 @@ ****************************************************************************/ #include <nuttx/config.h> +#include "at91uc3_config.h" +#include <sys/types.h> #include <stdint.h> #include <nuttx/irq.h> @@ -59,9 +61,6 @@ * Private Data ****************************************************************************/ -static xcpt_t g_irqbutton1; -static xcpt_t g_irqbutton2; - /**************************************************************************** * Private Functions ****************************************************************************/ @@ -89,7 +88,7 @@ uint8_t up_buttons(void) uint8_t retval; 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; } @@ -98,30 +97,33 @@ uint8_t up_buttons(void) * Name: up_irqbutton1 ****************************************************************************/ -#ifdef CONFIG_GPIOB_IRQ +#ifdef CONFIG_AVR32_GPIOIRQ xcpt_t up_irqbutton1(xcpt_t irqhandler) { +#ifdef CONFIG_AVR32DEV_BUTTON1_IRQ xcpt_t oldhandler; - irqstate_t flags; - - /* Disable interrupts until we are done */ - - flags = irqsave(); - /* Get the old button interrupt handler and save the new one */ + /* Attach the handler */ - oldhandler = g_irqbutton1; - g_irqbutton1 = irqhandler; + gpio_irqattach(GPIO_BUTTON1_IRQ, irqhandler, &oldhandler); - /* Configure and enable the interrupt */ + /* Enable/disable the interrupt */ -#warning "Missing Logic" - - irqrestore(flags); + if (irqhandler) + { + gpio_irqenable(GPIO_BUTTON1_IRQ); + } + else + { + gpio_irqdisable(GPIO_BUTTON1_IRQ); + } /* Return the old button handler (so that it can be restored) */ return oldhandler; +#else + return NULL; +#endif } #endif @@ -129,30 +131,33 @@ xcpt_t up_irqbutton1(xcpt_t irqhandler) * Name: up_irqbutton2 ****************************************************************************/ -#ifdef CONFIG_GPIOB_IRQ +#ifdef CONFIG_AVR32_GPIOIRQ xcpt_t up_irqbutton2(xcpt_t irqhandler) { +#ifdef CONFIG_AVR32DEV_BUTTON2_IRQ 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; - g_irqbutton2 = irqhandler; - - /* Configure and enable the interrupt */ - -#warning "Missing Logic" - - irqrestore(flags); + if (irqhandler) + { + gpio_irqenable(GPIO_BUTTON2_IRQ); + } + else + { + gpio_irqdisable(GPIO_BUTTON2_IRQ); + } /* Return the old button handler (so that it can be restored) */ return oldhandler; +#else + return NULL; +#endif } #endif |