Skip to content

Commit f4aea76

Browse files
authored
Merge pull request #677 from eZioPan/set_count-for-QEI
`.set_count()` for qei
2 parents a22d803 + 90f459a commit f4aea76

File tree

3 files changed

+15
-0
lines changed

3 files changed

+15
-0
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
88
## [Unreleased]
99

1010
- complete and rework Dma Stream API [#666]
11+
- add `.set_count()` for QEI, add `.write_count()` for TIM [#677]
1112

1213
[#666]: https://github.com/stm32-rs/stm32f4xx-hal/pull/666
14+
[#677]: https://github.com/stm32-rs/stm32f4xx-hal/pull/677
1315

1416
## [v0.17.1] - 2023-07-24
1517

src/qei.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,12 @@ impl<TIM: Instance> Qei<TIM> {
7070
) {
7171
(self.tim, self.pins)
7272
}
73+
74+
/// Set current count number
75+
pub fn set_count(&mut self, value: TIM::Width) -> &mut Self {
76+
self.tim.write_count(value);
77+
self
78+
}
7379
}
7480

7581
impl<TIM: Instance> embedded_hal::Qei for Qei<TIM> {

src/timer.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,7 @@ mod sealed {
273273
fn listen_interrupt(&mut self, event: Event, b: bool);
274274
fn get_interrupt_flag(&self) -> Event;
275275
fn read_count(&self) -> Self::Width;
276+
fn write_count(&mut self, value: Self::Width);
276277
fn start_one_pulse(&mut self);
277278
fn start_free(&mut self, update: bool);
278279
fn cr1_reset(&mut self);
@@ -405,6 +406,12 @@ macro_rules! hal {
405406
self.cnt.read().bits() as Self::Width
406407
}
407408
#[inline(always)]
409+
fn write_count(&mut self, value:Self::Width) {
410+
//TODO: remove "unsafe" when possible
411+
#[allow(unused_unsafe)]
412+
self.cnt.write(|w|unsafe{w.cnt().bits(value)});
413+
}
414+
#[inline(always)]
408415
fn start_one_pulse(&mut self) {
409416
self.cr1.modify(|_, w| unsafe { w.bits(1 << 3) }.cen().set_bit());
410417
}

0 commit comments

Comments
 (0)