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: u32The 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: DOThe 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>
impl<SPI, DO, DELAY> RF24<SPI, DO, DELAY>
Sourcepub fn is_plus_variant(&self) -> bool
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().
pub fn rpd(&mut self) -> Result<bool, Nrf24Error<SPI::Error, DO::Error>>
pub fn start_carrier_wave( &mut self, level: PaLevel, channel: u8, ) -> Result<(), Nrf24Error<SPI::Error, DO::Error>>
pub fn stop_carrier_wave( &mut self, ) -> Result<(), Nrf24Error<SPI::Error, DO::Error>>
Sourcepub fn set_lna(
&mut self,
enable: bool,
) -> Result<(), Nrf24Error<SPI::Error, DO::Error>>
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>
impl<SPI, DO, DELAY> EsbAutoAck for RF24<SPI, DO, DELAY>
type AutoAckErrorType = Nrf24Error<<SPI as ErrorType>::Error, <DO as ErrorType>::Error>
Source§fn set_ack_payloads(
&mut self,
enable: bool,
) -> Result<(), Self::AutoAckErrorType>
fn set_ack_payloads( &mut self, enable: bool, ) -> Result<(), Self::AutoAckErrorType>
Source§fn get_ack_payloads(&self) -> bool
fn get_ack_payloads(&self) -> bool
Source§fn set_auto_ack(&mut self, enable: bool) -> Result<(), Self::AutoAckErrorType>
fn set_auto_ack(&mut self, enable: bool) -> Result<(), Self::AutoAckErrorType>
Source§fn set_auto_ack_pipe(
&mut self,
enable: bool,
pipe: u8,
) -> Result<(), Self::AutoAckErrorType>
fn set_auto_ack_pipe( &mut self, enable: bool, pipe: u8, ) -> Result<(), Self::AutoAckErrorType>
pipe. Read moreSource§fn allow_ask_no_ack(
&mut self,
enable: bool,
) -> Result<(), Self::AutoAckErrorType>
fn allow_ask_no_ack( &mut self, enable: bool, ) -> Result<(), Self::AutoAckErrorType>
ask_no_ack parameter in EsbRadio::send() and
EsbRadio::write(). Read moreSource§fn write_ack_payload(
&mut self,
pipe: u8,
buf: &[u8],
) -> Result<bool, Self::AutoAckErrorType>
fn write_ack_payload( &mut self, pipe: u8, buf: &[u8], ) -> Result<bool, Self::AutoAckErrorType>
buf to the radio’s TX FIFO for use with automatic ACK packets. Read moreSource§fn set_auto_retries(
&mut self,
delay: u8,
count: u8,
) -> Result<(), Self::AutoAckErrorType>
fn set_auto_retries( &mut self, delay: u8, count: u8, ) -> Result<(), Self::AutoAckErrorType>
Source§impl<SPI, DO, DELAY> EsbChannel for RF24<SPI, DO, DELAY>
impl<SPI, DO, DELAY> EsbChannel for RF24<SPI, DO, DELAY>
Source§fn set_channel(&mut self, channel: u8) -> Result<(), Self::ChannelErrorType>
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>
fn get_channel(&mut self) -> Result<u8, Self::ChannelErrorType>
See also RF24::set_channel().
type ChannelErrorType = Nrf24Error<<SPI as ErrorType>::Error, <DO as ErrorType>::Error>
Source§impl<SPI, DO, DELAY> EsbCrcLength for RF24<SPI, DO, DELAY>
impl<SPI, DO, DELAY> EsbCrcLength for RF24<SPI, DO, DELAY>
type CrcLengthErrorType = Nrf24Error<<SPI as ErrorType>::Error, <DO as ErrorType>::Error>
Source§fn get_crc_length(&mut self) -> Result<CrcLength, Self::CrcLengthErrorType>
fn get_crc_length(&mut self) -> Result<CrcLength, Self::CrcLengthErrorType>
Source§fn set_crc_length(
&mut self,
crc_length: CrcLength,
) -> Result<(), Self::CrcLengthErrorType>
fn set_crc_length( &mut self, crc_length: CrcLength, ) -> Result<(), Self::CrcLengthErrorType>
Source§impl<SPI, DO, DELAY> EsbDataRate for RF24<SPI, DO, DELAY>
impl<SPI, DO, DELAY> EsbDataRate for RF24<SPI, DO, DELAY>
type DataRateErrorType = Nrf24Error<<SPI as ErrorType>::Error, <DO as ErrorType>::Error>
Source§fn get_data_rate(&mut self) -> Result<DataRate, Self::DataRateErrorType>
fn get_data_rate(&mut self) -> Result<DataRate, Self::DataRateErrorType>
Source§fn set_data_rate(
&mut self,
data_rate: DataRate,
) -> Result<(), Self::DataRateErrorType>
fn set_data_rate( &mut self, data_rate: DataRate, ) -> Result<(), Self::DataRateErrorType>
Source§impl<SPI, DO, DELAY> EsbDetails for RF24<SPI, DO, DELAY>
impl<SPI, DO, DELAY> EsbDetails for RF24<SPI, DO, DELAY>
type DetailsErrorType = Nrf24Error<<SPI as ErrorType>::Error, <DO as ErrorType>::Error>
Source§fn print_details(&mut self) -> Result<(), Self::DetailsErrorType>
fn print_details(&mut self) -> Result<(), Self::DetailsErrorType>
Source§impl<SPI, DO, DELAY> EsbFifo for RF24<SPI, DO, DELAY>
impl<SPI, DO, DELAY> EsbFifo for RF24<SPI, DO, DELAY>
Source§fn flush_rx(&mut self) -> Result<(), Self::FifoErrorType>
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>
fn flush_tx(&mut self) -> Result<(), Self::FifoErrorType>
Use this to discard all 3 layers in the radio’s TX FIFO.
type FifoErrorType = Nrf24Error<<SPI as ErrorType>::Error, <DO as ErrorType>::Error>
Source§fn available(&mut self) -> Result<bool, Self::FifoErrorType>
fn available(&mut self) -> Result<bool, Self::FifoErrorType>
Source§fn available_pipe(&mut self, pipe: &mut u8) -> Result<bool, Self::FifoErrorType>
fn available_pipe(&mut self, pipe: &mut u8) -> Result<bool, Self::FifoErrorType>
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 moreSource§fn get_fifo_state(
&mut self,
about_tx: bool,
) -> Result<FifoState, Self::FifoErrorType>
fn get_fifo_state( &mut self, about_tx: bool, ) -> Result<FifoState, Self::FifoErrorType>
Source§impl<SPI, DO, DELAY> EsbInit for RF24<SPI, DO, DELAY>
impl<SPI, DO, DELAY> EsbInit for RF24<SPI, DO, DELAY>
Source§fn init(&mut self) -> Result<(), Self::ConfigErrorType>
fn init(&mut self) -> Result<(), Self::ConfigErrorType>
Initialize the radio’s hardware using the SpiDevice and OutputPin given
to RF24::new().
type ConfigErrorType = Nrf24Error<<SPI as ErrorType>::Error, <DO as ErrorType>::Error>
Source§fn with_config(
&mut self,
config: &RadioConfig,
) -> Result<(), Self::ConfigErrorType>
fn with_config( &mut self, config: &RadioConfig, ) -> Result<(), Self::ConfigErrorType>
config object. Read moreSource§impl<SPI, DO, DELAY> EsbPaLevel for RF24<SPI, DO, DELAY>
impl<SPI, DO, DELAY> EsbPaLevel for RF24<SPI, DO, DELAY>
type PaLevelErrorType = Nrf24Error<<SPI as ErrorType>::Error, <DO as ErrorType>::Error>
Source§fn get_pa_level(&mut self) -> Result<PaLevel, Self::PaLevelErrorType>
fn get_pa_level(&mut self) -> Result<PaLevel, Self::PaLevelErrorType>
Source§fn set_pa_level(
&mut self,
pa_level: PaLevel,
) -> Result<(), Self::PaLevelErrorType>
fn set_pa_level( &mut self, pa_level: PaLevel, ) -> Result<(), Self::PaLevelErrorType>
Source§impl<SPI, DO, DELAY> EsbPayloadLength for RF24<SPI, DO, DELAY>
impl<SPI, DO, DELAY> EsbPayloadLength for RF24<SPI, DO, DELAY>
type PayloadLengthErrorType = Nrf24Error<<SPI as ErrorType>::Error, <DO as ErrorType>::Error>
Source§fn set_payload_length(
&mut self,
length: u8,
) -> Result<(), Self::PayloadLengthErrorType>
fn set_payload_length( &mut self, length: u8, ) -> Result<(), Self::PayloadLengthErrorType>
Source§fn get_payload_length(&mut self) -> Result<u8, Self::PayloadLengthErrorType>
fn get_payload_length(&mut self) -> Result<u8, Self::PayloadLengthErrorType>
Source§fn set_dynamic_payloads(
&mut self,
enable: bool,
) -> Result<(), Self::PayloadLengthErrorType>
fn set_dynamic_payloads( &mut self, enable: bool, ) -> Result<(), Self::PayloadLengthErrorType>
Source§fn get_dynamic_payloads(&self) -> bool
fn get_dynamic_payloads(&self) -> bool
Source§fn get_dynamic_payload_length(
&mut self,
) -> Result<u8, Self::PayloadLengthErrorType>
fn get_dynamic_payload_length( &mut self, ) -> Result<u8, Self::PayloadLengthErrorType>
Source§impl<SPI, DO, DELAY> EsbPipe for RF24<SPI, DO, DELAY>
impl<SPI, DO, DELAY> EsbPipe for RF24<SPI, DO, DELAY>
Source§fn close_rx_pipe(&mut self, pipe: u8) -> Result<(), Self::PipeErrorType>
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.
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>
fn open_rx_pipe( &mut self, pipe: u8, address: &[u8], ) -> Result<(), Self::PipeErrorType>
pipe for receiving data when radio is in RX mode. Read moreSource§fn open_tx_pipe(&mut self, address: &[u8]) -> Result<(), Self::PipeErrorType>
fn open_tx_pipe(&mut self, address: &[u8]) -> Result<(), Self::PipeErrorType>
Source§fn set_address_length(&mut self, length: u8) -> Result<(), Self::PipeErrorType>
fn set_address_length(&mut self, length: u8) -> Result<(), Self::PipeErrorType>
Source§fn get_address_length(&mut self) -> Result<u8, Self::PipeErrorType>
fn get_address_length(&mut self) -> Result<u8, Self::PipeErrorType>
Source§impl<SPI, DO, DELAY> EsbPower for RF24<SPI, DO, DELAY>
impl<SPI, DO, DELAY> EsbPower for RF24<SPI, DO, DELAY>
Source§fn power_down(&mut self) -> Result<(), Self::PowerErrorType>
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
fn is_powered(&self) -> bool
Is the radio powered up?
type PowerErrorType = Nrf24Error<<SPI as ErrorType>::Error, <DO as ErrorType>::Error>
Source§impl<SPI, DO, DELAY> EsbRadio for RF24<SPI, DO, DELAY>
impl<SPI, DO, DELAY> EsbRadio for RF24<SPI, DO, DELAY>
Source§fn send(
&mut self,
buf: &[u8],
ask_no_ack: bool,
) -> Result<bool, Self::RadioErrorType>
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>
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>
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
lenis less than the available payload’s length, then the payload remains in the RX FIFO. - If
lenis greater than the first of multiple available payloads, then the data saved to thebufparameter’s object will be supplemented with data from the next available payload. - If
lenis greater than the last available payload’s length, then the last byte in the payload is used as padding for the data saved to thebufparameter’s object. The nRF24L01 will repeatedly use the last byte from the last payload even whenRF24::read()is called with an empty RX FIFO.
type RadioErrorType = Nrf24Error<<SPI as ErrorType>::Error, <DO as ErrorType>::Error>
Source§fn as_rx(&mut self) -> Result<(), Self::RadioErrorType>
fn as_rx(&mut self) -> Result<(), Self::RadioErrorType>
Source§fn as_tx(&mut self) -> Result<(), Self::RadioErrorType>
fn as_tx(&mut self) -> Result<(), Self::RadioErrorType>
Source§fn resend(&mut self) -> Result<bool, Self::RadioErrorType>
fn resend(&mut self) -> Result<bool, Self::RadioErrorType>
EsbRadio::send() but specifically for failed transmissions. Read moreSource§fn rewrite(&mut self) -> Result<(), Self::RadioErrorType>
fn rewrite(&mut self) -> Result<(), Self::RadioErrorType>
EsbRadio::write() but specifically for failed transmissions. Read moreSource§fn get_last_arc(&mut self) -> Result<u8, Self::RadioErrorType>
fn get_last_arc(&mut self) -> Result<u8, Self::RadioErrorType>
Source§impl<SPI, DO, DELAY> EsbStatus for RF24<SPI, DO, DELAY>
impl<SPI, DO, DELAY> EsbStatus for RF24<SPI, DO, DELAY>
type StatusErrorType = Nrf24Error<<SPI as ErrorType>::Error, <DO as ErrorType>::Error>
Source§fn set_status_flags(
&mut self,
flags: StatusFlags,
) -> Result<(), Self::StatusErrorType>
fn set_status_flags( &mut self, flags: StatusFlags, ) -> Result<(), Self::StatusErrorType>
Source§fn clear_status_flags(
&mut self,
flags: StatusFlags,
) -> Result<(), Self::StatusErrorType>
fn clear_status_flags( &mut self, flags: StatusFlags, ) -> Result<(), Self::StatusErrorType>
Source§fn update(&mut self) -> Result<(), Self::StatusErrorType>
fn update(&mut self) -> Result<(), Self::StatusErrorType>
Source§fn get_status_flags(&self, flags: &mut StatusFlags)
fn get_status_flags(&self, flags: &mut StatusFlags)
StatusFlags state that was cached from the latest SPI transaction.