Skip to content
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

embedded-hal-bus does not impliment embedded-hal-async traits, despite claiming to #572

Open
Sycrosity opened this issue Jan 22, 2024 · 5 comments

Comments

@Sycrosity
Copy link

Despite it being stated that the async feature "enables embedded-hal-async support", there is no code implementation of this. Async shared busses would be very useful, especially for crates which only support the embedded-hal-async I2C traits, to be able to safely share i2c busses over.

@Dirbaio
Copy link
Member

Dirbaio commented Jan 22, 2024

There's one for ExclusiveDevice.

The problem with async shared buses is there's no "standard" async mutex, so it's left for crates from the ecosystem for now. For example there's embassy-embedded-hal containing impls using embassy-sync's async Mutex.

@Sycrosity
Copy link
Author

Sycrosity commented Jan 22, 2024

There's one for ExclusiveDevice.

That slipped past me, there indeed is - however there isn't any for I2C.

The problem with async shared buses is there's no "standard" async mutex, so it's left for crates from the ecosystem for now. For example there's embassy-embedded-hal containing impls using embassy-sync's async Mutex.

That seemed to be the issue when and around searching this issue - do you know of an example of a project using embedded asynchronous shared mutex's? Thank you for the links, I will investigate further into these.

@liarokapisv
Copy link

Does the above have implications for the async implementation of the RefCellDevice ?

@Dirbaio
Copy link
Member

Dirbaio commented Apr 10, 2024

RefCell is not async, so RefCellDevice can't implement the async traits. if it did you'd get BorrowMutErrors if you tried to use it from several tasks at the same time.

if you want async shared SpiDevice, use embassy-embedded-hal, which implements it using embassy-sync's async Mutex, which allows sharing between async tasks properly.

@liarokapisv
Copy link

liarokapisv commented Apr 10, 2024

RefCellDevice is useful even if only used by a single task. Eg you could implement a fair round-robin scheduler for the different devices in a single task. We still have the advantages of async like being composable with other tasks and consuming less processor time by taking advantage of dma without needing large sync primitives. It also helps reusing async drivers.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants