Merge "Adding AK8975 geo-sensor info in sensors.xml.in required by geo-plugin" into...
[platform/core/system/sensord.git] / src / shared / iio_common.h
1 /*
2  * sensord
3  *
4  * Copyright (c) 2014 Samsung Electronics Co., Ltd.
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  *
18  */
19
20 #ifndef IIO_COMMON_H_
21 #define IIO_COMMON_H_
22
23 #include <linux/ioctl.h>
24
25 #define NO_OF_ULL_BYTES         8
26 #define NO_OF_SHORT_VAL         4
27 #define CH0_INDEX                       0
28 #define CH1_INDEX                       1
29
30 #define GET_DIFF_BIT(val)       (((unsigned short)(val) >> 7) & 0x01)
31 #define GET_DIR_VAL(val)        ((val) & 0x0F)
32
33 #define IOCTL_IIO_EVENT_FD _IOR('i', 0x90, int)
34
35 struct channel_parameters
36 {
37         char *prefix_str;
38         float scale;
39         float offset;
40         unsigned int index;
41         unsigned int byte_count;
42         unsigned int valid_bits;
43         unsigned int shift;
44         unsigned long long int mask;
45         unsigned int big_endian;
46         unsigned int is_signed;
47         unsigned int is_en;
48         unsigned int buf_index;
49 };
50
51 typedef struct iio_event_struct
52 {
53         unsigned long long int event_id;
54         long long int timestamp;
55 } iio_event_t;
56
57 typedef enum event_id_field
58 {
59         CH_TYPE = 4,
60         MODIFIER,
61         DIRECTION,
62         EVENT_TYPE,
63 } event_id_field_t;
64
65 typedef union ull_bytes
66 {
67         unsigned long long num;
68         short int channels[NO_OF_SHORT_VAL];
69         unsigned char bytes[NO_OF_ULL_BYTES];
70 } ull_bytes_t;
71
72 void sort_channels_by_index(struct channel_parameters *channels, int count);
73 int decode_channel_data_type(const char *device_dir, const char *ch_name, struct channel_parameters *ch_info);
74 int add_channel_to_array(const char *device_dir, const char *ch_name, struct channel_parameters *channel);
75 int get_channel_array_size(struct channel_parameters *channels, int num_channels);
76 int update_sysfs_num(const char *filepath, int val, bool verify = false);
77 int update_sysfs_string(const char *filepath, char *val, bool verify = false);
78 int convert_bytes_to_int(int input, struct channel_parameters *info);
79
80 #endif /* IIO_COMMON_H_ */