linux-iio.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 01/11] iio: Add some helper macros for unit conversion
@ 2012-10-15  9:35 Lars-Peter Clausen
  2012-10-15  9:35 ` [PATCH 02/11] staging:iio: Fix adis16201 channel offsets and scales Lars-Peter Clausen
                   ` (10 more replies)
  0 siblings, 11 replies; 17+ messages in thread
From: Lars-Peter Clausen @ 2012-10-15  9:35 UTC (permalink / raw)
  To: Jonathan Cameron; +Cc: linux-iio, drivers, Lars-Peter Clausen

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>
---
 include/linux/iio/iio.h |   16 ++++++++++++++++
 1 file changed, 16 insertions(+)

diff --git a/include/linux/iio/iio.h b/include/linux/iio/iio.h
index c0ae76a..7806c24 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_ */
-- 
1.7.10.4


^ permalink raw reply related	[flat|nested] 17+ messages in thread

end of thread, other threads:[~2012-10-19  5:30 UTC | newest]

Thread overview: 17+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-10-15  9:35 [PATCH 01/11] iio: Add some helper macros for unit conversion Lars-Peter Clausen
2012-10-15  9:35 ` [PATCH 02/11] staging:iio: Fix adis16201 channel offsets and scales Lars-Peter Clausen
2012-10-18  9:06   ` Jonathan Cameron
2012-10-15  9:35 ` [PATCH 03/11] staging:iio: Fix adis16203 " Lars-Peter Clausen
2012-10-18  9:07   ` Jonathan Cameron
2012-10-15  9:35 ` [PATCH 04/11] " Lars-Peter Clausen
2012-10-15  9:42   ` Lars-Peter Clausen
2012-10-18  9:07     ` Jonathan Cameron
2012-10-15  9:35 ` [PATCH 05/11] staging:iio: Fix adis16209 " Lars-Peter Clausen
2012-10-18  9:09   ` Jonathan Cameron
2012-10-15  9:35 ` [PATCH 06/11] staging:iio: Fix adis16220 " Lars-Peter Clausen
2012-10-15  9:35 ` [PATCH 07/11] staging:iio: Fix adis16240 " Lars-Peter Clausen
2012-10-15  9:35 ` [PATCH 08/11] staging:iio: Fix adis16260 " Lars-Peter Clausen
2012-10-15  9:35 ` [PATCH 09/11] staging:iio: Fix adis16400 " Lars-Peter Clausen
2012-10-15  9:35 ` [PATCH 10/11] staging:iio:adis16400: Report correct temperature scale and offset Lars-Peter Clausen
2012-10-15  9:35 ` [PATCH 11/11] staging:iio:adis16400: Fixup adis16336 temp channel attributes Lars-Peter Clausen
2012-10-18  8:57 ` [PATCH 01/11] iio: Add some helper macros for unit conversion Jonathan Cameron

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).