/*
- * Copyright (C) 2014-2015 Intel Corporation.
- */
+// Copyright (c) 2015 Intel Corporation
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+*/
#ifndef __COMMON_H__
#define __COMMON_H__
+#include <string.h>
+
#define MAX_DEVICES 9 /* Check iio devices 0 to MAX_DEVICES-1 */
#define MAX_SENSORS 12 /* We can handle as many sensors */
#define MAX_CHANNELS 4 /* We can handle as many channels per sensor */
#define DEV_FILE_PATH "/dev/iio:device%d"
#define BASE_PATH "/sys/bus/iio/devices/iio:device%d/"
#define TRIGGER_FILE_PATH "/sys/bus/iio/devices/trigger%d/name"
+#define IIO_DEVICES "/sys/bus/iio/devices/"
#define CHANNEL_PATH BASE_PATH "scan_elements/"
#define ENABLE_PATH BASE_PATH "buffer/enable"
+#define BUFFER_LENGTH_PATH BASE_PATH "buffer/length"
#define NAME_PATH BASE_PATH "name"
#define TRIGGER_PATH BASE_PATH "trigger/current_trigger"
#define EVENTS_PATH BASE_PATH "events/"
#define DEVICE_AVAIL_FREQ_PATH BASE_PATH "sampling_frequency_available"
#define ILLUMINATION_CALIBPATH BASE_PATH "in_illuminance_calibscale"
#define SENSOR_CALIB_BIAS_PATH BASE_PATH "in_%s_calibbias"
+#define MOUNTING_MATRIX_PATH BASE_PATH "mounting_matrix"
+
+#define CONFIGFS_TRIGGER_PATH "/sys/kernel/config/iio/triggers/"
#define PROP_BASE "ro.iio.%s.%s" /* Note: PROPERTY_KEY_MAX is small */
#define MAX_SENSOR_REPORT_SIZE 32 /* Sensor report buffer size */
#define MAX_DEVICE_REPORT_SIZE 32 /* iio device scan buffer size */
-#define MAX_NAME_SIZE 32
+#define MAX_NAME_SIZE 64
#define MAX_SENSOR_BASES 3 /* Max number of base sensors a sensor can rely on */
#define MODE_EVENT 3
-/* Couple of temporary defines until we get a suitable linux/iio/events.h include */
-
-struct iio_event_data {
- __u64 id;
- __s64 timestamp;
-};
-
-#define IIO_GET_EVENT_FD_IOCTL _IOR('i', 0x90, int)
-
-#define IIO_EVENT_CODE_EXTRACT_TYPE(mask) ((mask >> 56) & 0xFF)
-#define IIO_EVENT_CODE_EXTRACT_DIR(mask) ((mask >> 48) & 0xCF)
-#define IIO_EVENT_CODE_EXTRACT_CHAN_TYPE(mask) ((mask >> 32) & 0xFF)
-#define IIO_EVENT_CODE_EXTRACT_MODIFIER(mask) ((mask >> 40) & 0xFF)
-
-/* Couple of temporary defines until we get a suitable linux/iio/types.h include */
-enum iio_chan_type {
- IIO_VOLTAGE,
- IIO_CURRENT,
- IIO_POWER,
- IIO_ACCEL,
- IIO_ANGL_VEL,
- IIO_MAGN,
- IIO_LIGHT,
- IIO_INTENSITY,
- IIO_PROXIMITY,
- IIO_TEMP,
- IIO_INCLI,
- IIO_ROT,
- IIO_ANGL,
- IIO_TIMESTAMP,
- IIO_CAPACITANCE,
- IIO_ALTVOLTAGE,
- IIO_CCT,
- IIO_PRESSURE,
- IIO_HUMIDITYRELATIVE,
- IIO_ACTIVITY,
- IIO_STEPS,
- IIO_CALORIES,
- IIO_DISTANCE,
- IIO_SPEED,
-};
-
-enum iio_modifier {
- IIO_NO_MOD,
- IIO_MOD_X,
- IIO_MOD_Y,
- IIO_MOD_Z,
- IIO_MOD_X_AND_Y,
- IIO_MOD_X_AND_Z,
- IIO_MOD_Y_AND_Z,
- IIO_MOD_X_AND_Y_AND_Z,
- IIO_MOD_X_OR_Y,
- IIO_MOD_X_OR_Z,
- IIO_MOD_Y_OR_Z,
- IIO_MOD_X_OR_Y_OR_Z,
- IIO_MOD_LIGHT_BOTH,
- IIO_MOD_LIGHT_IR,
- IIO_MOD_ROOT_SUM_SQUARED_X_Y,
- IIO_MOD_SUM_SQUARED_X_Y_Z,
- IIO_MOD_LIGHT_CLEAR,
- IIO_MOD_LIGHT_RED,
- IIO_MOD_LIGHT_GREEN,
- IIO_MOD_LIGHT_BLUE,
- IIO_MOD_QUATERNION,
- IIO_MOD_TEMP_AMBIENT,
- IIO_MOD_TEMP_OBJECT,
- IIO_MOD_NORTH_MAGN,
- IIO_MOD_NORTH_TRUE,
- IIO_MOD_NORTH_MAGN_TILT_COMP,
- IIO_MOD_NORTH_TRUE_TILT_COMP,
- IIO_MOD_RUNNING,
- IIO_MOD_JOGGING,
- IIO_MOD_WALKING,
- IIO_MOD_STILL,
-};
-
-enum iio_event_type {
- IIO_EV_TYPE_THRESH,
- IIO_EV_TYPE_MAG,
- IIO_EV_TYPE_ROC,
- IIO_EV_TYPE_THRESH_ADAPTIVE,
- IIO_EV_TYPE_MAG_ADAPTIVE,
- IIO_EV_TYPE_INSTANCE,
-};
-
-enum iio_event_info {
- IIO_EV_INFO_ENABLE,
- IIO_EV_INFO_VALUE,
- IIO_EV_INFO_HYSTERESIS,
- IIO_EV_INFO_PERIOD,
-};
-
-enum iio_event_direction {
- IIO_EV_DIR_EITHER,
- IIO_EV_DIR_RISING,
- IIO_EV_DIR_FALLING,
- IIO_EV_DIR_NONE,
-};
-
-
typedef struct
{
const char *type; /* event type; e.g: transition */
typedef struct
{
const char *tag; /* Prefix such as "accel", "gyro", "temp"... */
+ const char *shorthand;
const int type; /* Sensor type ; ex: SENSOR_TYPE_ACCELEROMETER */
const int num_channels; /* Expected iio channels for this sensor */
const int is_virtual; /* Is the sensor virtual or not */
char vendor_name[MAX_NAME_SIZE]; /* ex: Intel */
char init_trigger_name[MAX_NAME_SIZE]; /* ex: accel-name-dev1 */
char motion_trigger_name[MAX_NAME_SIZE];/* ex: accel-any-motion-dev1 */
+ char hrtimer_trigger_name[MAX_NAME_SIZE]; /*ex: accel-hr-dev1 */
+ int trigger_nr; /* trigger number associated with this device */
float max_range;
float resolution;
float power;
* more than one at a later time.
*/
sensors_event_t sample;
+ uint64_t event_id;
/*
* If the QUIRK_FIELD_ORDERING bit is set in quirks, the contents of this array are used in the finalization stage to swap sample fields
unsigned char order[MAX_CHANNELS];
/*
+ * If the QUIRK_MOUNTING_MATRIX bit is set in quirks, the contents of this matrix is used to correct the sample values so that it takes
+ * into account the way the sensor has been mounted on the PCB.
+ */
+ float mounting_matrix[9];
+
+ /** Count of available frequencies */
+ int avail_freqs_count;
+
+ /** Array of available frequencies */
+ float* avail_freqs;
+
+ /*
* Event counter - will be used to check if we have a significant sample for noisy sensors. We want to make sure we do not send any wrong
* events before filtering kicks in. We can also use it for statistics.
*/