Skip to content

Implement embedded_hal_timer::Timer - #998

Draft
jannic wants to merge 1 commit into
rp-rs:mainfrom
jannic:embedded-hal-timer
Draft

Implement embedded_hal_timer::Timer#998
jannic wants to merge 1 commit into
rp-rs:mainfrom
jannic:embedded-hal-timer

Conversation

@jannic

@jannic jannic commented May 24, 2026

Copy link
Copy Markdown
Member

Open questions:

  • Naming
  • Should we feature-gate this behind some unstable feature for now?
  • This doesn't detect overflows of the u64 tick counter. Most likely not an issue in practice, for microsecond ticks. But it should at least be documented.
  • Needs a MSRV bump because embedded-hal-timer requires edition2024. (See failing CI)

Before merging this, it should also be implemented for rp235x-hal.

Comment thread rp2040-hal/src/timer.rs
u64::MAX
}

fn max_micros(&self) -> u64 {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

2^64 microseconds is 584 millenia (or 584,542 years). I think we're fine to claim that overflows are impossible, and ignore the -1 here.

Comment thread rp2040-hal/src/timer.rs

impl TickCounter {
/// Creates a new TickCounter.
pub const fn new(timer: Timer) -> Self {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Does it need to own the timer? It seems like it would be OK to make a bunch of these, and have them unsafely conjure up the timer for reading whenever required? Or just have a freestanding function called fn get_time() -> u64 that all these types can use?

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