-
Notifications
You must be signed in to change notification settings - Fork 34
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
Add ADC proxy #24
Add ADC proxy #24
Conversation
Hi, thanks a lot for the PR! In general this is a good and useful idea. However I see a problem with the The In the context of
I think Now, all hope is not lost, I see a few possible solutions. First of all, I want to observe that actually a lot of HALs don't even implement So what we can do is, just like the HALs, we break the non-blocking contract of the trait and actually just busy-spin until a sample is returned. In practice this would mean changing the proxy implementation to the following: fn read(&mut self, pin: &mut Pin) -> nb::Result<Word, Self::Error> {
self.mutex.lock(|bus| nb::block!(bus.read(pin)))
} For the above-mentioned "blocking HALs", this would behave exactly the same, but for the non-blocking HALs which implement Of course this is kind of a hack - I think the better approach here would be to change |
Add support for ADC proxy. Note that OneShot trait describes a non-blocking contract for ADC read operation. However access to shared ADC unit can not be arbitrated in a completely non-blocking and concurrent way. Any reading from a channel shall be completed before `shared-bus` can allow next reading from the same or another channel. So suggested implementation breaks the non-blocking contract of the trait and just busy-spins until a sample is returned. Apparently this is kind of a hack. Possible better approach here would be to change embedded-hal to have an explicitly blocking OneShot trait instead and then make shared-bus work on top of that. Meanwhile it worth mentioning that a lot of HALs do not implement ADC traits in a non-blocking way. For instance, quite a few stm32 HALs actually block until the reading is completed. The list of such HALs includes stm32f0xx-hal, stm32f1xx-hal, stm32f4xx-hal to name a few. Signed-off-by: Sergey Matyukevich <geomatsi@gmail.com>
Hello @Rahix Thanks for careful review. I force-pushed PR after introducing the changes according to your review comments. One minor change was proper error type mapping of the blocking wait result. ADC blocking behavior has been documented in both documentation block to Regards, |
Hi @Rahix Do you plan to merge this PR in its current form ? Let me know if you have any other concerns. Regards, |
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.
Hi,
yes, sorry for the silence. One note for the future: The place where you documented the implementation details (on the read()
method inside the trait impl) makes them almost invisible in the documentation. I'll move it to the AdcProxy
struct documentation, so you don't have to worry about it :)
Thanks again for the PR!
Great to see this is already implemented here. Needed this feat, and rust analyzer pointed me out that shared bus is already implementing the One remark though: maybe call out in this projects' |
Done! |
You're da man! 🎉 |
Hi,
This PR adds new proxy type for sharing access to ADC hardware block. The
AdcProxy
implementsOneShot
trait so it can be passed to drivers instead of ADC instance. PR also includes some tests for the new proxy type based onembedded-hal-mock
.Regards,
Sergey