Zephyr API Documentation  3.5.0
A Scalable Open Source RTOS
3.5.0
All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
Sensing Sensor API

Sensing Sensor API. More...

Modules

 Sensor Callbacks
 Sensor Callbacks.
 

Data Structures

struct  sensing_sensor_register_info
 Sensor registration information. More...
 
struct  sensing_sensor_ctx
 Sensor context data structure. More...
 

Macros

#define SENSING_SENSOR_DT_DEFINE(node_id, reg_ptr, ctx_ptr, api_ptr)
 Macro for define a sensor instance from device tree node id.
 

Functions

static int sensing_sensor_dev_init (const struct device *dev)
 
static void * sensing_sensor_get_ctx_data (const struct device *dev)
 Get registered context data pointer for a sensor instance.
 
int sensing_sensor_post_data (const struct device *dev, void *buf, int size)
 Post sensor data, sensor subsystem runtime will deliver to it's clients.
 
int sensing_sensor_get_reporters (const struct device *dev, int type, const int *reporter_handles, int max_handles)
 Get reporter handles of a given sensor instance by sensor type.
 
int sensing_sensor_get_reporters_count (const struct device *dev, int type)
 Get reporters count of a given sensor instance by sensor type.
 
int sensing_sensor_get_state (const struct device *dev, enum sensing_sensor_state *state)
 Get this sensor's state.
 
int sensing_sensor_notify_data_ready (const struct device *dev)
 Trigger the data ready event to sensing.
 
int sensing_sensor_set_data_ready (const struct device *dev, bool data_ready)
 Set the data ready mode of the sensor.
 

Detailed Description

Sensing Sensor API.

Macro Definition Documentation

◆ SENSING_SENSOR_DT_DEFINE

#define SENSING_SENSOR_DT_DEFINE (   node_id,
  reg_ptr,
  ctx_ptr,
  api_ptr 
)

#include <zephyr/sensing/sensing_sensor.h>

Value:
static struct sensing_sensor_ctx \
_CONCAT(__sensing_sensor_ctx_, Z_DEVICE_DT_DEV_ID(node_id)) = { \
.register_info = reg_ptr, \
.sensor_ctx_ptr = ctx_ptr, \
}; \
DEVICE_DT_DEFINE(node_id, sensing_sensor_dev_init, NULL, \
&_CONCAT(__sensing_sensor_ctx_, Z_DEVICE_DT_DEV_ID(node_id)), \
NULL, POST_KERNEL, 99, api_ptr)
static int sensing_sensor_dev_init(const struct device *dev)
Definition: sensing_sensor.h:85
Sensor context data structure.
Definition: sensing_sensor.h:65

Macro for define a sensor instance from device tree node id.

This macro also defined a struct device for this sensor instance, and registered sensors' private context data, configuration data structure and API.

sensing_init will enumerate all sensor instances from device tree, and initialize each sensor instance defined by this macro.

Function Documentation

◆ sensing_sensor_dev_init()

static int sensing_sensor_dev_init ( const struct device dev)
inlinestatic

#include <zephyr/sensing/sensing_sensor.h>

Nothing need to do in system auto initialization. Sensor subsystem runtime will call each sensor instance's initialization function via API callback according sensor reporting dependency sequences. Sensor subsystem can make sure the depends sensor instances always initialized before client sensors.

◆ sensing_sensor_get_ctx_data()

static void * sensing_sensor_get_ctx_data ( const struct device dev)
inlinestatic

#include <zephyr/sensing/sensing_sensor.h>

Get registered context data pointer for a sensor instance.

Used by a sensor instance to get its registered context data pointer with its struct device.

Parameters
devThe sensor instance device structure.

◆ sensing_sensor_get_reporters()

int sensing_sensor_get_reporters ( const struct device dev,
int  type,
const int *  reporter_handles,
int  max_handles 
)

#include <zephyr/sensing/sensing_sensor.h>

Get reporter handles of a given sensor instance by sensor type.

Parameters
devThe sensor instance device structure.
typeThe given type, SENSING_SENSOR_TYPE_ALL to get reporters with all types.
max_handlesThe max count of the reporter_handles array input. Can get real count number via sensing_sensor_get_reporters_count
reporter_handlesInput handles array for receiving found reporter sensor instances
Returns
number of reporters found, 0 returned if not found.

◆ sensing_sensor_get_reporters_count()

int sensing_sensor_get_reporters_count ( const struct device dev,
int  type 
)

#include <zephyr/sensing/sensing_sensor.h>

Get reporters count of a given sensor instance by sensor type.

Parameters
devThe sensor instance device structure.
typeThe sensor type for checking, SENSING_SENSOR_TYPE_ALL
Returns
Count of reporters by type, 0 returned if no reporters by type.

◆ sensing_sensor_get_state()

int sensing_sensor_get_state ( const struct device dev,
enum sensing_sensor_state state 
)

#include <zephyr/sensing/sensing_sensor.h>

Get this sensor's state.

Parameters
devThe sensor instance device structure.
stateReturned sensor state value
Returns
0 on success or negative error value on failure.

◆ sensing_sensor_notify_data_ready()

int sensing_sensor_notify_data_ready ( const struct device dev)

#include <zephyr/sensing/sensing_sensor.h>

Trigger the data ready event to sensing.

Parameters
devPointer to the sensor device
Returns
0 on success or negative error value on failure.

◆ sensing_sensor_post_data()

int sensing_sensor_post_data ( const struct device dev,
void *  buf,
int  size 
)

#include <zephyr/sensing/sensing_sensor.h>

Post sensor data, sensor subsystem runtime will deliver to it's clients.

Unblocked function, returned immediately.

Used by a virtual sensor to post data to it's clients.

A reporter sensor can use this API to post data to it's clients. For example, when a virtual sensor computed a data, then can use this API to deliver the data to it's clients. Please note, this API just for reporter post data to the sensor subsystem runtime, the runtime will help delivered the data to it's all clients according clients' configurations such as reporter interval, data change sensitivity.

Parameters
devThe sensor instance device structure.
bufThe data buffer.
sizeThe buffer size in bytes.
Returns
0 on success or negative error value on failure.

◆ sensing_sensor_set_data_ready()

int sensing_sensor_set_data_ready ( const struct device dev,
bool  data_ready 
)

#include <zephyr/sensing/sensing_sensor.h>

Set the data ready mode of the sensor.

Parameters
devPointer to the sensor device
data_readyEnable/disable the data ready mode. Default:disabled
Returns
0 on success or negative error value on failure.