arduino-audio-tools
Loading...
Searching...
No Matches
AnalogDriverESP32V2.h
Go to the documentation of this file.
1#pragma once
2
3#include "AudioToolsConfig.h"
4
5#if defined(ESP32) && defined(USE_ANALOG) && !USE_LEGACY_I2S
6
7#ifdef ARDUINO
8 #ifndef perimanClearPinBus
9 #define perimanClearPinBus(p) perimanSetPinBus(p, ESP32_BUS_TYPE_INIT, NULL)
10 #endif
11#endif
12
17
18namespace audio_tools {
19
30public:
33
36 end();
37 }
38
42 TRACEI();
43 bool result = true;
44 this->cfg = cfg;
45
46 switch (cfg.rx_tx_mode) {
47 case TX_MODE:
48 if (!setup_tx()) return false;
49 // convert to 16 bits
50 if (!converter.begin(cfg, 16)) {
51 LOGE("converter");
52 return false;
53 }
54 active_tx = true;
55 break;
56 case RX_MODE:
57 if (!setup_rx()) return false;
58 active_rx = true;
59 break;
60 default:
61 LOGE( "Unsupported MODE: %d", cfg.rx_tx_mode);
62 return false;
63 }
64
65 active = true;
66 return active;
67 }
68
71 void end() override {
72 TRACEI();
73 if (active_tx) {
74 cleanup_tx();
75 }
76 if (active_rx) {
77 cleanup_rx();
78 }
79
80 converter.end();
81
82 active_tx = false;
83 active_rx = false;
84 active = false;
85 }
86
87 // Writes the data to the Digital to Analog Converter
88 // ----------------------------------------------------------
89 size_t write(const uint8_t *src, size_t size_bytes) override {
90 // TRACED();
91 // convert any format to int16_t
92 return converter.write(src, size_bytes);
93 }
94
95 // Reads data from DMA buffer of the Analog to Digital Converter
96 // ----------------------------------------------------------
97 size_t readBytes(uint8_t *dest, size_t size_bytes) override {
98 TRACED();
99 // Use the IO16Bit class for reading
100 return io.readBytes(dest, size_bytes);
101 }
102
103 // How much data will there be available after reading ADC buffer
104 // ----------------------------------------------------------
105 int available() override {
106 return active_rx ? configuredRxBytes() : 0;
107 }
108
109protected:
110
111 adc_continuous_handle_t adc_handle = nullptr;
112 adc_cali_handle_t adc_cali_handle = nullptr;
115 bool active = false;
116 bool active_tx = false;
117 bool active_rx = false;
118 bool rx_started = false;
121 #ifdef HAS_ESP32_DAC
122 dac_continuous_handle_t dac_handle = nullptr;
123 #endif
124
125 int configuredRxBytes() const {
126 return (cfg.buffer_size > 0) ? (int)(cfg.buffer_size * sizeof(int16_t)) : 0;
127 }
128
130 if (!adc_cali_handle_active || adc_cali_handle == nullptr) return;
131#if ADC_CALI_SCHEME_CURVE_FITTING_SUPPORTED
132 adc_cali_delete_scheme_curve_fitting(adc_cali_handle);
133#elif !defined(CONFIG_IDF_TARGET_ESP32H2)
134 adc_cali_delete_scheme_line_fitting(adc_cali_handle);
135#endif
136 adc_cali_handle = nullptr;
138 }
139
140#ifdef ARDUINO
141 void cleanupAttachedRxPins() {
142 perimanSetBusDeinit(ESP32_BUS_TYPE_ADC_CONT, adcDetachBus);
143 for (int i = 0; i < rx_pins_attached; ++i) {
144 adc_channel_t adc_channel = cfg.adc_channels[i];
145 int io_pin;
146 adc_continuous_channel_to_io(cfg.adc_unit, adc_channel, &io_pin);
147 if (perimanGetPinBusType(io_pin) == ESP32_BUS_TYPE_ADC_CONT) {
148 if (!perimanClearPinBus(io_pin)) {
149 LOGE("perimanClearPinBus failed!");
150 }
151 }
152 }
154 }
155#endif
156
157
158 // 16Bit Audiostream for ESP32
159 // ----------------------------------------------------------
160 class IO16Bit : public AudioStream {
161 public:
162 IO16Bit(AnalogDriverESP32V2 *driver) { self = driver; }
163
165 size_t write(const uint8_t *src, size_t size_bytes) override {
166 // TRACED();
167#ifdef HAS_ESP32_DAC
168 size_t result = 0;
169 // Convert signed 16-bit to unsigned 8-bit
170 int16_t *data16 = (int16_t *)src;
171 uint8_t *data8 = (uint8_t *)src;
172 int samples = size_bytes / 2;
173
174 // Process data in batches to reduce the number of conversions and writes
175 for (int j = 0; j < samples; j++) {
176 data8[j] = (32768u + data16[j]) >> 8;
177 }
178
179 if (dac_continuous_write(self->dac_handle, data8, samples, &result, self->cfg.timeout) != ESP_OK) {
180 result = 0;
181 }
182 return result * 2;
183#else
184 return 0;
185#endif
186 }
187
189 size_t readBytes(uint8_t *dest, size_t size_bytes) {
190 LOGD("readBytes: %d", (int) size_bytes);
191 size_t result = 0;
192 int channels = self->cfg.channels;
193 assert(channels > 0);
194 sampleIndex.resize(channels);
195 for(int ch=0;ch < channels;ch++){
196 sampleIndex[ch] = 0;
197 }
198 uint16_t *result16 = (uint16_t *)dest; // pointer to the destination buffer
199 int samples_requested = size_bytes / sizeof(int16_t);
200 int samples_requested_per_channel = samples_requested / channels;
201 int buffer_size = samples_requested * sizeof(adc_digi_output_data_t);
202 if (result_data.size() < buffer_size){
203 result_data.resize(buffer_size);
204 }
205
206 int read_size_bytes = buffer_size;
207
208 // read the requested bytes into the buffer
209 while (read_size_bytes > 0){
210 uint32_t bytes_read = 0;
211 if (adc_continuous_read(self->adc_handle, (uint8_t *)result_data.data(), (uint32_t)read_size_bytes, &bytes_read, (uint32_t)self->cfg.timeout) == ESP_OK) {
212 int samples_read = bytes_read / sizeof(adc_digi_output_data_t);
213 LOGD("adc_continuous_read -> %u bytes / %d samples of %d bytes requested", (unsigned)bytes_read, samples_read, (int)(samples_requested * sizeof(adc_digi_output_data_t)));
214
215 // Provide samples to dest
216 for (int i = 0; i < samples_read; i++) {
217 adc_digi_output_data_t *p = (adc_digi_output_data_t*) &result_data[i];
218 ADC_CHANNEL_TYPE chan_num = AUDIO_ADC_GET_CHANNEL(p);
219 ADC_DATA_TYPE sample_value = AUDIO_ADC_GET_DATA(p);
220 int channel = getChannelIdx(chan_num);
221
222 // provide data to dest
223 if (channel >=0 && channel < channels){
224 int idx = channel + (sampleIndex[channel] * channels);
225 LOGI("idx for %d: %d", channel, idx);
226 if(idx < samples_requested){
227 // Provide result in millivolts
229 result16[idx] = getCalibratedValue(sample_value);
230 } else {
231 result16[idx] = sample_value;
232 }
233 // increase index for the actual channel
234 sampleIndex[channel]++;
235 } else {
236 LOGE("Invalid idx: %d / max %d", idx, samples_requested);
237 }
238 } else {
239 LOGE("Invalid channel: %d", channel);
240 }
241 }
243 int samples_available = getMinSamplesForAllChannels(channels);
244 result = samples_available * channels * sizeof(int16_t);
245
247 read_size_bytes = result - size_bytes;
248 if (read_size_bytes > 0)
249 LOGI("read missing samples: %d", samples_requested_per_channel - samples_available);
250 } else {
251 LOGE("adc_continuous_read error");
252 break;
253 }
254 }
255
256
257 // Centering if enabled
259 self->auto_center.convert(dest, result);
260 }
261
262 // Scaling to 16 bits if enabled
264 scaleTo16Bits(dest, result, self->cfg.adc_bit_width,
266 }
267
268 return result;
269 }
270
271 protected:
275
276 int getChannelIdx(ADC_CHANNEL_TYPE chan_num){
277 for (int j = 0; j < self->cfg.channels; ++j) {
278 if (self->cfg.adc_channels[j] == chan_num) {
279 return j;
280 }
281 }
282 return -1;
283 }
284
285 int16_t getCalibratedValue(ADC_DATA_TYPE sample_value){
286 int data_milliVolts = 0;
287 int16_t result = 0;
288 auto err = adc_cali_raw_to_voltage(self->adc_cali_handle, sample_value, &data_milliVolts);
289 if (err == ESP_OK) {
290 result = static_cast<int16_t>(data_milliVolts);
291 } else {
292 LOGE("adc_cali_raw_to_voltage error: %d", err);
293 }
294 return result;
295 }
296
297 int getMinSamplesForAllChannels(int channels) {
298 int result = 100000;
299 for (int ch = 0; ch < channels; ch++){
300 if (sampleIndex[ch] < result){
301 result = sampleIndex[ch];
302 }
303 }
304 return result;
305 }
306
307 } io{this};
308
310
311 // Setup Digital to Analog
312 // ----------------------------------------------------------
313 #ifdef HAS_ESP32_DAC
314 bool setup_tx() {
315 dac_continuous_config_t cont_cfg = {
316 .chan_mask = (dac_channel_mask_t)(cfg.channels == 1 ? cfg.dac_mono_channel : DAC_CHANNEL_MASK_ALL),
317 .desc_num = (uint32_t)cfg.buffer_count,
318 .buf_size = (size_t)cfg.buffer_size,
319 .freq_hz = (uint32_t)cfg.sample_rate,
320 .offset = 0,
321 .clk_src = cfg.use_apll ? DAC_DIGI_CLK_SRC_APLL : DAC_DIGI_CLK_SRC_DEFAULT, // Using APLL as clock source to get a wider frequency range
322 .chan_mode = cfg.channels == 1 ? DAC_CHANNEL_MODE_SIMUL : DAC_CHANNEL_MODE_ALTER,
323 };
324 // Allocate continuous channels
325 if (dac_continuous_new_channels(&cont_cfg, &dac_handle) != ESP_OK) {
326 LOGE("new_channels");
327 return false;
328 }
329 if (dac_continuous_enable(dac_handle) != ESP_OK) {
330 LOGE("enable");
331 return false;
332 }
333 return true;
334 }
335 #else
336 bool setup_tx() {
337 LOGE("DAC not supported");
338 return false;
339 }
340 #endif
341
342 // Setup Analog to Digital Converter
343 // ----------------------------------------------------------
344 bool setup_rx() {
345 adc_channel_t adc_channel;
346 int io_pin;
347 esp_err_t err;
348
349 // Check the configuration
350 if (!checkADCChannels()) return false;
351 if (!checkADCSampleRate()) return false;
352 if (!checkADCBitWidth()) return false;
353 if (!checkADCBitsPerSample()) return false;
354
355 if (adc_handle != nullptr) {
356 LOGE("adc unit %u continuous is already initialized. Please call end() first!", cfg.adc_unit);
357 return false;
358 }
359
360 #ifdef ARDUINO
361 // Set periman deinit callback
362 // TODO, currently handled in end() method
363
364 // Set the pins/channels to INIT state
365 for (int i = 0; i < cfg.channels; i++) {
366 adc_channel = cfg.adc_channels[i];
367 adc_continuous_channel_to_io(cfg.adc_unit, adc_channel, &io_pin);
368 if (!perimanClearPinBus(io_pin)) {
369 LOGE("perimanClearPinBus failed!");
370 return false;
371 }
372 }
373 #endif
374
375 uint32_t conv_frame_size = (uint32_t)cfg.buffer_size * SOC_ADC_DIGI_RESULT_BYTES;
376 #if CONFIG_IDF_TARGET_ESP32 || CONFIG_IDF_TARGET_ESP32S2
377 conv_frame_size = adcContinuousAlignFrameSize(conv_frame_size);
378 #endif
379
380 uint32_t rx_max_conv_frame_bytes = adcContinuousMaxConvFrameBytes();
381 uint32_t max_samples_per_frame = adcContinuousMaxResultsPerFrame();
382 if (conv_frame_size > rx_max_conv_frame_bytes) {
383 LOGE(
384 "buffer_size is too big for one ADC DMA frame: %u samples = %u "
385 "bytes, max %u samples / %u bytes",
386 cfg.buffer_size, (unsigned)conv_frame_size,
387 (unsigned)max_samples_per_frame,
388 (unsigned)rx_max_conv_frame_bytes);
389 return false;
390 } else {
391 LOGI(
392 "RX DMA frame: %u conversion results, %u bytes (max %u results / "
393 "%u bytes)",
394 cfg.buffer_size, (unsigned)conv_frame_size,
395 (unsigned)max_samples_per_frame,
396 (unsigned)rx_max_conv_frame_bytes);
397 }
398
399 // Create adc_continuous handle
400 adc_continuous_handle_cfg_t adc_config;
401 uint32_t rx_frame_count = cfg.buffer_count > 0 ? (uint32_t)cfg.buffer_count : 1U;
402 adc_config.max_store_buf_size = (uint32_t)conv_frame_size * rx_frame_count;
403 adc_config.conv_frame_size = (uint32_t) conv_frame_size;
404#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 2, 0)
405 adc_config.flags.flush_pool = true;
406#endif
407 LOGI("RX pool: %u frames, %u bytes", (unsigned)rx_frame_count,
408 (unsigned)adc_config.max_store_buf_size);
409 err = adc_continuous_new_handle(&adc_config, &adc_handle);
410 if (err != ESP_OK) {
411 LOGE("adc_continuous_new_handle failed with error: %d", err);
412 return false;
413 } else {
414 LOGI("adc_continuous_new_handle successful");
415 }
416
417 // Configure the ADC patterns
418 adc_digi_pattern_config_t adc_pattern[cfg.channels] = {};
419 for (int i = 0; i < cfg.channels; i++) {
420 uint8_t ch = cfg.adc_channels[i];
421 adc_pattern[i].atten = (uint8_t) cfg.adc_attenuation;
422 adc_pattern[i].channel = (uint8_t)ch;
423 adc_pattern[i].unit = (uint8_t) cfg.adc_unit;
424 adc_pattern[i].bit_width = (uint8_t) cfg.adc_bit_width;
425 }
426
427 // Configure the ADC
428 adc_continuous_config_t dig_cfg = {
429 .pattern_num = (uint32_t) cfg.channels,
430 .adc_pattern = adc_pattern,
431 .sample_freq_hz = (uint32_t)cfg.sample_rate * cfg.channels,
432 .conv_mode = (adc_digi_convert_mode_t) cfg.adc_conversion_mode,
433 .format = (adc_digi_output_format_t) cfg.adc_output_type,
434 };
435
436 // Log the configuration
437 LOGI("dig_cfg.sample_freq_hz: %u", (unsigned)dig_cfg.sample_freq_hz);
438 LOGI("dig_cfg.conv_mode: %u (1: unit 1, 2: unit 2, 3: both)", dig_cfg.conv_mode);
439 LOGI("dig_cfg.format: %u (0 is type1: [12bit data, 4bit channel])", dig_cfg.format);
440 for (int i = 0; i < cfg.channels; i++) {
441 LOGI("dig_cfg.adc_pattern[%d].atten: %u", i, dig_cfg.adc_pattern[i].atten);
442 LOGI("dig_cfg.adc_pattern[%d].channel: %u", i, dig_cfg.adc_pattern[i].channel);
443 LOGI("dig_cfg.adc_pattern[%d].unit: %u", i, dig_cfg.adc_pattern[i].unit);
444 LOGI("dig_cfg.adc_pattern[%d].bit_width: %u", i, dig_cfg.adc_pattern[i].bit_width);
445 }
446
447 // Initialize ADC
448 err = adc_continuous_config(adc_handle, &dig_cfg);
449 if (err != ESP_OK) {
450 LOGE("adc_continuous_config unsuccessful with error: %d", err);
451 cleanup_rx();
452 return false;
453 }
454 LOGI("adc_continuous_config successful");
455
456 // Set up optional calibration
457 if (!setupADCCalibration()) {
458 cleanup_rx();
459 return false;
460 }
461
462 // Attach the pins to the ADC unit
463#ifdef ARDUINO
464 for (int i = 0; i < cfg.channels; i++) {
465 adc_channel = cfg.adc_channels[i];
466 adc_continuous_channel_to_io(cfg.adc_unit, adc_channel, &io_pin);
467 // perimanSetPinBus: uint8_t pin, peripheral_bus_type_t type, void * bus, int8_t bus_num, int8_t bus_channel
468 if (!perimanSetPinBus(io_pin, ESP32_BUS_TYPE_ADC_CONT, (void *)(cfg.adc_unit + 1), cfg.adc_unit, adc_channel)) {
469 LOGE("perimanSetPinBus to Continuous an ADC Unit %u failed!", cfg.adc_unit);
470 cleanup_rx();
471 return false;
472 }
473 rx_pins_attached = i + 1;
474 }
475#endif
476
477 // Start ADC
478 err = adc_continuous_start(adc_handle);
479 if (err != ESP_OK) {
480 LOGE("adc_continuous_start unsuccessful with error: %d", err);
481 cleanup_rx();
482 return false;
483 }
484 rx_started = true;
485
486 // Setup up optimal auto center which puts the avg at 0
489 LOGW("is_scale_to_16bit ignored: calibrated values are in mV");
490 }
491
492 LOGI("Setup ADC successful");
493
494 return true;
495 }
496
498 bool cleanup_tx() {
499 bool ok = true;
500#ifdef HAS_ESP32_DAC
501 if (dac_handle==nullptr) return true;
502 if (dac_continuous_disable(dac_handle) != ESP_OK){
503 ok = false;
504 LOGE("dac_continuous_disable failed");
505 }
506 if (dac_continuous_del_channels(dac_handle) != ESP_OK){
507 ok = false;
508 LOGE("dac_continuous_del_channels failed");
509 }
510 dac_handle = nullptr;
511#endif
512 return ok;
513 }
514
515#ifdef ARDUINO
516 // dummy detach: w/o this it's failing
517 static bool adcDetachBus(void *bus) {
518 LOGD("===> adcDetachBus: %d", (int) bus);
519 return true;
520 }
521#endif
522
524 bool cleanup_rx() {
525 bool ok = true;
526 if (adc_handle != nullptr && rx_started) {
527 if (adc_continuous_stop(adc_handle) != ESP_OK) {
528 LOGE("adc_continuous_stop failed");
529 ok = false;
530 }
531 rx_started = false;
532 }
533 if (adc_handle != nullptr) {
534 if (adc_continuous_deinit(adc_handle) != ESP_OK) {
535 LOGE("adc_continuous_deinit failed");
536 ok = false;
537 }
538 adc_handle = nullptr;
539 }
540
542
543#ifdef ARDUINO
544 cleanupAttachedRxPins();
545#endif
546 return ok;
547 }
548
551 if ((cfg.adc_bit_width < SOC_ADC_DIGI_MIN_BITWIDTH) ||
552 (cfg.adc_bit_width > SOC_ADC_DIGI_MAX_BITWIDTH)) {
553 LOGE("adc bit width: %u cannot be set, range: %u to %u", cfg.adc_bit_width,
554 (unsigned)SOC_ADC_DIGI_MIN_BITWIDTH, (unsigned)SOC_ADC_DIGI_MAX_BITWIDTH);
555 return false;
556 }
557 LOGI("adc bit width: %u, range: %u to %u", cfg.adc_bit_width,
558 (unsigned)SOC_ADC_DIGI_MIN_BITWIDTH, (unsigned)SOC_ADC_DIGI_MAX_BITWIDTH);
559 return true;
560 }
561
564 int io_pin;
565 adc_channel_t adc_channel;
566
567 int max_channels = sizeof(cfg.adc_channels) / sizeof(adc_channel_t);
568 if (cfg.channels > max_channels) {
569 LOGE("number of channels: %d, max: %d", cfg.channels, max_channels);
570 return false;
571 }
572 LOGI("channels: %d, max: %d", cfg.channels, max_channels);
573
574 // Lets make sure the adc channels are available
575 for (int i = 0; i < cfg.channels; i++) {
576 adc_channel = cfg.adc_channels[i];
577 auto err = adc_continuous_channel_to_io(cfg.adc_unit, adc_channel, &io_pin);
578 if (err != ESP_OK) {
579 LOGE("ADC channel %u is not available on ADC unit %u", adc_channel, cfg.adc_unit);
580 return false;
581 } else {
582 LOGI("ADC channel %u is on pin %u", adc_channel, io_pin);
583 }
584 }
585 return true;
586 }
587
590 LOGI("sample rate (audio): %d", cfg.sample_rate);
591 int sample_rate = cfg.sample_rate * cfg.channels;
592 if ((sample_rate < SOC_ADC_SAMPLE_FREQ_THRES_LOW) ||
593 (sample_rate > SOC_ADC_SAMPLE_FREQ_THRES_HIGH)) {
594 LOGE("sample rate eff: %u can not be set, range: %u to %u", sample_rate,
596 return false;
597 }
598 LOGI("sample rate eff: %u, range: %u to %u", sample_rate,
600
601 return true;
602 }
603
606 int supported_bits = 16; // for the time being we support only 16 bits!
607
608 // calculated default value if nothing is specified
609 if (cfg.bits_per_sample == 0) {
610 cfg.bits_per_sample = supported_bits;
611 LOGI("bits per sample set to: %d", cfg.bits_per_sample);
612 }
613
614 // check bits_per_sample
615 if (cfg.bits_per_sample != supported_bits) {
616 LOGE("bits per sample: error. It should be: %d but is %d",
617 supported_bits, cfg.bits_per_sample);
618 return false;
619 }
620 LOGI("bits per sample: %d", cfg.bits_per_sample);
621 return true;
622 }
623
627 return true;
628
629 // Initialize ADC calibration handle
630 // Calibration is applied to an ADC unit (not per channel).
631
632 // setup calibration only when requested
633 if (adc_cali_handle_active && adc_cali_handle != nullptr) {
634 return true;
635 }
636
637 if (adc_cali_handle == NULL) {
638 #if ADC_CALI_SCHEME_CURVE_FITTING_SUPPORTED
639 // curve fitting is preferred
640 adc_cali_curve_fitting_config_t cali_config;
641 cali_config.unit_id = cfg.adc_unit;
642 cali_config.atten = (adc_atten_t)cfg.adc_attenuation;
643 cali_config.bitwidth = (adc_bitwidth_t)cfg.adc_bit_width;
644 auto err = adc_cali_create_scheme_curve_fitting(&cali_config, &adc_cali_handle);
645 #elif !defined(CONFIG_IDF_TARGET_ESP32H2)
646 // line fitting is the alternative
647 adc_cali_line_fitting_config_t cali_config;
648 cali_config.unit_id = cfg.adc_unit;
649 cali_config.atten = (adc_atten_t)cfg.adc_attenuation;
650 cali_config.bitwidth = (adc_bitwidth_t)cfg.adc_bit_width;
651 auto err = adc_cali_create_scheme_line_fitting(&cali_config, &adc_cali_handle);
652 #endif
653 if (err != ESP_OK) {
654 adc_cali_handle = nullptr;
656 LOGE("creating calibration handle failed for ADC%d with atten %d and bitwidth %d",
658 return false;
659 } else {
661 LOGI("enabled calibration for ADC%d with atten %d and bitwidth %d",
663 }
664 }
665 return true;
666 }
667
668};
669
672
673} // namespace audio_tools
674
675#endif
#define SOC_ADC_SAMPLE_FREQ_THRES_LOW
Definition AnalogConfigESP32V1.h:18
#define SOC_ADC_SAMPLE_FREQ_THRES_HIGH
Definition AnalogConfigESP32V1.h:15
#define LOGW(...)
Definition AudioLoggerIDF.h:29
#define TRACEI()
Definition AudioLoggerIDF.h:32
#define TRACED()
Definition AudioLoggerIDF.h:31
#define LOGI(...)
Definition AudioLoggerIDF.h:28
#define LOGD(...)
Definition AudioLoggerIDF.h:27
#define LOGE(...)
Definition AudioLoggerIDF.h:30
#define assert(T)
Definition avr.h:10
ESP32 specific configuration for i2s input via adc using the adc_continuous API.
Definition AnalogConfigESP32V1.h:141
int buffer_count
Definition AnalogConfigESP32V1.h:148
uint8_t adc_bit_width
Definition AnalogConfigESP32V1.h:172
RxTxMode rx_tx_mode
Definition AnalogConfigESP32V1.h:153
adc_digi_convert_mode_t adc_conversion_mode
Definition AnalogConfigESP32V1.h:169
bool is_auto_center_read
Definition AnalogConfigESP32V1.h:165
TickType_t timeout
Definition AnalogConfigESP32V1.h:154
adc_unit_t adc_unit
Definition AnalogConfigESP32V1.h:174
bool is_scale_to_16bit
Definition AnalogConfigESP32V1.h:168
uint8_t adc_attenuation
Definition AnalogConfigESP32V1.h:171
adc_channel_t adc_channels[NUM_ADC_CHANNELS]
Definition AnalogConfigESP32V1.h:175
bool adc_calibration_active
Definition AnalogConfigESP32V1.h:164
adc_digi_output_format_t adc_output_type
Definition AnalogConfigESP32V1.h:170
int buffer_size
Definition AnalogConfigESP32V1.h:152
Definition AnalogDriverBase.h:9
static void scaleTo16Bits(uint8_t *data, size_t size_bytes, int adc_bits, bool is_centered)
Definition AnalogDriverBase.h:22
Definition AnalogDriverESP32V2.h:160
int getMinSamplesForAllChannels(int channels)
Definition AnalogDriverESP32V2.h:297
int16_t getCalibratedValue(ADC_DATA_TYPE sample_value)
Definition AnalogDriverESP32V2.h:285
size_t write(const uint8_t *src, size_t size_bytes) override
Write int16_t data to the Digital to Analog Converter.
Definition AnalogDriverESP32V2.h:165
IO16Bit(AnalogDriverESP32V2 *driver)
Definition AnalogDriverESP32V2.h:162
int getChannelIdx(ADC_CHANNEL_TYPE chan_num)
Definition AnalogDriverESP32V2.h:276
size_t readBytes(uint8_t *dest, size_t size_bytes)
Read int16_t data from ADC.
Definition AnalogDriverESP32V2.h:189
AnalogDriverESP32V2 * self
Definition AnalogDriverESP32V2.h:272
Vector< int > sampleIndex
Definition AnalogDriverESP32V2.h:274
Vector< uint8_t > result_data
Definition AnalogDriverESP32V2.h:273
AnalogAudioStream: A very fast DAC using DMA using the new dac_continuous API. This implementation as...
Definition AnalogDriverESP32V2.h:29
bool active
Definition AnalogDriverESP32V2.h:115
bool checkADCBitWidth()
Definition AnalogDriverESP32V2.h:550
bool active_tx
Definition AnalogDriverESP32V2.h:116
bool rx_started
Definition AnalogDriverESP32V2.h:118
virtual ~AnalogDriverESP32V2()
Destructor.
Definition AnalogDriverESP32V2.h:35
adc_cali_handle_t adc_cali_handle
Definition AnalogDriverESP32V2.h:112
bool setup_tx()
Definition AnalogDriverESP32V2.h:336
size_t write(const uint8_t *src, size_t size_bytes) override
Definition AnalogDriverESP32V2.h:89
bool active_rx
Definition AnalogDriverESP32V2.h:117
size_t readBytes(uint8_t *dest, size_t size_bytes) override
Definition AnalogDriverESP32V2.h:97
adc_continuous_handle_t adc_handle
Definition AnalogDriverESP32V2.h:111
bool setup_rx()
Definition AnalogDriverESP32V2.h:344
AnalogConfigESP32V1 cfg
Definition AnalogDriverESP32V2.h:114
bool checkADCChannels()
Definition AnalogDriverESP32V2.h:563
void end() override
Definition AnalogDriverESP32V2.h:71
int available() override
Definition AnalogDriverESP32V2.h:105
bool cleanup_tx()
Cleanup dac.
Definition AnalogDriverESP32V2.h:498
bool adc_cali_handle_active
Definition AnalogDriverESP32V2.h:113
bool cleanup_rx()
Cleanup Analog to Digital Converter.
Definition AnalogDriverESP32V2.h:524
int rx_pins_attached
Definition AnalogDriverESP32V2.h:119
bool begin(AnalogConfigESP32V1 cfg)
Definition AnalogDriverESP32V2.h:41
bool setupADCCalibration()
Definition AnalogDriverESP32V2.h:625
void cleanupADCCalibration()
Definition AnalogDriverESP32V2.h:129
bool checkADCSampleRate()
Definition AnalogDriverESP32V2.h:589
NumberFormatConverterStream converter
Definition AnalogDriverESP32V2.h:309
bool checkADCBitsPerSample()
Definition AnalogDriverESP32V2.h:605
ConverterAutoCenter auto_center
Definition AnalogDriverESP32V2.h:120
int configuredRxBytes() const
Definition AnalogDriverESP32V2.h:125
AnalogDriverESP32V2()=default
Default constructor.
Base class for all Audio Streams. It support the boolean operator to test if the object is ready with...
Definition BaseStream.h:120
Makes sure that the avg of the signal is set to 0.
Definition BaseConverter.h:239
bool begin(AudioInfo info, bool isDynamic=false)
Definition BaseConverter.h:259
size_t convert(uint8_t *src, size_t size) override
Definition BaseConverter.h:295
Converter which converts between bits_per_sample and 16 bits. The templated NumberFormatConverterStre...
Definition AudioStreamsConverter.h:471
virtual size_t write(const uint8_t *data, size_t len) override
Definition AudioStreamsConverter.h:563
bool begin(AudioInfo info, AudioInfo to, float gain=1.0f)
Definition AudioStreamsConverter.h:493
void end() override
Definition AudioStreamsConverter.h:514
Vector implementation which provides the most important methods as defined by std::vector....
Definition Vector.h:21
bool resize(size_t newSize, T value)
Definition Vector.h:266
T * data()
Definition Vector.h:316
int size()
Definition Vector.h:178
@ TX_MODE
Definition AudioTypes.h:26
@ RX_MODE
Definition AudioTypes.h:26
Generic Implementation of sound input and output for desktop environments using portaudio.
Definition LMSEchoCancellationStream.h:6
AnalogDriverArduino AnalogDriver
AnalogAudioStream.
Definition AnalogDriverArduino.h:48
sample_rate_t sample_rate
Sample Rate: e.g 44100.
Definition AudioTypes.h:58
uint16_t channels
Number of channels: 2=stereo, 1=mono.
Definition AudioTypes.h:60
uint8_t bits_per_sample
Number of bits per sample (int16_t = 16 bits)
Definition AudioTypes.h:62