Compare commits

..

No commits in common. "b86e97662a4f2aebb8482219bbcd80f8a8e2c694" and "d25f5ab98e0fa8701e042b9c3fee7f434857eaac" have entirely different histories.

5 changed files with 36 additions and 58 deletions

View File

@ -1,14 +1,14 @@
/*
* SCLICK SCLICK
* __________ ___________
* | | | | |
* | | | | |
* ----- -------------------- | ------
* |
* TIME_LIMIT TIME_LIMIT |
* >---------< >--------< | ==> DCLICK_INT
* LATENCY WINDOW >----|---<
* >----------<>----------< LATENCY
* SCLICK SCLICK
* _________ __________
* | | | | |
* | | | | |
* ----- ------------------ | ------
* |
* TIME_LIMIT TIME_LIMIT|
* >---------< >----------<|
* LATENCY WINDOW |
* >----------<>----------< | => DCLICK INT
* */
#define _GNU_SOURCE
#include <stdio.h>
@ -54,20 +54,18 @@ int main() {
lis.cfg.filter.mode = LIS3DH_FILTER_MODE_NORMAL;
lis.cfg.filter.cutoff = LIS3DH_FILTER_CUTOFF_8;
lis.cfg.filter.click = 1; /* enable filtering for CLICK function */
lis.cfg.click.xd = 1; /* enable X axis double click */
lis.cfg.click.yd = 1; /* enable Y axis double click */
lis.cfg.click.zd = 1; /* enable Z axis double click */
lis.cfg.pin1.click = 1; /* enable click int src through pin1 */
lis.cfg.int1.latch = 1; /* latch interrupt until INT1_SRC is read */
/* 1 LSb = 16 mg @ FS_2G
* so a 0.3g 'shock' is 300/16 = 18.75
* However, the device can have up to +- 40mg read error, so add 40mg
* 0.34g => 340/16 ~= 21
* so a 0.072g 'shock' is 72/16 = 4.5
* However, the device can have up to +- 40mg read error
* 0.112g => 112/16 = 15
*/
lis.cfg.click_ths = 21; /* pretty sensitive */
lis.cfg.click_ths = 15; /* pretty sensitive */
/* Duration time is measured in N/ODR where:
* --- N = The content of the intX_dur integer
@ -90,11 +88,6 @@ int main() {
/* error handling */
}
/* read CLICK_SRC to clear previous interrupts, if any */
if (lis3dh_read_click(&lis)) {
/* error handling */
}
for(;;) {
/* poll interrupt on INT1 pin */
@ -107,10 +100,10 @@ int main() {
/* error handling */
}
/* only print if DCLICK=1 */
/* only print data if DCLICK=1 in CLICK_SRC */
if (LIS3DH_CLICK_DCLICK(lis.src.click)) {
/* print data gathered from CLICK_SRC */
printf("Click: X=%d, Y=%d, Z=%d, Sign=%d, S_CLICK=%d, D_CLICK=%d\n",
printf("Click: X=%d, Y=%d, Z=%d, Sign=%d, S_en=%d, D_en=%d\n",
LIS3DH_CLICK_SRC_X(lis.src.click),
LIS3DH_CLICK_SRC_Y(lis.src.click),
LIS3DH_CLICK_SRC_Z(lis.src.click),
@ -118,10 +111,6 @@ int main() {
LIS3DH_CLICK_SCLICK(lis.src.click),
LIS3DH_CLICK_DCLICK(lis.src.click));
}
/* sleep for 5 ms because gpio sysfs is slow at clearing interrupts */
/* not necessary with "real" IRQ */
usleep(5000);
}
/* unregister interrupt */

View File

@ -45,7 +45,7 @@ int main() {
/* 1 LSb = 16 mg @ FS_2G
* 0.3g threshold = 300/16 = 18.75
* add read error, +40mg => 340/16 = 21.25 ~= 21
* add read error, +40mg => 240/16 = 21.25 ~= 21
* if you for some reason don't want to use the HP filter,
* just add 1g to the threshold calculation.
*/
@ -72,7 +72,8 @@ int main() {
lis.cfg.int1.aoi = 0; /* set to 1 for AND mode */
lis.cfg.int1.en_6d = 0;
/* latch interrupt */
/* latch interrupt. might not work. */
lis.cfg.int1.latch = 1;
/* set up a HP filter to ignore constant earth acceleration */
@ -80,6 +81,7 @@ int main() {
lis.cfg.filter.cutoff = LIS3DH_FILTER_CUTOFF_8;
lis.cfg.filter.ia1 = 1; /* enable filter for INT1 generator */
/* write device config */
if (lis3dh_configure(&lis)) {
/* error handling */
@ -109,17 +111,13 @@ int main() {
/* print received interrupt .. */
printf("IA=%d ZH=%d ZL=%d YH=%d YL=%d XH=%d XL=%d\n",
LIS3DH_INT_SRC_IA(lis.src.int1),
!!(lis.src.int1 & 0x40),
LIS3DH_INT_SRC_Z_HIGH(lis.src.int1),
LIS3DH_INT_SRC_Z_LOW(lis.src.int1),
LIS3DH_INT_SRC_Y_HIGH(lis.src.int1),
LIS3DH_INT_SRC_Y_LOW(lis.src.int1),
LIS3DH_INT_SRC_X_HIGH(lis.src.int1),
LIS3DH_INT_SRC_X_LOW(lis.src.int1));
/* sleep for 5 ms because gpio sysfs is slow at clearing interrupts */
/* not necessary with "real" IRQ */
usleep(5000);
}
/* unregister interrupt */

View File

@ -199,7 +199,6 @@ int lis3dh_configure(lis3dh_t *lis3dh) {
err |= lis3dh->dev.write(REG_ACT_THS, act_ths);
err |= lis3dh->dev.write(REG_ACT_DUR, lis3dh->cfg.act_dur);
err |= lis3dh->dev.write(REG_TEMP_CFG_REG, temp_cfg_reg);
err |= lis3dh->dev.write(REG_REFERENCE, lis3dh->cfg.reference);
err |= lis3dh->dev.write(REG_CTRL_REG0, ctrl_reg0);
err |= lis3dh->dev.write(REG_CTRL_REG1, ctrl_reg1);
@ -288,7 +287,6 @@ int lis3dh_read(lis3dh_t *lis3dh) {
return err;
}
/* assume fifo has been configured and poll'd */
int lis3dh_read_fifo(lis3dh_t *lis3dh, struct lis3dh_fifo_data *fifo) {
int32_t x, y, z;
uint8_t scale, sens;

View File

@ -4,21 +4,20 @@
#include <stdint.h>
/* macros for checking INT_SRC registers upon interrupt */
#define LIS3DH_INT_SRC_X_LOW(c) (!!(c & 0x01)) /* X axis low */
#define LIS3DH_INT_SRC_X_HIGH(c) (!!(c & 0x02)) /* X axis high */
#define LIS3DH_INT_SRC_Y_LOW(c) (!!(c & 0x04)) /* Y axis low */
#define LIS3DH_INT_SRC_Y_HIGH(c) (!!(c & 0x08)) /* Y axis high */
#define LIS3DH_INT_SRC_Z_LOW(c) (!!(c & 0x10)) /* Z axis low */
#define LIS3DH_INT_SRC_Z_HIGH(c) (!!(c & 0x20)) /* Z axis high */
#define LIS3DH_INT_SRC_IA(c) (!!(c & 0x40)) /* Interrupt active */
#define LIS3DH_INT_SRC_X_LOW(c) ((c & 1) == 1)
#define LIS3DH_INT_SRC_X_HIGH(c) (((c >> 1) & 1) == 1)
#define LIS3DH_INT_SRC_Y_LOW(c) (((c >> 2) & 1) == 1)
#define LIS3DH_INT_SRC_Y_HIGH(c) (((c >> 3) & 1) == 1)
#define LIS3DH_INT_SRC_Z_LOW(c) (((c >> 4) & 1) == 1)
#define LIS3DH_INT_SRC_Z_HIGH(c) (((c >> 5) & 1) == 1)
/* macros for checking CLICK_SRC register upon interrupt */
#define LIS3DH_CLICK_SRC_X(c) (!!(c & 0x01)) /* X high event */
#define LIS3DH_CLICK_SRC_Y(c) (!!(c & 0x02)) /* Y high event */
#define LIS3DH_CLICK_SRC_Z(c) (!!(c & 0x04)) /* Z high event */
#define LIS3DH_CLICK_SIGN(c) (!!(c & 0x08)) /* Click sign, 1 = positive */
#define LIS3DH_CLICK_SCLICK(c) (!!(c & 0x10)) /* Single-click det. enabled */
#define LIS3DH_CLICK_DCLICK(c) (!!(c & 0x20)) /* Double-click det. enabled */
#define LIS3DH_CLICK_SRC_X(c) ((c & 1) == 1) /* X high event */
#define LIS3DH_CLICK_SRC_Y(c) (((c >> 1) & 1) == 1) /* Y high event */
#define LIS3DH_CLICK_SRC_Z(c) (((c >> 2) & 1) == 1) /* Z high event */
#define LIS3DH_CLICK_SIGN(c) (((c >> 3) & 1) == 1) /* Click sign, 1 = positive */
#define LIS3DH_CLICK_SCLICK(c) (((c >> 4) & 1) == 1) /* Single-click det. enabled */
#define LIS3DH_CLICK_DCLICK(c) (((c >> 5) & 1) == 1) /* Double-click det. enabled */
/* rates */
/* all power modes */
@ -127,7 +126,7 @@ struct lis3dh_int_config {
uint8_t latch; /* active until INT1_SRC/INT2_SRC is read */
};
/* config for interrupt output pin #2 */
/* config for INT2 trigger output */
struct lis3dh_int_pin2_config {
uint8_t click; /* CLICK interrupt */
uint8_t ia1; /* IA1 interrupt */
@ -137,7 +136,7 @@ struct lis3dh_int_pin2_config {
uint8_t polarity; /* INT1 & INT2 polarity. 0 active high, 1 active low */
};
/* config for interrupt output pin #1 */
/* config for INT1 trigger output */
struct lis3dh_int_pin1_config {
uint8_t click; /* CLICK interrupt */
uint8_t ia1; /* IA1 interrupt */
@ -222,8 +221,6 @@ struct lis3dh_config {
uint8_t sdo_pullup; /* Use pull-up on SDO. default 0 use */
uint8_t en_adc; /* enable ADC */
uint8_t en_temp; /* enable temp sensor on ADC 3 */
uint8_t reference; /* HP filter reference */
};
/* reads from internal ADCs.

6
main.c
View File

@ -118,17 +118,13 @@ int main() {
/* print received interrupt .. */
printf("IA=%d ZH=%d ZL=%d YH=%d YL=%d XH=%d XL=%d\n",
LIS3DH_INT_SRC_IA(lis.src.int1),
!!(lis.src.int1 & 0x40),
LIS3DH_INT_SRC_Z_HIGH(lis.src.int1),
LIS3DH_INT_SRC_Z_LOW(lis.src.int1),
LIS3DH_INT_SRC_Y_HIGH(lis.src.int1),
LIS3DH_INT_SRC_Y_LOW(lis.src.int1),
LIS3DH_INT_SRC_X_HIGH(lis.src.int1),
LIS3DH_INT_SRC_X_LOW(lis.src.int1));
/* sleep for 5 ms because gpio sysfs is slow at clearing interrupts */
/* not necessary with "real" IRQ */
usleep(5000);
}
/* unregister interrupt */