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

Library enhancement request #2013

Closed
oconnoda opened this issue Apr 14, 2014 · 4 comments
Closed

Library enhancement request #2013

oconnoda opened this issue Apr 14, 2014 · 4 comments

Comments

@oconnoda
Copy link

Please consider modifying the Ethernet and Wifi libraries (and others as appropriate) to set the SPCR to the required value in every entry point into the library that uses SPI. The SPCR could have changed value between calls to the library (e.g. the user has another device on the SPI bus). The current situation requires the user to read the library code to determine the required SPI settings and write code to set the SPCR prior to each call into the library. Its seems natural that the library should manage its own SPI settings.

@mikaelpatel
Copy link

This issue has been posted several times. Mainly due to backward compatibility it has been rejected.

The SPI interface in Arduino is poorly designed and has resulted in libraries not being able to be used together. A total redesign is needed. This is what I have done for Cosa; https://github.com/mikaelpatel/Cosa/blob/master/cores/cosa/Cosa/SPI.hh

The Cosa SPI class does the following;

  1. The SPI driver holds the necessary setting of the hardware module (SPI register setting).
  2. The SPI begin/end are used to assert the chip select (automatically).
  3. The SPI begin/end also handles mutual exclusion on the bus so that interrupts (from SPI devices) cannot occur during a transaction.
  4. And it is implemented for USI and works with the same interface on Tiny.

Please see the Cosa Ethernet Controller driver for W5100 for an example of usage; https://github.com/mikaelpatel/Cosa/blob/master/cores/cosa/Cosa/Socket/Driver/W5100.cpp#L53

Another example is the Cosa ST7735 262K Color Single-Chip TFT Controller.
https://github.com/mikaelpatel/Cosa/blob/master/cores/cosa/Cosa/Canvas/Driver/ST7735.cpp#L146

Please note that the Cosa SPI begin/end block allows three different type of chip select pulses; 1) assert low, 2) assert high, and 3) high pulse on end.

The last variant is used for shift-registers. Please see the Cosa shift-register 3-wire SPI LCD adapter for an example of this pulse(2) variant, https://github.com/mikaelpatel/Cosa/blob/master/cores/cosa/Cosa/LCD/Driver/HD44780_IO_SR3WSPI.cpp#L50
https://github.com/mikaelpatel/Cosa/blob/master/cores/cosa/Cosa/LCD/Driver/HD44780.hh#L521

@oconnoda
Copy link
Author

Mikael,

Thanks for your reply. The backward compatibility issue is not obvious. I am curious, can you explain? Thanks.

-Dave

On Apr 14, 2014, at 7:36 PM, Mikael Patel notifications@github.com wrote:

This issue has been posted several times. Mainly due to backward compatibility it has been rejected.

The SPI interface in Arduino is poorly designed and has resulted in libraries not being able to be used together. A total redesign is needed. This is what I have done for Cosa; https://github.com/mikaelpatel/Cosa/blob/master/cores/cosa/Cosa/SPI.hh

The Cosa SPI class does the following;

  1. The SPI driver holds the necessary setting of the hardware module (SPI register setting).
  2. The SPI begin/end are used to assert the chip select (automatically).
  3. The SPI begin/end also handles mutual exclusion on the bus so that interrupts (from SPI devices) cannot occur during a transaction.
  4. And it is implemented for USI and works with the same interface on Tiny.

Please see the Cosa Ethernet Controller driver for W5100 for an example of usage; https://github.com/mikaelpatel/Cosa/blob/master/cores/cosa/Cosa/Socket/Driver/W5100.cpp#L53

Another example is the Cosa ST7735 262K Color Single-Chip TFT Controller.
https://github.com/mikaelpatel/Cosa/blob/master/cores/cosa/Cosa/Canvas/Driver/ST7735.cpp#L146

Please note that the Cosa SPI begin/end block allows three different type of chip select pulses; 1) assert low, 2) assert high, and 3) high pulse on end.

The last variant is used for shift-registers. Please see the Cosa shift-register 3-wire SPI LCD adapter for an example of this pulse(2) variant, https://github.com/mikaelpatel/Cosa/blob/master/cores/cosa/Cosa/LCD/Driver/HD44780_IO_SR3WSPI.cpp#L50
https://github.com/mikaelpatel/Cosa/blob/master/cores/cosa/Cosa/LCD/Driver/HD44780.hh#L521


Reply to this email directly or view it on GitHub.

@mikaelpatel
Copy link

The optimum solution would be if this issue could be fixed without an impact on existing libraries that use SPI. Therefore backward compatibility.

It is all about how much effort the Arduino Team can put on the software platform. One must remember that Arduino as a product line only makes money on the boards sold. The software is all minimum effort, badly documented, poor performance, high complexity and low abstraction. And most of all hard to maintain.

The great thing about the Arduino is the community and the contributions. This is also the Achilles heel as libraries are often abandon by the authors. They do not make any money at all if they do not design and sell a piece of hardware. We need to remember that industry strength software (which we are all expecting) cost approx. $100 per line of code. That needs to cover design, test, documentation, etc.

Changing the SPI interface to something like what is available in Linux, Windows, RTOS, etc requires several hundred hours effort which basically the Arduino team does not have at their disposal. The SPI library change is actually not that large in lines of code but the ripple effect is.

Unfortunately this makes the issue more or less "dead in the water".

Right now the issue is also on the developers mailing list (again).

Cheers!

@agdl
Copy link
Member

agdl commented Nov 7, 2014

@mikaelpatel it was solved with SPI Transacion API!

@agdl agdl closed this as completed Nov 7, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants