Skip to content

Commit

Permalink
Merge pull request #677 from eZioPan/set_count-for-QEI
Browse files Browse the repository at this point in the history
`.set_count()` for qei
  • Loading branch information
burrbull authored Aug 2, 2023
2 parents a22d803 + 90f459a commit f4aea76
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 0 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
## [Unreleased]

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

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

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

Expand Down
6 changes: 6 additions & 0 deletions src/qei.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,12 @@ impl<TIM: Instance> Qei<TIM> {
) {
(self.tim, self.pins)
}

/// Set current count number
pub fn set_count(&mut self, value: TIM::Width) -> &mut Self {
self.tim.write_count(value);
self
}
}

impl<TIM: Instance> embedded_hal::Qei for Qei<TIM> {
Expand Down
7 changes: 7 additions & 0 deletions src/timer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,7 @@ mod sealed {
fn listen_interrupt(&mut self, event: Event, b: bool);
fn get_interrupt_flag(&self) -> Event;
fn read_count(&self) -> Self::Width;
fn write_count(&mut self, value: Self::Width);
fn start_one_pulse(&mut self);
fn start_free(&mut self, update: bool);
fn cr1_reset(&mut self);
Expand Down Expand Up @@ -405,6 +406,12 @@ macro_rules! hal {
self.cnt.read().bits() as Self::Width
}
#[inline(always)]
fn write_count(&mut self, value:Self::Width) {
//TODO: remove "unsafe" when possible
#[allow(unused_unsafe)]
self.cnt.write(|w|unsafe{w.cnt().bits(value)});
}
#[inline(always)]
fn start_one_pulse(&mut self) {
self.cr1.modify(|_, w| unsafe { w.bits(1 << 3) }.cen().set_bit());
}
Expand Down

0 comments on commit f4aea76

Please sign in to comment.