diff --git a/examples/src/bin/sdm.rs b/examples/src/bin/sdm.rs new file mode 100644 index 00000000000..8f541f16d0b --- /dev/null +++ b/examples/src/bin/sdm.rs @@ -0,0 +1,55 @@ +//! Connect an oscilloscope to an IO pin and see the modulation sine wave. +//! +//! Also you may connect low-pass filter to SDM output. +//! +//! The following wiring is assumed for ESP32: +//! - SDM pin => GPIO32 +//! The following wiring is assumed for ESP32S2/S3: +//! - SDM pin => GPIO3 +//! The following wiring is assumed for others: +//! - SDM pin => GPIO2 + +//% CHIPS: esp32 esp32c2 esp32c3 esp32c6 esp32h2 esp32s2 esp32s3 + +#![no_std] +#![no_main] + +use esp_backtrace as _; +use esp_hal::{ + sdm::Sdm, + delay::Delay, + gpio::Io, + prelude::*, +}; +use esp_println::println; + +#[entry] +fn main() -> ! { + let peripherals = esp_hal::init(esp_hal::Config::default()); + + let io = Io::new(peripherals.GPIO, peripherals.IO_MUX); + cfg_if::cfg_if! { + if #[cfg(feature = "esp32")] { + let modulation_pin = io.pins.gpio32; + } else if #[cfg(any(feature = "esp32s2", feature = "esp32s3"))] { + let modulation_pin = io.pins.gpio3; + } else { + let modulation_pin = io.pins.gpio2; + } + } + + // Create SDM instances + //let mut sdm_config = SdmConfig::default(); + //let mut sdm_pin = sdm_config.enable_pin(modulation_pin, 1.MHz()); + //let mut sdm = Sdm::new(peripherals.GPIO_SD, sdm_config); + + let mut sdm = Sdm::new(peripherals.GPIO_SD); + let mut sdm_ch = sdm.enable_pin(modulation_pin, 100.kHz()).unwrap(); + + let delay = Delay::new(); + + loop { + sdm_ch.set_pulse_density(0); + delay.delay_millis(1500); + } +}