Skip to main content

Sx1261

Struct Sx1261 

Source
pub struct Sx1261<SPI, RESET, D> { /* private fields */ }
Expand description

The SX1261 beside a concentrator, on its own SPI device with its reset line.

Implementations§

Source§

impl<SPI, RESET, D> Sx1261<SPI, RESET, D>

Source

pub const fn new(spi: SPI, reset: RESET, delay: D) -> Sx1261<SPI, RESET, D>

Takes the radio’s bus, reset line and delay.

§Arguments
  • spi - the radio’s own SPI device, /dev/spidev0.1 on Semtech’s reference card.
  • reset - its reset line, which is held low to reset, the opposite of the concentrator’s.
  • delay - a blocking delay.
§Returns

The driver. Nothing is sent until a method is called.

Source

pub fn release(self) -> (SPI, RESET, D)

Gives the bus, the line and the delay back.

§Returns

What new was given.

Source§

impl<SPI, RESET, D> Sx1261<SPI, RESET, D>
where SPI: SpiDevice, RESET: OutputPin, D: DelayNs,

Source

pub fn bring_up( &mut self, patch: &[u32; 386], hertz: u32, ) -> Result<(), ListenerError<SPI::Error>>

Brings the radio up for carrier checks and spectral scans.

§Arguments
  • patch - the words of Semtech’s sx1261_pram.var, read with read_patch.
  • hertz - a carrier in the band the gateway works in, which the image is calibrated for; the reference uses the first front end’s.
§Returns

Ok(()) with the radio patched, calibrated and parked.

§Errors

Returns what reset, load_patch, calibrate or set_up returns.

Source

pub fn reset(&mut self) -> Result<(), ListenerError<SPI::Error>>

Resets the radio: its line low, then high, each held a tenth of a second.

§Errors

Returns ListenerError::Pin if the line cannot be driven.

Source

pub fn command( &mut self, frame: &Frame, ) -> Result<(), ListenerError<SPI::Error>>

Sends one command.

§Arguments
  • frame - the command and its payload.
§Errors

Returns ListenerError::Spi if the transfer fails.

Source

pub fn send( &mut self, opcode: u8, payload: &[u8], ) -> Result<(), ListenerError<SPI::Error>>

Sends an opcode and its payload as one transfer.

§Arguments
  • opcode - the command.
  • payload - what follows it.
§Errors

Returns ListenerError::Spi if the transfer fails.

Source

pub fn query( &mut self, opcode: u8, exchange: &mut [u8], ) -> Result<(), ListenerError<SPI::Error>>

Sends an opcode with a payload and reads back what the radio answers over it.

§Arguments
  • opcode - the command.
  • exchange - the payload going out, replaced by the bytes that came back over it.
§Errors

Returns ListenerError::Spi if the transfer fails.

Source

pub fn status(&mut self) -> Result<Status, ListenerError<SPI::Error>>

Asks the radio what it is doing.

§Returns

The status it answered with.

§Errors

Returns ListenerError::Spi if the transfer fails.

Source

pub fn read_memory( &mut self, address: u16, exchange: &mut [u8], ) -> Result<(), ListenerError<SPI::Error>>

Reads bytes from the radio’s memory.

§Arguments
  • address - where to start.
  • exchange - the address, a byte the radio answers over, then room for the data. The first three bytes are filled in here, and the data lands after them.
§Errors

Returns ListenerError::Spi if the transfer fails.

Source

pub fn load_patch( &mut self, patch: &[u32; 386], ) -> Result<(), ListenerError<SPI::Error>>

Loads the patch that adds the carrier check and the spectral scan, and proves it took.

Semtech’s sx1261_load_pram: park the radio and confirm it is parked, open the patch area, write each word, close it, commit, and read back a version string that ends in PRAM_VERSION.

§Arguments
  • patch - the patch’s words.
§Errors

Returns ListenerError::NotParked if the radio does not answer as a parked radio, ListenerError::Unpatched if the version it reports afterward is not the patch’s, and ListenerError::Spi if a transfer fails.

Source

pub fn calibrate(&mut self, hertz: u32) -> Result<(), ListenerError<SPI::Error>>

Calibrates the radio’s image rejection for the band a carrier falls in.

§Arguments
  • hertz - a carrier in the band.
§Errors

Returns ListenerError::UnsupportedBand for a carrier outside every band, ListenerError::Calibration if the radio reports the calibration failed, and ListenerError::Spi if a transfer fails.

Source

pub fn set_up(&mut self) -> Result<(), ListenerError<SPI::Error>>

Sets the receiver up for carrier checks: parked, its buffers placed, and its sensitivity trimmed.

§Errors

Returns ListenerError::NotParked if the radio does not settle parked, and ListenerError::Spi if a transfer fails.

Source

pub fn listen( &mut self, hertz: u32, bandwidth: Bandwidth, ) -> Result<(), ListenerError<SPI::Error>>

Points the receiver at a channel and leaves it listening.

§Arguments
  • hertz - the channel’s carrier.
  • bandwidth - the channel’s width.
§Errors

Returns ListenerError::Spi if a transfer fails.

Source

pub fn check( &mut self, scan_time: ScanTime, threshold_dbm: i8, ) -> Result<(), ListenerError<SPI::Error>>

Starts a carrier check on the channel the receiver listens on, and waits out its scan.

The radio then holds its answer on the pin the concentrator reads when the packet is due to leave, so the transmission that needs the check is armed after this returns.

§Arguments
  • scan_time - how long to listen.
  • threshold_dbm - the level above which the channel counts as busy, with the board’s RSSI offset already added.
§Errors

Returns ListenerError::Spi if the transfer fails.

Source

pub fn stop(&mut self) -> Result<(), ListenerError<SPI::Error>>

Ends a carrier check and parks the receiver on frequency.

§Errors

Returns ListenerError::Spi if a transfer fails.

Source

pub fn start_scan( &mut self, hertz: u32, scans: u16, ) -> Result<(), ListenerError<SPI::Error>>

Starts a spectral scan of a 125 kHz channel.

§Arguments
  • hertz - the channel’s carrier.
  • scans - how many times to sample it.
§Errors

Returns ListenerError::Spi if a transfer fails.

Source

pub fn scan_status(&mut self) -> Result<ScanStatus, ListenerError<SPI::Error>>

How far along a spectral scan is.

§Returns

The scan’s state.

§Errors

Returns ListenerError::ScanStatus for a value that is no state, and ListenerError::Spi if the transfer fails.

Source

pub fn scan_counts( &mut self, rssi_offset: i8, ) -> Result<[Level; 33], ListenerError<SPI::Error>>

Reads what a finished spectral scan counted.

§Arguments
  • rssi_offset - the board’s correction, in dB.
§Returns

The count at each level, strongest first.

§Errors

Returns ListenerError::Spi if the transfer fails.

Source

pub fn abort_scan(&mut self) -> Result<(), ListenerError<SPI::Error>>

Abandons a spectral scan, which frees the radio for a carrier check.

§Errors

Returns ListenerError::Spi if the transfer fails.

Auto Trait Implementations§

§

impl<SPI, RESET, D> Freeze for Sx1261<SPI, RESET, D>
where SPI: Freeze, RESET: Freeze, D: Freeze,

§

impl<SPI, RESET, D> RefUnwindSafe for Sx1261<SPI, RESET, D>
where SPI: RefUnwindSafe, RESET: RefUnwindSafe, D: RefUnwindSafe,

§

impl<SPI, RESET, D> Send for Sx1261<SPI, RESET, D>
where SPI: Send, RESET: Send, D: Send,

§

impl<SPI, RESET, D> Sync for Sx1261<SPI, RESET, D>
where SPI: Sync, RESET: Sync, D: Sync,

§

impl<SPI, RESET, D> Unpin for Sx1261<SPI, RESET, D>
where SPI: Unpin, RESET: Unpin, D: Unpin,

§

impl<SPI, RESET, D> UnsafeUnpin for Sx1261<SPI, RESET, D>
where SPI: UnsafeUnpin, RESET: UnsafeUnpin, D: UnsafeUnpin,

§

impl<SPI, RESET, D> UnwindSafe for Sx1261<SPI, RESET, D>
where SPI: 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.