drivers/audio: Add support for the ES8311 codec

Adds support for the ES8311 audio codec by Everest Semiconductor on NuttX. Both output and input are supported.
This commit is contained in:
Lucas Saavedra Vaz 2023-05-04 14:57:15 -03:00 committed by Alan Carvalho de Assis
parent 58f59fe9dc
commit 8b9dc54a0a
6 changed files with 4003 additions and 0 deletions

View File

@ -206,6 +206,63 @@ config CS4344_WORKER_STACKSIZE
endif # AUDIO_CS4344
config AUDIO_ES8311
bool "ES8311 codec chip"
default n
depends on AUDIO
---help---
Select to enable support for the ES8311 Audio codec by Everest
Semiconductor.
NOTE: This driver also depends on both I2C and I2S support although
that dependency is not explicit here.
if AUDIO_ES8311
config ES8311_INPUT_INITVOLUME
int "ES8311 initial input volume setting"
default 1000
config ES8311_OUTPUT_INITVOLUME
int "ES8311 initial output volume setting"
default 400
choice
prompt "MCLK source"
default ES8311_SRC_MCLK
---help---
Select the source of the MCLK signal.
config ES8311_SRC_MCLK
bool "From MCLK Pin"
config ES8311_SRC_BCLK
bool "From BCLK Pin"
endchoice
config ES8311_INFLIGHT
int "ES8311 maximum in-flight audio buffers"
default 2
config ES8311_MSG_PRIO
int "ES8311 message priority"
default 1
config ES8311_BUFFER_SIZE
int "ES8311 preferred buffer size"
default 8192
config ES8311_NUM_BUFFERS
int "ES8311 preferred number of buffers"
default 4
config ES8311_WORKER_STACKSIZE
int "ES8311 worker thread stack size"
default 2048
endif # AUDIO_ES8388
config AUDIO_ES8388
bool "ES8388 codec chip"
default n

View File

@ -48,6 +48,13 @@ ifeq ($(CONFIG_AUDIO_CS4344),y)
CSRCS += cs4344.c
endif
ifeq ($(CONFIG_AUDIO_ES8311),y)
CSRCS += es8311.c
ifeq ($(CONFIG_ES8311_REGDUMP),y)
CSRCS += es8311_debug.c
endif
endif
ifeq ($(CONFIG_AUDIO_ES8388),y)
CSRCS += es8388.c
ifeq ($(CONFIG_ES8388_REGDUMP),y)

2292
drivers/audio/es8311.c Normal file

File diff suppressed because it is too large Load Diff

1312
drivers/audio/es8311.h Normal file

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,144 @@
/****************************************************************************
* drivers/audio/es8311_debug.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.
*
****************************************************************************/
/* The framework for this driver is based on ESP-ADF's ES8311 driver. */
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <stdint.h>
#include <syslog.h>
#include <nuttx/audio/audio.h>
#include <nuttx/audio/es8311.h>
#include "es8311.h"
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
/****************************************************************************
* Private Types
****************************************************************************/
#ifdef CONFIG_ES8311_REGDUMP
struct es8311_regdump_s
{
FAR const char *regname;
uint8_t regaddr;
};
#endif
/****************************************************************************
* Private Function Prototypes
****************************************************************************/
/****************************************************************************
* Private Data
****************************************************************************/
#ifdef CONFIG_ES8311_REGDUMP
static const struct es8311_regdump_s g_es8311_debug[] =
{
{"ES8311_RESET_REG00", ES8311_RESET_REG00 },
{"ES8311_CLK_MANAGER_REG01", ES8311_CLK_MANAGER_REG01 },
{"ES8311_CLK_MANAGER_REG02", ES8311_CLK_MANAGER_REG02 },
{"ES8311_CLK_MANAGER_REG03", ES8311_CLK_MANAGER_REG03 },
{"ES8311_CLK_MANAGER_REG04", ES8311_CLK_MANAGER_REG04 },
{"ES8311_CLK_MANAGER_REG05", ES8311_CLK_MANAGER_REG05 },
{"ES8311_CLK_MANAGER_REG06", ES8311_CLK_MANAGER_REG06 },
{"ES8311_CLK_MANAGER_REG07", ES8311_CLK_MANAGER_REG07 },
{"ES8311_CLK_MANAGER_REG08", ES8311_CLK_MANAGER_REG08 },
{"ES8311_SDPIN_REG09", ES8311_SDPIN_REG09 },
{"ES8311_SDPOUT_REG0A", ES8311_SDPOUT_REG0A },
{"ES8311_SYSTEM_REG0B", ES8311_SYSTEM_REG0B },
{"ES8311_SYSTEM_REG0B", ES8311_SYSTEM_REG0B },
{"ES8311_SYSTEM_REG0C", ES8311_SYSTEM_REG0C },
{"ES8311_SYSTEM_REG0D", ES8311_SYSTEM_REG0D },
{"ES8311_SYSTEM_REG0E", ES8311_SYSTEM_REG0E },
{"ES8311_SYSTEM_REG0F", ES8311_SYSTEM_REG0F },
{"ES8311_SYSTEM_REG10", ES8311_SYSTEM_REG10 },
{"ES8311_SYSTEM_REG11", ES8311_SYSTEM_REG11 },
{"ES8311_SYSTEM_REG12", ES8311_SYSTEM_REG12 },
{"ES8311_SYSTEM_REG13", ES8311_SYSTEM_REG13 },
{"ES8311_SYSTEM_REG14", ES8311_SYSTEM_REG14 },
{"ES8311_ADC_REG15", ES8311_ADC_REG15 },
{"ES8311_ADC_REG16", ES8311_ADC_REG16 },
{"ES8311_ADC_REG17", ES8311_ADC_REG17 },
{"ES8311_ADC_REG18", ES8311_ADC_REG18 },
{"ES8311_ADC_REG19", ES8311_ADC_REG19 },
{"ES8311_ADC_REG1A", ES8311_ADC_REG1A },
{"ES8311_ADC_REG1B", ES8311_ADC_REG1B },
{"ES8311_ADC_REG1C", ES8311_ADC_REG1C },
{"ES8311_DAC_REG31", ES8311_DAC_REG31 },
{"ES8311_DAC_REG32", ES8311_DAC_REG32 },
{"ES8311_DAC_REG33", ES8311_DAC_REG33 },
{"ES8311_DAC_REG34", ES8311_DAC_REG34 },
{"ES8311_DAC_REG35", ES8311_DAC_REG35 },
{"ES8311_DAC_REG37", ES8311_DAC_REG37 },
{"ES8311_GPIO_REG44", ES8311_GPIO_REG44 },
{"ES8311_GP_REG45", ES8311_GP_REG45 },
{"ES8311_CHD1_REGFD", ES8311_CHD1_REGFD },
{"ES8311_CHD2_REGFE", ES8311_CHD2_REGFE },
{"ES8311_CHVER_REGFF", ES8311_CHVER_REGFF }
};
# define ES8311_NREGISTERS (sizeof(g_es8311_debug) / sizeof(struct es8311_regdump_s))
#endif /* CONFIG_ES8311_REGDUMP */
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: es8311_dump_registers
*
* Description:
* Dump the contents of all ES8311 registers to the syslog device
*
* Input Parameters:
* dev - The device instance returned by es8311_initialize
* msg - Message to appear before registers
*
* Returned Value:
* None.
*
****************************************************************************/
#ifdef CONFIG_ES8311_REGDUMP
void es8311_dump_registers(FAR struct audio_lowerhalf_s *dev,
FAR const char *msg)
{
int i;
syslog(LOG_INFO, "ES8311 Registers: %s\n", msg);
for (i = 0; i < ES8311_NREGISTERS; i++)
{
syslog(LOG_INFO, " %s[%02x]: %02x\n",
g_es8311_debug[i].regname, g_es8311_debug[i].regaddr,
es8311_readreg((FAR struct es8311_dev_s *)dev,
g_es8311_debug[i].regaddr));
}
}
#endif /* CONFIG_ES8311_REGDUMP */

View File

@ -0,0 +1,191 @@
/****************************************************************************
* include/nuttx/audio/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 __INCLUDE_NUTTX_AUDIO_ES8311_H
#define __INCLUDE_NUTTX_AUDIO_ES8311_H
/****************************************************************************
* Included Files
****************************************************************************/
#include <stdint.h>
#include <stdbool.h>
#include <nuttx/irq.h>
#ifdef CONFIG_AUDIO_ES8311
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
/* Configuration ************************************************************
*
* CONFIG_AUDIO_ES8311 - Enables ES8311 support
* CONFIG_ES8311_INITVOLUME - The initial volume level
* in the range {0..1000}
* CONFIG_ES8311_INFLIGHT - Maximum number of buffers that the ES8311
* driver will send to the I2S driver before any have completed.
* CONFIG_ES8311_MSG_PRIO - Priority of messages sent to the ES8311
* worker thread.
* CONFIG_ES8311_BUFFER_SIZE - Preferred buffer size
* CONFIG_ES8311_NUM_BUFFERS - Preferred number of buffers
* CONFIG_ES8311_WORKER_STACKSIZE - Stack size to use when creating the the
* ES8311 worker thread.
* CONFIG_ES8311_REGDUMP - Enable logic to dump all ES8311 registers to
* the SYSLOG device.
*/
/* Pre-requisites */
#ifndef CONFIG_AUDIO
# error CONFIG_AUDIO is required for audio subsystem support
#endif
#ifndef CONFIG_I2S
# error CONFIG_I2S is required by the ES8311 driver
#endif
#ifndef CONFIG_I2C
# error CONFIG_I2C is required by the ES8311 driver
#endif
#ifndef CONFIG_SCHED_WORKQUEUE
# error CONFIG_SCHED_WORKQUEUE is required by the ES8311 driver
#endif
/* Default configuration values */
#ifndef CONFIG_ES8311_INPUT_INITVOLUME
# define CONFIG_ES8311_INPUT_INITVOLUME 1000
#endif
#ifndef CONFIG_ES8311_OUTPUT_INITVOLUME
# define CONFIG_ES8311_OUTPUT_INITVOLUME 400
#endif
#ifndef CONFIG_ES8311_INFLIGHT
# define CONFIG_ES8311_INFLIGHT 2
#endif
#if CONFIG_ES8311_INFLIGHT > 255
# error CONFIG_ES8311_INFLIGHT must fit in a uint8_t
#endif
#ifndef CONFIG_ES8311_MSG_PRIO
# define CONFIG_ES8311_MSG_PRIO 1
#endif
#ifndef CONFIG_ES8311_BUFFER_SIZE
# define CONFIG_ES8311_BUFFER_SIZE 4096
#endif
#ifndef CONFIG_ES8311_NUM_BUFFERS
# define CONFIG_ES8311_NUM_BUFFERS 4
#endif
#ifndef CONFIG_ES8311_WORKER_STACKSIZE
# define CONFIG_ES8311_WORKER_STACKSIZE 2048
#endif
/****************************************************************************
* Public Types
****************************************************************************/
struct es8311_lower_s;
struct es8311_lower_s
{
/* I2C characterization */
uint32_t frequency; /* Initial I2C frequency */
uint8_t address; /* 7-bit I2C address (only bits 0-6 used) */
};
/****************************************************************************
* Public Data
****************************************************************************/
#ifdef __cplusplus
#define EXTERN extern "C"
extern "C"
{
#else
#define EXTERN extern
#endif
/****************************************************************************
* Public Function Prototypes
****************************************************************************/
/****************************************************************************
* Name: es8311_initialize
*
* Description:
* Initialize the ES8311 device.
*
* Input Parameters:
* i2c - An I2C driver instance;
* i2s - An I2S driver instance;
* lower - Persistent board configuration data.
*
* Returned Value:
* A new lower half audio interface for the ES8311 device is returned on
* success; NULL is returned on failure.
*
****************************************************************************/
struct i2c_master_s;
struct i2s_dev_s;
struct audio_lowerhalf_s;
FAR struct audio_lowerhalf_s *
es8311_initialize(FAR struct i2c_master_s *i2c,
FAR struct i2s_dev_s *i2s,
FAR const struct es8311_lower_s *lower);
/****************************************************************************
* Name: es8311_dump_registers
*
* Description:
* Dump the contents of all ES8311 registers to the syslog device
*
* Input Parameters:
* dev - The device instance returned by es8311_initialize
*
* Returned Value:
* None.
*
****************************************************************************/
#ifdef CONFIG_ES8311_REGDUMP
void es8311_dump_registers(FAR struct audio_lowerhalf_s *dev,
FAR const char *msg);
#else
# define es8311_dump_registers(d,m)
#endif
#undef EXTERN
#ifdef __cplusplus
}
#endif
#endif /* CONFIG_AUDIO_ES8311 */
#endif /* __INCLUDE_NUTTX_AUDIO_ES8311_H */