boards/nrf5340-dk: add buttons example
This commit is contained in:
parent
bcecf2023f
commit
6a2152aa44
5 changed files with 222 additions and 0 deletions
|
@ -1071,6 +1071,7 @@ config ARCH_BOARD_NRF5340_DK
|
|||
depends on ARCH_CHIP_NRF53
|
||||
select ARCH_HAVE_LEDS
|
||||
select ARCH_HAVE_BUTTONS
|
||||
select ARCH_HAVE_IRQBUTTONS
|
||||
---help---
|
||||
This option selects the nRF5340 Development Kit (PCA10095)
|
||||
|
||||
|
|
50
boards/arm/nrf53/nrf5340-dk/configs/buttons_cpuapp/defconfig
Normal file
50
boards/arm/nrf53/nrf5340-dk/configs/buttons_cpuapp/defconfig
Normal file
|
@ -0,0 +1,50 @@
|
|||
#
|
||||
# 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_NSH_DISABLE_IFCONFIG is not set
|
||||
# CONFIG_NSH_DISABLE_PS is not set
|
||||
# CONFIG_STANDARD_SERIAL is not set
|
||||
CONFIG_ARCH="arm"
|
||||
CONFIG_ARCH_BOARD="nrf5340-dk"
|
||||
CONFIG_ARCH_BOARD_NRF5340_DK=y
|
||||
CONFIG_ARCH_BUTTONS=y
|
||||
CONFIG_ARCH_CHIP="nrf53"
|
||||
CONFIG_ARCH_CHIP_NRF5340=y
|
||||
CONFIG_ARCH_CHIP_NRF5340_CPUAPP=y
|
||||
CONFIG_ARCH_CHIP_NRF53=y
|
||||
CONFIG_ARCH_IRQBUTTONS=y
|
||||
CONFIG_ARCH_STACKDUMP=y
|
||||
CONFIG_ARCH_STDARG_H=y
|
||||
CONFIG_BOARD_LOOPSPERMSEC=5500
|
||||
CONFIG_EXAMPLES_BUTTONS=y
|
||||
CONFIG_EXPERIMENTAL=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_MM_REGIONS=2
|
||||
CONFIG_NRF53_GPIOTE=y
|
||||
CONFIG_NRF53_UART0=y
|
||||
CONFIG_NSH_ARCHINIT=y
|
||||
CONFIG_NSH_FILEIOSIZE=512
|
||||
CONFIG_NSH_LINELEN=64
|
||||
CONFIG_NSH_READLINE=y
|
||||
CONFIG_PREALLOC_TIMERS=4
|
||||
CONFIG_RAM_SIZE=524288
|
||||
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
|
|
@ -36,6 +36,10 @@ else
|
|||
CSRCS += nrf53_userleds.c
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_ARCH_BUTTONS),y)
|
||||
CSRCS += nrf53_buttons.c
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_TIMER),y)
|
||||
ifeq ($(CONFIG_NRF53_TIMER),y)
|
||||
CSRCS += nrf53_timer.c
|
||||
|
|
|
@ -31,6 +31,10 @@
|
|||
# include <nuttx/leds/userled.h>
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_INPUT_BUTTONS
|
||||
# include <nuttx/input/buttons.h>
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_NRF53_SOFTDEVICE_CONTROLLER
|
||||
# include "nrf53_sdc.h"
|
||||
#endif
|
||||
|
@ -79,6 +83,16 @@ int nrf53_bringup(void)
|
|||
}
|
||||
#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_RPTUN
|
||||
#ifdef CONFIG_NRF53_APPCORE
|
||||
nrf53_rptun_init("nrf53-shmem", "appcore");
|
||||
|
|
153
boards/arm/nrf53/nrf5340-dk/src/nrf53_buttons.c
Normal file
153
boards/arm/nrf53/nrf5340-dk/src/nrf53_buttons.c
Normal file
|
@ -0,0 +1,153 @@
|
|||
/****************************************************************************
|
||||
* boards/arm/nrf53/nrf5340-dk/src/nrf53_buttons.c
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership. The
|
||||
* ASF licenses this file to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance with the
|
||||
* License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
|
||||
#include <debug.h>
|
||||
#include <errno.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include <nuttx/arch.h>
|
||||
#include <nuttx/board.h>
|
||||
#include <arch/board/board.h>
|
||||
|
||||
#include "nrf53_gpio.h"
|
||||
#include "nrf53_gpiote.h"
|
||||
|
||||
#include "nrf5340-dk.h"
|
||||
|
||||
#ifdef CONFIG_ARCH_BUTTONS
|
||||
|
||||
/****************************************************************************
|
||||
* Private Data
|
||||
****************************************************************************/
|
||||
|
||||
/* Pin configuration for each nrf5340 button. This array is indexed by
|
||||
* the BUTTON_* definitions in board.h
|
||||
*/
|
||||
|
||||
static const uint32_t g_buttons[NUM_BUTTONS] =
|
||||
{
|
||||
GPIO_BUTTON1,
|
||||
GPIO_BUTTON2,
|
||||
GPIO_BUTTON3,
|
||||
GPIO_BUTTON4
|
||||
};
|
||||
|
||||
/****************************************************************************
|
||||
* 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.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
uint32_t board_button_initialize(void)
|
||||
{
|
||||
int i;
|
||||
|
||||
/* Configure the GPIO pins as inputs. */
|
||||
|
||||
for (i = 0; i < NUM_BUTTONS; i++)
|
||||
{
|
||||
nrf53_gpio_config(g_buttons[i]);
|
||||
}
|
||||
|
||||
return NUM_BUTTONS;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: board_buttons
|
||||
****************************************************************************/
|
||||
|
||||
uint32_t board_buttons(void)
|
||||
{
|
||||
uint32_t ret = 0;
|
||||
int i;
|
||||
|
||||
/* Check that state of each key */
|
||||
|
||||
for (i = 0; i < NUM_BUTTONS; i++)
|
||||
{
|
||||
/* A LOW value means that the key is pressed. */
|
||||
|
||||
bool released = nrf53_gpio_read(g_buttons[BUTTON_BTN1]);
|
||||
|
||||
/* Accumulate the set of depressed (not released) keys */
|
||||
|
||||
if (!released)
|
||||
{
|
||||
ret |= (1 << i);
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* 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
|
||||
* 32-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.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef CONFIG_ARCH_IRQBUTTONS
|
||||
int board_button_irq(int id, xcpt_t irqhandler, void *arg)
|
||||
{
|
||||
int ret = OK;
|
||||
|
||||
ret = nrf53_gpiote_set_event(g_buttons[id], true, true, irqhandler, arg);
|
||||
if (ret < 0)
|
||||
{
|
||||
ierr("ERROR: nrf53_gpiote_set_event\n");
|
||||
return ret;
|
||||
}
|
||||
|
||||
return OK;
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* CONFIG_ARCH_BUTTONS */
|
Loading…
Reference in a new issue