mirror of
https://github.com/apache/nuttx.git
synced 2026-05-27 19:36:35 +08:00
boards/nrf52840-dk: add buttons example
This commit is contained in:
committed by
Alan Carvalho de Assis
parent
b15244d4b2
commit
384cbc2013
@@ -1013,6 +1013,7 @@ config ARCH_BOARD_NRF52840_DK
|
|||||||
depends on ARCH_CHIP_NRF52
|
depends on ARCH_CHIP_NRF52
|
||||||
select ARCH_HAVE_LEDS
|
select ARCH_HAVE_LEDS
|
||||||
select ARCH_HAVE_BUTTONS
|
select ARCH_HAVE_BUTTONS
|
||||||
|
select ARCH_HAVE_IRQBUTTONS
|
||||||
---help---
|
---help---
|
||||||
This option selects the Nordic nRF52840 Development Kit (PCA10056)
|
This option selects the Nordic nRF52840 Development Kit (PCA10056)
|
||||||
|
|
||||||
|
|||||||
@@ -37,6 +37,10 @@
|
|||||||
# include <nuttx/leds/userled.h>
|
# include <nuttx/leds/userled.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef CONFIG_INPUT_BUTTONS
|
||||||
|
# include <nuttx/input/buttons.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef CONFIG_NRF52_SOFTDEVICE_CONTROLLER
|
#ifdef CONFIG_NRF52_SOFTDEVICE_CONTROLLER
|
||||||
# include "nrf52_sdc.h"
|
# include "nrf52_sdc.h"
|
||||||
#endif
|
#endif
|
||||||
@@ -96,6 +100,16 @@ int nrf52_bringup(void)
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef CONFIG_INPUT_BUTTONS
|
||||||
|
/* Register the BUTTON driver */
|
||||||
|
|
||||||
|
ret = btn_lower_initialize("/dev/buttons");
|
||||||
|
if (ret < 0)
|
||||||
|
{
|
||||||
|
syslog(LOG_ERR, "ERROR: btn_lower_initialize() failed: %d\n", ret);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef CONFIG_NRF52_SOFTDEVICE_CONTROLLER
|
#ifdef CONFIG_NRF52_SOFTDEVICE_CONTROLLER
|
||||||
ret = nrf52_sdc_initialize();
|
ret = nrf52_sdc_initialize();
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,51 @@
|
|||||||
|
#
|
||||||
|
# This file is autogenerated: PLEASE DO NOT EDIT IT.
|
||||||
|
#
|
||||||
|
# You can use "make menuconfig" to make any modifications to the installed .config file.
|
||||||
|
# You can then do "make savedefconfig" to generate a new defconfig file that includes your
|
||||||
|
# modifications.
|
||||||
|
#
|
||||||
|
# CONFIG_ARCH_FPU is not set
|
||||||
|
# CONFIG_NSH_DISABLE_IFCONFIG is not set
|
||||||
|
# CONFIG_NSH_DISABLE_PS is not set
|
||||||
|
CONFIG_ARCH="arm"
|
||||||
|
CONFIG_ARCH_BOARD="nrf52840-dk"
|
||||||
|
CONFIG_ARCH_BOARD_NRF52840_DK=y
|
||||||
|
CONFIG_ARCH_BUTTONS=y
|
||||||
|
CONFIG_ARCH_CHIP="nrf52"
|
||||||
|
CONFIG_ARCH_CHIP_NRF52840=y
|
||||||
|
CONFIG_ARCH_CHIP_NRF52=y
|
||||||
|
CONFIG_ARCH_IRQBUTTONS=y
|
||||||
|
CONFIG_ARCH_STACKDUMP=y
|
||||||
|
CONFIG_ARCH_STDARG_H=y
|
||||||
|
CONFIG_BOARD_LOOPSPERMSEC=5500
|
||||||
|
CONFIG_BUILTIN=y
|
||||||
|
CONFIG_EXAMPLES_BUTTONS=y
|
||||||
|
CONFIG_FAT_LCNAMES=y
|
||||||
|
CONFIG_FAT_LFN=y
|
||||||
|
CONFIG_FS_FAT=y
|
||||||
|
CONFIG_INIT_ENTRYPOINT="nsh_main"
|
||||||
|
CONFIG_INPUT=y
|
||||||
|
CONFIG_INPUT_BUTTONS=y
|
||||||
|
CONFIG_INPUT_BUTTONS_LOWER=y
|
||||||
|
CONFIG_INTELHEX_BINARY=y
|
||||||
|
CONFIG_MM_REGIONS=2
|
||||||
|
CONFIG_NRF52_GPIOTE=y
|
||||||
|
CONFIG_NRF52_UART0=y
|
||||||
|
CONFIG_NSH_ARCHINIT=y
|
||||||
|
CONFIG_NSH_BUILTIN_APPS=y
|
||||||
|
CONFIG_NSH_FILEIOSIZE=512
|
||||||
|
CONFIG_NSH_LINELEN=64
|
||||||
|
CONFIG_NSH_READLINE=y
|
||||||
|
CONFIG_PREALLOC_TIMERS=4
|
||||||
|
CONFIG_RAM_SIZE=65535
|
||||||
|
CONFIG_RAM_START=0x20000000
|
||||||
|
CONFIG_RAW_BINARY=y
|
||||||
|
CONFIG_RR_INTERVAL=200
|
||||||
|
CONFIG_SCHED_WAITPID=y
|
||||||
|
CONFIG_START_DAY=26
|
||||||
|
CONFIG_START_MONTH=3
|
||||||
|
CONFIG_SYMTAB_ORDEREDBYNAME=y
|
||||||
|
CONFIG_SYSTEM_NSH=y
|
||||||
|
CONFIG_TASK_NAME_SIZE=0
|
||||||
|
CONFIG_UART0_SERIAL_CONSOLE=y
|
||||||
@@ -33,6 +33,10 @@
|
|||||||
# include <nuttx/leds/userled.h>
|
# include <nuttx/leds/userled.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef CONFIG_INPUT_BUTTONS
|
||||||
|
# include <nuttx/input/buttons.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef CONFIG_NRF52_SOFTDEVICE_CONTROLLER
|
#ifdef CONFIG_NRF52_SOFTDEVICE_CONTROLLER
|
||||||
# include "nrf52_sdc.h"
|
# include "nrf52_sdc.h"
|
||||||
#endif
|
#endif
|
||||||
@@ -142,6 +146,16 @@ int nrf52_bringup(void)
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef CONFIG_INPUT_BUTTONS
|
||||||
|
/* Register the BUTTON driver */
|
||||||
|
|
||||||
|
ret = btn_lower_initialize("/dev/buttons");
|
||||||
|
if (ret < 0)
|
||||||
|
{
|
||||||
|
syslog(LOG_ERR, "ERROR: btn_lower_initialize() failed: %d\n", ret);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef CONFIG_SENSORS_LSM6DSL
|
#ifdef CONFIG_SENSORS_LSM6DSL
|
||||||
ret = nrf52_lsm6dsl_initialize("/dev/lsm6dsl0");
|
ret = nrf52_lsm6dsl_initialize("/dev/lsm6dsl0");
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
|
|||||||
@@ -24,14 +24,16 @@
|
|||||||
|
|
||||||
#include <nuttx/config.h>
|
#include <nuttx/config.h>
|
||||||
|
|
||||||
#include <stdint.h>
|
#include <debug.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
#include <nuttx/arch.h>
|
#include <nuttx/arch.h>
|
||||||
#include <nuttx/board.h>
|
#include <nuttx/board.h>
|
||||||
#include <arch/board/board.h>
|
#include <arch/board/board.h>
|
||||||
|
|
||||||
#include "nrf52_gpio.h"
|
#include "nrf52_gpio.h"
|
||||||
|
#include "nrf52_gpiote.h"
|
||||||
|
|
||||||
#include "nrf52840-dk.h"
|
#include "nrf52840-dk.h"
|
||||||
|
|
||||||
@@ -89,27 +91,22 @@ uint32_t board_button_initialize(void)
|
|||||||
uint32_t board_buttons(void)
|
uint32_t board_buttons(void)
|
||||||
{
|
{
|
||||||
uint32_t ret = 0;
|
uint32_t ret = 0;
|
||||||
|
int i;
|
||||||
|
|
||||||
/* Check that state of each key */
|
/* Check that state of each key */
|
||||||
|
|
||||||
if (!nrf52_gpio_read(g_buttons[BUTTON_BTN1]))
|
for (i = 0; i < NUM_BUTTONS; i++)
|
||||||
{
|
{
|
||||||
ret |= BUTTON_BTN1_BIT;
|
/* A LOW value means that the key is pressed. */
|
||||||
}
|
|
||||||
|
|
||||||
if (!nrf52_gpio_read(g_buttons[BUTTON_BTN2]))
|
bool released = nrf52_gpio_read(g_buttons[i]);
|
||||||
{
|
|
||||||
ret |= BUTTON_BTN2_BIT;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!nrf52_gpio_read(g_buttons[BUTTON_BTN3]))
|
/* Accumulate the set of depressed (not released) keys */
|
||||||
{
|
|
||||||
ret |= BUTTON_BTN3_BIT;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!nrf52_gpio_read(g_buttons[BUTTON_BTN4]))
|
if (!released)
|
||||||
{
|
{
|
||||||
ret |= BUTTON_BTN4_BIT;
|
ret |= (1 << i);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
@@ -140,11 +137,16 @@ uint32_t board_buttons(void)
|
|||||||
#ifdef CONFIG_ARCH_IRQBUTTONS
|
#ifdef CONFIG_ARCH_IRQBUTTONS
|
||||||
int board_button_irq(int id, xcpt_t irqhandler, void *arg)
|
int board_button_irq(int id, xcpt_t irqhandler, void *arg)
|
||||||
{
|
{
|
||||||
int ret = -ENOSYS;
|
int ret = OK;
|
||||||
|
|
||||||
#warning Missing Implementation!
|
ret = nrf52_gpiote_set_event(g_buttons[id], true, true, irqhandler, arg);
|
||||||
|
if (ret < 0)
|
||||||
|
{
|
||||||
|
ierr("ERROR: nrf52_gpiote_set_event failed %d\n", ret);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
return ret;
|
return OK;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|||||||
@@ -88,8 +88,7 @@ static int sx127x_irq0_attach(xcpt_t isr, void *arg)
|
|||||||
|
|
||||||
/* IRQ on rising edge */
|
/* IRQ on rising edge */
|
||||||
|
|
||||||
nrf52_gpiote_set_ch_event(GPIO_SX127X_DIO0, 0, true, false, isr, arg);
|
return nrf52_gpiote_set_event(GPIO_SX127X_DIO0, true, false, isr, arg);
|
||||||
return OK;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
|
|||||||
Reference in New Issue
Block a user