1
+ //! API for the integrated timers
2
+ //!
3
+ //! This only implements basic functions, a lot of things are missing
4
+ //!
5
+ //! # Example
6
+ //! Blink the led with 1Hz
7
+ //! ``` no_run
8
+ //! use stm32f0xx_hal as hal;
9
+ //!
10
+ //! use crate::hal::stm32;
11
+ //! use crate::hal::prelude::*;
12
+ //! use crate::hal::time::*;
13
+ //! use crate::hal::timers::*;
14
+ //! use nb::block;
15
+ //!
16
+ //! let mut p = stm32::Peripherals::take().unwrap();
17
+ //!
18
+ //! let mut led = gpioa.pa1.into_push_pull_pull_output();
19
+ //! let rcc = p.RCC.constrain().cfgr.freeze();
20
+ //! let mut timer = Timer::tim1(p.TIM1, Hertz(1), clocks);
21
+ //! loop {
22
+ //! led.toggle();
23
+ //! block!(timer.wait()).ok();
24
+ //! }
25
+ //! ```
26
+
1
27
#[ cfg( feature = "stm32f030" ) ]
2
28
use crate :: stm32:: { RCC , TIM1 , TIM14 , TIM15 , TIM16 , TIM17 , TIM3 , TIM6 , TIM7 } ;
3
29
#[ cfg( feature = "stm32f042" ) ]
@@ -55,6 +81,7 @@ impl Timer<SYST> {
55
81
impl CountDown for Timer < SYST > {
56
82
type Time = Hertz ;
57
83
84
+ /// Start the timer with a `timeout`
58
85
fn start < T > ( & mut self , timeout : T )
59
86
where
60
87
T : Into < Hertz > ,
@@ -68,6 +95,8 @@ impl CountDown for Timer<SYST> {
68
95
self . tim . enable_counter ( ) ;
69
96
}
70
97
98
+ /// Return `Ok` if the timer has wrapped
99
+ /// Automatically clears the flag and restarts the time
71
100
fn wait ( & mut self ) -> nb:: Result < ( ) , Void > {
72
101
if self . tim . has_wrapped ( ) {
73
102
Ok ( ( ) )
@@ -143,6 +172,7 @@ macro_rules! timers {
143
172
impl CountDown for Timer <$TIM> {
144
173
type Time = Hertz ;
145
174
175
+ /// Start the timer with a `timeout`
146
176
fn start<T >( & mut self , timeout: T )
147
177
where
148
178
T : Into <Hertz >,
@@ -165,6 +195,8 @@ macro_rules! timers {
165
195
self . tim. cr1. modify( |_, w| w. cen( ) . set_bit( ) ) ;
166
196
}
167
197
198
+ /// Return `Ok` if the timer has wrapped
199
+ /// Automatically clears the flag and restarts the time
168
200
fn wait( & mut self ) -> nb:: Result <( ) , Void > {
169
201
if self . tim. sr. read( ) . uif( ) . bit_is_clear( ) {
170
202
Err ( nb:: Error :: WouldBlock )
0 commit comments