aboutsummaryrefslogtreecommitdiff
path: root/embassy-stm32/src/timer/qei.rs
diff options
context:
space:
mode:
authorDario Nieuwenhuis <[email protected]>2023-12-19 17:35:38 +0100
committerDario Nieuwenhuis <[email protected]>2023-12-19 17:35:38 +0100
commit189b15c426a3a9ef7d4024ba7e5de6a255f88ee7 (patch)
tree50a5c64c14cd2b920bc99ebcbd7fdf276ebe0ae0 /embassy-stm32/src/timer/qei.rs
parent41c3c26beb5d9ef683073c257c1269307be6ad43 (diff)
stm32/timer: docs.
Diffstat (limited to 'embassy-stm32/src/timer/qei.rs')
-rw-r--r--embassy-stm32/src/timer/qei.rs23
1 files changed, 17 insertions, 6 deletions
diff --git a/embassy-stm32/src/timer/qei.rs b/embassy-stm32/src/timer/qei.rs
index 9f9379c20..59efb72ba 100644
--- a/embassy-stm32/src/timer/qei.rs
+++ b/embassy-stm32/src/timer/qei.rs
@@ -9,23 +9,30 @@ use crate::gpio::sealed::AFType;
9use crate::gpio::AnyPin; 9use crate::gpio::AnyPin;
10use crate::Peripheral; 10use crate::Peripheral;
11 11
12/// Counting direction
12pub enum Direction { 13pub enum Direction {
14 /// Counting up.
13 Upcounting, 15 Upcounting,
16 /// Counting down.
14 Downcounting, 17 Downcounting,
15} 18}
16 19
17pub struct Ch1; 20/// Channel 1 marker type.
18pub struct Ch2; 21pub enum Ch1 {}
22/// Channel 2 marker type.
23pub enum Ch2 {}
19 24
20pub struct QeiPin<'d, Perip, Channel> { 25/// Wrapper for using a pin with QEI.
26pub struct QeiPin<'d, T, Channel> {
21 _pin: PeripheralRef<'d, AnyPin>, 27 _pin: PeripheralRef<'d, AnyPin>,
22 phantom: PhantomData<(Perip, Channel)>, 28 phantom: PhantomData<(T, Channel)>,
23} 29}
24 30
25macro_rules! channel_impl { 31macro_rules! channel_impl {
26 ($new_chx:ident, $channel:ident, $pin_trait:ident) => { 32 ($new_chx:ident, $channel:ident, $pin_trait:ident) => {
27 impl<'d, Perip: CaptureCompare16bitInstance> QeiPin<'d, Perip, $channel> { 33 impl<'d, T: CaptureCompare16bitInstance> QeiPin<'d, T, $channel> {
28 pub fn $new_chx(pin: impl Peripheral<P = impl $pin_trait<Perip>> + 'd) -> Self { 34 #[doc = concat!("Create a new ", stringify!($channel), " QEI pin instance.")]
35 pub fn $new_chx(pin: impl Peripheral<P = impl $pin_trait<T>> + 'd) -> Self {
29 into_ref!(pin); 36 into_ref!(pin);
30 critical_section::with(|_| { 37 critical_section::with(|_| {
31 pin.set_low(); 38 pin.set_low();
@@ -45,11 +52,13 @@ macro_rules! channel_impl {
45channel_impl!(new_ch1, Ch1, Channel1Pin); 52channel_impl!(new_ch1, Ch1, Channel1Pin);
46channel_impl!(new_ch2, Ch2, Channel2Pin); 53channel_impl!(new_ch2, Ch2, Channel2Pin);
47 54
55/// Quadrature decoder driver.
48pub struct Qei<'d, T> { 56pub struct Qei<'d, T> {
49 _inner: PeripheralRef<'d, T>, 57 _inner: PeripheralRef<'d, T>,
50} 58}
51 59
52impl<'d, T: CaptureCompare16bitInstance> Qei<'d, T> { 60impl<'d, T: CaptureCompare16bitInstance> Qei<'d, T> {
61 /// Create a new quadrature decoder driver.
53 pub fn new(tim: impl Peripheral<P = T> + 'd, _ch1: QeiPin<'d, T, Ch1>, _ch2: QeiPin<'d, T, Ch2>) -> Self { 62 pub fn new(tim: impl Peripheral<P = T> + 'd, _ch1: QeiPin<'d, T, Ch1>, _ch2: QeiPin<'d, T, Ch2>) -> Self {
54 Self::new_inner(tim) 63 Self::new_inner(tim)
55 } 64 }
@@ -84,6 +93,7 @@ impl<'d, T: CaptureCompare16bitInstance> Qei<'d, T> {
84 Self { _inner: tim } 93 Self { _inner: tim }
85 } 94 }
86 95
96 /// Get direction.
87 pub fn read_direction(&self) -> Direction { 97 pub fn read_direction(&self) -> Direction {
88 match T::regs_gp16().cr1().read().dir() { 98 match T::regs_gp16().cr1().read().dir() {
89 vals::Dir::DOWN => Direction::Downcounting, 99 vals::Dir::DOWN => Direction::Downcounting,
@@ -91,6 +101,7 @@ impl<'d, T: CaptureCompare16bitInstance> Qei<'d, T> {
91 } 101 }
92 } 102 }
93 103
104 /// Get count.
94 pub fn count(&self) -> u16 { 105 pub fn count(&self) -> u16 {
95 T::regs_gp16().cnt().read().cnt() 106 T::regs_gp16().cnt().read().cnt()
96 } 107 }