-
Notifications
You must be signed in to change notification settings - Fork 232
spi: add Operation::DelayUs(u32). #462
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
Conversation
hmm, is this a similar problem to the need to be able to do weird acknowledgement things within a transaction (eh. send command, wait on pin assertion, fetch data)? iirc for those cases we'd recommend using the bus instead of the device abstraction (which works for most cases with the usual caveats related to manual CS with multiple apps sharing buses under linux) cc. @eldruin because we had a big chat about this recently |
Could there be SpiDevice implementations that can't support the delay operation? Perhaps there should be some documented best practice on how to react in that situation. For example:
With an |
a64dc24
to
3425ea7
Compare
Discussed in today's WG meeting (chatlog, minutes) Changed:
I haven't added |
52370a3
to
27824ec
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this might make embedded-hal-bus
unusable for linux-embedded-hal
(or any implementation which provides meaningful buffering of the SPI transfers).
While this would work for SpiDevice
implementations provided by l-e-h
, I think it would not work for its SpiBus
implementation, since delays there are appropriately marked transfers to the kernel and not something handled externally without SpiBus
knowing about it.
This means that when using e-h-b
on a l-e-h::SpiBus
, we are delaying in "program-defined time", not in "bus-transfer-defined time".
Depending on the internal queue fill-up status of the SPI handler in the kernel, we might delay for a shorter time than requested to, down to no delay at all.
However, I do not know how the linux kernel buffers SPI transfers, and if there is a queue at all, so somebody with knowledge of the matter should clarify.
Nevertheless, the same issue applies to any HAL implementation which provides some kind of buffering due to the fundamental time difference.
Good point about buffering/queueing. I've added (Note that supporting |
friendly ping @eldruin @ryankurte @therealprof |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Alright, I checked a bit over at l-e-h
and this seems fine although we would not be able to use the kernel API for the delay when using e-h-b
, but for that we would need to make the e-h::SpiBus
know about delays and that would further the impact of this special case, without a clear benefit. When absolutely needed, it would be possible to define a different implementation for e-h-b
. Let's get it merged.
Thank you!
bors r+
bors r+ |
depends on #461
There are SPI devices out there that need delays between transfers within a transaction. Not dummy bytes, SCK must be idle during the delay. And it must be a single transaction, CS must not be deasserted.
This is not doable with the new operation-list API (it was doable with the previous closure API).
Examples:
To support these, this adds a new
Operation::DelayUs(u32)
.Linux spidev can implement this fine, it supports delaying after each transfer.
The downside is that
SpiDevice
impls now need a time source. Discussed a bit in yesterday's WG meeting.I don't think separating the traits by capability is worth it, we end up with the same problem as with the read-only/write-only traits (#461)