]> git.earman.xyz Git - sensor-watch.git/commitdiff
lis2dw driver: add stationary/motion detection
authorjoeycastillo <joeycastillo@utexas.edu>
Sat, 19 Oct 2024 18:54:33 +0000 (14:54 -0400)
committerjoeycastillo <joeycastillo@utexas.edu>
Sat, 19 Oct 2024 18:54:33 +0000 (14:54 -0400)
watch-library/shared/driver/lis2dw.c
watch-library/shared/driver/lis2dw.h

index a9d21706b931097e5021615f26d045a50b60dcaa..fdef6539c3de6b8f48f6710f46a990daf40f08e6 100644 (file)
@@ -218,6 +218,16 @@ void lis2dw_disable_sleep(void) {
     watch_i2c_write8(LIS2DW_ADDRESS, LIS2DW_REG_WAKE_UP_THS, configuration & ~LIS2DW_WAKE_UP_THS_VAL_SLEEP_ON);
 }
 
+void lis2dw_enable_stationary_motion_detection(void) {
+    uint8_t configuration = watch_i2c_read8(LIS2DW_ADDRESS, LIS2DW_REG_WAKE_UP_DUR);
+    watch_i2c_write8(LIS2DW_ADDRESS, LIS2DW_REG_WAKE_UP_DUR, configuration | LIS2DW_WAKE_UP_DUR_STATIONARY);
+}
+
+void lis2dw_disable_stationary_motion_detection(void) {
+    uint8_t configuration = watch_i2c_read8(LIS2DW_ADDRESS, LIS2DW_REG_WAKE_UP_DUR);
+    watch_i2c_write8(LIS2DW_ADDRESS, LIS2DW_REG_WAKE_UP_DUR, configuration & ~LIS2DW_WAKE_UP_DUR_STATIONARY);
+}
+
 void lis2dw_enable_tap_detection(void) {
     uint8_t configuration = watch_i2c_read8(LIS2DW_ADDRESS, LIS2DW_REG_WAKE_UP_THS);
     watch_i2c_write8(LIS2DW_ADDRESS, LIS2DW_REG_WAKE_UP_THS, configuration | LIS2DW_WAKE_UP_THS_VAL_TAP_EVENT_ENABLED);
index 6185150f8cc96f2d2830e96494f50a420dd7231c..1869feb64fe1cf1499015ac2d6e21f9445bcc9fa 100644 (file)
@@ -236,6 +236,8 @@ typedef enum {
 #define LIS2DW_WAKE_UP_THS_VAL_SLEEP_ON          0b01000000
 
 #define LIS2DW_REG_WAKE_UP_DUR 0x35
+#define LIS2DW_WAKE_UP_DUR_STATIONARY 0b00010000
+
 #define LIS2DW_REG_FREE_FALL 0x36
 #define LIS2DW_REG_STATUS_DUP 0x37
 
@@ -339,6 +341,10 @@ void lis2dw_enable_sleep(void);
 
 void lis2dw_disable_sleep(void);
 
+void lis2dw_enable_stationary_motion_detection(void);
+
+void lis2dw_disable_stationary_motion_detection(void);
+
 void lis2dw_enable_tap_detection(void);
 
 void lis2dw_disable_tap_detection(void);