123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708 |
- #ifndef _LIS3DSH_H_
- #define _LIS3DSH_H_
- #include "hal_accelerometer.h"
- #define EX_LIS3DSH_VERSION "1.1.2"
- #define EX_LIS3DSH_MAJOR 1
- #define EX_LIS3DSH_MINOR 1
- #define EX_LIS3DSH_PATCH 2
- #define LIS3DSH_ACC_NUMBER_OF_AXES 3U
- #define LIS3DSH_ACC_2G 2.0f
- #define LIS3DSH_ACC_4G 4.0f
- #define LIS3DSH_ACC_6G 6.0f
- #define LIS3DSH_ACC_8G 8.0f
- #define LIS3DSH_ACC_16G 16.0f
- #define LIS3DSH_ACC_SENS_2G 0.06f
- #define LIS3DSH_ACC_SENS_4G 0.12f
- #define LIS3DSH_ACC_SENS_6G 0.18f
- #define LIS3DSH_ACC_SENS_8G 0.24f
- #define LIS3DSH_ACC_SENS_16G 0.73f
- #define LIS3DSH_ACC_BIAS 0.0f
- #define LIS3DSH_DI_MASK 0xFF
- #define LIS3DSH_DI(n) (1 << n)
- #define LIS3DSH_AD_MASK 0x3F
- #define LIS3DSH_AD(n) (1 << n)
- #define LIS3DSH_MS (1 << 6)
- #define LIS3DSH_RW (1 << 7)
- #define LIS3DSH_AD_OUT_T 0x0C
- #define LIS3DSH_AD_INFO1 0x0D
- #define LIS3DSH_AD_INFO2 0x0E
- #define LIS3DSH_AD_WHO_AM_I 0x0F
- #define LIS3DSH_AD_OFF_X 0x10
- #define LIS3DSH_AD_OFF_Y 0x11
- #define LIS3DSH_AD_OFF_Z 0x12
- #define LIS3DSH_AD_CS_X 0x13
- #define LIS3DSH_AD_CS_Y 0x14
- #define LIS3DSH_AD_CS_Z 0x15
- #define LIS3DSH_AD_LC_L 0x16
- #define LIS3DSH_AD_LC_H 0x17
- #define LIS3DSH_AD_STAT 0x18
- #define LIS3DSH_AD_PEAK1 0x19
- #define LIS3DSH_AD_PEAK2 0x1A
- #define LIS3DSH_AD_VFC_1 0x1B
- #define LIS3DSH_AD_VFC_2 0x1C
- #define LIS3DSH_AD_VFC_3 0x1D
- #define LIS3DSH_AD_VFC_4 0x1E
- #define LIS3DSH_AD_THRS3 0x1F
- #define LIS3DSH_AD_CTRL_REG4 0x20
- #define LIS3DSH_AD_CTRL_REG1 0x21
- #define LIS3DSH_AD_CTRL_REG2 0x22
- #define LIS3DSH_AD_CTRL_REG3 0x23
- #define LIS3DSH_AD_CTRL_REG5 0x24
- #define LIS3DSH_AD_CTRL_REG6 0x25
- #define LIS3DSH_AD_STATUS 0x27
- #define LIS3DSH_AD_OUT_X_L 0x28
- #define LIS3DSH_AD_OUT_X_H 0x29
- #define LIS3DSH_AD_OUT_Y_L 0x2A
- #define LIS3DSH_AD_OUT_Y_H 0x2B
- #define LIS3DSH_AD_OUT_Z_L 0x2C
- #define LIS3DSH_AD_OUT_Z_H 0x2D
- #define LIS3DSH_AD_FIFO_CTRL 0x2E
- #define LIS3DSH_AD_FIFO_SRC 0x2F
- #define LIS3DSH_AD_ST1_0 0x40
- #define LIS3DSH_AD_ST1_1 0x41
- #define LIS3DSH_AD_ST1_2 0x42
- #define LIS3DSH_AD_ST1_3 0x43
- #define LIS3DSH_AD_ST1_4 0x44
- #define LIS3DSH_AD_ST1_5 0x45
- #define LIS3DSH_AD_ST1_6 0x46
- #define LIS3DSH_AD_ST1_7 0x47
- #define LIS3DSH_AD_ST1_8 0x48
- #define LIS3DSH_AD_ST1_9 0x49
- #define LIS3DSH_AD_ST1_A 0x4A
- #define LIS3DSH_AD_ST1_B 0x4B
- #define LIS3DSH_AD_ST1_C 0x4C
- #define LIS3DSH_AD_ST1_D 0x4D
- #define LIS3DSH_AD_ST1_E 0x4E
- #define LIS3DSH_AD_ST1_F 0x4F
- #define LIS3DSH_AD_TIM4_1 0x50
- #define LIS3DSH_AD_TIM3_1 0x51
- #define LIS3DSH_AD_TIM2_1_L 0x52
- #define LIS3DSH_AD_TIM2_1_H 0x53
- #define LIS3DSH_AD_TIM1_1_L 0x54
- #define LIS3DSH_AD_TIM1_1_H 0x55
- #define LIS3DSH_AD_THRS2_1 0x56
- #define LIS3DSH_AD_THRS1_1 0x57
- #define LIS3DSH_AD_MASK1_B 0x59
- #define LIS3DSH_AD_MASK1_A 0x5A
- #define LIS3DSH_AD_SETT1 0x5B
- #define LIS3DSH_AD_PR1 0x5C
- #define LIS3DSH_AD_TC1_L 0x5D
- #define LIS3DSH_AD_TC1_H 0x5E
- #define LIS3DSH_AD_OUTS1 0x5F
- #define LIS3DSH_AD_ST2_0 0x60
- #define LIS3DSH_AD_ST2_1 0x61
- #define LIS3DSH_AD_ST2_2 0x62
- #define LIS3DSH_AD_ST2_3 0x63
- #define LIS3DSH_AD_ST2_4 0x64
- #define LIS3DSH_AD_ST2_5 0x65
- #define LIS3DSH_AD_ST2_6 0x66
- #define LIS3DSH_AD_ST2_7 0x67
- #define LIS3DSH_AD_ST2_8 0x68
- #define LIS3DSH_AD_ST2_9 0x69
- #define LIS3DSH_AD_ST2_A 0x6A
- #define LIS3DSH_AD_ST2_B 0x6B
- #define LIS3DSH_AD_ST2_C 0x6C
- #define LIS3DSH_AD_ST2_D 0x6D
- #define LIS3DSH_AD_ST2_E 0x6E
- #define LIS3DSH_AD_ST2_F 0x6F
- #define LIS3DSH_AD_TIM4_2 0x70
- #define LIS3DSH_AD_TIM3_2 0x71
- #define LIS3DSH_AD_TIM2_2_L 0x72
- #define LIS3DSH_AD_TIM2_2_H 0x73
- #define LIS3DSH_AD_TIM1_2_L 0x74
- #define LIS3DSH_AD_TIM1_2_H 0x75
- #define LIS3DSH_AD_THRS2_2 0x76
- #define LIS3DSH_AD_THRS1_2 0x77
- #define LIS3DSH_AD_DES2 0x78
- #define LIS3DSH_AD_MASK2_B 0x79
- #define LIS3DSH_AD_MASK2_A 0x7A
- #define LIS3DSH_AD_SETT2 0x7B
- #define LIS3DSH_AD_PR2 0x7C
- #define LIS3DSH_AD_TC2_L 0x7D
- #define LIS3DSH_AD_TC2_H 0x7E
- #define LIS3DSH_AD_OUTS2 0x7F
- #define LIS3DSH_CTRL_REG1_MASK 0xE9
- #define LIS3DSH_CTRL_REG1_SM1_EN (1 << 0)
- #define LIS3DSH_CTRL_REG1_SM1_PIN (1 << 3)
- #define LIS3DSH_CTRL_REG1_HYST0_1 (1 << 5)
- #define LIS3DSH_CTRL_REG1_HYST1_1 (1 << 6)
- #define LIS3DSH_CTRL_REG1_HYST2_1 (1 << 7)
- #define LIS3DSH_CTRL_REG2_MASK 0xE9
- #define LIS3DSH_CTRL_REG2_SM2_EN (1 << 0)
- #define LIS3DSH_CTRL_REG2_SM2_PIN (1 << 3)
- #define LIS3DSH_CTRL_REG2_HYST0_2 (1 << 5)
- #define LIS3DSH_CTRL_REG2_HYST1_2 (1 << 6)
- #define LIS3DSH_CTRL_REG2_HYST2_2 (1 << 7)
- #define LIS3DSH_CTRL_REG3_MASK 0xFF
- #define LIS3DSH_CTRL_REG3_STRT (1 << 0)
- #define LIS3DSH_CTRL_REG3_VFILT (1 << 2)
- #define LIS3DSH_CTRL_REG3_INT1_EN (1 << 3)
- #define LIS3DSH_CTRL_REG3_INT2_EN (1 << 4)
- #define LIS3DSH_CTRL_REG3_IEL (1 << 5)
- #define LIS3DSH_CTRL_REG3_IEA (1 << 6)
- #define LIS3DSH_CTRL_REG3_DR_EN (1 << 7)
- #define LIS3DSH_CTRL_REG4_MASK 0xFF
- #define LIS3DSH_CTRL_REG4_XEN (1 << 0)
- #define LIS3DSH_CTRL_REG4_YEN (1 << 1)
- #define LIS3DSH_CTRL_REG4_ZEN (1 << 2)
- #define LIS3DSH_CTRL_REG4_BDU (1 << 3)
- #define LIS3DSH_CTRL_REG4_ODR_0 (1 << 4)
- #define LIS3DSH_CTRL_REG4_ODR_1 (1 << 5)
- #define LIS3DSH_CTRL_REG4_ODR_2 (1 << 6)
- #define LIS3DSH_CTRL_REG4_ODR_3 (1 << 7)
- #define LIS3DSH_CTRL_REG5_MASK 0xFF
- #define LIS3DSH_CTRL_REG5_SIM (1 << 0)
- #define LIS3DSH_CTRL_REG5_ST1 (1 << 1)
- #define LIS3DSH_CTRL_REG5_ST2 (1 << 2)
- #define LIS3DSH_CTRL_REG5_FS_MASK 0x38
- #define LIS3DSH_CTRL_REG5_FS0 (1 << 3)
- #define LIS3DSH_CTRL_REG5_FS1 (1 << 4)
- #define LIS3DSH_CTRL_REG5_FS2 (1 << 5)
- #define LIS3DSH_CTRL_REG5_BW1 (1 << 6)
- #define LIS3DSH_CTRL_REG5_BW2 (1 << 7)
- #define LIS3DSH_CTRL_REG6_MASK 0xFF
- #define LIS3DSH_CTRL_REG6_P2_BOOT (1 << 0)
- #define LIS3DSH_CTRL_REG6_P1_OVRUN (1 << 1)
- #define LIS3DSH_CTRL_REG6_P1_WTM (1 << 2)
- #define LIS3DSH_CTRL_REG6_P1_EMPTY (1 << 3)
- #define LIS3DSH_CTRL_REG6_ADD_INC (1 << 4)
- #define LIS3DSH_CTRL_REG6_WTM_EN (1 << 5)
- #define LIS3DSH_CTRL_REG6_FIFO_EN (1 << 6)
- #define LIS3DSH_CTRL_REG6_BOOT (1 << 7)
- #if !defined(LIS3DSH_USE_SPI) || defined(__DOXYGEN__)
- #define LIS3DSH_USE_SPI TRUE
- #endif
- #if !defined(LIS3DSH_SHARED_SPI) || defined(__DOXYGEN__)
- #define LIS3DSH_SHARED_SPI FALSE
- #endif
- #if !defined(LIS3DSH_USE_I2C) || defined(__DOXYGEN__)
- #define LIS3DSH_USE_I2C FALSE
- #endif
- #if !defined(LIS3DSH_SHARED_I2C) || defined(__DOXYGEN__)
- #define LIS3DSH_SHARED_I2C FALSE
- #endif
- #if !defined(LIS3DSH_USE_ADVANCED) || defined(__DOXYGEN__)
- #define LIS3DSH_USE_ADVANCED FALSE
- #endif
- #if !(LIS3DSH_USE_SPI ^ LIS3DSH_USE_I2C)
- #error "LIS3DSH_USE_SPI and LIS3DSH_USE_I2C cannot be both true or both false"
- #endif
- #if LIS3DSH_USE_SPI && !HAL_USE_SPI
- #error "LIS3DSH_USE_SPI requires HAL_USE_SPI"
- #endif
- #if LIS3DSH_SHARED_SPI && !SPI_USE_MUTUAL_EXCLUSION
- #error "LIS3DSH_SHARED_SPI requires SPI_USE_MUTUAL_EXCLUSION"
- #endif
- #if LIS3DSH_USE_I2C && !HAL_USE_I2C
- #error "LIS3DSH_USE_I2C requires HAL_USE_I2C"
- #endif
- #if LIS3DSH_SHARED_I2C && !I2C_USE_MUTUAL_EXCLUSION
- #error "LIS3DSH_SHARED_I2C requires I2C_USE_MUTUAL_EXCLUSION"
- #endif
- #if LIS3DSH_USE_I2C
- #error "LIS3DSH over I2C still not supported"
- #endif
- typedef struct LIS3DSHDriver LIS3DSHDriver;
- typedef enum {
- LIS3DSH_ACC_FS_2G = 0x00,
- LIS3DSH_ACC_FS_4G = 0x08,
- LIS3DSH_ACC_FS_6G = 0x10,
- LIS3DSH_ACC_FS_8G = 0x18,
- LIS3DSH_ACC_FS_16G = 0x20
- }lis3dsh_acc_fs_t;
- typedef enum {
- LIS3DSH_ACC_ODR_PD = 0x00,
- LIS3DSH_ACC_ODR_3_125HZ = 0x10,
- LIS3DSH_ACC_ODR_6_25HZ = 0x20,
- LIS3DSH_ACC_ODR_12_5HZ = 0x30,
- LIS3DSH_ACC_ODR_25HZ = 0x40,
- LIS3DSH_ACC_ODR_50HZ = 0x50,
- LIS3DSH_ACC_ODR_100HZ = 0x60,
- LIS3DSH_ACC_ODR_400HZ = 0x70,
- LIS3DSH_ACC_ODR_800HZ = 0x80,
- LIS3DSH_ACC_ODR_1600HZ = 0x90
- }lis3dsh_acc_odr_t;
- typedef enum {
- LIS3DSH_ACC_BW_800HZ = 0x00,
- LIS3DSH_ACC_BW_200HZ = 0x40,
- LIS3DSH_ACC_BW_400HZ = 0x80,
- LIS3DSH_ACC_BW_50HZ = 0xC0
- }lis3dsh_acc_bw_t;
- typedef enum {
- LIS3DSH_ACC_BDU_CONTINUOUS = 0x00,
- LIS3DSH_ACC_BDU_BLOCKED = 0x80
- } lis3dsh_acc_bdu_t;
- typedef enum {
- LIS3DSH_UNINIT = 0,
- LIS3DSH_STOP = 1,
- LIS3DSH_READY = 2,
- } lis3dsh_state_t;
- typedef struct {
- #if (LIS3DSH_USE_SPI) || defined(__DOXYGEN__)
-
- SPIDriver *spip;
-
- const SPIConfig *spicfg;
- #endif
- #if (LIS3DSH_USE_I2C) || defined(__DOXYGEN__)
-
- I2CDriver *i2cp;
-
- const I2CConfig *i2ccfg;
- #endif
-
- float *accsensitivity;
-
- float *accbias;
-
- lis3dsh_acc_fs_t accfullscale;
-
- lis3dsh_acc_odr_t accoutputdatarate;
- #if LIS3DSH_USE_ADVANCED || defined(__DOXYGEN__)
-
- lis3dsh_acc_bw_t accantialiasing;
-
- lis3dsh_acc_bdu_t accblockdataupdate;
- #endif
- } LIS3DSHConfig;
- #define _lis3dsh_methods_alone \
- \
- msg_t (*acc_set_full_scale)(LIS3DSHDriver *devp, lis3dsh_acc_fs_t fs);
- #define _lis3dsh_methods \
- _base_object_methods \
- _lis3dsh_methods_alone
- struct LIS3DSHVMT {
- _lis3dsh_methods
- };
- #define _lis3dsh_data \
- _base_sensor_data \
- \
- lis3dsh_state_t state; \
- \
- const LIS3DSHConfig *config; \
- \
- size_t accaxes; \
- \
- float accsensitivity[LIS3DSH_ACC_NUMBER_OF_AXES]; \
- \
- float accbias[LIS3DSH_ACC_NUMBER_OF_AXES]; \
- \
- float accfullscale;
- struct LIS3DSHDriver {
-
- const struct LIS3DSHVMT *vmt;
-
- BaseAccelerometer acc_if;
- _lis3dsh_data
- };
- #define lis3dshAccelerometerGetAxesNumber(devp) \
- accelerometerGetAxesNumber(&((devp)->acc_if))
- #define lis3dshAccelerometerReadRaw(devp, axes) \
- accelerometerReadRaw(&((devp)->acc_if), axes)
- #define lis3dshAccelerometerReadCooked(devp, axes) \
- accelerometerReadCooked(&((devp)->acc_if), axes)
- #define lis3dshAccelerometerSetBias(devp, bp) \
- accelerometerSetBias(&((devp)->acc_if), bp)
- #define lis3dshAccelerometerResetBias(devp) \
- accelerometerResetBias(&((devp)->acc_if))
- #define lis3dshAccelerometerSetSensitivity(devp, sp) \
- accelerometerSetSensitivity(&((devp)->acc_if), sp)
- #define lis3dshAccelerometerResetSensitivity(devp) \
- accelerometerResetSensitivity(&((devp)->acc_if))
- #define lis3dshAccelerometerSetFullScale(devp, fs) \
- (devp)->vmt->acc_set_full_scale(devp, fs)
- #ifdef __cplusplus
- extern "C" {
- #endif
- void lis3dshObjectInit(LIS3DSHDriver *devp);
- void lis3dshStart(LIS3DSHDriver *devp, const LIS3DSHConfig *config);
- void lis3dshStop(LIS3DSHDriver *devp);
- #ifdef __cplusplus
- }
- #endif
- #endif
|