rf24/lib.rs
1#![doc(
2 html_logo_url = "https://raw.githubusercontent.com/nRF24/rf24-rs/main/docs/src/images/logo-square.png"
3)]
4#![doc(html_favicon_url = "https://github.com/nRF24/rf24-rs/raw/main/docs/src/images/favicon.ico")]
5#![doc = include_str!("../README.md")]
6//!
7//! ## Basic API
8//!
9//! - [`RF24::new()`](fn@crate::radio::RF24::new)
10//! - [`RF24::init()`](radio/struct.RF24.html#method.init)
11//! - [`RF24::is_rx()`](radio/struct.RF24.html#method.is_rx)
12//! - [`RF24::as_rx()`](radio/struct.RF24.html#method.as_rx)
13//! - [`RF24::as_tx()`](radio/struct.RF24.html#method.as_tx)
14//! - [`RF24::open_tx_pipe()`](radio/struct.RF24.html#method.open_tx_pipe)
15//! - [`RF24::open_rx_pipe()`](radio/struct.RF24.html#method.open_rx_pipe)
16//! - [`RF24::close_rx_pipe()`](radio/struct.RF24.html#method.close_rx_pipe)
17//! - [`RF24::available()`](radio/struct.RF24.html#method.available)
18//! - [`RF24::available_pipe()`](radio/struct.RF24.html#method.available_pipe)
19//! - [`RF24::read()`](radio/struct.RF24.html#method.read)
20//! - [`RF24::send()`](radio/struct.RF24.html#method.send)
21//! - [`RF24::resend()`](radio/struct.RF24.html#method.resend)
22//! - [`RF24::set_channel()`](radio/struct.RF24.html#method.set_channel)
23//! - [`RF24::get_channel()`](radio/struct.RF24.html#method.get_channel)
24//!
25//! ## Advanced API
26//!
27//! - [`RF24::write_ack_payload()`](radio/struct.RF24.html#method.write_ack_payload)
28//! - [`RF24::write()`](radio/struct.RF24.html#method.write)
29//! - [`RF24::rewrite()`](radio/struct.RF24.html#method.rewrite)
30//! - [`RF24::get_fifo_state()`](radio/struct.RF24.html#method.get_fifo_state)
31//! - [`RF24::clear_status_flags()`](radio/struct.RF24.html#method.clear_status_flags)
32//! - [`RF24::update()`](radio/struct.RF24.html#method.update)
33//! - [`RF24::get_status_flags()`](radio/struct.RF24.html#method.get_status_flags)
34//! - [`RF24::flush_rx()`](radio/struct.RF24.html#method.flush_rx)
35//! - [`RF24::flush_tx()`](radio/struct.RF24.html#method.flush_tx)
36//! - [`RF24::start_carrier_wave()`](fn@crate::radio::RF24::start_carrier_wave)
37//! - [`RF24::stop_carrier_wave()`](fn@crate::radio::RF24::stop_carrier_wave)
38//! - [`RF24::rpd()`](fn@crate::radio::RF24::rpd)
39//! - [`RF24::get_last_arc()`](radio/struct.RF24.html#method.get_last_arc)
40//! - [`RF24::get_dynamic_payload_length()`](radio/struct.RF24.html#method.get_dynamic_payload_length)
41//!
42//! ## Configuration API
43//!
44//! - [`RF24::with_config()`](radio/struct.RF24.html#method.with_config)
45//! - [`RF24::set_status_flags()`](radio/struct.RF24.html#method.set_status_flags)
46//! - [`RF24::set_auto_ack()`](radio/struct.RF24.html#method.set_auto_ack)
47//! - [`RF24::set_auto_ack_pipe()`](radio/struct.RF24.html#method.set_auto_ack_pipe)
48//! - [`RF24::set_auto_retries()`](radio/struct.RF24.html#method.set_auto_retries)
49//! - [`RF24::set_dynamic_payloads()`](radio/struct.RF24.html#method.set_dynamic_payloads)
50//! - [`RF24::allow_ask_no_ack()`](radio/struct.RF24.html#method.allow_ask_no_ack)
51//! - [`RF24::allow_ack_payloads()`](radio/struct.RF24.html#method.set_ack_payloads)
52//! - [`RF24::set_address_length()`](radio/struct.RF24.html#method.set_address_length)
53//! - [`RF24::get_address_length()`](radio/struct.RF24.html#method.get_address_length)
54//! - [`RF24::set_payload_length()`](radio/struct.RF24.html#method.set_payload_length)
55//! - [`RF24::get_payload_length()`](radio/struct.RF24.html#method.get_payload_length)
56//! - [`RF24::set_data_rate()`](radio/struct.RF24.html#method.set_data_rate)
57//! - [`RF24::get_data_rate()`](radio/struct.RF24.html#method.get_data_rate)
58//! - [`RF24::set_pa_level()`](radio/struct.RF24.html#method.set_pa_level)
59//! - [`RF24::get_pa_level()`](radio/struct.RF24.html#method.get_pa_level)
60//! - [`RF24::set_lna()`](fn@crate::radio::RF24::set_lna)
61//! - [`RF24::set_crc_length()`](radio/struct.RF24.html#method.set_crc_length)
62//! - [`RF24::get_crc_length()`](radio/struct.RF24.html#method.get_crc_length)
63//! - [`RF24::is_powered()`](radio/struct.RF24.html#method.is_powered)
64//! - [`RF24::power_up()`](radio/struct.RF24.html#method.power_up)
65//! - [`RF24::power_down()`](radio/struct.RF24.html#method.power_down)
66//! - [`RF24::tx_delay`](value@crate::radio::RF24::tx_delay)
67//! - [`RF24::is_plus_variant()`](fn@crate::radio::RF24::is_plus_variant)
68//!
69#![no_std]
70
71mod types;
72pub use types::{CrcLength, DataRate, FifoState, PaLevel, StatusFlags};
73pub mod radio;
74
75#[cfg(test)]
76mod test {
77 use crate::radio::RF24;
78 use embedded_hal_mock::eh1::{
79 delay::NoopDelay,
80 digital::{Mock as PinMock, Transaction as PinTransaction},
81 spi::{Mock as SpiMock, Transaction as SpiTransaction},
82 };
83
84 /// Takes an indefinite repetition of a tuple of 2 vectors: `(expected_data, response_data)`
85 /// and generates an array of `SpiTransaction`s.
86 ///
87 /// NOTE: This macro is only used to generate code in unit tests (for this crate only).
88 #[macro_export]
89 macro_rules! spi_test_expects {
90 ($( ($expected:expr , $response:expr $(,)? ) , ) + ) => {
91 [
92 $(
93 SpiTransaction::transaction_start(),
94 SpiTransaction::transfer_in_place($expected, $response),
95 SpiTransaction::transaction_end(),
96 )*
97 ]
98 }
99 }
100
101 /// A tuple struct to encapsulate objects used to mock [`RF24`],
102 pub struct MockRadio(
103 pub RF24<SpiMock<u8>, PinMock, NoopDelay>,
104 pub SpiMock<u8>,
105 pub PinMock,
106 );
107
108 /// Create a mock objects using the given expectations.
109 ///
110 /// The `spi_expectations` parameter
111 pub fn mk_radio(
112 ce_expectations: &[PinTransaction],
113 spi_expectations: &[SpiTransaction<u8>],
114 ) -> MockRadio {
115 let spi = SpiMock::new(spi_expectations);
116 let ce_pin = PinMock::new(ce_expectations);
117 let delay_impl = NoopDelay;
118 let radio = RF24::new(ce_pin.clone(), spi.clone(), delay_impl);
119 MockRadio(radio, spi, ce_pin)
120 }
121}