jfpoilpret / fast-arduino-lib

C++ platform to build Arduino and AVR projects. Rationale is size and speed optimization.
GNU Lesser General Public License v2.1
60 stars 9 forks source link

Allow SPI to work without a CS pin #113

Closed jfpoilpret closed 1 year ago

jfpoilpret commented 1 year ago

In many boards, one may use a single SPI device for which there is no need for a specific CS "Chip Select" pin, as this could be directly forced on the device to the proper level (generally GND).

Currently, FastArduino SPIDevice class, the base of all SPI devices, requires the following template arguments:

FastArduino SPIDevice class should make these arguments optional and perform CS pin management only when one CS pin is provided.

One easy way to handle this improvement, without a deep redesign of SPIDevice class and all current subclasses implemented in FastArduino or outside, would be to:

In the best case, SPI would not need to be changed as gpio namespace already handles NONE pins by providing empty methods for everything.

jfpoilpret commented 1 year ago

As expected initially, FastArduino SPIDevice can work out of the box without the need of a CS pin. You just pass DigitalPin::NONE for CS and that's it! You should then be able to handle a single SPI device, provided its CS pin is forced to GND.

However, do perform some experiments to ensure your SPI device does support this way of working, with an always-0 CS pin. It seems some devices do not work properly with such wiring!

I will close this issue as there is nothing to do, besides updating SPIDevice API doc a little bit.

jfpoilpret commented 1 year ago

No need for a fix. Doc updated on master in commit #f3a571d