diff --git a/examples/tests/adc/read/read.ino b/examples/tests/adc/read/read.ino new file mode 100644 index 0000000000..ce555f108a --- /dev/null +++ b/examples/tests/adc/read/read.ino @@ -0,0 +1,31 @@ +#include "AudioTools.h" +#include "AudioTools.h" + +AudioInfo info(44100, 1, 16); +AnalogAudioStream adc; +MeasuringStream out(10, &Serial); +StreamCopy copier(out, adc); + +// Arduino Setup +void setup(void) { + Serial.begin(115200); + AudioLogger::instance().begin(Serial, AudioLogger::Info); + + LOGI("Supported samples rates: %d - %d", SOC_ADC_SAMPLE_FREQ_THRES_LOW, SOC_ADC_SAMPLE_FREQ_THRES_HIGH) + + auto cfg = adc.defaultConfig(RX_MODE); + cfg.copyFrom(info); + //cfg.use_apll = false; // try with yes + if (!adc.begin(cfg)) { + LOGE("adc.begin() failed"); + stop(); + } + + // make sure that we have the correct channels set up + out.begin(info); +} + +// Arduino loop - copy data +void loop() { + copier.copy(); +} \ No newline at end of file diff --git a/src/AudioAnalog/AnalogAudioESP32V1.h b/src/AudioAnalog/AnalogAudioESP32V1.h index 4816a090a7..ed18ef9169 100644 --- a/src/AudioAnalog/AnalogAudioESP32V1.h +++ b/src/AudioAnalog/AnalogAudioESP32V1.h @@ -88,7 +88,7 @@ class AnalogDriverESP32V1 : public AnalogDriverBase { } int available() override { - return 0; + return active_rx ? DEFAULT_BUFFER_SIZE : 0; } void setTimeout(int value){ @@ -201,19 +201,19 @@ class AnalogDriverESP32V1 : public AnalogDriverBase { LOGE("channels: %d, max: %d", cfg.channels, max_channels); return false; } + adc_continuous_handle_cfg_t adc_config = { .max_store_buf_size = (uint32_t)cfg.buffer_size * cfg.buffer_count, - .conv_frame_size = (uint32_t)cfg.buffer_size, + .conv_frame_size = (uint32_t)cfg.buffer_size / SOC_ADC_DIGI_DATA_BYTES_PER_CONV * SOC_ADC_DIGI_DATA_BYTES_PER_CONV, }; adc_continuous_new_handle(&adc_config, &adc_handle); - adc_continuous_config_t dvig_cfg = { + adc_continuous_config_t dig_cfg = { .sample_freq_hz = (uint32_t)cfg.sample_rate, .conv_mode = (adc_digi_convert_mode_t)cfg.adc_conversion_mode, .format = (adc_digi_output_format_t)cfg.adc_output_type, }; adc_digi_pattern_config_t adc_pattern[cfg.channels] = {0}; - adc_continuous_config_t dig_cfg = {}; dig_cfg.pattern_num = cfg.channels; for (int i = 0; i < cfg.channels; i++) { uint8_t unit = GET_UNIT(cfg.adc_channels[i]); @@ -232,11 +232,18 @@ class AnalogDriverESP32V1 : public AnalogDriverBase { LOGE("adc_continuous_config"); return false; } + + if (adc_continuous_start(adc_handle)!=ESP_OK){ + LOGE("adc_continuous_start"); + return false; + } + return true; } }; +#define ANALOG_DRIVER_DEFINED /// @brief AnalogAudioStream using AnalogDriver = AnalogDriverESP32V1;