Merge pull request #2609 from openmv/tof_fixes
Some checks failed
🔎 Check Code Formatting / formatting-check (push) Has been cancelled
🔥 Firmware Build / build-firmware (ARDUINO_GIGA) (push) Has been cancelled
🔥 Firmware Build / build-firmware (ARDUINO_NANO_33_BLE_SENSE) (push) Has been cancelled
🔥 Firmware Build / build-firmware (ARDUINO_NANO_RP2040_CONNECT) (push) Has been cancelled
🔥 Firmware Build / build-firmware (ARDUINO_NICLA_VISION) (push) Has been cancelled
🔥 Firmware Build / build-firmware (ARDUINO_PORTENTA_H7) (push) Has been cancelled
🔥 Firmware Build / build-firmware (OPENMV2) (push) Has been cancelled
🔥 Firmware Build / build-firmware (OPENMV3) (push) Has been cancelled
🔥 Firmware Build / build-firmware (OPENMV4) (push) Has been cancelled
🔥 Firmware Build / build-firmware (OPENMV4P) (push) Has been cancelled
🔥 Firmware Build / build-firmware (OPENMVPT) (push) Has been cancelled
🔥 Firmware Build / build-firmware (OPENMV_RT1060) (push) Has been cancelled
🔥 Firmware Build / code-size-report (push) Has been cancelled
🔥 Firmware Build / stable-release (push) Has been cancelled
🔥 Firmware Build / development-release (push) Has been cancelled

drivers/vl53l5cx: Add shutdown function and fix deinit.
This commit is contained in:
Ibrahim Abdelkader 2025-02-13 10:00:38 +02:00 committed by GitHub
commit a9f3191809
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 23 additions and 4 deletions

View File

@ -48,6 +48,7 @@ typedef struct {
} VL53L5CX_Platform;
void vl53l5cx_reset(VL53L5CX_Platform *platform);
void vl53l5cx_shutdown(VL53L5CX_Platform *platform);
void vl53l5cx_swap(uint8_t *buf, uint16_t size);
uint8_t vl53l5cx_read(VL53L5CX_Platform *platform, uint16_t addr, uint8_t *buf, uint32_t size);
uint8_t vl53l5cx_write(VL53L5CX_Platform *platform, uint16_t addr, uint8_t *buf, uint32_t size);

View File

@ -47,6 +47,13 @@ void vl53l5cx_reset(VL53L5CX_Platform *platform) {
#endif
}
void vl53l5cx_shutdown(VL53L5CX_Platform *platform) {
#if defined(OMV_TOF_POWER_PIN)
omv_gpio_config(OMV_TOF_POWER_PIN, OMV_GPIO_MODE_OUTPUT, OMV_GPIO_PULL_NONE, OMV_GPIO_SPEED_LOW, -1);
omv_gpio_write(OMV_TOF_POWER_PIN, 0);
#endif
}
void vl53l5cx_swap(uint8_t *buf, uint16_t size) {
for (size_t i=0; i<size; i++) {
((uint32_t *) buf)[i] = __REV(((uint32_t *) buf)[i]);

View File

@ -197,7 +197,7 @@ static mp_obj_t tof_get_depth_obj(int w, int h, float *frame, bool mirror,
}
#endif
static mp_obj_t py_tof_deinit() {
static mp_obj_t py_tof_reset() {
tof_width = 0;
tof_height = 0;
tof_transposed = false;
@ -216,6 +216,17 @@ static mp_obj_t py_tof_deinit() {
#endif
return mp_const_none;
}
static MP_DEFINE_CONST_FUN_OBJ_0(py_tof_reset_obj, py_tof_reset);
static mp_obj_t py_tof_deinit() {
tof_width = 0;
tof_height = 0;
tof_transposed = false;
#if (OMV_TOF_VL53L5CX_ENABLE == 1)
vl53l5cx_shutdown(&vl53l5cx_dev.platform);
#endif
return mp_const_none;
}
static MP_DEFINE_CONST_FUN_OBJ_0(py_tof_deinit_obj, py_tof_deinit);
mp_obj_t py_tof_init(uint n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
@ -228,7 +239,7 @@ mp_obj_t py_tof_init(uint n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)];
mp_arg_parse_all(n_args, pos_args, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args);
py_tof_deinit();
py_tof_reset();
bool first_init = true;
int type = args[ARG_type].u_int;
@ -302,7 +313,7 @@ mp_obj_t py_tof_init(uint n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
omv_i2c_pulse_scl(&tof_bus);
goto TOF_VL53L5CX_RETRY;
} else if (error != 0) {
py_tof_deinit();
py_tof_reset();
mp_raise_msg(&mp_type_RuntimeError, MP_ERROR_TEXT("Failed to init the VL53L5CX"));
}
tof_sensor = TOF_VL53L5CX;
@ -579,7 +590,7 @@ static const mp_rom_map_elem_t globals_dict_table[] = {
{ MP_ROM_QSTR(MP_QSTR_TOF_VL53L5CX), MP_ROM_INT(TOF_VL53L5CX) },
#endif
{ MP_ROM_QSTR(MP_QSTR_init), MP_ROM_PTR(&py_tof_init_obj) },
{ MP_ROM_QSTR(MP_QSTR_reset), MP_ROM_PTR(&py_tof_init_obj) },
{ MP_ROM_QSTR(MP_QSTR_reset), MP_ROM_PTR(&py_tof_reset_obj) },
{ MP_ROM_QSTR(MP_QSTR_deinit), MP_ROM_PTR(&py_tof_deinit_obj) },
{ MP_ROM_QSTR(MP_QSTR_type), MP_ROM_PTR(&py_tof_type_obj) },
{ MP_ROM_QSTR(MP_QSTR_width), MP_ROM_PTR(&py_tof_width_obj) },