Skip to content
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

[Question] Why is SPI included in this lib? #572

Closed
bertmelis opened this issue Feb 19, 2020 · 8 comments · Fixed by #646
Closed

[Question] Why is SPI included in this lib? #572

bertmelis opened this issue Feb 19, 2020 · 8 comments · Fixed by #646

Comments

@bertmelis
Copy link

Why is there a "custom" SPI class included in this lib?

I'm using this lib on an ATtiny85 and in the Arduino framework (https://github.com/SpenceKonde/ATTinyCore) there is a lib available. Furthermore, when using other libraries that use SPI (like a BME280), there's no other way to adapt this library and use the framework's lib. Otherwise you get redefinition errors.

@Avamander
Copy link
Member

I didn't write the initial support for ATTiny so I don't know exactly, but I suspect SPI didn't properly exist in ATTiny board cores. If there's a way now to detect ATTinycore that has proper SPI then a preprocessor directive can probably be added. Pull requests are welcome.

@jscrane
Copy link
Contributor

jscrane commented Feb 21, 2020

Maybe something like this? (This works but is pretty nasty.)

diff --git a/utility/ATTiny/RF24_arch_config.h b/utility/ATTiny/RF24_arch_config.h
index dc5b0aa..635874f 100644
--- a/utility/ATTiny/RF24_arch_config.h
+++ b/utility/ATTiny/RF24_arch_config.h
@@ -9,6 +9,7 @@
 /*** USER DEFINES:  ***/
 //#define FAILURE_HANDLING
 //#define MINIMAL
+//#define CORE_HAS_SPI
 /**********************/
 
 #define rf24_max(a, b) (a>b?a:b)
@@ -24,9 +25,12 @@
 
 #include <stddef.h>
 
+#ifndef CORE_HAS_SPI
 // Include the header file for SPI functions ( Main SPI code is contained in RF24.cpp for simplicity )
 #include "spi.h"
-
+#else
+#include <SPI.h>
+#endif
 #define _SPI SPI
 
 #ifdef SERIAL_DEBUG

@Avamander
Copy link
Member

@jscrane
It's not nasty if it's almost the only working way, I checked if SPI_HAS_TRANSACTIONS or SPI_ATOMIC_FIX could be used instead but the ATTinyCore has those defined even on versions where the SPI library doesn't even compile (according to git commit description).

Maybe ATTinyCore people could be nicely asked to define a version number somewhere, then RF24 could check for that?

@TMRh20
Copy link
Member

TMRh20 commented Aug 19, 2020

Lets admit, its kind of nasty. lol

Being the party responsible for adding the SPI code in for ATTiny, (stolen from @jscrane ) if I remember... I felt the need to chime in here. Anyway, I think its about time we just removed ATTiny SPI support from RF24 altogether. It was added in prior because there was not much for alternatives.

Now that the ATTiny core has it included, I don't see any reason why we should maintain SPI support for ATTiny SPI here, probably just adds more confusion than anything.

So, if this seems like a good idea and anybody gets a chance, I think the changes required are pretty straightforward, mostly just delete a bunch of stuff from RF24, and test with the examples etc to ensure functionality. I probably won't have a chance to do it for a while.

@bertmelis
Copy link
Author

I totally forgot about this issue. (because my ATTiny runs without any problem on a battery using SPI for 6+ months now).

Now, what I did to make my ATTiny code to compile was to comment out the #include to the SPI header in this lib. Otherwise it wouldn't compile because the core and this lib both define SPI. I've already looked into the SPI code itself and as far as I can see it's the same.

I've only looked to ATTiny85.

@Avamander
Copy link
Member

I added this to the Hacktoberfest list of potential contributions.

The only thing expected is that someone removes the ATTiny-specific SPI workarounds from the library and tests on a physical device that it works with ATTiny core on at least two ATTiny's.

If someone has any other ideas, requirements or suggestions to this request, leave them below.

@2bndy5
Copy link
Member

2bndy5 commented Sep 19, 2020

I have been putting off wiring up 3V regulators, but I have a digispark board (ATTiny85) that I can test changes on. I'm assuming the 3-wire hack wouldn't be affected.

@jscrane
Copy link
Contributor

jscrane commented Sep 19, 2020

I have some Tinysensors with ATtiny84 I can test on too if that helps...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants