nrf/temp: switch to new interrupt binding.
This commit is contained in:
parent
9e58d9274c
commit
36319fc121
2 changed files with 30 additions and 14 deletions
|
@ -3,6 +3,7 @@
|
|||
use core::future::poll_fn;
|
||||
use core::task::Poll;
|
||||
|
||||
use embassy_cortex_m::interrupt::Interrupt;
|
||||
use embassy_hal_common::drop::OnDrop;
|
||||
use embassy_hal_common::{into_ref, PeripheralRef};
|
||||
use embassy_sync::waitqueue::AtomicWaker;
|
||||
|
@ -12,27 +13,39 @@ use crate::interrupt::InterruptExt;
|
|||
use crate::peripherals::TEMP;
|
||||
use crate::{interrupt, pac, Peripheral};
|
||||
|
||||
/// Interrupt handler.
|
||||
pub struct InterruptHandler {
|
||||
_private: (),
|
||||
}
|
||||
|
||||
impl interrupt::Handler<interrupt::TEMP> for InterruptHandler {
|
||||
unsafe fn on_interrupt() {
|
||||
let r = unsafe { &*pac::TEMP::PTR };
|
||||
r.intenclr.write(|w| w.datardy().clear());
|
||||
WAKER.wake();
|
||||
}
|
||||
}
|
||||
|
||||
/// Builtin temperature sensor driver.
|
||||
pub struct Temp<'d> {
|
||||
_irq: PeripheralRef<'d, interrupt::TEMP>,
|
||||
_peri: PeripheralRef<'d, TEMP>,
|
||||
}
|
||||
|
||||
static WAKER: AtomicWaker = AtomicWaker::new();
|
||||
|
||||
impl<'d> Temp<'d> {
|
||||
/// Create a new temperature sensor driver.
|
||||
pub fn new(_t: impl Peripheral<P = TEMP> + 'd, irq: impl Peripheral<P = interrupt::TEMP> + 'd) -> Self {
|
||||
into_ref!(_t, irq);
|
||||
pub fn new(
|
||||
_peri: impl Peripheral<P = TEMP> + 'd,
|
||||
_irq: impl interrupt::Binding<interrupt::TEMP, InterruptHandler> + 'd,
|
||||
) -> Self {
|
||||
into_ref!(_peri);
|
||||
|
||||
// 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 }
|
||||
unsafe { interrupt::TEMP::steal() }.unpend();
|
||||
unsafe { interrupt::TEMP::steal() }.enable();
|
||||
|
||||
Self { _peri }
|
||||
}
|
||||
|
||||
/// Perform an asynchronous temperature measurement. The returned future
|
||||
|
|
|
@ -4,16 +4,19 @@
|
|||
|
||||
use defmt::info;
|
||||
use embassy_executor::Spawner;
|
||||
use embassy_nrf::interrupt;
|
||||
use embassy_nrf::temp::Temp;
|
||||
use embassy_nrf::{bind_interrupts, temp};
|
||||
use embassy_time::{Duration, Timer};
|
||||
use {defmt_rtt as _, panic_probe as _};
|
||||
|
||||
bind_interrupts!(struct Irqs {
|
||||
TEMP => temp::InterruptHandler;
|
||||
});
|
||||
|
||||
#[embassy_executor::main]
|
||||
async fn main(_spawner: Spawner) {
|
||||
let p = embassy_nrf::init(Default::default());
|
||||
let irq = interrupt::take!(TEMP);
|
||||
let mut temp = Temp::new(p.TEMP, irq);
|
||||
let mut temp = Temp::new(p.TEMP, Irqs);
|
||||
|
||||
loop {
|
||||
let value = temp.read().await;
|
||||
|
|
Loading…
Reference in a new issue