OSDN Git Service

STPK-1429 Use properties values for user-visible sensor description
[android-x86/hardware-intel-libsensors.git] / common.h
1 /*
2  * Copyright (C) 2014 Intel Corporation.
3  */
4
5 #ifndef __COMMON_H__
6 #define __COMMON_H__
7
8 #define MAX_DEVICES     8       /* Check iio devices 0 to MAX_DEVICES-1 */
9 #define MAX_SENSORS     10      /* We can handle as many sensors */
10 #define MAX_CHANNELS    4       /* We can handle as many channels per sensor */
11
12 #define DEV_FILE_PATH   "/dev/iio:device%d"
13
14 #define BASE_PATH       "/sys/bus/iio/devices/iio:device%d/"
15
16 #define CHANNEL_PATH            BASE_PATH "scan_elements/"
17 #define ENABLE_PATH             BASE_PATH "buffer/enable"
18 #define NAME_PATH               BASE_PATH "name"
19 #define TRIGGER_PATH            BASE_PATH "trigger/current_trigger"
20 #define COMMON_OFFSET_PATH      BASE_PATH "in_%s_offset"
21 #define COMMON_SCALE_PATH       BASE_PATH "in_%s_scale"
22 #define COMMON_SAMPLING_PATH    BASE_PATH "in_%s_sampling_frequency"
23
24 #define PROP_BASE       "ro.iio.%s.%s" /* Note: PROPERTY_KEY_MAX is small */
25
26 #define MAX_TYPE_SPEC_LEN 32    /* Channel type spec len; ex: "le:u10/16>>0" */
27 #define MAX_SENSOR_REPORT_SIZE  32      /* Sensor report buffer size */
28
29 #define MAX_NAME_SIZE           32
30
31 #define ARRAY_SIZE(x) sizeof(x)/sizeof(x[0])
32
33 struct channel_descriptor_t
34 {
35         /* sysfs entries located under scan_elements */
36         const char *en_path;    /* Enabled sysfs file name ; ex: "in_temp_en" */
37         const char *type_path;  /* _type sysfs file name  */
38         const char *index_path; /* _index sysfs file name */
39
40         /* sysfs entries located in /sys/bus/iio/devices/iio:deviceX */
41         const char *raw_path;   /* _raw sysfs file name  */
42         const char *input_path; /* _input sysfs file name */
43 };
44
45 struct sensor_catalog_entry_t
46 {
47         const char *tag; /* Prefix such as "accel", "gyro", "temp"... */
48         const int type;  /* Sensor type ; ex: SENSOR_TYPE_ACCELEROMETER */
49         const int num_channels; /* Expected iio channels for this sensor */
50         struct channel_descriptor_t channel[MAX_CHANNELS];
51 };
52
53 struct datum_info_t
54 {
55         char sign;
56         char endianness;
57         short realbits;
58         short storagebits;
59         short shift;
60 };
61
62 struct channel_info_t
63 {
64         int offset; /* Offset in bytes within the iio character device report */
65         int size;                       /* Field size in bytes */
66         char type_spec[MAX_TYPE_SPEC_LEN]; /* From driver; ex: le:u10/16>>0 */
67         struct datum_info_t type_info;     /* Decoded contents of type spec */
68 };
69
70 struct sensor_info_t
71 {
72         char friendly_name[MAX_NAME_SIZE];      /* ex: Accelerometer */
73         char internal_name[MAX_NAME_SIZE];      /* ex: accel_3d */
74         char vendor_name[MAX_NAME_SIZE];        /* ex: Intel */
75
76         float max_range;
77         float resolution;
78         float power;
79
80         float offset;   /* (cooked = raw + offset) * scale */
81         float scale;
82
83         int sampling_rate;      /* requested events / second */
84
85         int dev_num;    /* Associated iio dev num, ex: 3 for /dev/iio:device3 */
86         int enable_count;
87
88         int catalog_index;/* Associated entry within the sensor_catalog array */
89
90         int num_channels; /* Actual channel count ; 0 for poll mode sensors */
91
92         /*
93          * The array below indicates where to gather report data for this
94          * sensor inside the reports that we read from the iio character device.
95          * It is updated whenever channels are enabled or disabled on the same
96          * device. Channel size indicates the size in bytes of fields, and
97          * should be zero for disabled channels. The type field indicates how a
98          * specific channel data item is structured.
99          */
100         struct channel_info_t channel[MAX_CHANNELS];
101
102         /*
103          * This flag is set if we acquired data from the sensor but did not
104          * forward it to upper layers (i.e. Android) yet. If so, report_buffer
105          * contains that data.
106          */
107         int report_pending;
108
109         unsigned char report_buffer[MAX_SENSOR_REPORT_SIZE];
110
111         /* Note: we may have to explicitely serialize access to some fields */
112 };
113
114 /* Reference a few commonly used variables... */
115 extern int                              sensor_count;
116 extern struct sensor_info_t             sensor_info[MAX_SENSORS];
117 extern struct sensor_catalog_entry_t    sensor_catalog[];
118
119 #endif