arduino-audio-tools
Loading...
Searching...
No Matches
AnalogDriverESP32V1.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) || defined(DOXYGEN)
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
28public:
31
34 end();
35 }
36
40 TRACEI();
41 bool result = true;
42 this->cfg = cfg;
43
44 switch (cfg.rx_tx_mode) {
45 case TX_MODE:
46 if (!setup_tx()) return false;
47 // convert to 16 bits
48 if (!converter.begin(cfg, 16)) {
49 LOGE("converter");
50 return false;
51 }
52 active_tx = true;
53 break;
54 case RX_MODE:
55 if (!setup_rx()) return false;
56 active_rx = true;
57 break;
58 default:
59 LOGE( "Unsupported MODE: %d", cfg.rx_tx_mode);
60 return false;
61 }
62
63 active = true;
64 return active;
65 }
66
69 void end() override {
70 TRACEI();
71 if (active_tx) {
72 cleanup_tx();
73 }
74 if (active_rx) {
75 cleanup_rx();
76 }
77
78 converter.end();
79
80 active_tx = false;
81 active_rx = false;
82 active = false;
83 }
84
85 // Writes the data to the Digital to Analog Converter
86 // ----------------------------------------------------------
87 size_t write(const uint8_t *src, size_t size_bytes) override {
88 // TRACED();
89 // convert any format to int16_t
90 return converter.write(src, size_bytes);
91 }
92
93 // Reads data from DMA buffer of the Analog to Digital Converter
94 // ----------------------------------------------------------
95 size_t readBytes(uint8_t *dest, size_t size_bytes) override {
96 // TRACED();
97 // Use the IO16Bit class for reading
98 return io.readBytes(dest, size_bytes);
99 }
100
101 // How much data will there be available after reading ADC buffer
102 // ----------------------------------------------------------
103 int available() override {
104 if (!active_rx) return 0;
105 int buffered = availableFromFifoBytes();
106 return buffered > 0 ? buffered : configuredRxBytes();
107 }
108
109protected:
110
114 template<typename T>
115 class FIFO {
116 public:
117
118 FIFO() : size_(0), buffer_(nullptr), head_(0), tail_(0), count_(0) {}
119
120 FIFO(size_t size) : size_(size), buffer_(new T[size]), head_(0), tail_(0), count_(0) {}
121
123 delete[] buffer_;
124 //LOGD("FIFO destroyed: size: %d, count: %d", size_, count_);
125 }
126
127 bool push(const T& value) {
128 if (count_ < size_) {
129 buffer_[tail_] = value;
130 //LOGD("FIFO push - Value: %d at location: %d", value, tail_);
131 tail_ = (tail_ + 1) % size_;
132 count_++;
133 //LOGD("FIFO push updated tail: %d, count: %d", tail_, count_);
134 return true;
135 }
136 //LOGD("FIFO push failed - count %d > size %d", value, count_, size_);
137 return false; // Buffer full
138 }
139
140 bool pop(T& value) {
141 if (count_ > 0) {
142 value = buffer_[head_];
143 //LOGD("FIFO pop - Value: %d at location: %d", value, head_);
144 head_ = (head_ + 1) % size_;
145 count_--;
146 //LOGD("FIFO pop updated head: %d, count: %d", head_, count_);
147 return true;
148 }
149 //LOGD("FIFO pop failed - count %d == 0", count_);
150 return false; // Buffer empty
151 }
152
153 size_t size() const {
154 return count_;
155 }
156
157 bool empty() const {
158 return count_ == 0;
159 }
160
161 bool full() const {
162 return count_ == size_;
163 }
164
165 void clear() {
166 head_ = 0;
167 tail_ = 0;
168 count_ = 0;
169 }
170
171 private:
172 size_t size_;
173 T* buffer_;
174 size_t head_;
175 size_t tail_;
176 size_t count_;
177 };
178
183 bool active = false;
184 bool active_tx = false;
185 bool active_rx = false;
186 bool rx_started = false;
189 #ifdef HAS_ESP32_DAC
191 #endif
192
193 // create array of FIFO buffers, one for each channel
198
199 int configuredRxBytes() const {
200 return (cfg.buffer_size > 0) ? (int)(cfg.buffer_size * sizeof(int16_t)) : 0;
201 }
202
204 if (fifo_buffers == nullptr || cfg.channels <= 0) return 0;
205 size_t min_samples = fifo_buffers[0]->size();
206 for (int i = 1; i < cfg.channels; ++i) {
207 size_t fifo_size = fifo_buffers[i]->size();
208 if (fifo_size < min_samples) {
210 }
211 }
212 return (int)min_samples;
213 }
214
216 return availableFramesFromFifos() * cfg.channels * (int)sizeof(int16_t);
217 }
218
220 if (cfg.channels <= 0) return 8U;
221
222 size_t fallback = 8U;
223 if (SOC_ADC_DIGI_RESULT_BYTES == 0) return fallback;
224
226 if (frame_results == 0) return fallback;
227
229 if (frame_results_per_channel == 0) return fallback;
230
231 return frame_results_per_channel + 4U;
232 }
233
235 for (int j = 0; j < cfg.channels; ++j) {
236 if (cfg.adc_channels[j] == chan_num) {
237 return j;
238 }
239 }
240 return -1;
241 }
242
244 if (fifo_buffers == nullptr) return;
245 for (int i = 0; i < cfg.channels; ++i) {
246 if (fifo_buffers[i] != nullptr) {
247 fifo_buffers[i]->clear();
248 }
249 }
250 }
251
253 delete[] rx_result_buffer;
254 rx_result_buffer = nullptr;
257 }
258
259 bool isValidType2Record(const adc_digi_output_data_t& sample) const {
261
262 uint32_t chan_num = sample.type2.channel;
264 LOGE("Invalid TYPE2 ADC channel: %u", (unsigned)chan_num);
265 return false;
266 }
267
268#ifdef ADC_CONV_SINGLE_UNIT_1
270 sample.type2.unit != 0) {
271 LOGE("Invalid TYPE2 ADC unit for ADC1 mode: %u",
272 (unsigned)sample.type2.unit);
273 return false;
274 }
275#endif
276#ifdef ADC_CONV_SINGLE_UNIT_2
278 sample.type2.unit != 1) {
279 LOGE("Invalid TYPE2 ADC unit for ADC2 mode: %u",
280 (unsigned)sample.type2.unit);
281 return false;
282 }
283#endif
284 return true;
285 }
286
289 return static_cast<int16_t>(data);
290 }
291
292 int data_milliVolts = 0;
295 if (err != ESP_OK) {
296 LOGE("adc_cali_raw_to_voltage error: %d", err);
297 return 0;
298 }
299 return static_cast<int16_t>(data_milliVolts);
300 }
301
303 int samples_read) {
304 if (data == nullptr) return false;
305
306 for (int i = 0; i < samples_read; ++i) {
307 const adc_digi_output_data_t* sample = &data[i];
308 if (!isValidType2Record(*sample)) {
309 LOGE("ADC reorder resync on invalid TYPE2 record at sample %d", i);
311 return false;
312 }
313
316 if (channel_idx < 0) {
317 LOGE("ADC reorder resync on invalid channel %u at sample %d",
318 (unsigned)chan_num, i);
320 return false;
321 }
322
325 LOGE("ADC reorder FIFO overflow on channel index %d (channel %u)",
326 channel_idx, (unsigned)chan_num);
328 return false;
329 }
330 }
331 return true;
332 }
333
335 if (dest == nullptr || max_frames <= 0 || cfg.channels <= 0) return 0;
336
338 int frames_to_emit =
340 int frames_emitted = 0;
341
342 for (int frame = 0; frame < frames_to_emit; ++frame) {
344 for (int ch = 0; ch < cfg.channels; ++ch) {
345 if (!fifo_buffers[ch]->pop(frame_data[ch])) {
346 LOGE("ADC reorder pop failed on channel index %d", ch);
348 return frames_emitted;
349 }
350 }
351
352 for (int ch = 0; ch < cfg.channels; ++ch) {
355 }
357 }
358
359 return frames_emitted;
360 }
361
363 if (fifo_buffers == nullptr) return;
364 for (int i = 0; i < cfg.channels; ++i) {
365 delete fifo_buffers[i];
366 }
367 delete[] fifo_buffers;
368 fifo_buffers = nullptr;
369 }
370
372 if (!adc_cali_handle_active || adc_cali_handle == nullptr) return;
373#if ADC_CALI_SCHEME_CURVE_FITTING_SUPPORTED
375#elif !defined(CONFIG_IDF_TARGET_ESP32H2) && !defined(CONFIG_IDF_TARGET_ESP32P4)
377#endif
378 adc_cali_handle = nullptr;
380 }
381
382#ifdef ARDUINO
383 void cleanupAttachedRxPins() {
385 for (int i = 0; i < rx_pins_attached; ++i) {
386 adc_channel_t adc_channel = cfg.adc_channels[i];
387 int io_pin;
391 LOGE("perimanClearPinBus failed!");
392 }
393 }
394 }
396 }
397#endif
398
399 // 16Bit Audiostream for ESP32
400 // ----------------------------------------------------------
401 class IO16Bit : public AudioStream {
402 public:
403 IO16Bit(AnalogDriverESP32V1 *driver) { self = driver; }
404
405 // Write int16_t data to the Digital to Analog Converter
406 // ----------------------------------------------------------
407 size_t write(const uint8_t *src, size_t size_bytes) override {
408 // TRACED();
409 #ifdef HAS_ESP32_DAC
410 size_t result = 0;
411 // Convert signed 16-bit to unsigned 8-bit
413 uint8_t *data8 = (uint8_t *)src;
414 int samples = size_bytes / 2;
415
416 // Process data in batches to reduce the number of conversions and writes
417 for (int j = 0; j < samples; j++) {
418 data8[j] = (32768u + data16[j]) >> 8;
419 }
420
421 if (dac_continuous_write(self->dac_handle, data8, samples, &result, self->cfg.timeout) != ESP_OK) {
422 result = 0;
423 }
424 return result * 2;
425 #else
426 return 0;
427 #endif
428 }
429
430 // Read int16_t data from Analog to Digital Converter
431 // ----------------------------------------------------------
432 // FYI
433 // typedef struct {
434 // union {
435 // struct {
436 // uint16_t data: 12; /*!<ADC real output data info. Resolution: 12 bit. */
437 // uint16_t channel: 4; /*!<ADC channel index info. */
438 // } type1; /*!<ADC type1 */
439 // struct {
440 // uint16_t data: 11; /*!<ADC real output data info. Resolution: 11 bit. */
441 // uint16_t channel: 4; /*!<ADC channel index info. For ESP32-S2:
442 // If (channel < ADC_CHANNEL_MAX), The data is valid.
443 // If (channel > ADC_CHANNEL_MAX), The data is invalid. */
444 // uint16_t unit: 1; /*!<ADC unit index info. 0: ADC1; 1: ADC2. */
445 // } type2; /*!<When the configured output format is 11bit.*/
446 // uint16_t val; /*!<Raw data value */
447 // };
448 // } adc_digi_output_data_t;
449
450 size_t readBytes(uint8_t *dest, size_t size_bytes) {
451 if (dest == nullptr || size_bytes == 0 || self->cfg.channels <= 0) {
452 return 0;
453 }
454 if (self->rx_result_buffer == nullptr || self->rx_result_buffer_bytes == 0) {
455 LOGE("ADC RX scratch buffer is not initialized");
456 return 0;
457 }
458
459 const size_t frame_size_bytes =
460 (size_t)self->cfg.channels * sizeof(int16_t);
461 const size_t frames_requested = size_bytes / frame_size_bytes;
462 if (frames_requested == 0) {
463 return 0;
464 }
465
466 int16_t* result16 = reinterpret_cast<int16_t*>(dest);
467 int frames_provided =
469
470 while (frames_provided < (int)frames_requested) {
474 reinterpret_cast<uint8_t*>(self->rx_result_buffer),
477 if (err != ESP_OK) {
478 if (err != ESP_ERR_TIMEOUT) {
479 LOGE("adc_continuous_read unsuccessful: %d", err);
480 }
481 break;
482 }
483
485 if (samples_read <= 0) {
486 break;
487 }
488
490 samples_read)) {
491 break;
492 }
493
497 }
498
502 }
503 return bytes_provided;
504 }
505
506 protected:
508
509 } io{this};
510
512
513 // Setup Digital to Analog
514 // ----------------------------------------------------------
515 #ifdef HAS_ESP32_DAC
516 bool setup_tx() {
518 .chan_mask = cfg.channels == 1 ? cfg.dac_mono_channel : DAC_CHANNEL_MASK_ALL,
519 .desc_num = (uint32_t)cfg.buffer_count,
520 .buf_size = (size_t)cfg.buffer_size,
521 .freq_hz = (uint32_t)cfg.sample_rate,
522 .offset = 0,
523 .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
525 };
526 // Allocate continuous channels
528 LOGE("new_channels");
529 return false;
530 }
532 LOGE("enable");
533 return false;
534 }
535 return true;
536 }
537 #else
538 bool setup_tx() {
539 LOGE("DAC not supported");
540 return false;
541 }
542 #endif
543
544 // Setup Analog to Digital Converter
545 // ----------------------------------------------------------
546 bool setup_rx() {
547 adc_channel_t adc_channel;
548 int io_pin;
549 esp_err_t err;
550
551 // Check the configuration
552 if (!checkADCChannels()) return false;
553 if (!checkADCSampleRate()) return false;
554 if (!checkADCBitWidth()) return false;
555 if (!checkADCBitsPerSample()) return false;
556
557 if (adc_handle != nullptr) {
558 LOGE("adc unit %u continuous is already initialized. Please call end() first!", cfg.adc_unit);
559 return false;
560 }
561
562 #ifdef ARDUINO
563 // Set periman deinit callback
564 // TODO, currently handled in end() method
565
566 // Set the pins/channels to INIT state
567 for (int i = 0; i < cfg.channels; i++) {
568 adc_channel = cfg.adc_channels[i];
571 LOGE("perimanClearPinBus failed!");
572 return false;
573 }
574 }
575 #endif
576
578 #if CONFIG_IDF_TARGET_ESP32 || CONFIG_IDF_TARGET_ESP32S2
580 #endif
581
585 LOGE(
586 "buffer_size is too big for one ADC DMA frame: %u samples = %u "
587 "bytes, max %u samples / %u bytes",
589 (unsigned)max_samples_per_frame,
590 (unsigned)rx_max_conv_frame_bytes);
591 return false;
592 } else {
593 LOGI(
594 "RX DMA frame: %u conversion results, %u bytes (max %u results / "
595 "%u bytes)",
597 (unsigned)max_samples_per_frame,
598 (unsigned)rx_max_conv_frame_bytes);
599 }
600
601 // Create adc_continuous handle
604 adc_config.max_store_buf_size = (uint32_t)conv_frame_size * rx_frame_count;
605 adc_config.conv_frame_size = (uint32_t) conv_frame_size;
606#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 2, 0)
607 adc_config.flags.flush_pool = true;
608#endif
609 LOGI("RX pool: %u frames, %u bytes", (unsigned)rx_frame_count,
610 (unsigned)adc_config.max_store_buf_size);
611 err = adc_continuous_new_handle(&adc_config, &adc_handle);
612 if (err != ESP_OK) {
613 LOGE("adc_continuous_new_handle failed with error: %d", err);
614 return false;
615 } else {
616 LOGI("adc_continuous_new_handle successful");
617 }
618
619 // Configure the ADC patterns
621 for (int i = 0; i < cfg.channels; i++) {
624 adc_pattern[i].channel = (uint8_t)ch;
625 adc_pattern[i].unit = (uint8_t) cfg.adc_unit;
626 adc_pattern[i].bit_width = (uint8_t) cfg.adc_bit_width;
627 }
628
629 // Configure the ADC
631 .pattern_num = (uint32_t) cfg.channels,
632 .adc_pattern = adc_pattern,
633 .sample_freq_hz = (uint32_t)cfg.sample_rate * cfg.channels,
636 };
637
638 // Log the configuration
639 LOGI("dig_cfg.sample_freq_hz: %u", (unsigned)dig_cfg.sample_freq_hz);
640 LOGI("dig_cfg.conv_mode: %u (1: unit 1, 2: unit 2, 3: both)", dig_cfg.conv_mode);
641 LOGI("dig_cfg.format: %u (0 is type1: [12bit data, 4bit channel])", dig_cfg.format);
642 for (int i = 0; i < cfg.channels; i++) {
643 LOGI("dig_cfg.adc_pattern[%d].atten: %u", i, dig_cfg.adc_pattern[i].atten);
644 LOGI("dig_cfg.adc_pattern[%d].channel: %u", i, dig_cfg.adc_pattern[i].channel);
645 LOGI("dig_cfg.adc_pattern[%d].unit: %u", i, dig_cfg.adc_pattern[i].unit);
646 LOGI("dig_cfg.adc_pattern[%d].bit_width: %u", i, dig_cfg.adc_pattern[i].bit_width);
647 }
648
649 // Initialize ADC
651 if (err != ESP_OK) {
652 LOGE("adc_continuous_config unsuccessful with error: %d", err);
653 cleanup_rx();
654 return false;
655 }
656 LOGI("adc_continuous_config successful");
657
658 // Set up optional calibration
659 if (!setupADCCalibration()) {
660 cleanup_rx();
661 return false;
662 }
663
664 // Attach the pins to the ADC unit
665#ifdef ARDUINO
666 for (int i = 0; i < cfg.channels; i++) {
667 adc_channel = cfg.adc_channels[i];
669 // perimanSetPinBus: uint8_t pin, peripheral_bus_type_t type, void * bus, int8_t bus_num, int8_t bus_channel
670 if (!perimanSetPinBus(io_pin, ESP32_BUS_TYPE_ADC_CONT, (void *)(cfg.adc_unit + 1), cfg.adc_unit, adc_channel)) {
671 LOGE("perimanSetPinBus to Continuous an ADC Unit %u failed!", cfg.adc_unit);
672 cleanup_rx();
673 return false;
674 }
675 rx_pins_attached = i + 1;
676 }
677#endif
678
679 // Start ADC
681 if (err != ESP_OK) {
682 LOGE("adc_continuous_start unsuccessful with error: %d", err);
683 cleanup_rx();
684 return false;
685 }
686 rx_started = true;
687
688 // Setup up optimal auto center which puts the avg at 0
690
696 if (rx_result_buffer == nullptr || rx_result_buffer_samples == 0) {
697 LOGE("Failed to allocate ADC RX scratch buffer");
698 cleanup_rx();
699 return false;
700 }
701 LOGI("ADC RX scratch buffer allocated for %u bytes / %u samples",
703
704 // Keep the reorder FIFOs small: they absorb channel skew only and are
705 // not sized for the caller's full readBytes() window.
707 fifo_buffers = new FIFO<ADC_DATA_TYPE>*[cfg.channels](); // Allocate an array of FIFO objects
708 for (int i = 0; i < cfg.channels; ++i) {
710 }
712 LOGI("%d FIFO buffers allocated of size %u from DMA frame %u bytes",
713 cfg.channels, (unsigned)fifo_size, (unsigned)conv_frame_size);
714
715 LOGI("Setup ADC successful");
716
717 return true;
718 }
719
721 bool cleanup_tx() {
722 bool ok = true;
723#ifdef HAS_ESP32_DAC
724 if (dac_handle==nullptr) return true;
726 ok = false;
727 LOGE("dac_continuous_disable failed");
728 }
730 ok = false;
731 LOGE("dac_continuous_del_channels failed");
732 }
733 dac_handle = nullptr;
734#endif
735 return ok;
736 }
737
738#ifdef ARDUINO
739 // dummy detach: w/o this it's failing
740 static bool adcDetachBus(void *bus) {
741 LOGD("===> adcDetachBus: %d", (int) bus);
742 return true;
743 }
744#endif
745
747 bool cleanup_rx() {
748 bool ok = true;
749 if (adc_handle != nullptr && rx_started) {
751 LOGE("adc_continuous_stop failed");
752 ok = false;
753 }
754 rx_started = false;
755 }
756 if (adc_handle != nullptr) {
758 LOGE("adc_continuous_deinit failed");
759 ok = false;
760 }
761 adc_handle = nullptr;
762 }
763
767
768#ifdef ARDUINO
770#endif
771 return ok;
772 }
773
778 LOGE("adc bit width: %u cannot be set, range: %u to %u", cfg.adc_bit_width,
780 return false;
781 }
782 LOGI("adc bit width: %u, range: %u to %u", cfg.adc_bit_width,
784 return true;
785 }
786
789 int io_pin;
790 adc_channel_t adc_channel;
791
792 int max_channels = sizeof(cfg.adc_channels) / sizeof(adc_channel_t);
793 if (cfg.channels > max_channels) {
794 LOGE("number of channels: %d, max: %d", cfg.channels, max_channels);
795 return false;
796 }
797 LOGI("channels: %d, max: %d", cfg.channels, max_channels);
798
799 // Lets make sure the adc channels are available
800 for (int i = 0; i < cfg.channels; i++) {
801 adc_channel = cfg.adc_channels[i];
802 auto err = adc_continuous_channel_to_io(cfg.adc_unit, adc_channel, &io_pin);
803 if (err != ESP_OK) {
804 LOGE("ADC channel %u is not available on ADC unit %u", adc_channel, cfg.adc_unit);
805 return false;
806 } else {
807 LOGI("ADC channel %u is on pin %u", adc_channel, io_pin);
808 }
809 }
810 return true;
811 }
812
815 int sample_rate = cfg.sample_rate * cfg.channels;
816 if ((sample_rate < SOC_ADC_SAMPLE_FREQ_THRES_LOW) ||
817 (sample_rate > SOC_ADC_SAMPLE_FREQ_THRES_HIGH)) {
818 LOGE("sample rate eff: %u can not be set, range: %u to %u", sample_rate,
820 return false;
821 }
822 LOGI("sample rate eff: %u, range: %u to %u", sample_rate,
824
825 return true;
826 }
827
830 int supported_bits = 16; // for the time being we support only 16 bits!
831
832 // calculated default value if nothing is specified
833 if (cfg.bits_per_sample == 0) {
835 LOGI("bits per sample set to: %d", cfg.bits_per_sample);
836 }
837
838 // check bits_per_sample
840 LOGE("bits per sample: error. It should be: %d but is %d",
842 return false;
843 }
844 LOGI("bits per sample: %d", cfg.bits_per_sample);
845 return true;
846 }
847
851 return true;
852
853 // Initialize ADC calibration handle
854 // Calibration is applied to an ADC unit (not per channel).
855
856 // setup calibration only when requested
857 esp_err_t err = ESP_OK;
858
859 if (adc_cali_handle_active && adc_cali_handle != nullptr) {
860 return true;
861 }
862
863 if (adc_cali_handle == NULL) {
864 #if ADC_CALI_SCHEME_CURVE_FITTING_SUPPORTED
865 // curve fitting is preferred
867 cali_config.unit_id = cfg.adc_unit;
871 #elif !defined(CONFIG_IDF_TARGET_ESP32H2) && !defined(CONFIG_IDF_TARGET_ESP32P4)
872 // line fitting is the alternative
874 cali_config.unit_id = cfg.adc_unit;
878 #endif
879 if (err != ESP_OK) {
880 adc_cali_handle = nullptr;
882 LOGE("creating calibration handle failed for ADC%d with atten %d and bitwidth %d",
884 return false;
885 } else {
887 LOGI("enabled calibration for ADC%d with atten %d and bitwidth %d",
889 }
890 }
891 return true;
892 }
893
894};
895
898
899} // namespace audio_tools
900
901#endif
#define TRACEI()
Definition AudioLoggerIDF.h:32
#define LOGI(...)
Definition AudioLoggerIDF.h:28
#define LOGD(...)
Definition AudioLoggerIDF.h:27
#define LOGE(...)
Definition AudioLoggerIDF.h:30
ESP32 specific configuration for i2s input via adc using the adc_continuous API.
Definition AnalogConfigESP32V1.h:125
int buffer_count
Definition AnalogConfigESP32V1.h:132
uint8_t adc_bit_width
Definition AnalogConfigESP32V1.h:153
RxTxMode rx_tx_mode
Definition AnalogConfigESP32V1.h:137
adc_digi_convert_mode_t adc_conversion_mode
Definition AnalogConfigESP32V1.h:150
bool is_auto_center_read
Definition AnalogConfigESP32V1.h:149
TickType_t timeout
Definition AnalogConfigESP32V1.h:138
adc_unit_t adc_unit
Definition AnalogConfigESP32V1.h:155
uint8_t adc_attenuation
Definition AnalogConfigESP32V1.h:152
adc_channel_t adc_channels[NUM_ADC_CHANNELS]
Definition AnalogConfigESP32V1.h:156
bool adc_calibration_active
Definition AnalogConfigESP32V1.h:148
adc_digi_output_format_t adc_output_type
Definition AnalogConfigESP32V1.h:151
int buffer_size
Definition AnalogConfigESP32V1.h:136
Definition AnalogDriverBase.h:13
Custom FIFO class.
Definition AnalogDriverESP32V1.h:115
bool push(const T &value)
Definition AnalogDriverESP32V1.h:127
FIFO(size_t size)
Definition AnalogDriverESP32V1.h:120
size_t size() const
Definition AnalogDriverESP32V1.h:153
bool empty() const
Definition AnalogDriverESP32V1.h:157
~FIFO()
Definition AnalogDriverESP32V1.h:122
bool pop(T &value)
Definition AnalogDriverESP32V1.h:140
bool full() const
Definition AnalogDriverESP32V1.h:161
FIFO()
Definition AnalogDriverESP32V1.h:118
void clear()
Definition AnalogDriverESP32V1.h:165
Definition AnalogDriverESP32V1.h:401
size_t write(const uint8_t *src, size_t size_bytes) override
Definition AnalogDriverESP32V1.h:407
IO16Bit(AnalogDriverESP32V1 *driver)
Definition AnalogDriverESP32V1.h:403
size_t readBytes(uint8_t *dest, size_t size_bytes)
Definition AnalogDriverESP32V1.h:450
AnalogDriverESP32V1 * self
Definition AnalogDriverESP32V1.h:507
AnalogAudioStream: A very fast DAC using DMA using the new dac_continuous API.
Definition AnalogDriverESP32V1.h:27
size_t fifoCapacityFromConvFrameBytes(size_t conv_frame_bytes) const
Definition AnalogDriverESP32V1.h:219
bool active
Definition AnalogDriverESP32V1.h:183
bool checkADCBitWidth()
Definition AnalogDriverESP32V1.h:775
virtual ~AnalogDriverESP32V1()
Destructor.
Definition AnalogDriverESP32V1.h:33
bool active_tx
Definition AnalogDriverESP32V1.h:184
int16_t getOutputSample(ADC_DATA_TYPE data)
Definition AnalogDriverESP32V1.h:287
void resetReorderState()
Definition AnalogDriverESP32V1.h:243
bool rx_started
Definition AnalogDriverESP32V1.h:186
size_t rx_result_buffer_samples
Definition AnalogDriverESP32V1.h:196
adc_cali_handle_t adc_cali_handle
Definition AnalogDriverESP32V1.h:180
bool setup_tx()
Definition AnalogDriverESP32V1.h:538
int availableFramesFromFifos() const
Definition AnalogDriverESP32V1.h:203
size_t write(const uint8_t *src, size_t size_bytes) override
Definition AnalogDriverESP32V1.h:87
bool active_rx
Definition AnalogDriverESP32V1.h:185
size_t readBytes(uint8_t *dest, size_t size_bytes) override
Definition AnalogDriverESP32V1.h:95
adc_digi_output_data_t * rx_result_buffer
Definition AnalogDriverESP32V1.h:195
adc_continuous_handle_t adc_handle
Definition AnalogDriverESP32V1.h:179
bool isValidType2Record(const adc_digi_output_data_t &sample) const
Definition AnalogDriverESP32V1.h:259
int emitFramesFromFifos(int16_t *dest, int max_frames)
Definition AnalogDriverESP32V1.h:334
bool setup_rx()
Definition AnalogDriverESP32V1.h:546
AnalogConfigESP32V1 cfg
Definition AnalogDriverESP32V1.h:182
bool checkADCChannels()
Definition AnalogDriverESP32V1.h:788
void end() override
Definition AnalogDriverESP32V1.h:69
int available() override
Definition AnalogDriverESP32V1.h:103
bool cleanup_tx()
Cleanup dac.
Definition AnalogDriverESP32V1.h:721
bool adc_cali_handle_active
Definition AnalogDriverESP32V1.h:181
bool cleanup_rx()
Cleanup Analog to Digital Converter.
Definition AnalogDriverESP32V1.h:747
int rx_pins_attached
Definition AnalogDriverESP32V1.h:187
bool begin(AnalogConfigESP32V1 cfg)
Definition AnalogDriverESP32V1.h:39
AnalogDriverESP32V1()
Default constructor.
Definition AnalogDriverESP32V1.h:30
size_t rx_result_buffer_bytes
Definition AnalogDriverESP32V1.h:197
void cleanupFifoBuffers()
Definition AnalogDriverESP32V1.h:362
void cleanupScratchBuffer()
Definition AnalogDriverESP32V1.h:252
int getChannelIndex(ADC_CHANNEL_TYPE chan_num) const
Definition AnalogDriverESP32V1.h:234
bool setupADCCalibration()
Definition AnalogDriverESP32V1.h:849
FIFO< ADC_DATA_TYPE > ** fifo_buffers
Definition AnalogDriverESP32V1.h:194
void cleanupADCCalibration()
Definition AnalogDriverESP32V1.h:371
bool checkADCSampleRate()
Definition AnalogDriverESP32V1.h:814
NumberFormatConverterStream converter
Definition AnalogDriverESP32V1.h:511
bool checkADCBitsPerSample()
Definition AnalogDriverESP32V1.h:829
int availableFromFifoBytes() const
Definition AnalogDriverESP32V1.h:215
ConverterAutoCenter auto_center
Definition AnalogDriverESP32V1.h:188
bool pushAdcChunkToReorderBuffers(const adc_digi_output_data_t *data, int samples_read)
Definition AnalogDriverESP32V1.h:302
int configuredRxBytes() const
Definition AnalogDriverESP32V1.h:199
Base class for all Audio Streams. It support the boolean operator to test if the object is ready with...
Definition BaseStream.h:122
Makes sure that the avg of the signal is set to 0.
Definition BaseConverter.h:198
bool begin(AudioInfo info, bool isDynamic=false)
Definition BaseConverter.h:218
size_t convert(uint8_t *src, size_t size) override
Definition BaseConverter.h:254
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
@ TX_MODE
Definition AudioTypes.h:30
@ RX_MODE
Definition AudioTypes.h:30
Generic Implementation of sound input and output for desktop environments using portaudio.
Definition AudioCodecsBase.h:10
AnalogDriverArduino AnalogDriver
AnalogAudioStream.
Definition AnalogDriverArduino.h:48
size_t writeData(Print *p_out, T *data, int samples, int maxSamples=512)
Definition AudioTypes.h:512
sample_rate_t sample_rate
Sample Rate: e.g 44100.
Definition AudioTypes.h:57
uint16_t channels
Number of channels: 2=stereo, 1=mono.
Definition AudioTypes.h:59
uint8_t bits_per_sample
Number of bits per sample (int16_t = 16 bits)
Definition AudioTypes.h:61