1#![macro_use]
7
8#[cfg(any(
10 feature = "nrf52811",
11 feature = "nrf52820",
12 feature = "nrf52833",
13 feature = "nrf52840",
14 feature = "_nrf5340-net"
15))]
16pub mod ieee802154;
18
19use core::marker::PhantomData;
20
21use embassy_hal_internal::PeripheralType;
22use embassy_sync::waitqueue::AtomicWaker;
23pub use pac::radio::vals::Txpower as TxPower;
24
25use crate::{interrupt, pac};
26
27#[derive(Debug, Clone, Copy, PartialEq, Eq)]
29#[cfg_attr(feature = "defmt", derive(defmt::Format))]
30#[non_exhaustive]
31pub enum Error {
32 BufferTooLong,
34 BufferTooShort,
36 BufferNotInRAM,
38 ChannelInUse,
40 CrcFailed(u16),
42}
43
44pub struct InterruptHandler<T: Instance> {
46 _phantom: PhantomData<T>,
47}
48
49impl<T: Instance> interrupt::typelevel::Handler<T::Interrupt> for InterruptHandler<T> {
50 unsafe fn on_interrupt() {
51 let r = T::regs();
52 let s = T::state();
53 r.intenclr().write(|w| w.0 = 0xffff_ffff);
55 s.event_waker.wake();
56 }
57}
58
59pub(crate) struct State {
60 event_waker: AtomicWaker,
62}
63impl State {
64 pub(crate) const fn new() -> Self {
65 Self {
66 event_waker: AtomicWaker::new(),
67 }
68 }
69}
70
71pub(crate) trait SealedInstance {
72 fn regs() -> crate::pac::radio::Radio;
73 fn state() -> &'static State;
74}
75
76macro_rules! impl_radio {
77 ($type:ident, $pac_type:ident, $irq:ident) => {
78 impl crate::radio::SealedInstance for peripherals::$type {
79 fn regs() -> crate::pac::radio::Radio {
80 pac::$pac_type
81 }
82
83 #[allow(unused)]
84 fn state() -> &'static crate::radio::State {
85 static STATE: crate::radio::State = crate::radio::State::new();
86 &STATE
87 }
88 }
89 impl crate::radio::Instance for peripherals::$type {
90 type Interrupt = crate::interrupt::typelevel::$irq;
91 }
92 };
93}
94
95#[allow(private_bounds)]
97pub trait Instance: SealedInstance + PeripheralType + 'static + Send {
98 type Interrupt: interrupt::typelevel::Interrupt;
100}