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

SPI CS Traits / Implementations #180

Closed
ryankurte opened this issue Jan 21, 2020 · 3 comments
Closed

SPI CS Traits / Implementations #180

ryankurte opened this issue Jan 21, 2020 · 3 comments
Assignees

Comments

@ryankurte
Copy link
Contributor

At the moment we aren't super explicit about management of the chip select pin for SPI transactions, which means drivers have to either manage these themselves or make big assumptions about the underlying SPI implementation.

With #178 we have the ability to execute multiple operations in a single transaction which brings this to the forefront. (@jonas-schievink this is why I didn't call them Transaction because the whole thing is a bus transaction, whoops.)

To mitigate this, I'm proposing the addition of a ChipSelect marker trait for SPI devices that manage SPI themselves, As well as a wrapper object that takes an SPI object GPIO output and implements ChipSelect to simplify the use of devices with manual CS management.

A downside of this is that we now need to return distinct types where ChipSelect or !ChipSelect in cases where either is possible, for example, the linux embedded hal driver may have CS managed automatically or be used with manual CS management. This could be mitigated by splitting the constructors for no_cs and with_cs versions, however, will be required for many SPI devices.

@ryankurte ryankurte self-assigned this Jan 21, 2020
@thejpster
Copy link
Contributor

How would it work with multiple chip selects? Would you have multiple wrappers sharing the same SPI driver object (in some kind of Cell wrapper) each with a unique GPIO?

@ryankurte
Copy link
Contributor Author

Yeah good question, depends on the implementation (Linux you could just create multiple devices /dev/spidev0.N and leave them to manage CS themselves), but in the more embedded case i think shared-bus could be extended to do the job as you describe.

This is not quite as trivial as using a shared-bus object in the proposed wrapper as you really need to take ownership of the bus before asserting CS, so shared-bus or similar would need to be extended with support for all the CS stuff.

There's also a related issue in shared-bus Rahix/shared-bus#8 discussing this exact problem.

ryankurte added a commit to ryankurte/embedded-hal that referenced this issue Aug 29, 2020
ryankurte added a commit to ryankurte/embedded-hal that referenced this issue Jul 24, 2021
Co-authored-by: Diego Barrios Romero <eldruin@gmail.com>
ryankurte added a commit to ryankurte/embedded-hal that referenced this issue Jul 24, 2021
Co-authored-by: Diego Barrios Romero <eldruin@gmail.com>
ryankurte added a commit to ryankurte/embedded-hal that referenced this issue Jul 24, 2021
Co-authored-by: Diego Barrios Romero <eldruin@gmail.com>
ryankurte added a commit to ryankurte/embedded-hal that referenced this issue Jul 24, 2021
Co-authored-by: Diego Barrios Romero <eldruin@gmail.com>
@Dirbaio
Copy link
Member

Dirbaio commented Apr 28, 2023

Solved in #351, #444

@Dirbaio Dirbaio closed this as completed Apr 28, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants