#![no_main]
#![no_std]
use cortex_m::delay::Delay;
use cortex_m_rt::entry;
use defmt_rtt as _;
use hal::{
clocks::Clocks,
comp::{self, Comp, CompConfig, CompDevice},
gpio::{Pin, PinMode, Port},
pac,
};
use panic_probe as _;
#[entry]
fn main() -> ! {
let cp = cortex_m::Peripherals::take().unwrap();
let _dp = pac::Peripherals::take().unwrap();
let clock_cfg = Clocks::default();
clock_cfg.setup().unwrap();
let _pin = Pin::new(Port::B, 2, PinMode::Analog);
let mut delay = Delay::new(cp.SYST, clock_cfg.systick());
let cfg = CompConfig {
hyst: comp::Hysterisis::NoHysterisis,
inmsel: comp::InvertingInput::Vref,
inpsel: comp::NonInvertingInput::Io2,
polarity: comp::OutputPolarity::NotInverted,
pwrmode: comp::PowerMode::HighSpeed,
};
let mut comparator = Comp::new(CompDevice::One, cfg);
comparator.start().unwrap();
loop {
let output = comparator.get_output_level();
defmt::println!("{}", output);
delay.delay_ms(1000u32);
}
}
#[defmt::panic_handler]
fn panic() -> ! {
cortex_m::asm::udf()
}