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

[RFC] A time/rate solution #2923

Open
MabezDev opened this issue Jan 9, 2025 · 2 comments
Open

[RFC] A time/rate solution #2923

MabezDev opened this issue Jan 9, 2025 · 2 comments
Labels
1.0-blocker api RFC Request for comment

Comments

@MabezDev
Copy link
Member

MabezDev commented Jan 9, 2025

We currently use fugit, which has served us well, and works nicely overall. I do see a few issues with it though.

  • It's unstable, I asked about this here: 1.0 release korken89/fugit#52
  • I'm not sold on the extension traits. Whilst it can look nice to magically get this .khz() method on a u32 it's:
    • Not very discoverable, if you call it without the trait imported, the compiler will most likely throw a fit with a not very clear error message
    • There are ambiguous types involved when the backing for the type can be a u32 or a u64

I'm wondering if we should provide our own time types (which may very well use fugit under the hood), but we'll have more control on what we expose, and what we expect users to do.

For example, whilst it might be a bit more verbose, I think I'd prefer an API that looked like this:

pub struct Hertz(/* some type here, probably a `HertzU32` from fugit */);

impl Hertz {
	fn khz(khz: u32 /* unsure of type here, but u32 seems appropriate */) -> Hertz {
		// internally we can use fugit stuff, like the ext traits
		Hertz(khz.khz())
	}
}

The difference in use:

Before:

use fugit::ExtRate; // somewhere
// ..
.with_frequency(1000.khz())
// ..

After:

use esp_hal::time::Hertz; // somewhere
// ..
.with_frequency(Hertz::khz(1000))
// ..

^^ above is just an idea, I'd appreciate thoughts on this going forward.

@bugadani
Copy link
Contributor

bugadani commented Jan 9, 2025

Well the structure should probably be called Rate or Frequency, as Hertz is a unit of measurement so Hertz::kHz is already a confusion :)

We're mostly working with u64 as timestamp, which means using u64 under Duration and Instant is logical. For Rate, I'm not sure, depends whether we want to work with rates faster than 4GHz :)

@burrbull
Copy link
Contributor

burrbull commented Jan 9, 2025

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
1.0-blocker api RFC Request for comment
Projects
Status: Todo
Development

No branches or pull requests

3 participants