Add calibration data inside the BMP085 drive.
git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@10830 35acf78f-673a-0410-8e92-d51de3d6d3f4
This commit is contained in:
parent
c5d032c264
commit
aada1a7ea6
|
@ -51,22 +51,6 @@
|
|||
/* Driver local variables and types. */
|
||||
/*==========================================================================*/
|
||||
|
||||
/**
|
||||
* @brief Variables for Temperature and Pressure measurement.
|
||||
*/
|
||||
static int16_t ac1;
|
||||
static int16_t ac2;
|
||||
static int16_t ac3;
|
||||
static int16_t b1;
|
||||
static int16_t b2;
|
||||
static int16_t mb;
|
||||
static int16_t mc;
|
||||
static int16_t md;
|
||||
static uint16_t ac4;
|
||||
static uint16_t ac5;
|
||||
static uint16_t ac6;
|
||||
static int32_t b5;
|
||||
|
||||
/*==========================================================================*/
|
||||
/* Driver local functions. */
|
||||
/*==========================================================================*/
|
||||
|
@ -136,17 +120,17 @@ static msg_t bmp085ReadCoefficient(BMP085Driver *devp, uint8_t reg) {
|
|||
#endif /* BMP085_SHARED_I2C */
|
||||
|
||||
if (msg == MSG_OK) {
|
||||
ac1 = ((rxbuf[ 0] << 8) | rxbuf[ 1]);
|
||||
ac2 = ((rxbuf[ 2] << 8) | rxbuf[ 3]);
|
||||
ac3 = ((rxbuf[ 4] << 8) | rxbuf[ 5]);
|
||||
ac4 = ((rxbuf[ 6] << 8) | rxbuf[ 7]);
|
||||
ac5 = ((rxbuf[ 8] << 8) | rxbuf[ 9]);
|
||||
ac6 = ((rxbuf[10] << 8) | rxbuf[11]);
|
||||
b1 = ((rxbuf[12] << 8) | rxbuf[13]);
|
||||
b2 = ((rxbuf[14] << 8) | rxbuf[15]);
|
||||
mb = ((rxbuf[16] << 8) | rxbuf[17]);
|
||||
mc = ((rxbuf[18] << 8) | rxbuf[19]);
|
||||
md = ((rxbuf[20] << 8) | rxbuf[21]);
|
||||
devp->calibrationdata.ac1 = ((rxbuf[ 0] << 8) | rxbuf[ 1]);
|
||||
devp->calibrationdata.ac2 = ((rxbuf[ 2] << 8) | rxbuf[ 3]);
|
||||
devp->calibrationdata.ac3 = ((rxbuf[ 4] << 8) | rxbuf[ 5]);
|
||||
devp->calibrationdata.ac4 = ((rxbuf[ 6] << 8) | rxbuf[ 7]);
|
||||
devp->calibrationdata.ac5 = ((rxbuf[ 8] << 8) | rxbuf[ 9]);
|
||||
devp->calibrationdata.ac6 = ((rxbuf[10] << 8) | rxbuf[11]);
|
||||
devp->calibrationdata.b1 = ((rxbuf[12] << 8) | rxbuf[13]);
|
||||
devp->calibrationdata.b2 = ((rxbuf[14] << 8) | rxbuf[15]);
|
||||
devp->calibrationdata.mb = ((rxbuf[16] << 8) | rxbuf[17]);
|
||||
devp->calibrationdata.mc = ((rxbuf[18] << 8) | rxbuf[19]);
|
||||
devp->calibrationdata.md = ((rxbuf[20] << 8) | rxbuf[21]);
|
||||
}
|
||||
|
||||
return msg;
|
||||
|
@ -155,28 +139,30 @@ static msg_t bmp085ReadCoefficient(BMP085Driver *devp, uint8_t reg) {
|
|||
/**
|
||||
* @brief Calcul the true temperature.
|
||||
*
|
||||
* @param[in] devp pointer to the BMP085 device driver sensor
|
||||
* @param[in] ut uncompensated temperature
|
||||
* @param[out] ctp pointer of the compensated temperature
|
||||
*/
|
||||
static void calcul_t(int32_t ut, float *ctp) {
|
||||
static void calcul_t(BMP085Driver *devp, int32_t ut, float *ctp) {
|
||||
|
||||
int32_t x1, x2;
|
||||
|
||||
/* Converting the temperature value. */
|
||||
x1 = ((ut - ac6) * ac5) >> 15;
|
||||
x2 = (mc << 11) / (x1 + md);
|
||||
b5 = x1 + x2;
|
||||
*ctp = (float)((b5 + 8) >> 4)*BMP085_T_RES;
|
||||
x1 = ((ut - devp->calibrationdata.ac6) * devp->calibrationdata.ac5) >> 15;
|
||||
x2 = (devp->calibrationdata.mc << 11) / (x1 + devp->calibrationdata.md);
|
||||
devp->calibrationdata.b5 = x1 + x2;
|
||||
*ctp = (float)((devp->calibrationdata.b5 + 8) >> 4)*BMP085_T_RES;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Calcul the true pressure.
|
||||
*
|
||||
* @param[in] devp pointer to the BMP085 device driver sensor
|
||||
* @param[in] up uncompensated pressure
|
||||
* @param[in] oss over sampling setting
|
||||
* @param[out] cpp pointer of the compensated pressure
|
||||
*/
|
||||
static void calcul_p(int32_t up, uint8_t oss, float *cpp) {
|
||||
static void calcul_p(BMP085Driver *devp, int32_t up, uint8_t oss, float *cpp) {
|
||||
|
||||
int32_t press;
|
||||
int32_t x1,x2,x3;
|
||||
|
@ -184,15 +170,15 @@ static void calcul_p(int32_t up, uint8_t oss, float *cpp) {
|
|||
uint32_t b4,b7;
|
||||
|
||||
/* Converting the pressure value. */
|
||||
b6 = b5 - 4000;
|
||||
x1 = (b2 * ((b6 * b6) >> 12)) >> 11;
|
||||
x2 = (ac2 * b6) >> 11;
|
||||
b6 = devp->calibrationdata.b5 - 4000;
|
||||
x1 = (devp->calibrationdata.b2 * ((b6 * b6) >> 12)) >> 11;
|
||||
x2 = (devp->calibrationdata.ac2 * b6) >> 11;
|
||||
x3 = x1 + x2;
|
||||
b3 = ((((int32_t)ac1 * 4 + x3) << oss) + 2) >> 2;
|
||||
x1 = ((ac3)*b6) >> 13;
|
||||
x2 = (b1 * (b6*b6 >> 12)) >> 16;
|
||||
b3 = ((((int32_t)devp->calibrationdata.ac1 * 4 + x3) << oss) + 2) >> 2;
|
||||
x1 = ((devp->calibrationdata.ac3)*b6) >> 13;
|
||||
x2 = (devp->calibrationdata.b1 * (b6*b6 >> 12)) >> 16;
|
||||
x3 = ((x1 + x2) + 2) >> 2;
|
||||
b4 = ac4 * (uint32_t)(x3 + 32768) >> 15;
|
||||
b4 = devp->calibrationdata.ac4 * (uint32_t)(x3 + 32768) >> 15;
|
||||
b7 = ((uint32_t)up - b3)*(50000 >> oss);
|
||||
|
||||
if (b7 < 0x80000000)
|
||||
|
@ -217,18 +203,15 @@ static msg_t start_t_measurement(BMP085Driver *devp) {
|
|||
|
||||
uint8_t txbuf[2] = {BMP085_AD_CR, BMP085_CR_T_VAL};
|
||||
|
||||
if ((devp)->config->thermocfg != NULL) {
|
||||
i2cAcquireBus(devp->config->i2cp);
|
||||
msg_t msg = bmp085I2CWriteRegister(devp->config->i2cp, txbuf, 2);
|
||||
i2cReleaseBus(devp->config->i2cp);
|
||||
i2cAcquireBus(devp->config->i2cp);
|
||||
msg_t msg = bmp085I2CWriteRegister(devp->config->i2cp, txbuf, 2);
|
||||
i2cReleaseBus(devp->config->i2cp);
|
||||
|
||||
/* Conversion time for the temperature. */
|
||||
chThdSleepMilliseconds(BMP085_THERMO_CT_LOW);
|
||||
/* Conversion time for the temperature. */
|
||||
chThdSleepMilliseconds(BMP085_THERMO_CT_LOW);
|
||||
//chThdSleepMilliseconds(devp->config.tct); // TODO: use this instead of the top line:
|
||||
|
||||
return msg;
|
||||
}
|
||||
else
|
||||
return MSG_RESET;
|
||||
return msg;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -242,7 +225,7 @@ static msg_t start_p_measurement(BMP085Driver *devp) {
|
|||
uint8_t oss, delay;
|
||||
uint8_t txbuf[2];
|
||||
|
||||
oss = devp->config->barocfg->oss;
|
||||
oss = devp->config->oss;
|
||||
txbuf[0] = BMP085_AD_CR;
|
||||
|
||||
/* Check the oss according the bmp085 mode. */
|
||||
|
@ -332,7 +315,7 @@ static msg_t acquire_up(BMP085Driver *devp, int32_t *upress) {
|
|||
msg_t msg;
|
||||
|
||||
/* Get the oversampling setting from the driver configuratioin. */
|
||||
oss = devp->config->barocfg->oss;
|
||||
oss = devp->config->oss;
|
||||
|
||||
/* Start the pressure measurement. */
|
||||
start_p_measurement(devp);
|
||||
|
@ -486,18 +469,14 @@ static msg_t sens_read_raw(void *ip, int32_t axes[]) {
|
|||
int32_t* bp = axes;
|
||||
msg_t msg;
|
||||
|
||||
if (((BMP085Driver *)ip)->config->barocfg != NULL) {
|
||||
msg = baro_read_raw(ip, bp);
|
||||
msg = baro_read_raw(ip, bp);
|
||||
|
||||
if (msg != MSG_OK)
|
||||
return msg;
|
||||
if (msg != MSG_OK)
|
||||
return msg;
|
||||
|
||||
bp += BMP085_BARO_NUMBER_OF_AXES;
|
||||
}
|
||||
bp += BMP085_BARO_NUMBER_OF_AXES;
|
||||
|
||||
if (((BMP085Driver *)ip)->config->thermocfg != NULL) {
|
||||
msg = thermo_read_raw(ip, bp);
|
||||
}
|
||||
msg = thermo_read_raw(ip, bp);
|
||||
|
||||
return msg;
|
||||
}
|
||||
|
@ -522,10 +501,10 @@ static msg_t baro_read_cooked(void *ip, float axes[]) {
|
|||
"baro_read_cooked(), invalid state");
|
||||
|
||||
msg = baro_read_raw(ip, raw);
|
||||
oss = ((BMP085Driver *)ip)->config->barocfg->oss;
|
||||
oss = ((BMP085Driver *)ip)->config->oss;
|
||||
|
||||
for (i = 0; i < BMP085_BARO_NUMBER_OF_AXES; i++)
|
||||
calcul_p(raw[i], oss, &axes[i]);
|
||||
calcul_p(ip, raw[i], oss, &axes[i]);
|
||||
|
||||
return msg;
|
||||
}
|
||||
|
@ -550,7 +529,7 @@ static msg_t thermo_read_cooked(void *ip, float axes[]) {
|
|||
msg = thermo_read_raw(ip, raw);
|
||||
|
||||
for (i = 0; i < BMP085_THERMO_NUMBER_OF_AXES; i++)
|
||||
calcul_t(raw[i], &axes[i]);
|
||||
calcul_t(ip, raw[i], &axes[i]);
|
||||
|
||||
return msg;
|
||||
}
|
||||
|
@ -568,17 +547,13 @@ static msg_t sens_read_cooked(void *ip, float axes[]) {
|
|||
float* bp = axes;
|
||||
msg_t msg;
|
||||
|
||||
if (((BMP085Driver *)ip)->config->barocfg != NULL) {
|
||||
msg = baro_read_cooked(ip, bp);
|
||||
msg = baro_read_cooked(ip, bp);
|
||||
|
||||
if (msg != MSG_OK)
|
||||
return msg;
|
||||
if (msg != MSG_OK)
|
||||
return msg;
|
||||
|
||||
bp += BMP085_BARO_NUMBER_OF_AXES;
|
||||
}
|
||||
|
||||
if (((BMP085Driver *)ip)->config->thermocfg != NULL)
|
||||
msg = thermo_read_cooked(ip, bp);
|
||||
bp += BMP085_BARO_NUMBER_OF_AXES;
|
||||
msg = thermo_read_cooked(ip, bp);
|
||||
|
||||
return msg;
|
||||
}
|
||||
|
|
|
@ -45,7 +45,7 @@
|
|||
/**
|
||||
* @brief BMP085 driver version string.
|
||||
*/
|
||||
#define EX_BMP085_VERSION "1.0.0"
|
||||
#define EX_BMP085_VERSION "1.0.1"
|
||||
|
||||
/**
|
||||
* @brief BMP085 driver version major number.
|
||||
|
@ -60,7 +60,7 @@
|
|||
/**
|
||||
* @brief BMP085 driver version patch number.
|
||||
*/
|
||||
#define EX_BMP085_PATCH 0
|
||||
#define EX_BMP085_PATCH 1
|
||||
/** @}*/
|
||||
|
||||
/**
|
||||
|
@ -134,21 +134,12 @@
|
|||
#endif
|
||||
|
||||
/**
|
||||
* @brief BMP085 barometer subsystem advanced configurations switch.
|
||||
* @brief BMP085 sensor subsystem advanced configurations switch.
|
||||
* @details If set to @p TRUE more configurations are available.
|
||||
* @note The default is @p FALSE.
|
||||
* @note The default is @p TRUE.
|
||||
*/
|
||||
#if !defined(BMP085_BARO_USE_ADVANCED) || defined(__DOXYGEN__)
|
||||
#define BMP085_BARO_USE_ADVANCED FALSE
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief BMP085 thermometer subsystem advanced configurations switch.
|
||||
* @details If set to @p TRUE more configurations are available.
|
||||
* @note The default is @p FALSE.
|
||||
*/
|
||||
#if !defined(BMP085_THERMO_USE_ADVANCED) || defined(__DOXYGEN__)
|
||||
#define BMP085_THERMO_USE_ADVANCED FALSE
|
||||
#if !defined(BMP085_USE_ADVANCED) || defined(__DOXYGEN__)
|
||||
#define BMP085_USE_ADVANCED TRUE
|
||||
#endif
|
||||
|
||||
/**
|
||||
|
@ -214,24 +205,23 @@ typedef enum {
|
|||
}bmp085_baro_oss_t;
|
||||
|
||||
/**
|
||||
* @brief BMP085 barometer subsystem configuration structure.
|
||||
* @brief BMP085 barometer subsystem calibration data.
|
||||
*/
|
||||
typedef struct {
|
||||
/**
|
||||
* @brief BMP085 barometer subsystem pressure conversion time.
|
||||
*/
|
||||
bmp085_baro_ct_t ct;
|
||||
int16_t ac1;
|
||||
int16_t ac2;
|
||||
int16_t ac3;
|
||||
int16_t b1;
|
||||
int16_t b2;
|
||||
int16_t mb;
|
||||
int16_t mc;
|
||||
int16_t md;
|
||||
uint16_t ac4;
|
||||
uint16_t ac5;
|
||||
uint16_t ac6;
|
||||
int32_t b5;
|
||||
} bmp085_cd_t;
|
||||
|
||||
/**
|
||||
* @brief BMP085 barometer subsystem mode.
|
||||
*/
|
||||
bmp085_baro_mode_t mode;
|
||||
|
||||
/**
|
||||
* @brief BMP085 barometer subsystem oversampling setting.
|
||||
*/
|
||||
bmp085_baro_oss_t oss;
|
||||
} BMP085BaroConfig;
|
||||
/** @} */
|
||||
|
||||
/**
|
||||
|
@ -249,15 +239,6 @@ typedef enum {
|
|||
BMP085_THERMO_CT_LUHR = 0x1A /**< Conv time in ultra high res. mode. */
|
||||
} bmp085_thermo_ct_t;
|
||||
|
||||
/**
|
||||
* @brief BMP085 thermometer subsystem configuration structure.
|
||||
*/
|
||||
typedef struct {
|
||||
/**
|
||||
* @brief BMP085 thermometer subsystem temperature conversion time.
|
||||
*/
|
||||
bmp085_thermo_ct_t conversionTime;
|
||||
} BMP085ThermoConfig;
|
||||
/** @} */
|
||||
|
||||
/**
|
||||
|
@ -278,6 +259,7 @@ typedef enum {
|
|||
* @brief BMP085 configuration structure.
|
||||
*/
|
||||
typedef struct {
|
||||
#if BMP085_USE_I2C || defined(__DOXYGEN__)
|
||||
/**
|
||||
* @brief I2C driver associated to this BMP085.
|
||||
*/
|
||||
|
@ -287,16 +269,44 @@ typedef struct {
|
|||
* @brief I2C configuration associated to this BMP085 subsystem.
|
||||
*/
|
||||
const I2CConfig *i2ccfg;
|
||||
#endif /* BMP085_USE_I2C */
|
||||
/**
|
||||
* @brief HTS221 initial sensitivity.
|
||||
* @note Value are respectively related to hygrometer
|
||||
* and thermometer.
|
||||
*/
|
||||
float* sensitivity;
|
||||
/**
|
||||
* @brief HTS221 initial bias.
|
||||
* @note Value are respectively related to hygrometer
|
||||
* and thermometer.
|
||||
*/
|
||||
float* bias;
|
||||
/**
|
||||
* @brief HTS221 output data rate selection.
|
||||
*/
|
||||
float* outputdatarate;
|
||||
#if BMP085_USE_ADVANCED || defined(__DOXYGEN__)
|
||||
/**
|
||||
* @brief BMP085 barometer subsystem pressure conversion time.
|
||||
*/
|
||||
bmp085_baro_ct_t bct;
|
||||
|
||||
/**
|
||||
* @brief BMP085 barometer subsystem configuration structure
|
||||
* @brief BMP085 barometer subsystem mode.
|
||||
*/
|
||||
const BMP085BaroConfig *barocfg;
|
||||
bmp085_baro_mode_t mode;
|
||||
|
||||
/**
|
||||
* @brief BMP085 thermometer subsystem configuration structure
|
||||
* @brief BMP085 barometer subsystem oversampling setting.
|
||||
*/
|
||||
const BMP085ThermoConfig *thermocfg;
|
||||
bmp085_baro_oss_t oss;
|
||||
|
||||
/**
|
||||
* @brief BMP085 thermometer subsystem temperature conversion time.
|
||||
*/
|
||||
bmp085_thermo_ct_t tct;
|
||||
#endif /* BMP085_USE_ADVANCED */
|
||||
} BMP085Config;
|
||||
|
||||
/**
|
||||
|
@ -351,8 +361,13 @@ struct BMP085THERMOVMT {
|
|||
/* Current thermometer sensitivity. */ \
|
||||
float thermosensitivity[BMP085_THERMO_NUMBER_OF_AXES]; \
|
||||
/* Thermometer bias data. */ \
|
||||
int32_t thermobias[BMP085_THERMO_NUMBER_OF_AXES];
|
||||
int32_t thermobias[BMP085_THERMO_NUMBER_OF_AXES]; \
|
||||
/* BMP085 calibration data. */ \
|
||||
bmp085_cd_t calibrationdata;
|
||||
|
||||
/**
|
||||
* @brief BMP085 driver structure.
|
||||
*/
|
||||
struct BMP085Driver {
|
||||
/** @brief BaseSensor Virtual Methods Table. */
|
||||
const struct BaseSensorVMT *vmt_basesensor;
|
||||
|
@ -360,7 +375,7 @@ struct BMP085Driver {
|
|||
const struct BaseBarometerVMT *vmt_basebarometer;
|
||||
/** @brief BaseThermometer Virtual Methods Table. */
|
||||
const struct BaseThermometerVMT *vmt_basethermometer;
|
||||
_bmp085_data
|
||||
_bmp085_data;
|
||||
};
|
||||
|
||||
/** @} */
|
||||
|
|
Loading…
Reference in New Issue