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

* Unify the system peripheral Whilst the PCR, SYSTEM and DPORT peripherals are different, we currently use them all in the same way. This PR unifies the peripheral name in the hal to `SYSTEM`. The idea is that they all do the same sort of thing, so we can collect them under the same name, and later down the line we can being to expose differences under an extended API. The benifits to this are imo quite big, the examples now are all identical, which makes things easier for esp-wifi, and paves a path towards the multichip hal. Why not do this in the PAC? Imo the pac should be as close to the hardware as possible, and the HAL is where we should abstractions such as this. * changelog
43 lines
1.2 KiB
Rust
43 lines
1.2 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,
|
|
peripherals::Peripherals,
|
|
prelude::*,
|
|
Delay,
|
|
};
|
|
use esp_backtrace as _;
|
|
use esp_println::println;
|
|
|
|
#[entry]
|
|
fn main() -> ! {
|
|
let peripherals = Peripherals::take();
|
|
let system = peripherals.SYSTEM.split();
|
|
let clocks = ClockControl::boot_defaults(system.clock_control).freeze();
|
|
|
|
let io = IO::new(peripherals.GPIO, peripherals.IO_MUX);
|
|
|
|
// Create ADC instances
|
|
let analog = peripherals.SENS.split();
|
|
|
|
let mut adc2_config = AdcConfig::new();
|
|
let mut pin25 =
|
|
adc2_config.enable_pin(io.pins.gpio25.into_analog(), 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);
|
|
}
|
|
}
|