Nucleo-F401RE: Add standard, NuttX button support
This commit is contained in:
parent
55d069360a
commit
180dbe28c4
@ -31,7 +31,6 @@ Contents
|
|||||||
- LED
|
- LED
|
||||||
- Button
|
- Button
|
||||||
- USARTS and Serial Consoles
|
- USARTS and Serial Consoles
|
||||||
- Buttons and LEDs
|
|
||||||
- LQFP64
|
- LQFP64
|
||||||
- DFU and JTAG
|
- DFU and JTAG
|
||||||
- Configurations
|
- Configurations
|
||||||
@ -345,6 +344,8 @@ Hardware
|
|||||||
|
|
||||||
Buttons
|
Buttons
|
||||||
-------
|
-------
|
||||||
|
B1 USER: the user button is connected to the I/O PC13 (pin 2) of the STM32
|
||||||
|
microcontroller.
|
||||||
|
|
||||||
LEDs
|
LEDs
|
||||||
----
|
----
|
||||||
|
@ -328,6 +328,17 @@
|
|||||||
#define LED_ASSERTION 2
|
#define LED_ASSERTION 2
|
||||||
#define LED_PANIC 1
|
#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
|
* Public Data
|
||||||
************************************************************************************/
|
************************************************************************************/
|
||||||
|
@ -48,6 +48,10 @@ else
|
|||||||
CSRCS += stm32_userleds.c
|
CSRCS += stm32_userleds.c
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
ifeq ($(CONFIG_ARCH_BUTTONS),y)
|
||||||
|
CSRCS += stm32_buttons.c
|
||||||
|
endif
|
||||||
|
|
||||||
ifeq ($(CONFIG_WL_CC3000),y)
|
ifeq ($(CONFIG_WL_CC3000),y)
|
||||||
CSRCS += stm32_wireless.c
|
CSRCS += stm32_wireless.c
|
||||||
endif
|
endif
|
||||||
|
@ -14,6 +14,28 @@
|
|||||||
#include <nuttx/compiler.h>
|
#include <nuttx/compiler.h>
|
||||||
#include <stdint.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:
|
/* The shield uses the following pins:
|
||||||
*
|
*
|
||||||
* +5V
|
* +5V
|
||||||
@ -27,21 +49,12 @@
|
|||||||
* Digital pin 12:
|
* Digital pin 12:
|
||||||
* Digital pin 13:
|
* Digital pin 13:
|
||||||
* Even if optional 6-pin SPI header is used, these pins are unavailable for other use.
|
* 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_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_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_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)
|
#if defined(CONFIG_CC3000_PROBES)
|
||||||
# define GPIO_D0 (GPIO_PORTB | GPIO_PIN7 | GPIO_OUTPUT_CLEAR | GPIO_OUTPUT | GPIO_PULLUP | GPIO_SPEED_50MHz)
|
# 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)
|
# define GPIO_D1 (GPIO_PORTB | GPIO_PIN6 | GPIO_OUTPUT_CLEAR | GPIO_OUTPUT | GPIO_PULLUP | GPIO_SPEED_50MHz)
|
||||||
|
137
configs/nucleo-f401re/src/stm32_buttons.c
Normal file
137
configs/nucleo-f401re/src/stm32_buttons.c
Normal file
@ -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 */
|
Loading…
Reference in New Issue
Block a user