summaryrefslogtreecommitdiff
path: root/driver/mag_lis2mdl.h
diff options
context:
space:
mode:
authorYuval Peress <peress@chromium.org>2019-03-15 13:35:39 -0600
committerchrome-bot <chrome-bot@chromium.org>2019-04-23 10:16:29 -0700
commite166fa21167e0acb79a172fd44a9f4ac410a5b27 (patch)
treed9079d9e3a45aea52e271ac4fc6c56b829865ea3 /driver/mag_lis2mdl.h
parentdeee174f01c6272617321ffa9f2bcad50e255447 (diff)
downloadchrome-ec-e166fa21167e0acb79a172fd44a9f4ac410a5b27.tar.gz
driver: lis2mdl: add standalone support
BRANCH=None BUG=b:128619310 TEST=Created new console commands to directly trigger init, read, and set_data_rate for the sensor. Manually verified behavior and register values from the magnetometer using ISH console. Change-Id: Ie162827f596056ee4cfd96be5c457e08708a9b9b Signed-off-by: Yuval Peress <peress@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/1534339 Commit-Ready: Jett Rink <jettrink@chromium.org> Reviewed-by: Jett Rink <jettrink@chromium.org>
Diffstat (limited to 'driver/mag_lis2mdl.h')
-rw-r--r--driver/mag_lis2mdl.h50
1 files changed, 37 insertions, 13 deletions
diff --git a/driver/mag_lis2mdl.h b/driver/mag_lis2mdl.h
index 9d1941de6a..0a415ceebd 100644
--- a/driver/mag_lis2mdl.h
+++ b/driver/mag_lis2mdl.h
@@ -12,27 +12,41 @@
#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
+ * 8-bit address is 0011110Wb where the last bit represents whether the
+ * operation is a read or a write.
*/
-#define LIS2MDL_ADDR0 LIS2MDL_I2C_ADDR(0x1e)
-#define LIS2MDL_ADDR1 LIS2MDL_I2C_ADDR(0x1f)
+#define LIS2MDL_ADDR 0x3c
+
+#define LIS2MDL_STARTUP_MS 10
/* Registers */
#define LIS2MDL_WHO_AM_I_REG 0x4f
-#define LIS2MDL_WHO_AM_I 0x40
-
#define LIS2MDL_CFG_REG_A_ADDR 0x60
-#define LIS2MDL_SW_RESET 0x20
-#define LIS2MDL_ODR_100HZ 0xc
-#define LIS2MDL_CONT_MODE 0x0
-
+#define LIS2MDL_INT_CTRL_REG 0x63
#define LIS2MDL_STATUS_REG 0x67
#define LIS2MDL_OUT_REG 0x68
+#define LIS2MDL_WHO_AM_I 0x40
+
+#define LIS2MDL_FLAG_TEMP_COMPENSATION 0x80
+#define LIS2MDL_FLAG_REBOOT 0x40
+#define LIS2MDL_FLAG_SW_RESET 0x20
+#define LIS2MDL_FLAG_LOW_POWER 0x10
+#define LIS2MDL_ODR_50HZ 0x08
+#define LIS2MDL_ODR_20HZ 0x04
+#define LIS2MDL_ODR_10HZ 0x00
+#define LIS2MDL_MODE_IDLE 0x03
+#define LIS2MDL_MODE_SINGLE 0x01
+#define LIS2MDL_MODE_CONT 0x00
+#define LIS2MDL_ODR_MODE_MASK 0x8f
+
+#define LIS2MDL_X_DIRTY 0x01
+#define LIS2MDL_Y_DIRTY 0x02
+#define LIS2MDL_Z_DIRTY 0x04
+#define LIS2MDL_XYZ_DIRTY 0x08
+#define LIS2MDL_XYZ_DIRTY_MASK 0x0f
+
#define LIS2DSL_RESOLUTION 16
/*
* Maximum sensor data range (milligauss):
@@ -42,16 +56,26 @@
*/
#define LIS2MDL_RATIO(_in) (((_in) * 24) / 10)
-
struct lis2mdl_private_data {
/* lsm6dsm_data union requires cal be first element */
struct mag_cal_t cal;
+ struct stprivate_data data;
#ifdef CONFIG_MAG_BMI160_LIS2MDL
intv3_t hn; /* last sample for offset compensation */
int hn_valid;
#endif
};
+#define LIS2MDL_GET_DATA(_s) \
+ ((struct lis2mdl_private_data *)(_s->drv_data))
+
+#define LIS2MDL_ST_DATA(_s) \
+ (&(LIS2MDL_GET_DATA(_s)->data))
+
+#if !defined(CONFIG_LSM6DSM_SEC_I2C) && defined(CONFIG_MAG_CALIBRATE)
+#define LIS2MDL_CAL(_s) (&LIS2MDL_GET_DATA(_s)->cal)
+#endif
+
#define LIS2MDL_ODR_MIN_VAL 10000
#define LIS2MDL_ODR_MAX_VAL 50000