Go to the documentation of this file.
43 #define LIS3DH_WHO_AM_I_RESPONSE (0x33)
49 #define LIS3DH_REG_STATUS_AUX (0x07)
50 #define LIS3DH_REG_OUT_AUX_ADC1_L (0x08)
51 #define LIS3DH_REG_OUT_AUX_ADC1_H (0x09)
52 #define LIS3DH_REG_OUT_AUX_ADC2_L (0x0A)
53 #define LIS3DH_REG_OUT_AUX_ADC2_H (0x0B)
54 #define LIS3DH_REG_OUT_AUX_ADC3_L (0x0C)
55 #define LIS3DH_REG_OUT_AUX_ADC3_H (0x0D)
56 #define LIS3DH_REG_INT_COUNTER_REG (0x0E)
57 #define LIS3DH_REG_WHO_AM_I (0x0F)
58 #define LIS3DH_REG_TEMP_CFG_REG (0x1F)
59 #define LIS3DH_REG_CTRL_REG1 (0x20)
60 #define LIS3DH_REG_CTRL_REG2 (0x21)
61 #define LIS3DH_REG_CTRL_REG3 (0x22)
62 #define LIS3DH_REG_CTRL_REG4 (0x23)
63 #define LIS3DH_REG_CTRL_REG5 (0x24)
64 #define LIS3DH_REG_CTRL_REG6 (0x25)
65 #define LIS3DH_REG_REFERENCE (0x26)
66 #define LIS3DH_REG_STATUS_REG (0x27)
67 #define LIS3DH_REG_OUT_X_L (0x28)
68 #define LIS3DH_REG_OUT_X_H (0x29)
69 #define LIS3DH_REG_OUT_Y_L (0x2A)
70 #define LIS3DH_REG_OUT_Y_H (0x2B)
71 #define LIS3DH_REG_OUT_Z_L (0x2C)
72 #define LIS3DH_REG_OUT_Z_H (0x2D)
73 #define LIS3DH_REG_FIFO_CTRL_REG (0x2E)
74 #define LIS3DH_REG_FIFO_SRC_REG (0x2F)
75 #define LIS3DH_REG_INT1_CFG (0x30)
76 #define LIS3DH_REG_INT1_SOURCE (0x31)
77 #define LIS3DH_REG_INT1_THS (0x32)
78 #define LIS3DH_REG_INT1_DURATION (0x33)
79 #define LIS3DH_REG_CLICK_CFG (0x38)
80 #define LIS3DH_REG_CLICK_SRC (0x39)
81 #define LIS3DH_REG_CLICK_THS (0x3A)
82 #define LIS3DH_REG_TIME_LIMIT (0x3B)
83 #define LIS3DH_REG_TIME_LATENCY (0x3C)
84 #define LIS3DH_REG_TIME_WINDOW (0x3D)
103 #define LIS3DH_TEMP_CFG_REG_ADC_PD_MASK (1 << 7)
111 #define LIS3DH_TEMP_CFG_REG_TEMP_EN_MASK (1 << 6)
121 #define LIS3DH_CTRL_REG1_ODR_SHIFT (4)
125 #define LIS3DH_CTRL_REG1_ODR3_MASK (1 << (LIS3DH_CTRL_REG1_ODR_SHIFT + 3))
129 #define LIS3DH_CTRL_REG1_ODR2_MASK (1 << (LIS3DH_CTRL_REG1_ODR_SHIFT + 2))
133 #define LIS3DH_CTRL_REG1_ODR1_MASK (1 << (LIS3DH_CTRL_REG1_ODR_SHIFT + 1))
137 #define LIS3DH_CTRL_REG1_ODR0_MASK (1 << LIS3DH_CTRL_REG1_ODR_SHIFT)
147 #define LIS3DH_CTRL_REG1_ODR_MASK (LIS3DH_CTRL_REG1_ODR3_MASK | \
148 LIS3DH_CTRL_REG1_ODR2_MASK | \
149 LIS3DH_CTRL_REG1_ODR1_MASK | \
150 LIS3DH_CTRL_REG1_ODR0_MASK)
159 #define LIS3DH_CTRL_REG1_LPEN_MASK (1 << 3)
163 #define LIS3DH_CTRL_REG1_ZEN_SHIFT (2)
172 #define LIS3DH_CTRL_REG1_ZEN_MASK (1 << LIS3DH_CTRL_REG1_ZEN_SHIFT)
176 #define LIS3DH_CTRL_REG1_YEN_SHIFT (1)
185 #define LIS3DH_CTRL_REG1_YEN_MASK (1 << LIS3DH_CTRL_REG1_YEN_SHIFT)
189 #define LIS3DH_CTRL_REG1_XEN_SHIFT (0)
198 #define LIS3DH_CTRL_REG1_XEN_MASK (1 << LIS3DH_CTRL_REG1_XEN_SHIFT)
202 #define LIS3DH_CTRL_REG1_XYZEN_SHIFT (0)
206 #define LIS3DH_CTRL_REG1_XYZEN_MASK (LIS3DH_CTRL_REG1_XEN_MASK | \
207 LIS3DH_CTRL_REG1_YEN_MASK | LIS3DH_CTRL_REG1_ZEN_MASK)
212 #define LIS3DH_AXES_X (LIS3DH_CTRL_REG1_XEN_MASK)
216 #define LIS3DH_AXES_Y (LIS3DH_CTRL_REG1_YEN_MASK)
220 #define LIS3DH_AXES_Z (LIS3DH_CTRL_REG1_ZEN_MASK)
226 #define LIS3DH_AXES_XYZ (LIS3DH_CTRL_REG1_XYZEN_MASK)
239 #define LIS3DH_CTRL_REG2_HPM1_MASK (1 << 7)
247 #define LIS3DH_CTRL_REG2_HPM0_MASK (1 << 6)
251 #define LIS3DH_CTRL_REG2_HPCF2_MASK (1 << 5)
255 #define LIS3DH_CTRL_REG2_HPCF1_MASK (1 << 4)
264 #define LIS3DH_CTRL_REG2_FDS_MASK (1 << 3)
271 #define LIS3DH_CTRL_REG2_HPCLICK_MASK (1 << 2)
278 #define LIS3DH_CTRL_REG2_HPIS2_MASK (1 << 1)
285 #define LIS3DH_CTRL_REG2_HPIS1_MASK (1 << 0)
300 #define LIS3DH_CTRL_REG3_I1_CLICK_MASK (1 << 7)
309 #define LIS3DH_CTRL_REG3_I1_AOI1_MASK (1 << 6)
318 #define LIS3DH_CTRL_REG3_I1_AOI2_MASK (1 << 5)
327 #define LIS3DH_CTRL_REG3_I1_DRDY1_MASK (1 << 4)
336 #define LIS3DH_CTRL_REG3_I1_DRDY2_MASK (1 << 3)
345 #define LIS3DH_CTRL_REG3_I1_WTM_MASK (1 << 2)
354 #define LIS3DH_CTRL_REG3_I1_OVERRUN_MASK (1 << 1)
369 #define LIS3DH_CTRL_REG4_BDU_MASK (1 << 7)
373 #define LIS3DH_CTRL_REG4_BDU_ENABLE (LIS3DH_CTRL_REG4_BDU_MASK)
377 #define LIS3DH_CTRL_REG4_BDU_DISABLE (0)
386 #define LIS3DH_CTRL_REG4_BLE_MASK (1 << 6)
390 #define LIS3DH_CTRL_REG4_BLE_LITTLE_ENDIAN (0)
394 #define LIS3DH_CTRL_REG4_BLE_BIG_ENDIAN (LIS3DH_CTRL_REG4_BLE_MASK)
398 #define LIS3DH_CTRL_REG4_FS1_MASK (1 << 5)
402 #define LIS3DH_CTRL_REG4_FS0_MASK (1 << 4)
406 #define LIS3DH_CTRL_REG4_FS_MASK (LIS3DH_CTRL_REG4_FS1_MASK | \
407 LIS3DH_CTRL_REG4_FS0_MASK)
411 #define LIS3DH_CTRL_REG4_SCALE_2G (0)
415 #define LIS3DH_CTRL_REG4_SCALE_4G (LIS3DH_CTRL_REG4_FS0_MASK)
419 #define LIS3DH_CTRL_REG4_SCALE_8G (LIS3DH_CTRL_REG4_FS1_MASK)
423 #define LIS3DH_CTRL_REG4_SCALE_16G (LIS3DH_CTRL_REG4_FS1_MASK | LIS3DH_CTRL_REG4_FS0_MASK)
432 #define LIS3DH_CTRL_REG4_HR_MASK (1 << 3)
443 #define LIS3DH_CTRL_REG4_ST1_MASK (1 << 2)
447 #define LIS3DH_CTRL_REG4_ST0_MASK (1 << 1)
456 #define LIS3DH_CTRL_REG4_SIM_MASK (1 << 0)
465 #define LIS3DH_CTRL_REG5_REBOOT_MASK (1 << 7)
474 #define LIS3DH_CTRL_REG5_FIFO_EN_MASK (1 << 6)
486 #define LIS3DH_CTRL_REG5_LIR_I1_MASK (1 << 3)
492 #define LIS3DH_CTRL_REG5_D4D_I1_MASK (1 << 2)
507 #define LIS3DH_STATUS_REG_ZYXOR_MASK (1 << 7)
516 #define LIS3DH_STATUS_REG_ZOR_MASK (1 << 6)
525 #define LIS3DH_STATUS_REG_YOR_MASK (1 << 5)
534 #define LIS3DH_STATUS_REG_XOR_MASK (1 << 4)
543 #define LIS3DH_STATUS_REG_ZYXDA_MASK (1 << 3)
552 #define LIS3DH_STATUS_REG_ZDA_MASK (1 << 2)
561 #define LIS3DH_STATUS_REG_YDA_MASK (1 << 1)
570 #define LIS3DH_STATUS_REG_XDA_MASK (1 << 0)
577 #define LIS3DH_FIFO_CTRL_REG_FM_SHIFT (6)
578 #define LIS3DH_FIFO_CTRL_REG_FM1_MASK (1 << 7)
579 #define LIS3DH_FIFO_CTRL_REG_FM0_MASK (1 << 6)
580 #define LIS3DH_FIFO_CTRL_REG_FM_MASK (LIS3DH_FIFO_CTRL_REG_FM1_MASK | \
581 LIS3DH_FIFO_CTRL_REG_FM0_MASK)
582 #define LIS3DH_FIFO_CTRL_REG_TR_MASK (1 << 5)
583 #define LIS3DH_FIFO_CTRL_REG_FTH4_MASK (1 << 4)
584 #define LIS3DH_FIFO_CTRL_REG_FTH3_MASK (1 << 3)
585 #define LIS3DH_FIFO_CTRL_REG_FTH2_MASK (1 << 2)
586 #define LIS3DH_FIFO_CTRL_REG_FTH1_MASK (1 << 1)
587 #define LIS3DH_FIFO_CTRL_REG_FTH0_MASK (1 << 0)
588 #define LIS3DH_FIFO_CTRL_REG_FTH_SHIFT (0)
589 #define LIS3DH_FIFO_CTRL_REG_FTH_MASK (LIS3DH_FIFO_CTRL_REG_FTH0_MASK | \
590 LIS3DH_FIFO_CTRL_REG_FTH1_MASK | \
591 LIS3DH_FIFO_CTRL_REG_FTH2_MASK | \
592 LIS3DH_FIFO_CTRL_REG_FTH3_MASK | \
593 LIS3DH_FIFO_CTRL_REG_FTH4_MASK)
600 #define LIS3DH_FIFO_SRC_REG_WTM_MASK (1 << 7)
601 #define LIS3DH_FIFO_SRC_REG_OVRN_FIFO_MASK (1 << 6)
602 #define LIS3DH_FIFO_SRC_REG_EMPTY_MASK (1 << 5)
603 #define LIS3DH_FIFO_SRC_REG_FSS4_MASK (1 << 4)
604 #define LIS3DH_FIFO_SRC_REG_FSS3_MASK (1 << 3)
605 #define LIS3DH_FIFO_SRC_REG_FSS2_MASK (1 << 2)
606 #define LIS3DH_FIFO_SRC_REG_FSS1_MASK (1 << 1)
607 #define LIS3DH_FIFO_SRC_REG_FSS0_MASK (1 << 0)
608 #define LIS3DH_FIFO_SRC_REG_FSS_SHIFT (0)
609 #define LIS3DH_FIFO_SRC_REG_FSS_MASK (LIS3DH_FIFO_SRC_REG_FSS0_MASK | \
610 LIS3DH_FIFO_SRC_REG_FSS1_MASK | \
611 LIS3DH_FIFO_SRC_REG_FSS2_MASK | \
612 LIS3DH_FIFO_SRC_REG_FSS3_MASK | \
613 LIS3DH_FIFO_SRC_REG_FSS4_MASK)
623 #define LIS3DH_SPI_WRITE_MASK (0 << 7)
627 #define LIS3DH_SPI_READ_MASK (1 << 7)
631 #define LIS3DH_SPI_MULTI_MASK (1 << 6)
635 #define LIS3DH_SPI_SINGLE_MASK (0 << 6)
639 #define LIS3DH_SPI_ADDRESS_MASK (0x3F)
645 #define LIS3DH_ADC_DATA_SIZE (2U)
656 #define LIS3DH_FIFO_MODE_BYPASS (0x00 << LIS3DH_FIFO_CTRL_REG_FM_SHIFT)
660 #define LIS3DH_FIFO_MODE_FIFO (0x01 << LIS3DH_FIFO_CTRL_REG_FM_SHIFT)
664 #define LIS3DH_FIFO_MODE_STREAM (0x02 << LIS3DH_FIFO_CTRL_REG_FM_SHIFT)
668 #define LIS3DH_FIFO_MODE_STREAM_TO_FIFO (0x03 << LIS3DH_FIFO_CTRL_REG_FM_SHIFT)
680 #define LIS3DH_ODR_POWERDOWN (0x00 << LIS3DH_CTRL_REG1_ODR_SHIFT)
684 #define LIS3DH_ODR_1Hz (0x01 << LIS3DH_CTRL_REG1_ODR_SHIFT)
688 #define LIS3DH_ODR_10Hz (0x02 << LIS3DH_CTRL_REG1_ODR_SHIFT)
692 #define LIS3DH_ODR_25Hz (0x03 << LIS3DH_CTRL_REG1_ODR_SHIFT)
696 #define LIS3DH_ODR_50Hz (0x04 << LIS3DH_CTRL_REG1_ODR_SHIFT)
700 #define LIS3DH_ODR_100Hz (0x05 << LIS3DH_CTRL_REG1_ODR_SHIFT)
704 #define LIS3DH_ODR_200Hz (0x06 << LIS3DH_CTRL_REG1_ODR_SHIFT)
708 #define LIS3DH_ODR_400Hz (0x07 << LIS3DH_CTRL_REG1_ODR_SHIFT)
712 #define LIS3DH_ODR_LP1600Hz (0x08 << LIS3DH_CTRL_REG1_ODR_SHIFT)
717 #define LIS3DH_ODR_NP1250Hz (0x09 << LIS3DH_CTRL_REG1_ODR_SHIFT)
722 #define LIS3DH_ODR_LP5000HZ (0x09 << LIS3DH_CTRL_REG1_ODR_SHIFT)
749 typedef struct __attribute__((packed))
Result vector for accelerometer measurement.
int lis3dh_set_odr(const lis3dh_t *dev, const uint8_t odr)
Set the output data rate of the sensor.
Low-level SPI peripheral driver interface definition.
uint16_t scale
Internal sensor scale.
uint8_t odr
Default sensor ODR setting: LIS3DH_ODR_xxxHz.
int16_t acc_y
Acceleration in the Y direction in milli-G.
int16_t acc_z
Acceleration in the Z direction in milli-G.
int lis3dh_set_fifo(const lis3dh_t *dev, const uint8_t mode, const uint8_t watermark)
Enable/disable the FIFO.
Device descriptor for LIS3DH sensors.
int lis3dh_set_axes(const lis3dh_t *dev, const uint8_t axes)
Enable/disable accelerometer axes.
gpio_t int2
INT2 (DRDY) pin.
int lis3dh_set_scale(lis3dh_t *dev, const uint8_t scale)
Set the full scale range of the sensor.
int lis3dh_set_aux_adc(const lis3dh_t *dev, const uint8_t enable, const uint8_t temperature)
Turn on/off power to the auxiliary ADC in LIS3DH.
uint8_t scale
Default sensor scale: 2, 4, 8, or 16 (G)
int lis3dh_set_int1(const lis3dh_t *dev, const uint8_t mode)
Set INT1 pin function.
spi_clk_t
Available SPI clock speeds.
spi_t spi
SPI device the sensor is connected to.
int lis3dh_read_aux_adc2(const lis3dh_t *dev, int16_t *out)
Read auxiliary ADC channel 2 data from the accelerometer.
int lis3dh_init(lis3dh_t *dev, const lis3dh_params_t *params)
Initialize a LIS3DH sensor instance.
int lis3dh_read_aux_adc3(const lis3dh_t *dev, int16_t *out)
Read auxiliary ADC channel 3 data from the accelerometer.
Low-level GPIO peripheral driver interface definitions.
lis3dh_params_t params
Device initialization parameters.
int16_t acc_x
Acceleration in the X direction in milli-G.
int lis3dh_read_aux_adc1(const lis3dh_t *dev, int16_t *out)
Read auxiliary ADC channel 1 data from the accelerometer.
spi_clk_t clk
designated clock speed of the SPI bus
int lis3dh_read_xyz(const lis3dh_t *dev, lis3dh_data_t *acc_data)
Read 3D acceleration data from the accelerometer.
Configuration parameters for LIS3DH devices.
int lis3dh_get_fifo_level(const lis3dh_t *dev)
Get the current number of elements in the FIFO.
unsigned int spi_t
Default type for SPI devices.
gpio_t cs
Chip select pin.