1#ifndef _IIO_UTILS_H_
2#define _IIO_UTILS_H_
3
4
5
6
7
8
9
10
11
12
13#include <stdint.h>
14
15
16#define IIO_MAX_NAME_LENGTH 64
17
18#define FORMAT_SCAN_ELEMENTS_DIR "%s/scan_elements"
19#define FORMAT_TYPE_FILE "%s_type"
20
21#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof(arr[0]))
22
23extern const char *iio_dir;
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40struct iio_channel_info {
41 char *name;
42 char *generic_name;
43 float scale;
44 float offset;
45 unsigned index;
46 unsigned bytes;
47 unsigned bits_used;
48 unsigned shift;
49 uint64_t mask;
50 unsigned be;
51 unsigned is_signed;
52 unsigned location;
53};
54
55static inline int iioutils_check_suffix(const char *str, const char *suffix)
56{
57 return strlen(str) >= strlen(suffix) &&
58 strncmp(str+strlen(str)-strlen(suffix),
59 suffix, strlen(suffix)) == 0;
60}
61
62int iioutils_break_up_name(const char *full_name, char **generic_name);
63int iioutils_get_type(unsigned *is_signed, unsigned *bytes, unsigned *bits_used,
64 unsigned *shift, uint64_t *mask, unsigned *be,
65 const char *device_dir, const char *name,
66 const char *generic_name);
67int iioutils_get_param_float(float *output, const char *param_name,
68 const char *device_dir, const char *name,
69 const char *generic_name);
70void bsort_channel_array_by_index(struct iio_channel_info *ci_array, int cnt);
71int build_channel_array(const char *device_dir,
72 struct iio_channel_info **ci_array, int *counter);
73int find_type_by_name(const char *name, const char *type);
74int write_sysfs_int(const char *filename, const char *basedir, int val);
75int write_sysfs_int_and_verify(const char *filename, const char *basedir,
76 int val);
77int write_sysfs_string_and_verify(const char *filename, const char *basedir,
78 const char *val);
79int write_sysfs_string(const char *filename, const char *basedir,
80 const char *val);
81int read_sysfs_posint(const char *filename, const char *basedir);
82int read_sysfs_float(const char *filename, const char *basedir, float *val);
83int read_sysfs_string(const char *filename, const char *basedir, char *str);
84
85#endif
86