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