summaryrefslogtreecommitdiff
path: root/nuttx/configs/sam3u-ek/src
diff options
context:
space:
mode:
authorpatacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3>2010-01-23 03:05:05 +0000
committerpatacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3>2010-01-23 03:05:05 +0000
commit82c299159a50c72fc530abbd2210f084b5bcd938 (patch)
treef9169bd45dc5766382e6f0fd9efb63e7ca027e93 /nuttx/configs/sam3u-ek/src
parentdfddbfc5b48b54ccfdc5a6a6d096898a6ffdd027 (diff)
downloadpx4-nuttx-82c299159a50c72fc530abbd2210f084b5bcd938.tar.gz
px4-nuttx-82c299159a50c72fc530abbd2210f084b5bcd938.tar.bz2
px4-nuttx-82c299159a50c72fc530abbd2210f084b5bcd938.zip
Misc fixes, add button support, GPIO interrupt support
git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@2523 42af7a65-404d-4744-a932-0658087f49c3
Diffstat (limited to 'nuttx/configs/sam3u-ek/src')
-rwxr-xr-xnuttx/configs/sam3u-ek/src/sam3uek_internal.h4
-rwxr-xr-xnuttx/configs/sam3u-ek/src/up_buttons.c83
2 files changed, 85 insertions, 2 deletions
diff --git a/nuttx/configs/sam3u-ek/src/sam3uek_internal.h b/nuttx/configs/sam3u-ek/src/sam3uek_internal.h
index fde22f7d8..0e816204b 100755
--- a/nuttx/configs/sam3u-ek/src/sam3uek_internal.h
+++ b/nuttx/configs/sam3u-ek/src/sam3uek_internal.h
@@ -43,6 +43,7 @@
#include <nuttx/config.h>
#include <nuttx/compiler.h>
+#include <nuttx/irq.h>
#include <stdint.h>
/************************************************************************************
@@ -64,6 +65,9 @@
#define GPIO_BUTTON1 (GPIO_INPUT|GPIO_CFG_PULLUP|GPIO_CFG_DEGLITCH|GPIO_PORT_PIOA|GPIO_PIN18)
#define GPIO_BUTTON2 (GPIO_INPUT|GPIO_CFG_PULLUP|GPIO_CFG_DEGLITCH|GPIO_PORT_PIOA|GPIO_PIN19)
+#define IRQ_BUTTON1 SAM3U_IRQ_PA18
+#define IRQ_BUTTON2 SAM3U_IRQ_PA19
+
/* SPI Chip Selects */
/************************************************************************************
diff --git a/nuttx/configs/sam3u-ek/src/up_buttons.c b/nuttx/configs/sam3u-ek/src/up_buttons.c
index abbe502c2..ea8fe0aaf 100755
--- a/nuttx/configs/sam3u-ek/src/up_buttons.c
+++ b/nuttx/configs/sam3u-ek/src/up_buttons.c
@@ -1,7 +1,7 @@
/****************************************************************************
* configs/sam3u-ek/src/up_leds.c
*
- * Copyright (C) 2009 Gregory Nutt. All rights reserved.
+ * Copyright (C) 2010 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <spudmonkey@racsa.co.cr>
*
* Redistribution and use in source and binary forms, with or without
@@ -41,7 +41,12 @@
#include <stdint.h>
+#include <nuttx/irq.h>
+
+#include <arch/irq.h>
#include <arch/board/board.h>
+
+#include "sam3u_internal.h"
#include "sam3uek_internal.h"
#ifdef CONFIG_ARCH_BUTTONS
@@ -54,6 +59,9 @@
* Private Data
****************************************************************************/
+static xcpt_t g_irqbutton1;
+static xcpt_t g_irqbutton2;
+
/****************************************************************************
* Private Functions
****************************************************************************/
@@ -68,6 +76,8 @@
void up_buttoninit(void)
{
+ (void)sam3u_configgpio(GPIO_BUTTON1);
+ (void)sam3u_configgpio(GPIO_BUTTON2);
}
/****************************************************************************
@@ -76,7 +86,76 @@ void up_buttoninit(void)
uint8_t up_buttons(void)
{
- return 0;
+ uint8_t retval;
+
+ retval = sam3u_gpioread(GPIO_BUTTON1) ? 0 : GPIO_BUTTON1;
+ retval |= sam3u_gpioread(GPIO_BUTTON2) ? 0 : GPIO_BUTTON2;
+
+ return retval;
+}
+
+/****************************************************************************
+ * Name: up_irqbutton1
+ ****************************************************************************/
+
+#ifdef CONFIG_GPIOA_IRQ
+xcpt_t up_irqbutton1(xcpt_t irqhandler)
+{
+ 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 */
+
+ oldhandler = g_irqbutton1;
+ g_irqbutton1 = irqhandler;
+
+ /* Configure the interrupt */
+
+ sam3u_gpioirq(IRQ_BUTTON1);
+ (void)irq_attach(IRQ_BUTTON1, irqhandler);
+ sam3u_gpioirqenable(IRQ_BUTTON1);
+ irqrestore(flags);
+
+ /* Return the old button handler (so that it can be restored) */
+
+ return oldhandler;
+}
+#endif
+
+/****************************************************************************
+ * Name: up_irqbutton2
+ ****************************************************************************/
+
+#ifdef CONFIG_GPIOA_IRQ
+xcpt_t up_irqbutton2(xcpt_t irqhandler)
+{
+ 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 */
+
+ oldhandler = g_irqbutton2;
+ g_irqbutton2 = irqhandler;
+
+ /* Configure the interrupt */
+
+ sam3u_gpioirq(IRQ_BUTTON2);
+ (void)irq_attach(IRQ_BUTTON2, irqhandler);
+ sam3u_gpioirqenable(IRQ_BUTTON2);
+ irqrestore(flags);
+
+ /* Return the old button handler (so that it can be restored) */
+
+ return oldhandler;
}
+#endif
#endif /* CONFIG_ARCH_BUTTONS */