-
Notifications
You must be signed in to change notification settings - Fork 34
Description
SPI uses chip select lines to select which chip to talk to but this crate only synchronizes the SPI data transaction itself, not the chip select lines, so there's a possible race condition where a transaction occurs with multiple chip select lines asserted. I was bitten by this in an actual project, and had to revert to manually synchronizing everything.
The way to do chip select lines with embedded-hal
seems to be to just pass them to drivers separately from the SPI peripheral, so there is no real way to synchronize access via just the SPI trait. The only idea I had was to add a method like BusManager::acquire_spi(cs_pin)
which takes ownership of the chip select OutputPin
, and returns you both a BusProxy
as well as a wrapper for the chip select pin, and the wrapper actually does the locking (lock when chip select is asserted). This sounds incredibly hacky though, and I think the correct solution would be to expand the embedded-hal
SPI traits to include chip select support. I think some peripherals with hardware chip selects might benefit from it anyways.