boards/nrf52832-dk: add buttons example

This commit is contained in:
raiden00pl 2023-03-14 12:49:21 +01:00 committed by Alan Carvalho de Assis
parent 384cbc2013
commit ef9190379c
3 changed files with 72 additions and 18 deletions

View File

@ -981,6 +981,7 @@ config ARCH_BOARD_NRF52832_DK
depends on ARCH_CHIP_NRF52
select ARCH_HAVE_LEDS
select ARCH_HAVE_BUTTONS
select ARCH_HAVE_IRQBUTTONS
---help---
This option selects the Nordic nRF52832 Development Kit (PCA10040)

View File

@ -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="nrf52832-dk"
CONFIG_ARCH_BOARD_NRF52832_DK=y
CONFIG_ARCH_BUTTONS=y
CONFIG_ARCH_CHIP="nrf52"
CONFIG_ARCH_CHIP_NRF52832=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

View File

@ -24,14 +24,16 @@
#include <nuttx/config.h>
#include <stdint.h>
#include <debug.h>
#include <errno.h>
#include <stdint.h>
#include <nuttx/arch.h>
#include <nuttx/board.h>
#include <arch/board/board.h>
#include "nrf52_gpio.h"
#include "nrf52_gpiote.h"
#include "nrf52832-dk.h"
@ -89,27 +91,22 @@ uint32_t board_button_initialize(void)
uint32_t board_buttons(void)
{
uint32_t ret = 0;
int i;
/* 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]))
{
ret |= BUTTON_BTN2_BIT;
}
bool released = nrf52_gpio_read(g_buttons[i]);
if (!nrf52_gpio_read(g_buttons[BUTTON_BTN3]))
{
ret |= BUTTON_BTN3_BIT;
}
/* Accumulate the set of depressed (not released) keys */
if (!nrf52_gpio_read(g_buttons[BUTTON_BTN4]))
if (!released)
{
ret |= BUTTON_BTN4_BIT;
ret |= (1 << i);
}
}
return ret;
@ -140,11 +137,16 @@ uint32_t board_buttons(void)
#ifdef CONFIG_ARCH_IRQBUTTONS
int board_button_irq(int id, xcpt_t irqhandler, void *arg)
{
int ret = -ENOSYS;
#warning Missing Implementation!
int ret = OK;
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 OK;
}
#endif