-
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
[Request] allow non-default SPI bus by overloading begin() #743
Comments
Nice, can we make it default to a specific SPI bus?
|
I should test it, but that idea might make the overloaded I just was going for something most compatible with the existing code. UPDATE: As I suspected, gettingStarted.ino doesn't compile when the Its worth noting that the SPI access now looks like the following for when #else // !defined(RF24_LINUX)
beginTransaction();
#if defined (XMEGA_D3)
// using _SPI as an object
status = _SPI.transfer(R_RX_PAYLOAD);
while (data_len--) { *current++ = _SPI.transfer(0xFF); }
while (blank_len--) { _SPI.transfer(0xff); }
#else // !defined(XMEGA_D3)
// using _SPI as an datatype pointer
status = _spi->transfer(R_RX_PAYLOAD);
while (data_len--) { *current++ = _spi->transfer(0xFF); }
while (blank_len--) { _spi->transfer(0xff); }
#endif // !defined(XMEGA_D3)
endTransaction();
#endif // !defined(RF24_LINUX) and inline void RF24::endTransaction()
{
csn(HIGH);
#if defined(RF24_SPI_TRANSACTIONS)
#if defined(RF24_RPi)
_SPI.endTransaction();
#else // !defined(RF24_RPi)
_spi->endTransaction();
#endif // !defined(RF24_RPi)
#endif // defined (RF24_SPI_TRANSACTIONS)
} |
There are still some things that I really need to discuss:
p.s. I had to define a macro called |
|
@TMRh20 thanks for this vital info About 2: Looks like the ATxmega64D3 has 5 SPI buses to expose, but I'm still unsure if boards using this chip actual expose more than 1 SPI bus to the broken-out pins. Probably best to extend this feature to the ATxmega64D3 for completeness (and it would simplify the code I sampled above). About 3: I think if I just add |
Looking further into esp32 and esp8266, I'm finding it may be necessary to allow the user to call This might also support some bitbanging SPI implementations that would be specific to certain Arduino cores (as opposed to the limited SoftSPI implementation from the frozen DigitalIO lib). |
I think my overload-begin branch is ready for testing. I've modified support for Due, ATxmega64D3, Teensy, and all AVR (including SoftSPI implementation). Platform support that hasn't been modified includes anything Linux, ATTiny, LittleWire, and the SPI_UART implementation. SPI object's
|
I had to add a new CI to test the teensy platform against the RF24 examples using PlatformIO because the TeesnyCore for the Arduino IDE isn't CLI friendly... It seems to complete faster than the Arduino CI we're already using, but that may change if I add more boards like the STM32 family. |
Overload
begin()
for the Arduino platform onlyUsing a secondary (non-default) SPI bus with the RF24 lib has been a frequently requested feature lately. Demand for this will likely only increase with newer MCUs (that expose more than 1 SPI bus to the GPIO pins). Again this will only apply to the Arduino platform since the Linux platform already offers multiple SPI bus options via the SPIDEV or BCM283x drivers.
Solution
_SPI
into a pointer, and set it to the defaultSPI
object that the lib currently uses.RF24::begin()
with_SPI.func_name()
to_spi->func_name()
. I inadvertently made this easier by consolidating the SPI bus access functions back in new examples and more #691Alternative Ideas
I can't really think of any alternative implementations that wouldn't be over-complicated. The solution above is a pretty standard way that many libraries use.
I don't want to use the hack proposed in #722 for compatibility with the existing alternative SPI implementations (see below in "Additional context").
Additional context
I want to maintain compatibility with the existing alternative SPI implementations, namely
SoftSPI
andSPI_UART
. The real challenge will be sifting through the#ifdef
soup and only changing the_SPI
when!defined(RF24_LINUX) && defined(RF24_SPI_TRANSACTIONS)
(or something similar) 😰.I also want to satisfy #539 in a similar overloaded
begin(ce_pin, csn_pin)
, but that's still on the back burner (for now).The text was updated successfully, but these errors were encountered: