Skip to content

Commit 79e68ac

Browse files
committed
New timer methods
1 parent 33d175c commit 79e68ac

File tree

2 files changed

+19
-6
lines changed

2 files changed

+19
-6
lines changed

CHANGELOG.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,18 +15,20 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
1515
- Update existing ADC example according to ADC API changes
1616
- Add new ADC example to read ambient temperature using ADC1 CH16
1717
- Add `listen` and `unlisten` to `serial::Tx` and `serial::Rx`.
18+
- Add `count` and `reset` methods to timer
1819

1920

2021
### Breaking changes
2122

2223
- Replace gpio traits with digital::v2
2324
- Bump `stm32f1` dependency (`0.8.0`)
24-
- ADC now requires the clock configuration for intialisation
25+
- ADC now requires the clock configuration for initialisation
2526
- `disable_jtag` now transforms PA15, PB3 and PB4 to forbid their use without desactivating JTAG
2627

2728
### Changed
2829

2930
- Fix hclk miscalculation
31+
- Starting the timer does not generate interrupt requests anymore
3032

3133
## [v0.3.0] - 2019-04-27
3234

src/timer.rs

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,21 @@ macro_rules! hal {
160160
self.stop();
161161
self.tim
162162
}
163+
164+
/// Returns the current counter value
165+
pub fn count(&self) -> u16 {
166+
self.tim.cnt.read().cnt().bits()
167+
}
168+
169+
/// Resets the counter and generates an update event
170+
pub fn reset(&mut self) {
171+
// Sets the URS bit to prevent an interrupt from being triggered by
172+
// the UG bit.
173+
self.tim.cr1.modify(|_, w| w.urs().set_bit());
174+
175+
self.tim.egr.write(|w| w.ug().set_bit());
176+
self.tim.cr1.modify(|_, w| w.urs().clear_bit());
177+
}
163178
}
164179

165180
impl CountDown for Timer<$TIMX> {
@@ -184,11 +199,7 @@ macro_rules! hal {
184199
self.tim.arr.write(|w| w.arr().bits(arr) );
185200

186201
// Trigger an update event to load the prescaler value to the clock
187-
self.tim.egr.write(|w| w.ug().set_bit());
188-
// The above line raises an update event which will indicate
189-
// that the timer is already finished. Since this is not the case,
190-
// it should be cleared
191-
self.clear_update_interrupt_flag();
202+
self.reset();
192203

193204
// start counter
194205
self.tim.cr1.modify(|_, w| w.cen().set_bit());

0 commit comments

Comments
 (0)