Lines Matching +full:time +full:- +full:of +full:- +full:flight

1 /* vl53l1.c - Driver for ST VL53L1X time of flight sensor */
6 * SPDX-License-Identifier: Apache-2.0
53 ret = VL53L1_GetRangingMeasurementData(&drv_data->vl53l1x, &drv_data->data); in vl53l1x_read_sensor()
59 ret = VL53L1_ClearInterruptAndStartMeasurement(&drv_data->vl53l1x); in vl53l1x_read_sensor()
81 k_work_submit(&drv_data->work); in vl53l1x_gpio_callback()
86 struct vl53l1x_data *drv_data = dev->data; in vl53l1x_init_interrupt()
87 const struct vl53l1x_config *config = dev->config; in vl53l1x_init_interrupt()
90 drv_data->dev = dev; in vl53l1x_init_interrupt()
92 if (!gpio_is_ready_dt(&config->gpio1)) { in vl53l1x_init_interrupt()
93 LOG_ERR("%s: device %s is not ready", dev->name, config->gpio1.port->name); in vl53l1x_init_interrupt()
94 return -ENODEV; in vl53l1x_init_interrupt()
97 ret = gpio_pin_configure_dt(&config->gpio1, GPIO_INPUT | GPIO_PULL_UP); in vl53l1x_init_interrupt()
99 LOG_ERR("[%s] Unable to configure GPIO interrupt", dev->name); in vl53l1x_init_interrupt()
100 return -EIO; in vl53l1x_init_interrupt()
103 gpio_init_callback(&drv_data->gpio_cb, in vl53l1x_init_interrupt()
105 BIT(config->gpio1.pin)); in vl53l1x_init_interrupt()
107 ret = gpio_add_callback(config->gpio1.port, &drv_data->gpio_cb); in vl53l1x_init_interrupt()
110 return -EIO; in vl53l1x_init_interrupt()
113 drv_data->work.handler = vl53l1x_worker; in vl53l1x_init_interrupt()
121 struct vl53l1x_data *drv_data = dev->data; in vl53l1x_initialize()
125 LOG_DBG("[%s] Initializing ", dev->name); in vl53l1x_initialize()
129 const struct vl53l1x_config *const config = dev->config; in vl53l1x_initialize()
131 if (config->xshut.port) { in vl53l1x_initialize()
132 int gpio_ret = gpio_pin_set_dt(&config->xshut, 1); in vl53l1x_initialize()
135 LOG_ERR("[%s] Unable to set XSHUT gpio (error %d)", dev->name, gpio_ret); in vl53l1x_initialize()
136 return -EIO; in vl53l1x_initialize()
143 /* ONE TIME device initialization. in vl53l1x_initialize()
144 * To be called ONLY ONCE after device is brought out of reset in vl53l1x_initialize()
146 ret = VL53L1_DataInit(&drv_data->vl53l1x); in vl53l1x_initialize()
148 LOG_ERR("[%s] VL53L1X_DataInit return error (%d)", dev->name, ret); in vl53l1x_initialize()
149 return -ENOTSUP; in vl53l1x_initialize()
153 ret = VL53L1_StaticInit(&drv_data->vl53l1x); in vl53l1x_initialize()
155 LOG_ERR("[%s] VL53L1_StaticInit return error (%d)", dev->name, ret); in vl53l1x_initialize()
156 return -ENOTSUP; in vl53l1x_initialize()
162 ret = VL53L1_GetDeviceInfo(&drv_data->vl53l1x, &vl53l1x_dev_info); in vl53l1x_initialize()
164 LOG_ERR("[%s] VL53L1_GetDeviceInfo return error (%d)", dev->name, ret); in vl53l1x_initialize()
165 return -ENODEV; in vl53l1x_initialize()
168 LOG_DBG("[%s] VL53L1X_GetDeviceInfo returned %d", dev->name, ret); in vl53l1x_initialize()
176 drv_data->distance_mode = VL53L1_DISTANCEMODE_LONG; in vl53l1x_initialize()
177 ret = VL53L1_SetDistanceMode(&drv_data->vl53l1x, drv_data->distance_mode); in vl53l1x_initialize()
179 LOG_ERR("[%s] VL53L1_SetDistanceMode return error (%d)", dev->name, ret); in vl53l1x_initialize()
180 return -EINVAL; in vl53l1x_initialize()
190 * ----------------------------------------------------
198 struct vl53l1x_data *drv_data = dev->data; in vl53l1x_set_mode()
201 switch (val->val1) { in vl53l1x_set_mode()
208 drv_data->distance_mode = val->val1; in vl53l1x_set_mode()
211 drv_data->distance_mode = VL53L1_DISTANCEMODE_LONG; in vl53l1x_set_mode()
215 ret = VL53L1_SetDistanceMode(&drv_data->vl53l1x, drv_data->distance_mode); in vl53l1x_set_mode()
217 LOG_ERR("[%s] VL53L1_SetDistanceMode return error (%d)", dev->name, ret); in vl53l1x_set_mode()
218 return -EINVAL; in vl53l1x_set_mode()
227 * a total of 256 squares (numbered 0 through 255).
234 struct vl53l1x_data *drv_data = dev->data; in vl53l1x_set_roi()
237 if ((val->val1 < 0) || in vl53l1x_set_roi()
238 (val->val2 < 0) || in vl53l1x_set_roi()
239 (val->val1 > 255) || in vl53l1x_set_roi()
240 (val->val2 > 255) || in vl53l1x_set_roi()
241 (val->val2 >= val->val1)) { in vl53l1x_set_roi()
242 return -EINVAL; in vl53l1x_set_roi()
247 .TopLeftX = val->val1 % 16, in vl53l1x_set_roi()
248 .TopLeftY = (uint8_t)(val->val1 / 16), in vl53l1x_set_roi()
249 .BotRightX = val->val2 % 16, in vl53l1x_set_roi()
250 .BotRightY = (uint8_t)(val->val2 / 16), in vl53l1x_set_roi()
253 ret = VL53L1_SetUserROI(&drv_data->vl53l1x, &pUserROi); in vl53l1x_set_roi()
255 LOG_ERR("[%s] VL53L1_SetUserROI return error (%d)", dev->name, ret); in vl53l1x_set_roi()
256 return -EINVAL; in vl53l1x_set_roi()
265 struct vl53l1x_data *drv_data = dev->data; in vl53l1x_get_mode()
269 ret = VL53L1_GetDistanceMode(&drv_data->vl53l1x, &mode); in vl53l1x_get_mode()
271 LOG_ERR("[%s] VL53L1_GetDistanceMode return error (%d)", dev->name, ret); in vl53l1x_get_mode()
272 return -ENODATA; in vl53l1x_get_mode()
276 val->val1 = (int32_t)mode; in vl53l1x_get_mode()
277 val->val2 = 0; in vl53l1x_get_mode()
284 struct vl53l1x_data *drv_data = dev->data; in vl53l1x_get_roi()
288 ret = VL53L1_GetUserROI(&drv_data->vl53l1x, &pUserROi); in vl53l1x_get_roi()
290 LOG_ERR("[%s] VL53L1_GetUserROI return error (%d)", dev->name, ret); in vl53l1x_get_roi()
291 return -ENODATA; in vl53l1x_get_roi()
295 val->val1 = (int32_t)((16 * pUserROi.TopLeftY) + pUserROi.TopLeftX); in vl53l1x_get_roi()
296 val->val2 = (int32_t)((16 * pUserROi.BotRightY) + pUserROi.BotRightX); in vl53l1x_get_roi()
303 struct vl53l1x_data *drv_data = dev->data; in vl53l1x_sample_fetch()
310 ret = VL53L1_StopMeasurement(&drv_data->vl53l1x); in vl53l1x_sample_fetch()
313 return -EBUSY; in vl53l1x_sample_fetch()
317 const struct vl53l1x_config *config = dev->config; in vl53l1x_sample_fetch()
319 ret = gpio_pin_interrupt_configure_dt(&config->gpio1, GPIO_INT_EDGE_TO_INACTIVE); in vl53l1x_sample_fetch()
321 LOG_ERR("[%s] Unable to config interrupt", dev->name); in vl53l1x_sample_fetch()
322 return -EIO; in vl53l1x_sample_fetch()
326 ret = VL53L1_StartMeasurement(&drv_data->vl53l1x); in vl53l1x_sample_fetch()
328 LOG_ERR("[%s] VL53L1_StartMeasurement return error (%d)", dev->name, ret); in vl53l1x_sample_fetch()
329 return -EBUSY; in vl53l1x_sample_fetch()
339 struct vl53l1x_data *drv_data = dev->data; in vl53l1x_channel_get()
343 return -ENOTSUP; in vl53l1x_channel_get()
346 /* Calling VL53L1_WaitMeasurementDataReady regardless of using interrupt or in vl53l1x_channel_get()
347 * polling method ensures user does not have to consider the time between in vl53l1x_channel_get()
350 ret = VL53L1_WaitMeasurementDataReady(&drv_data->vl53l1x); in vl53l1x_channel_get()
352 LOG_ERR("[%s] VL53L1_WaitMeasurementDataReady return error (%d)", dev->name, ret); in vl53l1x_channel_get()
353 return -EBUSY; in vl53l1x_channel_get()
360 return -ENODATA; in vl53l1x_channel_get()
364 val->val1 = (int32_t)(drv_data->data.RangeMilliMeter); in vl53l1x_channel_get()
366 val->val2 = 0; in vl53l1x_channel_get()
385 return -ENOTSUP; in vl53l1x_attr_get()
405 return -ENOTSUP; in vl53l1x_attr_set()
421 struct vl53l1x_data *drv_data = dev->data; in vl53l1x_init()
422 const struct vl53l1x_config *config = dev->config; in vl53l1x_init()
425 drv_data->vl53l1x.i2c = &config->i2c; in vl53l1x_init()
427 if (!device_is_ready(config->i2c.bus)) { in vl53l1x_init()
429 return -ENODEV; in vl53l1x_init()
436 if (config->xshut.port) { in vl53l1x_init()
437 ret = gpio_pin_configure_dt(&config->xshut, GPIO_OUTPUT); in vl53l1x_init()
439 LOG_ERR("[%s] Unable to configure GPIO as output", dev->name); in vl53l1x_init()
440 return -EIO; in vl53l1x_init()
446 if (config->gpio1.port) { in vl53l1x_init()
450 return -EIO; in vl53l1x_init()
460 LOG_DBG("[%s] Initialized", dev->name); in vl53l1x_init()