audio: Add support for the ES8388 codec (output)

This commit is contained in:
Lucas Saavedra Vaz 2022-11-07 14:07:16 -03:00 committed by Alan Carvalho de Assis
parent 6bd285814d
commit fa0ccce046
7 changed files with 4043 additions and 0 deletions

View File

@ -206,6 +206,56 @@ config CS4344_WORKER_STACKSIZE
endif # AUDIO_CS4344
config AUDIO_ES8388
bool "ES8388 codec chip"
default n
depends on AUDIO
---help---
Select to enable support for the ES8388 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_ES8388
config ES8388_INPUT_INITVOLUME
int "ES8388 initial input volume setting"
default 1000
config ES8388_OUTPUT_INITVOLUME
int "ES8388 initial output volume setting"
default 400
config ES8388_INFLIGHT
int "ES8388 maximum in-flight audio buffers"
default 2
config ES8388_MSG_PRIO
int "ES8388 message priority"
default 1
config ES8388_BUFFER_SIZE
int "ES8388 preferred buffer size"
default 8192
config ES8388_NUM_BUFFERS
int "ES8388 preferred number of buffers"
default 4
config ES8388_WORKER_STACKSIZE
int "ES8388 worker thread stack size"
default 2048
config ES8388_REGDUMP
bool "ES8388 register dump"
default n
depends on DEBUG_FEATURES
---help---
Enable logic to dump the contents of all ES8388 registers.
endif # AUDIO_ES8388
config AUDIO_WM8776
bool "WM8776 audio chip"
default n

View File

@ -48,6 +48,13 @@ ifeq ($(CONFIG_AUDIO_CS4344),y)
CSRCS += cs4344.c
endif
ifeq ($(CONFIG_AUDIO_ES8388),y)
CSRCS += es8388.c
ifeq ($(CONFIG_ES8388_REGDUMP),y)
CSRCS += es8388_debug.c
endif
endif
ifeq ($(CONFIG_AUDIO_WM8994),y)
CSRCS += wm8994.c
ifeq ($(CONFIG_WM8994_REGDUMP),y)

2428
drivers/audio/es8388.c Normal file

File diff suppressed because it is too large Load Diff

1179
drivers/audio/es8388.h Normal file

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,163 @@
/****************************************************************************
* drivers/audio/es8388_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.
*
****************************************************************************/
/* References:
* - "ES8388 Low Power Stereo Audio CODEC With Headphone Amplifier",
* July 2018, Rev 5.0, Everest Semiconductor
* - The framework for this driver is based on Taras Drozdovsky's CS43L22
* driver.
*/
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <stdint.h>
#include <assert.h>
#include <fixedmath.h>
#include <syslog.h>
#include <nuttx/audio/audio.h>
#include <nuttx/audio/es8388.h>
#include "es8388.h"
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
/****************************************************************************
* Private Types
****************************************************************************/
#ifdef CONFIG_ES8388_REGDUMP
struct es8388_regdump_s
{
FAR const char *regname;
uint8_t regaddr;
};
#endif
/****************************************************************************
* Private Function Prototypes
****************************************************************************/
/****************************************************************************
* Private Data
****************************************************************************/
#ifdef CONFIG_ES8388_REGDUMP
static const struct es8388_regdump_s g_es8388_debug[] =
{
{"Chip Control 1", ES8388_CONTROL1 },
{"Chip Control 2", ES8388_CONTROL2 },
{"Chip Power Management", ES8388_CHIPPOWER },
{"ADC Power Management", ES8388_ADCPOWER },
{"DAC Power Management", ES8388_DACPOWER },
{"Chip Low Power 1", ES8388_CHIPLOPOW1 },
{"Chip Low Power 2", ES8388_CHIPLOPOW2 },
{"Analog Volume Management", ES8388_ANAVOLMANAG },
{"Master Mode Control", ES8388_MASTERMODE },
{"ADC Control 1", ES8388_ADCCONTROL1 },
{"ADC Control 2", ES8388_ADCCONTROL2 },
{"ADC Control 3", ES8388_ADCCONTROL3 },
{"ADC Control 4", ES8388_ADCCONTROL4 },
{"ADC Control 5", ES8388_ADCCONTROL5 },
{"ADC Control 6", ES8388_ADCCONTROL6 },
{"ADC Control 7", ES8388_ADCCONTROL7 },
{"ADC Control 8", ES8388_ADCCONTROL8 },
{"ADC Control 9", ES8388_ADCCONTROL9 },
{"ADC Control 10", ES8388_ADCCONTROL10 },
{"ADC Control 11", ES8388_ADCCONTROL11 },
{"ADC Control 12", ES8388_ADCCONTROL12 },
{"ADC Control 13", ES8388_ADCCONTROL13 },
{"ADC Control 14", ES8388_ADCCONTROL14 },
{"DAC Control 1", ES8388_DACCONTROL1 },
{"DAC Control 2", ES8388_DACCONTROL2 },
{"DAC Control 3", ES8388_DACCONTROL3 },
{"DAC Control 4", ES8388_DACCONTROL4 },
{"DAC Control 5", ES8388_DACCONTROL5 },
{"DAC Control 6", ES8388_DACCONTROL6 },
{"DAC Control 7", ES8388_DACCONTROL7 },
{"DAC Control 8", ES8388_DACCONTROL8 },
{"DAC Control 9", ES8388_DACCONTROL9 },
{"DAC Control 10", ES8388_DACCONTROL10 },
{"DAC Control 11", ES8388_DACCONTROL11 },
{"DAC Control 12", ES8388_DACCONTROL12 },
{"DAC Control 13", ES8388_DACCONTROL13 },
{"DAC Control 14", ES8388_DACCONTROL14 },
{"DAC Control 15", ES8388_DACCONTROL15 },
{"DAC Control 16", ES8388_DACCONTROL16 },
{"DAC Control 17", ES8388_DACCONTROL17 },
{"DAC Control 18", ES8388_DACCONTROL18 },
{"DAC Control 19", ES8388_DACCONTROL19 },
{"DAC Control 20", ES8388_DACCONTROL20 },
{"DAC Control 21", ES8388_DACCONTROL21 },
{"DAC Control 22", ES8388_DACCONTROL22 },
{"DAC Control 23", ES8388_DACCONTROL23 },
{"DAC Control 24", ES8388_DACCONTROL24 },
{"DAC Control 25", ES8388_DACCONTROL25 },
{"DAC Control 26", ES8388_DACCONTROL26 },
{"DAC Control 27", ES8388_DACCONTROL27 },
{"DAC Control 28", ES8388_DACCONTROL28 },
{"DAC Control 29", ES8388_DACCONTROL29 },
{"DAC Control 30", ES8388_DACCONTROL30 },
};
# define ES8388_NREGISTERS (sizeof(g_es8388_debug) / sizeof(struct es8388_regdump_s))
#endif /* CONFIG_ES8388_REGDUMP */
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: es8388_dump_registers
*
* Description:
* Dump the contents of all ES8388 registers to the syslog device
*
* Input Parameters:
* dev - The device instance returned by es8388_initialize
* msg - Message to appear before registers
*
* Returned Value:
* None.
*
****************************************************************************/
#ifdef CONFIG_ES8388_REGDUMP
void es8388_dump_registers(FAR struct audio_lowerhalf_s *dev,
FAR const char *msg)
{
int i;
syslog(LOG_INFO, "ES8388 Registers: %s\n", msg);
for (i = 0; i < ES8388_NREGISTERS; i++)
{
syslog(LOG_INFO, " %s[%02x]: %02x\n",
g_es8388_debug[i].regname, g_es8388_debug[i].regaddr,
es8388_readreg((FAR struct es8388_dev_s *)dev,
g_es8388_debug[i].regaddr));
}
}
#endif /* CONFIG_ES8388_REGDUMP */

View File

@ -232,6 +232,31 @@
#define AUDIO_BIT_RATE_172K 0x40
#define AUDIO_BIT_RATE_192K 0x80
/* Audio Volume Limits ******************************************************/
/* As nxplayer passes a value in the range (0..1000) to the ioctl, all audio
* drivers that implement volume expect a value from 0 to 1000 from the ioctl
*/
#define AUDIO_VOLUME_MAX 1000
#define AUDIO_VOLUME_MAX_FLOAT 1000.0f
#define AUDIO_VOLUME_MIN 0
#define AUDIO_VOLUME_MIN_FLOAT 0.0f
/* Audio Balance Limits *****************************************************/
/* As nxplayer passes a value in the range (0..1000) to the ioctl, all audio
* drivers that implement balance expect a value from 0 to 1000 from the
* ioctl
*/
#define AUDIO_BALANCE_RIGHT 1000
#define AUDIO_BALANCE_RIGHT_FLOAT 1000.0f
#define AUDIO_BALANCE_CENTER 500
#define AUDIO_BALANCE_CENTER_FLOAT 500.0f
#define AUDIO_BALANCE_LEFT 0
#define AUDIO_BALANCE_LEFT_FLOAT 0.0f
/* Supported Feature Units controls *****************************************/
#define AUDIO_FU_UNDEF 0x0000

View File

@ -0,0 +1,191 @@
/****************************************************************************
* include/nuttx/audio/es8388.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_ES8388_H
#define __INCLUDE_NUTTX_AUDIO_ES8388_H
/****************************************************************************
* Included Files
****************************************************************************/
#include <stdint.h>
#include <stdbool.h>
#include <nuttx/irq.h>
#ifdef CONFIG_AUDIO_ES8388
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
/* Configuration ************************************************************
*
* CONFIG_AUDIO_ES8388 - Enables ES8388 support
* CONFIG_ES8388_INITVOLUME - The initial volume level
* in the range {0..1000}
* CONFIG_ES8388_INFLIGHT - Maximum number of buffers that the ES8388
* driver will send to the I2S driver before any have completed.
* CONFIG_ES8388_MSG_PRIO - Priority of messages sent to the ES8388
* worker thread.
* CONFIG_ES8388_BUFFER_SIZE - Preferred buffer size
* CONFIG_ES8388_NUM_BUFFERS - Preferred number of buffers
* CONFIG_ES8388_WORKER_STACKSIZE - Stack size to use when creating the the
* ES8388 worker thread.
* CONFIG_ES8388_REGDUMP - Enable logic to dump all ES8388 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 ES8388 driver
#endif
#ifndef CONFIG_I2C
# error CONFIG_I2C is required by the ES8388 driver
#endif
#ifndef CONFIG_SCHED_WORKQUEUE
# error CONFIG_SCHED_WORKQUEUE is required by the ES8388 driver
#endif
/* Default configuration values */
#ifndef CONFIG_ES8388_INPUT_INITVOLUME
# define CONFIG_ES8388_INPUT_INITVOLUME 1000
#endif
#ifndef CONFIG_ES8388_OUTPUT_INITVOLUME
# define CONFIG_ES8388_OUTPUT_INITVOLUME 400
#endif
#ifndef CONFIG_ES8388_INFLIGHT
# define CONFIG_ES8388_INFLIGHT 2
#endif
#if CONFIG_ES8388_INFLIGHT > 255
# error CONFIG_ES8388_INFLIGHT must fit in a uint8_t
#endif
#ifndef CONFIG_ES8388_MSG_PRIO
# define CONFIG_ES8388_MSG_PRIO 1
#endif
#ifndef CONFIG_ES8388_BUFFER_SIZE
# define CONFIG_ES8388_BUFFER_SIZE 8192
#endif
#ifndef CONFIG_ES8388_NUM_BUFFERS
# define CONFIG_ES8388_NUM_BUFFERS 4
#endif
#ifndef CONFIG_ES8388_WORKER_STACKSIZE
# define CONFIG_ES8388_WORKER_STACKSIZE 2048
#endif
/****************************************************************************
* Public Types
****************************************************************************/
struct es8388_lower_s;
struct es8388_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: es8388_initialize
*
* Description:
* Initialize the ES8388 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 ES8388 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 *
es8388_initialize(FAR struct i2c_master_s *i2c,
FAR struct i2s_dev_s *i2s,
FAR const struct es8388_lower_s *lower);
/****************************************************************************
* Name: es8388_dump_registers
*
* Description:
* Dump the contents of all ES8388 registers to the syslog device
*
* Input Parameters:
* dev - The device instance returned by es8388_initialize
*
* Returned Value:
* None.
*
****************************************************************************/
#ifdef CONFIG_ES8388_REGDUMP
void es8388_dump_registers(FAR struct audio_lowerhalf_s *dev,
FAR const char *msg);
#else
# define es8388_dump_registers(d,m)
#endif
#undef EXTERN
#ifdef __cplusplus
}
#endif
#endif /* CONFIG_AUDIO_ES8388 */
#endif /* __INCLUDE_NUTTX_AUDIO_ES8388_H */