iio_utils.h 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. #ifndef _IIO_UTILS_H_
  2. #define _IIO_UTILS_H_
  3. /* IIO - useful set of util functionality
  4. *
  5. * Copyright (c) 2008 Jonathan Cameron
  6. *
  7. * This program is free software; you can redistribute it and/or modify it
  8. * under the terms of the GNU General Public License version 2 as published by
  9. * the Free Software Foundation.
  10. */
  11. #include <stdint.h>
  12. /* Made up value to limit allocation sizes */
  13. #define IIO_MAX_NAME_LENGTH 30
  14. #define FORMAT_SCAN_ELEMENTS_DIR "%s/scan_elements"
  15. #define FORMAT_TYPE_FILE "%s_type"
  16. extern const char *iio_dir;
  17. /**
  18. * struct iio_channel_info - information about a given channel
  19. * @name: channel name
  20. * @generic_name: general name for channel type
  21. * @scale: scale factor to be applied for conversion to si units
  22. * @offset: offset to be applied for conversion to si units
  23. * @index: the channel index in the buffer output
  24. * @bytes: number of bytes occupied in buffer output
  25. * @bits_used: number of valid bits of data
  26. * @shift: amount of bits to shift right data before applying bit mask
  27. * @mask: a bit mask for the raw output
  28. * @be: flag if data is big endian
  29. * @is_signed: is the raw value stored signed
  30. * @location: data offset for this channel inside the buffer (in bytes)
  31. **/
  32. struct iio_channel_info {
  33. char *name;
  34. char *generic_name;
  35. float scale;
  36. float offset;
  37. unsigned index;
  38. unsigned bytes;
  39. unsigned bits_used;
  40. unsigned shift;
  41. uint64_t mask;
  42. unsigned be;
  43. unsigned is_signed;
  44. unsigned location;
  45. };
  46. int iioutils_break_up_name(const char *full_name, char **generic_name);
  47. int iioutils_get_type(unsigned *is_signed, unsigned *bytes,
  48. unsigned *bits_used, unsigned *shift,
  49. uint64_t *mask, unsigned *be,
  50. const char *device_dir, const char *name,
  51. const char *generic_name);
  52. int iioutils_get_param_float(float *output, const char *param_name,
  53. const char *device_dir, const char *name,
  54. const char *generic_name);
  55. void bsort_channel_array_by_index(struct iio_channel_info **ci_array, int cnt);
  56. int build_channel_array(const char *device_dir,
  57. struct iio_channel_info **ci_array, int *counter);
  58. int find_type_by_name(const char *name, const char *type);
  59. int write_sysfs_int(const char *filename, const char *basedir, int val);
  60. int write_sysfs_int_and_verify(const char *filename, const char *basedir,
  61. int val);
  62. int write_sysfs_string_and_verify(const char *filename, const char *basedir,
  63. const char *val);
  64. int write_sysfs_string(const char *filename, const char *basedir,
  65. const char *val);
  66. int read_sysfs_posint(const char *filename, const char *basedir);
  67. int read_sysfs_float(const char *filename, const char *basedir, float *val);
  68. int read_sysfs_string(const char *filename, const char *basedir, char *str);
  69. #endif /* _IIO_UTILS_H_ */