0001
0002 #ifndef _IIO_UTILS_H_
0003 #define _IIO_UTILS_H_
0004
0005
0006
0007
0008
0009
0010 #include <stdint.h>
0011
0012
0013 #define IIO_MAX_NAME_LENGTH 64
0014
0015 #define FORMAT_SCAN_ELEMENTS_DIR "%s/buffer%d"
0016 #define FORMAT_EVENTS_DIR "%s/events"
0017 #define FORMAT_TYPE_FILE "%s_type"
0018
0019 #define ARRAY_SIZE(arr) (sizeof(arr) / sizeof(arr[0]))
0020
0021 extern const char *iio_dir;
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037
0038 struct iio_channel_info {
0039 char *name;
0040 char *generic_name;
0041 float scale;
0042 float offset;
0043 unsigned index;
0044 unsigned bytes;
0045 unsigned bits_used;
0046 unsigned shift;
0047 uint64_t mask;
0048 unsigned be;
0049 unsigned is_signed;
0050 unsigned location;
0051 };
0052
0053 static inline int iioutils_check_suffix(const char *str, const char *suffix)
0054 {
0055 return strlen(str) >= strlen(suffix) &&
0056 strncmp(str+strlen(str)-strlen(suffix),
0057 suffix, strlen(suffix)) == 0;
0058 }
0059
0060 int iioutils_break_up_name(const char *full_name, char **generic_name);
0061 int iioutils_get_param_float(float *output, const char *param_name,
0062 const char *device_dir, const char *name,
0063 const char *generic_name);
0064 void bsort_channel_array_by_index(struct iio_channel_info *ci_array, int cnt);
0065 int build_channel_array(const char *device_dir, int buffer_idx,
0066 struct iio_channel_info **ci_array, int *counter);
0067 int find_type_by_name(const char *name, const char *type);
0068 int write_sysfs_int(const char *filename, const char *basedir, int val);
0069 int write_sysfs_int_and_verify(const char *filename, const char *basedir,
0070 int val);
0071 int write_sysfs_string_and_verify(const char *filename, const char *basedir,
0072 const char *val);
0073 int write_sysfs_string(const char *filename, const char *basedir,
0074 const char *val);
0075 int read_sysfs_posint(const char *filename, const char *basedir);
0076 int read_sysfs_float(const char *filename, const char *basedir, float *val);
0077 int read_sysfs_string(const char *filename, const char *basedir, char *str);
0078
0079 #endif