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>where
SPI: SpiDevice,
BUSY: InputPin,
RESET: OutputPin,
D: DelayNs,
impl<SPI, BUSY, RESET, D> Radio<SPI, BUSY, RESET, D>where
SPI: SpiDevice,
BUSY: InputPin,
RESET: OutputPin,
D: DelayNs,
Sourcepub fn init(&mut self) -> Result<(), RadioError<SPI::Error>>
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.
Sourcepub fn configure(
&mut self,
config: RadioConfig,
) -> Result<(), RadioError<SPI::Error>>
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.
Sourcepub fn transmit(
&mut self,
payload: &[u8],
) -> Result<u64, RadioError<SPI::Error>>
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.
Sourcepub fn start_transmit(
&mut self,
payload: &[u8],
) -> Result<u64, RadioError<SPI::Error>>
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.
Sourcepub fn finish_transmit(&mut self) -> Result<bool, RadioError<SPI::Error>>
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.
Sourcepub fn receive(
&mut self,
buffer: &mut [u8],
timeout_us: u64,
) -> Result<Reception, RadioError<SPI::Error>>
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.
Sourcepub fn listen(&mut self) -> Result<(), RadioError<SPI::Error>>
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.
Sourcepub fn take_frame(
&mut self,
buffer: &mut [u8],
) -> Result<Option<Reception>, RadioError<SPI::Error>>
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.
Sourcepub fn standby(&mut self) -> Result<(), RadioError<SPI::Error>>
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.
Sourcepub fn sleep(&mut self) -> Result<(), RadioError<SPI::Error>>
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.
Sourcepub fn read_register(
&mut self,
address: u16,
) -> Result<u8, RadioError<SPI::Error>>
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.
Sourcepub fn write_register(
&mut self,
address: u16,
value: u8,
) -> Result<(), RadioError<SPI::Error>>
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> LoraRadio for Radio<SPI, BUSY, RESET, D>where
SPI: SpiDevice,
BUSY: InputPin,
RESET: OutputPin,
D: DelayNs,
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>
type Error = RadioError<<SPI as ErrorType>::Error>
Source§fn link(&self) -> Option<LinkSettings>
fn link(&self) -> Option<LinkSettings>
Source§fn start_transmit(&mut self, frame: &[u8]) -> Result<u64, Self::Error>
fn start_transmit(&mut self, frame: &[u8]) -> Result<u64, Self::Error>
Source§fn finish_transmit(&mut self) -> Result<bool, Self::Error>
fn finish_transmit(&mut self) -> Result<bool, Self::Error>
start_transmit began has
left. Read more