]> git.proxmox.com Git - mirror_ubuntu-hirsute-kernel.git/blame - tools/iio/iio_utils.h
treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 500
[mirror_ubuntu-hirsute-kernel.git] / tools / iio / iio_utils.h
CommitLineData
d2912cb1 1/* SPDX-License-Identifier: GPL-2.0-only */
bdcb31d0
RD
2#ifndef _IIO_UTILS_H_
3#define _IIO_UTILS_H_
4
c57f1ba7
JC
5/* IIO - useful set of util functionality
6 *
7 * Copyright (c) 2008 Jonathan Cameron
c57f1ba7
JC
8 */
9
e58537cc 10#include <stdint.h>
9d8ae6c8 11
b42f2a0c 12/* Made up value to limit allocation sizes */
f80ac400 13#define IIO_MAX_NAME_LENGTH 64
9d8ae6c8 14
1aa04278 15#define FORMAT_SCAN_ELEMENTS_DIR "%s/scan_elements"
e58537cc 16#define FORMAT_TYPE_FILE "%s_type"
c57f1ba7 17
34cbea19
CO
18#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof(arr[0]))
19
bdcb31d0 20extern const char *iio_dir;
e58537cc
JC
21
22/**
23 * struct iio_channel_info - information about a given channel
24 * @name: channel name
25 * @generic_name: general name for channel type
26 * @scale: scale factor to be applied for conversion to si units
27 * @offset: offset to be applied for conversion to si units
28 * @index: the channel index in the buffer output
29 * @bytes: number of bytes occupied in buffer output
5dc65d79
HK
30 * @bits_used: number of valid bits of data
31 * @shift: amount of bits to shift right data before applying bit mask
e58537cc 32 * @mask: a bit mask for the raw output
5dc65d79 33 * @be: flag if data is big endian
e58537cc 34 * @is_signed: is the raw value stored signed
5dc65d79 35 * @location: data offset for this channel inside the buffer (in bytes)
e58537cc
JC
36 **/
37struct iio_channel_info {
38 char *name;
39 char *generic_name;
40 float scale;
41 float offset;
42 unsigned index;
43 unsigned bytes;
44 unsigned bits_used;
52615d47 45 unsigned shift;
e58537cc 46 uint64_t mask;
117cf8b7 47 unsigned be;
e58537cc 48 unsigned is_signed;
e58537cc
JC
49 unsigned location;
50};
51
5f991a92
LW
52static inline int iioutils_check_suffix(const char *str, const char *suffix)
53{
54 return strlen(str) >= strlen(suffix) &&
55 strncmp(str+strlen(str)-strlen(suffix),
56 suffix, strlen(suffix)) == 0;
57}
58
bdcb31d0 59int iioutils_break_up_name(const char *full_name, char **generic_name);
7663a4aa
HK
60int iioutils_get_type(unsigned *is_signed, unsigned *bytes, unsigned *bits_used,
61 unsigned *shift, uint64_t *mask, unsigned *be,
62 const char *device_dir, const char *name,
63 const char *generic_name);
bdcb31d0 64int iioutils_get_param_float(float *output, const char *param_name,
7663a4aa
HK
65 const char *device_dir, const char *name,
66 const char *generic_name);
95ddd3f4 67void bsort_channel_array_by_index(struct iio_channel_info *ci_array, int cnt);
bdcb31d0 68int build_channel_array(const char *device_dir,
7663a4aa 69 struct iio_channel_info **ci_array, int *counter);
bdcb31d0 70int find_type_by_name(const char *name, const char *type);
9d475254
HK
71int write_sysfs_int(const char *filename, const char *basedir, int val);
72int write_sysfs_int_and_verify(const char *filename, const char *basedir,
73 int val);
74int write_sysfs_string_and_verify(const char *filename, const char *basedir,
75 const char *val);
76int write_sysfs_string(const char *filename, const char *basedir,
77 const char *val);
78int read_sysfs_posint(const char *filename, const char *basedir);
79int read_sysfs_float(const char *filename, const char *basedir, float *val);
bdcb31d0
RD
80int read_sysfs_string(const char *filename, const char *basedir, char *str);
81
82#endif /* _IIO_UTILS_H_ */