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

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

commit 000bf2a7c7914e476fd5bafe6aa347b9b3cc39b1
Author: Tiago Medicci Serrano <[email protected]>
AuthorDate: Thu Dec 7 15:18:21 2023 -0300

    esp32s3/rmt: Use the Espressif's common RMT driver.
    
    This commit use the new common RMT driver for all Espressif's
    xtensa-based chips on ESP32-S3.
---
 .../esp32s3/common/include/esp32s3_board_rmt.h     |  97 +++++++++++++
 boards/xtensa/esp32s3/common/src/Make.defs         |   4 +
 .../xtensa/esp32s3/common/src/esp32s3_board_rmt.c  | 152 +++++++++++++++++++++
 boards/xtensa/esp32s3/esp32s3-devkit/Kconfig       |  11 ++
 .../esp32s3/esp32s3-devkit/configs/rmt/defconfig   |  58 ++++++++
 .../esp32s3/esp32s3-devkit/src/esp32s3-devkit.h    |  20 +++
 .../esp32s3/esp32s3-devkit/src/esp32s3_bringup.c   |  18 +++
 7 files changed, 360 insertions(+)

diff --git a/boards/xtensa/esp32s3/common/include/esp32s3_board_rmt.h 
b/boards/xtensa/esp32s3/common/include/esp32s3_board_rmt.h
new file mode 100644
index 0000000000..2acdc33768
--- /dev/null
+++ b/boards/xtensa/esp32s3/common/include/esp32s3_board_rmt.h
@@ -0,0 +1,97 @@
+/****************************************************************************
+ * boards/xtensa/esp32s3/common/include/esp32s3_board_rmt.h
+ *
+ * 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.
+ *
+ ****************************************************************************/
+
+#ifndef __BOARDS_XTENSA_ESP32S3_COMMON_INCLUDE_ESP32S3_BOARD_RMT_H
+#define __BOARDS_XTENSA_ESP32S3_COMMON_INCLUDE_ESP32S3_BOARD_RMT_H
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+#ifndef __ASSEMBLY__
+
+/****************************************************************************
+ * Public Data
+ ****************************************************************************/
+
+#undef EXTERN
+#if defined(__cplusplus)
+#define EXTERN extern "C"
+extern "C"
+{
+#else
+#define EXTERN extern
+#endif
+
+/****************************************************************************
+ * Public Function Prototypes
+ ****************************************************************************/
+
+#ifdef CONFIG_ESP_RMT
+
+/****************************************************************************
+ * Name: board_rmt_rxinitialize
+ *
+ * Description:
+ *   Initialize the RMT peripheral and register a RX device.
+ *
+ * Input Parameters:
+ *   ch  - the RMT's channel that will be used
+ *   pin - The pin used for the RX channel
+ *
+ * Returned Value:
+ *   Zero (OK) on success; a negated errno value on failure.
+ *
+ ****************************************************************************/
+
+int board_rmt_rxinitialize(int ch, int pin);
+
+/****************************************************************************
+ * Name: board_rmt_txinitialize
+ *
+ * Description:
+ *   Initialize the RMT peripheral and register a TX device.
+ *
+ * Input Parameters:
+ *   ch  - the RMT's channel that will be used
+ *   pin - The pin used for the TX channel
+ *
+ * Returned Value:
+ *   Zero (OK) on success; a negated errno value on failure.
+ *
+ ****************************************************************************/
+
+int board_rmt_txinitialize(int ch, int pin);
+
+#endif /* CONFIG_ESP_RMT */
+
+#undef EXTERN
+#if defined(__cplusplus)
+}
+#endif
+
+#endif /* __ASSEMBLY__ */
+#endif /* __BOARDS_XTENSA_ESP32S3_COMMON_INCLUDE_ESP32S3_BOARD_RMT_H */
diff --git a/boards/xtensa/esp32s3/common/src/Make.defs 
b/boards/xtensa/esp32s3/common/src/Make.defs
index dbb2b82ca5..68c7f067e1 100644
--- a/boards/xtensa/esp32s3/common/src/Make.defs
+++ b/boards/xtensa/esp32s3/common/src/Make.defs
@@ -60,6 +60,10 @@ ifeq ($(CONFIG_NET_LAN9250),y)
   CSRCS += esp32s3_lan9250.c
 endif
 
+ifeq ($(CONFIG_ESP_RMT),y)
+  CSRCS += esp32s3_board_rmt.c
+endif
+
 DEPPATH += --dep-path src
 VPATH += :src
 CFLAGS += 
${INCDIR_PREFIX}$(TOPDIR)$(DELIM)arch$(DELIM)$(CONFIG_ARCH)$(DELIM)src$(DELIM)board$(DELIM)src
diff --git a/boards/xtensa/esp32s3/common/src/esp32s3_board_rmt.c 
b/boards/xtensa/esp32s3/common/src/esp32s3_board_rmt.c
new file mode 100644
index 0000000000..a3d178105e
--- /dev/null
+++ b/boards/xtensa/esp32s3/common/src/esp32s3_board_rmt.c
@@ -0,0 +1,152 @@
+/****************************************************************************
+ * boards/xtensa/esp32s3/common/src/esp32s3_board_rmt.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 <errno.h>
+#include <debug.h>
+#include <stdio.h>
+
+#include "xtensa.h"
+
+#include <nuttx/kmalloc.h>
+#include <nuttx/rmt/rmtchar.h>
+#ifdef CONFIG_WS2812_NON_SPI_DRIVER
+#include <nuttx/leds/ws2812.h>
+
+#include "espressif/esp_ws2812.h"
+#endif
+
+#include "espressif/esp_rmt.h"
+
+#ifdef CONFIG_ESP_RMT
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Private Types
+ ****************************************************************************/
+
+/****************************************************************************
+ * Private Function Prototypes
+ ****************************************************************************/
+
+/****************************************************************************
+ * Private Data
+ ****************************************************************************/
+
+/****************************************************************************
+ * Public Data
+ ****************************************************************************/
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: board_rmt_rxinitialize
+ *
+ * Description:
+ *   Initialize the RMT peripheral and register a RX device.
+ *
+ * Input Parameters:
+ *   ch  - the RMT's channel that will be used
+ *   pin - The pin used for the RX channel
+ *
+ * Returned Value:
+ *   Zero (OK) on success; a negated errno value on failure.
+ *
+ ****************************************************************************/
+
+int board_rmt_rxinitialize(int ch, int pin)
+{
+  int ret;
+
+  struct rmt_dev_s *rmt = esp_rmt_rx_init(ch, pin);
+
+  ret = rmtchar_register(rmt);
+  if (ret < 0)
+    {
+      rmterr("ERROR: rmtchar_register failed: %d\n", ret);
+      return ret;
+    }
+
+  return ret;
+}
+
+/****************************************************************************
+ * Name: board_rmt_txinitialize
+ *
+ * Description:
+ *   Initialize the RMT peripheral and register a TX device.
+ *
+ * Input Parameters:
+ *   ch  - the RMT's channel that will be used
+ *   pin - The pin used for the TX channel
+ *
+ * Returned Value:
+ *   Zero (OK) on success; a negated errno value on failure.
+ *
+ ****************************************************************************/
+
+int board_rmt_txinitialize(int ch, int pin)
+{
+  int ret;
+  struct rmt_dev_s *rmt;
+#ifdef CONFIG_WS2812_NON_SPI_DRIVER
+  struct ws2812_dev_s *led;
+#endif
+
+  rmt = esp_rmt_tx_init(ch, pin);
+  if (rmt == NULL)
+    {
+      rmterr("ERROR: esp_rmt_tx_init failed\n");
+      return -ENODEV;
+    }
+
+  ret = rmtchar_register(rmt);
+  if (ret < 0)
+    {
+      rmterr("ERROR: rmtchar_register failed: %d\n", ret);
+      return ret;
+    }
+
+#ifdef CONFIG_WS2812_NON_SPI_DRIVER
+  led = esp_ws2812_setup("/dev/leds0", rmt, CONFIG_WS2812_LED_COUNT, false);
+  if (led == NULL)
+    {
+      rmterr("ERROR: esp_ws2812_setup failed\n");
+      return -ENODEV;
+    }
+#endif
+
+  return ret;
+}
+#endif
diff --git a/boards/xtensa/esp32s3/esp32s3-devkit/Kconfig 
b/boards/xtensa/esp32s3/esp32s3-devkit/Kconfig
index 70f655aec2..d08044077b 100644
--- a/boards/xtensa/esp32s3/esp32s3-devkit/Kconfig
+++ b/boards/xtensa/esp32s3/esp32s3-devkit/Kconfig
@@ -5,6 +5,17 @@
 
 if ARCH_BOARD_ESP32S3_DEVKIT
 
+choice
+       prompt "ESP32-S3-DevKitC-1 version"
+       default ESP32S3_DEVKITC_1_V10
+
+config ESP32S3_DEVKITC_1_V10
+       bool "ESP32-S3-DevKitC-1 v1.0"
+
+config ESP32S3_DEVKITC_1_V11
+       bool "ESP32-S3-DevKitC-1 v1.1"
+endchoice
+
 config ESP32S3_STORAGE_MTD_OFFSET
        hex "Storage MTD base address in SPI Flash"
        default 0x180000 if !ESP32S3_HAVE_OTA_PARTITION
diff --git a/boards/xtensa/esp32s3/esp32s3-devkit/configs/rmt/defconfig 
b/boards/xtensa/esp32s3/esp32s3-devkit/configs/rmt/defconfig
new file mode 100644
index 0000000000..20eebbea88
--- /dev/null
+++ b/boards/xtensa/esp32s3/esp32s3-devkit/configs/rmt/defconfig
@@ -0,0 +1,58 @@
+#
+# 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_LEDS is not set
+# CONFIG_ASSERTIONS_FILENAME is not set
+# CONFIG_NDEBUG is not set
+# CONFIG_NSH_ARGCAT is not set
+# CONFIG_NSH_CMDOPT_HEXDUMP is not set
+CONFIG_ARCH="xtensa"
+CONFIG_ARCH_BOARD="esp32s3-devkit"
+CONFIG_ARCH_BOARD_COMMON=y
+CONFIG_ARCH_BOARD_ESP32S3_DEVKIT=y
+CONFIG_ARCH_CHIP="esp32s3"
+CONFIG_ARCH_CHIP_ESP32S3=y
+CONFIG_ARCH_CHIP_ESP32S3WROOM1=y
+CONFIG_ARCH_INTERRUPTSTACK=2048
+CONFIG_ARCH_STACKDUMP=y
+CONFIG_ARCH_XTENSA=y
+CONFIG_BOARD_LOOPSPERMSEC=16717
+CONFIG_BUILTIN=y
+CONFIG_ESP32S3_UART0=y
+CONFIG_ESP_RMT=y
+CONFIG_EXAMPLES_RMTCHAR=y
+CONFIG_EXAMPLES_RMTCHAR_RX=y
+CONFIG_EXAMPLES_RMTCHAR_TX=y
+CONFIG_EXAMPLES_WS2812=y
+CONFIG_FS_PROCFS=y
+CONFIG_HAVE_CXX=y
+CONFIG_HAVE_CXXINITIALIZE=y
+CONFIG_IDLETHREAD_STACKSIZE=3072
+CONFIG_INIT_ENTRYPOINT="nsh_main"
+CONFIG_INTELHEX_BINARY=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=114688
+CONFIG_RAM_START=0x20000000
+CONFIG_RMT=y
+CONFIG_RMTCHAR=y
+CONFIG_RMT_DEFAULT_RX_BUFFER_SIZE=256
+CONFIG_RR_INTERVAL=200
+CONFIG_SCHED_WAITPID=y
+CONFIG_START_DAY=6
+CONFIG_START_MONTH=12
+CONFIG_START_YEAR=2011
+CONFIG_SYSLOG_BUFFER=y
+CONFIG_SYSTEM_NSH=y
+CONFIG_UART0_SERIAL_CONSOLE=y
+CONFIG_WS2812=y
+CONFIG_WS2812_LED_COUNT=100
+CONFIG_WS2812_NON_SPI_DRIVER=y
diff --git a/boards/xtensa/esp32s3/esp32s3-devkit/src/esp32s3-devkit.h 
b/boards/xtensa/esp32s3/esp32s3-devkit/src/esp32s3-devkit.h
index 215a69468a..5284a52faf 100644
--- a/boards/xtensa/esp32s3/esp32s3-devkit/src/esp32s3-devkit.h
+++ b/boards/xtensa/esp32s3/esp32s3-devkit/src/esp32s3-devkit.h
@@ -44,6 +44,26 @@
 
 #define BUTTON_BOOT  0
 
+/* RMT gpio */
+
+#define RMT_RXCHANNEL       4
+#define RMT_TXCHANNEL       0
+
+#ifdef CONFIG_RMT_LOOP_TEST_MODE
+#  define RMT_INPUT_PIN       0
+#  define RMT_OUTPUT_PIN      0
+#else
+#  define RMT_INPUT_PIN       2
+
+/* The on-board RGB LED pin differs depending on the board version */
+
+#  ifdef CONFIG_ESP32S3_DEVKITC_1_V10
+#    define RMT_OUTPUT_PIN      48
+#  else
+#    define RMT_OUTPUT_PIN      38
+#  endif
+#endif
+
 /****************************************************************************
  * Public Types
  ****************************************************************************/
diff --git a/boards/xtensa/esp32s3/esp32s3-devkit/src/esp32s3_bringup.c 
b/boards/xtensa/esp32s3/esp32s3-devkit/src/esp32s3_bringup.c
index fca474d130..bdeca8b1af 100644
--- a/boards/xtensa/esp32s3/esp32s3-devkit/src/esp32s3_bringup.c
+++ b/boards/xtensa/esp32s3/esp32s3-devkit/src/esp32s3_bringup.c
@@ -96,6 +96,10 @@
 #  include "esp32s3_partition.h"
 #endif
 
+#ifdef CONFIG_ESP_RMT
+#  include "esp32s3_board_rmt.h"
+#endif
+
 #include "esp32s3-devkit.h"
 
 /****************************************************************************
@@ -206,6 +210,20 @@ int esp32s3_bringup(void)
     }
 #endif
 
+#ifdef CONFIG_ESP_RMT
+  ret = board_rmt_txinitialize(RMT_TXCHANNEL, RMT_OUTPUT_PIN);
+  if (ret < 0)
+    {
+      syslog(LOG_ERR, "ERROR: board_rmt_txinitialize() failed: %d\n", ret);
+    }
+
+  ret = board_rmt_rxinitialize(RMT_RXCHANNEL, RMT_INPUT_PIN);
+  if (ret < 0)
+    {
+      syslog(LOG_ERR, "ERROR: board_rmt_txinitialize() failed: %d\n", ret);
+    }
+#endif
+
 #ifdef CONFIG_RTC_DRIVER
   /* Instantiate the ESP32-S3 RTC driver */
 

Reply via email to