@@ -367,7 +367,8 @@ static pbio_error_t pbdrv_imu_lsm6ds3tr_c_stm32_process_thread(pbio_os_state_t *
367367 // value each time we want to read new data. This saves CPU usage since
368368 // we have fewer interrupts per sample.
369369
370- for (;;) {
370+ while (!(pbdrv_imu_lsm6ds3tr_c_stm32_process .request & PBIO_OS_PROCESS_REQUEST_TYPE_CANCEL )) {
371+
371372 PBIO_OS_AWAIT_UNTIL (state , atomic_exchange (& imu_dev -> int1 , false));
372373
373374 imu_dev -> ctx .read_write_done = false;
@@ -403,8 +404,10 @@ static pbio_error_t pbdrv_imu_lsm6ds3tr_c_stm32_process_thread(pbio_os_state_t *
403404 }
404405 }
405406
406- // Unreachable
407- PBIO_OS_ASYNC_END (PBIO_ERROR_FAILED );
407+ // Cancellation complete.
408+ pbdrv_imu_lsm6ds3tr_c_stm32_i2c_reset (hi2c );
409+ pbdrv_init_busy_down ();
410+ PBIO_OS_ASYNC_END (PBIO_ERROR_CANCELED );
408411}
409412
410413// internal driver interface implementation
@@ -414,6 +417,11 @@ void pbdrv_imu_init(void) {
414417 pbio_os_process_start (& pbdrv_imu_lsm6ds3tr_c_stm32_process , pbdrv_imu_lsm6ds3tr_c_stm32_process_thread , NULL );
415418}
416419
420+ void pbdrv_imu_deinit (void ) {
421+ pbdrv_init_busy_up ();
422+ pbio_os_process_make_request (& pbdrv_imu_lsm6ds3tr_c_stm32_process , PBIO_OS_PROCESS_REQUEST_TYPE_CANCEL );
423+ }
424+
417425// public driver interface implementation
418426
419427pbio_error_t pbdrv_imu_get_imu (pbdrv_imu_dev_t * * imu_dev , pbdrv_imu_config_t * * config ) {
0 commit comments