This is an automated email from the ASF dual-hosted git repository. xiaoxiang781216 pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/nuttx.git
commit 4295024832a0f70820156d2a7e6e09d68897e91f Author: Jukka Laitinen <[email protected]> AuthorDate: Tue Sep 29 14:29:13 2026 +0300 boards/imxrt/imxrt1180-evk: Add buttons example app and SW8 button configuration Add a button configuration to test GPIO inputs. Signed-off-by: Jukka Laitinen <[email protected]> --- boards/Kconfig | 2 + .../arm/imxrt/imxrt1180-evk/configs/nsh/defconfig | 10 ++ boards/arm/imxrt/imxrt1180-evk/include/board.h | 21 +++ boards/arm/imxrt/imxrt1180-evk/src/Makefile | 4 + boards/arm/imxrt/imxrt1180-evk/src/imxrt_bringup.c | 12 ++ boards/arm/imxrt/imxrt1180-evk/src/imxrt_buttons.c | 151 +++++++++++++++++++++ 6 files changed, 200 insertions(+) diff --git a/boards/Kconfig b/boards/Kconfig index 7a42a02720c..ab05ebd4454 100644 --- a/boards/Kconfig +++ b/boards/Kconfig @@ -1031,6 +1031,8 @@ config ARCH_BOARD_IMX93_QSB config ARCH_BOARD_IMXRT1180_EVK bool "NXP i.MX RT 1180 EVK" depends on ARCH_CHIP_MIMXRT1189CVM8C || ARCH_CHIP_MIMXRT1189CVM8C_CM33 + select ARCH_HAVE_BUTTONS + select ARCH_HAVE_IRQBUTTONS ---help--- This is the board configuration for the port of NuttX to the NXP i.MXRT evaluation kit, MIMXRT1180-EVK. This board features the IMXRT1189 MCU. diff --git a/boards/arm/imxrt/imxrt1180-evk/configs/nsh/defconfig b/boards/arm/imxrt/imxrt1180-evk/configs/nsh/defconfig index 2f04d395695..0511631a8c5 100644 --- a/boards/arm/imxrt/imxrt1180-evk/configs/nsh/defconfig +++ b/boards/arm/imxrt/imxrt1180-evk/configs/nsh/defconfig @@ -9,9 +9,11 @@ CONFIG_ARCH="arm" CONFIG_ARCH_BOARD="imxrt1180-evk" CONFIG_ARCH_BOARD_IMXRT1180_EVK=y +CONFIG_ARCH_BUTTONS=y CONFIG_ARCH_CHIP="imxrt" CONFIG_ARCH_CHIP_IMXRT=y CONFIG_ARCH_CHIP_MIMXRT1189CVM8C=y +CONFIG_ARCH_IRQBUTTONS=y CONFIG_ARCH_STACKDUMP=y CONFIG_ARMV7M_DCACHE=y CONFIG_ARMV7M_ICACHE=y @@ -33,14 +35,22 @@ CONFIG_DEBUG_FULLOPT=y CONFIG_DEBUG_HARDFAULT_ALERT=y CONFIG_DEBUG_SYMBOLS=y CONFIG_DEBUG_USAGEFAULT=y +CONFIG_EXAMPLES_BUTTONS=y +CONFIG_EXAMPLES_BUTTONS_NAME0="SW8" +CONFIG_EXAMPLES_BUTTONS_NAMES=y +CONFIG_EXAMPLES_BUTTONS_QTD=1 CONFIG_FS_NAMED_SEMAPHORES=y CONFIG_FS_PROCFS=y CONFIG_IDLETHREAD_STACKSIZE=4096 CONFIG_IMXRT_EDMA=y +CONFIG_IMXRT_GPIO_IRQ=y CONFIG_IMXRT_LPUART1=y CONFIG_IMXRT_USBDEV=y CONFIG_INIT_ENTRYPOINT="nsh_main" CONFIG_INIT_STACKSIZE=8192 +CONFIG_INPUT=y +CONFIG_INPUT_BUTTONS=y +CONFIG_INPUT_BUTTONS_LOWER=y CONFIG_INTELHEX_BINARY=y CONFIG_LIBC_LOCALTIME=y CONFIG_LINE_MAX=64 diff --git a/boards/arm/imxrt/imxrt1180-evk/include/board.h b/boards/arm/imxrt/imxrt1180-evk/include/board.h index 0e215df29a3..1ef648dc8c9 100644 --- a/boards/arm/imxrt/imxrt1180-evk/include/board.h +++ b/boards/arm/imxrt/imxrt1180-evk/include/board.h @@ -127,4 +127,25 @@ #define GPIO_LPSPI1_MISO IOMUX_PIN(IOMUXC_PAD_GPIO_AON_07_LPSPI1_SDI, \ IOMUX_LPSPI_DEFAULT, IOMUXC_MUX_SION_ON) +/* Buttons ******************************************************************/ + +/* The MIMXRT1180-EVK has one general purpose user button, SW8 ("GPIO INT + * BUTTON"), on GPIO_AON_04 = RGPIO1.4. The button shorts the pin to GND + * when pressed. The external pull-up (R2154) is not fitted, so the + * internal pull-up is used. + */ + +#define BUTTON_SW8 0 +#define NUM_BUTTONS 1 + +#define BUTTON_SW8_BIT (1 << BUTTON_SW8) + +#define IOMUX_SW_DEFAULT (IOMUXC_PAD_PUE | IOMUXC_PAD_PUS) + +#define GPIO_SW8 (IOMUX_GPIO(IOMUXC_PAD_GPIO_AON_04_GPIO1_IO04, \ + IOMUX_SW_DEFAULT, \ + GPIO_INTERRUPT | \ + GPIO_PORT1 | GPIO_PIN4) | \ + GPIO_INTBOTH_EDGES) + #endif /* __BOARDS_ARM_IMXRT_IMXRT1180_EVK_INCLUDE_BOARD_H */ diff --git a/boards/arm/imxrt/imxrt1180-evk/src/Makefile b/boards/arm/imxrt/imxrt1180-evk/src/Makefile index 6903eb14fe9..b0a5d88de7e 100644 --- a/boards/arm/imxrt/imxrt1180-evk/src/Makefile +++ b/boards/arm/imxrt/imxrt1180-evk/src/Makefile @@ -42,6 +42,10 @@ ifeq ($(CONFIG_IMXRT1180_EVK_BOOTLOADER),y) CSRCS += imxrt_bootloader.c endif +ifeq ($(CONFIG_ARCH_BUTTONS),y) +CSRCS += imxrt_buttons.c +endif + ifeq ($(CONFIG_USBDEV_DMAMEMORY),y) CSRCS += imxrt_dma_alloc.c endif diff --git a/boards/arm/imxrt/imxrt1180-evk/src/imxrt_bringup.c b/boards/arm/imxrt/imxrt1180-evk/src/imxrt_bringup.c index 7ce286c2490..34b24c59512 100644 --- a/boards/arm/imxrt/imxrt1180-evk/src/imxrt_bringup.c +++ b/boards/arm/imxrt/imxrt1180-evk/src/imxrt_bringup.c @@ -31,6 +31,10 @@ #include <nuttx/fs/fs.h> +#ifdef CONFIG_INPUT_BUTTONS +# include <nuttx/input/buttons.h> +#endif + #include "imxrt1180-evk.h" /**************************************************************************** @@ -67,5 +71,13 @@ int imxrt_bringup(void) } #endif +#if defined(CONFIG_INPUT_BUTTONS) && defined(CONFIG_INPUT_BUTTONS_LOWER) + ret = btn_lower_initialize("/dev/buttons"); + if (ret < 0) + { + syslog(LOG_ERR, "ERROR: btn_lower_initialize() failed: %d\n", ret); + } +#endif + return ret; } diff --git a/boards/arm/imxrt/imxrt1180-evk/src/imxrt_buttons.c b/boards/arm/imxrt/imxrt1180-evk/src/imxrt_buttons.c new file mode 100644 index 00000000000..7c4f9ebb08a --- /dev/null +++ b/boards/arm/imxrt/imxrt1180-evk/src/imxrt_buttons.c @@ -0,0 +1,151 @@ +/**************************************************************************** + * boards/arm/imxrt/imxrt1180-evk/src/imxrt_buttons.c + * + * SPDX-License-Identifier: Apache-2.0 + * + * 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 <stdint.h> +#include <errno.h> + +#include <nuttx/arch.h> +#include <nuttx/board.h> +#include <nuttx/irq.h> +#include <arch/board/board.h> + +#include "imxrt_gpio.h" +#include "imxrt1180-evk.h" + +#ifdef CONFIG_ARCH_BUTTONS + +#if defined(CONFIG_ARCH_IRQBUTTONS) && !defined(CONFIG_IMXRT_GPIO_IRQ) +# error "CONFIG_ARCH_IRQBUTTONS requires CONFIG_IMXRT_GPIO_IRQ" +#endif + +/**************************************************************************** + * Private Data + ****************************************************************************/ + +static const gpio_pinset_t g_buttons[NUM_BUTTONS] = +{ + GPIO_SW8, +}; + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: board_button_initialize + * + * Description: + * Configure the button pins as interrupting inputs. The interrupts stay + * disabled until a handler is attached with board_button_irq(). + * + ****************************************************************************/ + +uint32_t board_button_initialize(void) +{ + int i; + + for (i = 0; i < NUM_BUTTONS; i++) + { + imxrt_config_gpio(g_buttons[i]); + } + + return NUM_BUTTONS; +} + +/**************************************************************************** + * Name: board_buttons + * + * Description: + * Return the current state of the buttons, one bit per button, set when + * the button is pressed. + * + ****************************************************************************/ + +uint32_t board_buttons(void) +{ + uint32_t ret = 0; + int i; + + for (i = 0; i < NUM_BUTTONS; i++) + { + /* The buttons are active low */ + + if (!imxrt_gpio_read(g_buttons[i])) + { + ret |= (1 << i); + } + } + + return ret; +} + +/**************************************************************************** + * Name: board_button_irq + * + * Description: + * Attach (irqhandler != NULL) or detach (irqhandler == NULL) an interrupt + * handler to a button. The interrupt fires on both edges, i.e. on press + * and on release. + * + ****************************************************************************/ + +#ifdef CONFIG_ARCH_IRQBUTTONS +int board_button_irq(int id, xcpt_t irqhandler, void *arg) +{ + gpio_pinset_t pinset; + int ret; + + if (id < 0 || id >= NUM_BUTTONS) + { + return -EINVAL; + } + + pinset = g_buttons[id]; + + if (irqhandler != NULL) + { + ret = imxrt_gpioirq_attach(pinset, irqhandler, arg); + if (ret == OK) + { + ret = imxrt_gpioirq_enable(pinset); + } + } + else + { + ret = imxrt_gpioirq_disable(pinset); + if (ret == OK) + { + ret = imxrt_gpioirq_attach(pinset, NULL, NULL); + } + } + + return ret; +} +#endif + +#endif /* CONFIG_ARCH_BUTTONS */
