Lines Matching +full:pre +full:- +full:fetch
1 /* vl53l0x.c - Driver for ST VL53L0X time of flight sensor */
8 * SPDX-License-Identifier: Apache-2.0
31 * https://www.st.com/en/embedded-software/stsw-img005.html
33 * https://www.st.com/en/embedded-software/stm32cubel4.html
60 struct vl53l0x_data *drv_data = dev->data; in vl53l0x_setup_single_shot()
67 ret = VL53L0X_StaticInit(&drv_data->vl53l0x); in vl53l0x_setup_single_shot()
70 dev->name); in vl53l0x_setup_single_shot()
74 ret = VL53L0X_PerformRefCalibration(&drv_data->vl53l0x, in vl53l0x_setup_single_shot()
79 dev->name); in vl53l0x_setup_single_shot()
83 ret = VL53L0X_PerformRefSpadManagement(&drv_data->vl53l0x, in vl53l0x_setup_single_shot()
88 dev->name); in vl53l0x_setup_single_shot()
92 ret = VL53L0X_SetDeviceMode(&drv_data->vl53l0x, in vl53l0x_setup_single_shot()
96 dev->name); in vl53l0x_setup_single_shot()
100 ret = VL53L0X_SetLimitCheckEnable(&drv_data->vl53l0x, in vl53l0x_setup_single_shot()
105 dev->name); in vl53l0x_setup_single_shot()
109 ret = VL53L0X_SetLimitCheckEnable(&drv_data->vl53l0x, in vl53l0x_setup_single_shot()
114 dev->name); in vl53l0x_setup_single_shot()
118 ret = VL53L0X_SetLimitCheckValue(&drv_data->vl53l0x, in vl53l0x_setup_single_shot()
124 dev->name); in vl53l0x_setup_single_shot()
128 ret = VL53L0X_SetLimitCheckValue(&drv_data->vl53l0x, in vl53l0x_setup_single_shot()
133 dev->name); in vl53l0x_setup_single_shot()
137 ret = VL53L0X_SetMeasurementTimingBudgetMicroSeconds(&drv_data->vl53l0x, in vl53l0x_setup_single_shot()
141 dev->name); in vl53l0x_setup_single_shot()
145 ret = VL53L0X_SetVcselPulsePeriod(&drv_data->vl53l0x, in vl53l0x_setup_single_shot()
149 LOG_ERR("[%s] VL53L0X_SetVcselPulsePeriod pre range failed", in vl53l0x_setup_single_shot()
150 dev->name); in vl53l0x_setup_single_shot()
154 ret = VL53L0X_SetVcselPulsePeriod(&drv_data->vl53l0x, in vl53l0x_setup_single_shot()
159 dev->name); in vl53l0x_setup_single_shot()
169 const struct vl53l0x_config *const config = dev->config; in vl53l0x_start()
170 struct vl53l0x_data *drv_data = dev->data; in vl53l0x_start()
176 LOG_DBG("[%s] Starting", dev->name); in vl53l0x_start()
178 if (config->xshut.port) { in vl53l0x_start()
179 r = gpio_pin_configure_dt(&config->xshut, GPIO_OUTPUT_INACTIVE); in vl53l0x_start()
182 dev->name, r); in vl53l0x_start()
183 return -EIO; in vl53l0x_start()
189 if (config->i2c.addr != VL53L0X_INITIAL_ADDR) { in vl53l0x_start()
190 ret = VL53L0X_SetDeviceAddress(&drv_data->vl53l0x, 2 * config->i2c.addr); in vl53l0x_start()
193 dev->name); in vl53l0x_start()
194 return -EIO; in vl53l0x_start()
197 drv_data->vl53l0x.I2cDevAddr = config->i2c.addr; in vl53l0x_start()
198 LOG_DBG("[%s] I2C address reconfigured", dev->name); in vl53l0x_start()
203 ret = VL53L0X_GetDeviceInfo(&drv_data->vl53l0x, &vl53l0x_dev_info); in vl53l0x_start()
205 LOG_ERR("[%s] Could not get info from device.", dev->name); in vl53l0x_start()
206 return -ENODEV; in vl53l0x_start()
209 LOG_DBG("[%s] VL53L0X_GetDeviceInfo = %d", dev->name, ret); in vl53l0x_start()
218 ret = VL53L0X_RdWord(&drv_data->vl53l0x, in vl53l0x_start()
222 LOG_ERR("[%s] Issue on device identification", dev->name); in vl53l0x_start()
223 return -ENOTSUP; in vl53l0x_start()
227 ret = VL53L0X_DataInit(&drv_data->vl53l0x); in vl53l0x_start()
230 dev->name, ret); in vl53l0x_start()
231 return -ENOTSUP; in vl53l0x_start()
236 return -ENOTSUP; in vl53l0x_start()
239 drv_data->started = true; in vl53l0x_start()
240 LOG_DBG("[%s] Started", dev->name); in vl53l0x_start()
247 struct vl53l0x_data *drv_data = dev->data; in vl53l0x_sample_fetch()
255 if (!drv_data->started) { in vl53l0x_sample_fetch()
262 ret = VL53L0X_PerformSingleRangingMeasurement(&drv_data->vl53l0x, in vl53l0x_sample_fetch()
263 &drv_data->RangingMeasurementData); in vl53l0x_sample_fetch()
266 dev->name, ret); in vl53l0x_sample_fetch()
267 return -EINVAL; in vl53l0x_sample_fetch()
278 struct vl53l0x_data *drv_data = dev->data; in vl53l0x_channel_get()
281 if (drv_data->RangingMeasurementData.RangeMilliMeter <= in vl53l0x_channel_get()
283 val->val1 = 1; in vl53l0x_channel_get()
285 val->val1 = 0; in vl53l0x_channel_get()
287 val->val2 = 0; in vl53l0x_channel_get()
289 val->val1 = drv_data->RangingMeasurementData.RangeMilliMeter / 1000; in vl53l0x_channel_get()
290 val->val2 = (drv_data->RangingMeasurementData.RangeMilliMeter % 1000) * 1000; in vl53l0x_channel_get()
292 return -ENOTSUP; in vl53l0x_channel_get()
306 struct vl53l0x_data *drv_data = dev->data; in vl53l0x_init()
307 const struct vl53l0x_config *const config = dev->config; in vl53l0x_init()
312 drv_data->vl53l0x.I2cDevAddr = VL53L0X_INITIAL_ADDR; in vl53l0x_init()
313 drv_data->vl53l0x.i2c = config->i2c.bus; in vl53l0x_init()
316 if (config->xshut.port == NULL) { in vl53l0x_init()
317 LOG_ERR("[%s] Missing XSHUT gpio spec", dev->name); in vl53l0x_init()
318 return -ENOTSUP; in vl53l0x_init()
324 * Shutdown all vl53l0x sensors so at each sensor's 1st fetch call in vl53l0x_init()
327 r = gpio_pin_configure_dt(&config->xshut, GPIO_OUTPUT_ACTIVE); in vl53l0x_init()
329 LOG_ERR("[%s] Unable to shutdown sensor", dev->name); in vl53l0x_init()
330 return -EIO; in vl53l0x_init()
332 LOG_DBG("[%s] Shutdown", dev->name); in vl53l0x_init()
334 if (config->i2c.addr != VL53L0X_INITIAL_ADDR) { in vl53l0x_init()
337 dev->name, VL53L0X_INITIAL_ADDR); in vl53l0x_init()
338 return -ENOTSUP; in vl53l0x_init()
347 LOG_DBG("[%s] Initialized", dev->name); in vl53l0x_init()
355 const struct vl53l0x_config *const config = dev->config; in vl53l0x_pm_action()
367 ret = gpio_pin_set_dt(&config->xshut, 1); in vl53l0x_pm_action()
369 LOG_ERR("[%s] XSHUT pin active", dev->name); in vl53l0x_pm_action()
373 ret = -ENOTSUP; in vl53l0x_pm_action()