mirror of
https://github.com/esp-rs/esp-hal.git
synced 2025-10-04 07:34:48 +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
40 lines
1.2 KiB
Rust
40 lines
1.2 KiB
Rust
//! This example shows how to use the DAC on PIN 25 and 26
|
|
//! You can connect an LED (with a suitable resistor) or check the changing
|
|
//! voltage using a voltmeter on those pins.
|
|
|
|
#![no_std]
|
|
#![no_main]
|
|
|
|
use esp32_hal::{clock::ClockControl, dac, gpio::IO, peripherals::Peripherals, prelude::*, Delay};
|
|
use esp_backtrace as _;
|
|
|
|
#[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);
|
|
let pin25 = io.pins.gpio25.into_analog();
|
|
let pin26 = io.pins.gpio26.into_analog();
|
|
|
|
// Create DAC instances
|
|
let analog = peripherals.SENS.split();
|
|
let mut dac1 = dac::DAC1::dac(analog.dac1, pin25).unwrap();
|
|
let mut dac2 = dac::DAC2::dac(analog.dac2, pin26).unwrap();
|
|
|
|
let mut delay = Delay::new(&clocks);
|
|
|
|
let mut voltage_dac1: u8 = 200;
|
|
let mut voltage_dac2: u8 = 255;
|
|
loop {
|
|
// Change voltage on the pins using write function
|
|
voltage_dac1 = voltage_dac1.wrapping_add(1);
|
|
dac1.write(voltage_dac1);
|
|
|
|
voltage_dac2 = voltage_dac2.wrapping_sub(1);
|
|
dac2.write(voltage_dac2);
|
|
delay.delay_ms(50u32);
|
|
}
|
|
}
|