File tree Expand file tree Collapse file tree 2 files changed +17
-0
lines changed Expand file tree Collapse file tree 2 files changed +17
-0
lines changed Original file line number Diff line number Diff line change @@ -6,6 +6,8 @@ use crate::{
6
6
} ;
7
7
8
8
pub trait QeiExt : Sized + Instance {
9
+ type Count ;
10
+
9
11
fn qei (
10
12
self ,
11
13
pins : (
@@ -16,6 +18,8 @@ pub trait QeiExt: Sized + Instance {
16
18
}
17
19
18
20
impl < TIM : Instance > QeiExt for TIM {
21
+ type Count = TIM :: Width ;
22
+
19
23
fn qei (
20
24
self ,
21
25
pins : (
@@ -70,6 +74,12 @@ impl<TIM: Instance> Qei<TIM> {
70
74
) {
71
75
( self . tim , self . pins )
72
76
}
77
+
78
+ /// Set current count number
79
+ pub fn set_count ( & mut self , value : TIM :: Width ) -> & mut Self {
80
+ self . tim . write_count ( value) ;
81
+ self
82
+ }
73
83
}
74
84
75
85
impl < TIM : Instance > embedded_hal:: Qei for Qei < TIM > {
Original file line number Diff line number Diff line change @@ -273,6 +273,7 @@ mod sealed {
273
273
fn listen_interrupt ( & mut self , event : Event , b : bool ) ;
274
274
fn get_interrupt_flag ( & self ) -> Event ;
275
275
fn read_count ( & self ) -> Self :: Width ;
276
+ fn write_count ( & mut self , value : Self :: Width ) ;
276
277
fn start_one_pulse ( & mut self ) ;
277
278
fn start_free ( & mut self , update : bool ) ;
278
279
fn cr1_reset ( & mut self ) ;
@@ -405,6 +406,12 @@ macro_rules! hal {
405
406
self . cnt. read( ) . bits( ) as Self :: Width
406
407
}
407
408
#[ 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) ]
408
415
fn start_one_pulse( & mut self ) {
409
416
self . cr1. modify( |_, w| unsafe { w. bits( 1 << 3 ) } . cen( ) . set_bit( ) ) ;
410
417
}
You can’t perform that action at this time.
0 commit comments