]> git.earman.xyz Git - sensor-watch.git/commitdiff
separate out interrupt config vs enable
authorjoeycastillo <joeycastillo@utexas.edu>
Wed, 9 Oct 2024 05:09:48 +0000 (01:09 -0400)
committerjoeycastillo <joeycastillo@utexas.edu>
Wed, 9 Oct 2024 05:39:01 +0000 (01:39 -0400)
watch-faces/demo/accel_interrupt_count_face.c
watch-library/shared/driver/lis2dw.c
watch-library/shared/driver/lis2dw.h

index e7b61ffcc7dc2da59662c8640eb4b0bb994eee21..5f8d145e708ad4523497e2002284ee86df507c98 100644 (file)
@@ -54,7 +54,10 @@ static void _accel_interrupt_count_face_update_display(accel_interrupt_count_sta
 }
 
 static void _accel_interrupt_count_face_configure_threshold(uint8_t threshold) {
-    lis2dw_configure_wakeup_int1(threshold, false, true);
+    lis2dw_enable_sleep();
+    lis2dw_configure_wakeup_threshold(threshold);
+    lis2dw_configure_int1(LIS2DW_CTRL4_INT1_WU);
+    lis2dw_enable_interrupts();
 }
 
 void accel_interrupt_count_face_setup(uint8_t watch_face_index, void ** context_ptr) {
@@ -104,7 +107,7 @@ bool accel_interrupt_count_face_loop(movement_event_t event, void *context) {
                 }
                 break;
             case EVENT_ALARM_BUTTON_UP:
-                lis2dw_configure_wakeup_int1(state->threshold, false, true);
+                lis2dw_configure_wakeup_threshold(state->new_threshold);
                 state->threshold = state->new_threshold;
                 state->is_setting = false;
                 break;
index b39270281ac3fbb793267a112f8b28078e10a39d..7dbe8a4f570e1123ae8865b8d377dd957660ebd1 100644 (file)
@@ -208,27 +208,45 @@ void lis2dw_clear_fifo(void) {
     watch_i2c_write8(LIS2DW_ADDRESS, LIS2DW_REG_FIFO_CTRL, LIS2DW_FIFO_CTRL_MODE_COLLECT_AND_STOP | LIS2DW_FIFO_CTRL_FTH);
 }
 
-void lis2dw_configure_wakeup_int1(uint8_t threshold, bool latch, bool active_state) {
-    uint8_t configuration;
+void lis2dw_enable_sleep(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_SLEEP_ON);
+}
+
+void lis2dw_disable_sleep(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_SLEEP_ON);
+}
+
+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);
+}
 
-    // enable wakeup interrupt on INT1 pin
-    configuration = watch_i2c_read8(LIS2DW_ADDRESS, LIS2DW_REG_CTRL4_INT1);
-    watch_i2c_write8(LIS2DW_ADDRESS, LIS2DW_REG_CTRL4_INT1, configuration | LIS2DW_CTRL4_INT1_WU);
+void lis2dw_disable_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);
+}
 
-    // set threshold
-    watch_i2c_write8(LIS2DW_ADDRESS, LIS2DW_REG_WAKE_UP_THS, threshold | LIS2DW_WAKE_UP_THS_VAL_SLEEP_ON);
-    watch_i2c_write8(LIS2DW_ADDRESS, LIS2DW_REG_INT1_DUR, 0b01111111);
+void lis2dw_configure_wakeup_threshold(uint8_t threshold) {
+    uint8_t configuration = watch_i2c_read8(LIS2DW_ADDRESS, LIS2DW_REG_WAKE_UP_THS) & 0b11000000;
+    watch_i2c_write8(LIS2DW_ADDRESS, LIS2DW_REG_WAKE_UP_THS, configuration | threshold);
+}
 
-    configuration = watch_i2c_read8(LIS2DW_ADDRESS, LIS2DW_REG_CTRL3) & ~(LIS2DW_CTRL3_VAL_LIR);
-    if (!active_state) configuration |= LIS2DW_CTRL3_VAL_H_L_ACTIVE;
-    if (latch) configuration |= LIS2DW_CTRL3_VAL_LIR;
-    watch_i2c_write8(LIS2DW_ADDRESS, LIS2DW_REG_CTRL3, configuration);
+void lis2dw_configure_int1(uint8_t sources) {
+    watch_i2c_write8(LIS2DW_ADDRESS, LIS2DW_REG_CTRL4_INT1, sources);
+}
 
-    // enable interrupts
-    configuration = watch_i2c_read8(LIS2DW_ADDRESS, LIS2DW_REG_CTRL7);
+void lis2dw_enable_interrupts(void) {
+    uint8_t configuration = watch_i2c_read8(LIS2DW_ADDRESS, LIS2DW_REG_CTRL7);
     watch_i2c_write8(LIS2DW_ADDRESS, LIS2DW_REG_CTRL7, configuration | LIS2DW_CTRL7_VAL_INTERRUPTS_ENABLE);
 }
 
+void lis2dw_disable_interrupts(void) {
+    uint8_t configuration = watch_i2c_read8(LIS2DW_ADDRESS, LIS2DW_REG_CTRL7);
+    watch_i2c_write8(LIS2DW_ADDRESS, LIS2DW_REG_CTRL7, configuration & ~LIS2DW_CTRL7_VAL_INTERRUPTS_ENABLE);
+}
+
 lis2dw_wakeup_source_t lis2dw_get_wakeup_source() {
     return (lis2dw_wakeup_source_t) watch_i2c_read8(LIS2DW_ADDRESS, LIS2DW_REG_WAKE_UP_SRC);
 }
index 9815c2c69923caa71eb4eaff821e0054da4a05a6..d6379c07e830a9c85ea14f2971691e88a7d64e4a 100644 (file)
@@ -335,7 +335,21 @@ bool lis2dw_read_fifo(lis2dw_fifo_t *fifo_data);
 
 void lis2dw_clear_fifo(void);
 
-void lis2dw_configure_wakeup_int1(uint8_t threshold, bool latch, bool active_state);
+void lis2dw_enable_sleep(void);
+
+void lis2dw_disable_sleep(void);
+
+void lis2dw_enable_tap_detection(void);
+
+void lis2dw_disable_tap_detection(void);
+
+void lis2dw_configure_wakeup_threshold(uint8_t threshold);
+
+void lis2dw_configure_int1(uint8_t sources);
+
+void lis2dw_enable_interrupts(void);
+
+void lis2dw_disable_interrupts(void);
 
 lis2dw_interrupt_source_t lis2dw_get_interrupt_source(void);