@@ -47,7 +47,7 @@ impl<D: DurationTicks> TimerBuilder<D> {
4747 /// Note that the newly created timer must be started.
4848 pub fn create < F > ( & self , callback : F ) -> Result < Timer , FreeRtosError >
4949 where
50- F : Fn ( Timer ) -> ( ) ,
50+ F : Fn ( & Timer ) -> ( ) ,
5151 F : Send + ' static ,
5252 {
5353 Timer :: spawn (
@@ -87,7 +87,7 @@ impl Timer {
8787 name : & str ,
8888 period_ticks : FreeRtosTickType ,
8989 auto_reload : bool ,
90- callback : Box < dyn Fn ( Timer ) + Send + ' a > ,
90+ callback : Box < dyn Fn ( & Timer ) + Send + ' a > ,
9191 ) -> Result < Timer , FreeRtosError > {
9292 let f = Box :: new ( callback) ;
9393 let param_ptr = & * f as * const _ as * mut _ ;
@@ -119,10 +119,11 @@ impl Timer {
119119 {
120120 let timer = Timer { handle } ;
121121 if let Ok ( callback_ptr) = timer. get_id ( ) {
122- let b = Box :: from_raw ( callback_ptr as * mut Box < dyn Fn ( Timer ) > ) ;
123- b ( timer) ;
122+ let b = Box :: from_raw ( callback_ptr as * mut Box < dyn Fn ( & Timer ) > ) ;
123+ b ( & timer) ;
124124 let _ = Box :: into_raw ( b) ;
125125 }
126+ mem:: forget ( timer) ;
126127 }
127128 }
128129 }
@@ -139,7 +140,7 @@ impl Timer {
139140 callback : F ,
140141 ) -> Result < Timer , FreeRtosError >
141142 where
142- F : Fn ( Timer ) -> ( ) ,
143+ F : Fn ( & Timer ) -> ( ) ,
143144 F : Send + ' static ,
144145 {
145146 unsafe { Timer :: spawn_inner ( name, period_tick, auto_reload, Box :: new ( callback) ) }
0 commit comments