pub struct Gpt<const N: u8> { /* private fields */ }
Expand description
A general purpose timer
The timers support three output compare registers. When a compare register matches the value of the counter, the GPT may trigger an interrupt.
By default, the timer runs in wait mode.
Implementations§
source§impl<const N: u8> Gpt<N>
impl<const N: u8> Gpt<N>
sourcepub fn new(gpt: Instance<N>) -> Self
pub fn new(gpt: Instance<N>) -> Self
Create a GPT timer from the RAL’s GPT instance.
When new
returns, the GPT is reset and disabled.
sourcepub fn set_divider(&mut self, divider: u32)
pub fn set_divider(&mut self, divider: u32)
Set the divider value.
The divider value is clamped between 1 and 4096. A change in the divider cause the prescaler counter to reset and a new count period to start immediately.
sourcepub fn divider_24mhz(&self) -> u32
pub fn divider_24mhz(&self) -> u32
Return the 24MHz clock divider.
sourcepub fn set_divider_24mhz(&mut self, divider: u32)
pub fn set_divider_24mhz(&mut self, divider: u32)
Set the 24MHz clock divider.
The divider value is clamped between 1 and 16. 24MHz crystal clock is divided by the divider before selected by the clock selection. If 24M crystal clock is not selected, this feild takes no effect.
sourcepub fn set_mode(&mut self, mode: Mode)
pub fn set_mode(&mut self, mode: Mode)
Set the GPT mode.
Refer to the module level documentation for more information on the GPT modes.
sourcepub fn clock_source(&self) -> ClockSource
pub fn clock_source(&self) -> ClockSource
Returns the GPT clock source
sourcepub fn set_clock_source(&mut self, clock_source: ClockSource)
pub fn set_clock_source(&mut self, clock_source: ClockSource)
Set the GPT clock source.
sourcepub fn set_reset_on_enable(&mut self, reset_on_enable: bool)
pub fn set_reset_on_enable(&mut self, reset_on_enable: bool)
Set the reset on enable behavior
See the module-level docs for more information.
sourcepub fn is_reset_on_enable(&self) -> bool
pub fn is_reset_on_enable(&self) -> bool
Returns true
if the GPT counter will reset the next time it is enabled.
sourcepub fn enable(&mut self)
pub fn enable(&mut self)
Enable the GPT.
When enabled, the counter starts counting. The value of the counter
is determined by the reset on enable setting. See
set_reset_on_enable
.
sourcepub fn is_enabled(&self) -> bool
pub fn is_enabled(&self) -> bool
Indicates if the GPT is enabled (true
) or disabled (false
).
sourcepub fn set_wait_mode_enable(&mut self, wait: bool)
pub fn set_wait_mode_enable(&mut self, wait: bool)
Allow the GPT to run in wait mode; or, prevent the GPT from running in wait mode.
sourcepub fn is_wait_mode_enabled(&self) -> bool
pub fn is_wait_mode_enabled(&self) -> bool
Indicates if the GPT runs while in wait mode.
sourcepub fn set_output_interrupt_on_compare(
&mut self,
ocr: OutputCompareRegister,
intr: bool
)
pub fn set_output_interrupt_on_compare( &mut self, ocr: OutputCompareRegister, intr: bool )
Enable the GPT interrupt when the output compares.
sourcepub fn is_output_interrupt_on_compare(&self, ocr: OutputCompareRegister) -> bool
pub fn is_output_interrupt_on_compare(&self, ocr: OutputCompareRegister) -> bool
Returns true
if a comparison triggers an interrupt.
sourcepub fn set_output_compare_count(&self, ocr: OutputCompareRegister, count: u32)
pub fn set_output_compare_count(&self, ocr: OutputCompareRegister, count: u32)
Set an output compare register to trigger on the next count
value of the
counter.
sourcepub fn output_compare_count(&self, ocr: OutputCompareRegister) -> u32
pub fn output_compare_count(&self, ocr: OutputCompareRegister) -> u32
Returns the current output compare count for the specified register.
sourcepub fn is_elapsed(&self, ocr: OutputCompareRegister) -> bool
pub fn is_elapsed(&self, ocr: OutputCompareRegister) -> bool
Returns true
if the time tracked by the OCR has elapsed.
sourcepub fn clear_elapsed(&self, ocr: OutputCompareRegister)
pub fn clear_elapsed(&self, ocr: OutputCompareRegister)
Clear the elapsed flag.
sourcepub fn set_rollover_interrupt_enable(&mut self, rov: bool)
pub fn set_rollover_interrupt_enable(&mut self, rov: bool)
Enable / disable an interrupt when the GPT counter rolls over from u32::max_value()
to
0
.
The GPT triggers a rollover regardless of the GPT mode.
sourcepub fn is_rollover_interrupt_enabled(&self) -> bool
pub fn is_rollover_interrupt_enabled(&self) -> bool
Returns true
if a rollover generates an interrupt.
sourcepub fn is_rollover(&self) -> bool
pub fn is_rollover(&self) -> bool
Returns true
if the rollover flag is set.
A rollover occurs when the counter rolls over from u32::max_value()
to 0
. Rollover
may occur regardless of the GPT mode.
sourcepub fn clear_rollover(&self)
pub fn clear_rollover(&self)
Clear the rollover status flag.
Users must clear the rollover flag if a rollover triggered an interrupt.