3 #include "AudioConfig.h"
4 #if defined(USE_ANALOG) && defined(ESP32) && \
5 ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 0, 0) || \
8 #include "esp_adc/adc_cali_scheme.h"
9 #include "esp_adc/adc_continuous.h"
11 #include "esp32-hal-periman.h"
14 #if CONFIG_IDF_TARGET_ESP32
15 #define ADC_CONV_MODE ADC_CONV_SINGLE_UNIT_1
16 #define ADC_OUTPUT_TYPE ADC_DIGI_OUTPUT_FORMAT_TYPE1
17 #define ADC_CHANNELS \
18 {ADC_CHANNEL_0, ADC_CHANNEL_3, ADC_CHANNEL_4, \
19 ADC_CHANNEL_5, ADC_CHANNEL_6, ADC_CHANNEL_7}
20 #define NUM_ADC_CHANNELS 6
21 #define AUDIO_ADC_GET_CHANNEL(p_data) ((p_data)->type1.channel)
22 #define AUDIO_ADC_GET_DATA(p_data) ((p_data)->type1.data)
24 #define ADC_CHANNEL_TYPE uint16_t
25 #define ADC_DATA_TYPE uint16_t
26 #elif CONFIG_IDF_TARGET_ESP32S2
27 #define ADC_CONV_MODE ADC_CONV_SINGLE_UNIT_1
28 #define ADC_OUTPUT_TYPE ADC_DIGI_OUTPUT_FORMAT_TYPE2
29 #define AUDIO_ADC_GET_CHANNEL(p_data) ((p_data)->type2.channel)
30 #define AUDIO_ADC_GET_DATA(p_data) ((p_data)->type2.data)
31 #define ADC_CHANNELS \
32 {ADC_CHANNEL_0, ADC_CHANNEL_1, ADC_CHANNEL_2, ADC_CHANNEL_3, ADC_CHANNEL_4, \
33 ADC_CHANNEL_5, ADC_CHANNEL_6, ADC_CHANNEL_7, ADC_CHANNEL_8, ADC_CHANNEL_9}
34 #define NUM_ADC_CHANNELS 10
36 #define ADC_CHANNEL_TYPE uint16_t
37 #define ADC_DATA_TYPE uint16_t
38 #elif CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32H2 || \
39 CONFIG_IDF_TARGET_ESP32C2 || CONFIG_IDF_TARGET_ESP32C6
40 #define ADC_CONV_MODE ADC_CONV_ALTER_UNIT
41 #define ADC_OUTPUT_TYPE ADC_DIGI_OUTPUT_FORMAT_TYPE2
42 #define AUDIO_ADC_GET_CHANNEL(p_data) ((p_data)->type2.channel)
43 #define AUDIO_ADC_GET_DATA(p_data) ((p_data)->type2.data)
44 #define ADC_CHANNELS \
45 {ADC_CHANNEL_0, ADC_CHANNEL_1, ADC_CHANNEL_2, ADC_CHANNEL_3, ADC_CHANNEL_4}
46 #define NUM_ADC_CHANNELS 5
47 #define ADC_CHANNEL_TYPE uint32_t
48 #define ADC_DATA_TYPE uint32_t
49 #elif CONFIG_IDF_TARGET_ESP32C6
50 #define ADC_CONV_MODE ADC_CONV_ALTER_UNIT
51 #define ADC_OUTPUT_TYPE ADC_DIGI_OUTPUT_FORMAT_TYPE2
52 #define AUDIO_ADC_GET_CHANNEL(p_data) ((p_data)->type2.channel)
53 #define AUDIO_ADC_GET_DATA(p_data) ((p_data)->type2.data)
54 #define ADC_CHANNELS \
55 {ADC_CHANNEL_0, ADC_CHANNEL_1, ADC_CHANNEL_2, ADC_CHANNEL_3, \
56 ADC_CHANNEL_4, ADC_CHANNEL_5, ADC_CHANNEL_6}
57 #define NUM_ADC_CHANNELS 7
58 #define ADC_CHANNEL_TYPE uint32_t
59 #define ADC_DATA_TYPE uint32_t
60 #elif CONFIG_IDF_TARGET_ESP32S3
61 #define ADC_CONV_MODE ADC_CONV_SINGLE_UNIT_1
62 #define ADC_OUTPUT_TYPE ADC_DIGI_OUTPUT_FORMAT_TYPE2
63 #define AUDIO_ADC_GET_CHANNEL(p_data) ((p_data)->type2.channel)
64 #define AUDIO_ADC_GET_DATA(p_data) ((p_data)->type2.data)
65 #define ADC_CHANNELS \
66 {ADC_CHANNEL_0, ADC_CHANNEL_1, ADC_CHANNEL_2, ADC_CHANNEL_3, ADC_CHANNEL_4, \
67 ADC_CHANNEL_5, ADC_CHANNEL_6, ADC_CHANNEL_7, ADC_CHANNEL_8, ADC_CHANNEL_9}
68 #define NUM_ADC_CHANNELS 10
69 #define ADC_CHANNEL_TYPE uint32_t
70 #define ADC_DATA_TYPE uint32_t
71 #elif CONFIG_IDF_TARGET_ESP32P4
72 #define ADC_CONV_MODE ADC_CONV_SINGLE_UNIT_1
73 #define ADC_OUTPUT_TYPE ADC_DIGI_OUTPUT_FORMAT_TYPE2
74 #define AUDIO_ADC_GET_CHANNEL(p_data) ((p_data)->type2.channel)
75 #define AUDIO_ADC_GET_DATA(p_data) ((p_data)->type2.data)
76 #define ADC_CHANNELS \
77 {ADC_CHANNEL_0, ADC_CHANNEL_1, ADC_CHANNEL_2, ADC_CHANNEL_3, \
78 ADC_CHANNEL_4, ADC_CHANNEL_5, ADC_CHANNEL_6, ADC_CHANNEL_7}
79 #define NUM_ADC_CHANNELS 8
80 #define ADC_CHANNEL_TYPE uint32_t
81 #define ADC_DATA_TYPE uint32_t
86 #define ADC_UNIT ADC_UNIT_1
88 #include "driver/dac_continuous.h"
105 int buffer_count = ANALOG_BUFFER_COUNT;
106 int buffer_size = ANALOG_BUFFER_SIZE;
108 TickType_t timeout = portMAX_DELAY;
111 bool is_blocking_write =
true;
112 bool use_apll =
false;
114 dac_channel_mask_t dac_mono_channel = DAC_CHANNEL_MASK_CH0;
118 bool adc_calibration_active =
false;
119 bool is_auto_center_read =
false;
120 adc_digi_convert_mode_t adc_conversion_mode = ADC_CONV_MODE;
121 adc_digi_output_format_t adc_output_type = ADC_OUTPUT_TYPE;
122 uint8_t adc_attenuation = ADC_ATTEN_DB_12;
123 uint8_t adc_bit_width = SOC_ADC_DIGI_MAX_BITWIDTH;
125 adc_channel_t adc_channels[NUM_ADC_CHANNELS] = ADC_CHANNELS;
132 rx_tx_mode = rxtxMode;
133 switch (rx_tx_mode) {
139 LOGI(
"I2S_MODE_ADC_BUILT_IN");
145 LOGI(
"I2S_MODE_DAC_BUILT_IN");
150 LOGE(
"RxTxMode not supported: %d", rx_tx_mode);
159 AudioInfo::logInfo();
161 if (rx_tx_mode == TX_MODE) {
162 LOGI(
"analog left output pin: %d", 25);
163 LOGI(
"analog right output pin: %d", 26);
167 LOGI(
"use_apll: %d", use_apll);
172 #ifndef ANALOG_CONFIG
173 #define ANALOG_CONFIG
174 using AnalogConfig = AnalogConfigESP32V1;
RxTxMode
The Microcontroller is the Audio Source (TX_MODE) or Audio Sink (RX_MODE). RXTX_MODE is Source and Si...
Definition: AudioTypes.h:28