RfSwitch

Struct RfSwitch 

Source
pub struct RfSwitch { /* private fields */ }
Expand description

RF switch

Implementations§

Source§

impl RfSwitch

Source

pub fn new(a4: A4, a5: A5, cs: &CriticalSection) -> RfSwitch

Create a new RfSwitch struct from GPIOs.

§Example
use lora_e5_bsp::{
    hal::{cortex_m, gpio::PortA, pac},
    RfSwitch,
};

let mut dp: pac::Peripherals = pac::Peripherals::take().unwrap();

let gpioa: PortA = PortA::split(dp.GPIOA, &mut dp.RCC);
let rfs: RfSwitch = cortex_m::interrupt::free(|cs| RfSwitch::new(gpioa.a4, gpioa.a5, cs));
Source

pub unsafe fn steal() -> Self

Steal the RF switch from whatever is currently using it.

§Safety
  1. Ensure that the code stealing the RF switch has exclusive access. Singleton checks are bypassed with this method.
  2. You must set up the RF switch pins. No setup will occur when using this method.
§Example
use lora_e5_bsp::{
    hal::{
        cortex_m,
        gpio::{pins, Output, PortA},
        pac,
    },
    RfSwitch,
};

let mut dp: pac::Peripherals = pac::Peripherals::take().unwrap();

let pa: PortA = PortA::split(dp.GPIOA, &mut dp.RCC);
cortex_m::interrupt::free(|cs| {
    let _: Output<pins::A4> = Output::default(pa.a4, cs);
    let _: Output<pins::A5> = Output::default(pa.a5, cs);
});

// safety:
// 1. we have exclusive access to the underlying pins
// 2. the pins have been setup
let rfs: RfSwitch = unsafe { RfSwitch::steal() };
Source

pub fn set_rx(&mut self)

Set the RF switch to receive.

§Example
use lora_e5_bsp::{
    hal::{cortex_m, gpio::PortA, pac},
    RfSwitch,
};

let mut dp: pac::Peripherals = pac::Peripherals::take().unwrap();

let gpioa: PortA = PortA::split(dp.GPIOA, &mut dp.RCC);
let mut rfs: RfSwitch = cortex_m::interrupt::free(|cs| RfSwitch::new(gpioa.a4, gpioa.a5, cs));
rfs.set_rx();
Source

pub fn set_tx_hp(&mut self)

Set the RF switch to high power transmit.

§Example
use lora_e5_bsp::{
    hal::{cortex_m, gpio::PortA, pac},
    RfSwitch,
};

let mut dp: pac::Peripherals = pac::Peripherals::take().unwrap();

let gpioa: PortA = PortA::split(dp.GPIOA, &mut dp.RCC);
let mut rfs: RfSwitch = cortex_m::interrupt::free(|cs| RfSwitch::new(gpioa.a4, gpioa.a5, cs));
rfs.set_tx_hp();

Trait Implementations§

Source§

impl Debug for RfSwitch

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.