nrf-hal
nrf-hal copied to clipboard
Implement a polling async SPI interface
Addresses a part of #128. The existing code was moved around and with an optimizing compiler I expect it to generate the same code as before.
There are also new polling versions of the transfer functions that don't block. The idea is that one could call these from interrupt handlers to get non-blocking/low power SPI transfers. The returned types intentionally don't implement core::future::Future
since that would require waker management.
See https://github.com/dflemstr/embedded-platform/tree/master/platforms/nrf52840 for higher-level async code that could be supported by this change.
Thank you for the pull request, @dflemstr! It seems that nobody (including me) has the time to look into it right now. Sorry!
Feel free to ping @nrf-rs/nrf52 and @nrf-rs/nrf91, to remind us, if you feel it's taken too long.
Pinging @nrf-rs/nrf52 and @nrf-rs/nrf91 :)
I couldn't find any place where this code calls set_low
on the chip select pin. Is that handled differently or is this missing?
I think this looks basically fine now. Have you tested this on real hardware?
I have tested it on a Particle Argon, but the SPI slave device (which is custom made...) has a few power glitches (even when using a different master device) so I would appreciate some secondary testing by someone with a more reliable SPI slave device
Isn't this API susceptible to the mem::forget
problem ? See https://docs.rust-embedded.org/embedonomicon/dma.html#memforget
@thalesfragoso how would you recommend that we fix it in this case?
Right now, I see two solutions:
-
'static
borrows, also explained in the embedonomicon: https://docs.rust-embedded.org/embedonomicon/dma.html#static-bound, you can see an example implementation here: https://github.com/stm32-rs/stm32f1xx-hal/blob/master/src/dma.rs (Pin
probably wasn't used because it wasn't stabilized back then). -
Using owning pointers, like this implementation: https://github.com/nrf-rs/nrf52-hal/pull/102, I also did an adaption of that to get rid of the size features, you can see it here: https://github.com/thalesfragoso/usbd-serial/blob/writer-impl/src/pool_serial.rs
@thalesfragoso @jonas-schievink as you might see from the PR metadata, I've decided to get some clarity around async HAL in https://github.com/rust-embedded/embedded-hal/pull/206 before I'd feel comfortable with picking a direction for how to continue this PR.