@@ -60,6 +60,11 @@ static void qdec_trigger_handler(const struct device *dev, const struct sensor_t
60
60
61
61
static void qenc_emulate_work_handler (struct k_work * work )
62
62
{
63
+ /* Check if emulation has been stopped after submitting this work item. */
64
+ if (loopback_currently_under_test == NULL ) {
65
+ return ;
66
+ }
67
+
63
68
if (toggle_a ) {
64
69
gpio_pin_toggle_dt (& loopback_currently_under_test -> qenc_phase_a );
65
70
} else {
@@ -113,6 +118,8 @@ static void qenc_emulate_stop(void)
113
118
k_timer_stop (& qenc_emulate_timer );
114
119
qenc_emulate_reset_pin (& loopback_currently_under_test -> qenc_phase_a );
115
120
qenc_emulate_reset_pin (& loopback_currently_under_test -> qenc_phase_b );
121
+
122
+ loopback_currently_under_test = NULL ;
116
123
}
117
124
}
118
125
@@ -218,6 +225,9 @@ static void sensor_trigger_set_and_disable(struct qdec_qenc_loopback *loopback)
218
225
if (IS_ENABLED (CONFIG_PM_DEVICE_RUNTIME )) {
219
226
pm_device_runtime_put (loopback -> qdec );
220
227
}
228
+
229
+ qenc_emulate_stop ();
230
+ k_sem_reset (& sem );
221
231
}
222
232
223
233
/**
@@ -270,8 +280,7 @@ static void sensor_trigger_set_test(struct qdec_qenc_loopback *loopback)
270
280
}
271
281
272
282
qenc_emulate_stop ();
273
- /* emulation not working, but there may be old trigger which needs to be cleaned up */
274
- rc = k_sem_take (& sem , K_MSEC (200 ));
283
+ k_sem_reset (& sem );
275
284
}
276
285
277
286
/**
@@ -571,6 +580,7 @@ static void after(void *fixture)
571
580
ARG_UNUSED (fixture );
572
581
573
582
qenc_emulate_stop ();
583
+ k_sem_reset (& sem );
574
584
}
575
585
576
586
ZTEST_SUITE (qdec_sensor , NULL , setup , before , after , NULL );
0 commit comments