diff options
author | Lars-Peter Clausen <lars@metafoo.de> | 2012-10-15 10:35:00 +0100 |
---|---|---|
committer | Jonathan Cameron <jic23@kernel.org> | 2012-10-19 16:12:38 +0100 |
commit | 9dbf8ccde1b810a59b684e1d1aec7f9d2d007162 (patch) | |
tree | b9ea9422165c02ca043b2936730afef4629a8f55 /include/linux/iio/iio.h | |
parent | ddffeb8c4d0331609ef2581d84de4d763607bd37 (diff) | |
download | talos-obmc-linux-9dbf8ccde1b810a59b684e1d1aec7f9d2d007162.tar.gz talos-obmc-linux-9dbf8ccde1b810a59b684e1d1aec7f9d2d007162.zip |
iio: Add some helper macros for unit conversion
Some datasheets use a different unit to specify the channel scale than what IIO
expects it to be. This patch adds two helper macros which allow to convert units
commonly used in datasheets to IIO units:
* acceleration: g -> meter / second**2
* angular velocity: degree (/ second) -> rad (/ second)
This makes it much more convenient to specify and also easier to verify a
channel's scale attribute.
Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
Signed-off-by: Jonathan Cameron <jic23@kernel.org>
Diffstat (limited to 'include/linux/iio/iio.h')
-rw-r--r-- | include/linux/iio/iio.h | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/include/linux/iio/iio.h b/include/linux/iio/iio.h index c0ae76ac4e0b..7806c24e5bc8 100644 --- a/include/linux/iio/iio.h +++ b/include/linux/iio/iio.h @@ -618,4 +618,20 @@ static inline struct dentry *iio_get_debugfs_dentry(struct iio_dev *indio_dev) }; #endif +/** + * IIO_DEGREE_TO_RAD() - Convert degree to rad + * @deg: A value in degree + * + * Returns the given value converted from degree to rad + */ +#define IIO_DEGREE_TO_RAD(deg) (((deg) * 314159ULL + 9000000ULL) / 18000000ULL) + +/** + * IIO_G_TO_M_S_2() - Convert g to meter / second**2 + * @g: A value in g + * + * Returns the given value converted from g to meter / second**2 + */ +#define IIO_G_TO_M_S_2(g) ((g) * 980665ULL / 100000ULL) + #endif /* _INDUSTRIAL_IO_H_ */ |