Skip to content

Instantly share code, notes, and snippets.

@plaes
Created November 13, 2023 13:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save plaes/5e9c0135513f10e169da02ab92f7757c to your computer and use it in GitHub Desktop.
Save plaes/5e9c0135513f10e169da02ab92f7757c to your computer and use it in GitHub Desktop.
lora_iface_sx1272_nrf.rs
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