summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGregory Nutt <gnutt@nuttx.org>2014-04-22 13:09:34 -0600
committerGregory Nutt <gnutt@nuttx.org>2014-04-22 13:09:34 -0600
commit4ab110139337ce2b6d0f142fe23f241797fdb5e8 (patch)
treeb36ee3da80474280e73c09078980fcc0e02e7628
parent36e36e07c2450ca18424cae78c2bf7b69e8f464b (diff)
downloadnuttx-4ab110139337ce2b6d0f142fe23f241797fdb5e8.tar.gz
nuttx-4ab110139337ce2b6d0f142fe23f241797fdb5e8.tar.bz2
nuttx-4ab110139337ce2b6d0f142fe23f241797fdb5e8.zip
Nucleo-F401RE: Add standard, NuttX button support
-rw-r--r--nuttx/configs/nucleo-f401re/README.txt3
-rw-r--r--nuttx/configs/nucleo-f401re/include/board.h11
-rw-r--r--nuttx/configs/nucleo-f401re/src/Makefile4
-rw-r--r--nuttx/configs/nucleo-f401re/src/nucleo-f401re.h31
-rw-r--r--nuttx/configs/nucleo-f401re/src/stm32_buttons.c137
5 files changed, 176 insertions, 10 deletions
diff --git a/nuttx/configs/nucleo-f401re/README.txt b/nuttx/configs/nucleo-f401re/README.txt
index 868c12358..fe1d527f1 100644
--- a/nuttx/configs/nucleo-f401re/README.txt
+++ b/nuttx/configs/nucleo-f401re/README.txt
@@ -31,7 +31,6 @@ Contents
- LED
- Button
- USARTS and Serial Consoles
- - Buttons and LEDs
- LQFP64
- DFU and JTAG
- Configurations
@@ -345,6 +344,8 @@ Hardware
Buttons
-------
+ B1 USER: the user button is connected to the I/O PC13 (pin 2) of the STM32
+ microcontroller.
LEDs
----
diff --git a/nuttx/configs/nucleo-f401re/include/board.h b/nuttx/configs/nucleo-f401re/include/board.h
index ecebadf87..9f4c00fe3 100644
--- a/nuttx/configs/nucleo-f401re/include/board.h
+++ b/nuttx/configs/nucleo-f401re/include/board.h
@@ -328,6 +328,17 @@
#define LED_ASSERTION 2
#define LED_PANIC 1
+/* Buttons
+ *
+ * B1 USER: the user button is connected to the I/O PC13 (pin 2) of the STM32
+ * microcontroller.
+ */
+
+#define BUTTON_USER 0
+#define NUM_BUTTONS 1
+
+#define BUTTON_USER_BIT (1 << BUTTON_USER)
+
/************************************************************************************
* Public Data
************************************************************************************/
diff --git a/nuttx/configs/nucleo-f401re/src/Makefile b/nuttx/configs/nucleo-f401re/src/Makefile
index e952073f6..dcda3c89f 100644
--- a/nuttx/configs/nucleo-f401re/src/Makefile
+++ b/nuttx/configs/nucleo-f401re/src/Makefile
@@ -48,6 +48,10 @@ else
CSRCS += stm32_userleds.c
endif
+ifeq ($(CONFIG_ARCH_BUTTONS),y)
+CSRCS += stm32_buttons.c
+endif
+
ifeq ($(CONFIG_WL_CC3000),y)
CSRCS += stm32_wireless.c
endif
diff --git a/nuttx/configs/nucleo-f401re/src/nucleo-f401re.h b/nuttx/configs/nucleo-f401re/src/nucleo-f401re.h
index eb904a9f2..a46149158 100644
--- a/nuttx/configs/nucleo-f401re/src/nucleo-f401re.h
+++ b/nuttx/configs/nucleo-f401re/src/nucleo-f401re.h
@@ -14,6 +14,28 @@
#include <nuttx/compiler.h>
#include <stdint.h>
+/* LED. User LD2: the green LED is a user LED connected to Arduino signal D13
+ * corresponding to MCU I/O PA5 (pin 21) or PB13 (pin 34) depending on the STM32
+ * target.
+ *
+ * - When the I/O is HIGH value, the LED is on.
+ * - When the I/O is LOW, the LED is off.
+ */
+
+#define GPIO_LD2 (GPIO_PORTA | GPIO_PIN13 | GPIO_OUTPUT_CLEAR | GPIO_OUTPUT | GPIO_PULLUP | GPIO_SPEED_50MHz)
+
+/* Buttons
+ *
+ * B1 USER: the user button is connected to the I/O PC13 (pin 2) of the STM32
+ * microcontroller.
+ */
+
+#define MIN_IRQBUTTON BUTTON_USER
+#define MAX_IRQBUTTON BUTTON_USER
+#define NUM_IRQBUTTONS 1
+
+#define GPIO_BTN_USER (GPIO_INPUT |GPIO_FLOAT |GPIO_EXTI | GPIO_PORTC | GPIO_PIN13)
+
/* The shield uses the following pins:
*
* +5V
@@ -27,21 +49,12 @@
* Digital pin 12:
* Digital pin 13:
* Even if optional 6-pin SPI header is used, these pins are unavailable for other use.
- *
- * LED. User LD2: the green LED is a user LED connected to Arduino signal D13
- * corresponding to MCU I/O PA5 (pin 21) or PB13 (pin 34) depending on the STM32
- * target.
- *
- * - When the I/O is HIGH value, the LED is on.
- * - When the I/O is LOW, the LED is off.
*/
#define GPIO_WIFI_INT (GPIO_PORTB | GPIO_PIN3 | GPIO_INPUT | GPIO_PULLUP | GPIO_EXTI)
#define GPIO_WIFI_EN (GPIO_PORTB | GPIO_PIN4 | GPIO_OUTPUT_CLEAR | GPIO_OUTPUT | GPIO_PULLUP | GPIO_SPEED_50MHz)
#define GPIO_WIFI_CS (GPIO_PORTB | GPIO_PIN6 | GPIO_OUTPUT_SET | GPIO_OUTPUT | GPIO_PULLUP | GPIO_SPEED_50MHz)
-#define GPIO_LD2 (GPIO_PORTA | GPIO_PIN13 | GPIO_OUTPUT_CLEAR | GPIO_OUTPUT | GPIO_PULLUP | GPIO_SPEED_50MHz)
-
#if defined(CONFIG_CC3000_PROBES)
# define GPIO_D0 (GPIO_PORTB | GPIO_PIN7 | GPIO_OUTPUT_CLEAR | GPIO_OUTPUT | GPIO_PULLUP | GPIO_SPEED_50MHz)
# define GPIO_D1 (GPIO_PORTB | GPIO_PIN6 | GPIO_OUTPUT_CLEAR | GPIO_OUTPUT | GPIO_PULLUP | GPIO_SPEED_50MHz)
diff --git a/nuttx/configs/nucleo-f401re/src/stm32_buttons.c b/nuttx/configs/nucleo-f401re/src/stm32_buttons.c
new file mode 100644
index 000000000..e4ced3768
--- /dev/null
+++ b/nuttx/configs/nucleo-f401re/src/stm32_buttons.c
@@ -0,0 +1,137 @@
+/****************************************************************************
+ * configs/nucleo-f401re/src/stm32_buttons.c
+ *
+ * Copyright (C) 2014 Gregory Nutt. All rights reserved.
+ * Author: Gregory Nutt <gnutt@nuttx.org>
+ *
+ * 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 <stdint.h>
+
+#include <nuttx/arch.h>
+#include <arch/board/board.h>
+
+#include "nucleo-f401re.h"
+
+#ifdef CONFIG_ARCH_BUTTONS
+
+/****************************************************************************
+ * Definitions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Private Data
+ ****************************************************************************/
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: board_button_initialize
+ *
+ * Description:
+ * board_button_initialize() must be called to initialize button resources.
+ * After that, board_buttons() may be called to collect the current state
+ * of all buttons or board_button_irq() may be called to register button
+ * interrupt handlers.
+ *
+ ****************************************************************************/
+
+void board_button_initialize(void)
+{
+ /* Configure the single button as an input. NOTE that EXTI interrupts are
+ * also configured for the pin.
+ */
+
+ stm32_configgpio(GPIO_BTN_USER);
+}
+
+/****************************************************************************
+ * Name: board_buttons
+ ****************************************************************************/
+
+uint8_t board_buttons(void)
+{
+ /* Check that state of each USER button. A LOW value means that the key is
+ * pressed.
+ */
+
+ bool released = stm32_gpioread(GPIO_BTN_USER);
+ return !released;
+}
+
+/************************************************************************************
+ * Button support.
+ *
+ * Description:
+ * board_button_initialize() must be called to initialize button resources. After
+ * that, board_buttons() may be called to collect the current state of all
+ * buttons or board_button_irq() may be called to register button interrupt
+ * handlers.
+ *
+ * After board_button_initialize() has been called, board_buttons() may be called to
+ * collect the state of all buttons. board_buttons() returns an 8-bit bit set
+ * with each bit associated with a button. See the BUTTON_*_BIT
+ * definitions in board.h for the meaning of each bit.
+ *
+ * board_button_irq() may be called to register an interrupt handler that will
+ * be called when a button is depressed or released. The ID value is a
+ * button enumeration value that uniquely identifies a button resource. See the
+ * BUTTON_* definitions in board.h for the meaning of enumeration
+ * value. The previous interrupt handler address is returned (so that it may
+ * restored, if so desired).
+ *
+ ************************************************************************************/
+
+#ifdef CONFIG_ARCH_IRQBUTTONS
+xcpt_t board_button_irq(int id, xcpt_t irqhandler)
+{
+ xcpt_t oldhandler = NULL;
+
+ if (id == BUTTON_USER)
+ {
+ oldhandler = stm32_gpiosetevent(GPIO_BTN_USER, true, true, true, irqhandler);
+ }
+
+ return oldhandler;
+}
+#endif
+#endif /* CONFIG_ARCH_BUTTONS */