Skip to content

Commit 64d9ef0

Browse files
committed
AD1938
1 parent 7bd1cb4 commit 64d9ef0

File tree

3 files changed

+1037
-44
lines changed

3 files changed

+1037
-44
lines changed

src/Common.h

Lines changed: 55 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,30 @@
11
#pragma once
22
#include <stdint.h>
3+
34
#include "Utils/Logger.h"
45
/*!
56
* @file
67
* @defgroup audio_driver Audio Driver
78
* @defgroup enumerations Public enumeration types
89
*/
910

10-
// To increase the max volume e.g. for ai_thinker (ES8388) 2957 or A202 -> set to 1 or 2
11-
// 0 AUX volume is LINE level
12-
// 1 you can control the AUX volume with setVolume()
11+
// To increase the max volume e.g. for ai_thinker (ES8388) 2957 or A202 -> set
12+
// to 1 or 2 0 AUX volume is LINE level 1 you can control the AUX volume with
13+
// setVolume()
1314
#ifndef AI_THINKER_ES8388_VOLUME_HACK
14-
# define AI_THINKER_ES8388_VOLUME_HACK 1
15+
#define AI_THINKER_ES8388_VOLUME_HACK 1
1516
#endif
1617

1718
// Default volume at startup
1819
#ifndef DRIVER_DEFAULT_VOLUME
19-
# define DRIVER_DEFAULT_VOLUME 70
20+
#define DRIVER_DEFAULT_VOLUME 70
2021
#endif
2122

2223
// Define the default gain for the microphone amp (see values from
2324
// es_mic_gain_t) Alternativly you can call es8388_set_mic_gain(es_mic_gain_t
2425
// gain) if you prefer to use value from an comprehensive enum
2526
#ifndef ES8388_DEFAULT_INPUT_GAIN
26-
# define ES8388_DEFAULT_INPUT_GAIN 25
27+
#define ES8388_DEFAULT_INPUT_GAIN 25
2728
#endif
2829

2930
/// Fixed Definitions
@@ -86,13 +87,18 @@ typedef enum {
8687
*/
8788
typedef enum {
8889
RATE_8K = 0, /*!< set to 8k samples per second */
89-
RATE_11K, /*!< set to 11.025k samples per second */
90-
RATE_16K, /*!< set to 16k samples in per second */
91-
RATE_22K, /*!< set to 22.050k samples per second */
92-
RATE_24K, /*!< set to 24k samples in per second */
93-
RATE_32K, /*!< set to 32k samples in per second */
94-
RATE_44K, /*!< set to 44.1k samples per second */
95-
RATE_48K, /*!< set to 48k samples per second */
90+
RATE_11K, /*!< set to 11.025k samples per second */
91+
RATE_16K, /*!< set to 16k samples in per second */
92+
RATE_22K, /*!< set to 22.050k samples per second */
93+
RATE_24K, /*!< set to 24k samples in per second */
94+
RATE_32K, /*!< set to 32k samples in per second */
95+
RATE_44K, /*!< set to 44.1k samples per second */
96+
RATE_48K, /*!< set to 48k samples per second */
97+
RATE_88K, /*!< set to 88.2k samples per second */
98+
RATE_96K, /*!< set to 96k samples per second */
99+
RATE_128K, /*!< set to 128K samples per second */
100+
RATE_176K, /*!< set to 176.4K samples per second */
101+
RATE_192K, /*!< set to 192k samples per second */
96102
} samplerate_t;
97103

98104
/**
@@ -101,13 +107,13 @@ typedef enum {
101107
* @ingroup enumerations
102108
*/
103109
typedef enum {
104-
BIT_LENGTH_MIN = -1,
105-
BIT_LENGTH_16BITS = 0x03,
106-
BIT_LENGTH_18BITS = 0x02,
107-
BIT_LENGTH_20BITS = 0x01,
108-
BIT_LENGTH_24BITS = 0x00,
109-
BIT_LENGTH_32BITS = 0x04,
110-
BIT_LENGTH_MAX,
110+
BIT_LENGTH_MIN = -1,
111+
BIT_LENGTH_16BITS = 0x03,
112+
BIT_LENGTH_18BITS = 0x02,
113+
BIT_LENGTH_20BITS = 0x01,
114+
BIT_LENGTH_24BITS = 0x00,
115+
BIT_LENGTH_32BITS = 0x04,
116+
BIT_LENGTH_MAX,
111117
} sample_bits_t;
112118

113119
/**
@@ -117,10 +123,10 @@ typedef enum {
117123
*/
118124
typedef enum {
119125
I2S_NORMAL = 0, /*!< set normal I2S format */
120-
I2S_LEFT = 1, /*!< set all left format */
121-
I2S_RIGHT = 2, /*!< set all right format */
122-
I2S_DSP = 3, /*!< set dsp/pcm format */
123-
TDM = 4, /*!< set tdm format */
126+
I2S_LEFT = 1, /*!< set all left format */
127+
I2S_RIGHT = 2, /*!< set all right format */
128+
I2S_DSP = 3, /*!< set dsp/pcm format */
129+
TDM = 4, /*!< set tdm format */
124130
} i2s_format_t;
125131

126132
/**
@@ -129,20 +135,19 @@ typedef enum {
129135
* @ingroup enumerations
130136
*/
131137
typedef enum {
132-
MIC_GAIN_MIN = -1,
133-
MIC_GAIN_0DB = 0,
134-
MIC_GAIN_3DB = 3,
135-
MIC_GAIN_6DB = 6,
136-
MIC_GAIN_9DB = 9,
137-
MIC_GAIN_12DB = 12,
138-
MIC_GAIN_15DB = 15,
139-
MIC_GAIN_18DB = 18,
140-
MIC_GAIN_21DB = 21,
141-
MIC_GAIN_24DB = 24,
142-
MIC_GAIN_MAX,
138+
MIC_GAIN_MIN = -1,
139+
MIC_GAIN_0DB = 0,
140+
MIC_GAIN_3DB = 3,
141+
MIC_GAIN_6DB = 6,
142+
MIC_GAIN_9DB = 9,
143+
MIC_GAIN_12DB = 12,
144+
MIC_GAIN_15DB = 15,
145+
MIC_GAIN_18DB = 18,
146+
MIC_GAIN_21DB = 21,
147+
MIC_GAIN_24DB = 24,
148+
MIC_GAIN_MAX,
143149
} es_mic_gain_t;
144150

145-
146151
/**
147152
* @enum codec_mode_t
148153
* @brief Select media hal codec mode
@@ -151,27 +156,35 @@ typedef enum {
151156
typedef enum {
152157
CODEC_MODE_MIN = -1,
153158
CODEC_MODE_NONE = 0x00,
154-
CODEC_MODE_ENCODE = 0x01, /*!< select adc */
155-
CODEC_MODE_DECODE = 0x02, /*!< select dac */
156-
CODEC_MODE_BOTH = 0x03, /*!< select both adc and dac */
157-
CODEC_MODE_LINE_IN = 0x04, /*!< set adc channel */
159+
CODEC_MODE_ENCODE = 0x01, /*!< select adc */
160+
CODEC_MODE_DECODE = 0x02, /*!< select dac */
161+
CODEC_MODE_BOTH = 0x03, /*!< select both adc and dac */
162+
CODEC_MODE_LINE_IN = 0x04, /*!< set adc channel */
158163
CODEC_MODE_MAX
159164
} codec_mode_t;
160165

166+
typedef enum {
167+
CHANNELS2 = 2,
168+
CHANNELS8 = 8,
169+
CHANNELS16 = 16,
170+
} channels_t;
161171

162172
/**
163173
* @brief I2s interface configuration for audio codec chip
164174
* @ingroup audio_driver
165175
*/
166176
typedef struct {
167-
/*!< Audio codec chip mode: if the microcontroller is master the codec must be slave! */
177+
/*!< Audio codec chip mode: if the microcontroller is master the codec must be
178+
* slave! */
168179
i2s_master_slave_t mode;
169180
/*!< I2S interface format */
170181
i2s_format_t fmt;
171182
/*!< I2S sample rate in samples per second */
172183
samplerate_t rate;
173184
/*!< i2s number of bits per sample */
174185
sample_bits_t bits;
186+
/*!< i2s number of channels */
187+
channels_t channels;
175188
} I2SDefinition;
176189

177190
/**
@@ -180,13 +193,11 @@ typedef struct {
180193
typedef struct {
181194
input_device_t input_device; /*!< set adc channel */
182195
output_device_t output_device; /*!< set dac channel */
183-
I2SDefinition i2s; /*!< set I2S interface configuration */
196+
I2SDefinition i2s; /*!< set I2S interface configuration */
184197
} codec_config_t;
185198

186199
#ifdef __cplusplus
187200
}
188201
// automatically use namespace
189202
using namespace audio_driver;
190203
#endif
191-
192-

0 commit comments

Comments
 (0)