@@ -47,7 +47,7 @@ impl<D: DurationTicks> TimerBuilder<D> {
47
47
/// Note that the newly created timer must be started.
48
48
pub fn create < F > ( & self , callback : F ) -> Result < Timer , FreeRtosError >
49
49
where
50
- F : Fn ( Timer ) -> ( ) ,
50
+ F : Fn ( & Timer ) -> ( ) ,
51
51
F : Send + ' static ,
52
52
{
53
53
Timer :: spawn (
@@ -87,7 +87,7 @@ impl Timer {
87
87
name : & str ,
88
88
period_ticks : FreeRtosTickType ,
89
89
auto_reload : bool ,
90
- callback : Box < dyn Fn ( Timer ) + Send + ' a > ,
90
+ callback : Box < dyn Fn ( & Timer ) + Send + ' a > ,
91
91
) -> Result < Timer , FreeRtosError > {
92
92
let f = Box :: new ( callback) ;
93
93
let param_ptr = & * f as * const _ as * mut _ ;
@@ -119,10 +119,11 @@ impl Timer {
119
119
{
120
120
let timer = Timer { handle } ;
121
121
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) ;
124
124
let _ = Box :: into_raw ( b) ;
125
125
}
126
+ mem:: forget ( timer) ;
126
127
}
127
128
}
128
129
}
@@ -139,7 +140,7 @@ impl Timer {
139
140
callback : F ,
140
141
) -> Result < Timer , FreeRtosError >
141
142
where
142
- F : Fn ( Timer ) -> ( ) ,
143
+ F : Fn ( & Timer ) -> ( ) ,
143
144
F : Send + ' static ,
144
145
{
145
146
unsafe { Timer :: spawn_inner ( name, period_tick, auto_reload, Box :: new ( callback) ) }
0 commit comments