STM32 DAC: Rework DAC driver, support all families.
This commit is contained in:
committed by
Dario Nieuwenhuis
parent
267cbaebe6
commit
09d7950313
@ -10,7 +10,7 @@ use common::*;
|
||||
use defmt::assert;
|
||||
use embassy_executor::Spawner;
|
||||
use embassy_stm32::adc::Adc;
|
||||
use embassy_stm32::dac::{DacCh1, DacChannel, Value};
|
||||
use embassy_stm32::dac::{DacCh1, Value};
|
||||
use embassy_stm32::dma::NoDma;
|
||||
use embassy_time::{Delay, Timer};
|
||||
use {defmt_rtt as _, panic_probe as _};
|
||||
@ -26,9 +26,7 @@ async fn main(_spawner: Spawner) {
|
||||
#[cfg(any(feature = "stm32h755zi", feature = "stm32g071rb"))]
|
||||
let dac_peripheral = p.DAC1;
|
||||
|
||||
let mut dac: DacCh1<'_, _, NoDma> = DacCh1::new(dac_peripheral, NoDma, p.PA4);
|
||||
unwrap!(dac.set_trigger_enable(false));
|
||||
|
||||
let mut dac = DacCh1::new(dac_peripheral, NoDma, p.PA4);
|
||||
let mut adc = Adc::new(p.ADC1, &mut Delay);
|
||||
|
||||
#[cfg(feature = "stm32h755zi")]
|
||||
@ -36,7 +34,7 @@ async fn main(_spawner: Spawner) {
|
||||
#[cfg(any(feature = "stm32f429zi", feature = "stm32g071rb"))]
|
||||
let normalization_factor: i32 = 16;
|
||||
|
||||
unwrap!(dac.set(Value::Bit8(0)));
|
||||
dac.set(Value::Bit8(0));
|
||||
// Now wait a little to obtain a stable value
|
||||
Timer::after_millis(30).await;
|
||||
let offset = adc.read(&mut unsafe { embassy_stm32::Peripherals::steal() }.PA4);
|
||||
@ -44,7 +42,7 @@ async fn main(_spawner: Spawner) {
|
||||
for v in 0..=255 {
|
||||
// First set the DAC output value
|
||||
let dac_output_val = to_sine_wave(v);
|
||||
unwrap!(dac.set(Value::Bit8(dac_output_val)));
|
||||
dac.set(Value::Bit8(dac_output_val));
|
||||
|
||||
// Now wait a little to obtain a stable value
|
||||
Timer::after_millis(30).await;
|
||||
|
Reference in New Issue
Block a user