-
Notifications
You must be signed in to change notification settings - Fork 1k
add: expose status byte in public API #1032
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 1 commit
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
4a86d73
add: expose status byte in public API.
2bndy5 f1393d1
modify streamingData and IRQconfig examples
2bndy5 2da1c23
remove StatusFlags struct
2bndy5 981b8db
migrate internal API and expose printStatus()
2bndy5 dbb4d00
deprecate maskIRQ() and whatHappened()
2bndy5 958c94f
add migration guide about deprecated API
2bndy5 fd1b725
proofread migration guide
2bndy5 308a89a
store IRQ config in cached config_reg
2bndy5 c4f5a57
code gulfing
2bndy5 2e30486
accept rvalue for python wrapper
2bndy5 eed69be
only print elapsed time for each stream
2bndy5 9308937
use 1-based counter in RX role of CPP streaming example
2bndy5 11f97d8
review migration guide
2bndy5 db98a47
fix pico irq example
2bndy5 3db7cfa
final review
2bndy5 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
add migration guide about deprecated API
- Loading branch information
commit 958c94f7af05ebebea0b942a61b14b7ccff2295f
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,208 @@ | ||
| # Migration guide | ||
|
|
||
| @tableofcontents | ||
|
|
||
| This is a collection of snippets that highlight preferred API over the deprecated original API. | ||
|
|
||
| ## isAckPayloadAvailable() | ||
|
|
||
| > **Deprecated since v1.4.2** | ||
|
|
||
| This function is equivalent to `RF24::available()`. | ||
| Any use of `RF24::isAckPayloadAvailable()` is interchangeable with `RF24::available()`. | ||
|
|
||
| <table><tr> | ||
| <th>Old</th> | ||
| <th>New (supported)</th> | ||
| </tr><tr><td> | ||
|
|
||
| ```cpp | ||
| if radio.isAckPayloadAvailable() { /* .. */ } | ||
| ``` | ||
|
|
||
| </td><td> | ||
|
|
||
| ```cpp | ||
| if radio.available() { /* .. */ } | ||
| ``` | ||
|
|
||
| </td></tr></table> | ||
|
|
||
| ## openReadingPipe(uint8_t, uint64_t) and openWritingPipe(uint64_t) | ||
|
|
||
| > **Deprecated since v1.3.11** | ||
|
|
||
| These function's address parameter used a 64-bit unsigned integer (`uint64_t`). | ||
| The nRF24L01 can only use up to 40 bit addresses. | ||
| Thus, there was unused 24 bits being allocated for addresses using this function. | ||
|
|
||
| There are overloaded functions that use a buffer instead: | ||
|
|
||
| - `RF24::openReadingPipe(uint8_t, const uint8_t*)` | ||
| - `RF24::openWritingPipe(const uint8_t*)` | ||
|
|
||
| These eliminates the extra 24 bits by only using the length of the buffer (`uint8_t*`) | ||
| specified by `RF24::setAddressWidth()`. | ||
|
|
||
| > [!CAUTION] | ||
| > The endianness (byte order) of a buffer is reversed compared to a 64-bit integer. | ||
| > ```c | ||
| > uint64_t address = 0xB3B4B5B6C2; | ||
| > // is the same address as | ||
| > uint8_t address[5] = {0xC2, 0xB6, 0xB5, 0xB4, 0xB3}; | ||
| > ``` | ||
| > Notice the MSB (Most Significant Byte) `0xC2` is last in the integer but first in the buffer. | ||
|
|
||
| <table><tr> | ||
| <th>Old</th> | ||
| <th>New (supported)</th> | ||
| </tr><tr><td> | ||
|
|
||
| ```cpp | ||
| uint64_t address = 0xB3B4B5B6C2; | ||
| radio.openReadingPipe(1, address); | ||
| ``` | ||
|
|
||
| </td><td> | ||
|
|
||
| ```cpp | ||
| uint8_t address[5] = {0xC2, 0xB6, 0xB5, 0xB4, 0xB3}; | ||
| radio.openReadingPipe(1, address); | ||
| ``` | ||
|
|
||
| </td></tr></table> | ||
|
|
||
| > [!NOTE] | ||
| > Our examples actually use a C-string casted as `uint8_t` array of 6 bytes. | ||
| > That's because a C-string (`char*`) must be NULL terminated (`\0` at the end) in memory. | ||
| > ```c | ||
| > uint8_t address[][6] = { "1Node", "2Node" }; | ||
| > // is equivalent to | ||
| > uint8_t address[][6] = { { '1', 'N', 'o', 'd', 'e', '\0' }, | ||
| > { '2', 'N', 'o', 'd', 'e', '\0' } }; | ||
| > ``` | ||
|
|
||
| ## isFifo(bool, bool) | ||
|
|
||
| > **Deprecated since v1.4.11** | ||
|
|
||
| Introduced as a compliment to `RF24::isFifo(bool)` in v1.4.3, this function was | ||
| supposed to provide specific detail about a specified radio's FIFO. However, it was | ||
| discovered that the function may not highlight binary corruption (`RF24_FIFO_INVALID`) | ||
| observed in the SPI bus' MISO line. | ||
|
|
||
| A fix was introduced using enumerated values of `rf24_fifo_state_e`. | ||
| Since then, `RF24::isFifo(bool)` is now preferred as it accurately describes the result. | ||
|
|
||
| <table><tr> | ||
| <th>Old</th> | ||
| <th>New (supported)</th> | ||
| </tr><tr><td> | ||
|
|
||
| ```cpp | ||
| bool rxFifoEmpty = radio.isFifo(false, true); | ||
| ``` | ||
|
|
||
| </td><td> | ||
|
|
||
| ```cpp | ||
| bool rxFifoEmpty = radio.isFifo(false) == RF24_FIFO_EMPTY; | ||
| ``` | ||
|
|
||
| </td></tr></table> | ||
|
|
||
| ## maskIRQ() | ||
|
|
||
| > **Deprecated since v1.5** | ||
|
|
||
| Originally `RF24::maskIRQ()` was the only function provided to influence the radio's IRQ pin. | ||
| However, the 3 required boolean parameters made this prone to bugs in user code. | ||
| The parameters' meaning was confusingly reversed and it was too easy put them in the wrong order. | ||
|
|
||
| A better approach was introduced with `RF24::setStatusFlags()`. | ||
| It's 1 parameter accepts values defined by the `rf24_irq_flags_e` enumerated constants. | ||
|
|
||
| <table><tr> | ||
| <th>Old</th> | ||
| <th>New (supported)</th> | ||
| </tr><tr><td> | ||
|
|
||
| ```cpp | ||
| // IRQ pin only activated by "RX Data Ready" event | ||
| radio.maskIRQ(1, 1, 0); | ||
|
|
||
| // IRQ pin activated by "TX Data Sent" and TX Data Failed" events | ||
| radio.maskIRQ(0, 0, 1); | ||
|
|
||
| // IRQ pin activated by all events | ||
| radio.maskIRQ(0, 0, 0); | ||
|
|
||
| // IRQ pin disabled | ||
| radio.maskIRQ(1, 1, 1); | ||
| ``` | ||
|
|
||
| </td><td> | ||
|
|
||
| ```cpp | ||
| // IRQ pin only activated by "RX Data Ready" event | ||
| radio.setStatusFlags(RF24_RX_DR); | ||
|
|
||
| // IRQ pin activated by "TX Data Sent" and TX Data Failed" events | ||
| radio.setStatusFlags(RF24_TX_DS | RF24_TX_DF); | ||
|
|
||
| // IRQ pin activated by all events | ||
| radio.setStatusFlags(RF24_IRQ_ALL); | ||
|
|
||
| // IRQ pin disabled | ||
| radio.setStatusFlags(RF24_IRQ_NONE); | ||
| // or equivalently | ||
| radio.setStatusFlags(); | ||
| ``` | ||
|
|
||
| </td></tr></table> | ||
|
|
||
|
|
||
| ## whatHappened() | ||
|
|
||
| > **Deprecated since v1.5** | ||
|
|
||
| Originally, `RF24::whatHappened()` was the only way to clear the events that triggered the IRQ pin. | ||
| Like `maskIRQ()`, this was also prone to bugs because of the 3 required boolean parameters | ||
| (passed by reference). | ||
|
|
||
| The aptly named `RF24::clearStatusFlags()` is designed to be a replacement for `RF24::whatHappened()`. | ||
| Like `RF24::clearStatusFlags()`, `RF24::setStatusFlags()` takes 1 parameter whose value is defined by | ||
| the `rf24_irq_flags_e` enumerated constants. | ||
| Additionally, it returns the STATUS byte containing the flags that caused the IRQ pin to go active LOW. | ||
| This allows the user code to allocate less memory when diagnosing the IRQ pin's meaning. | ||
|
|
||
| <table><tr> | ||
| <th>Old</th> | ||
| <th>New (supported)</th> | ||
| </tr><tr><td> | ||
|
|
||
| ```cpp | ||
| bool tx_ds, tx_df, rx_dr; | ||
| radio.whatHappened(tx_ds, tx_df, rx_dr); | ||
| ``` | ||
|
|
||
| </td><td> | ||
|
|
||
| ```cpp | ||
| uint8_t flags = radio.clearStatusFlags(); | ||
| // or equivalently | ||
| uint8_t flags = radio.clearStatusFlags(RF24_IRQ_ALL); | ||
|
|
||
| // focus on the events you care about | ||
| if (flags & RF24_TX_DS) { /* TX data sent */ } | ||
| if (flags & RF24_TX_DF) { /* TX data failed to send */ } | ||
| if (flags & RF24_RX_DR) { /* RX data is in the RX FIFO */ } | ||
|
|
||
| // only clear the "TX Data Sent" and TX Data Failed" events | ||
| radio.clearStatusFlags(RF24_TX_DS | RF24_TX_DF); | ||
|
|
||
| // only clear the "RX Data Ready" event | ||
| radio.clearStatusFlags(RF24_RX_DR); | ||
| ``` | ||
|
|
||
| </td></tr></table> |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.