Skip to main content

Radio

Enum Radio 

Source
pub enum Radio<SPI, BUSY, RESET, D> {
    Sx126x(Sx126x<SPI, BUSY, RESET, D>),
    Sx127x(Sx127x<SPI, RESET, D>),
}
Expand description

A LoRa radio of either family: an SX126x with its BUSY line, or an SX127x.

Build one from a driver with From, or open one on a Linux board through linux with the linux feature. init resets the chip, configure tunes it, and the calls after that are the same for both families. The SX127x has no BUSY line, so its radio names a BUSY type it never uses.

Variants§

§

Sx126x(Sx126x<SPI, BUSY, RESET, D>)

An SX1261, SX1262, SX1268, or LLCC68.

§

Sx127x(Sx127x<SPI, RESET, D>)

An SX1276, SX1277, SX1278, or SX1279.

Implementations§

Source§

impl<SPI, BUSY, RESET, D> Radio<SPI, BUSY, RESET, D>

Source

pub fn family(&self) -> Family

Returns the family of the chip.

§Returns

Family::Sx126x or Family::Sx127x.

Returns the link settings the radio was last configured with.

§Returns

The settings, or None before configure and after an SX126x has slept.

Source§

impl<SPI, BUSY, RESET, D> Radio<SPI, BUSY, RESET, D>
where SPI: SpiDevice, BUSY: InputPin, RESET: OutputPin, D: DelayNs,

Source

pub fn init(&mut self) -> Result<(), RadioError<SPI::Error>>

Resets the chip and sets up what its board wires around it.

§Errors

Returns the errors of Sx126x::init or Sx127x::init: most often that no chip of the family answered, which is a wiring or a power problem.

Source

pub fn configure( &mut self, config: RadioConfig, ) -> Result<(), RadioError<SPI::Error>>

Tunes the chip to a configuration.

The output power becomes the settings of the amplifier the board names, clamped to its range, and the sync word takes the family’s own layout.

§Arguments
  • config - the configuration.
§Errors

Returns the errors of Sx126x::configure or Sx127x::configure, such as a bandwidth the chip does not have or a link an LLCC68 cannot carry.

Source

pub fn transmit( &mut self, payload: &[u8], ) -> Result<u64, RadioError<SPI::Error>>

Sends one frame and waits for it to leave.

§Arguments
  • payload - the frame’s payload, 1 to 255 bytes.
§Returns

The frame’s airtime in microseconds, for a DutyCycle to count.

§Errors

Returns the errors of Sx126x::transmit or Sx127x::transmit.

Source

pub fn start_transmit( &mut self, payload: &[u8], ) -> Result<u64, RadioError<SPI::Error>>

Starts sending one frame and returns once the chip is transmitting.

§Arguments
  • payload - the frame’s payload, 1 to 255 bytes.
§Returns

The frame’s airtime in microseconds, after which finish_transmit reports it sent.

§Errors

Returns the errors of Sx126x::start_transmit or Sx127x::start_transmit.

Source

pub fn finish_transmit(&mut self) -> Result<bool, RadioError<SPI::Error>>

Reports whether the frame start_transmit began has left.

§Returns

true once it has been sent.

§Errors

Returns the errors of Sx126x::finish_transmit or Sx127x::finish_transmit.

Source

pub fn receive( &mut self, buffer: &mut [u8], timeout_us: u64, ) -> Result<Reception, RadioError<SPI::Error>>

Listens for one frame.

§Arguments
  • buffer - where the payload goes; up to 255 bytes are accepted.
  • timeout_us - how long to listen for a frame to start, in microseconds. The SX127x counts it in symbols, from 4 to 1023.
§Returns

The frame’s length and signal levels, or that the timeout passed or the frame was corrupt.

§Errors

Returns the errors of Sx126x::receive or Sx127x::receive.

Source

pub fn listen(&mut self) -> Result<(), RadioError<SPI::Error>>

Starts listening, frame after frame, until another mode is set.

§Errors

Returns the errors of Sx126x::listen or Sx127x::listen.

Source

pub fn take_frame( &mut self, buffer: &mut [u8], ) -> Result<Option<Reception>, RadioError<SPI::Error>>

Takes the frame a listen has received, if one has arrived.

§Arguments
  • buffer - where the payload goes.
§Returns

The frame, a corrupt frame, or None when nothing has arrived.

§Errors

Returns the errors of Sx126x::take_frame or Sx127x::take_frame.

Source

pub fn standby(&mut self) -> Result<(), RadioError<SPI::Error>>

Puts the chip in standby, which stops a transmission or a reception.

§Errors

Returns the bus errors of either driver.

Source

pub fn sleep(&mut self) -> Result<(), RadioError<SPI::Error>>

Puts the chip to sleep until the next call wakes it.

An SX126x takes a warm start, keeping its settings in retention, and is configured again before its next frame. An SX127x keeps its registers and wakes for the next frame as it is.

§Errors

Returns the bus errors of either driver.

Source

pub fn read_register( &mut self, address: u16, ) -> Result<u8, RadioError<SPI::Error>>

Reads one register.

§Arguments
  • address - the register address: 16 bits on the SX126x, 0x00 to 0x7F on the SX127x.
§Returns

The register’s value.

§Errors

Returns RadioError::Address for an SX127x address past 0x7F, and the bus errors of either driver.

Source

pub fn write_register( &mut self, address: u16, value: u8, ) -> Result<(), RadioError<SPI::Error>>

Writes one register.

§Arguments
  • address - the register address: 16 bits on the SX126x, 0x00 to 0x7F on the SX127x.
  • value - the value to write.
§Errors

Returns RadioError::Address for an SX127x address past 0x7F, and the bus errors of either driver.

Trait Implementations§

Source§

impl<SPI, BUSY, RESET, D> From<Sx126x<SPI, BUSY, RESET, D>> for Radio<SPI, BUSY, RESET, D>

Source§

fn from(radio: Sx126x<SPI, BUSY, RESET, D>) -> Self

Converts to this type from the input type.
Source§

impl<SPI, BUSY, RESET, D> From<Sx127x<SPI, RESET, D>> for Radio<SPI, BUSY, RESET, D>

Source§

fn from(radio: Sx127x<SPI, RESET, D>) -> Self

Converts to this type from the input type.
Source§

impl<SPI, BUSY, RESET, D> LoraRadio for Radio<SPI, BUSY, RESET, D>
where SPI: SpiDevice, BUSY: InputPin, RESET: OutputPin, D: DelayNs,

Source§

type Error = RadioError<<SPI as ErrorType>::Error>

What the radio reports when it or the bus under it fails.
Returns the link settings frames go out with, which the duty cycle’s arithmetic needs. Read more
Source§

fn start_transmit(&mut self, frame: &[u8]) -> Result<u64, Self::Error>

Starts sending one frame, without waiting for it to leave. Read more
Source§

fn finish_transmit(&mut self) -> Result<bool, Self::Error>

Reports whether the frame start_transmit began has left. Read more
Source§

fn listen(&mut self) -> Result<(), Self::Error>

Starts listening, and keeps listening frame after frame. Read more
Source§

fn take_frame( &mut self, buffer: &mut [u8], ) -> Result<Option<usize>, Self::Error>

Takes a frame the radio has received since the last call, dropping one whose CRC failed. Read more

Auto Trait Implementations§

§

impl<SPI, BUSY, RESET, D> Freeze for Radio<SPI, BUSY, RESET, D>
where SPI: Freeze, BUSY: Freeze, RESET: Freeze, D: Freeze,

§

impl<SPI, BUSY, RESET, D> RefUnwindSafe for Radio<SPI, BUSY, RESET, D>

§

impl<SPI, BUSY, RESET, D> Send for Radio<SPI, BUSY, RESET, D>
where SPI: Send, BUSY: Send, RESET: Send, D: Send,

§

impl<SPI, BUSY, RESET, D> Sync for Radio<SPI, BUSY, RESET, D>
where SPI: Sync, BUSY: Sync, RESET: Sync, D: Sync,

§

impl<SPI, BUSY, RESET, D> Unpin for Radio<SPI, BUSY, RESET, D>
where SPI: Unpin, BUSY: Unpin, RESET: Unpin, D: Unpin,

§

impl<SPI, BUSY, RESET, D> UnsafeUnpin for Radio<SPI, BUSY, RESET, D>
where SPI: UnsafeUnpin, BUSY: UnsafeUnpin, RESET: UnsafeUnpin, D: UnsafeUnpin,

§

impl<SPI, BUSY, RESET, D> UnwindSafe for Radio<SPI, BUSY, RESET, D>
where SPI: UnwindSafe, BUSY: UnwindSafe, RESET: UnwindSafe, D: UnwindSafe,

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.