Skip to content

Commit

Permalink
separate out interrupt config vs enable
Browse files Browse the repository at this point in the history
  • Loading branch information
joeycastillo committed Oct 9, 2024
1 parent d9bee40 commit eb9206c
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 17 deletions.
7 changes: 5 additions & 2 deletions watch-faces/demo/accel_interrupt_count_face.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
Expand Down
46 changes: 32 additions & 14 deletions watch-library/shared/driver/lis2dw.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
16 changes: 15 additions & 1 deletion watch-library/shared/driver/lis2dw.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down

0 comments on commit eb9206c

Please sign in to comment.