diff options
author | Jonathan Cameron <jic23@cam.ac.uk> | 2011-12-04 19:10:59 +0000 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@suse.de> | 2011-12-08 11:32:35 -0800 |
commit | 117cf8b7e879a33b24b7bea7ca598715c4654846 (patch) | |
tree | d72b9214637470eb0974679e672c581a93286777 /drivers/staging/iio/Documentation/generic_buffer.c | |
parent | staging:iio:Documentation: cleanup properly in buffer handling code (diff) | |
download | linux-dev-117cf8b7e879a33b24b7bea7ca598715c4654846.tar.xz linux-dev-117cf8b7e879a33b24b7bea7ca598715c4654846.zip |
staging:iio:generic_buffer example - handle endian differences
Signed-off-by: Jonathan Cameron <jic23@cam.ac.uk>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
Diffstat (limited to 'drivers/staging/iio/Documentation/generic_buffer.c')
-rw-r--r-- | drivers/staging/iio/Documentation/generic_buffer.c | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/drivers/staging/iio/Documentation/generic_buffer.c b/drivers/staging/iio/Documentation/generic_buffer.c index d58095321491..69a05b9456d6 100644 --- a/drivers/staging/iio/Documentation/generic_buffer.c +++ b/drivers/staging/iio/Documentation/generic_buffer.c @@ -28,6 +28,7 @@ #include <linux/types.h> #include <string.h> #include <poll.h> +#include <endian.h> #include "iio_utils.h" /** @@ -56,6 +57,13 @@ int size_from_channelarray(struct iio_channel_info *channels, int num_channels) void print2byte(int input, struct iio_channel_info *info) { + /* First swap if incorrect endian */ + + if (info->be) + input = be16toh((uint_16t)input); + else + input = le16toh((uint_16t)input); + /* shift before conversion to avoid sign extension of left aligned data */ input = input >> info->shift; |