async version, and tool to avoid versions getting out of sync#12
async version, and tool to avoid versions getting out of sync#12alsuren wants to merge 8 commits intoqrasmont:masterfrom
Conversation
|
Hey! Sorry for the delayed response, I've been sick. I will take some time to look at this in details. |
|
Take it easy and get yourself better. Programming can wait. In fact, this pr probably shouldn't be merged until I have proven that it works. I got a bit stuck today trying to debug a FifoExceeded error from esp-hal when I try to run bmi.init(&FILE). Turns out it's this: https://github.com/esp-rs/esp-hal/blob/d53e0b834289c90aaed0829c3d2525e3aa1cc60f/esp-hal/src/i2c/master/mod.rs#L1952-L1958 and setting Burst::Other(31) fixes it. I now have bmi.get_data() telling me a time that is increasing at about 25_000 steps per second, but acc and gyr remain all zeros. I will actually try reading the data sheet and cross referencing some Arduino examples tomorrow. |
|
Hey there @alsuren, were you able to get the async version to work? |
|
Yes. I managed to get it into the sky (just about): (I should get into the habit of actually merging my prs so people can find the latest progress more easily) |
|
I have recently got a new job so I've put the project down for a bit. I am starting to get into the swing of things though, so I can fix up this PR this week if you want. If you fundamentally don't like the approach then that's completely fine, and we can close the PR. |
|
Is there anything actually missing from this (besides the conflicts with the latest PR)? It looks good and would be pretty useful for me to be able to use in embassy. |
I have only been using it in https://github.com/hoverkite/kitesabre as a joystick of sorts so far. I should really look into the power saving mode at some point, because my m5stack atom is getting pretty warm (might not have anything to do with the bmi2 - I've not checked). My main concern is the overhead of keeping the async and sync versions in sync with each other. I wouldn't want to inflict that burden on the upstream maintainer, so I spent a bit of time working on that. I added a Makefile with rules If you give Claude Sonnet 3.5 the instructions: then it does seem to converge eventually (I doubt it was quicker than doing it myself by hand though)
Please try using it as a git dependency and tell me how it goes. |
|
Thanks for updating it. I'll give it a try. I know other drivers duplicate the code (ala your Makefile), but generally it is much easier to use async from sync than the other way around, so in general drivers should be async. But that is up to the maintainer and whether they hold the same opinion and want to make a breaking change. I'll update on how it goes |
|
I got it working reading to the point of reading the right chip id at this point. I didn't test past that yet, but the latest two commits on top of the async branch of your fork in my fork are required to make the SPI driver work. It had a few fundamental errors (needing to do a dummy read in the spi constructor, needing to skip a byte for SPI reads, and adding 0x80 to the address for the read bit): |
When implementing the "shared bus" example ( #10 (comment) ), I realised that it would be easier to implement an embedded_hal_async version of bmi2.
What do you think of this general approach?
The idea is that the blocking version can be derived from the async version by deleting code (specifically
.await,async,_asyncand#[allow(async_fn_in_trait)]) and then passing the result through rustfmt.Potential ways to tidy this up:
a) move the check into a Makefile, so you can type
make checkto look for differences (then add amake syncto re-generate the blocking code from the async versions)b) same as a, but using pair of files in scripts/
c) same as a, but using the
cargo xtaskpatternd) make the error message a bit better (currently it just relies on the fact that
diffwill exit nonzero if it spots differencese) work out how to annotate PRs to put errors on lines that need to change
f) actually just delete interface.rs and bmi2.rs and generate them using a build.rs
I have been working off a hacked version of the esp-hal qa-test/src/bin/embassy_i2c_bmp180_calibration_data.rs example. If you like, I can extract the relevant bits out and add it as an example in this crate.
interesting bits from the example
( for context, I am using it in my kitebox firmware, which is using esp32 + embassy https://github.com/hoverkite/hoverkite/tree/main/cross/kitebox )