Skip to content

Commit

Permalink
esp32 adc move defines to config
Browse files Browse the repository at this point in the history
  • Loading branch information
pschatzmann committed Nov 12, 2023
1 parent 1e8e3c4 commit ec451e1
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 26 deletions.
14 changes: 2 additions & 12 deletions src/AudioAnalog/AnalogAudioESP32V1.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,12 @@
#if defined(ESP32) && defined(USE_ANALOG) && \
ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 0, 0) || \
defined(DOXYGEN)

#include "AudioAnalog/AnalogConfigESP32V1.h"
#include "AudioAnalog/AnalogAudioBase.h"
#include "AudioTools/AudioStreams.h"
#include "AudioTools/AudioStreamsConverter.h"

#if CONFIG_IDF_TARGET_ESP32 || CONFIG_IDF_TARGET_ESP32S2
#define AUDIO_ADC_OUTPUT_TYPE ADC_DIGI_OUTPUT_FORMAT_TYPE1
#define AUDIO_ADC_GET_CHANNEL(p_data) ((p_data)->type1.channel)
#define AUDIO_ADC_GET_DATA(p_data) ((p_data)->type1.data)
#else
#define AUDIO_ADC_OUTPUT_TYPE ADC_DIGI_OUTPUT_FORMAT_TYPE2
#define AUDIO_ADC_GET_CHANNEL(p_data) ((p_data)->type2.channel)
#define AUDIO_ADC_GET_DATA(p_data) ((p_data)->type2.data)
#endif
#define GET_UNIT(x) ((x >> 3) & 0x1)



namespace audio_tools {

Expand Down
39 changes: 25 additions & 14 deletions src/AudioAnalog/AnalogConfigESP32V1.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,36 @@
#include "esp_adc/adc_cali_scheme.h"

#if CONFIG_IDF_TARGET_ESP32
#define ADC_CONV_MODE ADC_CONV_SINGLE_UNIT_1 // ADC2 and Wifi work together
#define ADC_OUTPUT_TYPE ADC_DIGI_OUTPUT_FORMAT_TYPE1
#define ADC_CHANNELS {ADC_CHANNEL_6, ADC_CHANNEL_7}
#define HAS_ESP32_DAC
# define ADC_CONV_MODE ADC_CONV_SINGLE_UNIT_1 // ADC2 and Wifi work together
# define ADC_OUTPUT_TYPE ADC_DIGI_OUTPUT_FORMAT_TYPE1
# define ADC_CHANNELS {ADC_CHANNEL_6, ADC_CHANNEL_7}
# define AUDIO_ADC_GET_CHANNEL(p_data) ((p_data)->type1.channel)
# define AUDIO_ADC_GET_DATA(p_data) ((p_data)->type1.data)
# define HAS_ESP32_DAC
#elif CONFIG_IDF_TARGET_ESP32S2
#define ADC_CONV_MODE ADC_CONV_SINGLE_UNIT_1 // ADC2 competes with WiFi and WiFi has priority, ADC_CONV_BOTH_UNIT
#define ADC_OUTPUT_TYPE ADC_DIGI_OUTPUT_FORMAT_TYPE2
#define ADC_CHANNELS {ADC_CHANNEL_2, ADC_CHANNEL_3}
#define HAS_ESP32_DAC
# define ADC_CONV_MODE ADC_CONV_SINGLE_UNIT_1 // ADC2 competes with WiFi and WiFi has priority, ADC_CONV_BOTH_UNIT
# define ADC_OUTPUT_TYPE ADC_DIGI_OUTPUT_FORMAT_TYPE2
# define AUDIO_ADC_GET_CHANNEL(p_data) ((p_data)->type2.channel)
# define AUDIO_ADC_GET_DATA(p_data) ((p_data)->type2.data)
# define ADC_CHANNELS {ADC_CHANNEL_2, ADC_CHANNEL_3}
# define HAS_ESP32_DAC
#elif CONFIG_IDF_TARGET_ESP32C3 || CONFIG_IDF_TARGET_ESP32H2 || CONFIG_IDF_TARGET_ESP32C2 || CONFIG_IDF_TARGET_ESP32C6
#define ADC_CONV_MODE ADC_CONV_ALTER_UNIT //ESP32C3 only supports alter mode
#define ADC_OUTPUT_TYPE ADC_DIGI_OUTPUT_FORMAT_TYPE2
#define ADC_CHANNELS {ADC_CHANNEL_2, ADC_CHANNEL_3}
# define ADC_CONV_MODE ADC_CONV_ALTER_UNIT //ESP32C3 only supports alter mode
# define ADC_OUTPUT_TYPE ADC_DIGI_OUTPUT_FORMAT_TYPE2
# define AUDIO_ADC_GET_CHANNEL(p_data) ((p_data)->type2.channel)
# define AUDIO_ADC_GET_DATA(p_data) ((p_data)->type2.data)
# define ADC_CHANNELS {ADC_CHANNEL_2, ADC_CHANNEL_3}
#elif CONFIG_IDF_TARGET_ESP32S3
#define ADC_CONV_MODE ADC_CONV_SINGLE_UNIT_1 // ADC2 competes with WiFi and WiFi has priority
#define ADC_OUTPUT_TYPE ADC_DIGI_OUTPUT_FORMAT_TYPE2
#define ADC_CHANNELS {ADC_CHANNEL_2, ADC_CHANNEL_3} // These are the I2C SDA and SCL pins on Adafruit ESP32-S3 feather , Channel 4&5 might be better
# define ADC_CONV_MODE ADC_CONV_SINGLE_UNIT_1 // ADC2 competes with WiFi and WiFi has priority
# define ADC_OUTPUT_TYPE ADC_DIGI_OUTPUT_FORMAT_TYPE2
# define AUDIO_ADC_GET_CHANNEL(p_data) ((p_data)->type2.channel)
# define AUDIO_ADC_GET_DATA(p_data) ((p_data)->type2.data)
# define ADC_CHANNELS {ADC_CHANNEL_2, ADC_CHANNEL_3} // These are the I2C SDA and SCL pins on Adafruit ESP32-S3 feather , Channel 4&5 might be better
#endif

#define GET_UNIT(x) ((x >> 3) & 0x1)


#ifdef HAS_ESP32_DAC
# include "driver/dac_continuous.h"
#endif
Expand Down

0 comments on commit ec451e1

Please sign in to comment.