This repository has been archived by the owner on May 15, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 13
Drivers for the TIMER and RTC peripherals #19
Merged
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
… the event register If we don't do this, a second call to start() shortly before the countdown was due to expire could find the event flag was set again between it being cleared and the timer being reset to zero, causing a following wait() to exit immediately.
Provides type-safe access to the TIMER peripherals. Makes the timer's current bit-width part of the type, so we can statically prevent misuse including - setting a bit-width not supported by a particular TIMER - passing a compare register value out of range for the current bit-width Includes HiResTimer, TimerFrequency, and TimerCc types.
Now uses 32-bit mode rather than 24-bit mode. Now uses a shortcut to stop the timer. Now checks for overlong delay times.
Adds a free() method. No longer enables the TIMER's interrupt.
The frequency is still always 1MHz, so the maximum delay when not using TIMER0 is ~65ms. Adds new struct DelayTimer<T: Nrf51Timer>. Delay is now an alias for DelayTimer<TIMER0>.
The frequency is still always 1MHz, so the maximum period when not using TIMER0 is ~65ms. Adds new struct CountDownTimer<T: Nrf51Timer>. Timer is now an alias for CountDownTimer<TIMER0>.
DelayTimer::new() now requires a TimerFrequency parameter. Adds new module time.rs, defining an Hfticks type. Adds new method TimerFrequency::scale(). Delay is now a wrapper rather than an alias, so that its new() can keep the same signature.
CountDownTimer::new() now requires a TimerFrequency parameter. Implements From<Duration> for Hfticks. Timer is now a wrapper rather than an alias, so that its new() can keep the same signature. The From<Duration> implementation is based on code from https://github.com/droogmic/nrf51-hal/tree/timers
Provides access to the RTC peripherals. Includes LoResTimer, RtcFrequency, and RtcCc types.
Adds new struct DelayRtc<T: Nrf51Rtc>. Adds new Lfticks type to time.rs.
Unlike the TIMER-backed implementation, this one isn't Periodic (because there's no shortcut to use). Adds new struct CountDownRtc<T: Nrf51Rtc>. Implements From<Duration> for Lfticks. The From<Duration> implementation is based on code from https://github.com/droogmic/nrf51-hal/tree/timers
therealprof
reviewed
Apr 6, 2019
/// | ||
/// # Panics | ||
/// | ||
/// `delay_ms()` and `delay_us()` panic if the requested time requires more |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It should be possible to allow the timers to wrap as often as required for longer delays instead of panicking but this is fine for now.
therealprof
approved these changes
Apr 6, 2019
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Outstanding work! Thank you so much.
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Includes standalone modules for the TIMER and RTC peripherals exposing most but not all of their functionality (the main missing feature is the TIMERs' counter mode).
Provides new implementations of the embedded-hal
CountDown
andDelay
traits based on these modules.These support using all three TIMERs, or either RTC, at any frequency supported by the hardware.
Includes backwards-compatible
timer::Timer
anddelay::Delay
types.The approach is loosely based on PR #12 but the implementation is new, with the 'driver' code separated from the countdown/delay support, and no macros.
The hardware restriction to no more than 16-bit mode for TIMER1 and TIMER2 is enforced statically.
There are usage examples in the rustdoc and in
test_timer.rs
andtest_countdown.rs
on the mattheww/microbit timer-test-examples branch (which is based on the droogmic/microbit timer-rtc branch).