Blame view

tools/iio/iio_utils.h 2.79 KB
d2912cb15   Thomas Gleixner   treewide: Replace...
1
  /* SPDX-License-Identifier: GPL-2.0-only */
bdcb31d04   Roberta Dobrescu   staging: iio: Doc...
2
3
  #ifndef _IIO_UTILS_H_
  #define _IIO_UTILS_H_
c57f1ba73   Jonathan Cameron   Staging: IIO: Ini...
4
5
6
  /* IIO - useful set of util functionality
   *
   * Copyright (c) 2008 Jonathan Cameron
c57f1ba73   Jonathan Cameron   Staging: IIO: Ini...
7
   */
e58537ccc   Jonathan Cameron   staging: iio: upd...
8
  #include <stdint.h>
9d8ae6c88   Jonathan Cameron   staging:iio:Docum...
9

b42f2a0c6   Peter Meerwald   staging: iio: mov...
10
  /* Made up value to limit allocation sizes */
f80ac400e   Eugen Hristev   iio: tools: gener...
11
  #define IIO_MAX_NAME_LENGTH 64
9d8ae6c88   Jonathan Cameron   staging:iio:Docum...
12

1aa042783   Jonathan Cameron   staging: iio: pus...
13
  #define FORMAT_SCAN_ELEMENTS_DIR "%s/scan_elements"
e58537ccc   Jonathan Cameron   staging: iio: upd...
14
  #define FORMAT_TYPE_FILE "%s_type"
c57f1ba73   Jonathan Cameron   Staging: IIO: Ini...
15

34cbea190   Cristina Opriceana   tools: iio: Add A...
16
  #define ARRAY_SIZE(arr) (sizeof(arr) / sizeof(arr[0]))
bdcb31d04   Roberta Dobrescu   staging: iio: Doc...
17
  extern const char *iio_dir;
e58537ccc   Jonathan Cameron   staging: iio: upd...
18
19
20
21
22
23
24
25
26
  
  /**
   * struct iio_channel_info - information about a given channel
   * @name: channel name
   * @generic_name: general name for channel type
   * @scale: scale factor to be applied for conversion to si units
   * @offset: offset to be applied for conversion to si units
   * @index: the channel index in the buffer output
   * @bytes: number of bytes occupied in buffer output
5dc65d791   Hartmut Knaack   tools:iio:iio_uti...
27
28
   * @bits_used: number of valid bits of data
   * @shift: amount of bits to shift right data before applying bit mask
e58537ccc   Jonathan Cameron   staging: iio: upd...
29
   * @mask: a bit mask for the raw output
5dc65d791   Hartmut Knaack   tools:iio:iio_uti...
30
   * @be: flag if data is big endian
e58537ccc   Jonathan Cameron   staging: iio: upd...
31
   * @is_signed: is the raw value stored signed
5dc65d791   Hartmut Knaack   tools:iio:iio_uti...
32
   * @location: data offset for this channel inside the buffer (in bytes)
e58537ccc   Jonathan Cameron   staging: iio: upd...
33
34
35
36
37
38
39
40
41
   **/
  struct iio_channel_info {
  	char *name;
  	char *generic_name;
  	float scale;
  	float offset;
  	unsigned index;
  	unsigned bytes;
  	unsigned bits_used;
52615d478   Jonathan Cameron   staging:iio:Docum...
42
  	unsigned shift;
e58537ccc   Jonathan Cameron   staging: iio: upd...
43
  	uint64_t mask;
117cf8b7e   Jonathan Cameron   staging:iio:gener...
44
  	unsigned be;
e58537ccc   Jonathan Cameron   staging: iio: upd...
45
  	unsigned is_signed;
e58537ccc   Jonathan Cameron   staging: iio: upd...
46
47
  	unsigned location;
  };
5f991a921   Linus Walleij   iio: tools: gener...
48
49
50
51
52
53
  static inline int iioutils_check_suffix(const char *str, const char *suffix)
  {
  	return strlen(str) >= strlen(suffix) &&
  		strncmp(str+strlen(str)-strlen(suffix),
  			suffix, strlen(suffix)) == 0;
  }
bdcb31d04   Roberta Dobrescu   staging: iio: Doc...
54
  int iioutils_break_up_name(const char *full_name, char **generic_name);
7663a4aac   Hartmut Knaack   tools:iio: adjust...
55
56
57
58
  int iioutils_get_type(unsigned *is_signed, unsigned *bytes, unsigned *bits_used,
  		      unsigned *shift, uint64_t *mask, unsigned *be,
  		      const char *device_dir, const char *name,
  		      const char *generic_name);
bdcb31d04   Roberta Dobrescu   staging: iio: Doc...
59
  int iioutils_get_param_float(float *output, const char *param_name,
7663a4aac   Hartmut Knaack   tools:iio: adjust...
60
61
  			     const char *device_dir, const char *name,
  			     const char *generic_name);
95ddd3f4b   Joo Aun Saw   tools: iio: remov...
62
  void bsort_channel_array_by_index(struct iio_channel_info *ci_array, int cnt);
bdcb31d04   Roberta Dobrescu   staging: iio: Doc...
63
  int build_channel_array(const char *device_dir,
7663a4aac   Hartmut Knaack   tools:iio: adjust...
64
  			struct iio_channel_info **ci_array, int *counter);
bdcb31d04   Roberta Dobrescu   staging: iio: Doc...
65
  int find_type_by_name(const char *name, const char *type);
9d4752544   Hartmut Knaack   tools:iio:iio_uti...
66
67
68
69
70
71
72
73
74
  int write_sysfs_int(const char *filename, const char *basedir, int val);
  int write_sysfs_int_and_verify(const char *filename, const char *basedir,
  			       int val);
  int write_sysfs_string_and_verify(const char *filename, const char *basedir,
  				  const char *val);
  int write_sysfs_string(const char *filename, const char *basedir,
  		       const char *val);
  int read_sysfs_posint(const char *filename, const char *basedir);
  int read_sysfs_float(const char *filename, const char *basedir, float *val);
bdcb31d04   Roberta Dobrescu   staging: iio: Doc...
75
76
77
  int read_sysfs_string(const char *filename, const char *basedir, char *str);
  
  #endif /* _IIO_UTILS_H_ */