aboutsummaryrefslogtreecommitdiff
path: root/embassy-lora/src/lib.rs
blob: 5637802bb7288c6475bb8d9d2e3091a9c1f0d536 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#![no_std]
#![feature(async_fn_in_trait)]
//! embassy-lora holds LoRa-specific functionality.

pub(crate) mod fmt;

/// interface variants required by the external lora physical layer crate (lora-phy)
pub mod iv;

#[cfg(feature = "time")]
use embassy_time::{Duration, Instant, Timer};

/// A convenience timer to use with the LoRaWAN crate
#[cfg(feature = "time")]
pub struct LoraTimer {
    start: Instant,
}

#[cfg(feature = "time")]
impl LoraTimer {
    pub fn new() -> Self {
        Self { start: Instant::now() }
    }
}

#[cfg(feature = "time")]
impl lorawan_device::async_device::radio::Timer for LoraTimer {
    fn reset(&mut self) {
        self.start = Instant::now();
    }

    async fn at(&mut self, millis: u64) {
        Timer::at(self.start + Duration::from_millis(millis)).await
    }

    async fn delay_ms(&mut self, millis: u64) {
        Timer::after_millis(millis).await
    }
}