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

Generic Delay implementation #103

Closed
TeXitoi opened this issue Oct 11, 2018 · 4 comments
Closed

Generic Delay implementation #103

TeXitoi opened this issue Oct 11, 2018 · 4 comments

Comments

@TeXitoi
Copy link

TeXitoi commented Oct 11, 2018

Almost all the hal implementations:

  • have the same time.rs module defining time object like Hz
  • implement (more or less right) a Delay object on each timer.

I think that this can be solved in embedded-hal by:

  • Defining something like time.rs
  • Having a trait CalibratedCountDown that provide the needed function to implement delay
  • A Wrapper type over a CalibratedCountDown that provide the Delay implementation.

Then, the hal only have to provide a CalibratedCountDown object that can be created from a timer and a Clock object.

An idea of the implementation:

pub trait CalibratedCountDown {
    /// The duration of a tick.
    fn tick(&self) -> Duration;
    /// Maximum ticks the counter can count.
    fn max_ticks(&self) -> usize;
    /// Start a new countdown of `count` ticks.
    fn start<T>(&mut self, count: usize);
    /// Non-blockingly "waits" until the count down finishes.
    fn wait(&mut self) -> Result<(), Void>
}

Then you can generically implement Delay as atsamd-rs/atsamd#14

@TeXitoi TeXitoi changed the title Abstracting time Generic Delay implementation Oct 11, 2018
@therealprof
Copy link
Contributor

I fully agree there's plenty of room for improvement. We do need to be a bit careful about how we design something generic so it can actually be used by any implementation and will lead to efficient code everywhere (especially division operations can be problematic).

I'm not quite sure how ergonomic your suggestion would be in real life, it would be great to have an implementation available to play with it on different systems to get a feel how it might work.

@TeXitoi
Copy link
Author

TeXitoi commented Oct 11, 2018

the timer can implement an fn into_delay(self, Clock) -> Delay<Self> that returns the Generic delay. That would be ergonomic, no?

@therealprof
Copy link
Contributor

That would indeed be ergonomic. But will it actually blend? 😅

@Dirbaio
Copy link
Member

Dirbaio commented Apr 28, 2023

Now that the timer traits with an unconstrained associated type Timer; are gone, this is no longer an issue #324

Of course this is not ideal since we no longer have timer traits. This is now tracked in #359

@Dirbaio Dirbaio closed this as completed Apr 28, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants