Skip to content

Commit 479a70c

Browse files
Add documentation to timers
1 parent 9a1ef4d commit 479a70c

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

src/timers.rs

+32
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,29 @@
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+
127
#[cfg(feature = "stm32f030")]
228
use crate::stm32::{RCC, TIM1, TIM14, TIM15, TIM16, TIM17, TIM3, TIM6, TIM7};
329
#[cfg(feature = "stm32f042")]
@@ -55,6 +81,7 @@ impl Timer<SYST> {
5581
impl CountDown for Timer<SYST> {
5682
type Time = Hertz;
5783

84+
/// Start the timer with a `timeout`
5885
fn start<T>(&mut self, timeout: T)
5986
where
6087
T: Into<Hertz>,
@@ -68,6 +95,8 @@ impl CountDown for Timer<SYST> {
6895
self.tim.enable_counter();
6996
}
7097

98+
/// Return `Ok` if the timer has wrapped
99+
/// Automatically clears the flag and restarts the time
71100
fn wait(&mut self) -> nb::Result<(), Void> {
72101
if self.tim.has_wrapped() {
73102
Ok(())
@@ -143,6 +172,7 @@ macro_rules! timers {
143172
impl CountDown for Timer<$TIM> {
144173
type Time = Hertz;
145174

175+
/// Start the timer with a `timeout`
146176
fn start<T>(&mut self, timeout: T)
147177
where
148178
T: Into<Hertz>,
@@ -165,6 +195,8 @@ macro_rules! timers {
165195
self.tim.cr1.modify(|_, w| w.cen().set_bit());
166196
}
167197

198+
/// Return `Ok` if the timer has wrapped
199+
/// Automatically clears the flag and restarts the time
168200
fn wait(&mut self) -> nb::Result<(), Void> {
169201
if self.tim.sr.read().uif().bit_is_clear() {
170202
Err(nb::Error::WouldBlock)

0 commit comments

Comments
 (0)