8#include <nuttx/sensors/sensor.h>
15#include "dawn/debug.hxx"
16#include "dawn/porting/config.hxx"
26int sensor_open(
const char *path)
30 fd = open(path, O_CLOEXEC | O_RDWR | O_NONBLOCK);
31 DAWNINFO(
"CIOSensor: open %s %d\n", path, fd);
34 DAWNERR(
"Failed to open SENSOR file %s (error %d)\n", path, fd);
44void sensor_close(
int fd)
56int sensor_read(
int fd,
void *data,
size_t len)
60 ret = read(fd, data, len);
63 DAWNERR(
"read failed %d\n", -errno);
67 return static_cast<int>(ret);
74int sensor_set_interval(
int fd, uint32_t interval_us)
78 ret = ioctl(fd, SNIOC_SET_INTERVAL,
static_cast<unsigned long>(interval_us));
81 DAWNERR(
"SNIOC_SET_INTERVAL failed %d\n", -errno);
92int sensor_gnss_set_priority(
int fd,
bool on)
96 ret = ioctl(fd, SNIOC_GNSS_SET_PRIORITY,
static_cast<unsigned long>(on));
99 DAWNERR(
"SNIOC_GNSS_SET_PRIORITY failed %d\n", -errno);
111int sensor_user_register(
const char *path,
size_t event_size, uint32_t queue_size,
bool persist)
113 struct sensor_reginfo_s reginfo;
118 std::memset(®info, 0,
sizeof(reginfo));
119 strlcpy(reginfo.path, path,
sizeof(reginfo.path));
120 reginfo.esize = event_size;
121 reginfo.nbuffer = queue_size;
122 reginfo.persist = persist;
124 fd = open(
"/dev/usensor", O_CLOEXEC | O_WRONLY);
127 DAWNERR(
"Failed to open /dev/usensor (error %d)\n", -errno);
132 ioctl(fd, SNIOC_REGISTER,
static_cast<unsigned long>(
reinterpret_cast<uintptr_t
>(®info)));
147int sensor_user_unregister(
const char *path)
153 fd = open(
"/dev/usensor", O_CLOEXEC | O_WRONLY);
159 ret = ioctl(fd, SNIOC_UNREGISTER,
static_cast<unsigned long>(
reinterpret_cast<uintptr_t
>(path)));
175int sensor_open_write(
const char *path)
179 fd = open(path, O_CLOEXEC | O_WRONLY | O_NONBLOCK);
180 DAWNINFO(
"CIOSensorProducer: open %s %d\n", path, fd);
183 DAWNERR(
"Failed to open SENSOR producer file %s (error %d)\n", path, fd);
194int sensor_write(
int fd,
const void *data,
size_t len)
198 ret = write(fd, data, len);
201 DAWNERR(
"write failed %d\n", -errno);
205 return static_cast<int>(ret);