driver/sensor: add struct file for all sensor_ops_s

Signed-off-by: Jiuzhu Dong <dongjiuzhu1@xiaomi.com>
This commit is contained in:
Jiuzhu Dong
2022-04-14 11:58:35 +08:00
committed by Xiang Xiao
parent bb07354198
commit 2ae5a82607
7 changed files with 54 additions and 19 deletions
+6
View File
@@ -160,10 +160,13 @@ static int bmp280_putreg8(FAR struct bmp280_dev_s *priv, uint8_t regaddr,
/* Sensor methods */ /* Sensor methods */
static int bmp280_set_interval(FAR struct sensor_lowerhalf_s *lower, static int bmp280_set_interval(FAR struct sensor_lowerhalf_s *lower,
FAR struct file *filep,
FAR unsigned long *period_us); FAR unsigned long *period_us);
static int bmp280_activate(FAR struct sensor_lowerhalf_s *lower, static int bmp280_activate(FAR struct sensor_lowerhalf_s *lower,
FAR struct file *filep,
bool enable); bool enable);
static int bmp280_fetch(FAR struct sensor_lowerhalf_s *lower, static int bmp280_fetch(FAR struct sensor_lowerhalf_s *lower,
FAR struct file *filep,
FAR char *buffer, size_t buflen); FAR char *buffer, size_t buflen);
/**************************************************************************** /****************************************************************************
@@ -504,6 +507,7 @@ static uint32_t bmp280_compensate_press(FAR struct bmp280_dev_s *priv,
****************************************************************************/ ****************************************************************************/
static int bmp280_set_interval(FAR struct sensor_lowerhalf_s *lower, static int bmp280_set_interval(FAR struct sensor_lowerhalf_s *lower,
FAR struct file *filep,
FAR unsigned long *period_us) FAR unsigned long *period_us)
{ {
FAR struct bmp280_dev_s *priv = container_of(lower, FAR struct bmp280_dev_s *priv = container_of(lower,
@@ -557,6 +561,7 @@ static int bmp280_set_interval(FAR struct sensor_lowerhalf_s *lower,
****************************************************************************/ ****************************************************************************/
static int bmp280_activate(FAR struct sensor_lowerhalf_s *lower, static int bmp280_activate(FAR struct sensor_lowerhalf_s *lower,
FAR struct file *filep,
bool enable) bool enable)
{ {
FAR struct bmp280_dev_s *priv = container_of(lower, FAR struct bmp280_dev_s *priv = container_of(lower,
@@ -591,6 +596,7 @@ static int bmp280_activate(FAR struct sensor_lowerhalf_s *lower,
****************************************************************************/ ****************************************************************************/
static int bmp280_fetch(FAR struct sensor_lowerhalf_s *lower, static int bmp280_fetch(FAR struct sensor_lowerhalf_s *lower,
FAR struct file *filep,
FAR char *buffer, size_t buflen) FAR char *buffer, size_t buflen)
{ {
FAR struct bmp280_dev_s *priv = container_of(lower, FAR struct bmp280_dev_s *priv = container_of(lower,
+15 -6
View File
@@ -158,16 +158,20 @@ struct ds18b20_dev_s
/* Sensor functions */ /* Sensor functions */
static int ds18b20_active(FAR struct sensor_lowerhalf_s *lower, static int ds18b20_active(FAR struct sensor_lowerhalf_s *lower,
FAR struct file *filep,
bool enabled); bool enabled);
static int ds18b20_fetch(FAR struct sensor_lowerhalf_s *lower, static int ds18b20_fetch(FAR struct sensor_lowerhalf_s *lower,
FAR struct file *filep,
FAR char *buffer, size_t buflen); FAR char *buffer, size_t buflen);
static int ds18b20_control(FAR struct sensor_lowerhalf_s *lower, static int ds18b20_control(FAR struct sensor_lowerhalf_s *lower,
FAR struct file *filep,
int cmd, unsigned long arg); int cmd, unsigned long arg);
#ifdef CONFIG_SENSORS_DS18B20_POLL #ifdef CONFIG_SENSORS_DS18B20_POLL
static int ds18b20_set_interval(FAR struct sensor_lowerhalf_s *lower, static int ds18b20_set_interval(FAR struct sensor_lowerhalf_s *lower,
FAR struct file *filep,
FAR unsigned long *period_us); FAR unsigned long *period_us);
#endif #endif
@@ -623,16 +627,18 @@ static int ds18b20_measure_read(FAR struct ds18b20_dev_s *dev,
* conversion. * conversion.
* *
* Parameter: * Parameter:
* lower - Pointer to lower half sensor driver instance * lower - Pointer to lower half sensor driver instance.
* buffer - Pointer to the buffer for reading data * filep - The pointer of file, represents each user using the sensor.
* buflen - Size of the buffer * buffer - Pointer to the buffer for reading data.
* buflen - Size of the buffer.
* *
* Return: * Return:
* OK - on success * OK - on success
****************************************************************************/ ****************************************************************************/
static int ds18b20_fetch(FAR struct sensor_lowerhalf_s *lower, static int ds18b20_fetch(FAR struct sensor_lowerhalf_s *lower,
FAR char *buffer, size_t buflen) FAR struct file *filep,
FAR char *buffer, size_t buflen)
{ {
int ret; int ret;
struct ds18b20_sensor_data_s data; struct ds18b20_sensor_data_s data;
@@ -673,7 +679,8 @@ static int ds18b20_fetch(FAR struct sensor_lowerhalf_s *lower,
****************************************************************************/ ****************************************************************************/
static int ds18b20_control(FAR struct sensor_lowerhalf_s *lower, static int ds18b20_control(FAR struct sensor_lowerhalf_s *lower,
int cmd, unsigned long arg) FAR struct file *filep,
int cmd, unsigned long arg)
{ {
int ret; int ret;
struct ds18b20_dev_s *priv = (FAR struct ds18b20_dev_s *)lower; struct ds18b20_dev_s *priv = (FAR struct ds18b20_dev_s *)lower;
@@ -740,6 +747,7 @@ static int ds18b20_control(FAR struct sensor_lowerhalf_s *lower,
****************************************************************************/ ****************************************************************************/
static int ds18b20_active(FAR struct sensor_lowerhalf_s *lower, static int ds18b20_active(FAR struct sensor_lowerhalf_s *lower,
FAR struct file *filep,
bool enabled) bool enabled)
{ {
#ifdef CONFIG_SENSORS_DS18B20_POLL #ifdef CONFIG_SENSORS_DS18B20_POLL
@@ -778,7 +786,8 @@ static int ds18b20_active(FAR struct sensor_lowerhalf_s *lower,
#ifdef CONFIG_SENSORS_DS18B20_POLL #ifdef CONFIG_SENSORS_DS18B20_POLL
static int ds18b20_set_interval(FAR struct sensor_lowerhalf_s *lower, static int ds18b20_set_interval(FAR struct sensor_lowerhalf_s *lower,
FAR unsigned long *period_us) FAR struct file *filep,
FAR unsigned long *period_us)
{ {
FAR struct ds18b20_dev_s *priv = (FAR struct ds18b20_dev_s *)lower; FAR struct ds18b20_dev_s *priv = (FAR struct ds18b20_dev_s *)lower;
priv->interval = *period_us; priv->interval = *period_us;
+7 -2
View File
@@ -60,10 +60,12 @@ struct fakesensor_s
****************************************************************************/ ****************************************************************************/
static int fakesensor_activate(FAR struct sensor_lowerhalf_s *lower, static int fakesensor_activate(FAR struct sensor_lowerhalf_s *lower,
bool sw); FAR struct file *filep, bool sw);
static int fakesensor_set_interval(FAR struct sensor_lowerhalf_s *lower, static int fakesensor_set_interval(FAR struct sensor_lowerhalf_s *lower,
FAR struct file *filep,
FAR unsigned long *period_us); FAR unsigned long *period_us);
static int fakesensor_batch(FAR struct sensor_lowerhalf_s *lower, static int fakesensor_batch(FAR struct sensor_lowerhalf_s *lower,
FAR struct file *filep,
FAR unsigned long *latency_us); FAR unsigned long *latency_us);
static void fakesensor_push_event(FAR struct sensor_lowerhalf_s *lower); static void fakesensor_push_event(FAR struct sensor_lowerhalf_s *lower);
static int fakesensor_thread(int argc, char** argv); static int fakesensor_thread(int argc, char** argv);
@@ -213,7 +215,8 @@ static inline void fakesensor_read_gps(FAR struct fakesensor_s *sensor)
sizeof(struct sensor_gps)); sizeof(struct sensor_gps));
} }
static int fakesensor_activate(FAR struct sensor_lowerhalf_s *lower, bool sw) static int fakesensor_activate(FAR struct sensor_lowerhalf_s *lower,
FAR struct file *filep, bool sw)
{ {
FAR struct fakesensor_s *sensor = container_of(lower, FAR struct fakesensor_s *sensor = container_of(lower,
struct fakesensor_s, lower); struct fakesensor_s, lower);
@@ -234,6 +237,7 @@ static int fakesensor_activate(FAR struct sensor_lowerhalf_s *lower, bool sw)
} }
static int fakesensor_set_interval(FAR struct sensor_lowerhalf_s *lower, static int fakesensor_set_interval(FAR struct sensor_lowerhalf_s *lower,
FAR struct file *filep,
FAR unsigned long *period_us) FAR unsigned long *period_us)
{ {
FAR struct fakesensor_s *sensor = container_of(lower, FAR struct fakesensor_s *sensor = container_of(lower,
@@ -243,6 +247,7 @@ static int fakesensor_set_interval(FAR struct sensor_lowerhalf_s *lower,
} }
static int fakesensor_batch(FAR struct sensor_lowerhalf_s *lower, static int fakesensor_batch(FAR struct sensor_lowerhalf_s *lower,
FAR struct file *filep,
FAR unsigned long *latency_us) FAR unsigned long *latency_us)
{ {
FAR struct fakesensor_s *sensor = container_of(lower, FAR struct fakesensor_s *sensor = container_of(lower,
+12 -5
View File
@@ -110,16 +110,19 @@ struct hyt271_dev_s
/* Sensor functions */ /* Sensor functions */
static int hyt271_active(FAR struct sensor_lowerhalf_s *lower, static int hyt271_active(FAR struct sensor_lowerhalf_s *lower,
bool enabled); FAR struct file *filep, bool enabled);
static int hyt271_fetch(FAR struct sensor_lowerhalf_s *lower, static int hyt271_fetch(FAR struct sensor_lowerhalf_s *lower,
FAR struct file *filep,
FAR char *buffer, size_t buflen); FAR char *buffer, size_t buflen);
static int hyt271_control(FAR struct sensor_lowerhalf_s *lower, static int hyt271_control(FAR struct sensor_lowerhalf_s *lower,
FAR struct file *filep,
int cmd, unsigned long arg); int cmd, unsigned long arg);
#ifdef CONFIG_SENSORS_HYT271_POLL #ifdef CONFIG_SENSORS_HYT271_POLL
static int hyt271_set_interval(FAR struct sensor_lowerhalf_s *lower, static int hyt271_set_interval(FAR struct sensor_lowerhalf_s *lower,
FAR struct file *filep,
FAR unsigned long *period_us); FAR unsigned long *period_us);
#endif #endif
@@ -601,15 +604,17 @@ err_unlock:
* conversion. * conversion.
* *
* Parameter: * Parameter:
* lower - Pointer to lower half sensor driver instance * lower - Pointer to lower half sensor driver instance.
* buffer - Pointer to the buffer for reading data * filep - The pointer of file, represents each user using the sensor.
* buflen - Size of the buffer * buffer - Pointer to the buffer for reading data.
* buflen - Size of the buffer.
* *
* Return: * Return:
* OK - on success * OK - on success
****************************************************************************/ ****************************************************************************/
static int hyt271_fetch(FAR struct sensor_lowerhalf_s *lower, static int hyt271_fetch(FAR struct sensor_lowerhalf_s *lower,
FAR struct file *filep,
FAR char *buffer, size_t buflen) FAR char *buffer, size_t buflen)
{ {
int ret; int ret;
@@ -664,6 +669,7 @@ static int hyt271_fetch(FAR struct sensor_lowerhalf_s *lower,
****************************************************************************/ ****************************************************************************/
static int hyt271_control(FAR struct sensor_lowerhalf_s *lower, static int hyt271_control(FAR struct sensor_lowerhalf_s *lower,
FAR struct file *filep,
int cmd, unsigned long arg) int cmd, unsigned long arg)
{ {
int ret; int ret;
@@ -712,7 +718,7 @@ static int hyt271_control(FAR struct sensor_lowerhalf_s *lower,
****************************************************************************/ ****************************************************************************/
static int hyt271_active(FAR struct sensor_lowerhalf_s *lower, static int hyt271_active(FAR struct sensor_lowerhalf_s *lower,
bool enabled) FAR struct file *filep, bool enabled)
{ {
#ifdef CONFIG_SENSORS_HYT271_POLL #ifdef CONFIG_SENSORS_HYT271_POLL
bool start_thread = false; bool start_thread = false;
@@ -751,6 +757,7 @@ static int hyt271_active(FAR struct sensor_lowerhalf_s *lower,
#ifdef CONFIG_SENSORS_HYT271_POLL #ifdef CONFIG_SENSORS_HYT271_POLL
static int hyt271_set_interval(FAR struct sensor_lowerhalf_s *lower, static int hyt271_set_interval(FAR struct sensor_lowerhalf_s *lower,
FAR struct file *filep,
FAR unsigned long *period_us) FAR unsigned long *period_us)
{ {
FAR struct hyt271_sensor_s *priv = (FAR struct hyt271_sensor_s *)lower; FAR struct hyt271_sensor_s *priv = (FAR struct hyt271_sensor_s *)lower;
+4 -2
View File
@@ -91,11 +91,12 @@ static void l3gd20_read_temperature(FAR struct l3gd20_dev_s *dev,
static int l3gd20_interrupt_handler(int irq, FAR void *context, static int l3gd20_interrupt_handler(int irq, FAR void *context,
FAR void *arg); FAR void *arg);
static int l3gd20_activate(FAR struct sensor_lowerhalf_s *lower, static int l3gd20_activate(FAR struct sensor_lowerhalf_s *lower,
bool enable); FAR struct file *filep, bool enable);
#if CONFIG_SENSORS_L3GD20_BUFFER_SIZE > 0 #if CONFIG_SENSORS_L3GD20_BUFFER_SIZE > 0
static void l3gd20_worker(FAR void *arg); static void l3gd20_worker(FAR void *arg);
#else #else
static int l3gd20_fetch(FAR struct sensor_lowerhalf_s *lower, static int l3gd20_fetch(FAR struct sensor_lowerhalf_s *lower,
FAR struct file *filep,
FAR char *buffer, size_t buflen); FAR char *buffer, size_t buflen);
#endif #endif
@@ -403,6 +404,7 @@ static void l3gd20_worker(FAR void *arg)
****************************************************************************/ ****************************************************************************/
static int l3gd20_fetch(FAR struct sensor_lowerhalf_s *lower, static int l3gd20_fetch(FAR struct sensor_lowerhalf_s *lower,
FAR struct file *filep,
FAR char *buffer, size_t buflen) FAR char *buffer, size_t buflen)
{ {
FAR struct l3gd20_dev_s *priv = container_of(lower, FAR struct l3gd20_dev_s *priv = container_of(lower,
@@ -427,7 +429,7 @@ static int l3gd20_fetch(FAR struct sensor_lowerhalf_s *lower,
****************************************************************************/ ****************************************************************************/
static int l3gd20_activate(FAR struct sensor_lowerhalf_s *lower, static int l3gd20_activate(FAR struct sensor_lowerhalf_s *lower,
bool enable) FAR struct file *filep, bool enable)
{ {
FAR struct l3gd20_dev_s *priv = container_of(lower, FAR struct l3gd20_dev_s *priv = container_of(lower,
FAR struct l3gd20_dev_s, FAR struct l3gd20_dev_s,
+4 -2
View File
@@ -121,9 +121,10 @@ static unsigned long ms5611_curtime(void);
/* Sensor methods */ /* Sensor methods */
static int ms5611_set_interval(FAR struct sensor_lowerhalf_s *lower, static int ms5611_set_interval(FAR struct sensor_lowerhalf_s *lower,
FAR struct file *filep,
FAR unsigned long *period_us); FAR unsigned long *period_us);
static int ms5611_activate(FAR struct sensor_lowerhalf_s *lower, static int ms5611_activate(FAR struct sensor_lowerhalf_s *lower,
bool enable); FAR struct file *filep, bool enable);
#if 0 /* Please read below */ #if 0 /* Please read below */
static int ms5611_fetch(FAR struct sensor_lowerhalf_s *lower, static int ms5611_fetch(FAR struct sensor_lowerhalf_s *lower,
@@ -540,6 +541,7 @@ static uint32_t ms5611_compensate_press(FAR struct ms5611_dev_s *priv,
****************************************************************************/ ****************************************************************************/
static int ms5611_set_interval(FAR struct sensor_lowerhalf_s *lower, static int ms5611_set_interval(FAR struct sensor_lowerhalf_s *lower,
FAR struct file *filep,
FAR unsigned long *period_us) FAR unsigned long *period_us)
{ {
FAR struct ms5611_dev_s *priv = container_of(lower, FAR struct ms5611_dev_s *priv = container_of(lower,
@@ -555,7 +557,7 @@ static int ms5611_set_interval(FAR struct sensor_lowerhalf_s *lower,
****************************************************************************/ ****************************************************************************/
static int ms5611_activate(FAR struct sensor_lowerhalf_s *lower, static int ms5611_activate(FAR struct sensor_lowerhalf_s *lower,
bool enable) FAR struct file *filep, bool enable)
{ {
bool start_thread = false; bool start_thread = false;
struct ms5611_dev_s *priv = (FAR struct ms5611_dev_s *)lower; struct ms5611_dev_s *priv = (FAR struct ms5611_dev_s *)lower;
+6 -2
View File
@@ -95,8 +95,10 @@ struct wtgahrs2_dev_s
* Private Function Prototypes * Private Function Prototypes
****************************************************************************/ ****************************************************************************/
static int wtgahrs2_activate(FAR struct sensor_lowerhalf_s *lower, bool sw); static int wtgahrs2_activate(FAR struct sensor_lowerhalf_s *lower,
FAR struct file *filep, bool sw);
static int wtgahrs2_set_interval(FAR struct sensor_lowerhalf_s *lower, static int wtgahrs2_set_interval(FAR struct sensor_lowerhalf_s *lower,
FAR struct file *filep,
FAR unsigned long *interval); FAR unsigned long *interval);
/**************************************************************************** /****************************************************************************
@@ -152,7 +154,8 @@ static void wtgahrs2_sendcmd(FAR struct wtgahrs2_dev_s *rtdata,
usleep(10000); usleep(10000);
} }
static int wtgahrs2_activate(FAR struct sensor_lowerhalf_s *lower, bool sw) static int wtgahrs2_activate(FAR struct sensor_lowerhalf_s *lower,
FAR struct file *filep, bool sw)
{ {
FAR struct wtgahrs2_sensor_s *dev = (FAR struct wtgahrs2_sensor_s *)lower; FAR struct wtgahrs2_sensor_s *dev = (FAR struct wtgahrs2_sensor_s *)lower;
dev->enable = sw; dev->enable = sw;
@@ -161,6 +164,7 @@ static int wtgahrs2_activate(FAR struct sensor_lowerhalf_s *lower, bool sw)
} }
static int wtgahrs2_set_interval(FAR struct sensor_lowerhalf_s *lower, static int wtgahrs2_set_interval(FAR struct sensor_lowerhalf_s *lower,
FAR struct file *filep,
FAR unsigned long *interval) FAR unsigned long *interval)
{ {
FAR struct wtgahrs2_sensor_s *dev = (FAR struct wtgahrs2_sensor_s *)lower; FAR struct wtgahrs2_sensor_s *dev = (FAR struct wtgahrs2_sensor_s *)lower;