forked from zephyrproject-rtos/zephyr
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathsensing_sensor.c
65 lines (54 loc) · 1.61 KB
/
sensing_sensor.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
/*
* Copyright (c) 2023 Intel Corporation.
*
* SPDX-License-Identifier: Apache-2.0
*/
#include <zephyr/kernel.h>
#include <zephyr/sensing/sensing.h>
#include <zephyr/sensing/sensing_sensor.h>
#include <zephyr/sys/__assert.h>
#include <zephyr/logging/log.h>
#include "sensor_mgmt.h"
LOG_MODULE_DECLARE(sensing, CONFIG_SENSING_LOG_LEVEL);
static void sensing_iodev_submit(struct rtio_iodev_sqe *iodev_sqe)
{
struct sensing_sensor *sensor = (struct sensing_sensor *)iodev_sqe->sqe.userdata;
const struct device *dev = sensor->dev;
const struct sensor_driver_api *api = dev->api;
if (api->submit != NULL) {
api->submit(dev, iodev_sqe);
} else {
LOG_ERR("submit function not supported for device %p %s!\n", dev, dev->name);
rtio_iodev_sqe_err(iodev_sqe, -ENOTSUP);
}
}
const struct rtio_iodev_api __sensing_iodev_api = {
.submit = sensing_iodev_submit,
};
int sensing_sensor_get_reporters(const struct device *dev, int type,
sensing_sensor_handle_t *reporter_handles,
int max_handles)
{
struct sensing_sensor *sensor = get_sensor_by_dev(dev);
int i, num = 0;
for (i = 0; i < sensor->reporter_num && num < max_handles; ++i) {
if (type == sensor->conns[i].source->info->type
|| type == SENSING_SENSOR_TYPE_ALL) {
reporter_handles[num] = &sensor->conns[i];
num++;
}
}
return num;
}
int sensing_sensor_get_reporters_count(const struct device *dev, int type)
{
struct sensing_sensor *sensor = get_sensor_by_dev(dev);
int i, num = 0;
for (i = 0; i < sensor->reporter_num; ++i) {
if (type == sensor->conns[i].source->info->type
|| type == SENSING_SENSOR_TYPE_ALL) {
num++;
}
}
return num;
}