nrf-rs / nrf-hal

A Rust HAL for the nRF family of devices
Apache License 2.0
499 stars 139 forks source link

Add is_done and try_wait methods to i2s::Transfer #412

Closed nospam2678 closed 1 year ago

nospam2678 commented 1 year ago

Wouldn't it be useful if being able to determine whether an I²S transfer has completed without busy looping?

The changes is this PR appears to be working for both wait() and try_wait(), but I must admit that the compiler fencing part flies a bit above my head even after refreshing myself on the topic. I'm actually preplexed of why it is needed in the first place. Is it to prevent buffer from being fetched for return prior to the loop being finished?

An implementation detail which might be questioned is whether is_done() is at all desired. My reasoning is that it reduces the code duplication slightly, and that adding it to the public api might be useful for someone. One could argue an extra function call adds overhead, but I am imagining the compiler would inline and optimize away such a tiny function.

jonas-schievink commented 1 year ago

Thanks, this looks good. I'm a bit uneasy about the unreachable_unchecked calls, I wish Rust allowed moving out of fields of a Drop type, but I guess there's little we can do.

bors r+

bors[bot] commented 1 year ago

Build succeeded: