mirror of
https://github.com/esp-rs/esp-hal.git
synced 2025-10-01 14:20:44 +00:00

* PeripheralClockControl timer * Add PeripheralClockControl to timg, wdt, sha, usb-serial-jtag and uart * ESP32 updated examples * ESP32C2 updated examples * ESP32C3 updated examples * ESP32S2 updated examples * ESP32S3 updated examples * ESP32C6 updated examples * cargo fmt
60 lines
1.6 KiB
Rust
60 lines
1.6 KiB
Rust
//! Connect a potentiometer to PIN3 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 esp32s2_hal::{
|
|
adc::{AdcConfig, Attenuation, ADC, ADC1},
|
|
clock::ClockControl,
|
|
gpio::IO,
|
|
peripherals::Peripherals,
|
|
prelude::*,
|
|
timer::TimerGroup,
|
|
Delay,
|
|
Rtc,
|
|
};
|
|
use esp_backtrace as _;
|
|
use esp_println::println;
|
|
|
|
#[entry]
|
|
fn main() -> ! {
|
|
let peripherals = Peripherals::take();
|
|
let mut system = peripherals.SYSTEM.split();
|
|
let clocks = ClockControl::boot_defaults(system.clock_control).freeze();
|
|
|
|
let timer_group0 = TimerGroup::new(
|
|
peripherals.TIMG0,
|
|
&clocks,
|
|
&mut system.peripheral_clock_control,
|
|
);
|
|
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 pin3 = io.pins.gpio3.into_analog();
|
|
|
|
// Create ADC instances
|
|
let analog = peripherals.SENS.split();
|
|
|
|
let mut adc1_config = AdcConfig::new();
|
|
|
|
let mut pin3 =
|
|
adc1_config.enable_pin(io.pins.gpio3.into_analog(), Attenuation::Attenuation11dB);
|
|
|
|
let mut adc1 = ADC::<ADC1>::adc(analog.adc1, adc1_config).unwrap();
|
|
|
|
let mut delay = Delay::new(&clocks);
|
|
|
|
loop {
|
|
let pin3_value: u16 = nb::block!(adc1.read(&mut pin3)).unwrap();
|
|
println!("PIN3 ADC reading = {}", pin3_value);
|
|
delay.delay_ms(1500u32);
|
|
}
|
|
}
|