acassis commented on code in PR #15852:
URL: https://github.com/apache/nuttx/pull/15852#discussion_r1958679911


##########
arch/risc-v/src/common/espressif/Kconfig:
##########
@@ -1647,6 +1660,125 @@ endif # PWM_MULTICHAN && PWM_NCHANNELS > 1
 
 endmenu # LEDC configuration
 
+menu "I2S Configuration"
+       depends on ESPRESSIF_I2S
+
+config ESPRESSIF_I2S_MAXINFLIGHT
+       int "I2S queue size"
+       default 4
+       ---help---
+               This is the total number of transfers, both RX and TX, that can 
be
+               enqueued before the caller is required to wait.  This setting
+               determines the number certain queue data structures that will be
+               pre-allocated.
+
+if ESPRESSIF_I2S0
+
+config ESPRESSIF_I2S0_RX
+       bool "Enable I2S receiver"
+       default y
+       ---help---
+               Enable I2S receiver (port 0)
+
+config ESPRESSIF_I2S0_TX
+       bool "Enable I2S transmitter"
+       default y
+       ---help---
+               Enable I2S transmitter (port 0)
+
+choice ESPRESSIF_I2S0_ROLE
+       prompt "I2S0 role"
+       default ESPRESSIF_I2S0_ROLE_MASTER
+       ---help---
+               Selects the operation role of the I2S0.
+
+config ESPRESSIF_I2S0_ROLE_MASTER
+       bool "Master"
+
+config ESPRESSIF_I2S0_ROLE_SLAVE
+       bool "Slave"
+
+endchoice # I2S0 role
+
+choice ESPRESSIF_I2S0_DATA_BIT_WIDTH
+       prompt "Bit width"
+       default ESPRESSIF_I2S0_DATA_BIT_WIDTH_16BIT
+       ---help---
+               Selects the valid data bits per sample.
+               Note that this option may be overwritten by the audio
+               according to the bit width of the file being played
+
+config ESPRESSIF_I2S0_DATA_BIT_WIDTH_8BIT
+       bool "8 bits"
+
+config ESPRESSIF_I2S0_DATA_BIT_WIDTH_16BIT
+       bool "16 bits"
+
+config ESPRESSIF_I2S0_DATA_BIT_WIDTH_24BIT
+       bool "24 bits"
+
+config ESPRESSIF_I2S0_DATA_BIT_WIDTH_32BIT
+       bool "32 bits"
+
+endchoice # Bit width
+
+config ESPRESSIF_I2S0_SAMPLE_RATE
+       int "I2S0 sample rate"
+       default 44100
+       range 8000 48000
+       ---help---
+               Selects the sample rate.
+               Note that this option may be overwritten by the audio
+               according to the bit width of the file being played
+
+config ESPRESSIF_I2S0_BCLKPIN
+       int "I2S0 BCLK pin"
+       default 4
+       range 0 48
+
+config ESPRESSIF_I2S0_WSPIN
+       int "I2S0 WS pin"
+       default 5
+       range 0 48
+
+config ESPRESSIF_I2S0_DINPIN
+       int "I2S0 DIN pin"
+       depends on ESPRESSIF_I2S0_RX
+       default 19 if !ESPRESSIF_ESP32H2
+       default 11 if ESPRESSIF_ESP32H2
+       range 0 48
+
+config ESPRESSIF_I2S0_DOUTPIN
+       int "I2S0 DOUT pin"
+       depends on ESPRESSIF_I2S0_TX
+       default 18 if !ESPRESSIF_ESP32H2
+       default 10 if ESPRESSIF_ESP32H2
+       range 0 48
+
+config ESPRESSIF_I2S0_MCLK
+       bool "Enable I2S Master Clock"
+       depends on ESPRESSIF_I2S0_ROLE_MASTER
+       default n
+       ---help---
+               Enable I2S master clock
+
+config ESPRESSIF_I2S0_MCLKPIN
+       int "I2S MCLK pin"
+       depends on ESPRESSIF_I2S0_MCLK
+       default 0
+       range 0 48
+
+endif # ESPRESSIF_I2S0
+
+config I2S_DMADESC_NUM
+       int "I2S DMA maximum number of descriptors"
+       default 2
+       ---help---
+               Configure the maximum number of out-link/in-link descriptors to
+               be chained for a I2S DMA transfer.

Review Comment:
   ```suggestion
                be chained for an I2S DMA transfer.



##########
boards/risc-v/esp32h2/common/src/esp_board_i2s.c:
##########
@@ -0,0 +1,204 @@
+/****************************************************************************
+ * boards/risc-v/esp32h2/common/src/esp_board_i2s.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 <debug.h>
+#include <errno.h>
+#include <sys/types.h>
+#include <stdio.h>
+
+#include <nuttx/audio/audio.h>
+#include <nuttx/audio/audio_i2s.h>
+#include <nuttx/audio/i2s.h>
+#include <nuttx/audio/pcm.h>
+
+#include <arch/board/board.h>
+
+#include "espressif/esp_i2s.h"
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: board_i2sdev_initialize
+ *
+ * Description:
+ *   This function is called by platform-specific, setup logic to configure
+ *   and register the generic I2S audio driver.  This function will register
+ *   the driver as /dev/audio/pcm[x] where x is determined by the I2S port
+ *   number.
+ *
+ * Input Parameters:
+ *   port       - The I2S port used for the device
+ *   enable_tx  - Register device as TX if true
+ *   enable_rx  - Register device as RX if true
+ *
+ * Returned Value:
+ *   Zero is returned on success.  Otherwise, a negated errno value is
+ *   returned to indicate the nature of the failure.
+ *
+ ****************************************************************************/
+
+int board_i2sdev_initialize(int port, bool enable_tx, bool enable_rx)
+{
+  struct audio_lowerhalf_s *audio_i2s;
+  struct i2s_dev_s *i2s;
+  char devname[8];
+  int ret;
+
+  audinfo("Initializing I2S\n");
+
+  i2s = esp_i2sbus_initialize(port);
+
+#ifdef CONFIG_AUDIO_I2SCHAR
+  ret = i2schar_register(i2s, port);
+  if (ret < 0)
+    {
+      aerr("ERROR: i2schar_register failed: %d\n", ret);
+      return ret;
+    }
+#endif
+
+  if (enable_tx)
+    {
+      /* Initialize audio output */
+
+      audio_i2s = audio_i2s_initialize(i2s, true);
+
+      if (audio_i2s == NULL)
+        {
+          auderr("ERROR: Failed to initialize I2S audio output\n");
+          return -ENODEV;
+        }
+
+      snprintf(devname, sizeof(devname), "pcm%d", port);
+
+      /* If nxlooper is selected, the playback buffer is not rendered as
+       * a WAV file. Therefore, PCM decode will fail while processing such
+       * output buffer. In such a case, we bypass the PCM decode.
+       */
+
+#ifdef CONFIG_SYSTEM_NXLOOPER
+      ret = audio_register(devname, audio_i2s);
+#else
+      struct audio_lowerhalf_s *pcm;
+
+      pcm = pcm_decode_initialize(audio_i2s);
+
+      if (pcm == NULL)
+        {
+          auderr("ERROR: Failed create the PCM decoder\n");
+          return -ENODEV;
+        }
+
+      ret = audio_register(devname, pcm);
+#endif /* CONFIG_SYSTEM_NXLOOPER */
+
+      if (ret < 0)
+        {
+          auderr("ERROR: Failed to register /dev/%s device: %d\n",
+                 devname, ret);
+          return ret;
+        }
+    }
+
+  if (enable_rx)
+    {
+      /* Initialize audio input */
+
+      audio_i2s = audio_i2s_initialize(i2s, false);
+
+      if (audio_i2s == NULL)
+        {
+          auderr("ERROR: Failed to initialize I2S audio input\n");
+          return -ENODEV;
+        }
+
+      snprintf(devname, sizeof(devname), "pcm_in%d", port);
+
+      ret = audio_register(devname, audio_i2s);
+

Review Comment:
   Please remove empty line



##########
boards/risc-v/esp32c6/esp32c6-devkitc/src/esp32c6_bringup.c:
##########
@@ -270,6 +274,17 @@ int esp_bringup(void)
     }
 #endif
 
+#if defined(CONFIG_ESPRESSIF_I2S)
+  /* Configure I2S peripheral interfaces */
+
+  ret = board_i2s_init();
+

Review Comment:
   please remove empty line



##########
boards/risc-v/esp32c3/common/src/esp_board_i2s.c:
##########
@@ -0,0 +1,204 @@
+/****************************************************************************
+ * boards/risc-v/esp32c3/common/src/esp_board_i2s.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 <debug.h>
+#include <errno.h>
+#include <sys/types.h>
+#include <stdio.h>
+
+#include <nuttx/audio/audio.h>
+#include <nuttx/audio/audio_i2s.h>
+#include <nuttx/audio/i2s.h>
+#include <nuttx/audio/pcm.h>
+
+#include <arch/board/board.h>
+
+#include "espressif/esp_i2s.h"
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: board_i2sdev_initialize
+ *
+ * Description:
+ *   This function is called by platform-specific, setup logic to configure
+ *   and register the generic I2S audio driver.  This function will register
+ *   the driver as /dev/audio/pcm[x] where x is determined by the I2S port
+ *   number.
+ *
+ * Input Parameters:
+ *   port       - The I2S port used for the device
+ *   enable_tx  - Register device as TX if true
+ *   enable_rx  - Register device as RX if true
+ *
+ * Returned Value:
+ *   Zero is returned on success.  Otherwise, a negated errno value is
+ *   returned to indicate the nature of the failure.
+ *
+ ****************************************************************************/
+
+int board_i2sdev_initialize(int port, bool enable_tx, bool enable_rx)
+{
+  struct audio_lowerhalf_s *audio_i2s;
+  struct i2s_dev_s *i2s;
+  char devname[8];
+  int ret;
+
+  audinfo("Initializing I2S\n");
+
+  i2s = esp_i2sbus_initialize(port);
+
+#ifdef CONFIG_AUDIO_I2SCHAR
+  ret = i2schar_register(i2s, port);
+  if (ret < 0)
+    {
+      aerr("ERROR: i2schar_register failed: %d\n", ret);
+      return ret;
+    }
+#endif
+
+  if (enable_tx)
+    {
+      /* Initialize audio output */
+
+      audio_i2s = audio_i2s_initialize(i2s, true);
+
+      if (audio_i2s == NULL)
+        {
+          auderr("ERROR: Failed to initialize I2S audio output\n");
+          return -ENODEV;
+        }
+
+      snprintf(devname, sizeof(devname), "pcm%d", port);
+
+      /* If nxlooper is selected, the playback buffer is not rendered as
+       * a WAV file. Therefore, PCM decode will fail while processing such
+       * output buffer. In such a case, we bypass the PCM decode.
+       */
+
+#ifdef CONFIG_SYSTEM_NXLOOPER
+      ret = audio_register(devname, audio_i2s);
+#else
+      struct audio_lowerhalf_s *pcm;
+
+      pcm = pcm_decode_initialize(audio_i2s);
+
+      if (pcm == NULL)
+        {
+          auderr("ERROR: Failed create the PCM decoder\n");
+          return -ENODEV;
+        }
+
+      ret = audio_register(devname, pcm);
+#endif /* CONFIG_SYSTEM_NXLOOPER */
+
+      if (ret < 0)
+        {
+          auderr("ERROR: Failed to register /dev/%s device: %d\n",
+                 devname, ret);
+          return ret;
+        }
+    }
+
+  if (enable_rx)
+    {
+      /* Initialize audio input */
+
+      audio_i2s = audio_i2s_initialize(i2s, false);
+
+      if (audio_i2s == NULL)
+        {
+          auderr("ERROR: Failed to initialize I2S audio input\n");
+          return -ENODEV;
+        }
+
+      snprintf(devname, sizeof(devname), "pcm_in%d", port);
+
+      ret = audio_register(devname, audio_i2s);
+

Review Comment:
   please remove empty line



##########
boards/risc-v/esp32h2/common/src/esp_board_i2s.c:
##########
@@ -0,0 +1,204 @@
+/****************************************************************************
+ * boards/risc-v/esp32h2/common/src/esp_board_i2s.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 <debug.h>
+#include <errno.h>
+#include <sys/types.h>
+#include <stdio.h>
+
+#include <nuttx/audio/audio.h>
+#include <nuttx/audio/audio_i2s.h>
+#include <nuttx/audio/i2s.h>
+#include <nuttx/audio/pcm.h>
+
+#include <arch/board/board.h>
+
+#include "espressif/esp_i2s.h"
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: board_i2sdev_initialize
+ *
+ * Description:
+ *   This function is called by platform-specific, setup logic to configure
+ *   and register the generic I2S audio driver.  This function will register
+ *   the driver as /dev/audio/pcm[x] where x is determined by the I2S port
+ *   number.
+ *
+ * Input Parameters:
+ *   port       - The I2S port used for the device
+ *   enable_tx  - Register device as TX if true
+ *   enable_rx  - Register device as RX if true
+ *
+ * Returned Value:
+ *   Zero is returned on success.  Otherwise, a negated errno value is
+ *   returned to indicate the nature of the failure.
+ *
+ ****************************************************************************/
+
+int board_i2sdev_initialize(int port, bool enable_tx, bool enable_rx)
+{
+  struct audio_lowerhalf_s *audio_i2s;
+  struct i2s_dev_s *i2s;
+  char devname[8];
+  int ret;
+
+  audinfo("Initializing I2S\n");
+
+  i2s = esp_i2sbus_initialize(port);
+
+#ifdef CONFIG_AUDIO_I2SCHAR
+  ret = i2schar_register(i2s, port);
+  if (ret < 0)
+    {
+      aerr("ERROR: i2schar_register failed: %d\n", ret);
+      return ret;
+    }
+#endif
+
+  if (enable_tx)
+    {
+      /* Initialize audio output */
+
+      audio_i2s = audio_i2s_initialize(i2s, true);
+

Review Comment:
   please remove empty line



##########
boards/risc-v/esp32h2/esp32h2-devkit/src/esp32h2_bringup.c:
##########
@@ -264,6 +268,17 @@ int esp_bringup(void)
     }
 #endif
 
+#if defined(CONFIG_ESPRESSIF_I2S)
+  /* Configure I2S peripheral interfaces */
+
+  ret = board_i2s_init();
+

Review Comment:
   please remove empty line



##########
boards/risc-v/esp32c6/common/src/esp_board_i2s.c:
##########
@@ -0,0 +1,204 @@
+/****************************************************************************
+ * boards/risc-v/esp32c6/common/src/esp_board_i2s.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 <debug.h>
+#include <errno.h>
+#include <sys/types.h>
+#include <stdio.h>
+
+#include <nuttx/audio/audio.h>
+#include <nuttx/audio/audio_i2s.h>
+#include <nuttx/audio/i2s.h>
+#include <nuttx/audio/pcm.h>
+
+#include <arch/board/board.h>
+
+#include "espressif/esp_i2s.h"
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: board_i2sdev_initialize
+ *
+ * Description:
+ *   This function is called by platform-specific, setup logic to configure
+ *   and register the generic I2S audio driver.  This function will register
+ *   the driver as /dev/audio/pcm[x] where x is determined by the I2S port
+ *   number.
+ *
+ * Input Parameters:
+ *   port       - The I2S port used for the device
+ *   enable_tx  - Register device as TX if true
+ *   enable_rx  - Register device as RX if true
+ *
+ * Returned Value:
+ *   Zero is returned on success.  Otherwise, a negated errno value is
+ *   returned to indicate the nature of the failure.
+ *
+ ****************************************************************************/
+
+int board_i2sdev_initialize(int port, bool enable_tx, bool enable_rx)
+{
+  struct audio_lowerhalf_s *audio_i2s;
+  struct i2s_dev_s *i2s;
+  char devname[8];
+  int ret;
+
+  audinfo("Initializing I2S\n");
+
+  i2s = esp_i2sbus_initialize(port);
+
+#ifdef CONFIG_AUDIO_I2SCHAR
+  ret = i2schar_register(i2s, port);
+  if (ret < 0)
+    {
+      aerr("ERROR: i2schar_register failed: %d\n", ret);
+      return ret;
+    }
+#endif
+
+  if (enable_tx)
+    {
+      /* Initialize audio output */
+
+      audio_i2s = audio_i2s_initialize(i2s, true);
+

Review Comment:
   please remove empty line, they are part of same logic, testing the returned 
variable



##########
boards/risc-v/esp32c6/esp32c6-devkitm/src/esp32c6_bringup.c:
##########
@@ -266,6 +270,17 @@ int esp_bringup(void)
     }
 #endif
 
+#if defined(CONFIG_ESPRESSIF_I2S)
+  /* Configure I2S peripheral interfaces */
+
+  ret = board_i2s_init();
+

Review Comment:
   please remove empty line



##########
boards/risc-v/esp32c3/esp32c3-generic/src/esp32c3_bringup.c:
##########
@@ -317,6 +321,17 @@ int esp_bringup(void)
     }
 #endif
 
+#if defined(CONFIG_ESPRESSIF_I2S)
+  /* Configure I2S peripheral interfaces */
+
+  ret = board_i2s_init();
+

Review Comment:
   please remove empty line



##########
boards/risc-v/esp32c6/common/src/esp_board_i2s.c:
##########
@@ -0,0 +1,204 @@
+/****************************************************************************
+ * boards/risc-v/esp32c6/common/src/esp_board_i2s.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 <debug.h>
+#include <errno.h>
+#include <sys/types.h>
+#include <stdio.h>
+
+#include <nuttx/audio/audio.h>
+#include <nuttx/audio/audio_i2s.h>
+#include <nuttx/audio/i2s.h>
+#include <nuttx/audio/pcm.h>
+
+#include <arch/board/board.h>
+
+#include "espressif/esp_i2s.h"
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: board_i2sdev_initialize
+ *
+ * Description:
+ *   This function is called by platform-specific, setup logic to configure
+ *   and register the generic I2S audio driver.  This function will register
+ *   the driver as /dev/audio/pcm[x] where x is determined by the I2S port
+ *   number.
+ *
+ * Input Parameters:
+ *   port       - The I2S port used for the device
+ *   enable_tx  - Register device as TX if true
+ *   enable_rx  - Register device as RX if true
+ *
+ * Returned Value:
+ *   Zero is returned on success.  Otherwise, a negated errno value is
+ *   returned to indicate the nature of the failure.
+ *
+ ****************************************************************************/
+
+int board_i2sdev_initialize(int port, bool enable_tx, bool enable_rx)
+{
+  struct audio_lowerhalf_s *audio_i2s;
+  struct i2s_dev_s *i2s;
+  char devname[8];
+  int ret;
+
+  audinfo("Initializing I2S\n");
+
+  i2s = esp_i2sbus_initialize(port);
+
+#ifdef CONFIG_AUDIO_I2SCHAR
+  ret = i2schar_register(i2s, port);
+  if (ret < 0)
+    {
+      aerr("ERROR: i2schar_register failed: %d\n", ret);
+      return ret;
+    }
+#endif
+
+  if (enable_tx)
+    {
+      /* Initialize audio output */
+
+      audio_i2s = audio_i2s_initialize(i2s, true);
+
+      if (audio_i2s == NULL)
+        {
+          auderr("ERROR: Failed to initialize I2S audio output\n");
+          return -ENODEV;
+        }
+
+      snprintf(devname, sizeof(devname), "pcm%d", port);
+
+      /* If nxlooper is selected, the playback buffer is not rendered as
+       * a WAV file. Therefore, PCM decode will fail while processing such
+       * output buffer. In such a case, we bypass the PCM decode.
+       */
+
+#ifdef CONFIG_SYSTEM_NXLOOPER
+      ret = audio_register(devname, audio_i2s);
+#else
+      struct audio_lowerhalf_s *pcm;
+
+      pcm = pcm_decode_initialize(audio_i2s);
+
+      if (pcm == NULL)
+        {
+          auderr("ERROR: Failed create the PCM decoder\n");
+          return -ENODEV;
+        }
+
+      ret = audio_register(devname, pcm);
+#endif /* CONFIG_SYSTEM_NXLOOPER */
+
+      if (ret < 0)
+        {
+          auderr("ERROR: Failed to register /dev/%s device: %d\n",
+                 devname, ret);
+          return ret;
+        }
+    }
+
+  if (enable_rx)
+    {
+      /* Initialize audio input */
+
+      audio_i2s = audio_i2s_initialize(i2s, false);
+
+      if (audio_i2s == NULL)
+        {
+          auderr("ERROR: Failed to initialize I2S audio input\n");
+          return -ENODEV;
+        }
+
+      snprintf(devname, sizeof(devname), "pcm_in%d", port);
+
+      ret = audio_register(devname, audio_i2s);
+

Review Comment:
   please remove empty line



##########
boards/risc-v/esp32c3/common/src/esp_board_i2s.c:
##########
@@ -0,0 +1,204 @@
+/****************************************************************************
+ * boards/risc-v/esp32c3/common/src/esp_board_i2s.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 <debug.h>
+#include <errno.h>
+#include <sys/types.h>
+#include <stdio.h>
+
+#include <nuttx/audio/audio.h>
+#include <nuttx/audio/audio_i2s.h>
+#include <nuttx/audio/i2s.h>
+#include <nuttx/audio/pcm.h>
+
+#include <arch/board/board.h>
+
+#include "espressif/esp_i2s.h"
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: board_i2sdev_initialize
+ *
+ * Description:
+ *   This function is called by platform-specific, setup logic to configure
+ *   and register the generic I2S audio driver.  This function will register
+ *   the driver as /dev/audio/pcm[x] where x is determined by the I2S port
+ *   number.
+ *
+ * Input Parameters:
+ *   port       - The I2S port used for the device
+ *   enable_tx  - Register device as TX if true
+ *   enable_rx  - Register device as RX if true
+ *
+ * Returned Value:
+ *   Zero is returned on success.  Otherwise, a negated errno value is
+ *   returned to indicate the nature of the failure.
+ *
+ ****************************************************************************/
+
+int board_i2sdev_initialize(int port, bool enable_tx, bool enable_rx)
+{
+  struct audio_lowerhalf_s *audio_i2s;
+  struct i2s_dev_s *i2s;
+  char devname[8];
+  int ret;
+
+  audinfo("Initializing I2S\n");
+
+  i2s = esp_i2sbus_initialize(port);
+
+#ifdef CONFIG_AUDIO_I2SCHAR
+  ret = i2schar_register(i2s, port);
+  if (ret < 0)
+    {
+      aerr("ERROR: i2schar_register failed: %d\n", ret);
+      return ret;
+    }
+#endif
+
+  if (enable_tx)
+    {
+      /* Initialize audio output */
+
+      audio_i2s = audio_i2s_initialize(i2s, true);
+
+      if (audio_i2s == NULL)
+        {
+          auderr("ERROR: Failed to initialize I2S audio output\n");
+          return -ENODEV;
+        }
+
+      snprintf(devname, sizeof(devname), "pcm%d", port);
+
+      /* If nxlooper is selected, the playback buffer is not rendered as
+       * a WAV file. Therefore, PCM decode will fail while processing such
+       * output buffer. In such a case, we bypass the PCM decode.
+       */
+
+#ifdef CONFIG_SYSTEM_NXLOOPER
+      ret = audio_register(devname, audio_i2s);
+#else
+      struct audio_lowerhalf_s *pcm;
+
+      pcm = pcm_decode_initialize(audio_i2s);
+

Review Comment:
   please remove empty line



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscr...@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to