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 1.0 trait support #129

Open
wants to merge 14 commits into
base: main
Choose a base branch
from
Open

Conversation

techmccat
Copy link

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

Comment on lines -50 to +55
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()),
);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this needed? :)

Copy link
Author

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

Copy link
Contributor

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?

Copy link
Author

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

Copy link
Contributor

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

Copy link
Author

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

@usbalbin
Copy link
Contributor

usbalbin commented Aug 4, 2024

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?

@techmccat
Copy link
Author

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" }
Copy link
Contributor

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?

Copy link
Author

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.

examples/pwm.rs Outdated Show resolved Hide resolved
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;
Copy link
Contributor

@usbalbin usbalbin Aug 5, 2024

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? :)

Copy link
Author

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

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.

Move to embedded-hal 1.0
2 participants