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

Add embedded-hal-async support #7

Merged
merged 9 commits into from
Mar 1, 2025

Conversation

hawkw
Copy link
Contributor

@hawkw hawkw commented Jun 9, 2024

This commit adds support for the embedded-hal-async crate in addition
to embedded-hal. I've done this by adding a separate AsyncSht4x
type, based on the assumption that most projects won't need to use both
the blocking embedded-hal traits and the embedded-hal-async traits
at the same time, and providing async fn methods on a separate type
with the same names as the blocking ones seemed a bit nicer than having
one type that has both fn measure and async fn measure_async and so
on.

Support for embedded-hal-async is gated behind the
embedded-hal-async feature flag, so the dependency is not enabled by
default.

Note that this branch depends on my PR #6, which updates this crate to
use embedded-hal v1.0, and currently contains the commit from that
change as well. Once #6 has merged, this branch will need to be rebased
onto the main branch.

It also depends on my upstream PR adding embedded-hal-async support to
sensirion-i2c-rs, Sensirion/sensirion-i2c-rs#30, which has been
merged, but hasn't been published to crates.io yet. Currently, this
branch adds a Cargo [patch] to use a Git dep on sensirion-i2c-rs.
So, this change cannot be released to crates.io until upstream publishes
a new release of sensirion-i2c-rs. Hopefully they do that soon! :)

@hawkw hawkw changed the title Eliza/embedded hal async Add embedded-hal-async support Jun 9, 2024
@bbustin
Copy link

bbustin commented Sep 5, 2024

Please also see my pull request which added support for embedded-hal-1.0 and async support gated behind a feature: #5

hawkw and others added 9 commits November 20, 2024 12:30
This commit adds support for the `embedded-hal-async` crate in addition
to `embedded-hal`. I've done this by adding a separate `AsyncSht4x`
type, based on the assumption that most projects won't need to use both
the blocking `embedded-hal` traits and the `embedded-hal-async` traits
at the same time, and providing `async fn` methods on a separate type
with the same names as the blocking ones seemed a bit nicer than having
one type that has both `fn measure` and `async fn measure_async` and so
on.

Support for `embedded-hal-async` is gated behind the
`embedded-hal-async` feature flag, so the dependency is not enabled by
default.

Note that this branch depends on my PR sirhcel#6, which updates this crate to
use `embedded-hal` v1.0, and currently contains the commit from that
change as well. Once sirhcel#6 has merged, this branch will need to be rebased
onto the main branch.

It also depends on my upstream PR adding `embedded-hal-async` support to
`sensirion-i2c-rs`, Sensirion/sensirion-i2c-rs#30, which has been
[merged], but hasn't been published to crates.io yet. Currently, this
branch adds a Cargo `[patch]` to use a Git dep on `sensirion-i2c-rs`.
So, this change cannot be released to crates.io until upstream publishes
a new release of `sensirion-i2c-rs`. Hopefully they do that soon! :)

[merged]: Sensirion/sensirion-i2c-rs@f7b9f3a
Now that my changes have been published upstream, we can remove the Git
patch. This PR should now be okay to merge!
This way, the naming scheme is more consistent with the async driver
I added to the `sgp30` crate. See:
dbrgn/sgp30-rs@cb769b0
It's about the error and not the I2C implementation type.
With the driver struct already named Sht4xAsync, its source file should
follow the same order.
Sensor data extraction is already shared and the serial number
extraction code should be shared as well.
It's written in the sensors data sheet but I did not remember this after
looking into the code after quite some time.
@sirhcel sirhcel force-pushed the eliza/embedded-hal-async branch from 8e2519a to 40cef0d Compare March 1, 2025 21:30
@sirhcel
Copy link
Owner

sirhcel commented Mar 1, 2025

Thank you very much for your PR @hawkw! I took me a while to wrap my head around how to provide a sync and async driver variant from a single crate. I wished that more code could be shared but this seems not conveniently possible as of now.

@sirhcel sirhcel merged commit 7ff8d0f into sirhcel:master Mar 1, 2025
10 checks passed
@hawkw
Copy link
Contributor Author

hawkw commented Mar 1, 2025

I wished that more code could be shared but this seems not conveniently possible as of now.

Yeah, I also wished that, but unfortunately the story for this sort of thing is still a bit rough. Thanks for taking the time to merge my PR!

This was referenced Mar 2, 2025
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

Successfully merging this pull request may close these issues.

3 participants