rust-embedded / embedded-hal

A Hardware Abstraction Layer (HAL) for embedded systems
Apache License 2.0
2.01k stars 202 forks source link

RFC: rename DelayNs to Delay #541

Closed adamgreig closed 10 months ago

adamgreig commented 11 months ago

The obvious name for the DelayNs trait is Delay, but we've reserved that name for a future, post-1.0 trait once we have a good Duration. Right now it's not clear what that Duration will look like or do, so we've been leaving thinking about it until later.

I suggest we rename the current DelayNs trait to Delay now anyway:

My main point is that perhaps what we have in DelayNs is already good enough to warrant using the name Delay, and it's nice that we could conceivably add a delay(Duration) method later (with some caveats) if we wanted to, while if we stick with DelayNs now, we're sure to always have DelayNs and maybe also have Delay, with all the confusion that multiple overlappnig traits has brought us in the past.

There are some downsides to "just add delay(Duration) later", though:

It's not a slam-dunk either way, but it seemed worth discussing before we hit 1.0.

rmsyn commented 11 months ago

Would it be useful to switch to u64 as the argument type, since the scale has changed three orders of magnitude?

Users of the trait now have significantly less range to delay the core.

Max delay is now ~4.29 seconds. Previously, the maximum was ~4,294 seconds.

MathiasKoch commented 11 months ago

The trait still has delay_us and delay_ms with u32, so I don't think that is going to an issue?

adamgreig commented 11 months ago

We discussed this again today and didn't reach a firm conclusion, so probably default to not renaming this, but I'll leave the issue open another week in case anyone else wants to chime in.

rmsyn commented 11 months ago

The trait still has delay_us and delay_ms with u32, so I don't think that is going to an issue?

If you look at the inner implementation of delay_us and delay_ms, they make a call to delay_ns, which limits the max delay to ~4.29 seconds (4.29 billion nanoseconds).

If this isn't a concern, since users could call delay_* functions multiple times to get longer delays, then it's a non-issue. It just seems like a good time to widen the argument bit size before the first stable release.

adamgreig commented 11 months ago

If you look at the inner implementation of delay_us and delay_ms, they make a call to delay_ns, which limits the max delay to ~4.29 seconds (4.29 billion nanoseconds).

They don't? The provided default implementation (the final implementer can override) makes multiple calls to delay_ns to ensure the total delay is as many micro/milliseconds as required, even if that's many more than 4.29 billion nanoseconds.

rmsyn commented 11 months ago

The provided default implementation (the final implementer can override) makes multiple calls to delay_ns to ensure the total delay is as many micro/milliseconds as required, even if that's many more than 4.29 billion nanoseconds.

You're right, I misread the implementation somehow late last night, and thought there was only a single call.

Dirbaio commented 10 months ago

In the end we decided not to do this for 1.0, i'm closing this to keep the roadmap clear.