You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The user code will manage the state of a radio object in a way that the compiler can keep track and prevent undesired behavior.
Here's some pseudo (user-space) code that should explain better:
letmut radio = RF24::new(ce_pin, spi_dev, delay_impl);// mutate the radio object so that it is in TX mode with auto-ack enabled
radio = radio.init()?;// `available()` and `read()` are exposed as a TX node.letmut payload = [0u8;32];if radio.available()? {
radio.read(&mut payload)?;}// `send()` and `write()` are also exposed as a TX nodelet ok = radio.send(&payload,/* ask_no_ack */false)?;// mutate the STATE of the radio
radio = radio.as_rx()?;// `send()` and `write()` are NOT exposed as a RX node, so// this line would fail to compile//let ok = radio.send(&payload, false)?;
The state management can be further extended to some radio features like power up/down, auto-ack, dynamic payloads, ACK payloads, etc. The main advantage here is that we no longer have the runtime overhead for checking the radio's settings for validity according to the invoked behavior; send() will not need to check the CONFIG register's PTX and PWR_UP flags.
Considerations
Addressing this is nothing short of a refactor (likely a complete API overhaul). Additionally, this solution may impact the convenient configurable API introduced by Consider abstracting config out of radio instance #5.
The bindings (both python and node.js are scripting languages that use dynamic types) may suffer additional overhead because the state would be managed dynamically at runtime (as it does currently).
The text was updated successfully, but these errors were encountered:
The main idea here is to take advantage of the rustc compiler's zero-cost abstractions.
Tip
See example in the embedded-rust book.
What does this mean?
The user code will manage the state of a radio object in a way that the compiler can keep track and prevent undesired behavior.
Here's some pseudo (user-space) code that should explain better:
The state management can be further extended to some radio features like power up/down, auto-ack, dynamic payloads, ACK payloads, etc. The main advantage here is that we no longer have the runtime overhead for checking the radio's settings for validity according to the invoked behavior;
send()
will not need to check the CONFIG register's PTX and PWR_UP flags.Considerations
The text was updated successfully, but these errors were encountered: