rust-embedded / rust-embedded/linux-embedded-hal
SPI struct implements both SpiBus and SpiDevice
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 319
- Forks
- 60
- Avg merge
- 12h 31m
- Merged PRs (30d)
- 1
Description
Currently our Spidev wrapper struct implements both SpiBus and SpiDevice from embedded-hal. I think this is likely to lead to some confusion, especially since the SpiBus methods will still actually be using a shared SPI bus, toggling CS, and multiplexing with any other spidev devices on the same bus.
We discussed this a bit in #87 and while the main problem there is resolved by the new embedded-hal design, I think the split suggested is still worth considering. The proposal is to have two wrapper structs, SpidevBus and SpidevDevice perhaps, where:
SpidevBusimplements just theSpiBustrait- we configure
spidevto not drive the associated CS pin - we explain in the documentation that when this struct is used, it must be the only active
spidevdevice on that bus - we encourage users to give it a CS pin that is not connected to anything, since whatever pin is assigned to it in the device tree can't be re-used as GPIO (and therefore can't be used as a CS)
- this struct can then be used with any of the bus-multiplexing crates (like embedded-hal-bus) to generate lots of
SpiDeviceobjects, using generic GPIO for CS control, or used when dedicated bus access is required (eg to generate smart LED waveforms) - we are basically lying to the kernel about it being a single device, because there's no way to request exclusive bus access with
spidev
- we configure
SpidevDeviceimplements just theSpiDevicetrait- it's already a perfect fit for
SpiDevice, the kernel handles sharing and CS for us, even with other programs - it will work just as users expect
- but their device tree has to be set up to create the device and use the right CS
- it's already a perfect fit for
I'm happy to implement this as a PR if it sounds good to people, but it'd be great to get some feedback first or any suggestions on how it might be better done, especially if there's any clever spidev-related tricks that might be useful.
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reviewing the current Spidev wrapper and the embedded-hal SpiBus and SpiDevice implementations, along with the discussion in issue #87. Evaluate splitting the wrapper into SpidevBus and SpidevDevice, including the proposed chip-select and bus-sharing behavior. Done means the API separation and its documentation clearly match the intended kernel and bus-multiplexing semantics.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- linux, rust
- Domain
- embedded-iot, operating-systems
- Issue type
- Refactor
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 25/100