MCPcopy Create free account
hub / github.com/RT-Thread/rt-thread / rt_sensor_close

Function rt_sensor_close

components/drivers/sensor/v1/sensor.c:226–283  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

224}
225
226static rt_err_t rt_sensor_close(rt_device_t dev)
227{
228 rt_sensor_t sensor = (rt_sensor_t)dev;
229 int i;
230 rt_err_t (*local_ctrl)(struct rt_sensor_device * sensor, int cmd, void *arg) = local_control;
231
232 RT_ASSERT(dev != RT_NULL);
233
234 if (sensor->module)
235 {
236 rt_mutex_take(sensor->module->lock, RT_WAITING_FOREVER);
237 }
238 if (sensor->ops->control != RT_NULL)
239 {
240 local_ctrl = sensor->ops->control;
241 }
242
243 /* Configure power mode to power down mode */
244 if (local_ctrl(sensor, RT_SENSOR_CTRL_SET_POWER, (void *)RT_SENSOR_POWER_DOWN) == RT_EOK)
245 {
246 sensor->config.power = RT_SENSOR_POWER_DOWN;
247 }
248
249 if (sensor->module != RT_NULL && sensor->info.fifo_max > 0 && sensor->data_buf != RT_NULL)
250 {
251 for (i = 0; i < sensor->module->sen_num; i ++)
252 {
253 if (sensor->module->sen[i]->parent.ref_count > 0)
254 goto __exit;
255 }
256
257 /* Free memory for the sensor buffer */
258 for (i = 0; i < sensor->module->sen_num; i ++)
259 {
260 if (sensor->module->sen[i]->data_buf != RT_NULL)
261 {
262 rt_free(sensor->module->sen[i]->data_buf);
263 sensor->module->sen[i]->data_buf = RT_NULL;
264 }
265 }
266 }
267 if (sensor->config.mode != RT_SENSOR_MODE_POLLING)
268 {
269 /* Sensor disable interrupt */
270 if (sensor->config.irq_pin.pin != RT_PIN_NONE)
271 {
272 rt_pin_irq_enable(sensor->config.irq_pin.pin, RT_FALSE);
273 }
274 }
275
276__exit:
277 if (sensor->module)
278 {
279 rt_mutex_release(sensor->module->lock);
280 }
281
282 return RT_EOK;
283}

Callers

nothing calls this directly

Calls 4

rt_mutex_takeFunction · 0.85
rt_freeFunction · 0.85
rt_pin_irq_enableFunction · 0.85
rt_mutex_releaseFunction · 0.85

Tested by

no test coverage detected