2009-11-05 14:07:41 +00:00
|
|
|
/****************************************************************************
|
2014-11-28 11:35:47 -06:00
|
|
|
* configs/stm3210e-eval/src/stm32_buttons.c
|
2009-11-05 14:07:41 +00:00
|
|
|
*
|
2017-03-02 15:27:55 -06:00
|
|
|
* Copyright (C) 2009, 2011, 2014-2015, 2017 Gregory Nutt. All rights reserved.
|
2012-09-07 23:34:16 +00:00
|
|
|
* Author: Gregory Nutt <gnutt@nuttx.org>
|
2009-11-05 14:07:41 +00:00
|
|
|
*
|
|
|
|
* 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>
|
2009-12-15 20:56:22 +00:00
|
|
|
|
|
|
|
#include <stdint.h>
|
2017-03-02 16:34:37 -06:00
|
|
|
#include <errno.h>
|
2009-11-05 14:07:41 +00:00
|
|
|
|
2014-01-24 13:50:23 -06:00
|
|
|
#include <nuttx/arch.h>
|
2015-02-27 20:02:03 -06:00
|
|
|
#include <nuttx/board.h>
|
2009-11-05 14:07:41 +00:00
|
|
|
#include <arch/board/board.h>
|
2014-01-24 13:50:23 -06:00
|
|
|
|
2017-09-21 09:24:58 -06:00
|
|
|
#include "stm32_gpio.h"
|
2014-11-28 11:35:47 -06:00
|
|
|
#include "stm3210e-eval.h"
|
2009-11-05 14:07:41 +00:00
|
|
|
|
|
|
|
#ifdef CONFIG_ARCH_BUTTONS
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Private Data
|
|
|
|
****************************************************************************/
|
2011-07-07 16:20:35 +00:00
|
|
|
/* Pin configuration for each STM3210E-EVAL button. This array is indexed by
|
|
|
|
* the BUTTON_* and JOYSTICK_* definitions in board.h
|
|
|
|
*/
|
2009-11-05 14:07:41 +00:00
|
|
|
|
2016-02-25 11:12:27 -06:00
|
|
|
static const uint32_t g_buttons[NUM_BUTTONS] =
|
2009-11-05 14:07:41 +00:00
|
|
|
{
|
2014-11-28 12:05:08 -06:00
|
|
|
GPIO_BTN_WAKEUP, GPIO_BTN_TAMPER, GPIO_BTN_KEY,
|
|
|
|
|
|
|
|
/* The Joystick is treated like the other buttons unless CONFIG_DJOYSTICK
|
|
|
|
* is defined, then it is assumed that they should be used by the discrete
|
|
|
|
* joystick driver.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef CONFIG_DJOYSTICK
|
|
|
|
GPIO_JOY_SEL, GPIO_JOY_DOWN, GPIO_JOY_LEFT, GPIO_JOY_RIGHT, GPIO_JOY_UP
|
|
|
|
#endif
|
2009-11-05 14:07:41 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Private Functions
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Public Functions
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
2014-01-24 13:50:23 -06:00
|
|
|
* Name: board_button_initialize
|
2011-07-07 16:20:35 +00:00
|
|
|
*
|
|
|
|
* Description:
|
2014-01-24 13:50:23 -06:00
|
|
|
* board_button_initialize() must be called to initialize button resources. After
|
2014-01-24 13:59:24 -06:00
|
|
|
* that, board_buttons() may be called to collect the current state of all
|
2014-01-24 14:04:07 -06:00
|
|
|
* buttons or board_button_irq() may be called to register button interrupt
|
2011-07-07 16:20:35 +00:00
|
|
|
* handlers.
|
|
|
|
*
|
2009-11-05 14:07:41 +00:00
|
|
|
****************************************************************************/
|
|
|
|
|
2014-01-24 13:50:23 -06:00
|
|
|
void board_button_initialize(void)
|
2009-11-05 14:07:41 +00:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
2014-04-13 16:22:22 -06:00
|
|
|
/* Configure the GPIO pins as inputs. NOTE that EXTI interrupts are
|
2009-11-05 14:07:41 +00:00
|
|
|
* configured for some pins but NOT used in this file
|
|
|
|
*/
|
|
|
|
|
|
|
|
for (i = 0; i < NUM_BUTTONS; i++)
|
|
|
|
{
|
|
|
|
stm32_configgpio(g_buttons[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
2014-01-24 13:59:24 -06:00
|
|
|
* Name: board_buttons
|
2009-11-05 14:07:41 +00:00
|
|
|
****************************************************************************/
|
|
|
|
|
2017-04-09 07:22:49 -06:00
|
|
|
uint32_t board_buttons(void)
|
2009-11-05 14:07:41 +00:00
|
|
|
{
|
2017-04-09 07:22:49 -06:00
|
|
|
uint32_t ret = 0;
|
2009-11-05 14:07:41 +00:00
|
|
|
int i;
|
|
|
|
|
|
|
|
/* Check that state of each key */
|
|
|
|
|
|
|
|
for (i = 0; i < NUM_BUTTONS; i++)
|
|
|
|
{
|
2011-07-07 18:40:15 +00:00
|
|
|
/* A LOW value means that the key is pressed for most keys. The exception
|
|
|
|
* is the WAKEUP button.
|
|
|
|
*/
|
2009-11-05 14:07:41 +00:00
|
|
|
|
2011-07-07 18:40:15 +00:00
|
|
|
bool released = stm32_gpioread(g_buttons[i]);
|
|
|
|
if (i == BUTTON_WAKEUP)
|
2009-11-05 14:07:41 +00:00
|
|
|
{
|
2011-07-07 18:40:15 +00:00
|
|
|
released = !released;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Accumulate the set of depressed (not released) keys */
|
|
|
|
|
|
|
|
if (!released)
|
|
|
|
{
|
|
|
|
ret |= (1 << i);
|
2009-11-05 14:07:41 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2011-07-07 16:20:35 +00:00
|
|
|
/************************************************************************************
|
|
|
|
* Button support.
|
|
|
|
*
|
|
|
|
* Description:
|
2014-01-24 13:50:23 -06:00
|
|
|
* board_button_initialize() must be called to initialize button resources. After
|
2014-01-24 13:59:24 -06:00
|
|
|
* that, board_buttons() may be called to collect the current state of all
|
2014-01-24 14:04:07 -06:00
|
|
|
* buttons or board_button_irq() may be called to register button interrupt
|
2011-07-07 16:20:35 +00:00
|
|
|
* handlers.
|
|
|
|
*
|
2014-01-24 13:59:24 -06:00
|
|
|
* After board_button_initialize() has been called, board_buttons() may be called to
|
2017-04-09 14:44:49 -06:00
|
|
|
* collect the state of all buttons. board_buttons() returns an 32-bit bit set
|
2011-07-07 16:20:35 +00:00
|
|
|
* with each bit associated with a button. See the BUTTON_*_BIT and JOYSTICK_*_BIT
|
|
|
|
* definitions in board.h for the meaning of each bit.
|
|
|
|
*
|
2014-01-24 14:04:07 -06:00
|
|
|
* board_button_irq() may be called to register an interrupt handler that will
|
2011-07-07 16:20:35 +00:00
|
|
|
* 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_* and JOYSTICK_* definitions in board.h for the meaning of enumeration
|
2017-03-02 14:37:22 -06:00
|
|
|
* value.
|
2011-07-07 16:20:35 +00:00
|
|
|
*
|
|
|
|
************************************************************************************/
|
|
|
|
|
|
|
|
#ifdef CONFIG_ARCH_IRQBUTTONS
|
2017-03-02 15:27:55 -06:00
|
|
|
int board_button_irq(int id, xcpt_t irqhandler, FAR void *arg)
|
2011-07-07 16:20:35 +00:00
|
|
|
{
|
2017-03-02 16:34:37 -06:00
|
|
|
int ret = -EINVAL;
|
2011-07-07 16:20:35 +00:00
|
|
|
|
|
|
|
/* The following should be atomic */
|
|
|
|
|
|
|
|
if (id >= MIN_IRQBUTTON && id <= MAX_IRQBUTTON)
|
|
|
|
{
|
2017-03-02 16:34:37 -06:00
|
|
|
ret = stm32_gpiosetevent(g_buttons[id], true, true, true, irqhandler, arg);
|
2011-07-07 16:20:35 +00:00
|
|
|
}
|
2014-11-28 12:05:08 -06:00
|
|
|
|
2017-03-02 16:34:37 -06:00
|
|
|
return ret;
|
2011-07-07 16:20:35 +00:00
|
|
|
}
|
|
|
|
#endif
|
2009-11-05 14:07:41 +00:00
|
|
|
#endif /* CONFIG_ARCH_BUTTONS */
|