70 uint8_t reg, uint8_t *rxbuf,
size_t n) {
90 uint8_t *txbuf,
size_t n) {
138 "acc_read_raw(), invalid state");
140 "acc_read_raw(), channel not ready");
142#if LSM303DLHC_SHARED_I2C
145 devp->config->i2ccfg);
152#if LSM303DLHC_SHARED_I2C
158 tmp = buff[2 * i] + (buff[2 * i + 1] << 8);
159 axes[i] = (int32_t)tmp;
193 "acc_read_cooked(), invalid state");
197 axes[i] = (raw[i] * devp->accsensitivity[i]) - devp->accbias[i];
225 "acc_set_bias(), invalid state");
228 devp->accbias[i] = bp[i];
254 "acc_reset_bias(), invalid state");
284 "acc_set_sensivity(), invalid state");
287 devp->accsensitivity[i] = sp[i];
313 "acc_reset_sensivity(), invalid state");
356 "acc_set_full_scale(), invalid state");
358 "acc_set_full_scale(), channel not ready");
382 (newfs != devp->accfullscale)) {
384 scale = newfs / devp->accfullscale;
385 devp->accfullscale = newfs;
387#if LSM303DLHC_SHARED_I2C
390 devp->config->i2ccfg);
399#if LSM303DLHC_SHARED_I2C
409#if LSM303DLHC_SHARED_I2C
411 i2cStart(devp->config->i2cp, devp->config->i2ccfg);
417#if LSM303DLHC_SHARED_I2C
425 devp->accsensitivity[i] *= scale;
426 devp->accbias[i] *= scale;
474 "comp_read_raw(), invalid state");
476 "comp_read_raw(), channel not ready");
478#if LSM303DLHC_SHARED_I2C
481 devp->config->i2ccfg);
487#if LSM303DLHC_SHARED_I2C
493 tmp = buff[2 * i] + (buff[2 * i + 1] << 8);
494 axes[i] = (int32_t)tmp;
529 "comp_read_cooked(), invalid state");
533 axes[i] = (raw[i] * devp->compsensitivity[i]) - devp->compbias[i];
561 "comp_set_bias(), invalid state");
564 devp->compbias[i] = bp[i];
590 "comp_reset_bias(), invalid state");
620 "comp_set_sensivity(), invalid state");
623 devp->compsensitivity[i] = sp[i];
649 "comp_reset_sensivity(), invalid state");
743 "comp_set_full_scale(), invalid state");
745 "comp_set_full_scale(), channel not ready");
774 if(newfs != devp->compfullscale) {
776 scale = newfs / devp->compfullscale;
777 devp->compfullscale = newfs;
779#if LSM303DLHC_SHARED_I2C
781 i2cStart(devp->config->i2cp, devp->config->i2ccfg);
788#if LSM303DLHC_SHARED_I2C
798#if LSM303DLHC_SHARED_I2C
800 i2cStart(devp->config->i2cp, devp->config->i2ccfg);
806#if LSM303DLHC_SHARED_I2C
815 devp->compsensitivity[i] *= scale;
816 devp->compbias[i] *= scale;
878 "lsm303dlhcStart(), invalid state");
880 devp->config = config;
891#if LSM303DLHC_USE_ADVANCED || defined(__DOXYGEN__)
892 cr[1] |= devp->config->acclowpower;
908 cr[4] = devp->config->accfullscale;
909#if LSM303DLHC_USE_ADVANCED || defined(__DOXYGEN__)
910 cr[4] |= devp->config->accendianess |
911 devp->config->accbdu |
912 devp->config->acchighresmode;
916#if LSM303DLHC_SHARED_I2C
923#if LSM303DLHC_SHARED_I2C
931 if(devp->config->accsensitivity == NULL)
934 devp->accsensitivity[i] = devp->config->accsensitivity[i];
940 if(devp->config->accsensitivity == NULL)
943 devp->accsensitivity[i] = devp->config->accsensitivity[i];
949 if(devp->config->accsensitivity == NULL)
952 devp->accsensitivity[i] = devp->config->accsensitivity[i];
958 if(devp->config->accsensitivity == NULL)
961 devp->accsensitivity[i] = devp->config->accsensitivity[i];
968 if(devp->config->accbias != NULL)
970 devp->accbias[i] = devp->config->accbias[i];
981 cr[1] = devp->config->compodr;
986 cr[2] = devp->config->compfullscale;
992#if LSM303DLHC_USE_ADVANCED || defined(__DOXYGEN__)
993 cr[3] |= devp->config->compmode;
997#if LSM303DLHC_SHARED_I2C
1005#if LSM303DLHC_SHARED_I2C
1012 if(devp->config->compsensitivity == NULL) {
1021 devp->compsensitivity[i] = devp->config->compsensitivity[i];
1028 if(devp->config->compsensitivity == NULL) {
1037 devp->compsensitivity[i] = devp->config->compsensitivity[i];
1044 if(devp->config->compsensitivity == NULL) {
1053 devp->compsensitivity[i] = devp->config->compsensitivity[i];
1060 if(devp->config->compsensitivity == NULL) {
1069 devp->compsensitivity[i] = devp->config->compsensitivity[i];
1076 if(devp->config->compsensitivity == NULL) {
1085 devp->compsensitivity[i] = devp->config->compsensitivity[i];
1092 if(devp->config->compsensitivity == NULL) {
1101 devp->compsensitivity[i] = devp->config->compsensitivity[i];
1108 if(devp->config->compsensitivity == NULL) {
1117 devp->compsensitivity[i] = devp->config->compsensitivity[i];
1125 if(devp->config->compbias != NULL)
1127 devp->compbias[i] = devp->config->compbias[i];
1151 "lsm303dlhcStop(), invalid state");
1154#if LSM303DLHC_SHARED_I2C
1156 i2cStart((devp)->config->i2cp, (devp)->config->i2ccfg);
1171 i2cStop((devp)->config->i2cp);
1172#if LSM303DLHC_SHARED_I2C
static size_t acc_get_axes_number(void *ip)
Return the number of axes of the BaseAccelerometer.
static msg_t acc_reset_sensivity(void *ip)
Reset sensitivity values for the BaseAccelerometer.
static msg_t acc_set_bias(void *ip, float *bp)
Set bias values for the BaseAccelerometer.
static msg_t acc_reset_bias(void *ip)
Reset bias values for the BaseAccelerometer.
static msg_t acc_set_sensivity(void *ip, float *sp)
Set sensitivity values for the BaseAccelerometer.
static msg_t acc_read_cooked(void *ip, float axes[])
Retrieves cooked data from the BaseAccelerometer.
static msg_t acc_read_raw(void *ip, int32_t axes[])
Retrieves raw data from the BaseAccelerometer.
static const struct BaseAccelerometerVMT vmt_accelerometer
static const struct ADXL317VMT vmt_device
static msg_t acc_set_full_scale(ADXL355Driver *devp, adxl355_acc_fs_t fs)
Changes the ADXL355Driver accelerometer fullscale value.
#define objGetInstance(type, ip)
Returns the instance pointer starting from an interface pointer.
msg_t i2cStart(I2CDriver *i2cp, const I2CConfig *config)
Configures and activates the I2C peripheral.
msg_t i2cMasterTransmitTimeout(I2CDriver *i2cp, i2caddr_t addr, const uint8_t *txbuf, size_t txbytes, uint8_t *rxbuf, size_t rxbytes, sysinterval_t timeout)
Sends data via the I2C bus.
void i2cReleaseBus(I2CDriver *i2cp)
Releases exclusive access to the I2C bus.
void i2cStop(I2CDriver *i2cp)
Deactivates the I2C peripheral.
void i2cAcquireBus(I2CDriver *i2cp)
Gains exclusive access to the I2C bus.
struct hal_i2c_driver I2CDriver
Type of a structure representing an I2C driver.
static size_t comp_get_axes_number(void *ip)
Return the number of axes of the BaseCompass.
static msg_t comp_set_full_scale(LIS3MDLDriver *devp, lis3mdl_comp_fs_t fs)
Changes the LIS3MDLDriver compass fullscale value.
static msg_t comp_set_sensivity(void *ip, float *sp)
Set sensitivity values for the BaseCompass.
static msg_t comp_reset_bias(void *ip)
Reset bias values for the BaseCompass.
static msg_t comp_set_bias(void *ip, float *bp)
Set bias values for the BaseCompass.
static msg_t comp_reset_sensivity(void *ip)
Reset sensitivity values for the BaseCompass.
static msg_t comp_read_cooked(void *ip, float axes[])
Retrieves cooked data from the BaseCompass.
static const struct BaseCompassVMT vmt_compass
static msg_t comp_read_raw(void *ip, int32_t axes[])
Retrieves raw data from the BaseCompass.
#define LSM303DLHC_COMP_SENS_Z_4P0GA
#define LSM303DLHC_AD_ACC_CTRL_REG1
static size_t comp_get_axes_number(void *ip)
Return the number of axes of the BaseCompass.
#define LSM303DLHC_COMP_1P9GA
void lsm303dlhcStop(LSM303DLHCDriver *devp)
Deactivates the LSM303DLHC Complex Driver peripheral.
#define LSM303DLHC_ACC_8G
static msg_t comp_set_sensivity(void *ip, float *sp)
Set sensitivity values for the BaseCompass.
#define LSM303DLHC_ACC_4G
#define LSM303DLHC_COMP_2P5GA
#define LSM303DLHC_COMP_SENS_Z_1P3GA
static msg_t comp_reset_bias(void *ip)
Reset bias values for the BaseCompass.
static size_t acc_get_axes_number(void *ip)
Return the number of axes of the BaseAccelerometer.
#define LSM303DLHC_COMP_SENS_XY_5P6GA
lsm303dlhc_comp_fs_t
LSM303DLHC compass subsystem full scale.
#define LSM303DLHC_AD_ACC_CTRL_REG4
static msg_t comp_set_full_scale(LSM303DLHCDriver *devp, lsm303dlhc_comp_fs_t fs)
Changes the LSM303DLHCDriver compass fullscale value.
static msg_t acc_set_full_scale(LSM303DLHCDriver *devp, lsm303dlhc_acc_fs_t fs)
Changes the LSM303DLHCDriver accelerometer fullscale value.
#define LSM303DLHC_COMP_SENS_Z_8P1GA
static msg_t acc_reset_sensivity(void *ip)
Reset sensitivity values for the BaseAccelerometer.
#define LSM303DLHC_CTRL_REG1_A_XEN
static msg_t comp_set_bias(void *ip, float *bp)
Set bias values for the BaseCompass.
#define LSM303DLHC_COMP_8P1GA
static msg_t acc_set_bias(void *ip, float *bp)
Set bias values for the BaseAccelerometer.
#define LSM303DLHC_ACC_SENS_8G
#define LSM303DLHC_CTRL_REG4_A_FS_MASK
static msg_t comp_reset_sensivity(void *ip)
Reset sensitivity values for the BaseCompass.
static msg_t lsm303dlhcI2CWriteRegister(I2CDriver *i2cp, lsm303dlhc_sad_t sad, uint8_t *txbuf, size_t n)
Writes a value into a register using I2C.
#define LSM303DLHC_AD_COMP_OUT_X_L
#define LSM303DLHC_AD_COMP_MR_REG
#define LSM303DLHC_COMP_4P0GA
#define LSM303DLHC_ACC_BIAS
void lsm303dlhcStart(LSM303DLHCDriver *devp, const LSM303DLHCConfig *config)
Configures and activates LSM303DLHC Complex Driver peripheral.
#define LSM303DLHC_COMP_4P7GA
static msg_t comp_read_cooked(void *ip, float axes[])
Retrieves cooked data from the BaseCompass.
#define LSM303DLHC_ACC_NUMBER_OF_AXES
LSM303DLHC accelerometer subsystem characteristics.
#define LSM303DLHC_ACC_SENS_16G
static msg_t lsm303dlhcI2CReadRegister(I2CDriver *i2cp, lsm303dlhc_sad_t sad, uint8_t reg, uint8_t *rxbuf, size_t n)
Reads registers value using I2C.
#define LSM303DLHC_CRB_REG_M_GN_MASK
static msg_t acc_reset_bias(void *ip)
Reset bias values for the BaseAccelerometer.
lsm303dlhc_acc_fs_t
LSM303DLHC accelerometer subsystem full scale.
#define LSM303DLHC_ACC_SENS_2G
#define LSM303DLHC_COMP_SENS_XY_1P9GA
#define LSM303DLHC_ACC_2G
#define LSM303DLHC_ACC_16G
#define LSM303DLHC_COMP_SENS_XY_2P5GA
static msg_t acc_set_sensivity(void *ip, float *sp)
Set sensitivity values for the BaseAccelerometer.
#define LSM303DLHC_AD_ACC_OUT_X_L
static msg_t acc_read_cooked(void *ip, float axes[])
Retrieves cooked data from the BaseAccelerometer.
#define LSM303DLHC_COMP_SENS_XY_1P3GA
static msg_t acc_read_raw(void *ip, int32_t axes[])
Retrieves raw data from the BaseAccelerometer.
lsm303dlhc_sad_t
Accelerometer and Compass Slave Address.
#define LSM303DLHC_COMP_1P3GA
#define LSM303DLHC_AD_COMP_CRB_REG
#define LSM303DLHC_COMP_SENS_XY_4P7GA
void lsm303dlhcObjectInit(LSM303DLHCDriver *devp)
Initializes an instance.
#define LSM303DLHC_COMP_SENS_Z_1P9GA
#define LSM303DLHC_COMP_SENS_Z_2P5GA
#define LSM303DLHC_CTRL_REG1_A_ZEN
#define LSM303DLHC_COMP_SENS_Z_5P6GA
#define LSM303DLHC_COMP_5P6GA
#define LSM303DLHC_CTRL_REG1_A_YEN
static msg_t comp_read_raw(void *ip, int32_t axes[])
Retrieves raw data from the BaseCompass.
#define LSM303DLHC_COMP_BIAS
#define LSM303DLHC_COMP_SENS_XY_4P0GA
#define LSM303DLHC_COMP_SENS_XY_8P1GA
#define LSM303DLHC_COMP_NUMBER_OF_AXES
LSM303DLHC compass subsystem characteristics.
#define LSM303DLHC_AD_COMP_CRA_REG
#define LSM303DLHC_ACC_SENS_4G
#define LSM303DLHC_COMP_SENS_Z_4P7GA
@ LSM303DLHC_COMP_FS_8P1GA
@ LSM303DLHC_COMP_FS_4P7GA
@ LSM303DLHC_COMP_FS_1P3GA
@ LSM303DLHC_COMP_FS_2P5GA
@ LSM303DLHC_COMP_FS_1P9GA
@ LSM303DLHC_COMP_FS_4P0GA
@ LSM303DLHC_COMP_FS_5P6GA
@ LSM303DLHC_ACC_AE_DISABLED
@ LSM303DLHC_COMP_MD_SLEEP
#define osalDbgAssert(c, remark)
Condition assertion.
#define osalDbgCheck(c)
Function parameters check.
#define osalThreadSleepMilliseconds(msecs)
Delays the invoking thread for the specified number of milliseconds.
#define FALSE
Generic 'false' preprocessor boolean constant.
#define MSG_OK
Normal wakeup message.
#define MSG_RESET
Wakeup caused by a reset condition.
#define TIME_INFINITE
Infinite interval specification for all functions with a timeout specification.
LSM303DLHC MEMS interface module header.
Base accelerometer class.
const struct BaseAccelerometerVMT * vmt
Virtual Methods Table.
BaseAccelerometer virtual methods table.
const struct BaseCompassVMT * vmt
Virtual Methods Table.
BaseCompass virtual methods table.
LSM303DLHC configuration structure.
I2CDriver * i2cp
I2C driver associated to this LSM303DLHC.
LSM303DLHC 6-axis accelerometer/compass class.
BaseCompass comp_if
Base compass interface.
const struct LSM303DLHCVMT * vmt
Virtual Methods Table.
BaseAccelerometer acc_if
Base accelerometer interface.
LSM303DLHC virtual methods table.
const I2CConfig * config
Current configuration data.