Add support for async polling #11
Conversation
f3fa8e1 to
860afe4
Compare
|
@leighleighleigh thanks! I'll try to give this a review this weekend. |
|
FWIW I just tested this on real hardware, and |
|
The approach using |
There was a problem hiding this comment.
Thanks for this great contribution! 🙇
Thanks for the handy crate!
Glad you find it useful! 🥳
Looking at the CLI failures it looks like the next steps to get the PR ready for merging are:
-
Resolve change requests.
-
Fix formatting by running
cargo fmt. -
Remove stray
quadrature-encoder/src/main.rsfile. -
Add a section on async usage to
quadrature-encoder/README.mdfile. -
Add entry to
CHANGELOG.mdfile:## [Unreleased] ### Added - Added support for async-await (via optional `async` crate feature): - Added `async fn poll_async()` method to `IncrementalEncoder<…>`. - Added `async fn poll_async()` method to `IndexedIncrementalEncoder<…>`.
|
@leighleighleigh lemme know if I should take it from here or if you want to do it yourself. |
|
I have updated the original description - apologies for the delay, I've been AFK. I've also got a full |
async polling
…ing for specific rising/falling edges.
… Made 'async' features additive, opt-out if desired. Improved examples to demonstrate ehal v0.2 usage.
d89c129 to
6d3a242
Compare
6d3a242 to
574e3dd
Compare
No worries! I just wanted to make sure you weren't waiting on me for a release with your features.
I like the FYI: I've just rebased the branch onto I'll wait for CI to pass, merge it and release a
👨🏻🍳👌🏻 That looks like a nice improvement to |
c725f35 to
a0d7723
Compare
|
Awesome, thanks! |
|
I just published Thanks for this great contribution! 🙏 |
This PR adds a few useful feature flags, resulting from my own usage with the atsamd HAL, which has a mix of
embedded-halv0.2.7andv1.0.0scattered throughout.Original PR text, relevant to first commit only.
At a high level, the
eh1andeh0features simply change the trait requirement for the encoder pins - usingInputPin, but from different versions of theembedded-halcrate.eh1uses v1.0.0,eh0uses v0.2.7.The
asyncfeature adds theWaittrait requirement to the encoder pins, and enables a newpoll_asyncfunction.This function
select()s thewait_for_any_edge()function on each pin, until an edge is detected, then calls the regularpoll()function. I haven't tested thispoll_async()on any hardware yet - I shall do so in the next 24 hours.I've added a few new dependencies, most are fairly self-explanatory. I chose to use
embassy-futuresinstead of the regularfuturescrate because of it's niceselect3function, and the crate has no further dependencies of it's own, so felt safe.Thanks for the handy crate!
Updated Description
...updated on epoch 1737691201.
After a bit of testing in the wild, I realized that my approach to both
asyncandeh0/eh1compatibility had a couple fatal flaws:InputPintrait was affected by the feature flags in use.eh0-compatibility 'from inside the library'. Even though it's 'ugly', I think it's better to rely on a user-wrappedForward<Pin>from theembedded-hal-compatcrate instead. I've addedrotary_eh0andlinear_eh0examples that demonstrates this (although there is probably no need to have both).#[cfg(feature = XYZ)]around resulted in non-additive features, and it was a bit ugly.poll()topoll_async(), which is an admittedly a minor change, but one that is inconsistent with how async rust is usually done.To address these shortcomings, I've opted to create an empty
PollModemarker trait, akin to theDriverModetrait in projects such asesp-hal's peripheral drivers. This allows for unique implementations ofpoll()function, depending on this mode, which can be eitherBlockingorAsync. Common logic for each implementation (updating theDecoder) has been moved to a private methodupdate().Apologies for hacking on this existing PR - it was a bit more of a WIP than I expected.