blob: 379eed9deaea242025fc53e081bc350b3d931097 [file] [log] [blame]
Roberta Dobrescubdcb31d2015-02-26 10:49:24 +02001#ifndef _IIO_UTILS_H_
2#define _IIO_UTILS_H_
3
Jonathan Cameronc57f1ba2009-08-18 18:06:32 +01004/* IIO - useful set of util functionality
5 *
6 * Copyright (c) 2008 Jonathan Cameron
7 *
8 * This program is free software; you can redistribute it and/or modify it
9 * under the terms of the GNU General Public License version 2 as published by
10 * the Free Software Foundation.
11 */
12
Jonathan Camerone58537c2010-10-08 12:14:14 +010013#include <stdint.h>
Jonathan Cameron9d8ae6c2010-05-04 14:43:13 +010014
Peter Meerwaldb42f2a02012-06-25 23:12:13 +020015/* Made up value to limit allocation sizes */
Jonathan Cameron9d8ae6c2010-05-04 14:43:13 +010016#define IIO_MAX_NAME_LENGTH 30
17
Jonathan Cameron1aa04272011-08-30 12:32:47 +010018#define FORMAT_SCAN_ELEMENTS_DIR "%s/scan_elements"
Jonathan Camerone58537c2010-10-08 12:14:14 +010019#define FORMAT_TYPE_FILE "%s_type"
Jonathan Cameronc57f1ba2009-08-18 18:06:32 +010020
Roberta Dobrescubdcb31d2015-02-26 10:49:24 +020021extern const char *iio_dir;
Jonathan Camerone58537c2010-10-08 12:14:14 +010022
23/**
24 * struct iio_channel_info - information about a given channel
25 * @name: channel name
26 * @generic_name: general name for channel type
27 * @scale: scale factor to be applied for conversion to si units
28 * @offset: offset to be applied for conversion to si units
29 * @index: the channel index in the buffer output
30 * @bytes: number of bytes occupied in buffer output
Hartmut Knaack5dc65d72015-05-31 14:40:16 +020031 * @bits_used: number of valid bits of data
32 * @shift: amount of bits to shift right data before applying bit mask
Jonathan Camerone58537c2010-10-08 12:14:14 +010033 * @mask: a bit mask for the raw output
Hartmut Knaack5dc65d72015-05-31 14:40:16 +020034 * @be: flag if data is big endian
Jonathan Camerone58537c2010-10-08 12:14:14 +010035 * @is_signed: is the raw value stored signed
Hartmut Knaack5dc65d72015-05-31 14:40:16 +020036 * @location: data offset for this channel inside the buffer (in bytes)
Jonathan Camerone58537c2010-10-08 12:14:14 +010037 **/
38struct iio_channel_info {
39 char *name;
40 char *generic_name;
41 float scale;
42 float offset;
43 unsigned index;
44 unsigned bytes;
45 unsigned bits_used;
Jonathan Cameron52615d42011-05-18 14:41:19 +010046 unsigned shift;
Jonathan Camerone58537c2010-10-08 12:14:14 +010047 uint64_t mask;
Jonathan Cameron117cf8b2011-12-04 19:10:59 +000048 unsigned be;
Jonathan Camerone58537c2010-10-08 12:14:14 +010049 unsigned is_signed;
Jonathan Camerone58537c2010-10-08 12:14:14 +010050 unsigned location;
51};
52
Roberta Dobrescubdcb31d2015-02-26 10:49:24 +020053int iioutils_break_up_name(const char *full_name, char **generic_name);
54int iioutils_get_type(unsigned *is_signed, unsigned *bytes,
55 unsigned *bits_used, unsigned *shift,
56 uint64_t *mask, unsigned *be,
57 const char *device_dir, const char *name,
58 const char *generic_name);
59int iioutils_get_param_float(float *output, const char *param_name,
60 const char *device_dir, const char *name,
61 const char *generic_name);
62void bsort_channel_array_by_index(struct iio_channel_info **ci_array, int cnt);
63int build_channel_array(const char *device_dir,
64 struct iio_channel_info **ci_array, int *counter);
65int find_type_by_name(const char *name, const char *type);
Hartmut Knaack9d475252015-05-31 14:40:36 +020066int write_sysfs_int(const char *filename, const char *basedir, int val);
67int write_sysfs_int_and_verify(const char *filename, const char *basedir,
68 int val);
69int write_sysfs_string_and_verify(const char *filename, const char *basedir,
70 const char *val);
71int write_sysfs_string(const char *filename, const char *basedir,
72 const char *val);
73int read_sysfs_posint(const char *filename, const char *basedir);
74int read_sysfs_float(const char *filename, const char *basedir, float *val);
Roberta Dobrescubdcb31d2015-02-26 10:49:24 +020075int read_sysfs_string(const char *filename, const char *basedir, char *str);
Jonathan Camerone58537c2010-10-08 12:14:14 +010076
Roberta Dobrescubdcb31d2015-02-26 10:49:24 +020077#endif /* _IIO_UTILS_H_ */