Created
November 13, 2023 13:11
-
-
Save plaes/5e9c0135513f10e169da02ab92f7757c to your computer and use it in GitHub Desktop.
lora_iface_sx1272_nrf.rs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use embassy_nrf::gpio::{AnyPin, Flex, OutputDrive, Pull}; | |
use embedded_hal::digital::OutputPin; | |
use embassy_futures::select::{select, Either}; | |
use embedded_hal_async::{delay::DelayUs, digital::Wait}; | |
use lora_phy::mod_params::RadioError; | |
use lora_phy::mod_traits::InterfaceVariant; | |
pub struct LoRaInterfaceVariant<'d, WAIT> { | |
reset: Flex<'d, AnyPin>, | |
dio0: WAIT, | |
dio3: WAIT, | |
} | |
impl<'d, WAIT> LoRaInterfaceVariant<'d, WAIT> | |
where | |
// CTRL: OutputPin, | |
WAIT: Wait, | |
{ | |
pub fn new(reset: Flex<'d, AnyPin>, dio0: WAIT, dio3: WAIT) -> Result<Self, RadioError> { | |
Ok(Self { reset, dio0, dio3 }) | |
} | |
} | |
impl<'d, WAIT> InterfaceVariant for LoRaInterfaceVariant<'d, WAIT> | |
where | |
WAIT: Wait, | |
{ | |
async fn reset(&mut self, delay: &mut impl DelayUs) -> Result<(), RadioError> { | |
self.reset.set_high(); | |
self.reset.set_as_input(Pull::Up); | |
delay.delay_ms(1); | |
self.reset.set_high(); | |
self.reset.set_as_output(OutputDrive::HighDrive); | |
delay.delay_ms(6); | |
self.reset.set_as_input(Pull::Up); | |
delay.delay_ms(10); | |
Ok(()) | |
} | |
async fn wait_on_busy(&mut self) -> Result<(), RadioError> { | |
Ok(()) | |
} | |
async fn await_irq(&mut self) -> Result<(), RadioError> { | |
let dio = match select(self.dio0.wait_for_high(), self.dio3.wait_for_high()).await { | |
Either::First(p) => p, | |
Either::Second(p) => p, | |
}; | |
dio.map_err(|_| RadioError::Irq)?; | |
Ok(()) | |
} | |
async fn enable_rf_switch_rx(&mut self) -> Result<(), RadioError> { | |
Ok(()) | |
} | |
async fn enable_rf_switch_tx(&mut self) -> Result<(), RadioError> { | |
Ok(()) | |
} | |
async fn disable_rf_switch(&mut self) -> Result<(), RadioError> { | |
Ok(()) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment