pub struct Gpt<'a> { /* private fields */ }
Expand description
General purpose timer (GPT).
USB GPTs have a 1us resolution. The counter is 24 bits wide. GPTs can generate USB interrupts that are independent of USB protocol interrupts. This lets you add additional, time-driven logic into your USB ISR and driver state machine.
See the module-level documentation for an example.
Implementations§
source§impl<'a> Gpt<'a>
impl<'a> Gpt<'a>
sourcepub fn run(&mut self)
pub fn run(&mut self)
Run the GPT timer.
Run will start counting down the timer. Use stop()
to cancel a running timer.
sourcepub fn is_running(&self) -> bool
pub fn is_running(&self) -> bool
Indicates if the timer is running (true
) or stopped (false
).
sourcepub fn reset(&mut self)
pub fn reset(&mut self)
Reset the timer.
reset
loads the counter value. It does not stop a running counter.
sourcepub fn set_load(&mut self, us: u32)
pub fn set_load(&mut self, us: u32)
Set the counter load value.
us
is the number of microseconds to count. us
will saturate at a 24-bit value (0xFFFFFF,
or 16.777215 seconds). A value of 0
will result in a 1us delay.
Note that the load count value is not loaded until the next call to reset()
(one shot mode)
or until after the timer elapses (repeat mode).
sourcepub fn is_elapsed(&self) -> bool
pub fn is_elapsed(&self) -> bool
Indicates if the timer has elapsed.
If the timer has elapsed, you should clear the elapsed flag with clear_elapsed()
.
sourcepub fn clear_elapsed(&mut self)
pub fn clear_elapsed(&mut self)
Clear the flag that indicates the timer has elapsed.
sourcepub fn set_interrupt_enabled(&mut self, enable: bool)
pub fn set_interrupt_enabled(&mut self, enable: bool)
Enable or disable interrupt generation when the timer elapses.
If enabled (true
), an elapsed GPT will generate an interrupt. This happens regardless of the USB
interrupt enable state.
sourcepub fn is_interrupt_enabled(&self) -> bool
pub fn is_interrupt_enabled(&self) -> bool
Indicates if interrupt generation is enabled.