mirror of
https://github.com/esphome/esphome.git
synced 2024-11-13 02:37:47 +01:00
Swap ADC back to use 'int' because C3 (#5151)
This commit is contained in:
parent
73db164fb1
commit
3843d21dbf
3 changed files with 14 additions and 6 deletions
|
@ -32,8 +32,8 @@ static const int32_t SOC_ADC_RTC_MAX_BITWIDTH = 12;
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static const int32_t ADC_MAX = (1 << SOC_ADC_RTC_MAX_BITWIDTH) - 1; // 4095 (12 bit) or 8191 (13 bit)
|
static const int ADC_MAX = (1 << SOC_ADC_RTC_MAX_BITWIDTH) - 1; // 4095 (12 bit) or 8191 (13 bit)
|
||||||
static const int32_t ADC_HALF = (1 << SOC_ADC_RTC_MAX_BITWIDTH) >> 1; // 2048 (12 bit) or 4096 (13 bit)
|
static const int ADC_HALF = (1 << SOC_ADC_RTC_MAX_BITWIDTH) >> 1; // 2048 (12 bit) or 4096 (13 bit)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef USE_RP2040
|
#ifdef USE_RP2040
|
||||||
|
@ -59,7 +59,7 @@ extern "C"
|
||||||
}
|
}
|
||||||
|
|
||||||
// load characteristics for each attenuation
|
// load characteristics for each attenuation
|
||||||
for (int32_t i = 0; i < (int32_t) ADC_ATTEN_MAX; i++) {
|
for (int32_t i = 0; i <= ADC_ATTEN_DB_11; i++) {
|
||||||
auto adc_unit = channel1_ != ADC1_CHANNEL_MAX ? ADC_UNIT_1 : ADC_UNIT_2;
|
auto adc_unit = channel1_ != ADC1_CHANNEL_MAX ? ADC_UNIT_1 : ADC_UNIT_2;
|
||||||
auto cal_value = esp_adc_cal_characterize(adc_unit, (adc_atten_t) i, ADC_WIDTH_MAX_SOC_BITS,
|
auto cal_value = esp_adc_cal_characterize(adc_unit, (adc_atten_t) i, ADC_WIDTH_MAX_SOC_BITS,
|
||||||
1100, // default vref
|
1100, // default vref
|
||||||
|
@ -157,7 +157,7 @@ float ADCSensor::sample() {
|
||||||
#ifdef USE_ESP32
|
#ifdef USE_ESP32
|
||||||
float ADCSensor::sample() {
|
float ADCSensor::sample() {
|
||||||
if (!autorange_) {
|
if (!autorange_) {
|
||||||
int32_t raw = -1;
|
int raw = -1;
|
||||||
if (channel1_ != ADC1_CHANNEL_MAX) {
|
if (channel1_ != ADC1_CHANNEL_MAX) {
|
||||||
raw = adc1_get_raw(channel1_);
|
raw = adc1_get_raw(channel1_);
|
||||||
} else if (channel2_ != ADC2_CHANNEL_MAX) {
|
} else if (channel2_ != ADC2_CHANNEL_MAX) {
|
||||||
|
@ -174,7 +174,7 @@ float ADCSensor::sample() {
|
||||||
return mv / 1000.0f;
|
return mv / 1000.0f;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t raw11 = ADC_MAX, raw6 = ADC_MAX, raw2 = ADC_MAX, raw0 = ADC_MAX;
|
int raw11 = ADC_MAX, raw6 = ADC_MAX, raw2 = ADC_MAX, raw0 = ADC_MAX;
|
||||||
|
|
||||||
if (channel1_ != ADC1_CHANNEL_MAX) {
|
if (channel1_ != ADC1_CHANNEL_MAX) {
|
||||||
adc1_config_channel_atten(channel1_, ADC_ATTEN_DB_11);
|
adc1_config_channel_atten(channel1_, ADC_ATTEN_DB_11);
|
||||||
|
|
|
@ -62,7 +62,7 @@ class ADCSensor : public sensor::Sensor, public PollingComponent, public voltage
|
||||||
adc1_channel_t channel1_{ADC1_CHANNEL_MAX};
|
adc1_channel_t channel1_{ADC1_CHANNEL_MAX};
|
||||||
adc2_channel_t channel2_{ADC2_CHANNEL_MAX};
|
adc2_channel_t channel2_{ADC2_CHANNEL_MAX};
|
||||||
bool autorange_{false};
|
bool autorange_{false};
|
||||||
esp_adc_cal_characteristics_t cal_characteristics_[(int32_t) ADC_ATTEN_MAX] = {};
|
esp_adc_cal_characteristics_t cal_characteristics_[ADC_ATTEN_MAX] = {};
|
||||||
#endif
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -31,3 +31,11 @@ logger:
|
||||||
http_request:
|
http_request:
|
||||||
useragent: esphome/tagreader
|
useragent: esphome/tagreader
|
||||||
timeout: 10s
|
timeout: 10s
|
||||||
|
|
||||||
|
sensor:
|
||||||
|
- platform: adc
|
||||||
|
id: adc_sensor_p4
|
||||||
|
name: ADC pin 4
|
||||||
|
pin: 4
|
||||||
|
attenuation: 11db
|
||||||
|
update_interval: 1s
|
||||||
|
|
Loading…
Reference in a new issue