This is an automated email from the ASF dual-hosted git repository.

linguini pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git

commit e274655d1c2e427c553cd6aee7d242c2416a566e
Author: raiden00pl <[email protected]>
AuthorDate: Sat Apr 11 14:27:40 2026 +0200

    boards/nrf5340-dk: add qencoder example
    
    add qencoder support and enable qe example for config
    
    Signed-off-by: raiden00pl <[email protected]>
---
 .../nrf5340-dk/configs/qencoder_cpuapp/defconfig   | 51 +++++++++++++++
 boards/arm/nrf53/nrf5340-dk/include/board.h        |  5 ++
 boards/arm/nrf53/nrf5340-dk/src/CMakeLists.txt     |  4 ++
 boards/arm/nrf53/nrf5340-dk/src/Make.defs          |  4 ++
 boards/arm/nrf53/nrf5340-dk/src/nrf5340-dk.h       | 12 ++++
 boards/arm/nrf53/nrf5340-dk/src/nrf53_bringup.c    |  8 +++
 boards/arm/nrf53/nrf5340-dk/src/nrf53_qencoder.c   | 76 ++++++++++++++++++++++
 7 files changed, 160 insertions(+)

diff --git a/boards/arm/nrf53/nrf5340-dk/configs/qencoder_cpuapp/defconfig 
b/boards/arm/nrf53/nrf5340-dk/configs/qencoder_cpuapp/defconfig
new file mode 100644
index 00000000000..b991e2e4a29
--- /dev/null
+++ b/boards/arm/nrf53/nrf5340-dk/configs/qencoder_cpuapp/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_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_CHIP="nrf53"
+CONFIG_ARCH_CHIP_NRF5340=y
+CONFIG_ARCH_CHIP_NRF5340_CPUAPP=y
+CONFIG_ARCH_CHIP_NRF53=y
+CONFIG_ARCH_STACKDUMP=y
+CONFIG_ARCH_STDARG_H=y
+CONFIG_BOARD_LOOPSPERMSEC=5500
+CONFIG_BUILTIN=y
+CONFIG_EXAMPLES_QENCODER=y
+CONFIG_EXAMPLES_QENCODER_HAVE_MAXPOS=y
+CONFIG_EXAMPLES_QENCODER_MAXPOS=32
+CONFIG_EXPERIMENTAL=y
+CONFIG_FAT_LCNAMES=y
+CONFIG_FAT_LFN=y
+CONFIG_FS_FAT=y
+CONFIG_INIT_ENTRYPOINT="nsh_main"
+CONFIG_LINE_MAX=64
+CONFIG_MM_REGIONS=2
+CONFIG_NRF53_QDEC0=y
+CONFIG_NRF53_UART0=y
+CONFIG_NSH_ARCHINIT=y
+CONFIG_NSH_BUILTIN_APPS=y
+CONFIG_NSH_FILEIOSIZE=512
+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_SENSORS=y
+CONFIG_SENSORS_QENCODER=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/nrf53/nrf5340-dk/include/board.h 
b/boards/arm/nrf53/nrf5340-dk/include/board.h
index 6b940111ed0..d0f924d99c5 100644
--- a/boards/arm/nrf53/nrf5340-dk/include/board.h
+++ b/boards/arm/nrf53/nrf5340-dk/include/board.h
@@ -179,4 +179,9 @@
 #define NRF53_QSPI0_IO3_PIN (GPIO_MCUSEL_PERIP | GPIO_OUTPUT | \
                              GPIO_PORT0 | GPIO_PIN(16))
 
+/* QDEC Pins ****************************************************************/
+
+#define BOARD_QDEC0_A_PIN            (GPIO_MCUSEL_APP | GPIO_INPUT | 
GPIO_PORT0 | GPIO_PIN(25))
+#define BOARD_QDEC0_B_PIN            (GPIO_MCUSEL_APP | GPIO_INPUT | 
GPIO_PORT0 | GPIO_PIN(26))
+
 #endif /* __BOARDS_ARM_NRF53_NRF5340_DK_INCLUDE_BOARD_H */
diff --git a/boards/arm/nrf53/nrf5340-dk/src/CMakeLists.txt 
b/boards/arm/nrf53/nrf5340-dk/src/CMakeLists.txt
index f65cbeda9c7..9955186065b 100644
--- a/boards/arm/nrf53/nrf5340-dk/src/CMakeLists.txt
+++ b/boards/arm/nrf53/nrf5340-dk/src/CMakeLists.txt
@@ -64,6 +64,10 @@ if(CONFIG_NRF53_QSPI)
   list(APPEND SRCS nrf53_mx25.c)
 endif()
 
+if(CONFIG_NRF53_QDEC)
+  list(APPEND SRCS nrf53_qencoder.c)
+endif()
+
 target_sources(board PRIVATE ${SRCS})
 
 if(CONFIG_ARCH_BOARD_COMMON)
diff --git a/boards/arm/nrf53/nrf5340-dk/src/Make.defs 
b/boards/arm/nrf53/nrf5340-dk/src/Make.defs
index 350dbb62cf6..7f9cc96e158 100644
--- a/boards/arm/nrf53/nrf5340-dk/src/Make.defs
+++ b/boards/arm/nrf53/nrf5340-dk/src/Make.defs
@@ -66,6 +66,10 @@ ifeq ($(CONFIG_NRF53_QSPI),y)
 CSRCS += nrf53_mx25.c
 endif
 
+ifeq ($(CONFIG_NRF53_QDEC),y)
+CSRCS += nrf53_qencoder.c
+endif
+
 DEPPATH += --dep-path board
 VPATH += :board
 CFLAGS += 
${INCDIR_PREFIX}$(TOPDIR)$(DELIM)arch$(DELIM)$(CONFIG_ARCH)$(DELIM)src$(DELIM)board$(DELIM)board
diff --git a/boards/arm/nrf53/nrf5340-dk/src/nrf5340-dk.h 
b/boards/arm/nrf53/nrf5340-dk/src/nrf5340-dk.h
index 8a714b4007c..637d953f767 100644
--- a/boards/arm/nrf53/nrf5340-dk/src/nrf5340-dk.h
+++ b/boards/arm/nrf53/nrf5340-dk/src/nrf5340-dk.h
@@ -164,5 +164,17 @@ int nrf53_mx25_initialize(void);
 int nrf53_gpio_initialize(void);
 #endif
 
+/****************************************************************************
+ * Name: nrf53_qencoder_initialize
+ *
+ * Description:
+ *   Initialize and register the qencoder driver
+ *
+ ****************************************************************************/
+
+#ifdef CONFIG_NRF53_QDEC
+int nrf53_qencoder_initialize(int devno);
+#endif
+
 #endif /* __ASSEMBLY__ */
 #endif /* __BOARDS_ARM_NRF53_NRF5340_DK_SRC_NRF5340_DK_H */
diff --git a/boards/arm/nrf53/nrf5340-dk/src/nrf53_bringup.c 
b/boards/arm/nrf53/nrf5340-dk/src/nrf53_bringup.c
index 03c64034c5e..ce25793893e 100644
--- a/boards/arm/nrf53/nrf5340-dk/src/nrf53_bringup.c
+++ b/boards/arm/nrf53/nrf5340-dk/src/nrf53_bringup.c
@@ -267,6 +267,14 @@ int nrf53_bringup(void)
     }
 #endif
 
+#ifdef CONFIG_NRF53_QDEC0
+  ret = nrf53_qencoder_initialize(0);
+  if (ret < 0)
+    {
+      syslog(LOG_ERR, "ERROR: Failed to initialize qencoder: %d\n", ret);
+    }
+#endif
+
 #ifdef CONFIG_USBMONITOR
   /* Start the USB Monitor */
 
diff --git a/boards/arm/nrf53/nrf5340-dk/src/nrf53_qencoder.c 
b/boards/arm/nrf53/nrf5340-dk/src/nrf53_qencoder.c
new file mode 100644
index 00000000000..178b8abc5a4
--- /dev/null
+++ b/boards/arm/nrf53/nrf5340-dk/src/nrf53_qencoder.c
@@ -0,0 +1,76 @@
+/****************************************************************************
+ * boards/arm/nrf53/nrf5340-dk/src/nrf53_qencoder.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 <errno.h>
+#include <debug.h>
+
+#include <nuttx/sensors/qencoder.h>
+
+#include "nrf53_qdec.h"
+
+/****************************************************************************
+ * Private Data
+ ****************************************************************************/
+
+static const struct nrf53_qeconfig_s g_qe0_config =
+{
+  .sample_period   = 0,
+  .report_period   = 0,
+  .enable_debounce = false,
+};
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+int nrf53_qencoder_initialize(int devno)
+{
+  struct qe_lowerhalf_s *lower;
+  char devpath[12];
+  int ret;
+
+  sninfo("Initializing /dev/qe%d\n", devno);
+
+  lower = nrf53_qeinitialize(devno, &g_qe0_config);
+  if (lower == NULL)
+    {
+      snerr("ERROR: nrf53_qeinitialize failed\n");
+      return -ENODEV;
+    }
+
+  snprintf(devpath, sizeof(devpath), "/dev/qe%d", devno);
+
+  ret = qe_register(devpath, lower);
+  if (ret < 0)
+    {
+      snerr("ERROR: qe_register failed: %d\n", ret);
+      return ret;
+    }
+
+  return OK;
+}

Reply via email to