-
Notifications
You must be signed in to change notification settings - Fork 666
/
es8374.h
executable file
·251 lines (225 loc) · 5.59 KB
/
es8374.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
/*
* ESPRESSIF MIT License
*
* Copyright (c) 2018 <ESPRESSIF SYSTEMS (SHANGHAI) PTE LTD>
*
* Permission is hereby granted for use on all ESPRESSIF SYSTEMS products, in which case,
* it is free of charge, to any person obtaining a copy of this software and associated
* documentation files (the "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the Software is furnished
* to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or
* substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
*/
#ifndef __ES8374_H__
#define __ES8374_H__
#include "esp_types.h"
#include "audio_hal.h"
#include "esxxx_common.h"
#ifdef __cplusplus
extern "C" {
#endif
/* ES8374 address */
#define ES8374_ADDR 0x20 // 0x22:CE=1;0x20:CE=0
/**
* @brief Initialize ES8374 codec chip
*
* @param cfg configuration of ES8374
*
* @return
* - ESP_OK
* - ESP_FAIL
*/
esp_err_t es8374_codec_init(audio_hal_codec_config_t *cfg);
/**
* @brief Deinitialize ES8374 codec chip
*
* @return
* - ESP_OK
* - ESP_FAIL
*/
esp_err_t es8374_codec_deinit(void);
/**
* @brief Configure ES8374 I2S format
*
* @param mode: set ADC or DAC or both
* @param fmt: ES8374 I2S format
*
* @return
* - ESP_OK
* - ESP_FAIL
*/
esp_err_t es8374_config_fmt(es_module_t mode, es_i2s_fmt_t fmt);
/**
* @brief Configure I2S clock in MSATER mode
*
* @param cfg: set bits clock and WS clock
*
* @return
* - ESP_OK
* - ESP_FAIL
*/
esp_err_t es8374_i2s_config_clock(es_i2s_clock_t cfg);
/**
* @brief Configure ES8374 data sample bits
*
* @param mode: set ADC or DAC or both
* @param bit_per_sample: bit number of per sample
*
* @return
* - ESP_OK
* - ESP_FAIL
*/
esp_err_t es8374_set_bits_per_sample(es_module_t mode, es_bits_length_t bit_per_sample);
/**
* @brief Start ES8374 codec chip
*
* @param mode: set ADC or DAC or both
*
* @return
* - ESP_OK
* - ESP_FAIL
*/
esp_err_t es8374_start(es_module_t mode);
/**
* @brief Stop ES8374 codec chip
*
* @param mode: set ADC or DAC or both
*
* @return
* - ESP_OK
* - ESP_FAIL
*/
esp_err_t es8374_stop(es_module_t mode);
/**
* @brief Set voice volume
*
* @param volume: voice volume (0~100)
*
* @return
* - ESP_OK
* - ESP_FAIL
*/
esp_err_t es8374_codec_set_voice_volume(int volume);
/**
* @brief Get voice volume
*
* @param[out] *volume: voice volume (0~100)
*
* @return
* - ESP_OK
* - ESP_FAIL
*/
esp_err_t es8374_codec_get_voice_volume(int *volume);
/**
* @brief Mute or unmute ES8374 DAC. Basically you can use this function to mute or unmute the output
*
* @param enable mute(1) or unmute(0)
*
* @return
* - ESP_FAIL Parameter error
* - ESP_OK Success
*/
esp_err_t es8374_set_voice_mute(bool enable);
/**
* @brief Get ES8374 DAC mute status
*
* @return
* - ESP_FAIL
* - ESP_OK
*/
esp_err_t es8374_get_voice_mute(void);
/**
* @brief Set ES8374 mic gain
*
* @param gain db of mic gain
*
* @return
* - ESP_FAIL Parameter error
* - ESP_OK Success
*/
esp_err_t es8374_set_mic_gain(es_mic_gain_t gain);
/**
* @brief Set ES8374 ADC input mode
*
* @param input adc input mode
*
* @return
* - ESP_FAIL Parameter error
* - ESP_OK Success
*/
esp_err_t es8374_config_adc_input(es_adc_input_t input);
/**
* @brief Set ES8374 DAC output mode
*
* @param output dac output mode
*
* @return
* - ESP_FAIL Parameter error
* - ESP_OK Success
*/
esp_err_t es8374_config_dac_output(es_dac_output_t output);
/**
* @brief Write ES8374 register
*
* @param reg_add address of register
* @param data data of register
*
* @return
* - ESP_FAIL Parameter error
* - ESP_OK Success
*/
esp_err_t es8374_write_reg(uint8_t reg_add, uint8_t data);
/**
* @brief Print all ES8374 registers
*
* @return
* - void
*/
void es8374_read_all();
/**
* @brief Configure ES8374 codec mode and I2S interface
*
* @param mode codec mode
* @param iface I2S config
*
* @return
* - ESP_FAIL Parameter error
* - ESP_OK Success
*/
esp_err_t es8374_codec_config_i2s(audio_hal_codec_mode_t mode, audio_hal_codec_i2s_iface_t *iface);
/**
* @brief Control ES8374 codec chip
*
* @param mode codec mode
* @param ctrl_state start or stop decode or encode progress
*
* @return
* - ESP_FAIL Parameter error
* - ESP_OK Success
*/
esp_err_t es8374_codec_ctrl_state(audio_hal_codec_mode_t mode, audio_hal_ctrl_t ctrl_state);
/**
* @brief Set ES8374 PA power
*
* @param enable true for enable PA power, false for disable PA power
*
* @return
* - ESP_ERR_INVALID_ARG
* - ESP_OK
*/
esp_err_t es8374_pa_power(bool enable);
#ifdef __cplusplus
}
#endif
#endif //__ES8374_H__