Skip to content

Can Alarm::wait_until_{micros, millis, secs}, Timer::max_{micros, millis, secs}, and Timer::elapsed_{micros, millis, secs} have default implementations? #3

@datdenkikniet

Description

@datdenkikniet

Given that implementors must provide wait_until_nanos, could the less-granular functions be implemented in terms of the nanos wait (or, alternatively, in a "stepping down" fashion, i.e. seconds calls millis, millis calls micros, micros calls nanos? It should reduce the amount of logic that implementors have to do, and by extension reduce the likelihood of introducing bugs that way.

Time-wise, 2^64 nanoseconds is 584 years, so the reduced maximum time/duration (being 1e{3,6,9} longer in the future) shouldn't really be a problem, IMO.

I think the same holds for Timer::max_{micros, millis, seconds} and Timer::elapsed_{micros, millis, secs}. They all "do the same thing", just with a differing maximum value and resolution.

This will also place "being consistent" responsibility closer to the HAL: instead of every Alarm/Timer implementor being forced to do the math for converting to/from ticks correctly, and rounding in an expected way, this can be done by the HAL instead. If implementors choose to override any functions, they have a clear example of the expected behaviour in the HAL itself.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions