//! Temperature sensor interface. use core::future::poll_fn; use core::task::Poll; use embassy_hal_common::drop::OnDrop; use embassy_hal_common::{into_ref, PeripheralRef}; use embassy_sync::waitqueue::AtomicWaker; use fixed::types::I30F2; use crate::interrupt::InterruptExt; use crate::peripherals::TEMP; use crate::{interrupt, pac, Peripheral}; /// Integrated temperature sensor. pub struct Temp<'d> { _irq: PeripheralRef<'d, interrupt::TEMP>, } static WAKER: AtomicWaker = AtomicWaker::new(); impl<'d> Temp<'d> { pub fn new(_t: impl Peripheral
+ 'd, irq: impl Peripheral
+ 'd) -> Self {
into_ref!(_t, irq);
// Enable interrupt that signals temperature values
irq.disable();
irq.set_handler(|_| {
let t = Self::regs();
t.intenclr.write(|w| w.datardy().clear());
WAKER.wake();
});
irq.enable();
Self { _irq: irq }
}
/// Perform an asynchronous temperature measurement. The returned future
/// can be awaited to obtain the measurement.
///
/// If the future is dropped, the measurement is cancelled.
///
/// # Example
///
/// ```no_run
/// let mut t = Temp::new(p.TEMP, interrupt::take!(TEMP));
/// let v: u16 = t.read().await.to_num::