-
Notifications
You must be signed in to change notification settings - Fork 1k
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
Added compatibility for RFM7X and bk242x-style nRF24 clones including… #754
Conversation
This looks like a copy and paste job. You should be more mindful of putting other people's names on your work. That lib you copied from uses MIT license, but this lib uses GNU license (there's a subtle difference), so an MIT license might be required to be added. Are you willing to keep maintaining this extra support? Because this is probably going to require your help to troubleshoot in the future. We don't own any of these modules to verify this work. |
The important part are the changes to RF24.cpp. The MIT license is the most open license and allows practically everything. Plus I referenced this code in both the example and in the RF24_config. The example code only contains the properly configured library and the calls to it. Since I have personal interest in this feature, I can maintain it. The important changes are rather small though (hard to find nonetheless). @Avamander stated in an old Issue in RF24Mesh that he liked support for these modules |
That's good news. I'm just trying to avoid disappointing someone that might need help. @Avamander would never turn down support for more devices. Ever. I will leave a review when I get the time to look through it all. |
Great! I'll wait until this is merged and then add the changes to RF24Network as well |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You still have a lot of work to do here. Remember that the RF24 library supports all/various Arduino platforms (not just ARDUINO_ARCH_AVR
) and Linux platforms.
So Far, this PR doesn't add support for the RFM7x and bk252x radio modules. Rather this PR simply patches the config file for compatibility with a dependent library that isn't able to install in the Arduino IDE (nor PlatformIO); the other library needs to exist in the sketch folder like you've done in the new example here.
@@ -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 | |||
|
|||
//This introduces some changes to make the library work with RFM73/75 and other bk242x derivates. See examples/rfm7xAndBk242xCompatiblity | |||
//Those modules require additional initialization which can be done with https://github.com/jnk0le/RFM7x-lib | |||
//#define RF24_COMPATIBILITY_MODE_FOR_RFM7X_BK242X |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would prefer to use RF24_FOR_RFM7X_BK242X
as the macro name. I know some would prefer wordiness, but think of the beginners who would have to memorize and declare this in their project.
@@ -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 | |||
|
|||
//This introduces some changes to make the library work with RFM73/75 and other bk242x derivates. See examples/rfm7xAndBk242xCompatiblity | |||
//Those modules require additional initialization which can be done with https://github.com/jnk0le/RFM7x-lib |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If this PR still requires the RFM7x lib then it should be listed as a dependency, but RFM7X is not able to install in the Arduino IDE (nor its Library Manager).
If the RFM7X lib is just a reference to originating work, then this needs to be re-worded to avoid confusion.
#include "RF24.h" | ||
|
||
// See https://github.com/jnk0le/RFM7x-lib | ||
#include "rfm7x.h" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This include should be automatically done in RF24_config.h using #if defined (RF24_FOR_RFM7X_BK252X
.
The rest of this example is identical to GettingStarted.ino (excluding my comment about the init code in setup()
). Any radio module that's supported should not be limited to 1 example. Have you tested the other examples to see if they're all as compatible as this is?
I re-wrote and simplified all the examples to avoid having too many examples to maintain. If we change anything to GettingStarted, then we'd also have to go into this example and make the same changes. Copy-n-Paste skills or no, our time is worth more than that. Allowing this example is asking for other contributors to submit their own circumstantial code examples (its a snowball effect).
@@ -0,0 +1,499 @@ | |||
#ifndef RFM7X_CONFIG_H_ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No license nor authorship. Also this file won't be available in the docs (we use Doxygen to generate the docs), this missing comment block also needs a @file
command.
Much of the rest of this file isn't necessary if the libraries are combined properly.
rfm7x_io_init(); | ||
spi_init(); | ||
if (rfm7x_is_present()) { | ||
Serial.println("RFM7X connected, initializing"); | ||
//this code initializes the required registers for the clones. Especially bank1 | ||
rfm7x_init(); | ||
delay(2); | ||
rfm7x_toggle_reg4(); | ||
delay(1); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- This code should reside in
RF24::begin()
. Since its use is conditional to theRF24_FOR_RFM7X_BK242X
macro, the code should be encapsulated in#if defined (RF24_FOR_RFM7X_BK242X) if (rfm7x_is_present()) { IF_SERIAL_DEBUG(printf_P(PSTR("RFM7X connected, initializing\r\n"))); //this code initializes the required registers for the clones. Especially bank1 rfm7x_init(); delay(2); rfm7x_toggle_reg4(); delay(1); } #else // !defined (RF24_FOR_RFM7X_BK242X)
rfm7x_io_init()
andspi_init()
should also be consolidated intoRF24::begin()
. Please try to find a way that these libraries could be better combined. Otherwise, I suggest you simply submit a link (that we could add to the docs homepage) to a (your) personal repo that demonstrates using both libraries independently.
@@ -0,0 +1,65 @@ | |||
#ifndef RFM7X_HARDWARE_H_ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No license nor authorship. Also this file won't be available in the docs (we use Doxygen to generate the docs), this missing comment block also needs a @file
command.
Much of the rest of this file isn't necessary if the libraries are combined properly.
//Compiler : GCC | ||
//Author : [email protected] | ||
// https://github.com/jnk0le | ||
//License : MIT |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is why we need a copy of the MIT License. I quote directly from the license aggreement:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
//************************************************************** | ||
//Compiler : GCC | ||
//Author : [email protected] | ||
// https://github.com/jnk0le |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did you adapt this or are you deflecting ownership?
|
||
/************************************************************************************ | ||
Author: [email protected] | ||
https://github.com/jnk0le |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did you adapt this or are you deflecting ownership?
/************************************************************************************ | ||
Author: [email protected] | ||
https://github.com/jnk0le | ||
This library is distributed under MIT license terms |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No it is not; not in the current state of this PR
Sorry but thats nonsense... The fix for compatibility is done in RF24.cpp as I already stated. https://github.com/jnk0le/RFM7x-lib/blob/master/examples/Arduino%20workaround/RF24.ino btw also references to RF24 as an example. The initialization procedure that is additionally required could be added to RF24, but I don't see the point in doing so. We can leave out the whole example code and just use the fix in RF24.cpp... |
from the comment you linked: This library is based on ManiacBug's work, but his library only supported Arduino platforms (nor did it support PlatformIO) .
That would be more acceptable if you don't want to distill the necessary parts from RFM7x lib into the RF24 class. But to be clear, that doesn't provide automatic support for RFM7x/bk252x radio modules, rather it allows the use of the RFM7x lib as a local-only dependency to provide support for those radios. |
I think that's the best solution and when somebody want's to enable support they find the info that additional initialization is required with a link to RFM7x-lib. And as I stated, I don't have any issues regarding the ACK/noACK-bit that jnk0le mentions... |
The docs could use some explanation how to use the RFM7x lib as a dependency. That way we have a reference to link to instead C-n-P the info on a per-issue/question basis. As for RF24Network, please tag this PR when you're ready |
Its possible that the RFM7x lib disables the auto-ack feature to avoid that problem. Which is why so many uninformed people suggest disabling auto-ack when troubleshooting for possible clones/counterfeits. |
@microtronics you are going to hate me. After looking into the source code for the RFM7x lib, I've found that using it as a dependency will ignore (and make this RF24 lib look like it's broken for) newer features implemented in this RF24 lib (since its ManiacBug days) - namely:
For these reasons, I would prefer to have a more native solution to support the RFM7x radios. To save memory (storing the BANK1 register's mandatory values), we can use a macro to enable RFM7x/bk242x support. @Avamander @TMRh20 Need a second opinion before I do the asshole thing and just close this. |
@2bndy5 IMHO I pretty much agree with your assessment. Supporting clones is one thing when it is a matter of adding a define or a line or two of code, but with all that this requires, I would suggest a separate fork of RF24 or a lib dedicated to these clones. We could then link to it from the documentation. I think the best advice is to avoid these clones altogether. |
I would say there are simple solutions, but whatever... I'll just keep the fixes to myself... |
@microtronics Sometimes the simplest solutions aren't the most sustainable. Sorry this didn't work out, but I'm still willing to add to the documentation so others can still benefit from your solution. Are you willing to submit a step-by-step rfm7x.md file written in markdown? It would need to be in the root folder of this repo, and don't worry about syntax (I'm willing to address that if needed). |
You guys seem to mix things up... First of all the RFM7X are not clones but rather counterfeits. All channels, auto-ack and so on do work and they work even together with genuine nRF24l01+ The steps required are literally:
I'd say it's a totally viable solution to leave Bank1 init to the users who want to use these modules and even if not, the init code could be added to RF24... |
because you want us to distribute someone else's work without proper Licensing (we've been over that) If step 2 was so simple, then why pack it into a full fledged example? A code snippet in a step-by-step tutorial would have been better (that way we're not distributing the code from someone else's library).
The words "clones" and "counterfeits" are often used interchangeably in these issues, so we've stopped caring about that semantic.
have you verified that? even the comments from the RFM7x lib say that they have a specific range.
that's what I thought this PR was doing, but you went with just copying and pasting the entire RFM7x lib instead of actually using the SPI functions in our library. BTW, its easier said than done... (please prove me wrong). |
As I said, we can just drop the whole example...
Of course, why would I say it otherwise. And btw also RFM7x-lib states:
Most things are easier said than done, but still it's no big deal. I did that initialization manually on my old PIC-micros for AC-dimming |
this sounds like something in BANK1 needs tweaking
does that mean we can expect a PR with a more native solution? |
no, it doesn't...
I don't know... I'd still say that this is easier done by using a library that already does this kind of work (why reinvent the wheel?). Guess I'll get back to work on my dissertation |
Well, that was intended as a quick hack to slap onto existing arduino codebase in case of rogue supply chains etc. IIRC, at some point I tried to update this to a more maintaied fork, but it wasn't gonna work without modifying innerworkings of that lib, so gave up quickly. It was probably related to "protected" retransmit counter or something else that could make an infinite loop. Licensing issues should be fixed by this commit:
It's not disabling but inverting it (as I think it is). One of the bank 1 register has a field documented as :
which should control the inversion of noACK bit. Selectable by RFM73_CONFIG_COMPATIBLE_MODE in config header. I have cross checked that with an NRF24l01+ from aliexpress which I assumed was an SI24R1 due to instability under default PA setting for genuine nRF, corresponding to +4 or +7dBm on SI. Other module with RFX2401 was especially unstable at those +4/+7dBm, similarly bk2425 at +4dBm couldn't transmit through its RFX2401 at all (-1dBm was fine) In yes-ACK comm, RFM with static compatible mode can't talk to the one set with dynamic compatible and vice versa. To talk to SI24R1, it requires static compatible mode set up. |
@jnk0le Thanks for the feedback (especially regarding the License question)! It would be easier to integrate your lib if
Otherwise, we'd have to copy the source and modify it (like what was done here, but a as a library instead of as an example application). As for the NOACK inversion, I see that register in the RFM73 datasheet at offset 0x0C in bank 0. Ideally, this RF24 lib would use the RFM7x lib for init only, so I think the
This is one of the reasons that the RF24 lib doesn't auto-enable the use of the NOACK flag by default. This is controlled by However, I'm not sure if changing anything in bank 1 would require a re-init for bank 0 registers (which would further complicate the existing RF24 codebase). Its been a while since I read any of the datasheets in your RFM7x lib. I would love to continue this discussion in #776 now that you've taken some interest. I'm kinda flattered that you commented on this because your work/research has been invaluable to RF24 for numerous reasons. |
Critical configuration done by modifying definitions in one file and SPI/IO by modifying 2 other files. I would say that this is not usable as an arduino lib.
|
See #753