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

Inconsistent use of furi::time::Duration and core::time::Duration #128

Open
dcoles opened this issue Jan 23, 2024 · 1 comment
Open

Inconsistent use of furi::time::Duration and core::time::Duration #128

dcoles opened this issue Jan 23, 2024 · 1 comment
Assignees
Labels
enhancement New feature or request

Comments

@dcoles
Copy link
Collaborator

dcoles commented Jan 23, 2024

Currently we have some APIs that use core::time::Duration (e.g. flipperzero::furi::thread::sleep) and some that use flipperzero::furi::time::Duration (e.g. flipperzero::gpio::i2c). This isn't great since it leads to a rather confusing situation where you have two incompatible Duration implementations in scope.

My understanding that the main reason that flipperzero::furi::time exists is that there is no Instant implementation in core::time and to better align with the kernel's tick resolution.

A quick comparison:

core::time::Duration flipperzero::furi::time::Duration flipperzero::furi::time::Instant
Representation { secs: u64, nanos: u32 } { ticks: u32 } { ticks: u32 }
Size 12 bytes 4 bytes 4 bytes
Limits ~5.8¹¹ years ~49.7 days1 ± ~24.9 days1
Resolution 1 ns 1 ms1 1 ms1

Consumers:

Function Limits Resolution
furi_delay_us(u32) ~1.2 hours 1 μs
furi_delay_ms(u32) ~49.7 days 1 ms
furi_delay_tick(u32) ~49.7 days1 1 ms1
furi_hal_i2c_tx(..., u32) ~49.7 days 1 ms

Footnotes

  1. Assuming the default configTICK_RATE_HZ_RAW = 1000 2 3 4 5 6

@dcoles dcoles added the enhancement New feature or request label Jan 23, 2024
@dcoles
Copy link
Collaborator Author

dcoles commented Jan 23, 2024

Having a Furi specific Duration/Instant type that works on ticks seems to be quite useful, especially for some of the more low-level APIs. I wonder if we want to rename these FuriDuration and FuriInstant and provide conversion functions (e.g. FuriDuration::try_from(Duration)).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants