aboutsummaryrefslogtreecommitdiffstats
path: root/include/linux/iio/iio.h
diff options
context:
space:
mode:
authorLars-Peter Clausen <lars@metafoo.de>2012-10-15 05:35:00 -0400
committerJonathan Cameron <jic23@kernel.org>2012-10-19 11:12:38 -0400
commit9dbf8ccde1b810a59b684e1d1aec7f9d2d007162 (patch)
treeb9ea9422165c02ca043b2936730afef4629a8f55 /include/linux/iio/iio.h
parentddffeb8c4d0331609ef2581d84de4d763607bd37 (diff)
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.h16
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)
618}; 618};
619#endif 619#endif
620 620
621/**
622 * IIO_DEGREE_TO_RAD() - Convert degree to rad
623 * @deg: A value in degree
624 *
625 * Returns the given value converted from degree to rad
626 */
627#define IIO_DEGREE_TO_RAD(deg) (((deg) * 314159ULL + 9000000ULL) / 18000000ULL)
628
629/**
630 * IIO_G_TO_M_S_2() - Convert g to meter / second**2
631 * @g: A value in g
632 *
633 * Returns the given value converted from g to meter / second**2
634 */
635#define IIO_G_TO_M_S_2(g) ((g) * 980665ULL / 100000ULL)
636
621#endif /* _INDUSTRIAL_IO_H_ */ 637#endif /* _INDUSTRIAL_IO_H_ */