Skip to content

Commit 9dbf8cc

Browse files
larsclausenjic23
authored andcommitted
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>
1 parent ddffeb8 commit 9dbf8cc

1 file changed

Lines changed: 16 additions & 0 deletions

File tree

‎include/linux/iio/iio.h‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -618,4 +618,20 @@ static inline struct dentry *iio_get_debugfs_dentry(struct iio_dev *indio_dev)
618618
};
619619
#endif
620620

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+
621637
#endif /* _INDUSTRIAL_IO_H_ */

0 commit comments

Comments
 (0)