embassy-rs / embassy

Modern embedded framework, using Rust and async.
https://embassy.dev
Apache License 2.0
5.15k stars 713 forks source link

stm32/i2cv2: remove blocking loops in async i2c. #2299

Open Dirbaio opened 8 months ago

Dirbaio commented 8 months ago

Async and blocking currently share some "setup" code. This setup code needs to wait for some things, for example here:

https://github.com/embassy-rs/embassy/blob/a2d4bab2f8a4a9b994bc0289938a9f725950715f/embassy-stm32/src/i2c/v2.rs#L164

This waiting is done blockingly, it should be done asynchronously in async code. This means we can share less code, but that's fine.

Once this is done, async timeouts should be simplified to using with_timeout at the top level, instead of passing a check_timeout closure through everywhere. This will ensure user timeouts also behave nicely when they use with_timeout themselves instead of using the builtin timeouts, or select.

shufps commented 7 months ago

Hi, this sounds very good.

I just wondered why everything is async on Embassy except the I2C :thinking: :man_shrugging:

Similar blocking loops seem to be in v1 (eg for the L1).