Skip to content

Commit ebaecba

Browse files
committed
both embedded-hals for Qei
1 parent 24f8d16 commit ebaecba

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

src/qei.rs

+17
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,23 @@ impl<TIM: Instance, PINS> embedded_hal::Qei for Qei<TIM, PINS> {
5959
}
6060
}
6161

62+
impl<TIM: Instance, PINS> embedded_hal_one::qei::blocking::Qei for Qei<TIM, PINS> {
63+
type Error = core::convert::Infallible;
64+
type Count = TIM::Width;
65+
66+
fn count(&self) -> Result<Self::Count, Self::Error> {
67+
Ok(self.tim.read_count() as Self::Count)
68+
}
69+
70+
fn direction(&self) -> Result<embedded_hal_one::qei::Direction, Self::Error> {
71+
Ok(if self.tim.read_direction() {
72+
embedded_hal_one::qei::Direction::Upcounting
73+
} else {
74+
embedded_hal_one::qei::Direction::Downcounting
75+
})
76+
}
77+
}
78+
6279
pub trait Instance: crate::Sealed + rcc::Enable + rcc::Reset + General {
6380
fn setup_qei(&mut self);
6481

0 commit comments

Comments
 (0)