From f8c279edb007d751d96a6267f088a1ae6ac473c8 Mon Sep 17 00:00:00 2001 From: MichaelDvP Date: Thu, 14 Nov 2024 17:15:17 +0100 Subject: [PATCH] fix input pullup and counter on gpio 25/26, #2201 --- src/analogsensor.cpp | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/src/analogsensor.cpp b/src/analogsensor.cpp index 1a0e6f39c..daa1562ca 100644 --- a/src/analogsensor.cpp +++ b/src/analogsensor.cpp @@ -138,14 +138,10 @@ void AnalogSensor::reload(bool get_nvs) { continue; // skip this loop pass } - if (sensor.type() == AnalogType::ADC) { - LOG_DEBUG("ADC Sensor on GPIO %02d", sensor.gpio()); - // analogSetPinAttenuation does not work with analogReadMilliVolts - sensor.analog_ = 0; // initialize - sensor.last_reading_ = 0; - } else if (sensor.type() == AnalogType::COUNTER) { - LOG_DEBUG("I/O Counter on GPIO %02d", sensor.gpio()); - pinMode(sensor.gpio(), INPUT_PULLUP); + if ((sensor.gpio() == 25 || sensor.gpio() == 26) + && (sensor.type() == AnalogType::COUNTER || sensor.type() == AnalogType::DIGITAL_IN || sensor.type() == AnalogType::RATE + || sensor.type() == AnalogType::TIMER)) { + // pullup is mapped to DAC, so set to 3.3V #if CONFIG_IDF_TARGET_ESP32 if (sensor.gpio() == 25 || sensor.gpio() == 26) { dacWrite(sensor.gpio(), 255); @@ -155,6 +151,15 @@ void AnalogSensor::reload(bool get_nvs) { dacWrite(sensor.gpio(), 255); } #endif + } + if (sensor.type() == AnalogType::ADC) { + LOG_DEBUG("ADC Sensor on GPIO %02d", sensor.gpio()); + // analogSetPinAttenuation does not work with analogReadMilliVolts + sensor.analog_ = 0; // initialize + sensor.last_reading_ = 0; + } else if (sensor.type() == AnalogType::COUNTER) { + LOG_DEBUG("I/O Counter on GPIO %02d", sensor.gpio()); + pinMode(sensor.gpio(), INPUT_PULLUP); sensor.polltime_ = 0; sensor.poll_ = digitalRead(sensor.gpio()); if (double_t val = EMSESP::nvs_.getDouble(sensor.name().c_str(), 0)) {