29 #ifndef _LSM303DLHC_H_ 30 #define _LSM303DLHC_H_ 46 #define EX_LSM303DLHC_VERSION "1.1.1" 51 #define EX_LSM303DLHC_MAJOR 1 56 #define EX_LSM303DLHC_MINOR 1 61 #define EX_LSM303DLHC_PATCH 1 72 #define LSM303DLHC_ACC_NUMBER_OF_AXES 3U 74 #define LSM303DLHC_ACC_2G 2.0f 75 #define LSM303DLHC_ACC_4G 4.0f 76 #define LSM303DLHC_ACC_8G 8.0f 77 #define LSM303DLHC_ACC_16G 16.0f 79 #define LSM303DLHC_ACC_SENS_2G 0.0610f 80 #define LSM303DLHC_ACC_SENS_4G 0.1221f 81 #define LSM303DLHC_ACC_SENS_8G 0.2442f 82 #define LSM303DLHC_ACC_SENS_16G 0.4884f 84 #define LSM303DLHC_ACC_BIAS 0.0f 94 #define LSM303DLHC_COMP_NUMBER_OF_AXES 3U 96 #define LSM303DLHC_COMP_1P3GA 1.3f 97 #define LSM303DLHC_COMP_1P9GA 1.9f 98 #define LSM303DLHC_COMP_2P5GA 2.5f 99 #define LSM303DLHC_COMP_4P0GA 4.0f 100 #define LSM303DLHC_COMP_4P7GA 4.7f 101 #define LSM303DLHC_COMP_5P6GA 5.6f 102 #define LSM303DLHC_COMP_8P1GA 8.1f 104 #define LSM303DLHC_COMP_SENS_XY_1P3GA 0.000909f 105 #define LSM303DLHC_COMP_SENS_XY_1P9GA 0.001169f 106 #define LSM303DLHC_COMP_SENS_XY_2P5GA 0.0014925f 107 #define LSM303DLHC_COMP_SENS_XY_4P0GA 0.0022222f 108 #define LSM303DLHC_COMP_SENS_XY_4P7GA 0.0025000f 109 #define LSM303DLHC_COMP_SENS_XY_5P6GA 0.0030303f 110 #define LSM303DLHC_COMP_SENS_XY_8P1GA 0.0043478f 112 #define LSM303DLHC_COMP_SENS_Z_1P3GA 0.0010204f 113 #define LSM303DLHC_COMP_SENS_Z_1P9GA 0.0013071f 114 #define LSM303DLHC_COMP_SENS_Z_2P5GA 0.0016666f 115 #define LSM303DLHC_COMP_SENS_Z_4P0GA 0.0025000f 116 #define LSM303DLHC_COMP_SENS_Z_4P7GA 0.0028169f 117 #define LSM303DLHC_COMP_SENS_Z_5P6GA 0.0033898f 118 #define LSM303DLHC_COMP_SENS_Z_8P1GA 0.0048780f 120 #define LSM303DLHC_COMP_BIAS 0.0f 127 #define LSM303DLHC_DI_MASK 0xFF 128 #define LSM303DLHC_DI(n) (1 << n) 129 #define LSM303DLHC_AD_MASK 0x7F 130 #define LSM303DLHC_AD(n) (1 << n) 131 #define LSM303DLHC_MS (1 << 7) 138 #define LSM303DLHC_AD_ACC_CTRL_REG1 0x20 139 #define LSM303DLHC_AD_ACC_CTRL_REG2 0x21 140 #define LSM303DLHC_AD_ACC_CTRL_REG3 0x22 141 #define LSM303DLHC_AD_ACC_CTRL_REG4 0x23 142 #define LSM303DLHC_AD_ACC_CTRL_REG5 0x24 143 #define LSM303DLHC_AD_ACC_CTRL_REG6 0x25 144 #define LSM303DLHC_AD_ACC_REFERENCE 0x26 145 #define LSM303DLHC_AD_ACC_STATUS_REG 0x27 146 #define LSM303DLHC_AD_ACC_OUT_X_L 0x28 147 #define LSM303DLHC_AD_ACC_OUT_X_H 0x29 148 #define LSM303DLHC_AD_ACC_OUT_Y_L 0x2A 149 #define LSM303DLHC_AD_ACC_OUT_Y_H 0x2B 150 #define LSM303DLHC_AD_ACC_OUT_Z_L 0x2C 151 #define LSM303DLHC_AD_ACC_OUT_Z_H 0x2D 152 #define LSM303DLHC_AD_ACC_FIFO_CTRL_REG 0x2E 153 #define LSM303DLHC_AD_ACC_FIFO_SRC_REG 0x2F 154 #define LSM303DLHC_AD_ACC_INT1_CFG 0x30 155 #define LSM303DLHC_AD_ACC_INT1_SRC 0x31 156 #define LSM303DLHC_AD_ACC_INT1_THS 0x32 157 #define LSM303DLHC_AD_ACC_INT1_DURATION 0x33 158 #define LSM303DLHC_AD_ACC_INT2_CFG 0x34 159 #define LSM303DLHC_AD_ACC_INT2_SRC 0x35 160 #define LSM303DLHC_AD_ACC_INT2_THS 0x36 161 #define LSM303DLHC_AD_ACC_INT2_DURATION 0x37 162 #define LSM303DLHC_AD_ACC_CLICK_CFG 0x38 163 #define LSM303DLHC_AD_ACC_CLICK_SRC 0x39 164 #define LSM303DLHC_AD_ACC_CLICK_THS 0x3A 165 #define LSM303DLHC_AD_ACC_TIME_LIMIT 0x3B 166 #define LSM303DLHC_AD_ACC_TIME_LATENCY 0x3C 167 #define LSM303DLHC_AD_ACC_TIME_WINDOW 0x3D 168 #define LSM303DLHC_AD_COMP_CRA_REG 0x00 169 #define LSM303DLHC_AD_COMP_CRB_REG 0x01 170 #define LSM303DLHC_AD_COMP_MR_REG 0x02 171 #define LSM303DLHC_AD_COMP_OUT_X_H 0x03 172 #define LSM303DLHC_AD_COMP_OUT_X_L 0x04 173 #define LSM303DLHC_AD_COMP_OUT_Z_H 0x05 174 #define LSM303DLHC_AD_COMP_OUT_Z_L 0x06 175 #define LSM303DLHC_AD_COMP_OUT_Y_H 0x07 176 #define LSM303DLHC_AD_COMP_OUT_Y_L 0x08 177 #define LSM303DLHC_AD_COMP_SR_REG 0x09 178 #define LSM303DLHC_AD_COMP_IRA_REG 0x0A 179 #define LSM303DLHC_AD_COMP_IRB_REG 0x0B 180 #define LSM303DLHC_AD_COMP_IRC_REG 0x0C 181 #define LSM303DLHC_AD_COMP_TEMP_OUT_H 0x31 182 #define LSM303DLHC_AD_COMP_TEMP_OUT_L 0x32 189 #define LSM303DLHC_CTRL_REG1_A_MASK 0xFF 190 #define LSM303DLHC_CTRL_REG1_A_XEN (1 << 0) 191 #define LSM303DLHC_CTRL_REG1_A_YEN (1 << 1) 192 #define LSM303DLHC_CTRL_REG1_A_ZEN (1 << 2) 193 #define LSM303DLHC_CTRL_REG1_A_LPEN (1 << 3) 194 #define LSM303DLHC_CTRL_REG1_A_ODR0 (1 << 4) 195 #define LSM303DLHC_CTRL_REG1_A_ODR1 (1 << 5) 196 #define LSM303DLHC_CTRL_REG1_A_ODR2 (1 << 6) 197 #define LSM303DLHC_CTRL_REG1_A_ODR3 (1 << 7) 204 #define LSM303DLHC_CTRL_REG2_A_MASK 0xFF 205 #define LSM303DLHC_CTRL_REG2_A_HPIS1 (1 << 0) 206 #define LSM303DLHC_CTRL_REG2_A_HPIS2 (1 << 1) 207 #define LSM303DLHC_CTRL_REG2_A_HPCLICK (1 << 2) 208 #define LSM303DLHC_CTRL_REG2_A_FDS (1 << 3) 209 #define LSM303DLHC_CTRL_REG2_A_HPCF1 (1 << 4) 210 #define LSM303DLHC_CTRL_REG2_A_HPCF2 (1 << 5) 211 #define LSM303DLHC_CTRL_REG2_A_HPM0 (1 << 6) 212 #define LSM303DLHC_CTRL_REG2_A_HPM1 (1 << 7) 219 #define LSM303DLHC_CTRL_REG3_A_MASK 0xFD 220 #define LSM303DLHC_CTRL_REG3_A_I1_OVERRUN (1 << 1) 221 #define LSM303DLHC_CTRL_REG3_A_I1_WTM (1 << 2) 222 #define LSM303DLHC_CTRL_REG3_A_I1_DRDY2 (1 << 3) 223 #define LSM303DLHC_CTRL_REG3_A_I1_DRDY1 (1 << 4) 224 #define LSM303DLHC_CTRL_REG3_A_I1_AOI2 (1 << 5) 225 #define LSM303DLHC_CTRL_REG3_A_I1_AOI1 (1 << 6) 226 #define LSM303DLHC_CTRL_REG3_A_I1_CLICK (1 << 7) 233 #define LSM303DLHC_CTRL_REG4_A_MASK 0xF9 234 #define LSM303DLHC_CTRL_REG4_A_SIM (1 << 0) 235 #define LSM303DLHC_CTRL_REG4_A_HR (1 << 3) 236 #define LSM303DLHC_CTRL_REG4_A_FS_MASK 0x30 237 #define LSM303DLHC_CTRL_REG4_A_FS0 (1 << 4) 238 #define LSM303DLHC_CTRL_REG4_A_FS1 (1 << 5) 239 #define LSM303DLHC_CTRL_REG4_A_BLE (1 << 6) 240 #define LSM303DLHC_CTRL_REG4_A_BDU (1 << 7) 247 #define LSM303DLHC_CTRL_REG5_A_MASK 0xCF 248 #define LSM303DLHC_CTRL_REG5_A_D4D_INT2 (1 << 0) 249 #define LSM303DLHC_CTRL_REG5_A_LIR_INT2 (1 << 1) 250 #define LSM303DLHC_CTRL_REG5_A_D4D_INT1 (1 << 2) 251 #define LSM303DLHC_CTRL_REG5_A_LIR_INT1 (1 << 3) 252 #define LSM303DLHC_CTRL_REG5_A_FIFO_EN (1 << 6) 253 #define LSM303DLHC_CTRL_REG5_A_BOOT (1 << 7) 260 #define LSM303DLHC_CTRL_REG6_A_MASK 0xFA 261 #define LSM303DLHC_CTRL_REG6_A_H_LACTIVE (1 << 1) 262 #define LSM303DLHC_CTRL_REG6_A_P2_ACT (1 << 3) 263 #define LSM303DLHC_CTRL_REG6_A_BOOT_I1 (1 << 4) 264 #define LSM303DLHC_CTRL_REG6_A_I2_INT2 (1 << 5) 265 #define LSM303DLHC_CTRL_REG6_A_I2_INT1 (1 << 6) 266 #define LSM303DLHC_CTRL_REG6_A_I2_CLICKEN (1 << 7) 273 #define LSM303DLHC_CRA_REG_M_MASK 0x9C 274 #define LSM303DLHC_CRA_REG_M_DO0 (1 << 2) 275 #define LSM303DLHC_CRA_REG_M_DO1 (1 << 3) 276 #define LSM303DLHC_CRA_REG_M_DO2 (1 << 4) 277 #define LSM303DLHC_CRA_REG_M_TEMP_EN (1 << 7) 284 #define LSM303DLHC_CRB_REG_M_MASK 0xE0 285 #define LSM303DLHC_CRB_REG_M_GN_MASK 0xE0 286 #define LSM303DLHC_CRB_REG_M_GN0 (1 << 5) 287 #define LSM303DLHC_CRB_REG_M_GN1 (1 << 6) 288 #define LSM303DLHC_CRB_REG_M_GN2 (1 << 7) 294 #define LSM303DLHC_MR_REG_M_MASK 0x03 295 #define LSM303DLHC_MR_REG_M_MD0 (1 << 0) 296 #define LSM303DLHC_MR_REG_M_MD1 (1 << 1) 312 #if !defined(LSM303DLHC_USE_SPI) || defined(__DOXYGEN__) 313 #define LSM303DLHC_USE_SPI FALSE 322 #if !defined(LSM303DLHC_SHARED_SPI) || defined(__DOXYGEN__) 323 #define LSM303DLHC_SHARED_SPI FALSE 331 #if !defined(LSM303DLHC_USE_I2C) || defined(__DOXYGEN__) 332 #define LSM303DLHC_USE_I2C TRUE 341 #if !defined(LSM303DLHC_SHARED_I2C) || defined(__DOXYGEN__) 342 #define LSM303DLHC_SHARED_I2C FALSE 351 #if !defined(LSM303DLHC_ACC_USE_ADVANCED) || defined(__DOXYGEN__) 352 #define LSM303DLHC_ACC_USE_ADVANCED FALSE 361 #if !defined(LSM303DLHC_COMP_USE_ADVANCED) || defined(__DOXYGEN__) 362 #define LSM303DLHC_COMP_USE_ADVANCED FALSE 370 #if !(LSM303DLHC_USE_SPI ^ LSM303DLHC_USE_I2C) 371 #error "LSM303DLHC_USE_SPI and LSM303DLHC_USE_I2C cannot be both true or both false" 374 #if LSM303DLHC_USE_SPI && !HAL_USE_SPI 375 #error "LSM303DLHC_USE_SPI requires HAL_USE_SPI" 378 #if LSM303DLHC_SHARED_SPI && !SPI_USE_MUTUAL_EXCLUSION 379 #error "LSM303DLHC_SHARED_SPI requires SPI_USE_MUTUAL_EXCLUSION" 382 #if LSM303DLHC_USE_I2C && !HAL_USE_I2C 383 #error "LSM303DLHC_USE_I2C requires HAL_USE_I2C" 386 #if LSM303DLHC_SHARED_I2C && !I2C_USE_MUTUAL_EXCLUSION 387 #error "LSM303DLHC_SHARED_I2C requires I2C_USE_MUTUAL_EXCLUSION" 393 #if LSM303DLHC_USE_SPI 394 #error "LSM303DLHC over SPI still not supported" 563 #if LSM303DLHC_ACC_USE_ADVANCED || defined(__DOXYGEN__) 597 #if LSM303DLHC_COMP_USE_ADVANCED || defined(__DOXYGEN__) 608 #define _lsm303dlhc_methods_alone \ 610 msg_t (*acc_set_full_scale)(LSM303DLHCDriver *devp, \ 611 lsm303dlhc_acc_fs_t fs); \ 613 msg_t (*comp_set_full_scale)(LSM303DLHCDriver *devp, \ 614 lsm303dlhc_comp_fs_t fs); \ 619 #define _lsm303dlhc_methods \ 620 _base_object_methods \ 621 _lsm303dlhc_methods_alone 635 #define _lsm303dlhc_data \ 638 lsm303dlhc_state_t state; \ 640 const LSM303DLHCConfig *config; \ 644 float accsensitivity[LSM303DLHC_ACC_NUMBER_OF_AXES]; \ 646 float accbias[LSM303DLHC_ACC_NUMBER_OF_AXES]; \ 648 float accfullscale; \ 652 float compsensitivity[LSM303DLHC_COMP_NUMBER_OF_AXES];\ 654 float compbias[LSM303DLHC_COMP_NUMBER_OF_AXES]; \ 685 #define lsm303dlhcAccelerometerGetAxesNumber(devp) \ 686 accelerometerGetAxesNumber(&((devp)->acc_if)) 706 #define lsm303dlhcAccelerometerReadRaw(devp, axes) \ 707 accelerometerReadRaw(&((devp)->acc_if), axes) 728 #define lsm303dlhcAccelerometerReadCooked(devp, axes) \ 729 accelerometerReadCooked(&((devp)->acc_if), axes) 745 #define lsm303dlhcAccelerometerSetBias(devp, bp) \ 746 accelerometerSetBias(&((devp)->acc_if), bp) 760 #define lsm303dlhcAccelerometerResetBias(devp) \ 761 accelerometerResetBias(&((devp)->acc_if)) 777 #define lsm303dlhcAccelerometerSetSensitivity(devp, sp) \ 778 accelerometerSetSensitivity(&((devp)->acc_if), sp) 792 #define lsm303dlhcAccelerometerResetSensitivity(devp) \ 793 accelerometerResetSensitivity(&((devp)->acc_if)) 810 #define lsm303dlhcAccelerometerSetFullScale(devp, fs) \ 811 (devp)->vmt->acc_set_full_scale(devp, fs) 822 #define lsm303dlhcCompassGetAxesNumber(devp) \ 823 compassGetAxesNumber(&((devp)->comp_if)) 843 #define lsm303dlhcCompassReadRaw(devp, axes) \ 844 compassReadRaw(&((devp)->comp_if), axes) 865 #define lsm303dlhcCompassReadCooked(devp, axes) \ 866 compassReadCooked(&((devp)->comp_if), axes) 882 #define lsm303dlhcCompassSetBias(devp, bp) \ 883 compassSetBias(&((devp)->comp_if), bp) 897 #define lsm303dlhcCompassResetBias(devp) \ 898 compassResetBias(&((devp)->comp_if)) 914 #define lsm303dlhcCompassSetSensitivity(devp, sp) \ 915 compassSetSensitivity(&((devp)->comp_if), sp) 929 #define lsm303dlhcCompassResetSensitivity(devp) \ 930 compassResetSensitivity(&((devp)->comp_if)) 947 #define lsm303dlhcCompassSetFullScale(devp, fs) \ 948 (devp)->vmt->comp_set_full_scale(devp, fs) #define _lsm303dlhc_methods
LSM303DLHC specific methods with inherited ones.
lsm303dlhc_comp_md_t
LSM303DLHC compass subsystem working mode.
lsm303dlhc_acc_lp_t acclowpower
LSM303DLHC accelerometer subsystem low power mode.
float * compbias
LSM303DLHC compass initial bias.
lsm303dlhc_acc_end_t
LSM303DLHC accelerometer endianness.
lsm303dlhc_comp_md_t compmode
LSM303DLHC compass subsystem working mode.
Type of I2C driver configuration structure.
float * accsensitivity
LSM303DLHC accelerometer subsystem initial sensitivity.
float * accbias
LSM303DLHC accelerometer subsystem initial bias.
lsm303dlhc_comp_odr_t
LSM303DLHC compass subsystem output data rate.
lsm303dlhc_comp_odr_t compoutputdatarate
LSM303DLHC compass subsystem output data rate.
const I2CConfig * i2ccfg
I2C configuration associated to this LSM303DLHC.
void lsm303dlhcStop(LSM303DLHCDriver *devp)
Deactivates the LSM303DLHC Complex Driver peripheral.
I2CDriver * i2cp
I2C driver associated to this LSM303DLHC.
lsm303dlhc_acc_ae_t
LSM303DLHC accelerometer subsystem axes enabling.
#define _lsm303dlhc_data
LSM303DLHCDriver specific data.
lsm303dlhc_acc_odr_t
LSM303DLHC accelerometer subsystem output data rate.
lsm303dlhc_acc_bdu_t accblockdataupdate
LSM303DLHC accelerometer subsystem block data update.
lsm303dlhc_acc_odr_t accoutdatarate
LSM303DLHC accelerometer subsystem output data rate.
BaseCompass comp_if
Base compass interface.
BaseAccelerometer acc_if
Base accelerometer interface.
Structure representing an I2C driver.
LSM303DLHC configuration structure.
lsm303dlhc_acc_end_t accendianess
LSM303DLHC accelerometer endianness.
Generic accelerometer interface header.
Generic compass interface header.
const struct LSM303DLHCVMT * vmt
Virtual Methods Table.
lsm303dlhc_acc_bdu_t
LSM303DLHC accelerometer subsystem block data update.
float * compsensitivity
LSM303DLHC compass initial sensitivity.
lsm303dlhc_state_t
Driver state machine possible states.
void lsm303dlhcStart(LSM303DLHCDriver *devp, const LSM303DLHCConfig *config)
Configures and activates LSM303DLHC Complex Driver peripheral.
lsm303dlhc_acc_lp_t
LSM303DLHC accelerometer subsystem low power mode.
void lsm303dlhcObjectInit(LSM303DLHCDriver *devp)
Initializes an instance.
lsm303dlhc_comp_fs_t compfullscale
LSM303DLHC compass subsystem initial full scale.
LSM303DLHC 6-axis accelerometer/compass class.
lsm303dlhc_acc_fs_t
LSM303DLHC accelerometer subsystem full scale.
LSM303DLHC virtual methods table.
lsm303dlhc_acc_hr_t acchighresmode
LSM303DLHC accelerometer subsystem high resolution mode.
lsm303dlhc_acc_fs_t accfullscale
LSM303DLHC accelerometer subsystem initial full scale.
Base accelerometer class.
lsm303dlhc_comp_fs_t
LSM303DLHC compass subsystem full scale.
lsm303dlhc_acc_hr_t
LSM303DLHC accelerometer subsystem high resolution mode.