esp32[c3|c6|h2]: Add I2S support

Add I2S support for risc-v based Espressif devices

Signed-off-by: Eren Terzioglu <eren.terzioglu@espressif.com>
This commit is contained in:
Eren Terzioglu
2025-01-23 09:54:29 +01:00
committed by Lup Yuen Lee
parent f286a63223
commit 3661cdeed9
30 changed files with 4390 additions and 2 deletions
@@ -0,0 +1,76 @@
/****************************************************************************
* boards/risc-v/esp32c3/common/include/esp_board_i2s.h
*
* 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.
*
****************************************************************************/
#ifndef __BOARDS_RISCV_ESP32C3_COMMON_INCLUDE_ESP_BOARD_I2S_H
#define __BOARDS_RISCV_ESP32C3_COMMON_INCLUDE_ESP_BOARD_I2S_H
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
#ifndef __ASSEMBLY__
#undef EXTERN
#if defined(__cplusplus)
#define EXTERN extern "C"
extern "C"
{
#else
#define EXTERN extern
#endif
/****************************************************************************
* Public Function Prototypes
****************************************************************************/
/****************************************************************************
* Name: board_i2s_init
*
* Description:
* Configure the I2S driver.
*
* Input Parameters:
* None.
*
* Returned Value:
* Zero (OK) is returned on success; A negated errno value is returned
* to indicate the nature of any failure.
*
****************************************************************************/
#ifdef CONFIG_ESPRESSIF_I2S
int board_i2s_init(void);
#endif
#undef EXTERN
#if defined(__cplusplus)
}
#endif
#endif /* __ASSEMBLY__ */
#endif /* __BOARDS_RISCV_ESP32C3_COMMON_INCLUDE_ESP_BOARD_I2S_H */
@@ -46,6 +46,10 @@ ifeq ($(CONFIG_I2C_DRIVER),y)
CSRCS += esp_board_i2c.c
endif
ifeq ($(CONFIG_ESPRESSIF_I2S),y)
CSRCS += esp_board_i2s.c
endif
ifeq ($(CONFIG_ESPRESSIF_SPIFLASH),y)
CSRCS += esp_board_spiflash.c
endif
@@ -0,0 +1,200 @@
/****************************************************************************
* 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);
if (ret < 0)
{
auderr("ERROR: Failed to register /dev/%s device: %d\n",
devname, ret);
return ret;
}
}
return ret;
}
/****************************************************************************
* Name: board_i2s_init
*
* Description:
* Configure the I2S driver.
*
* Returned Value:
* Zero (OK) is returned on success; A negated errno value is returned
* to indicate the nature of any failure.
*
****************************************************************************/
int board_i2s_init(void)
{
int ret = OK;
#if defined(CONFIG_ESPRESSIF_I2S0)
bool i2s_enable_tx;
bool i2s_enable_rx;
#endif
#ifdef CONFIG_ESPRESSIF_I2S
#ifdef CONFIG_ESPRESSIF_I2S0_TX
i2s_enable_tx = true;
#else
i2s_enable_tx = false;
#endif /* CONFIG_ESPRESSIF_I2S0_TX */
#ifdef CONFIG_ESPRESSIF_I2S0_RX
i2s_enable_rx = true;
#else
i2s_enable_rx = false;
#endif /* CONFIG_ESPRESSIF_I2S0_RX */
/* Configure I2S generic audio on I2S0 */
ret = board_i2sdev_initialize(ESPRESSIF_I2S0,
i2s_enable_tx,
i2s_enable_rx);
if (ret < 0)
{
syslog(LOG_ERR, "Failed to initialize I2S0 driver: %d\n", ret);
}
#endif /* CONFIG_ESPRESSIF_I2S */
return ret;
}
@@ -0,0 +1,62 @@
#
# 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_NDEBUG is not set
# CONFIG_NSH_ARGCAT is not set
# CONFIG_NSH_CMDOPT_HEXDUMP is not set
CONFIG_ARCH="risc-v"
CONFIG_ARCH_BOARD="esp32c3-generic"
CONFIG_ARCH_BOARD_COMMON=y
CONFIG_ARCH_BOARD_ESP32C3_GENERIC=y
CONFIG_ARCH_CHIP="esp32c3"
CONFIG_ARCH_CHIP_ESP32C3_GENERIC=y
CONFIG_ARCH_INTERRUPTSTACK=1536
CONFIG_ARCH_RISCV=y
CONFIG_ARCH_STACKDUMP=y
CONFIG_AUDIO=y
CONFIG_AUDIO_I2S=y
CONFIG_AUDIO_I2SCHAR=y
CONFIG_BOARDCTL_RESET=y
CONFIG_BOARD_LOOPSPERMSEC=15000
CONFIG_BUILTIN=y
CONFIG_DRIVERS_AUDIO=y
CONFIG_ESPRESSIF_I2S0=y
CONFIG_ESPRESSIF_I2S0_MCLK=y
CONFIG_EXAMPLES_I2SCHAR=y
CONFIG_EXAMPLES_I2SCHAR_BUFSIZE=1024
CONFIG_EXAMPLES_I2SCHAR_RX=y
CONFIG_EXAMPLES_I2SCHAR_RXBUFFERS=2
CONFIG_EXAMPLES_I2SCHAR_RXSTACKSIZE=4096
CONFIG_EXAMPLES_I2SCHAR_TX=y
CONFIG_EXAMPLES_I2SCHAR_TXBUFFERS=2
CONFIG_EXAMPLES_I2SCHAR_TXSTACKSIZE=4096
CONFIG_FS_PROCFS=y
CONFIG_IDLETHREAD_STACKSIZE=2048
CONFIG_INIT_ENTRYPOINT="nsh_main"
CONFIG_INIT_STACKSIZE=4096
CONFIG_INTELHEX_BINARY=y
CONFIG_LIBC_PERROR_STDOUT=y
CONFIG_LIBC_STRERROR=y
CONFIG_NFILE_DESCRIPTORS_PER_BLOCK=6
CONFIG_NSH_ARCHINIT=y
CONFIG_NSH_BUILTIN_APPS=y
CONFIG_NSH_FILEIOSIZE=512
CONFIG_NSH_READLINE=y
CONFIG_NSH_STRERROR=y
CONFIG_PREALLOC_TIMERS=0
CONFIG_RR_INTERVAL=200
CONFIG_SCHED_BACKTRACE=y
CONFIG_SCHED_LPWORK=y
CONFIG_SCHED_WAITPID=y
CONFIG_START_DAY=29
CONFIG_START_MONTH=11
CONFIG_START_YEAR=2019
CONFIG_SYSTEM_DUMPSTACK=y
CONFIG_SYSTEM_NSH=y
CONFIG_TESTING_GETPRIME=y
CONFIG_TESTING_OSTEST=y
CONFIG_UART0_SERIAL_CONSOLE=y
@@ -73,6 +73,10 @@
# include "esp_board_rmt.h"
#endif
#ifdef CONFIG_ESPRESSIF_I2S
# include "esp_board_i2s.h"
#endif
#ifdef CONFIG_ESPRESSIF_SPI
# include "espressif/esp_spi.h"
# include "esp_board_spidev.h"
@@ -317,6 +321,16 @@ int esp_bringup(void)
}
#endif
#if defined(CONFIG_ESPRESSIF_I2S)
/* Configure I2S peripheral interfaces */
ret = board_i2s_init();
if (ret < 0)
{
syslog(LOG_ERR, "Failed to initialize I2S driver: %d\n", ret);
}
#endif
#if defined(CONFIG_I2C_DRIVER)
/* Configure I2C peripheral interfaces */
@@ -0,0 +1,76 @@
/****************************************************************************
* boards/risc-v/esp32c6/common/include/esp_board_i2s.h
*
* 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.
*
****************************************************************************/
#ifndef __BOARDS_RISCV_ESP32C6_COMMON_INCLUDE_ESP_BOARD_I2S_H
#define __BOARDS_RISCV_ESP32C3_COMMON_INCLUDE_ESP_BOARD_I2S_H
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
#ifndef __ASSEMBLY__
#undef EXTERN
#if defined(__cplusplus)
#define EXTERN extern "C"
extern "C"
{
#else
#define EXTERN extern
#endif
/****************************************************************************
* Public Function Prototypes
****************************************************************************/
/****************************************************************************
* Name: board_i2s_init
*
* Description:
* Configure the I2S driver.
*
* Input Parameters:
* None.
*
* Returned Value:
* Zero (OK) is returned on success; A negated errno value is returned
* to indicate the nature of any failure.
*
****************************************************************************/
#ifdef CONFIG_ESPRESSIF_I2S
int board_i2s_init(void);
#endif
#undef EXTERN
#if defined(__cplusplus)
}
#endif
#endif /* __ASSEMBLY__ */
#endif /* __BOARDS_RISCV_ESP32C6_COMMON_INCLUDE_ESP_BOARD_I2S_H */
@@ -46,6 +46,10 @@ ifeq ($(CONFIG_I2C_DRIVER),y)
CSRCS += esp_board_i2c.c
endif
ifeq ($(CONFIG_ESPRESSIF_I2S),y)
CSRCS += esp_board_i2s.c
endif
ifeq ($(CONFIG_ESPRESSIF_SPIFLASH),y)
CSRCS += esp_board_spiflash.c
endif
@@ -0,0 +1,200 @@
/****************************************************************************
* 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);
if (ret < 0)
{
auderr("ERROR: Failed to register /dev/%s device: %d\n",
devname, ret);
return ret;
}
}
return ret;
}
/****************************************************************************
* Name: board_i2s_init
*
* Description:
* Configure the I2S driver.
*
* Returned Value:
* Zero (OK) is returned on success; A negated errno value is returned
* to indicate the nature of any failure.
*
****************************************************************************/
int board_i2s_init(void)
{
int ret = OK;
#if defined(CONFIG_ESPRESSIF_I2S0)
bool i2s_enable_tx;
bool i2s_enable_rx;
#endif
#ifdef CONFIG_ESPRESSIF_I2S
#ifdef CONFIG_ESPRESSIF_I2S0_TX
i2s_enable_tx = true;
#else
i2s_enable_tx = false;
#endif /* CONFIG_ESPRESSIF_I2S0_TX */
#ifdef CONFIG_ESPRESSIF_I2S0_RX
i2s_enable_rx = true;
#else
i2s_enable_rx = false;
#endif /* CONFIG_ESPRESSIF_I2S0_RX */
/* Configure I2S generic audio on I2S0 */
ret = board_i2sdev_initialize(ESPRESSIF_I2S0,
i2s_enable_tx,
i2s_enable_rx);
if (ret < 0)
{
syslog(LOG_ERR, "Failed to initialize I2S0 driver: %d\n", ret);
}
#endif /* CONFIG_ESPRESSIF_I2S */
return ret;
}
@@ -0,0 +1,64 @@
#
# 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_NDEBUG is not set
# CONFIG_NSH_ARGCAT is not set
# CONFIG_NSH_CMDOPT_HEXDUMP is not set
CONFIG_ARCH="risc-v"
CONFIG_ARCH_BOARD="esp32c6-devkitc"
CONFIG_ARCH_BOARD_COMMON=y
CONFIG_ARCH_BOARD_ESP32C6_DEVKITC=y
CONFIG_ARCH_CHIP="esp32c6"
CONFIG_ARCH_CHIP_ESP32C6=y
CONFIG_ARCH_CHIP_ESP32C6WROOM1=y
CONFIG_ARCH_INTERRUPTSTACK=2048
CONFIG_ARCH_RISCV=y
CONFIG_ARCH_STACKDUMP=y
CONFIG_AUDIO=y
CONFIG_AUDIO_I2S=y
CONFIG_AUDIO_I2SCHAR=y
CONFIG_BOARDCTL_RESET=y
CONFIG_BOARD_LOOPSPERMSEC=15000
CONFIG_BUILTIN=y
CONFIG_DRIVERS_AUDIO=y
CONFIG_ESPRESSIF_ESP32C6=y
CONFIG_ESPRESSIF_I2S0=y
CONFIG_ESPRESSIF_I2S0_MCLK=y
CONFIG_EXAMPLES_I2SCHAR=y
CONFIG_EXAMPLES_I2SCHAR_BUFSIZE=1024
CONFIG_EXAMPLES_I2SCHAR_RX=y
CONFIG_EXAMPLES_I2SCHAR_RXBUFFERS=2
CONFIG_EXAMPLES_I2SCHAR_RXSTACKSIZE=4096
CONFIG_EXAMPLES_I2SCHAR_TX=y
CONFIG_EXAMPLES_I2SCHAR_TXBUFFERS=2
CONFIG_EXAMPLES_I2SCHAR_TXSTACKSIZE=4096
CONFIG_FS_PROCFS=y
CONFIG_IDLETHREAD_STACKSIZE=2048
CONFIG_INIT_ENTRYPOINT="nsh_main"
CONFIG_INIT_STACKSIZE=4096
CONFIG_INTELHEX_BINARY=y
CONFIG_LIBC_PERROR_STDOUT=y
CONFIG_LIBC_STRERROR=y
CONFIG_NFILE_DESCRIPTORS_PER_BLOCK=6
CONFIG_NSH_ARCHINIT=y
CONFIG_NSH_BUILTIN_APPS=y
CONFIG_NSH_FILEIOSIZE=512
CONFIG_NSH_READLINE=y
CONFIG_NSH_STRERROR=y
CONFIG_PREALLOC_TIMERS=0
CONFIG_RR_INTERVAL=200
CONFIG_SCHED_BACKTRACE=y
CONFIG_SCHED_LPWORK=y
CONFIG_SCHED_WAITPID=y
CONFIG_START_DAY=29
CONFIG_START_MONTH=11
CONFIG_START_YEAR=2019
CONFIG_SYSTEM_DUMPSTACK=y
CONFIG_SYSTEM_NSH=y
CONFIG_TESTING_GETPRIME=y
CONFIG_TESTING_OSTEST=y
CONFIG_UART0_SERIAL_CONSOLE=y
@@ -73,6 +73,10 @@
# include "esp_board_rmt.h"
#endif
#ifdef CONFIG_ESPRESSIF_I2S
# include "esp_board_i2s.h"
#endif
#ifdef CONFIG_ESPRESSIF_SPI
# include "espressif/esp_spi.h"
# include "esp_board_spidev.h"
@@ -270,6 +274,16 @@ int esp_bringup(void)
}
#endif
#if defined(CONFIG_ESPRESSIF_I2S)
/* Configure I2S peripheral interfaces */
ret = board_i2s_init();
if (ret < 0)
{
syslog(LOG_ERR, "Failed to initialize I2S driver: %d\n", ret);
}
#endif
#if defined(CONFIG_I2C_DRIVER)
/* Configure I2C peripheral interfaces */
@@ -0,0 +1,64 @@
#
# 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_NDEBUG is not set
# CONFIG_NSH_ARGCAT is not set
# CONFIG_NSH_CMDOPT_HEXDUMP is not set
CONFIG_ARCH="risc-v"
CONFIG_ARCH_BOARD="esp32c6-devkitm"
CONFIG_ARCH_BOARD_COMMON=y
CONFIG_ARCH_BOARD_ESP32C6_DEVKITM=y
CONFIG_ARCH_CHIP="esp32c6"
CONFIG_ARCH_CHIP_ESP32C6=y
CONFIG_ARCH_CHIP_ESP32C6MINI1=y
CONFIG_ARCH_INTERRUPTSTACK=2048
CONFIG_ARCH_RISCV=y
CONFIG_ARCH_STACKDUMP=y
CONFIG_AUDIO=y
CONFIG_AUDIO_I2S=y
CONFIG_AUDIO_I2SCHAR=y
CONFIG_BOARDCTL_RESET=y
CONFIG_BOARD_LOOPSPERMSEC=15000
CONFIG_BUILTIN=y
CONFIG_DRIVERS_AUDIO=y
CONFIG_ESPRESSIF_ESP32C6=y
CONFIG_ESPRESSIF_I2S0=y
CONFIG_ESPRESSIF_I2S0_MCLK=y
CONFIG_EXAMPLES_I2SCHAR=y
CONFIG_EXAMPLES_I2SCHAR_BUFSIZE=1024
CONFIG_EXAMPLES_I2SCHAR_RX=y
CONFIG_EXAMPLES_I2SCHAR_RXBUFFERS=2
CONFIG_EXAMPLES_I2SCHAR_RXSTACKSIZE=4096
CONFIG_EXAMPLES_I2SCHAR_TX=y
CONFIG_EXAMPLES_I2SCHAR_TXBUFFERS=2
CONFIG_EXAMPLES_I2SCHAR_TXSTACKSIZE=4096
CONFIG_FS_PROCFS=y
CONFIG_IDLETHREAD_STACKSIZE=2048
CONFIG_INIT_ENTRYPOINT="nsh_main"
CONFIG_INIT_STACKSIZE=4096
CONFIG_INTELHEX_BINARY=y
CONFIG_LIBC_PERROR_STDOUT=y
CONFIG_LIBC_STRERROR=y
CONFIG_NFILE_DESCRIPTORS_PER_BLOCK=6
CONFIG_NSH_ARCHINIT=y
CONFIG_NSH_BUILTIN_APPS=y
CONFIG_NSH_FILEIOSIZE=512
CONFIG_NSH_READLINE=y
CONFIG_NSH_STRERROR=y
CONFIG_PREALLOC_TIMERS=0
CONFIG_RR_INTERVAL=200
CONFIG_SCHED_BACKTRACE=y
CONFIG_SCHED_LPWORK=y
CONFIG_SCHED_WAITPID=y
CONFIG_START_DAY=29
CONFIG_START_MONTH=11
CONFIG_START_YEAR=2019
CONFIG_SYSTEM_DUMPSTACK=y
CONFIG_SYSTEM_NSH=y
CONFIG_TESTING_GETPRIME=y
CONFIG_TESTING_OSTEST=y
CONFIG_UART0_SERIAL_CONSOLE=y
@@ -73,6 +73,10 @@
# include "esp_board_rmt.h"
#endif
#ifdef CONFIG_ESPRESSIF_I2S
# include "esp_board_i2s.h"
#endif
#ifdef CONFIG_ESPRESSIF_SPI
# include "espressif/esp_spi.h"
# include "esp_board_spidev.h"
@@ -266,6 +270,16 @@ int esp_bringup(void)
}
#endif
#if defined(CONFIG_ESPRESSIF_I2S)
/* Configure I2S peripheral interfaces */
ret = board_i2s_init();
if (ret < 0)
{
syslog(LOG_ERR, "Failed to initialize I2S driver: %d\n", ret);
}
#endif
#if defined(CONFIG_I2C_DRIVER)
/* Configure I2C peripheral interfaces */
@@ -0,0 +1,76 @@
/****************************************************************************
* boards/risc-v/esp32h2/common/include/esp_board_i2s.h
*
* 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.
*
****************************************************************************/
#ifndef __BOARDS_RISCV_ESP32H2_COMMON_INCLUDE_ESP_BOARD_I2S_H
#define __BOARDS_RISCV_ESP32H2_COMMON_INCLUDE_ESP_BOARD_I2S_H
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
#ifndef __ASSEMBLY__
#undef EXTERN
#if defined(__cplusplus)
#define EXTERN extern "C"
extern "C"
{
#else
#define EXTERN extern
#endif
/****************************************************************************
* Public Function Prototypes
****************************************************************************/
/****************************************************************************
* Name: board_i2s_init
*
* Description:
* Configure the I2S driver.
*
* Input Parameters:
* None.
*
* Returned Value:
* Zero (OK) is returned on success; A negated errno value is returned
* to indicate the nature of any failure.
*
****************************************************************************/
#ifdef CONFIG_ESPRESSIF_I2S
int board_i2s_init(void);
#endif
#undef EXTERN
#if defined(__cplusplus)
}
#endif
#endif /* __ASSEMBLY__ */
#endif /* __BOARDS_RISCV_ESP32H2_COMMON_INCLUDE_ESP_BOARD_I2S_H */
@@ -46,6 +46,10 @@ ifeq ($(CONFIG_I2C_DRIVER),y)
CSRCS += esp_board_i2c.c
endif
ifeq ($(CONFIG_ESPRESSIF_I2S),y)
CSRCS += esp_board_i2s.c
endif
ifeq ($(CONFIG_ESPRESSIF_SPIFLASH),y)
CSRCS += esp_board_spiflash.c
endif
@@ -0,0 +1,200 @@
/****************************************************************************
* 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);
if (ret < 0)
{
auderr("ERROR: Failed to register /dev/%s device: %d\n",
devname, ret);
return ret;
}
}
return ret;
}
/****************************************************************************
* Name: board_i2s_init
*
* Description:
* Configure the I2S driver.
*
* Returned Value:
* Zero (OK) is returned on success; A negated errno value is returned
* to indicate the nature of any failure.
*
****************************************************************************/
int board_i2s_init(void)
{
int ret = OK;
#if defined(CONFIG_ESPRESSIF_I2S0)
bool i2s_enable_tx;
bool i2s_enable_rx;
#endif
#ifdef CONFIG_ESPRESSIF_I2S
#ifdef CONFIG_ESPRESSIF_I2S0_TX
i2s_enable_tx = true;
#else
i2s_enable_tx = false;
#endif /* CONFIG_ESPRESSIF_I2S0_TX */
#ifdef CONFIG_ESPRESSIF_I2S0_RX
i2s_enable_rx = true;
#else
i2s_enable_rx = false;
#endif /* CONFIG_ESPRESSIF_I2S0_RX */
/* Configure I2S generic audio on I2S0 */
ret = board_i2sdev_initialize(ESPRESSIF_I2S0,
i2s_enable_tx,
i2s_enable_rx);
if (ret < 0)
{
syslog(LOG_ERR, "Failed to initialize I2S0 driver: %d\n", ret);
}
#endif /* CONFIG_ESPRESSIF_I2S */
return ret;
}
@@ -0,0 +1,63 @@
#
# 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_NDEBUG is not set
# CONFIG_NSH_ARGCAT is not set
# CONFIG_NSH_CMDOPT_HEXDUMP is not set
CONFIG_ARCH="risc-v"
CONFIG_ARCH_BOARD="esp32h2-devkit"
CONFIG_ARCH_BOARD_COMMON=y
CONFIG_ARCH_BOARD_ESP32H2_DEVKIT=y
CONFIG_ARCH_CHIP="esp32h2"
CONFIG_ARCH_CHIP_ESP32H2=y
CONFIG_ARCH_INTERRUPTSTACK=2048
CONFIG_ARCH_RISCV=y
CONFIG_ARCH_STACKDUMP=y
CONFIG_AUDIO=y
CONFIG_AUDIO_I2S=y
CONFIG_AUDIO_I2SCHAR=y
CONFIG_BOARDCTL_RESET=y
CONFIG_BOARD_LOOPSPERMSEC=15000
CONFIG_BUILTIN=y
CONFIG_DRIVERS_AUDIO=y
CONFIG_ESPRESSIF_ESP32H2=y
CONFIG_ESPRESSIF_I2S0=y
CONFIG_ESPRESSIF_I2S0_MCLK=y
CONFIG_EXAMPLES_I2SCHAR=y
CONFIG_EXAMPLES_I2SCHAR_BUFSIZE=1024
CONFIG_EXAMPLES_I2SCHAR_RX=y
CONFIG_EXAMPLES_I2SCHAR_RXBUFFERS=2
CONFIG_EXAMPLES_I2SCHAR_RXSTACKSIZE=4096
CONFIG_EXAMPLES_I2SCHAR_TX=y
CONFIG_EXAMPLES_I2SCHAR_TXBUFFERS=2
CONFIG_EXAMPLES_I2SCHAR_TXSTACKSIZE=4096
CONFIG_FS_PROCFS=y
CONFIG_IDLETHREAD_STACKSIZE=2048
CONFIG_INIT_ENTRYPOINT="nsh_main"
CONFIG_INIT_STACKSIZE=4096
CONFIG_INTELHEX_BINARY=y
CONFIG_LIBC_PERROR_STDOUT=y
CONFIG_LIBC_STRERROR=y
CONFIG_NFILE_DESCRIPTORS_PER_BLOCK=6
CONFIG_NSH_ARCHINIT=y
CONFIG_NSH_BUILTIN_APPS=y
CONFIG_NSH_FILEIOSIZE=512
CONFIG_NSH_READLINE=y
CONFIG_NSH_STRERROR=y
CONFIG_PREALLOC_TIMERS=0
CONFIG_RR_INTERVAL=200
CONFIG_SCHED_BACKTRACE=y
CONFIG_SCHED_LPWORK=y
CONFIG_SCHED_WAITPID=y
CONFIG_START_DAY=29
CONFIG_START_MONTH=11
CONFIG_START_YEAR=2019
CONFIG_SYSTEM_DUMPSTACK=y
CONFIG_SYSTEM_NSH=y
CONFIG_TESTING_GETPRIME=y
CONFIG_TESTING_OSTEST=y
CONFIG_UART0_SERIAL_CONSOLE=y
@@ -73,6 +73,10 @@
# include "esp_board_rmt.h"
#endif
#ifdef CONFIG_ESPRESSIF_I2S
# include "esp_board_i2s.h"
#endif
#ifdef CONFIG_ESPRESSIF_SPI
# include "espressif/esp_spi.h"
# include "esp_board_spidev.h"
@@ -264,6 +268,16 @@ int esp_bringup(void)
}
#endif
#if defined(CONFIG_ESPRESSIF_I2S)
/* Configure I2S peripheral interfaces */
ret = board_i2s_init();
if (ret < 0)
{
syslog(LOG_ERR, "Failed to initialize I2S driver: %d\n", ret);
}
#endif
#if defined(CONFIG_I2C_DRIVER)
/* Configure I2C peripheral interfaces */