use esp_idf_sys::{self as _};
use std::thread;
use std::time::Duration;
#[cfg(any(feature = "adc-oneshot-legacy", esp_idf_version_major = "4"))]
fn main() -> anyhow::Result<()> {
use esp_idf_hal::adc::config::Config;
use esp_idf_hal::adc::*;
use esp_idf_hal::peripherals::Peripherals;
let peripherals = Peripherals::take()?;
#[cfg(not(esp32))]
let mut adc = AdcDriver::new(peripherals.adc1, &Config::new().calibration(true))?;
#[cfg(esp32)]
let mut adc = AdcDriver::new(peripherals.adc2, &Config::new().calibration(true))?;
#[cfg(not(esp32))]
let mut adc_pin: esp_idf_hal::adc::AdcChannelDriver<{ attenuation::DB_11 }, _> =
AdcChannelDriver::new(peripherals.pins.gpio4)?;
#[cfg(esp32)]
let mut adc_pin: esp_idf_hal::adc::AdcChannelDriver<{ attenuation::DB_11 }, _> =
AdcChannelDriver::new(peripherals.pins.gpio12)?;
loop {
thread::sleep(Duration::from_millis(10));
println!("ADC value: {}", adc.read(&mut adc_pin)?);
}
}
#[cfg(not(any(feature = "adc-oneshot-legacy", esp_idf_version_major = "4")))]
fn main() -> anyhow::Result<()> {
println!("This example requires feature `adc-oneshot-legacy` enabled or using ESP-IDF v4.4.X");
loop {
thread::sleep(Duration::from_millis(1000));
}
}