Commit b9b714c8 authored by Guangfu Hu's avatar Guangfu Hu Committed by Carles Cufi
Browse files

sensing: refine sensing API

1) move variable shift behind struct sensing_sensor_value_header in
struct sensing_sensor_value_q31
2) add pointer checking for sensing API
3) add context sensing_callback_list and sensing_data_event_t
4) add macro SENSING_SENSITIVITY_INDEX_ALL
5) rename zephyr,sensing-phy-3d-sensor.yaml

Signed-off-by: default avatarGuangfu Hu <guangfu.hu@intel.com>
parent 2166a6f9
Loading
Loading
Loading
Loading
+11 −1
Changes for include/zephyr/sensing/sensing.h: 11 added lines, 1 removed line.
Original line number Diff line number Diff line
@@ -72,6 +72,11 @@ struct sensing_sensor_version {
 */
#define SENSING_SENSOR_FLAG_REPORT_ON_CHANGE			BIT(1)

/**
 * @brief SENSING_SENSITIVITY_INDEX_ALL indicating sensitivity of each data field should be set
 *
 */
#define SENSING_SENSITIVITY_INDEX_ALL -1

/**
 * @brief Sensing subsystem sensor state.
@@ -110,7 +115,8 @@ typedef void *sensing_sensor_handle_t;
 */
typedef void (*sensing_data_event_t)(
		sensing_sensor_handle_t handle,
		const void *buf);
		const void *buf,
		void *context);

/**
 * @struct sensing_sensor_info
@@ -144,6 +150,7 @@ struct sensing_sensor_info {
 */
struct sensing_callback_list {
	sensing_data_event_t on_data_event;
	void *context;
};
/**
 * @struct sensing_sensor_config
@@ -152,7 +159,10 @@ struct sensing_callback_list {
 */
struct sensing_sensor_config {
	enum sensing_sensor_attribute attri;

	/** \ref SENSING_SENSITIVITY_INDEX_ALL */
	int8_t data_field;

	union {
		uint32_t interval;
		uint32_t sensitivity;
+1 −1
Changes for include/zephyr/sensing/sensing_datatypes.h: 1 added line, 1 removed line.
Original line number Diff line number Diff line
@@ -99,8 +99,8 @@ struct sensing_sensor_value_uint32 {
 * q31 version
 */
struct sensing_sensor_value_q31 {
	int8_t shift;
	struct sensing_sensor_value_header header;
	int8_t shift;
	struct {
		uint32_t timestamp_delta;
		q31_t v;
+3 −1
Changes for samples/subsys/sensing/simple/src/main.c: 3 added lines, 1 removed line.
Original line number Diff line number Diff line
@@ -12,10 +12,12 @@

LOG_MODULE_REGISTER(main, LOG_LEVEL_INF);

static void acc_data_event_callback(sensing_sensor_handle_t handle, const void *buf)
static void acc_data_event_callback(sensing_sensor_handle_t handle, const void *buf,
				    void *context)
{
	const struct sensing_sensor_info *info = sensing_get_sensor_info(handle);
	struct sensing_sensor_value_3d_q31 *sample = (struct sensing_sensor_value_3d_q31 *)buf;
	ARG_UNUSED(context);

	LOG_INF("%s(%d), handle:%p, Sensor:%s data:(x:%d, y:%d, z:%d)",
		__func__, __LINE__, handle, info->name,
+13 −1
Changes for subsys/sensing/sensing.c: 13 added lines, 1 removed line.
Original line number Diff line number Diff line
@@ -19,7 +19,7 @@ int sensing_open_sensor(const struct sensing_sensor_info *sensor_info,
{
	int ret = 0;

	if (handle == NULL) {
	if (sensor_info == NULL || handle == NULL) {
		return -ENODEV;
	}

@@ -64,6 +64,10 @@ int sensing_open_sensor_by_dt(const struct device *dev,
/* sensing_close_sensor is normally called by applications: hid, chre, zephyr main, etc */
int sensing_close_sensor(sensing_sensor_handle_t *handle)
{
	if (handle == NULL) {
		return -ENODEV;
	}

	return close_sensor((struct sensing_connection **)handle);
}

@@ -74,6 +78,10 @@ int sensing_set_config(sensing_sensor_handle_t handle,
	struct sensing_sensor_config *cfg;
	int i, ret = 0;

	if (handle == NULL || configs == NULL) {
		return -ENODEV;
	}

	if (count <= 0 || count > SENSING_SENSOR_ATTRIBUTE_MAX) {
		LOG_ERR("invalid config count:%d", count);
		return -EINVAL;
@@ -110,6 +118,10 @@ int sensing_get_config(sensing_sensor_handle_t handle,
	struct sensing_sensor_config *cfg;
	int i, ret = 0;

	if (handle == NULL || configs == NULL) {
		return -ENODEV;
	}

	if (count <= 0 || count > SENSING_SENSOR_ATTRIBUTE_MAX) {
		LOG_ERR("invalid config count:%d", count);
		return -EINVAL;