iio_utils.h 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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. * @mask: a bit mask for the raw output
  26. * @is_signed: is the raw value stored signed
  27. * @enabled: is this channel enabled
  28. **/
  29. struct iio_channel_info {
  30. char *name;
  31. char *generic_name;
  32. float scale;
  33. float offset;
  34. unsigned index;
  35. unsigned bytes;
  36. unsigned bits_used;
  37. unsigned shift;
  38. uint64_t mask;
  39. unsigned be;
  40. unsigned is_signed;
  41. unsigned location;
  42. };
  43. int iioutils_break_up_name(const char *full_name, char **generic_name);
  44. int iioutils_get_type(unsigned *is_signed, unsigned *bytes,
  45. unsigned *bits_used, unsigned *shift,
  46. uint64_t *mask, unsigned *be,
  47. const char *device_dir, const char *name,
  48. const char *generic_name);
  49. int iioutils_get_param_float(float *output, const char *param_name,
  50. const char *device_dir, const char *name,
  51. const char *generic_name);
  52. void bsort_channel_array_by_index(struct iio_channel_info **ci_array, int cnt);
  53. int build_channel_array(const char *device_dir,
  54. struct iio_channel_info **ci_array, int *counter);
  55. int find_type_by_name(const char *name, const char *type);
  56. int write_sysfs_int(char *filename, char *basedir, int val);
  57. int write_sysfs_int_and_verify(char *filename, char *basedir, int val);
  58. int write_sysfs_string_and_verify(char *filename, char *basedir, char *val);
  59. int write_sysfs_string(char *filename, char *basedir, char *val);
  60. int read_sysfs_posint(char *filename, char *basedir);
  61. int read_sysfs_float(char *filename, char *basedir, float *val);
  62. int read_sysfs_string(const char *filename, const char *basedir, char *str);
  63. #endif /* _IIO_UTILS_H_ */