Gustavo Henrique Nihei 91ea205446
ESP32-C3: Add driver for RTC Watchdog Timer (RWDT) (#134)
* esp32: Fix typo in Frequency word in some identifiers

Signed-off-by: Gustavo Henrique Nihei <gustavo.nihei@espressif.com>

* esp32c3: Add support for PLL clock configuration

Signed-off-by: Gustavo Henrique Nihei <gustavo.nihei@espressif.com>

* clock: Move definition of Clock types to common level

Signed-off-by: Gustavo Henrique Nihei <gustavo.nihei@espressif.com>

* esp32c3: Add support for RTC Clock configuration

Signed-off-by: Gustavo Henrique Nihei <gustavo.nihei@espressif.com>

* esp32c3: Add example for the RTC Watchdog Timer driver

Signed-off-by: Gustavo Henrique Nihei <gustavo.nihei@espressif.com>
2022-08-08 15:36:19 +01:00

54 lines
1.5 KiB
Rust

//! Connect a potentiometer to PIN25 and see the read values change when
//! rotating the shaft. Alternatively you could also connect the PIN to GND or
//! 3V3 to see the maximum and minimum raw values read.
#![no_std]
#![no_main]
use esp32_hal::{
adc::{AdcConfig, Attenuation, ADC, ADC2},
clock::ClockControl,
gpio::IO,
pac::Peripherals,
prelude::*,
timer::TimerGroup,
Delay,
Rtc,
};
use esp_println::println;
use panic_halt as _;
use xtensa_lx_rt::entry;
#[entry]
fn main() -> ! {
let peripherals = Peripherals::take().unwrap();
let system = peripherals.DPORT.split();
let clocks = ClockControl::boot_defaults(system.clock_control).freeze();
let timer_group0 = TimerGroup::new(peripherals.TIMG0, &clocks);
let mut wdt = timer_group0.wdt;
let mut rtc = Rtc::new(peripherals.RTC_CNTL);
// Disable MWDT and RWDT (Watchdog) flash boot protection
wdt.disable();
rtc.rwdt.disable();
let io = IO::new(peripherals.GPIO, peripherals.IO_MUX);
let mut pin25 = io.pins.gpio25.into_analog();
// Create ADC instances
let analog = peripherals.SENS.split();
let mut adc2_config = AdcConfig::new();
adc2_config.enable_pin(&pin25, Attenuation::Attenuation11dB);
let mut adc2 = ADC::<ADC2>::adc(analog.adc2, adc2_config).unwrap();
let mut delay = Delay::new(&clocks);
loop {
let pin25_value: u16 = nb::block!(adc2.read(&mut pin25)).unwrap();
println!("PIN25 ADC reading = {}", pin25_value);
delay.delay_ms(1500u32);
}
}