-
Notifications
You must be signed in to change notification settings - Fork 48
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 1.0 trait support #129
base: main
Are you sure you want to change the base?
Conversation
let mut delay = cp.SYST.delay(&rcc.clocks); | ||
// let mut delay = cp.SYST.delay(&rcc.clocks); | ||
let mut delay = DelayFromCountDownTimer::new( | ||
Timer::new(dp.TIM6, &rcc.clocks).start_count_down(100u32.millis()), | ||
); |
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 needed? :)
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 switched out the SYST delay provider because cortex-m doesn't implement the new delay trait yet, it's probably not necessary though
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.
Is there any way to avoid this since I would imagine this would break a lot of users code?
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.
Using the old e-hal 0.2 trait should still work, but the function names are in conflict with the new ones which are exported in the prelude
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.
Might be a good idea to see how/if this is solved in for example stm32-rs/stm32f4xx-hal
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.
DelayNs has been implemented in rust-embedded/cortex-m@ec6b3ba but it hasn't been included in a release yet
There appears a bunch of unrelated changes. Since this PR is quite large, would it be possible to keep this PR to only the e-hal 1.0 migration? :) Also the CI was has just been fixed in #128, which was just merged. Would it be possible to rebase over the latest changes to get better ci results? |
embedded-hal 1.0 renamed from embedded-hal-one to embedded-hal embedded-hal 0.2 renamed from embedded-hal to embedded-hal-old, still re-exported as hal-02
I've tried cherry-picking only the hal-1 related changes, suppose I'll put SPI driver improvements and i2c example in separate PRs once this one goes through. |
Cargo.toml
Outdated
@@ -70,6 +75,8 @@ cortex-m-log = { version = "0.7", features = ["log-integration"] } | |||
cfg-if = "0.1.10" | |||
mpu6050 = "0.1.4" | |||
bme680 = "0.6.0" | |||
sh1106 = { git = "https://github.com/techmccat/sh1106.git", branch = "hal-1", version = "0.5.0" } |
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.
Is there any reason we are not using the regular 0.5.0 from crates.io?
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 was using my fork to test the i2c implementation for e-hal 1.
I also thought I hadn't included this example in the new set of changes but I must've re-added it by mistake at some point.
src/time.rs
Outdated
let cycles = cycles as u64; | ||
let clk = hz.raw() as u64; | ||
let us = cycles.saturating_mul(1_000_000_u64) / clk; | ||
MicroSecond::from_ticks(us as u32) | ||
let us = cycles.saturating_mul(DENOM as u64) / clk / NOM as u64; |
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.
let us
: Is this even microseconds any more? :)
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.
Guess not, it would be duration ticks
I had added them by accident for an example that didn't end up in the PR
Fixes #118
The new traits are not feature gated, instead embedded_hal 0.2 is now exported as hal_02
Traits from embedded-hal 1.0 have replaced the old ones in the prelude