-
Notifications
You must be signed in to change notification settings - Fork 44
Add pico-de-gallo battery example #676
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
base: v0.2.0
Are you sure you want to change the base?
Add pico-de-gallo battery example #676
Conversation
Cargo Vet Audit Passed
|
24a1cf5 to
4a630c5
Compare
08cc2a3 to
b4db5a7
Compare
7f0f011 to
c925d15
Compare
|
|
||
| /// Platform specific battery controller. | ||
| struct Battery { | ||
| pub driver: Bq40z50R5<pico_de_gallo_hal::I2c, pico_de_gallo_hal::Delay>, |
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.
Can't you use embedded_hal::i2c::I2c and embedded_hal::delay::DelayNs instead?
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.
I could make this struct generic on those traits but I consider this app level code, so the types should be resolved at this level. We don't want to construct multiple instances of Battery with differing types in this example.
c925d15 to
6ef312a
Compare
Yeah i tried without the unsafe impl but it is still needed. Not sure why because all its fields are Send but ¯\_(ツ)_/¯ |
Not to beat a dead horse but I think actually the reason is because you take a reference. So for |
daba71f to
e2e9b0a
Compare
Nah no dead horse, the horse is still alive and well. Reading more into |
| #[cfg_attr(feature = "defmt", derive(defmt::Format))] | ||
| pub struct Data<'a> { | ||
| contents: &'a dyn Any, | ||
| contents: &'a (dyn Any + Send + Sync), |
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.
This is a breaking change, could you make sure to announce it?
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.
Why is this necessary now?
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.
This is necessary because tokio's spawn function requires the spawned future to implement not just Future, but also Send. All our services use the comms service to enable message passing. Comms sends a static reference to a dyn Any. dyn will make the type opaque so adding the Send bound is required to ensure the object is thread safe. Furthermore, it needs to be Sync because we are sending a reference, and &T is Send iff T is Sync. Embassy doesn't have the same bound, maybe because it assumes a singly threaded environment?
268bd11 to
3b49a5b
Compare
|
|
||
| /// Use the battery service endpoint to send data to other subsystems and services. | ||
| pub async fn comms_send(endpoint_id: EndpointID, data: &impl Any) -> Result<(), Infallible> { | ||
| pub async fn comms_send(endpoint_id: EndpointID, data: &(impl Any + Send + Sync)) -> Result<(), Infallible> { |
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.
Nit: probably better to add a where clause there. Can be done in a follow-up PR.
Add support for examples with the pico-de-gallo development board.
This PR sets up a new workspace for pico-de-gallo examples and adds an example that runs the battery service with the bq40z50-r5 fuel gauge connected to the pico-de-gallo's I2C bus.