Skip to content

Commit

Permalink
implement INT2, accelerometer test shows sleep state on LED
Browse files Browse the repository at this point in the history
  • Loading branch information
joeycastillo committed Oct 9, 2024
1 parent 9c0330f commit dd8599a
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
13 changes: 12 additions & 1 deletion watch-faces/demo/accel_interrupt_count_face.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,15 @@ void accel_interrupt_handler(void) {
(*ptr_to_count)++;
}

void sleep_interrupt_handler(void);
void sleep_interrupt_handler(void) {
if (HAL_GPIO_A3_read()) {
movement_force_led_on(255, 0, 0);
} else {
movement_force_led_on(0, 255, 0);
}
}

static void _accel_interrupt_count_face_update_display(accel_interrupt_count_state_t *state) {
char buf[7];

Expand All @@ -56,7 +65,8 @@ static void _accel_interrupt_count_face_update_display(accel_interrupt_count_sta
static void _accel_interrupt_count_face_configure_threshold(uint8_t threshold) {
lis2dw_enable_sleep();
lis2dw_configure_wakeup_threshold(threshold);
lis2dw_configure_int1(LIS2DW_CTRL4_INT1_WU);
// lis2dw_configure_int1(LIS2DW_CTRL4_INT1_WU);
lis2dw_configure_int2(LIS2DW_CTRL5_INT2_SLEEP_CHG);
lis2dw_enable_interrupts();
}

Expand Down Expand Up @@ -92,6 +102,7 @@ void accel_interrupt_count_face_activate(void *context) {

state->running = true;
watch_register_interrupt_callback(HAL_GPIO_A4_pin(), accel_interrupt_handler, INTERRUPT_TRIGGER_RISING);
watch_register_interrupt_callback(HAL_GPIO_A3_pin(), sleep_interrupt_handler, INTERRUPT_TRIGGER_BOTH);
}

bool accel_interrupt_count_face_loop(movement_event_t event, void *context) {
Expand Down
4 changes: 4 additions & 0 deletions watch-library/shared/driver/lis2dw.c
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,10 @@ void lis2dw_configure_int1(uint8_t sources) {
watch_i2c_write8(LIS2DW_ADDRESS, LIS2DW_REG_CTRL4_INT1, sources);
}

void lis2dw_configure_int2(uint8_t sources) {
watch_i2c_write8(LIS2DW_ADDRESS, LIS2DW_REG_CTRL5_INT2, sources);
}

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);
Expand Down
2 changes: 2 additions & 0 deletions watch-library/shared/driver/lis2dw.h
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,8 @@ void lis2dw_configure_wakeup_threshold(uint8_t threshold);

void lis2dw_configure_int1(uint8_t sources);

void lis2dw_configure_int2(uint8_t sources);

void lis2dw_enable_interrupts(void);

void lis2dw_disable_interrupts(void);
Expand Down

0 comments on commit dd8599a

Please sign in to comment.