OpenCloudOS-Kernel/tools/iio/iio_utils.h

83 lines
2.8 KiB
C
Raw Normal View History

/* SPDX-License-Identifier: GPL-2.0-only */
#ifndef _IIO_UTILS_H_
#define _IIO_UTILS_H_
/* IIO - useful set of util functionality
*
* Copyright (c) 2008 Jonathan Cameron
*/
#include <stdint.h>
/* Made up value to limit allocation sizes */
#define IIO_MAX_NAME_LENGTH 64
#define FORMAT_SCAN_ELEMENTS_DIR "%s/scan_elements"
#define FORMAT_TYPE_FILE "%s_type"
#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof(arr[0]))
extern const char *iio_dir;
/**
* 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
* @bits_used: number of valid bits of data
* @shift: amount of bits to shift right data before applying bit mask
* @mask: a bit mask for the raw output
* @be: flag if data is big endian
* @is_signed: is the raw value stored signed
* @location: data offset for this channel inside the buffer (in bytes)
**/
struct iio_channel_info {
char *name;
char *generic_name;
float scale;
float offset;
unsigned index;
unsigned bytes;
unsigned bits_used;
unsigned shift;
uint64_t mask;
unsigned be;
unsigned is_signed;
unsigned location;
};
iio: tools: generic_buffer: auto-enable channels If no channels are enabled when we run generic_buffer on a device, add a command-line option to just enable all of them, run the sampling and disable them all again afterwards. This is extremely useful when I'm low-level testing my sensors with interrupts and triggers, sample session: root@Ux500:/ lsiio Device 000: lsm303dlh_accel Device 001: lis331dl_accel Device 002: l3g4200d Device 003: lsm303dlh_magn Device 004: lps001wp Trigger 000: lsm303dlh_accel-trigger Trigger 001: lis331dl_accel-trigger Trigger 002: l3g4200d-trigger root@Ux500:/ generic_buffer -a -c 10 -n l3g4200d iio device number being used is 2 iio trigger number being used is 2 No channels are enabled, enabling all channels Enabling: in_anglvel_x_en Enabling: in_anglvel_y_en Enabling: in_anglvel_z_en Enabling: in_timestamp_en /sys/bus/iio/devices/iio:device2 l3g4200d-trigger -3.593664 -0.713133 4.870143 946684863662292480 3.225546 0.867357 -4.945878 946684863671875000 -0.676413 0.127296 0.106641 946684863681488037 -0.661113 0.110160 0.128826 946684863690673828 -0.664173 0.113067 0.123471 946684863700683593 -0.664938 0.109395 0.124848 946684863710144042 -0.664173 0.110619 0.130203 946684863719512939 -0.666162 0.111231 0.132651 946684863729125976 -0.668610 0.111690 0.130662 946684863738739013 -0.660501 0.110466 0.131733 946684863748565673 Disabling: in_anglvel_x_en Disabling: in_anglvel_y_en Disabling: in_anglvel_z_en Disabling: in_timestamp_en Pure awesomeness. If some channels have been enabled through scripts or manual interaction, nothing happens. Cc: Peter Meerwald-Stadler <pmeerw@pmeerw.net> Acked-by: Daniel Baluta <daniel.baluta@intel.com> Signed-off-by: Linus Walleij <linus.walleij@linaro.org> Signed-off-by: Jonathan Cameron <jic23@kernel.org>
2016-04-14 16:26:47 +08:00
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;
}
int iioutils_break_up_name(const char *full_name, char **generic_name);
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);
int iioutils_get_param_float(float *output, const char *param_name,
const char *device_dir, const char *name,
const char *generic_name);
void bsort_channel_array_by_index(struct iio_channel_info *ci_array, int cnt);
int build_channel_array(const char *device_dir,
struct iio_channel_info **ci_array, int *counter);
int find_type_by_name(const char *name, const char *type);
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);
int read_sysfs_string(const char *filename, const char *basedir, char *str);
#endif /* _IIO_UTILS_H_ */