-
Notifications
You must be signed in to change notification settings - Fork 2.1k
sys/arduino: Added SPI interface #12118
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
Conversation
@maribu This PR is related to PR #10592 which
My PR is waiting since January for merge. Maybe we can help each other by reviewing both the PRs. |
@keestux, @gschorcht : I'd like to push this PR forward. Anything left to do on my side? |
One question left. Would it make sense to add |
Better: |
Yes. Very much. I think it is not possible to just do I would go the Using |
I just added the |
Yes of course, |
Would it possible to find a small Arduino library that uses SPI, for example a sensor driver, but has not be hacked to get it working in RIOT? Until now, we couldn't find an agreement in PR #12180 on how to deal with Arduino libraries which would make an import into RIOT much easier. |
I 'm interested to test the SPI interface with a small Arduino lib together with PR #12180. That might become the test for this PR. |
From my point of view, a good candidate for testing is a sensor for which we already have a driver, for example LIS3DH. I have this sensor and Adafruit provides a driver library including examples at GitHub. Since these kind of sensors always have I2C and SPI interface, the library supports both. I will and put together PR #12118, #10592 and #12180 and create a package tomorrow that can serve as test for these 3 PRs. Unfortunatly, it will not be possible to test them separately. |
@maribu Could you address the issue in static tests (Travis) in the meantime? |
BTW, I could already compile https://github.com/adafruit/Adafruit_L3GD20 successfully in that way. |
@maribu What about the functions
Although they are declared as deprecated, they are used by a number of existing Arduino libraries. I know, |
I have not yet implemented both bitorders. (I have never seen hardware seen using non-defauly bitorder.) I'm happy to add it similar to the configuration: Just asserting it to be the default bitorder and otherwise ignoring it. If someone reports to actually own and use a device with different bitorder, I'll do my best to add that feautre properly. But as far as I understand setClockDivider seems to be a archaic way of setting the SPI clock judging by its name without having checked the doc. I could check which value would translate to which SPI clock and simply use the closet SPI clock supported in RIOT. That way it would be hardware independent. I'm currently away from keyboard and don't what to check the API doc of setDataMode via smartphone. But I will do so soon and think that there will also be a reasonable way to provide that API. |
@maribu I get the following linking error on AVR platform when I try to compile an Arduino library:
Adding |
Now that I have looked into the details: It is not possible to integrate these into the current approach of the SPI interface. E.g. the Arudino SPI interface should be using by running SPI.begin()
SPI.beginTransaction(spi_settings);
// send and receive data via SPI
SPI.endTransaction(spi_settings);
// and optionally:
SPI.end(); It could however also be using like this: SPI.begin()
// send and receive data via SPI
// and optionally
SPI.end(); In the latter case the user is in charge to make sure that concurrent contexts do not access the SPI bus at the same time - which means two devices on the SPI bus can only be used, if both drivers use the transaction flavor of accessing the bus. Also, as Therefore, the current implementation just forces that So providing the deprecated API is currently not possible with this implementation. I could however change the approach like this:
It would be more overhead, but fully compatible. I assume you would prefer this approach? |
OK. |
I think it's better to leave the API as it is. Everything else could become too tricky. That's not worth it for old-style libraries. |
Hmm, I have completed the implementation by now. Only the issue with |
One problem I run into when I try to use https://github.com/adafruit/Adafruit_LIS3DH as test library is that the statement in the library
doesn't work correctly on ESP32. Although I believe that it is unrelated to this PR, it is pretty weird. In the
Any idea? Unfortunatly, I have no other platform, for which I could test it:
The only platform that I have which support all modules is ESP32 😟 |
OK. Now the legacy SPI interface should work as well, with the same conceptional bugs and hazards the real Arduino API has. (That is: When not surround transactions with |
@maribu Please squash. |
Done |
@maribu We should also remove Do you think that it would be possible to remove both items with your PR maybe as separate commits? Otherwise, I would have to provide a PR for only removing this one item. |
Done |
Thanks. |
Please fix the errors reported by Travis and squash afterwards. |
Added an Arduino compatible SPI API on top of RIOT's SPI API.
Arduino is always enabling C++11 support, so sketches and libs are depending on it. Every C++ compiler has been enabling C++11 by default for some years now. Still, Ubuntu's avr-gcc is so **horrible** out of date, that it is not enabled there. As a simple work around, -std=c++11 is now passed to the C++ compiler if Arduino is used.
The I2C (Wire) interface has been added, so it should no longer be listed on the ToDo list.
The SPI interface has been added, so it should no longer be listed on the ToDo list.
@maribu Thanks for providing the Arduino SPI library. |
Thanks for the review! |
Contribution description
Added an Arduino compatible SPI API on top of RIOT's SPI API.
Testing procedure
A student of mine had to use the MFRC522 RFID card reader, for which RIOT did not yet provide a driver. I hacked together this SPI API to allow using the Arduino driver, which however still needed some modifications to work (most notably: RIOT does not support storing
const char *
in the flash for non-von-Neumann architecture boards). This could be reproduced to test the driver, or any other Arudino library using SPI could be used.Issues/PRs references
None