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

Add a non busy sleep #8

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

nathansamson
Copy link

This adds a way to sleep in a non-busy way so different threads could sleep simoultaniously and execute actions on different intervals.

Added an example that toggles the Arduino One led every second, and writes to the serial console every 3.5s.
I checked this on my device and things seems to have been relatively accurate.

Note since the tick counter is limted to a u16 and a tick occurs at least once every 0.064 ms the maximum delay that is possible is approx 4100 ms. If you want longer delays these need to be chained.
Faster than 1 ms delays are also not supported. In principle this is possible but I feel those won't be accurate so I rather have them not supported.

A ``TimeReader` needs to be provided for the specific board and configured to be 16Mhz and prescaled at 1024.

I am not sure what would be the best cross-hardware way to distribute them (I am not sure if TC1 is always a 16bit timer that can prescale)

A possible addition would be to pass the Hz so the user can choose between precision and range.

I also wrapped the user provider TimeReader in a RefCell to prevent issues when trying to use this from multiple async handlers. Not sure what the cleanest Rust way would be (relatively new to rust)

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.

1 participant