diff --git a/boards/xtensa/esp32s2/common/src/Make.defs b/boards/xtensa/esp32s2/common/src/Make.defs index 1a8957b55e9..e98e8deba0e 100644 --- a/boards/xtensa/esp32s2/common/src/Make.defs +++ b/boards/xtensa/esp32s2/common/src/Make.defs @@ -32,6 +32,10 @@ ifeq ($(CONFIG_ESP32S2_I2S),y) CSRCS += esp32s2_board_i2sdev.c endif +ifeq ($(CONFIG_AUDIO_CS4344),y) + CSRCS += esp32s2_cs4344.c +endif + DEPPATH += --dep-path src VPATH += :src CFLAGS += $(shell $(INCDIR) "$(CC)" $(TOPDIR)$(DELIM)arch$(DELIM)$(CONFIG_ARCH)$(DELIM)src$(DELIM)board$(DELIM)src) diff --git a/boards/xtensa/esp32s2/common/src/esp32s2_cs4344.c b/boards/xtensa/esp32s2/common/src/esp32s2_cs4344.c new file mode 100644 index 00000000000..57f39a8f9b1 --- /dev/null +++ b/boards/xtensa/esp32s2/common/src/esp32s2_cs4344.c @@ -0,0 +1,160 @@ +/**************************************************************************** + * boards/xtensa/esp32s2/common/src/esp32s2_cs4344.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 + +#include +#include +#include +#include +#include + +#include +#include +#include +#include + +#include + +#include "esp32s2_i2s.h" + +#if defined(CONFIG_ESP32S2_I2S) && defined(CONFIG_AUDIO_CS4344) + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: esp32s2_cs4344_initialize + * + * Description: + * This function is called by platform-specific, setup logic to configure + * and register the CS4344 device. This function will register the driver + * as /dev/audio/pcm[x] where x is determined by the I2S port number. + * + * Input Parameters: + * None + * + * Returned Value: + * Zero is returned on success. Otherwise, a negated errno value is + * returned to indicate the nature of the failure. + * + ****************************************************************************/ + +int esp32s2_cs4344_initialize(void) +{ + struct audio_lowerhalf_s *cs4344; + struct audio_lowerhalf_s *pcm; + struct i2s_dev_s *i2s; + static bool initialized = false; + char devname[5]; + int ret; + + /* Have we already initialized? Since we are already initialized we must + * prevent multiple initializations. + */ + + if (!initialized) + { + /* Get an instance of the I2S interface for the CS4344 data channel */ + + i2s = esp32s2_i2sbus_initialize(); + if (!i2s) + { + auderr("ERROR: Failed to initialize I2S0\n"); + ret = -ENODEV; + goto errout; + } + + /* Check wheter to enable a simple character driver that supports I2S + * transfers via a read() and write(). The intent of this driver is to + * support I2S testing. It is not an audio driver but does conform to + * some of the buffer management heuristics of an audio driver. It is + * not suitable for use in any real driver application in its current + * form. The i2schar driver will be initialized at /dev/i2schar0 + */ + +#ifdef CONFIG_AUDIO_I2SCHAR + ret = i2schar_register(i2s, 0); + if (ret < 0) + { + auderr("ERROR: i2schar_register failed: %d\n", ret); + goto errout; + } +#endif + + /* Now we can use this I2S interface to initialize the CS4344 which + * will return an audio interface. + */ + + cs4344 = cs4344_initialize(i2s); + if (!cs4344) + { + auderr("ERROR: Failed to initialize the CS4344\n"); + ret = -ENODEV; + goto errout; + } + + /* No we can embed the CS4344/I2S conglomerate into a PCM decoder + * instance so that we will have a PCM front end for the the CS4344 + * driver. + */ + + pcm = pcm_decode_initialize(cs4344); + if (!pcm) + { + auderr("ERROR: Failed create the PCM decoder\n"); + ret = -ENODEV; + goto errout; + } + + /* Create a device name */ + + snprintf(devname, 12, "pcm0"); + + /* Finally, we can register the PCM/CS4344/I2S audio device. + * + * Is anyone young enough to remember Rube Goldberg? + */ + + ret = audio_register(devname, pcm); + if (ret < 0) + { + auderr("ERROR: Failed to register /dev/%s device: %d\n", + devname, ret); + goto errout; + } + + /* Now we are initialized */ + + initialized = true; + } + + return OK; + +errout: + return ret; +} + +#endif /* CONFIG_ESP32S2_I2S && CONFIG_AUDIO_CS4344 */ diff --git a/boards/xtensa/esp32s2/esp32s2-saola-1/configs/audio/defconfig b/boards/xtensa/esp32s2/esp32s2-saola-1/configs/audio/defconfig new file mode 100644 index 00000000000..6831dacc676 --- /dev/null +++ b/boards/xtensa/esp32s2/esp32s2-saola-1/configs/audio/defconfig @@ -0,0 +1,80 @@ +# +# 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_ESP32S2_I2S_RX is not set +# CONFIG_NDEBUG is not set +# CONFIG_NSH_ARGCAT is not set +# CONFIG_NSH_CMDOPT_HEXDUMP is not set +# CONFIG_NSH_CMDPARMS is not set +# CONFIG_NXPLAYER_INCLUDE_MEDIADIR is not set +CONFIG_ARCH="xtensa" +CONFIG_ARCH_BOARD="esp32s2-saola-1" +CONFIG_ARCH_BOARD_COMMON=y +CONFIG_ARCH_BOARD_ESP32S2_SAOLA_1=y +CONFIG_ARCH_CHIP="esp32s2" +CONFIG_ARCH_CHIP_ESP32S2=y +CONFIG_ARCH_CHIP_ESP32S2WROVER=y +CONFIG_ARCH_STACKDUMP=y +CONFIG_ARCH_XTENSA=y +CONFIG_AUDIO=y +CONFIG_AUDIO_CS4344=y +CONFIG_AUDIO_EXCLUDE_BALANCE=y +CONFIG_AUDIO_EXCLUDE_FFORWARD=y +CONFIG_AUDIO_EXCLUDE_TONE=y +CONFIG_AUDIO_EXCLUDE_VOLUME=y +CONFIG_AUDIO_I2SCHAR=y +CONFIG_AUDIO_NUM_BUFFERS=4 +CONFIG_BOARDCTL_ROMDISK=y +CONFIG_BOARD_LOOPSPERMSEC=16717 +CONFIG_BUILTIN=y +CONFIG_CS4344_INFLIGHT=4 +CONFIG_CS4344_NUM_BUFFERS=2 +CONFIG_CS4344_WORKER_STACKSIZE=4096 +CONFIG_DEFAULT_TASK_STACKSIZE=4096 +CONFIG_DRIVERS_AUDIO=y +CONFIG_ESP32S2_I2S=y +CONFIG_ESP32S2_I2S_DATA_BIT_WIDTH_16BIT=y +CONFIG_ESP32S2_I2S_MCLK=y +CONFIG_ESP32S2_UART0=y +CONFIG_EXAMPLES_I2SCHAR=y +CONFIG_EXAMPLES_I2SCHAR_TX=y +CONFIG_EXAMPLES_I2SCHAR_TXBUFFERS=2 +CONFIG_EXAMPLES_I2SCHAR_TXSTACKSIZE=2048 +CONFIG_EXAMPLES_ROMFS=y +CONFIG_FS_PROCFS=y +CONFIG_FS_ROMFS=y +CONFIG_HAVE_CXX=y +CONFIG_HAVE_CXXINITIALIZE=y +CONFIG_I2S_DMADESC_NUM=4 +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_NXPLAYER_MAINTHREAD_STACKSIZE=2048 +CONFIG_PREALLOC_TIMERS=4 +CONFIG_PTHREAD_STACK_DEFAULT=2048 +CONFIG_RAM_SIZE=114688 +CONFIG_RAM_START=0x20000000 +CONFIG_RR_INTERVAL=200 +CONFIG_SCHED_HPWORK=y +CONFIG_SCHED_HPWORKSTACKSIZE=2048 +CONFIG_SCHED_LPWORK=y +CONFIG_SCHED_LPWORKSTACKSIZE=2048 +CONFIG_SCHED_WAITPID=y +CONFIG_START_DAY=6 +CONFIG_START_MONTH=12 +CONFIG_START_YEAR=2011 +CONFIG_SYSTEM_NSH=y +CONFIG_SYSTEM_NSH_STACKSIZE=2048 +CONFIG_SYSTEM_NXPLAYER=y +CONFIG_TASK_SPAWN_DEFAULT_STACKSIZE=2048 +CONFIG_UART0_SERIAL_CONSOLE=y diff --git a/boards/xtensa/esp32s2/esp32s2-saola-1/src/esp32s2-saola-1.h b/boards/xtensa/esp32s2/esp32s2-saola-1/src/esp32s2-saola-1.h index bd46eca2a74..be4c69aa255 100644 --- a/boards/xtensa/esp32s2/esp32s2-saola-1/src/esp32s2-saola-1.h +++ b/boards/xtensa/esp32s2/esp32s2-saola-1/src/esp32s2-saola-1.h @@ -170,9 +170,30 @@ int board_bmp180_initialize(int devno, int busno); * ****************************************************************************/ -#ifdef CONFIG_ESP32S2_I2S +#if defined(CONFIG_ESP32S2_I2S) && !defined(CONFIG_AUDIO_CS4344) int board_i2sdev_initialize(void); #endif +/**************************************************************************** + * Name: esp32s2_cs4344_initialize + * + * Description: + * This function is called by platform-specific, setup logic to configure + * and register the CS4344 device. This function will register the driver + * as /dev/audio/pcm[x] where x is determined by the I2S port number. + * + * Input Parameters: + * None + * + * Returned Value: + * Zero is returned on success. Otherwise, a negated errno value is + * returned to indicate the nature of the failure. + * + ****************************************************************************/ + +#ifdef CONFIG_AUDIO_CS4344 +int esp32s2_cs4344_initialize(void); +#endif + #endif /* __ASSEMBLY__ */ #endif /* __BOARDS_XTENSA_ESP32S2_ESP32S2_SAOLA_1_SRC_ESP32S2_SAOLA_1_H */ diff --git a/boards/xtensa/esp32s2/esp32s2-saola-1/src/esp32s2_bringup.c b/boards/xtensa/esp32s2/esp32s2-saola-1/src/esp32s2_bringup.c index 49fb1f8f28d..47fbe50649b 100644 --- a/boards/xtensa/esp32s2/esp32s2-saola-1/src/esp32s2_bringup.c +++ b/boards/xtensa/esp32s2/esp32s2-saola-1/src/esp32s2_bringup.c @@ -231,6 +231,17 @@ int esp32s2_bringup(void) #ifdef CONFIG_ESP32S2_I2S +#ifdef CONFIG_AUDIO_CS4344 + + /* Configure CS4344 audio on I2S0 */ + + ret = esp32s2_cs4344_initialize(); + if (ret != OK) + { + syslog(LOG_ERR, "Failed to initialize CS4344 audio: %d\n", ret); + } +#else + /* Configure I2S generic audio on I2S0 */ ret = board_i2sdev_initialize(); @@ -238,6 +249,7 @@ int esp32s2_bringup(void) { syslog(LOG_ERR, "Failed to initialize I2S0 driver: %d\n", ret); } +#endif /* CONFIG_AUDIO_CS4344 */ #endif /* CONFIG_ESP32S2_I2S */