You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by ac...@apache.org on 2023/03/14 22:17:42 UTC
[nuttx] 04/04: boards/nrf52832-dk: add buttons example
This is an automated email from the ASF dual-hosted git repository.
acassis pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git
commit ef9190379cc56d82cbf7d2cd46e954a74ae1d06f
Author: raiden00pl <ra...@railab.me>
AuthorDate: Tue Mar 14 12:49:21 2023 +0100
boards/nrf52832-dk: add buttons example
---
boards/Kconfig | 1 +
.../nrf52/nrf52832-dk/configs/buttons/defconfig | 51 ++++++++++++++++++++++
boards/arm/nrf52/nrf52832-dk/src/nrf52_buttons.c | 38 ++++++++--------
3 files changed, 72 insertions(+), 18 deletions(-)
diff --git a/boards/Kconfig b/boards/Kconfig
index bad6f227be..e904275394 100644
--- a/boards/Kconfig
+++ b/boards/Kconfig
@@ -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)
diff --git a/boards/arm/nrf52/nrf52832-dk/configs/buttons/defconfig b/boards/arm/nrf52/nrf52832-dk/configs/buttons/defconfig
new file mode 100644
index 0000000000..abd9c9210d
--- /dev/null
+++ b/boards/arm/nrf52/nrf52832-dk/configs/buttons/defconfig
@@ -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
diff --git a/boards/arm/nrf52/nrf52832-dk/src/nrf52_buttons.c b/boards/arm/nrf52/nrf52832-dk/src/nrf52_buttons.c
index f4b7f02431..334d3323e2 100644
--- a/boards/arm/nrf52/nrf52832-dk/src/nrf52_buttons.c
+++ b/boards/arm/nrf52/nrf52832-dk/src/nrf52_buttons.c
@@ -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]))
- {
- ret |= BUTTON_BTN4_BIT;
+ if (!released)
+ {
+ 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;
+ 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