Struct RF24

Source
pub struct RF24<SPI, DO, DELAY> {
    pub tx_delay: u32,
    pub ce_pin: DO,
    /* private fields */
}
Expand description

This struct implements the Esb* traits for the nRF24L01 transceiver.

Additionally, there are some functions implemented that are specific to the nRF24L01.

Fields§

§tx_delay: u32

The delay (in microseconds) in which RF24::as_rx() will wait for ACK packets to complete.

If the auto-ack feature is disabled, then this can be set as low as 0. If the auto-ack feature is enabled, then set to 100 microseconds minimum on generally faster devices (like RPi).

Since this value can be optimized per the radio’s data rate, this value is automatically adjusted when calling EsbDataRate::set_data_rate(). If setting this to a custom value be sure, to set it after changing the radio’s data rate.

If set to 0, ensure 130 microsecond delay after calling RF24::as_rx() and before transmitting.

§ce_pin: DO

The CE pin for the radio.

This really only exposed for advanced manipulation of active TX mode. It is strongly recommended to enter RX or TX mode using RF24::as_rx() and RF24::as_tx() because those methods guarantee proper radio usage.

Implementations§

Source§

impl<SPI, DO, DELAY> RF24<SPI, DO, DELAY>
where SPI: SpiDevice, DO: OutputPin, DELAY: DelayNs,

Source

pub fn new(ce_pin: DO, spi: SPI, delay_impl: DELAY) -> RF24<SPI, DO, DELAY>

Instantiate an RF24 object for use on the specified spi bus with the given ce_pin.

The radio’s CSN pin (aka Chip Select pin) shall be defined when instantiating the SpiDevice object (passed to the spi parameter).

Source

pub fn is_plus_variant(&self) -> bool

Is this radio a nRF24L01+ variant?

The bool that this function returns is only valid after calling init().

Source

pub fn rpd(&mut self) -> Result<bool, Nrf24Error<SPI::Error, DO::Error>>

Source

pub fn start_carrier_wave( &mut self, level: PaLevel, channel: u8, ) -> Result<(), Nrf24Error<SPI::Error, DO::Error>>

Source

pub fn stop_carrier_wave( &mut self, ) -> Result<(), Nrf24Error<SPI::Error, DO::Error>>

Source

pub fn set_lna( &mut self, enable: bool, ) -> Result<(), Nrf24Error<SPI::Error, DO::Error>>

Control the builtin LNA feature on nRF24L01 (older non-plus variants) and Si24R1 (cheap chinese clones of the nRF24L01).

This is enabled by default (regardless of chip variant). See PaLevel for effective behavior.

This function has no effect on nRF24L01+ modules and PA/LNA variants because the LNA feature is always enabled.

Trait Implementations§

Source§

impl<SPI, DO, DELAY> EsbAutoAck for RF24<SPI, DO, DELAY>
where SPI: SpiDevice, DO: OutputPin, DELAY: DelayNs,

Source§

type AutoAckErrorType = Nrf24Error<<SPI as ErrorType>::Error, <DO as ErrorType>::Error>

Source§

fn set_ack_payloads( &mut self, enable: bool, ) -> Result<(), Self::AutoAckErrorType>

Enable or disable the custom ACK (acknowledgement) payloads attached to auto-ack packets. Read more
Source§

fn get_ack_payloads(&self) -> bool

Get the current setting of the ACK payloads feature. Read more
Source§

fn set_auto_ack(&mut self, enable: bool) -> Result<(), Self::AutoAckErrorType>

Enable or disable the auto-ack (automatic acknowledgement) feature for all pipes. Read more
Source§

fn set_auto_ack_pipe( &mut self, enable: bool, pipe: u8, ) -> Result<(), Self::AutoAckErrorType>

Set the auto-ack feature for an individual pipe. Read more
Source§

fn allow_ask_no_ack( &mut self, enable: bool, ) -> Result<(), Self::AutoAckErrorType>

Allow the functionality of the ask_no_ack parameter in EsbRadio::send() and EsbRadio::write(). Read more
Source§

fn write_ack_payload( &mut self, pipe: u8, buf: &[u8], ) -> Result<bool, Self::AutoAckErrorType>

Write a buf to the radio’s TX FIFO for use with automatic ACK packets. Read more
Source§

fn set_auto_retries( &mut self, delay: u8, count: u8, ) -> Result<(), Self::AutoAckErrorType>

Set the number of retry attempts and delay between retry attempts when transmitting a payload. Read more
Source§

impl<SPI, DO, DELAY> EsbChannel for RF24<SPI, DO, DELAY>
where SPI: SpiDevice, DO: OutputPin, DELAY: DelayNs,

Source§

fn set_channel(&mut self, channel: u8) -> Result<(), Self::ChannelErrorType>

The nRF24L01 support 126 channels. The specified channel is clamped to the range [0, 125].

Source§

fn get_channel(&mut self) -> Result<u8, Self::ChannelErrorType>

Source§

type ChannelErrorType = Nrf24Error<<SPI as ErrorType>::Error, <DO as ErrorType>::Error>

Source§

impl<SPI, DO, DELAY> EsbCrcLength for RF24<SPI, DO, DELAY>
where SPI: SpiDevice, DO: OutputPin, DELAY: DelayNs,

Source§

type CrcLengthErrorType = Nrf24Error<<SPI as ErrorType>::Error, <DO as ErrorType>::Error>

Source§

fn get_crc_length(&mut self) -> Result<CrcLength, Self::CrcLengthErrorType>

Get the currently configured CRC (Cyclical Redundancy Checksum) length
Source§

fn set_crc_length( &mut self, crc_length: CrcLength, ) -> Result<(), Self::CrcLengthErrorType>

Set the radio’s CRC (Cyclical Redundancy Checksum) length
Source§

impl<SPI, DO, DELAY> EsbDataRate for RF24<SPI, DO, DELAY>
where SPI: SpiDevice, DO: OutputPin, DELAY: DelayNs,

Source§

type DataRateErrorType = Nrf24Error<<SPI as ErrorType>::Error, <DO as ErrorType>::Error>

Source§

fn get_data_rate(&mut self) -> Result<DataRate, Self::DataRateErrorType>

Get the currently configured Data Rate
Source§

fn set_data_rate( &mut self, data_rate: DataRate, ) -> Result<(), Self::DataRateErrorType>

Set the radio’s Data Rate
Source§

impl<SPI, DO, DELAY> EsbDetails for RF24<SPI, DO, DELAY>
where SPI: SpiDevice, DO: OutputPin, DELAY: DelayNs,

Source§

type DetailsErrorType = Nrf24Error<<SPI as ErrorType>::Error, <DO as ErrorType>::Error>

Source§

fn print_details(&mut self) -> Result<(), Self::DetailsErrorType>

Print details about radio’s current configuration. Read more
Source§

impl<SPI, DO, DELAY> EsbFifo for RF24<SPI, DO, DELAY>
where SPI: SpiDevice, DO: OutputPin, DELAY: DelayNs,

Source§

fn flush_rx(&mut self) -> Result<(), Self::FifoErrorType>

Use this to discard all 3 layers in the radio’s RX FIFO.

Source§

fn flush_tx(&mut self) -> Result<(), Self::FifoErrorType>

Use this to discard all 3 layers in the radio’s TX FIFO.

Source§

type FifoErrorType = Nrf24Error<<SPI as ErrorType>::Error, <DO as ErrorType>::Error>

Source§

fn available(&mut self) -> Result<bool, Self::FifoErrorType>

Is there a payload available in the radio’s RX FIFO? Read more
Source§

fn available_pipe(&mut self, pipe: &mut u8) -> Result<bool, Self::FifoErrorType>

This is similar to EsbFifo::available() except the pipe parameter is given a mutable u8 value, and the pipe number that received the data is stored to it. Read more
Source§

fn get_fifo_state( &mut self, about_tx: bool, ) -> Result<FifoState, Self::FifoErrorType>

Get the state of the specified FIFO. Read more
Source§

impl<SPI, DO, DELAY> EsbInit for RF24<SPI, DO, DELAY>
where SPI: SpiDevice, DO: OutputPin, DELAY: DelayNs,

Source§

fn init(&mut self) -> Result<(), Self::ConfigErrorType>

Initialize the radio’s hardware using the SpiDevice and OutputPin given to RF24::new().

Source§

type ConfigErrorType = Nrf24Error<<SPI as ErrorType>::Error, <DO as ErrorType>::Error>

Source§

fn with_config( &mut self, config: &RadioConfig, ) -> Result<(), Self::ConfigErrorType>

Reconfigure the radio using the given config object. Read more
Source§

impl<SPI, DO, DELAY> EsbPaLevel for RF24<SPI, DO, DELAY>
where SPI: SpiDevice, DO: OutputPin, DELAY: DelayNs,

Source§

type PaLevelErrorType = Nrf24Error<<SPI as ErrorType>::Error, <DO as ErrorType>::Error>

Source§

fn get_pa_level(&mut self) -> Result<PaLevel, Self::PaLevelErrorType>

Get the currently configured Power Amplitude Level (PA Level)
Source§

fn set_pa_level( &mut self, pa_level: PaLevel, ) -> Result<(), Self::PaLevelErrorType>

Set the radio’s Power Amplitude Level (PA Level)
Source§

impl<SPI, DO, DELAY> EsbPayloadLength for RF24<SPI, DO, DELAY>
where SPI: SpiDevice, DO: OutputPin, DELAY: DelayNs,

Source§

type PayloadLengthErrorType = Nrf24Error<<SPI as ErrorType>::Error, <DO as ErrorType>::Error>

Source§

fn set_payload_length( &mut self, length: u8, ) -> Result<(), Self::PayloadLengthErrorType>

Set the radio’s static payload length. Read more
Source§

fn get_payload_length(&mut self) -> Result<u8, Self::PayloadLengthErrorType>

Get the currently configured static payload length used on pipe 0 Read more
Source§

fn set_dynamic_payloads( &mut self, enable: bool, ) -> Result<(), Self::PayloadLengthErrorType>

Set the dynamic payloads feature for all pipes. Read more
Source§

fn get_dynamic_payloads(&self) -> bool

Get the current setting of the dynamic payloads feature. Read more
Source§

fn get_dynamic_payload_length( &mut self, ) -> Result<u8, Self::PayloadLengthErrorType>

Get the dynamic length of the next available payload in the RX FIFO. Read more
Source§

impl<SPI, DO, DELAY> EsbPipe for RF24<SPI, DO, DELAY>
where SPI: SpiDevice, DO: OutputPin, DELAY: DelayNs,

Source§

fn close_rx_pipe(&mut self, pipe: u8) -> Result<(), Self::PipeErrorType>

If the given pipe number is not in range [0, 5], then this function does nothing.

Source§

type PipeErrorType = Nrf24Error<<SPI as ErrorType>::Error, <DO as ErrorType>::Error>

Source§

fn open_rx_pipe( &mut self, pipe: u8, address: &[u8], ) -> Result<(), Self::PipeErrorType>

Open a specified pipe for receiving data when radio is in RX mode. Read more
Source§

fn open_tx_pipe(&mut self, address: &[u8]) -> Result<(), Self::PipeErrorType>

Set an address to pipe 0 for transmitting when radio is in TX mode.
Source§

fn set_address_length(&mut self, length: u8) -> Result<(), Self::PipeErrorType>

Set the address length (applies to all pipes). Read more
Source§

fn get_address_length(&mut self) -> Result<u8, Self::PipeErrorType>

Get the currently configured address length (applied to all pipes).
Source§

impl<SPI, DO, DELAY> EsbPower for RF24<SPI, DO, DELAY>
where SPI: SpiDevice, DO: OutputPin, DELAY: DelayNs,

Source§

fn power_down(&mut self) -> Result<(), Self::PowerErrorType>

After calling EsbRadio::as_rx(), a non-PA/LNA radio will consume about 13.5mA at PaLevel::MAX. During active transmission (including RX role when transmitting an auto-ACK packet), a non-PA/LNA radio will consume about 11.5mA. In power standby mode (when not receiving nor transmitting), a non-PA/LNA radio will consume about 26uA (.026mA). In full power down mode (a sleep state), the radio will consume approximately 900nA (.0009mA).

Source§

fn is_powered(&self) -> bool

Is the radio powered up?

Source§

type PowerErrorType = Nrf24Error<<SPI as ErrorType>::Error, <DO as ErrorType>::Error>

Source§

fn power_up(&mut self, delay: Option<u32>) -> Result<(), Self::PowerErrorType>

Power up the radio. Read more
Source§

impl<SPI, DO, DELAY> EsbRadio for RF24<SPI, DO, DELAY>
where SPI: SpiDevice, DO: OutputPin, DELAY: DelayNs,

Source§

fn send( &mut self, buf: &[u8], ask_no_ack: bool, ) -> Result<bool, Self::RadioErrorType>

See EsbRadio::send() for implementation-agnostic detail.

This function calls RF24::flush_tx() upon entry, but it does not deactivate the radio’s CE pin upon exit.

Source§

fn write( &mut self, buf: &[u8], ask_no_ack: bool, start_tx: bool, ) -> Result<bool, Self::RadioErrorType>

See EsbRadio::write() for implementation-agnostic detail. Remember, the nRF24L01’s active TX mode is activated by the nRF24L01’s CE pin.

To transmit a payload the radio’s CE pin must be active for at least 10 microseconds. The caller is required to ensure the CE pin has been active for at least 10 microseconds when using this function, thus non-blocking behavior.

Source§

fn read( &mut self, buf: &mut [u8], len: Option<u8>, ) -> Result<u8, Self::RadioErrorType>

See EsbRadio::read() for implementation-agnostic detail.

Remember that each call to RF24::read() fetches data from the RX FIFO beginning with the first byte from the first available payload. A payload is not removed from the RX FIFO until it’s entire length (or more) is fetched.

  • If len is less than the available payload’s length, then the payload remains in the RX FIFO.
  • If len is greater than the first of multiple available payloads, then the data saved to the buf parameter’s object will be supplemented with data from the next available payload.
  • If len is greater than the last available payload’s length, then the last byte in the payload is used as padding for the data saved to the buf parameter’s object. The nRF24L01 will repeatedly use the last byte from the last payload even when RF24::read() is called with an empty RX FIFO.
Source§

type RadioErrorType = Nrf24Error<<SPI as ErrorType>::Error, <DO as ErrorType>::Error>

Source§

fn as_rx(&mut self) -> Result<(), Self::RadioErrorType>

Put the radio into active RX mode. Read more
Source§

fn as_tx(&mut self) -> Result<(), Self::RadioErrorType>

Put the radio into inactive TX mode. Read more
Source§

fn is_rx(&self) -> bool

Is the radio in RX mode?
Source§

fn resend(&mut self) -> Result<bool, Self::RadioErrorType>

Similar to EsbRadio::send() but specifically for failed transmissions. Read more
Source§

fn rewrite(&mut self) -> Result<(), Self::RadioErrorType>

Similar to EsbRadio::write() but specifically for failed transmissions. Read more
Source§

fn get_last_arc(&mut self) -> Result<u8, Self::RadioErrorType>

Get the Auto-Retry Count (ARC) about the previous transmission. Read more
Source§

impl<SPI, DO, DELAY> EsbStatus for RF24<SPI, DO, DELAY>
where SPI: SpiDevice, DO: OutputPin, DELAY: DelayNs,

Source§

type StatusErrorType = Nrf24Error<<SPI as ErrorType>::Error, <DO as ErrorType>::Error>

Source§

fn set_status_flags( &mut self, flags: StatusFlags, ) -> Result<(), Self::StatusErrorType>

Configure which status flags trigger the radio’s IRQ pin. Read more
Source§

fn clear_status_flags( &mut self, flags: StatusFlags, ) -> Result<(), Self::StatusErrorType>

Clear the radio’s IRQ status flags Read more
Source§

fn update(&mut self) -> Result<(), Self::StatusErrorType>

Refresh the internal cache of status byte (which is also saved from every SPI transaction). Read more
Source§

fn get_status_flags(&self, flags: &mut StatusFlags)

Get the StatusFlags state that was cached from the latest SPI transaction.

Auto Trait Implementations§

§

impl<SPI, DO, DELAY> Freeze for RF24<SPI, DO, DELAY>
where SPI: Freeze, DO: Freeze, DELAY: Freeze,

§

impl<SPI, DO, DELAY> RefUnwindSafe for RF24<SPI, DO, DELAY>
where SPI: RefUnwindSafe, DO: RefUnwindSafe, DELAY: RefUnwindSafe,

§

impl<SPI, DO, DELAY> Send for RF24<SPI, DO, DELAY>
where SPI: Send, DO: Send, DELAY: Send,

§

impl<SPI, DO, DELAY> Sync for RF24<SPI, DO, DELAY>
where SPI: Sync, DO: Sync, DELAY: Sync,

§

impl<SPI, DO, DELAY> Unpin for RF24<SPI, DO, DELAY>
where SPI: Unpin, DO: Unpin, DELAY: Unpin,

§

impl<SPI, DO, DELAY> UnwindSafe for RF24<SPI, DO, DELAY>
where SPI: UnwindSafe, DO: UnwindSafe, DELAY: 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.