diff --git a/lis3dh.c b/lis3dh.c index ba1ac89..f1a69d7 100644 --- a/lis3dh.c +++ b/lis3dh.c @@ -74,6 +74,7 @@ int lis3dh_init(lis3dh_t *lis3dh) { lis3dh->cfg.int1.drdy_321 = 0; lis3dh->cfg.int1.wtm = 0; lis3dh->cfg.int1.overrun = 0; + lis3dh->cfg.int1.latch = 0; lis3dh->cfg.int2.click = 0; lis3dh->cfg.int2.ia1 = 0; @@ -81,6 +82,7 @@ int lis3dh_init(lis3dh_t *lis3dh) { lis3dh->cfg.int2.boot = 0; lis3dh->cfg.int2.act = 0; lis3dh->cfg.int2.polarity = 0; + lis3dh->cfg.int2.latch = 0; err |= lis3dh_reset(lis3dh); @@ -119,6 +121,9 @@ int lis3dh_configure(lis3dh_t *lis3dh) { ctrl_reg6 |= (lis3dh->cfg.int2.act & 1) << 3; ctrl_reg6 |= (lis3dh->cfg.int2.polarity & 1) << 1; + ctrl_reg5 |= (lis3dh->cfg.int1.latch & 1) << 3; + ctrl_reg5 |= (lis3dh->cfg.int2.latch & 1) << 1; + /* set enable FIFO */ if (lis3dh->cfg.fifo.mode != 0xFF) { ctrl_reg5 |= 0x40; /* bit FIFO_EN */ @@ -331,4 +336,16 @@ int lis3dh_read_fifo(lis3dh_t *lis3dh, struct lis3dh_fifo_data *fifo) { int lis3dh_deinit(lis3dh_t *lis3dh) { return lis3dh->dev.deinit(); +} + +/* read INT1_SRC to clear latched INT1 irq */ +int lis3dh_clear_int1(lis3dh_t *lis3dh) { + uint8_t res; + return lis3dh->dev.read(REG_INT1_SRC, &res, 1); +} + +/* read INT2_SRC to clear latched INT2 irq */ +int lis3dh_clear_int2(lis3dh_t *lis3dh) { + uint8_t res; + return lis3dh->dev.read(REG_INT2_SRC, &res, 1); } \ No newline at end of file diff --git a/lis3dh.h b/lis3dh.h index d93b97c..5ce88c7 100644 --- a/lis3dh.h +++ b/lis3dh.h @@ -70,6 +70,7 @@ struct lis3dh_int2_config { uint8_t boot; /* enable BOOT on pin 2 */ uint8_t act; /* interrupt on activity */ uint8_t polarity; /* INT1 & INT2 polarity. 0 active high, 1 active low */ + uint8_t latch; }; struct lis3dh_int1_config { @@ -80,6 +81,7 @@ struct lis3dh_int1_config { uint8_t drdy_321; /* not sure */ uint8_t wtm; /* FIFO reached watermark level */ uint8_t overrun; /* FIFO has overrun */ + uint8_t latch; }; struct lis3dh_filter_config { @@ -136,6 +138,8 @@ int lis3dh_poll(lis3dh_t *lis3dh); int lis3dh_read(lis3dh_t *lis3dh); int lis3dh_poll_fifo(lis3dh_t *lis3dh); int lis3dh_read_fifo(lis3dh_t *lis3dh, struct lis3dh_fifo_data *fifo); +int lis3dh_clear_int1(lis3dh_t *lis3dh); +int lis3dh_clear_int2(lis3dh_t *lis3dh); diff --git a/main.c b/main.c index fc171a5..6c005d0 100644 --- a/main.c +++ b/main.c @@ -52,6 +52,7 @@ int main() { lis.cfg.fifo.mode = LIS3DH_FIFO_MODE_STREAM; lis.cfg.fifo.trig = LIS3DH_FIFO_TRIG_INT1; lis.cfg.int1.wtm = 1; + lis.cfg.int1.latch = 1; /* write device config */ @@ -64,6 +65,10 @@ int main() { quit("int_poll()", &lis); } + if (lis3dh_clear_int1(&lis)) { + quit("clear_int1()", &lis); + } + /* read stored fifo data into `fifo' struct */ if (lis3dh_read_fifo(&lis, &fifo)) { quit("read_fifo()", &lis);