* drivers/audio/es8311.h
*
* SPDX-License-Identifier: Apache-2.0
*
* 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 __DRIVERS_AUDIO_ES8311_H
#define __DRIVERS_AUDIO_ES8311_H
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <nuttx/compiler.h>
#include <pthread.h>
#include <nuttx/mqueue.h>
#include <nuttx/wqueue.h>
#include <nuttx/fs/ioctl.h>
#include "esxxxx_common.h"
#ifdef CONFIG_AUDIO
* Pre-processor Definitions
****************************************************************************/
#define ES8311_RESET_REG00 0x00
#define ES8311_CLK_MANAGER_REG01 0x01
#define ES8311_CLK_MANAGER_REG02 0x02
#define ES8311_CLK_MANAGER_REG03 0x03
#define ES8311_CLK_MANAGER_REG04 0x04
#define ES8311_CLK_MANAGER_REG05 0x05
#define ES8311_CLK_MANAGER_REG06 0x06
#define ES8311_CLK_MANAGER_REG07 0x07
#define ES8311_CLK_MANAGER_REG08 0x08
#define ES8311_SDPIN_REG09 0x09
#define ES8311_SDPOUT_REG0A 0x0a
#define ES8311_SYSTEM_REG0B 0x0b
#define ES8311_SYSTEM_REG0C 0x0c
#define ES8311_SYSTEM_REG0D 0x0d
#define ES8311_SYSTEM_REG0E 0x0e
#define ES8311_SYSTEM_REG0F 0x0f
#define ES8311_SYSTEM_REG10 0x10
#define ES8311_SYSTEM_REG11 0x11
#define ES8311_SYSTEM_REG12 0x12
#define ES8311_SYSTEM_REG13 0x13
#define ES8311_SYSTEM_REG14 0x14
#define ES8311_ADC_REG15 0x15
#define ES8311_ADC_REG16 0x16
#define ES8311_ADC_REG17 0x17
#define ES8311_ADC_REG18 0x18
#define ES8311_ADC_REG19 0x19
#define ES8311_ADC_REG1A 0x1a
#define ES8311_ADC_REG1B 0x1b
#define ES8311_ADC_REG1C 0x1c
#define ES8311_DAC_REG31 0x31
#define ES8311_DAC_REG32 0x32
#define ES8311_DAC_REG33 0x33
#define ES8311_DAC_REG34 0x34
#define ES8311_DAC_REG35 0x35
#define ES8311_DAC_REG37 0x37
#define ES8311_GPIO_REG44 0x44
#define ES8311_GP_REG45 0x45
#define ES8311_CHD1_REGFD 0xfd
#define ES8311_CHD2_REGFE 0xfe
#define ES8311_CHVER_REGFF 0xff
#define ES8311_MAX_REGISTER 0xff
#define ES8311_DEFAULT_SAMPRATE 48000
#define ES8311_DEFAULT_BPSAMP 16
* Public Types
****************************************************************************/
struct es8311_dev_s
{
* the ES8311 driver with respect to the board lower half driver).
*
* Terminology:
* Our "lower" half audio instances will be called dev for the publicly
* visible version and "priv" for the version that only this driver knows
* From the point of view of this driver, it is the board lower "half"
* that is referred to as "lower".
*/
struct audio_lowerhalf_s dev;
FAR const struct es8311_lower_s *lower;
FAR struct i2c_master_s *i2c;
FAR struct i2s_dev_s *i2s;
struct dq_queue_s pendq;
struct dq_queue_s doneq;
struct file mq;
char mqname[NAME_MAX];
pthread_t threadid;
mutex_t pendlock;
uint32_t samprate;
#ifndef CONFIG_AUDIO_EXCLUDE_VOLUME
uint16_t volume_out;
uint16_t volume_in;
#endif
uint8_t bpsamp;
volatile uint8_t inflight;
bool running;
bool paused;
bool mute;
#ifndef CONFIG_AUDIO_EXCLUDE_STOP
bool terminating;
#endif
bool reserved;
volatile int result;
es_module_e audio_mode;
es_mic_gain_e mic_gain;
uint32_t mclk;
};
struct es8311_coeff_div_s
{
uint32_t mclk;
uint32_t rate;
uint8_t pre_div;
uint8_t pre_multi;
uint8_t adc_div;
uint8_t dac_div;
uint8_t fs_mode;
uint8_t lrck_h;
uint8_t lrck_l;
uint8_t bclk_div;
uint8_t adc_osr;
uint8_t dac_osr;
};
typedef enum
{
ES8311_MIC_GAIN_0DB,
ES8311_MIC_GAIN_6DB,
ES8311_MIC_GAIN_12DB,
ES8311_MIC_GAIN_18DB,
ES8311_MIC_GAIN_24DB,
ES8311_MIC_GAIN_30DB,
ES8311_MIC_GAIN_36DB,
ES8311_MIC_GAIN_42DB
} es8311_mic_gain_e;
typedef enum
{
ES8311_MCLK_FROM_MCLK_PIN,
ES8311_MCLK_FROM_SCLK_PIN
} es8311_mclk_src_e;
* Public Data
****************************************************************************/
static const struct es8311_coeff_div_s es8311_coeff_div[] =
{
{
12288000,
8000,
0x06,
0x01,
0x01,
0x01,
0x00,
0x00,
0xff,
0x04,
0x10,
0x20
},
{
18432000,
8000,
0x03,
0x02,
0x03,
0x03,
0x00,
0x05,
0xff,
0x18,
0x10,
0x20
},
{
16384000,
8000,
0x08,
0x01,
0x01,
0x01,
0x00,
0x00,
0xff,
0x04,
0x10,
0x20
},
{
8192000,
8000,
0x04,
0x01,
0x01,
0x01,
0x00,
0x00,
0xff,
0x04,
0x10,
0x20
},
{
6144000,
8000,
0x03,
0x01,
0x01,
0x01,
0x00,
0x00,
0xff,
0x04,
0x10,
0x20
},
{
4096000,
8000,
0x02,
0x01,
0x01,
0x01,
0x00,
0x00,
0xff,
0x04,
0x10,
0x20
},
{
3072000,
8000,
0x01,
0x01,
0x01,
0x01,
0x00,
0x00,
0xff,
0x04,
0x10,
0x20
},
{
2048000,
8000,
0x01,
0x01,
0x01,
0x01,
0x00,
0x00,
0xff,
0x04,
0x10,
0x20
},
{
1536000,
8000,
0x03,
0x04,
0x01,
0x01,
0x00,
0x00,
0xff,
0x04,
0x10,
0x20
},
{
1024000,
8000,
0x01,
0x02,
0x01,
0x01,
0x00,
0x00,
0xff,
0x04,
0x10,
0x20
},
{
11289600,
11025,
0x04,
0x01,
0x01,
0x01,
0x00,
0x00,
0xff,
0x04,
0x10,
0x20
},
{
5644800,
11025,
0x02,
0x01,
0x01,
0x01,
0x00,
0x00,
0xff,
0x04,
0x10,
0x20
},
{
2822400,
11025,
0x01,
0x01,
0x01,
0x01,
0x00,
0x00,
0xff,
0x04,
0x10,
0x20
},
{
1411200,
11025,
0x01,
0x02,
0x01,
0x01,
0x00,
0x00,
0xff,
0x04,
0x10,
0x20
},
{
12288000,
12000,
0x04,
0x01,
0x01,
0x01,
0x00,
0x00,
0xff,
0x04,
0x10,
0x20
},
{
6144000,
12000,
0x02,
0x01,
0x01,
0x01,
0x00,
0x00,
0xff,
0x04,
0x10,
0x20
},
{
3072000,
12000,
0x01,
0x01,
0x01,
0x01,
0x00,
0x00,
0xff,
0x04,
0x10,
0x20
},
{
1536000,
12000,
0x01,
0x02,
0x01,
0x01,
0x00,
0x00,
0xff,
0x04,
0x10,
0x20
},
{
12288000,
16000,
0x03,
0x01,
0x01,
0x01,
0x00,
0x00,
0xff,
0x04,
0x10,
0x20
},
{
18432000,
16000,
0x03,
0x02,
0x03,
0x03,
0x00,
0x02,
0xff,
0x0c,
0x10,
0x20
},
{
16384000,
16000,
0x04,
0x01,
0x01,
0x01,
0x00,
0x00,
0xff,
0x04,
0x10,
0x20
},
{
8192000,
16000,
0x02,
0x01,
0x01,
0x01,
0x00,
0x00,
0xff,
0x04,
0x10,
0x20
},
{
6144000,
16000,
0x03,
0x02,
0x01,
0x01,
0x00,
0x00,
0xff,
0x04,
0x10,
0x20
},
{
4096000,
16000,
0x01,
0x01,
0x01,
0x01,
0x00,
0x00,
0xff,
0x04,
0x10,
0x20
},
{
3072000,
16000,
0x03,
0x04,
0x01,
0x01,
0x00,
0x00,
0xff,
0x04,
0x10,
0x20
},
{
2048000,
16000,
0x01,
0x02,
0x01,
0x01,
0x00,
0x00,
0xff,
0x04,
0x10,
0x20
},
{
1536000,
16000,
0x03,
0x08,
0x01,
0x01,
0x00,
0x00,
0xff,
0x04,
0x10,
0x20
},
{
1024000,
16000,
0x01,
0x04,
0x01,
0x01,
0x00,
0x00,
0xff,
0x04,
0x10,
0x20
},
{
11289600,
22050,
0x02,
0x01,
0x01,
0x01,
0x00,
0x00,
0xff,
0x04,
0x10,
0x10
},
{
5644800,
22050,
0x01,
0x01,
0x01,
0x01,
0x00,
0x00,
0xff,
0x04,
0x10,
0x10
},
{
2822400,
22050,
0x01,
0x02,
0x01,
0x01,
0x00,
0x00,
0xff,
0x04,
0x10,
0x10
},
{
1411200,
22050,
0x01,
0x04,
0x01,
0x01,
0x00,
0x00,
0xff,
0x04,
0x10,
0x10
},
{
12288000,
24000,
0x02,
0x01,
0x01,
0x01,
0x00,
0x00,
0xff,
0x04,
0x10,
0x10
},
{
18432000,
24000,
0x03,
0x01,
0x01,
0x01,
0x00,
0x00,
0xff,
0x04,
0x10,
0x10
},
{
6144000,
24000,
0x01,
0x01,
0x01,
0x01,
0x00,
0x00,
0xff,
0x04,
0x10,
0x10
},
{
3072000,
24000,
0x01,
0x02,
0x01,
0x01,
0x00,
0x00,
0xff,
0x04,
0x10,
0x10
},
{
1536000,
24000,
0x01,
0x04,
0x01,
0x01,
0x00,
0x00,
0xff,
0x04,
0x10,
0x10
},
{
12288000,
32000,
0x03,
0x02,
0x01,
0x01,
0x00,
0x00,
0xff,
0x04,
0x10,
0x10
},
{
18432000,
32000,
0x03,
0x04,
0x03,
0x03,
0x00,
0x02,
0xff,
0x0c,
0x10,
0x10
},
{
16384000,
32000,
0x02,
0x01,
0x01,
0x01,
0x00,
0x00,
0xff,
0x04,
0x10,
0x10
},
{
8192000,
32000,
0x01,
0x01,
0x01,
0x01,
0x00,
0x00,
0xff,
0x04,
0x10,
0x10
},
{
6144000,
32000,
0x03,
0x04,
0x01,
0x01,
0x00,
0x00,
0xff,
0x04,
0x10,
0x10
},
{
4096000,
32000,
0x01,
0x02,
0x01,
0x01,
0x00,
0x00,
0xff,
0x04,
0x10,
0x10
},
{
3072000,
32000,
0x03,
0x08,
0x01,
0x01,
0x00,
0x00,
0xff,
0x04,
0x10,
0x10
},
{
2048000,
32000,
0x01,
0x04,
0x01,
0x01,
0x00,
0x00,
0xff,
0x04,
0x10,
0x10
},
{
1536000,
32000,
0x03,
0x08,
0x01,
0x01,
0x01,
0x00,
0x7f,
0x02,
0x10,
0x10
},
{
1024000,
32000,
0x01,
0x08,
0x01,
0x01,
0x00,
0x00,
0xff,
0x04,
0x10,
0x10
},
{
11289600,
44100,
0x01,
0x01,
0x01,
0x01,
0x00,
0x00,
0xff,
0x04,
0x10,
0x10
},
{
5644800,
44100,
0x01,
0x02,
0x01,
0x01,
0x00,
0x00,
0xff,
0x04,
0x10,
0x10
},
{
2822400,
44100,
0x01,
0x04,
0x01,
0x01,
0x00,
0x00,
0xff,
0x04,
0x10,
0x10
},
{
1411200,
44100,
0x01,
0x08,
0x01,
0x01,
0x00,
0x00,
0xff,
0x04,
0x10,
0x10
},
{
12288000,
48000,
0x01,
0x01,
0x01,
0x01,
0x00,
0x00,
0xff,
0x04,
0x10,
0x10
},
{
18432000,
48000,
0x03,
0x02,
0x01,
0x01,
0x00,
0x00,
0xff,
0x04,
0x10,
0x10
},
{
6144000,
48000,
0x01,
0x02,
0x01,
0x01,
0x00,
0x00,
0xff,
0x04,
0x10,
0x10
},
{
3072000,
48000,
0x01,
0x04,
0x01,
0x01,
0x00,
0x00,
0xff,
0x04,
0x10,
0x10
},
{
1536000,
48000,
0x01,
0x08,
0x01,
0x01,
0x00,
0x00,
0xff,
0x04,
0x10,
0x10
},
{
12288000,
64000,
0x03,
0x04,
0x01,
0x01,
0x00,
0x00,
0xff,
0x04,
0x10,
0x10
},
{
18432000,
64000,
0x03,
0x04,
0x03,
0x03,
0x01,
0x01,
0x7f,
0x06,
0x10,
0x10
},
{
16384000,
64000,
0x01,
0x01,
0x01,
0x01,
0x00,
0x00,
0xff,
0x04,
0x10,
0x10
},
{
8192000,
64000,
0x01,
0x02,
0x01,
0x01,
0x00,
0x00,
0xff,
0x04,
0x10,
0x10
},
{
6144000,
64000,
0x01,
0x04,
0x03,
0x03,
0x01,
0x01,
0x7f,
0x06,
0x10,
0x10
},
{
4096000,
64000,
0x01,
0x04,
0x01,
0x01,
0x00,
0x00,
0xff,
0x04,
0x10,
0x10
},
{
3072000,
64000,
0x01,
0x08,
0x03,
0x03,
0x01,
0x01,
0x7f,
0x06,
0x10,
0x10
},
{
2048000,
64000,
0x01,
0x08,
0x01,
0x01,
0x00,
0x00,
0xff,
0x04,
0x10,
0x10
},
{
1536000,
64000,
0x01,
0x08,
0x01,
0x01,
0x01,
0x00,
0xbf,
0x03,
0x18,
0x18
},
{
1024000,
64000,
0x01,
0x08,
0x01,
0x01,
0x01,
0x00,
0x7f,
0x02,
0x10,
0x10
},
{
11289600,
88200,
0x01,
0x02,
0x01,
0x01,
0x00,
0x00,
0xff,
0x04,
0x10,
0x10
},
{
5644800,
88200,
0x01,
0x04,
0x01,
0x01,
0x00,
0x00,
0xff,
0x04,
0x10,
0x10
},
{
2822400,
88200,
0x01,
0x08,
0x01,
0x01,
0x00,
0x00,
0xff,
0x04,
0x10,
0x10
},
{
1411200,
88200,
0x01,
0x08,
0x01,
0x01,
0x01,
0x00,
0x7f,
0x02,
0x10,
0x10
},
{
12288000,
96000,
0x01,
0x02,
0x01,
0x01,
0x00,
0x00,
0xff,
0x04,
0x10,
0x10
},
{
18432000,
96000,
0x03,
0x04,
0x01,
0x01,
0x00,
0x00,
0xff,
0x04,
0x10,
0x10
},
{
6144000,
96000,
0x01,
0x04,
0x01,
0x01,
0x00,
0x00,
0xff,
0x04,
0x10,
0x10
},
{
3072000,
96000,
0x01,
0x08,
0x01,
0x01,
0x00,
0x00,
0xff,
0x04,
0x10,
0x10
},
{
1536000,
96000,
0x01,
0x08,
0x01,
0x01,
0x01,
0x00,
0x7f,
0x02,
0x10,
0x10
}
};
* Public Function Prototypes
****************************************************************************/
* Name: es8311_readreg
*
* Description:
* Read the specified 8-bit register from the ES8311 device.
*
****************************************************************************/
#if defined(CONFIG_ES8311_REGDUMP)
struct es8311_dev_s;
uint8_t es8311_readreg(FAR struct es8311_dev_s *priv, uint8_t regaddr);
#endif
#endif
#endif