async-avr
async-avr copied to clipboard
Add a non busy sleep
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)