summaryrefslogtreecommitdiff
path: root/nuttx/configs/olimex-strp711
diff options
context:
space:
mode:
authorpatacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3>2008-11-01 00:42:39 +0000
committerpatacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3>2008-11-01 00:42:39 +0000
commita440b85be84c22756148426a6c0e8dcf03d47138 (patch)
tree71f364d48d59e0247ebab4104022f68772bb3cfb /nuttx/configs/olimex-strp711
parent40c5377d94f76f07e30e85f7be5a4892726aba81 (diff)
downloadpx4-nuttx-a440b85be84c22756148426a6c0e8dcf03d47138.tar.gz
px4-nuttx-a440b85be84c22756148426a6c0e8dcf03d47138.tar.bz2
px4-nuttx-a440b85be84c22756148426a6c0e8dcf03d47138.zip
Add support for LEDs and buttons
git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@1113 42af7a65-404d-4744-a932-0658087f49c3
Diffstat (limited to 'nuttx/configs/olimex-strp711')
-rw-r--r--nuttx/configs/olimex-strp711/include/board.h48
-rw-r--r--nuttx/configs/olimex-strp711/ostest/defconfig2
-rw-r--r--nuttx/configs/olimex-strp711/src/Makefile2
-rw-r--r--nuttx/configs/olimex-strp711/src/up_buttons.c116
-rw-r--r--nuttx/configs/olimex-strp711/src/up_leds.c134
5 files changed, 296 insertions, 6 deletions
diff --git a/nuttx/configs/olimex-strp711/include/board.h b/nuttx/configs/olimex-strp711/include/board.h
index 15a979750..911e0bff7 100644
--- a/nuttx/configs/olimex-strp711/include/board.h
+++ b/nuttx/configs/olimex-strp711/include/board.h
@@ -123,6 +123,22 @@
/* LED definitions **********************************************************/
+/* The Olimex board has only two LEDs, so following states are faked as
+ * follows
+ *
+ * SET CLEAR
+ * LED_STARTED (none) (n/a)
+ * LED_HEAPALLOCATE LED1 (n/a)
+ * LED_IRQSENABLED LED1 (n/a)
+ * LED_STACKCREATED LED1 (n/a)
+ * LED_INIRQ LED1+LED2 LED1
+ * LED_SIGNAL LED1+LED2 LED1
+ * LED_ASSERTION LED1+LED2 LED1
+ * LED_PANIC LED1+LED2* LED1
+ *
+ * *The previous state of LED2 will be retained
+ */
+
#define LED_STARTED 0
#define LED_HEAPALLOCATE 1
#define LED_IRQSENABLED 2
@@ -132,8 +148,38 @@
#define LED_ASSERTION 6
#define LED_PANIC 7
+/* Button definitions *******************************************************/
+
+/* The Olimex board has two buttons, one labled "BUT" and the other "WAKEUP" */
+
+#define BUT_BUTTON 1 /* Bit 0: BUT button is depressed */
+#define WAKEUP_BUTTON 2 /* Bit 1: WAKEUP button is depressed */
+
+/****************************************************************************
+ * Public Data
+ ****************************************************************************/
+
+#ifndef __ASSEMBLY__
+#ifdef __cplusplus
+#define EXTERN extern "C"
+extern "C" {
+#else
+#define EXTERN extern
+#endif
+
/****************************************************************************
- * Inline Functions
+ * Public Functions
****************************************************************************/
+#ifdef CONFIG_ARCH_BUTTONS
+EXTERN void up_buttoninit(void);
+EXTERN ubyte up_buttons(void);
+#endif
+
+#undef EXTERN
+#ifdef __cplusplus
+}
+#endif
+#endif
+
#endif /* _CONFIGS_OLIMEX_STRP711_BOARD_H */
diff --git a/nuttx/configs/olimex-strp711/ostest/defconfig b/nuttx/configs/olimex-strp711/ostest/defconfig
index 70ef9aab9..e310f54fe 100644
--- a/nuttx/configs/olimex-strp711/ostest/defconfig
+++ b/nuttx/configs/olimex-strp711/ostest/defconfig
@@ -48,6 +48,7 @@
# CONFIG_ARCH_BOARD_name - for use in C code
# CONFIG_BOARD_LOOPSPERMSEC - for delay loops
# CONFIG_ARCH_LEDS - Use LEDs to show state. Unique to Olimex STR-P711
+# CONFIG_ARCH_BUTTONS - Support reading buttons. Unique to Olimex STR-P711
# CONFIG_DRAM_SIZE - Describes the internal DRAM.
# CONFIG_DRAM_START - The start address of internal DRAM
# CONFIG_ARCH_INTERRUPTSTACK - This architecture supports an interrupt
@@ -63,6 +64,7 @@ CONFIG_ARCH_BOARD=olimex-strp711
CONFIG_ARCH_BOARD_OLIMEX_STRP711=y
CONFIG_BOARD_LOOPSPERMSEC=3270
CONFIG_ARCH_LEDS=y
+CONFIG_ARCH_BUTTONS=y
CONFIG_DRAM_SIZE=0x00010000
CONFIG_DRAM_START=0x20000000
CONFIG_DRAM_END=(CONFIG_DRAM_START+CONFIG_DRAM_SIZE)
diff --git a/nuttx/configs/olimex-strp711/src/Makefile b/nuttx/configs/olimex-strp711/src/Makefile
index 7fa4565c8..bff294aef 100644
--- a/nuttx/configs/olimex-strp711/src/Makefile
+++ b/nuttx/configs/olimex-strp711/src/Makefile
@@ -40,7 +40,7 @@ CFLAGS += -I$(ARCH_SRCDIR)/chip -I$(ARCH_SRCDIR)/common -I$(TOPDIR)/sched
ASRCS =
AOBJS = $(ASRCS:.S=$(OBJEXT))
-CSRCS = up_spi.c up_leds.c
+CSRCS = up_spi.c up_leds.c up_buttons.c
COBJS = $(CSRCS:.c=$(OBJEXT))
SRCS = $(ASRCS) $(CSRCS)
diff --git a/nuttx/configs/olimex-strp711/src/up_buttons.c b/nuttx/configs/olimex-strp711/src/up_buttons.c
new file mode 100644
index 000000000..2ee386daa
--- /dev/null
+++ b/nuttx/configs/olimex-strp711/src/up_buttons.c
@@ -0,0 +1,116 @@
+/****************************************************************************
+ * configs/olimex-strp711/src/up_leds.c
+ *
+ * Copyright (C) 2008 Gregory Nutt. All rights reserved.
+ * Author: Gregory Nutt <spudmonkey@racsa.co.cr>
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ * 3. Neither the name NuttX nor the names of its contributors may be
+ * used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
+ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+#include <sys/types.h>
+
+#include "chip.h"
+#include "up_arch.h"
+#include "up_internal.h"
+
+/****************************************************************************
+ * Definitions
+ ****************************************************************************/
+
+/* The Olimex board has two buttons, one labled "BUT" and the other "WAKEUP"
+ *
+ * P1.14: WAKEUP button
+ * P1.13: BUT button
+ */
+
+#define STR71X_BUTBUTTON_GPIO1 (0x2000)
+#define STR71X_WAKEUPBUTTON_GPIO1 (0x4000)
+#define STR71X_BOTHBUTTONS_GPIO1 (STR71X_BUTBUTTON_GPIO1|STR71X_WAKEUPBUTTON_GPIO1)
+
+/****************************************************************************
+ * Private Data
+ ****************************************************************************/
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: up_buttoninit
+ ****************************************************************************/
+
+#ifdef CONFIG_ARCH_BUTTONS
+void up_buttoninit(void)
+{
+ uint16 reg16;
+
+ /* Configure the GPIO pins as inputs */
+
+ reg16 = getreg16(STR71X_GPIO1_PC0);
+ reg16 |= STR71X_BOTHBUTTONS_GPIO1
+ putreg16(reg16, STR71X_GPIO1_PC0);
+
+ reg16 = getreg16(STR71X_GPIO1_PC1);
+ reg16 &= ~STR71X_BOTHBUTTONS_GPIO1
+ putreg16(reg16, STR71X_GPIO1_PC1);
+
+ reg16 = getreg16(STR71X_GPIO1_PC2);
+ reg16 &= ~STR71X_BOTHBUTTONS_GPIO1
+ putreg16(reg16, STR71X_GPIO1_PC2);
+}
+
+/****************************************************************************
+ * Name: up_buttons
+ ****************************************************************************/
+
+ubyte up_buttons(void)
+{
+ uint16 reg16 = getreg16(STR71X_GPIO1_PD);
+ ubyte ret = 0;
+
+ if ((reg16 & STR71X_BUTBUTTON_GPIO1) != 0)
+ {
+ ret |= BUT_BUTTON;
+ }
+ if ((reg16 & STR71X_WAKEUPBUTTON_GPIO1) != 0)
+ {
+ ret |= WAKEUP_BUTTON;
+ }
+ return ret;
+}
+#endif /* CONFIG_ARCH_BUTTONS */
diff --git a/nuttx/configs/olimex-strp711/src/up_leds.c b/nuttx/configs/olimex-strp711/src/up_leds.c
index 5014b05e2..873994c68 100644
--- a/nuttx/configs/olimex-strp711/src/up_leds.c
+++ b/nuttx/configs/olimex-strp711/src/up_leds.c
@@ -48,16 +48,50 @@
* Definitions
****************************************************************************/
+/* There are two LEDs are connected to P1.8 & 9 */
+
+#if defined(CONFIG_ARCH_LEDS) && !defined(CONFIG_STR71X_GPIO1)
+# error "LEDs require GPIO1"
+#endif
+
+#define STR71X_LED1GPIO1_BIT (0x0100)
+#define STR71X_LED2GPIO1_BIT (0x0200)
+#define STR71X_LEDGPIO1_BITS (STR71X_LED1GPIO1_BIT|STR71X_LED2GPIO1_BIT)
+
/****************************************************************************
* Private Data
****************************************************************************/
+static uint16 g_led2set;
+static uint16 g_led2clr;
+
/****************************************************************************
* Private Functions
****************************************************************************/
/****************************************************************************
- * Public Funtions
+ * Name: up_setleds
+ ****************************************************************************/
+
+static void up_setleds(uint16 setbits, uint16 clearbits)
+{
+ uint16 reg16;
+
+ /* Save the state of LED2 for later */
+
+ g_led2set = setbits & STR71X_LED2GPIO1_BIT;
+ g_led2clr = clearbits & STR71X_LED2GPIO1_BIT;
+
+ /* Set and clear bits as directed */
+
+ reg16 = getreg16(STR71X_GPIO1_PD);
+ reg16 &= ~clearbits;
+ reg16 |= setbits;
+ putreg16(reg16, STR71X_GPIO1_PD);
+}
+
+/****************************************************************************
+ * Public Functions
****************************************************************************/
/****************************************************************************
@@ -67,7 +101,27 @@
#ifdef CONFIG_ARCH_LEDS
void up_ledinit(void)
{
-#warning "To be provided"
+ uint16 reg16;
+
+ /* Set normal function output */
+
+ reg16 = getreg16(STR71X_GPIO1_PC0);
+ reg16 |= STR71X_LEDGPIO1_BITS
+ putreg16(reg16, STR71X_GPIO1_PC0);
+
+ reg16 = getreg16(STR71X_GPIO1_PC1);
+ reg16 &= ~STR71X_LEDGPIO1_BITS
+ putreg16(reg16, STR71X_GPIO1_PC1);
+
+ reg16 = getreg16(STR71X_GPIO1_PC2);
+ reg16 |= STR71X_LEDGPIO1_BITS
+ putreg16(reg16, STR71X_GPIO1_PC2);
+
+ /* Clear the LEDs (1 clears; 0 sets) */
+
+ reg16 = getreg16(STR71X_GPIO1_PD);
+ reg16 |= STR71X_LEDGPIO1_BITS
+ putreg16(reg16, STR71X_GPIO1_PD);
}
/****************************************************************************
@@ -76,7 +130,45 @@ void up_ledinit(void)
void up_ledon(int led)
{
-#warning "To be provided"
+ /* The Olimex board has only two LEDs, so following states are faked as
+ * follows
+ *
+ * SET CLEAR
+ * LED_STARTED (none) (n/a)
+ * LED_HEAPALLOCATE LED1 (n/a)
+ * LED_IRQSENABLED LED1 (n/a)
+ * LED_STACKCREATED LED1 (n/a)
+ * LED_INIRQ LED1+LED2 LED1
+ * LED_SIGNAL LED1+LED2 LED1
+ * LED_ASSERTION LED1+LED2 LED1
+ * LED_PANIC LED1+LED2* LED1
+ *
+ * *The previous state of LED2 will be retained
+ */
+
+ switch (led)
+ {
+ default:
+ case LED_STARTED:
+ up_setleds(0, STR71X_LED1GPIO1_BIT|STR71X_LED2GPIO1_BIT); /* Clear LED1&2 */
+ break;
+
+ case LED_HEAPALLOCATE:
+ case LED_IRQSENABLED:
+ case LED_STACKCREATED:
+ up_setleds(STR71X_LED1GPIO1_BIT, STR71X_LED2GPIO1_BIT); /* Set LED1, clear LED2 */
+ break;
+
+ case LED_INIRQ:
+ case LED_SIGNAL:
+ case LED_ASSERTION:
+ up_setleds(STR71X_LED1GPIO1_BIT|STR71X_LED2GPIO1_BIT, 0); /* Set LED1&2 */
+ break;
+
+ case LED_PANIC:
+ up_setleds(STR71X_LED2GPIO1_BIT|g_led2set, g_led2set); /* Set LED1, preserve LED2 */
+ break;
+ }
}
/****************************************************************************
@@ -85,6 +177,40 @@ void up_ledon(int led)
void up_ledoff(int led)
{
-#warning "To be provided"
+ /* The Olimex board has only two LEDs, so following states are faked as
+ * follows
+ *
+ * SET CLEAR
+ * LED_STARTED (none) (n/a)
+ * LED_HEAPALLOCATE LED1 (n/a)
+ * LED_IRQSENABLED LED1 (n/a)
+ * LED_STACKCREATED LED1 (n/a)
+ * LED_INIRQ LED1+LED2 LED1
+ * LED_SIGNAL LED1+LED2 LED1
+ * LED_ASSERTION LED1+LED2 LED1
+ * LED_PANIC LED1+LED2* LED1
+ *
+ * *The previous state of LED2 will be retained
+ */
+
+ switch (led)
+ {
+ default:
+ case LED_STARTED:
+ case LED_HEAPALLOCATE:
+ case LED_IRQSENABLED:
+ case LED_STACKCREATED:
+ break;
+
+ case LED_INIRQ:
+ case LED_SIGNAL:
+ case LED_ASSERTION:
+ up_setleds(STR71X_LED1GPIO1_BIT, STR71X_LED2GPIO1_BIT); /* Set LED1, clear LED2 */
+ break;
+
+ case LED_PANIC:
+ up_setleds(g_led2set, STR71X_LED1GPIO1_BIT|g_led2clr); /* Clear LED1, preserve LED2 */
+ break;
+ }
}
#endif /* CONFIG_ARCH_LEDS */