@@ -50,12 +50,12 @@ pub trait HrCapture {
5050 /// <-------------- 0 --------------> t
5151 /// Negative result | positive result
5252 /// ````
53- fn get_signed ( & self ) -> i32 {
53+ fn get_signed ( & self , period : u16 ) -> i32 {
5454 let ( value, dir) = self . get ( ) ;
5555
5656 match dir {
5757 CountingDirection :: Up => i32:: from ( value) ,
58- CountingDirection :: Down => - i32:: from ( value) ,
58+ CountingDirection :: Down => i32 :: from ( period ) - i32:: from ( value) ,
5959 }
6060 }
6161
@@ -66,18 +66,18 @@ pub trait HrCapture {
6666
6767pub fn dma_value_to_dir_and_value ( x : u32 ) -> ( u16 , CountingDirection ) {
6868 let value = ( x & 0xFFFF ) as u16 ;
69- match x & 1 << 16 != 0 {
69+ match x & ( 1 << 16 ) != 0 {
7070 true => ( value, CountingDirection :: Down ) ,
7171 false => ( value, CountingDirection :: Up ) ,
7272 }
7373}
7474
75- pub fn dma_value_to_signed ( x : u32 ) -> i32 {
75+ pub fn dma_value_to_signed ( x : u32 , period : u16 ) -> i32 {
7676 let ( value, dir) = dma_value_to_dir_and_value ( x) ;
7777
7878 match dir {
7979 CountingDirection :: Up => i32:: from ( value) ,
80- CountingDirection :: Down => - i32:: from ( value) ,
80+ CountingDirection :: Down => i32 :: from ( period ) - i32:: from ( value) ,
8181 }
8282}
8383
0 commit comments