lorawan_device/async_device/radio.rs
1pub use crate::radio::{RfConfig, RxConfig, RxMode, RxQuality, TxConfig};
2
3#[cfg_attr(feature = "defmt", derive(defmt::Format))]
4pub struct Error<E>(pub E);
5
6impl<R> From<Error<R>> for super::Error<R> {
7 fn from(radio_error: Error<R>) -> super::Error<R> {
8 super::Error::Radio(radio_error.0)
9 }
10}
11
12pub enum RxStatus {
13 Rx(usize, RxQuality),
14 RxTimeout,
15}
16
17/// An asynchronous timer that allows the state machine to await
18/// between RX windows.
19#[allow(async_fn_in_trait)]
20pub trait Timer {
21 fn reset(&mut self);
22
23 /// Wait until millis milliseconds after reset has passed
24 async fn at(&mut self, millis: u64);
25
26 /// Delay for millis milliseconds
27 async fn delay_ms(&mut self, millis: u64);
28}
29
30/// An asynchronous radio implementation that can transmit and receive data.
31#[allow(async_fn_in_trait)]
32pub trait PhyRxTx: Sized {
33 #[cfg(feature = "defmt")]
34 type PhyError: defmt::Format;
35
36 #[cfg(not(feature = "defmt"))]
37 type PhyError;
38
39 /// Board-specific antenna gain and power loss in dBi.
40 const ANTENNA_GAIN: i8 = 0;
41
42 /// Maximum power (dBm) that the radio is able to output. When preparing instructions for radio,
43 /// the value of maximum power will be used as an upper bound.
44 const MAX_RADIO_POWER: u8;
45
46 /// Transmit data buffer with the given transceiver configuration. The returned future
47 /// should only complete once data have been transmitted.
48 async fn tx(&mut self, config: TxConfig, buf: &[u8]) -> Result<u32, Self::PhyError>;
49
50 /// Configures the radio to receive data. This future should not actually await the data itself.
51 async fn setup_rx(&mut self, config: RxConfig) -> Result<(), Self::PhyError>;
52
53 /// Receive data into the provided buffer with the given transceiver configuration. The returned
54 /// future should only complete when RX data has been received. Furthermore, it should be
55 /// possible to await the future again without settings up the receive config again.
56 async fn rx_continuous(
57 &mut self,
58 rx_buf: &mut [u8],
59 ) -> Result<(usize, RxQuality), Self::PhyError>;
60
61 /// Receive data into the provided buffer with the given transceiver configuration. The returned
62 /// future should complete when RX data has been received or when the timeout has expired.
63 async fn rx_single(&mut self, buf: &mut [u8]) -> Result<RxStatus, Self::PhyError>;
64
65 /// Puts the radio into a low-power mode
66 async fn low_power(&mut self) -> Result<(), Self::PhyError> {
67 Ok(())
68 }
69}