Skip to content

Commit b738379

Browse files
lucasssvazAlan Carvalho de Assis
authored andcommitted
boards/xtensa/esp32s2-kaluga-1: Add support for the ES8311 codec
Adds support for the ES8311 codec on the ESP32-S2-Kaluga-1 board. This commit also adds basic configurations for testing and updates the board documentation.
1 parent 8b9dc54 commit b738379

File tree

12 files changed

+660
-13
lines changed

12 files changed

+660
-13
lines changed

Documentation/platforms/xtensa/esp32/boards/esp32-devkitc/index.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -602,7 +602,7 @@ The ``nxlooper`` application captures data from the audio device with receiving
602602
capabilities (the I2S1 on this example) and forwards the audio data frame to
603603
the audio device with transmitting capabilities (the I2S0 on this example).
604604

605-
After successfully built and flashed, run on the boards's terminal::
605+
After successfully built and flashed, run on the boards' terminal::
606606

607607
nsh> nxlooper
608608
nxlooper> loopback

Documentation/platforms/xtensa/esp32s2/boards/esp32s2-kaluga-1/index.rst

Lines changed: 63 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -180,11 +180,41 @@ Configurations
180180
All of the configurations presented below can be tested by running the following commands::
181181

182182
$ ./tools/configure.sh esp32s2-kaluga-1:<config_name>
183-
$ make flash ESPTOOL_PORT=/dev/ttyUSB0 -j
183+
$ make flash ESPTOOL_PORT=/dev/ttyUSB1 -j
184184

185185
Where <config_name> is the name of board configuration you want to use, i.e.: nsh, buttons, wifi...
186186
Then use a serial console terminal like ``picocom`` configured to 115200 8N1.
187187

188+
audio
189+
-----
190+
191+
This configuration uses the I2S peripheral and the ES8311 audio
192+
codec to play an audio file. The easiest way of playing an uncompressed file
193+
is embedding into the firmware. This configuration selects
194+
`romfs example <https://github.com/apache/nuttx-apps/tree/master/examples/romfs>`__
195+
to allow that.
196+
197+
**ROMFS example**
198+
199+
Prepare and build the ``audio`` defconfig::
200+
201+
$ make -j distclean && ./tools/configure.sh esp32s2-kaluga-1:audio && make
202+
203+
This will create a temporary folder in ``apps/examples/romfs/testdir``. Move
204+
a PCM-encoded (``.wav``) audio file with 16 or 24 bits/sample (sampled at 16~48kHz)
205+
to this folder.
206+
207+
.. note:: You can use :download:`this 440 Hz sinusoidal tone <tone.wav>`.
208+
The audio file should be located at ``apps/examples/romfs/testdir/tone.wav``
209+
210+
Build the project again and flash it (make sure not to clean it, just build)
211+
212+
After successfully built and flashed, load the romfs and play it::
213+
214+
nsh> romfs
215+
nsh> nxplayer
216+
nxplayer> play /usr/share/local/tone.wav
217+
188218
buttons
189219
-------
190220

@@ -210,6 +240,14 @@ the ``buttons`` application and pressing on any of the available board buttons a
210240
Sample = 64
211241
Sample = 0
212242

243+
i2c
244+
---
245+
246+
This configuration can be used to scan and manipulate I2C devices.
247+
You can scan for all I2C devices using the following command::
248+
249+
nsh> i2c dev 0x00 0x7f
250+
213251
lvgl_ili9341
214252
------------
215253

@@ -219,8 +257,8 @@ driver with the ILI9341 display. You can find LVGL here::
219257
https://www.lvgl.io/
220258
https://github.com/lvgl/lvgl
221259

222-
This configuration uses the LVGL demonstration at `apps/examples/lvgldemo` and
223-
can be executed by running the `lvgldemo` application.
260+
This configuration uses the LVGL demonstration at ``apps/examples/lvgldemo`` and
261+
can be executed by running the ``lvgldemo`` application.
224262

225263
lvgl_st7789
226264
-----------
@@ -231,11 +269,30 @@ driver with the ST7799 display. You can find LVGL here::
231269
https://www.lvgl.io/
232270
https://github.com/lvgl/lvgl
233271

234-
This configuration uses the LVGL demonstration at `apps/examples/lvgldemo` and
235-
can be executed by running the `lvgldemo` application.
272+
This configuration uses the LVGL demonstration at ``apps/examples/lvgldemo`` and
273+
can be executed by running the ``lvgldemo`` application.
236274

237275
nsh
238276
---
239277

240278
Basic NuttShell configuration (console enabled in UART0, exposed via
241-
USB connection by means of CP2102 converter, at 115200 bps).
279+
USB connection by means of CP2102 converter, at 115200 bps).
280+
281+
nxlooper
282+
--------
283+
284+
The ``nxlooper`` application captures data from the audio device with receiving
285+
capabilities and forwards the audio data frame to the audio device with transmitting
286+
capabilities.
287+
288+
After successfully built and flashed, run on the boards' terminal::
289+
290+
nsh> nxlooper
291+
nxlooper> loopback
292+
293+
.. note:: ``loopback`` command default arguments for the channel configuration,
294+
the data width and the sample rate are, respectively, 2 channels,
295+
16 bits/sample and 48KHz. These arguments can be supplied to select
296+
different audio formats, for instance::
297+
298+
nxlooper> loopback 2 8 44100
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
/****************************************************************************
2+
* boards/xtensa/esp32s2/common/include/esp32s2_es8311.h
3+
*
4+
* Licensed to the Apache Software Foundation (ASF) under one or more
5+
* contributor license agreements. See the NOTICE file distributed with
6+
* this work for additional information regarding copyright ownership. The
7+
* ASF licenses this file to you under the Apache License, Version 2.0 (the
8+
* "License"); you may not use this file except in compliance with the
9+
* License. You may obtain a copy of the License at
10+
*
11+
* http://www.apache.org/licenses/LICENSE-2.0
12+
*
13+
* Unless required by applicable law or agreed to in writing, software
14+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
15+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
16+
* License for the specific language governing permissions and limitations
17+
* under the License.
18+
*
19+
****************************************************************************/
20+
21+
#ifndef __BOARDS_XTENSA_ESP32S2_COMMON_INCLUDE_ESP32S2_ES8311_H
22+
#define __BOARDS_XTENSA_ESP32S2_COMMON_INCLUDE_ESP32S2_ES8311_H
23+
24+
/****************************************************************************
25+
* Included Files
26+
****************************************************************************/
27+
28+
#include <nuttx/config.h>
29+
30+
#include <stdint.h>
31+
32+
/****************************************************************************
33+
* Pre-processor Definitions
34+
****************************************************************************/
35+
36+
/****************************************************************************
37+
* Type Definitions
38+
****************************************************************************/
39+
40+
/****************************************************************************
41+
* Public Types
42+
****************************************************************************/
43+
44+
/****************************************************************************
45+
* Public Data
46+
****************************************************************************/
47+
48+
#ifdef __cplusplus
49+
#define EXTERN extern "C"
50+
extern "C"
51+
{
52+
#else
53+
#define EXTERN extern
54+
#endif
55+
56+
/****************************************************************************
57+
* Inline Functions
58+
****************************************************************************/
59+
60+
/****************************************************************************
61+
* Public Function Prototypes
62+
****************************************************************************/
63+
64+
/****************************************************************************
65+
* Name: esp32s2_es8311_initialize
66+
*
67+
* Description:
68+
* This function is called by platform-specific, setup logic to configure
69+
* and register the ES8311 device. This function will register the driver
70+
* as /dev/audio/pcm[x] where x is determined by the I2S port number.
71+
*
72+
* Input Parameters:
73+
* i2c_port - The I2C port used for the device;
74+
* i2c_addr - The I2C address used by the device;
75+
* i2c_freq - The I2C frequency used for the device.
76+
*
77+
* Returned Value:
78+
* Zero is returned on success. Otherwise, a negated errno value is
79+
* returned to indicate the nature of the failure.
80+
*
81+
****************************************************************************/
82+
83+
int esp32s2_es8311_initialize(int i2c_port, uint8_t i2c_addr, int i2c_freq);
84+
85+
#undef EXTERN
86+
#ifdef __cplusplus
87+
}
88+
#endif
89+
90+
#endif /* __BOARDS_XTENSA_ESP32S2_COMMON_INCLUDE_ESP32S2_ES8311_H */

boards/xtensa/esp32s2/common/src/Make.defs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,10 @@ ifeq ($(CONFIG_LCD_ST7789),y)
4444
CSRCS += esp32s2_st7789.c
4545
endif
4646

47+
ifeq ($(CONFIG_AUDIO_ES8311),y)
48+
CSRCS += esp32s2_es8311.c
49+
endif
50+
4751
DEPPATH += --dep-path src
4852
VPATH += :src
4953
CFLAGS += $(shell $(INCDIR) "$(CC)" $(TOPDIR)$(DELIM)arch$(DELIM)$(CONFIG_ARCH)$(DELIM)src$(DELIM)board$(DELIM)src)

boards/xtensa/esp32s2/common/src/esp32s2_board_i2sdev.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@
3737

3838
#include "esp32s2_i2s.h"
3939

40-
#if defined(CONFIG_ESP32S2_I2S) && !defined(CONFIG_AUDIO_CS4344)
40+
#if defined(CONFIG_ESP32S2_I2S) && !defined(CONFIG_AUDIO_CS4344) && \
41+
!defined(CONFIG_AUDIO_ES8311)
4142

4243
/****************************************************************************
4344
* Public Functions
@@ -152,4 +153,5 @@ int board_i2sdev_initialize(bool enable_tx, bool enable_rx)
152153
return ret;
153154
}
154155

155-
#endif /* (CONFIG_ESP32S2_I2S) && !defined (CONFIG_AUDIO_CS4344) */
156+
#endif /* (CONFIG_ESP32S2_I2S) && !(CONFIG_AUDIO_CS4344) *
157+
* !(CONFIG_AUDIO_ES8311) */

0 commit comments

Comments
 (0)