From 30dd007291e625fe42897d2f2f2f5bd3d2569900 Mon Sep 17 00:00:00 2001 From: Gwendal Grignou Date: Fri, 30 Nov 2018 17:06:39 -0800 Subject: driver: lsm6dsm: Integrate LIS2MDL behind LSM6DSM - Cros set_rate and normalize between LIS2MDL and LSM6DSM - Remove unused sensor hub function. - Remove parent field, use macro instead (magnetometer is just after the gyroscope). BUG=b:110143516,b:115587004 BRANCH=none TEST=On meep, check the magnetometer is returning data with shell/python script. Check calibration quick in. Check with AIDA64, compass and sensor app the magnetometer is seen. Change-Id: I2efef99eda095e33b6a0555b1cbc4ac8fdbfab5d Signed-off-by: Gwendal Grignou Reviewed-on: https://chromium-review.googlesource.com/c/1361992 Reviewed-by: Justin TerAvest Trybot-Ready: Justin TerAvest Tested-by: Justin TerAvest --- driver/mag_lis2mdl.h | 36 +++++++++++++++++++++++++++++++++--- 1 file changed, 33 insertions(+), 3 deletions(-) (limited to 'driver/mag_lis2mdl.h') diff --git a/driver/mag_lis2mdl.h b/driver/mag_lis2mdl.h index 13e1b422e4..9d1941de6a 100644 --- a/driver/mag_lis2mdl.h +++ b/driver/mag_lis2mdl.h @@ -8,11 +8,20 @@ #ifndef __CROS_EC_MAG_LIS2MDL_H #define __CROS_EC_MAG_LIS2MDL_H +#include "accelgyro.h" +#include "mag_cal.h" +#include "stm_mems_common.h" + #define LIS2MDL_I2C_ADDR(__x) (__x << 1) +/* + * 7-bit address is 0011110Xb. Where 'X' is determined + * by the voltage on the ADDR pin + */ #define LIS2MDL_ADDR0 LIS2MDL_I2C_ADDR(0x1e) #define LIS2MDL_ADDR1 LIS2MDL_I2C_ADDR(0x1f) +/* Registers */ #define LIS2MDL_WHO_AM_I_REG 0x4f #define LIS2MDL_WHO_AM_I 0x40 @@ -24,15 +33,36 @@ #define LIS2MDL_STATUS_REG 0x67 #define LIS2MDL_OUT_REG 0x68 -#define LIS2MDL_RANGE 4915 -#define LIS2MDL_RESOLUTION 16 +#define LIS2DSL_RESOLUTION 16 +/* + * Maximum sensor data range (milligauss): + * Spec is 1.5 mguass / LSB, so 0.15 uT / LSB. + * Calibration code is set to 16LSB/ut, [0.0625 uT/LSB] + * Apply a multiplier to change the unit + */ +#define LIS2MDL_RATIO(_in) (((_in) * 24) / 10) + + +struct lis2mdl_private_data { + /* lsm6dsm_data union requires cal be first element */ + struct mag_cal_t cal; +#ifdef CONFIG_MAG_BMI160_LIS2MDL + intv3_t hn; /* last sample for offset compensation */ + int hn_valid; +#endif +}; + #define LIS2MDL_ODR_MIN_VAL 10000 -#define LIS2MDL_ODR_MAX_VAL 100000 +#define LIS2MDL_ODR_MAX_VAL 50000 #if (CONFIG_EC_MAX_SENSOR_FREQ_MILLIHZ <= LIS2MDL_ODR_MAX_VAL) #error "EC too slow for magnetometer" #endif +void lis2mdl_normalize(const struct motion_sensor_t *s, + intv3_t v, + uint8_t *data); + extern const struct accelgyro_drv lis2mdl_drv; #endif /* __CROS_EC_MAG_LIS2MDL_H */ -- cgit v1.2.1