[adc] Move require_adc_oneshot_iram to config validation

The esp32 to_code runs at PLATFORM priority (1000) before component
to_code at COMPONENT priority (0), so the flag was set too late.
Move to config validation to ensure it is set before esp32 processes
sdkconfig options.
This commit is contained in:
J. Nick Koston
2026-04-13 12:25:38 -10:00
parent d1d96d488d
commit 8c0436cc7e
+8 -1
View File
@@ -69,6 +69,13 @@ def validate_config(config):
return config
def _require_adc_iram(config):
"""Register ADC oneshot IRAM requirement during config validation."""
if CORE.is_esp32:
require_adc_oneshot_iram()
return config
ADCSensor = adc_ns.class_(
"ADCSensor", sensor.Sensor, cg.PollingComponent, voltage_sampler.VoltageSampler
)
@@ -99,6 +106,7 @@ CONFIG_SCHEMA = cv.All(
)
.extend(cv.polling_component_schema("60s")),
validate_config,
_require_adc_iram,
)
CONF_ADC_CHANNEL_ID = "adc_channel_id"
@@ -124,7 +132,6 @@ async def to_code(config):
if CORE.is_esp32:
# Re-enable ESP-IDF's ADC driver (excluded by default to save compile time)
include_builtin_idf_component("esp_adc")
require_adc_oneshot_iram()
if attenuation := config.get(CONF_ATTENUATION):
if attenuation == "auto":