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

Migrate crate over to embedded-time #183

Merged
merged 1 commit into from
Jul 26, 2021

Conversation

jamwaffles
Copy link
Contributor

No description provided.


/// Wait for the given time.
///
/// Note that durations above `u32::MAX` microseconds will be clamped at `u32::MAX`.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm not particularly happy with this behaviour but I can't think of a better solution right now. Thoughts appreciated!

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not happy about that either, but can't think of a better solution right now. A fallible interface isn't great, panicking isn't great either. Your solution here at least should work for the common case, and the pitfall is documented.

pub fn delay<T>(&mut self, delay: T)
where
T: Into<MicroSeconds>,
T: TryInto<Microseconds>,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is so we can use e.g. 1.second() or 300.milliseconds() in calling code. We could also use this pattern in other hertz-accepting places. There's at least one demo that replaces 1.khz() with 100_000.Hz() which I don't like.

@@ -24,7 +24,7 @@ fn main() -> ! {
let gpioa = dp.GPIOA.split(&mut rcc);

// Initialize TIM2 for PWM
let pwm = pwm::Timer::new(dp.TIM2, 10.khz(), &mut rcc);
let pwm = pwm::Timer::new(dp.TIM2, 10_000.Hz(), &mut rcc);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This (and IIRC the SPI interface require this change unless I use TryInto in the APIs - embedded-time can convert from e.g. Khz<u32> to Hz<u64> without failing, but needs the fallible conversions if we want to go from Khz<u32> to Hz<u32>. Realistically, confining to u32 everywhere isn't an issue (IMO) so I'd be up for using TryInto and clamping to u32::MAX like I do with the delay() API. Thoughts?

@jamwaffles jamwaffles force-pushed the embedded-time branch 5 times, most recently from a642284 to a4745ff Compare July 25, 2021 13:53
@jamwaffles jamwaffles marked this pull request as ready for review July 25, 2021 13:58
@jamwaffles jamwaffles requested a review from a team as a code owner July 25, 2021 13:58
Copy link
Contributor

@hannobraun hannobraun left a comment

Choose a reason for hiding this comment

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

Thank you, @jamwaffles! I found one issue (see comment), but otherwise this looks great!


/// Wait for the given time.
///
/// Note that durations above `u32::MAX` microseconds will be clamped at `u32::MAX`.
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not happy about that either, but can't think of a better solution right now. A fallible interface isn't great, panicking isn't great either. Your solution here at least should work for the common case, and the pitfall is documented.

src/serial.rs Outdated
@@ -93,14 +91,14 @@ pub enum StopBits {
}

pub struct Config {
pub baudrate: Bps,
pub baudrate: BitsPerSecond,
Copy link
Contributor

Choose a reason for hiding this comment

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

This isn't right, is it? I think we need BytesPerSecond.

(I don't think it makes a difference in functionality, but it's the wrong type semantically. Could lead to confusion.)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Turns out there's a Baud struct which is far better suited lol. I force pushed to the branch with a fix for BitsPerSecond to Baud.

@jamwaffles jamwaffles force-pushed the embedded-time branch 2 times, most recently from a5676aa to 260d8ad Compare July 26, 2021 13:28
Copy link
Contributor

@hannobraun hannobraun left a comment

Choose a reason for hiding this comment

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

Thank you, @jamwaffles!

@hannobraun hannobraun merged commit 37cfc5e into stm32-rs:master Jul 26, 2021
@jamwaffles jamwaffles deleted the embedded-time branch July 27, 2021 12:49
jamwaffles added a commit to jamwaffles/stm32l0xx-hal that referenced this pull request Aug 1, 2021
IIRC I did test the examples when working on stm32-rs#183, but this error shows
up when using the PLL which none of them do. I found this when testing
with my own project code. At any rate, here's a fix for embedded-time
comparisons when using the PLL.
jamwaffles added a commit to jamwaffles/stm32l0xx-hal that referenced this pull request Aug 1, 2021
IIRC I did test the examples when working on stm32-rs#183, but this error shows
up when using the PLL which none of them do. I found this when testing
with my own project code. At any rate, here's a fix for embedded-time
comparisons when using the PLL.
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.

2 participants