From 1fdd8ce9a4fa52031fef8d6a7e4909356900d257 Mon Sep 17 00:00:00 2001 From: Stephen Crane Date: Sat, 17 Oct 2020 13:04:02 +0100 Subject: [PATCH 1/8] available() could be slightly faster #631 --- RF24.cpp | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/RF24.cpp b/RF24.cpp index 09d0ea0a9..64def5001 100644 --- a/RF24.cpp +++ b/RF24.cpp @@ -1074,19 +1074,16 @@ bool RF24::available(void) bool RF24::available(uint8_t* pipe_num) { - if (!(read_register(FIFO_STATUS) & _BV(RX_EMPTY))) { - - // If the caller wants the pipe number, include that - if (pipe_num) { - uint8_t status = get_status(); - *pipe_num = (status >> RX_P_NO) & 0x07; - } - return 1; - } - - return 0; + // get implied RX FIFO empty flag from status byte + uint8_t pipe = (get_status() >> RX_P_NO) & 0x07; + if (pipe > 5) + return 0; + // If the caller wants the pipe number, include that + if (pipe_num) + *pipe_num = pipe; + return 1; } /****************************************************************************/ From 5fe7dde1c74a1312ddc944938f13dee96906c9f5 Mon Sep 17 00:00:00 2001 From: Stephen Crane Date: Sun, 15 Nov 2020 13:54:47 +0000 Subject: [PATCH 2/8] allow skipping delay(5) in powerUp() --- RF24.cpp | 5 +++-- RF24.h | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/RF24.cpp b/RF24.cpp index 64def5001..29ec199a1 100644 --- a/RF24.cpp +++ b/RF24.cpp @@ -755,7 +755,7 @@ void RF24::powerDown(void) /****************************************************************************/ //Power up now. Radio will not power down unless instructed by MCU for config changes etc. -void RF24::powerUp(void) +void RF24::powerUp(bool wait) { // if not powered up then power up and wait for the radio to initialize if (!(config_reg & _BV(PWR_UP))) { @@ -765,7 +765,8 @@ void RF24::powerUp(void) // For nRF24L01+ to go from power down mode to TX or RX mode it must first pass through stand-by mode. // There must be a delay of Tpd2stby (see Table 16.) after the nRF24L01+ leaves power down mode before // the CEis set high. - Tpd2stby can be up to 5ms per the 1.0 datasheet - delay(5); + if (wait) + delay(5); } } diff --git a/RF24.h b/RF24.h index 442431d58..322aa4dc6 100644 --- a/RF24.h +++ b/RF24.h @@ -385,7 +385,7 @@ class RF24 { * To return to low power mode, call powerDown(). * @note This will take up to 5ms for maximum compatibility */ - void powerUp(void); + void powerUp(bool wait = true); /** * Write for single NOACK writes. Optionally disables acknowledgements/autoretries for a single write. From ffd7524a8c787507f820c7c5384874e232cdb4f4 Mon Sep 17 00:00:00 2001 From: Stephen Crane Date: Sun, 15 Nov 2020 13:54:47 +0000 Subject: [PATCH 3/8] allow skipping delay(5) in powerUp() --- RF24.cpp | 5 +++-- RF24.h | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/RF24.cpp b/RF24.cpp index 0b557fb04..6f06f12b3 100644 --- a/RF24.cpp +++ b/RF24.cpp @@ -755,7 +755,7 @@ void RF24::powerDown(void) /****************************************************************************/ //Power up now. Radio will not power down unless instructed by MCU for config changes etc. -void RF24::powerUp(void) +void RF24::powerUp(bool wait) { // if not powered up then power up and wait for the radio to initialize if (!(config_reg & _BV(PWR_UP))) { @@ -765,7 +765,8 @@ void RF24::powerUp(void) // For nRF24L01+ to go from power down mode to TX or RX mode it must first pass through stand-by mode. // There must be a delay of Tpd2stby (see Table 16.) after the nRF24L01+ leaves power down mode before // the CEis set high. - Tpd2stby can be up to 5ms per the 1.0 datasheet - delay(5); + if (wait) + delay(5); } } diff --git a/RF24.h b/RF24.h index 442431d58..322aa4dc6 100644 --- a/RF24.h +++ b/RF24.h @@ -385,7 +385,7 @@ class RF24 { * To return to low power mode, call powerDown(). * @note This will take up to 5ms for maximum compatibility */ - void powerUp(void); + void powerUp(bool wait = true); /** * Write for single NOACK writes. Optionally disables acknowledgements/autoretries for a single write. From 2d21fab0194fdd1cfca26d1a5546ac50b44d8666 Mon Sep 17 00:00:00 2001 From: Stephen Crane Date: Fri, 27 Nov 2020 09:35:23 +0000 Subject: [PATCH 4/8] Revert "allow skipping delay(5) in powerUp()" This reverts commit ffd7524a8c787507f820c7c5384874e232cdb4f4. --- RF24.cpp | 5 ++--- RF24.h | 2 +- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/RF24.cpp b/RF24.cpp index 6f06f12b3..0b557fb04 100644 --- a/RF24.cpp +++ b/RF24.cpp @@ -755,7 +755,7 @@ void RF24::powerDown(void) /****************************************************************************/ //Power up now. Radio will not power down unless instructed by MCU for config changes etc. -void RF24::powerUp(bool wait) +void RF24::powerUp(void) { // if not powered up then power up and wait for the radio to initialize if (!(config_reg & _BV(PWR_UP))) { @@ -765,8 +765,7 @@ void RF24::powerUp(bool wait) // For nRF24L01+ to go from power down mode to TX or RX mode it must first pass through stand-by mode. // There must be a delay of Tpd2stby (see Table 16.) after the nRF24L01+ leaves power down mode before // the CEis set high. - Tpd2stby can be up to 5ms per the 1.0 datasheet - if (wait) - delay(5); + delay(5); } } diff --git a/RF24.h b/RF24.h index 322aa4dc6..442431d58 100644 --- a/RF24.h +++ b/RF24.h @@ -385,7 +385,7 @@ class RF24 { * To return to low power mode, call powerDown(). * @note This will take up to 5ms for maximum compatibility */ - void powerUp(bool wait = true); + void powerUp(void); /** * Write for single NOACK writes. Optionally disables acknowledgements/autoretries for a single write. From 319178f361a64a9273c9f9aa18145a5c51a472cf Mon Sep 17 00:00:00 2001 From: Stephen Crane Date: Fri, 27 Nov 2020 09:36:43 +0000 Subject: [PATCH 5/8] Revert "allow skipping delay(5) in powerUp()" This reverts commit ffd7524a8c787507f820c7c5384874e232cdb4f4. --- RF24.cpp | 5 ++--- RF24.h | 2 +- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/RF24.cpp b/RF24.cpp index 6f06f12b3..0b557fb04 100644 --- a/RF24.cpp +++ b/RF24.cpp @@ -755,7 +755,7 @@ void RF24::powerDown(void) /****************************************************************************/ //Power up now. Radio will not power down unless instructed by MCU for config changes etc. -void RF24::powerUp(bool wait) +void RF24::powerUp(void) { // if not powered up then power up and wait for the radio to initialize if (!(config_reg & _BV(PWR_UP))) { @@ -765,8 +765,7 @@ void RF24::powerUp(bool wait) // For nRF24L01+ to go from power down mode to TX or RX mode it must first pass through stand-by mode. // There must be a delay of Tpd2stby (see Table 16.) after the nRF24L01+ leaves power down mode before // the CEis set high. - Tpd2stby can be up to 5ms per the 1.0 datasheet - if (wait) - delay(5); + delay(5); } } diff --git a/RF24.h b/RF24.h index 322aa4dc6..442431d58 100644 --- a/RF24.h +++ b/RF24.h @@ -385,7 +385,7 @@ class RF24 { * To return to low power mode, call powerDown(). * @note This will take up to 5ms for maximum compatibility */ - void powerUp(bool wait = true); + void powerUp(void); /** * Write for single NOACK writes. Optionally disables acknowledgements/autoretries for a single write. From 4d421179a51297ff01d81a35bcf2abea0d88d1c0 Mon Sep 17 00:00:00 2001 From: Stephen Crane Date: Fri, 27 Nov 2020 09:54:27 +0000 Subject: [PATCH 6/8] add RF24_POWERUP_DELAY_MS to RF24_config.h --- RF24.cpp | 2 +- RF24_config.h | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/RF24.cpp b/RF24.cpp index 0b557fb04..f1b6a9ac2 100644 --- a/RF24.cpp +++ b/RF24.cpp @@ -765,7 +765,7 @@ void RF24::powerUp(void) // For nRF24L01+ to go from power down mode to TX or RX mode it must first pass through stand-by mode. // There must be a delay of Tpd2stby (see Table 16.) after the nRF24L01+ leaves power down mode before // the CEis set high. - Tpd2stby can be up to 5ms per the 1.0 datasheet - delay(5); + delay(RF24_POWERUP_DELAY_MS); } } diff --git a/RF24_config.h b/RF24_config.h index 7572a957f..d505a6284 100644 --- a/RF24_config.h +++ b/RF24_config.h @@ -25,6 +25,10 @@ //#define SPI_UART // Requires library from https://github.com/TMRh20/Sketches/tree/master/SPI_UART //#define SOFTSPI // Requires library from https://github.com/greiman/DigitalIO +#if !defined(RF24_POWERUP_DELAY_MS) +#define RF24_POWERUP_DELAY_MS 5 +#endif + /**********************/ #define rf24_max(a,b) (a>b?a:b) #define rf24_min(a,b) (a Date: Fri, 27 Nov 2020 15:21:33 +0000 Subject: [PATCH 7/8] delayMicroseconds() --- RF24.cpp | 2 +- RF24_config.h | 9 +++++---- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/RF24.cpp b/RF24.cpp index f1b6a9ac2..f8ace8987 100644 --- a/RF24.cpp +++ b/RF24.cpp @@ -765,7 +765,7 @@ void RF24::powerUp(void) // For nRF24L01+ to go from power down mode to TX or RX mode it must first pass through stand-by mode. // There must be a delay of Tpd2stby (see Table 16.) after the nRF24L01+ leaves power down mode before // the CEis set high. - Tpd2stby can be up to 5ms per the 1.0 datasheet - delay(RF24_POWERUP_DELAY_MS); + delayMicroseconds(RF24_POWERUP_DELAY); } } diff --git a/RF24_config.h b/RF24_config.h index d505a6284..539e4d662 100644 --- a/RF24_config.h +++ b/RF24_config.h @@ -18,15 +18,16 @@ #ifndef __RF24_CONFIG_H__ #define __RF24_CONFIG_H__ -/*** USER DEFINES: ***/ +/*** USER DEFINES: ***/ #define FAILURE_HANDLING //#define SERIAL_DEBUG //#define MINIMAL //#define SPI_UART // Requires library from https://github.com/TMRh20/Sketches/tree/master/SPI_UART //#define SOFTSPI // Requires library from https://github.com/greiman/DigitalIO - -#if !defined(RF24_POWERUP_DELAY_MS) -#define RF24_POWERUP_DELAY_MS 5 + +/** User access to internally used delay time (in microseconds) during RF24::powerUp() */ +#if !defined(RF24_POWERUP_DELAY) +#define RF24_POWERUP_DELAY 5000 #endif /**********************/ From 7509052371b7e701d0ff9195e42569c41144bce7 Mon Sep 17 00:00:00 2001 From: Stephen Crane Date: Sat, 28 Nov 2020 09:16:18 +0000 Subject: [PATCH 8/8] update doc comment --- RF24_config.h | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/RF24_config.h b/RF24_config.h index 539e4d662..b142af195 100644 --- a/RF24_config.h +++ b/RF24_config.h @@ -25,7 +25,11 @@ //#define SPI_UART // Requires library from https://github.com/TMRh20/Sketches/tree/master/SPI_UART //#define SOFTSPI // Requires library from https://github.com/greiman/DigitalIO -/** User access to internally used delay time (in microseconds) during RF24::powerUp() */ +/** + * User access to internally used delay time (in microseconds) during RF24::powerUp() + * @warning This default value compensates for all supported hardware. Only adjust this if you + * know your radio's hardware is, in fact, genuine and reliable. + */ #if !defined(RF24_POWERUP_DELAY) #define RF24_POWERUP_DELAY 5000 #endif