diff --git a/Documentation/platforms/xtensa/esp32/boards/esp32-devkitc/index.rst b/Documentation/platforms/xtensa/esp32/boards/esp32-devkitc/index.rst index 13cb2c4b13c..4ac3c2abad9 100644 --- a/Documentation/platforms/xtensa/esp32/boards/esp32-devkitc/index.rst +++ b/Documentation/platforms/xtensa/esp32/boards/esp32-devkitc/index.rst @@ -602,7 +602,7 @@ The ``nxlooper`` application captures data from the audio device with receiving capabilities (the I2S1 on this example) and forwards the audio data frame to the audio device with transmitting capabilities (the I2S0 on this example). -After successfully built and flashed, run on the boards's terminal:: +After successfully built and flashed, run on the boards' terminal:: nsh> nxlooper nxlooper> loopback diff --git a/Documentation/platforms/xtensa/esp32s2/boards/esp32s2-kaluga-1/index.rst b/Documentation/platforms/xtensa/esp32s2/boards/esp32s2-kaluga-1/index.rst index d0896b22950..fae84dd7dfe 100644 --- a/Documentation/platforms/xtensa/esp32s2/boards/esp32s2-kaluga-1/index.rst +++ b/Documentation/platforms/xtensa/esp32s2/boards/esp32s2-kaluga-1/index.rst @@ -180,11 +180,41 @@ Configurations All of the configurations presented below can be tested by running the following commands:: $ ./tools/configure.sh esp32s2-kaluga-1: - $ make flash ESPTOOL_PORT=/dev/ttyUSB0 -j + $ make flash ESPTOOL_PORT=/dev/ttyUSB1 -j Where is the name of board configuration you want to use, i.e.: nsh, buttons, wifi... Then use a serial console terminal like ``picocom`` configured to 115200 8N1. +audio +----- + +This configuration uses the I2S peripheral and the ES8311 audio +codec to play an audio file. The easiest way of playing an uncompressed file +is embedding into the firmware. This configuration selects +`romfs example `__ +to allow that. + +**ROMFS example** + +Prepare and build the ``audio`` defconfig:: + + $ make -j distclean && ./tools/configure.sh esp32s2-kaluga-1:audio && make + +This will create a temporary folder in ``apps/examples/romfs/testdir``. Move +a PCM-encoded (``.wav``) audio file with 16 or 24 bits/sample (sampled at 16~48kHz) +to this folder. + +.. note:: You can use :download:`this 440 Hz sinusoidal tone `. + The audio file should be located at ``apps/examples/romfs/testdir/tone.wav`` + +Build the project again and flash it (make sure not to clean it, just build) + +After successfully built and flashed, load the romfs and play it:: + + nsh> romfs + nsh> nxplayer + nxplayer> play /usr/share/local/tone.wav + buttons ------- @@ -210,6 +240,14 @@ the ``buttons`` application and pressing on any of the available board buttons a Sample = 64 Sample = 0 +i2c +--- + +This configuration can be used to scan and manipulate I2C devices. +You can scan for all I2C devices using the following command:: + + nsh> i2c dev 0x00 0x7f + lvgl_ili9341 ------------ @@ -219,8 +257,8 @@ driver with the ILI9341 display. You can find LVGL here:: https://www.lvgl.io/ https://github.com/lvgl/lvgl -This configuration uses the LVGL demonstration at `apps/examples/lvgldemo` and -can be executed by running the `lvgldemo` application. +This configuration uses the LVGL demonstration at ``apps/examples/lvgldemo`` and +can be executed by running the ``lvgldemo`` application. lvgl_st7789 ----------- @@ -231,11 +269,30 @@ driver with the ST7799 display. You can find LVGL here:: https://www.lvgl.io/ https://github.com/lvgl/lvgl -This configuration uses the LVGL demonstration at `apps/examples/lvgldemo` and -can be executed by running the `lvgldemo` application. +This configuration uses the LVGL demonstration at ``apps/examples/lvgldemo`` and +can be executed by running the ``lvgldemo`` application. nsh --- Basic NuttShell configuration (console enabled in UART0, exposed via -USB connection by means of CP2102 converter, at 115200 bps). \ No newline at end of file +USB connection by means of CP2102 converter, at 115200 bps). + +nxlooper +-------- + +The ``nxlooper`` application captures data from the audio device with receiving +capabilities and forwards the audio data frame to the audio device with transmitting +capabilities. + +After successfully built and flashed, run on the boards' terminal:: + + nsh> nxlooper + nxlooper> loopback + +.. note:: ``loopback`` command default arguments for the channel configuration, + the data width and the sample rate are, respectively, 2 channels, + 16 bits/sample and 48KHz. These arguments can be supplied to select + different audio formats, for instance:: + + nxlooper> loopback 2 8 44100 \ No newline at end of file diff --git a/boards/xtensa/esp32s2/common/include/esp32s2_es8311.h b/boards/xtensa/esp32s2/common/include/esp32s2_es8311.h new file mode 100644 index 00000000000..4ed64d5934b --- /dev/null +++ b/boards/xtensa/esp32s2/common/include/esp32s2_es8311.h @@ -0,0 +1,90 @@ +/**************************************************************************** + * boards/xtensa/esp32s2/common/include/esp32s2_es8311.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_ESP32S2_COMMON_INCLUDE_ESP32S2_ES8311_H +#define __BOARDS_XTENSA_ESP32S2_COMMON_INCLUDE_ESP32S2_ES8311_H + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +/**************************************************************************** + * Type Definitions + ****************************************************************************/ + +/**************************************************************************** + * Public Types + ****************************************************************************/ + +/**************************************************************************** + * Public Data + ****************************************************************************/ + +#ifdef __cplusplus +#define EXTERN extern "C" +extern "C" +{ +#else +#define EXTERN extern +#endif + +/**************************************************************************** + * Inline Functions + ****************************************************************************/ + +/**************************************************************************** + * Public Function Prototypes + ****************************************************************************/ + +/**************************************************************************** + * Name: esp32s2_es8311_initialize + * + * Description: + * This function is called by platform-specific, setup logic to configure + * and register the ES8311 device. This function will register the driver + * as /dev/audio/pcm[x] where x is determined by the I2S port number. + * + * Input Parameters: + * i2c_port - The I2C port used for the device; + * i2c_addr - The I2C address used by the device; + * i2c_freq - The I2C frequency used for the device. + * + * Returned Value: + * Zero is returned on success. Otherwise, a negated errno value is + * returned to indicate the nature of the failure. + * + ****************************************************************************/ + +int esp32s2_es8311_initialize(int i2c_port, uint8_t i2c_addr, int i2c_freq); + +#undef EXTERN +#ifdef __cplusplus +} +#endif + +#endif /* __BOARDS_XTENSA_ESP32S2_COMMON_INCLUDE_ESP32S2_ES8311_H */ diff --git a/boards/xtensa/esp32s2/common/src/Make.defs b/boards/xtensa/esp32s2/common/src/Make.defs index 27e1ce2200e..fca2a9b5fb2 100644 --- a/boards/xtensa/esp32s2/common/src/Make.defs +++ b/boards/xtensa/esp32s2/common/src/Make.defs @@ -44,6 +44,10 @@ ifeq ($(CONFIG_LCD_ST7789),y) CSRCS += esp32s2_st7789.c endif +ifeq ($(CONFIG_AUDIO_ES8311),y) + CSRCS += esp32s2_es8311.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_board_i2sdev.c b/boards/xtensa/esp32s2/common/src/esp32s2_board_i2sdev.c index 52b40d0baea..a548a882bbf 100644 --- a/boards/xtensa/esp32s2/common/src/esp32s2_board_i2sdev.c +++ b/boards/xtensa/esp32s2/common/src/esp32s2_board_i2sdev.c @@ -37,7 +37,8 @@ #include "esp32s2_i2s.h" -#if defined(CONFIG_ESP32S2_I2S) && !defined(CONFIG_AUDIO_CS4344) +#if defined(CONFIG_ESP32S2_I2S) && !defined(CONFIG_AUDIO_CS4344) && \ + !defined(CONFIG_AUDIO_ES8311) /**************************************************************************** * Public Functions @@ -152,4 +153,5 @@ int board_i2sdev_initialize(bool enable_tx, bool enable_rx) return ret; } -#endif /* (CONFIG_ESP32S2_I2S) && !defined (CONFIG_AUDIO_CS4344) */ +#endif /* (CONFIG_ESP32S2_I2S) && !(CONFIG_AUDIO_CS4344) * + * !(CONFIG_AUDIO_ES8311) */ diff --git a/boards/xtensa/esp32s2/common/src/esp32s2_es8311.c b/boards/xtensa/esp32s2/common/src/esp32s2_es8311.c new file mode 100644 index 00000000000..6f4509b4044 --- /dev/null +++ b/boards/xtensa/esp32s2/common/src/esp32s2_es8311.c @@ -0,0 +1,212 @@ +/**************************************************************************** + * boards/xtensa/esp32s2/common/src/esp32s2_es8311.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 + +#include + +#include "esp32s2_i2c.h" +#include "esp32s2_i2s.h" + +#if defined(CONFIG_ESP32S2_I2S) && defined(CONFIG_AUDIO_ES8311) + +/**************************************************************************** + * Private Data + ****************************************************************************/ + +static struct es8311_lower_s g_es8311_lower[2]; + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: esp32s2_es8311_initialize + * + * Description: + * This function is called by platform-specific, setup logic to configure + * and register the ES8311 device. This function will register the driver + * as /dev/audio/pcm[x] where x is determined by the I2S port number. + * + * Input Parameters: + * i2c_port - The I2C port used for the device; + * i2c_addr - The I2C address used by the device; + * i2c_freq - The I2C frequency used for the device. + * + * Returned Value: + * Zero is returned on success. Otherwise, a negated errno value is + * returned to indicate the nature of the failure. + * + ****************************************************************************/ + +int esp32s2_es8311_initialize(int i2c_port, uint8_t i2c_addr, int i2c_freq) +{ + struct audio_lowerhalf_s *es8311; + struct i2s_dev_s *i2s; + struct i2c_master_s *i2c; + static bool initialized = false; + int ret; + + audinfo("i2c_port %d, i2c_addr %d, i2c_freq %d\n", + i2c_port, i2c_addr, i2c_freq); + + /* Have we already initialized? Since we never uninitialize we must + * prevent multiple initializations. This is necessary, for example, + * when the touchscreen example is used as a built-in application in + * NSH and can be called numerous time. It will attempt to initialize + * each time. + */ + + if (!initialized) + { + /* Get an instance of the I2S interface for the ES8311 data channel */ + + i2s = esp32s2_i2sbus_initialize(); + if (i2s == NULL) + { + auderr("ERROR: Failed to initialize I2S\n"); + ret = -ENODEV; + goto errout; + } + + i2c = esp32s2_i2cbus_initialize(i2c_port); + if (i2c == NULL) + { + auderr("ERROR: Failed to initialize I2C%d\n", i2c_port); + 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 ES8311 output + * which will return an audio interface. + */ + + g_es8311_lower[0].address = i2c_addr; + g_es8311_lower[0].frequency = i2c_freq; + + es8311 = es8311_initialize(i2c, i2s, &g_es8311_lower[0]); + if (es8311 == NULL) + { + auderr("ERROR: Failed to initialize the ES8311\n"); + ret = -ENODEV; + goto errout; + } + +#ifdef CONFIG_SYSTEM_NXLOOPER + /* 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. + */ + + ret = audio_register("pcm0", es8311); +#else + /* Now we can embed the ES8311/I2S conglomerate into a PCM decoder + * instance so that we will have a PCM front end for the the ES8311 + * driver. + */ + + struct audio_lowerhalf_s *pcm = pcm_decode_initialize(es8311); + if (pcm == NULL) + { + auderr("ERROR: Failed create the PCM decoder\n"); + ret = -ENODEV; + goto errout; + } + + /* Finally, we can register the PCM/ES8311/I2S audio device. */ + + ret = audio_register("pcm0", pcm); +#endif + if (ret < 0) + { + auderr("ERROR: Failed to register /dev/pcm0 device: %d\n", ret); + goto errout; + } + + /* Now we can use this I2S interface to initialize the ES8311 input + * which will return an audio interface. + */ + + g_es8311_lower[1].address = i2c_addr; + g_es8311_lower[1].frequency = i2c_freq; + + es8311 = es8311_initialize(i2c, i2s, &g_es8311_lower[1]); + if (es8311 == NULL) + { + auderr("ERROR: Failed to initialize the ES8311\n"); + ret = -ENODEV; + goto errout; + } + + /* Finally, we can register the PCM/ES8311/I2S audio device. */ + + ret = audio_register("pcm_in0", es8311); + if (ret < 0) + { + auderr("ERROR: Failed to register /dev/pcm_in0 device: %d\n", ret); + goto errout; + } + + /* Now we are initialized */ + + initialized = true; + } + + return OK; + +errout: + return ret; +} + +#endif /* CONFIG_ESP32S2_I2S && CONFIG_AUDIO_ES8311 */ diff --git a/boards/xtensa/esp32s2/esp32s2-kaluga-1/configs/audio/defconfig b/boards/xtensa/esp32s2/esp32s2-kaluga-1/configs/audio/defconfig new file mode 100644 index 00000000000..462a20c7c16 --- /dev/null +++ b/boards/xtensa/esp32s2/esp32s2-kaluga-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_AUDIO_FORMAT_MP3 is not set +# CONFIG_ESP32S2_I2S_RX is not set +# CONFIG_NSH_ARGCAT is not set +# CONFIG_NSH_CMDOPT_HEXDUMP is not set +CONFIG_ARCH="xtensa" +CONFIG_ARCH_BOARD="esp32s2-kaluga-1" +CONFIG_ARCH_BOARD_COMMON=y +CONFIG_ARCH_BOARD_ESP32S2_KALUGA_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_ES8311=y +CONFIG_AUDIO_EXCLUDE_BALANCE=y +CONFIG_AUDIO_EXCLUDE_FFORWARD=y +CONFIG_AUDIO_EXCLUDE_TONE=y +CONFIG_BOARDCTL_ROMDISK=y +CONFIG_BOARD_LOOPSPERMSEC=16717 +CONFIG_BUILTIN=y +CONFIG_DEFAULT_TASK_STACKSIZE=4096 +CONFIG_DRIVERS_AUDIO=y +CONFIG_ES8311_BUFFER_SIZE=4096 +CONFIG_ES8311_SRC_BCLK=y +CONFIG_ESP32S2_I2C0=y +CONFIG_ESP32S2_I2C0_SCLPIN=7 +CONFIG_ESP32S2_I2C0_SDAPIN=8 +CONFIG_ESP32S2_I2S=y +CONFIG_ESP32S2_I2S_BCLKPIN=18 +CONFIG_ESP32S2_I2S_DATA_BIT_WIDTH_16BIT=y +CONFIG_ESP32S2_I2S_DOUTPIN=12 +CONFIG_ESP32S2_I2S_MCLK=y +CONFIG_ESP32S2_I2S_MCLKPIN=35 +CONFIG_ESP32S2_I2S_SAMPLE_RATE=48000 +CONFIG_ESP32S2_I2S_WSPIN=17 +CONFIG_ESP32S2_UART0=y +CONFIG_EXAMPLES_ROMFS=y +CONFIG_FS_PROCFS=y +CONFIG_FS_ROMFS=y +CONFIG_HAVE_CXX=y +CONFIG_HAVE_CXXINITIALIZE=y +CONFIG_I2CTOOL_DEFFREQ=100000 +CONFIG_I2CTOOL_MAXBUS=1 +CONFIG_I2C_RESET=y +CONFIG_I2S_DMADESC_NUM=4 +CONFIG_IDLETHREAD_STACKSIZE=3072 +CONFIG_INIT_ENTRYPOINT="nsh_main" +CONFIG_INIT_STACKSIZE=2048 +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_POSIX_SPAWN_DEFAULT_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_LPWORK=y +CONFIG_SCHED_WAITPID=y +CONFIG_START_DAY=6 +CONFIG_START_MONTH=12 +CONFIG_START_YEAR=2011 +CONFIG_SYSTEM_I2CTOOL=y +CONFIG_SYSTEM_NSH=y +CONFIG_SYSTEM_NSH_STACKSIZE=2048 +CONFIG_SYSTEM_NXPLAYER=y +CONFIG_UART0_SERIAL_CONSOLE=y diff --git a/boards/xtensa/esp32s2/esp32s2-kaluga-1/configs/i2c/defconfig b/boards/xtensa/esp32s2/esp32s2-kaluga-1/configs/i2c/defconfig new file mode 100644 index 00000000000..45d90015d55 --- /dev/null +++ b/boards/xtensa/esp32s2/esp32s2-kaluga-1/configs/i2c/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_ARCH_LEDS 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="esp32s2-kaluga-1" +CONFIG_ARCH_BOARD_COMMON=y +CONFIG_ARCH_BOARD_ESP32S2_KALUGA_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_BOARD_LOOPSPERMSEC=16717 +CONFIG_BUILTIN=y +CONFIG_ESP32S2_I2C0=y +CONFIG_ESP32S2_I2C0_SCLPIN=7 +CONFIG_ESP32S2_I2C0_SDAPIN=8 +CONFIG_ESP32S2_UART0=y +CONFIG_FS_PROCFS=y +CONFIG_HAVE_CXX=y +CONFIG_HAVE_CXXINITIALIZE=y +CONFIG_I2CTOOL_DEFFREQ=100000 +CONFIG_I2CTOOL_MAXBUS=0 +CONFIG_I2C_RESET=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_RR_INTERVAL=200 +CONFIG_SCHED_WAITPID=y +CONFIG_START_DAY=28 +CONFIG_START_MONTH=6 +CONFIG_START_YEAR=2022 +CONFIG_SYSTEM_I2CTOOL=y +CONFIG_SYSTEM_NSH=y +CONFIG_UART0_SERIAL_CONSOLE=y diff --git a/boards/xtensa/esp32s2/esp32s2-kaluga-1/configs/nxlooper/defconfig b/boards/xtensa/esp32s2/esp32s2-kaluga-1/configs/nxlooper/defconfig new file mode 100644 index 00000000000..bd8aa6dc4c5 --- /dev/null +++ b/boards/xtensa/esp32s2/esp32s2-kaluga-1/configs/nxlooper/defconfig @@ -0,0 +1,78 @@ +# +# 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_AUDIO_FORMAT_MP3 is not set +# CONFIG_NSH_ARGCAT is not set +# CONFIG_NSH_CMDOPT_HEXDUMP is not set +CONFIG_ARCH="xtensa" +CONFIG_ARCH_BOARD="esp32s2-kaluga-1" +CONFIG_ARCH_BOARD_COMMON=y +CONFIG_ARCH_BOARD_ESP32S2_KALUGA_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_ES8311=y +CONFIG_AUDIO_EXCLUDE_BALANCE=y +CONFIG_AUDIO_EXCLUDE_FFORWARD=y +CONFIG_AUDIO_EXCLUDE_TONE=y +CONFIG_BOARDCTL_ROMDISK=y +CONFIG_BOARD_LOOPSPERMSEC=16717 +CONFIG_BUILTIN=y +CONFIG_DEFAULT_TASK_STACKSIZE=4096 +CONFIG_DRIVERS_AUDIO=y +CONFIG_ES8311_BUFFER_SIZE=4096 +CONFIG_ES8311_SRC_BCLK=y +CONFIG_ESP32S2_I2C0=y +CONFIG_ESP32S2_I2C0_SCLPIN=7 +CONFIG_ESP32S2_I2C0_SDAPIN=8 +CONFIG_ESP32S2_I2S=y +CONFIG_ESP32S2_I2S_BCLKPIN=18 +CONFIG_ESP32S2_I2S_DATA_BIT_WIDTH_16BIT=y +CONFIG_ESP32S2_I2S_DINPIN=34 +CONFIG_ESP32S2_I2S_DOUTPIN=12 +CONFIG_ESP32S2_I2S_MCLK=y +CONFIG_ESP32S2_I2S_MCLKPIN=35 +CONFIG_ESP32S2_I2S_SAMPLE_RATE=48000 +CONFIG_ESP32S2_I2S_WSPIN=17 +CONFIG_ESP32S2_UART0=y +CONFIG_FS_PROCFS=y +CONFIG_HAVE_CXX=y +CONFIG_HAVE_CXXINITIALIZE=y +CONFIG_I2CTOOL_DEFFREQ=100000 +CONFIG_I2CTOOL_MAXBUS=1 +CONFIG_I2C_RESET=y +CONFIG_I2S_DMADESC_NUM=4 +CONFIG_IDLETHREAD_STACKSIZE=3072 +CONFIG_INIT_ENTRYPOINT="nsh_main" +CONFIG_INIT_STACKSIZE=2048 +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_POSIX_SPAWN_DEFAULT_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_LPWORK=y +CONFIG_SCHED_WAITPID=y +CONFIG_START_DAY=6 +CONFIG_START_MONTH=12 +CONFIG_START_YEAR=2011 +CONFIG_SYSTEM_I2CTOOL=y +CONFIG_SYSTEM_NSH=y +CONFIG_SYSTEM_NSH_STACKSIZE=2048 +CONFIG_SYSTEM_NXLOOPER=y +CONFIG_UART0_SERIAL_CONSOLE=y diff --git a/boards/xtensa/esp32s2/esp32s2-kaluga-1/include/board.h b/boards/xtensa/esp32s2/esp32s2-kaluga-1/include/board.h index f27b866732e..d77fb761a9b 100644 --- a/boards/xtensa/esp32s2/esp32s2-kaluga-1/include/board.h +++ b/boards/xtensa/esp32s2/esp32s2-kaluga-1/include/board.h @@ -75,6 +75,17 @@ #define GPIO_LCD_RST 16 #define GPIO_LCD_BCKL 6 +/* ES8311 Codec */ + +#define ES8311_I2C_CCLK 7 /* SCL */ +#define ES8311_I2C_CDATA 8 /* SDA */ +#define ES8311_I2S_MCLK 35 /* Master clock */ +#define ES8311_I2S_SCLK 18 /* Audio data bit clock */ +#define ES8311_I2S_LRCK 17 /* Audio data left and right clock */ +#define ES8311_I2S_DSDIN 34 /* DAC audio data (to speakers) */ +#define ES8311_I2S_ASDOUT 12 /* ADC audio data (from microphone) */ +#define ES8311_GPIO_PA_EN 10 /* Power amplifier */ + /* LED definitions **********************************************************/ /* Define how many LEDs this board has (needed by userleds) */ @@ -87,4 +98,11 @@ #define BOARD_NGPIOIN 1 /* Amount of GPIO Input without Interruption */ #define BOARD_NGPIOINT 1 /* Amount of GPIO Input w/ Interruption pins */ +/* Peripherals definitions **************************************************/ + +/* ES8311 CODEC */ + +#define ES8311_I2C_FREQ 100000 +#define ES8311_I2C_ADDR 0x18 + #endif /* __BOARDS_XTENSA_ESP32S2_ESP32S2_KALUGA_1_INCLUDE_BOARD_H */ diff --git a/boards/xtensa/esp32s2/esp32s2-kaluga-1/src/esp32s2-kaluga-1.h b/boards/xtensa/esp32s2/esp32s2-kaluga-1/src/esp32s2-kaluga-1.h index 1d51eec7c34..a8e0b2c7708 100644 --- a/boards/xtensa/esp32s2/esp32s2-kaluga-1/src/esp32s2-kaluga-1.h +++ b/boards/xtensa/esp32s2/esp32s2-kaluga-1/src/esp32s2-kaluga-1.h @@ -27,6 +27,7 @@ #include #include + #include /**************************************************************************** @@ -35,6 +36,10 @@ /* ESP32S2-Kaluga-1 GPIOs ***************************************************/ +/* Audio Amplifier */ + +#define SPEAKER_ENABLE_GPIO 10 + /* Buttons */ #define BUTTON_BOOT 0 @@ -144,7 +149,7 @@ int board_i2c_init(void); * * Description: * This function is called by platform-specific, setup logic to configure - * and register the generic I2S audio driver. This function will register + * 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. * @@ -152,14 +157,35 @@ int board_i2c_init(void); * None. * * Returned Value: - * Zero is returned on success. Otherwise, a negated errno value is + * Zero is returned on success. Otherwise, a negated errno value is * returned to indicate the nature of the failure. * ****************************************************************************/ -#if defined(CONFIG_ESP32S2_I2S) && !defined(CONFIG_AUDIO_CS4344) +#if defined(CONFIG_ESP32S2_I2S) && !defined(CONFIG_AUDIO_ES8311) int board_i2sdev_initialize(void); #endif +/**************************************************************************** + * Name: esp32s2_es8311_initialize + * + * Description: + * This function is called by platform-specific, setup logic to configure + * and register the ES8311 device. This function will register the driver + * as /dev/audio/pcm[x] where x is determined by the I2S port number. + * + * Input Parameters: + * i2c_port - The I2C port used for the device; + * i2c_addr - The I2C address used by the device; + * i2c_freq - The I2C frequency used for the device. + * + * Returned Value: + * Zero is returned on success. Otherwise, a negated errno value is + * returned to indicate the nature of the failure. + * + ****************************************************************************/ + +int esp32s2_es8311_initialize(int i2c_port, uint8_t i2c_addr, int i2c_freq); + #endif /* __ASSEMBLY__ */ #endif /* __BOARDS_XTENSA_ESP32S2_ESP32S2_KALUGA_1_SRC_ESP32S2_KALUGA_1_H */ diff --git a/boards/xtensa/esp32s2/esp32s2-kaluga-1/src/esp32s2_bringup.c b/boards/xtensa/esp32s2/esp32s2-kaluga-1/src/esp32s2_bringup.c index c23ceb96044..cb79d5cd70a 100644 --- a/boards/xtensa/esp32s2/esp32s2-kaluga-1/src/esp32s2_bringup.c +++ b/boards/xtensa/esp32s2/esp32s2-kaluga-1/src/esp32s2_bringup.c @@ -34,9 +34,12 @@ #include #include #include - #include + #include +#include + +#include "esp32s2_gpio.h" #ifdef CONFIG_USERLED # include @@ -54,6 +57,10 @@ # include "esp32s2_i2c.h" #endif +#ifdef CONFIG_ESP32_I2S +# include "esp32s2_i2s.h" +#endif + #ifdef CONFIG_ESP32S2_RT_TIMER # include "esp32s2_rt_timer.h" #endif @@ -235,6 +242,28 @@ int esp32s2_bringup(void) } #endif +#ifdef CONFIG_ESP32S2_I2S + + /* Configure I2S0 */ + +#ifdef CONFIG_AUDIO_ES8311 + + /* Configure ES8311 audio on I2C0 and I2S0 */ + + esp32s2_configgpio(SPEAKER_ENABLE_GPIO, OUTPUT); + esp32s2_gpiowrite(SPEAKER_ENABLE_GPIO, true); + + ret = esp32s2_es8311_initialize(ESP32S2_I2C0, ES8311_I2C_ADDR, + ES8311_I2C_FREQ); + if (ret != OK) + { + syslog(LOG_ERR, "Failed to initialize ES8311 audio: %d\n", ret); + } + +#endif /* CONFIG_AUDIO_ES8311 */ + +#endif /* CONFIG_ESP32S2_I2S */ + /* If we got here then perhaps not all initialization was successful, but * at least enough succeeded to bring-up NSH with perhaps reduced * capabilities.