Improved EX drivers

git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@11685 110e8d01-0319-4d1e-a829-52ad28d1bb01
This commit is contained in:
Rocco Marco Guglielmi 2018-03-10 13:53:44 +00:00
parent e0fcf2b6c7
commit f2f3035c3c
5 changed files with 50 additions and 32 deletions

View File

@ -66,23 +66,26 @@
* @brief HTS221 hygrometer subsystem characteristics. * @brief HTS221 hygrometer subsystem characteristics.
* @note Sensitivity is expressed as %rH/LSB whereas %rH stand for percentage * @note Sensitivity is expressed as %rH/LSB whereas %rH stand for percentage
* of relative humidity. * of relative humidity.
* * @note Bias is expressed as %rH.
* @{ * @{
*/ */
#define HTS221_HYGRO_NUMBER_OF_AXES 1U #define HTS221_HYGRO_NUMBER_OF_AXES 1U
#define HTS221_HYGRO_SENS 0.00390625f #define HTS221_HYGRO_SENS 0.00390625f
#define HTS221_HYGRO_BIAS 0.0f
/** @} */ /** @} */
/** /**
* @brief HTS221 thermometer subsystem characteristics. * @brief HTS221 thermometer subsystem characteristics.
* @note Sensitivity is expressed as °C/LSB. * @note Sensitivity is expressed as °C/LSB.
* @note Bias is expressed as °C.
* *
* @{ * @{
*/ */
#define HTS221_THERMO_NUMBER_OF_AXES 1U #define HTS221_THERMO_NUMBER_OF_AXES 1U
#define HTS221_THERMO_SENS 0.0015625f #define HTS221_THERMO_SENS 0.0015625f
#define HTS221_THERMO_BIAS 0.0f
/** @} */ /** @} */
/** /**

View File

@ -286,7 +286,7 @@ static msg_t gyro_reset_bias(void *ip) {
"gyro_reset_bias(), invalid state"); "gyro_reset_bias(), invalid state");
for(i = 0; i < L3GD20_GYRO_NUMBER_OF_AXES; i++) for(i = 0; i < L3GD20_GYRO_NUMBER_OF_AXES; i++)
devp->gyrobias[i] = 0.0; devp->gyrobias[i] = L3GD20_GYRO_BIAS;
return MSG_OK; return MSG_OK;
} }
@ -345,13 +345,13 @@ static msg_t gyro_reset_sensivity(void *ip) {
if(devp->config->gyrofullscale == L3GD20_FS_250DPS) if(devp->config->gyrofullscale == L3GD20_FS_250DPS)
for(i = 0; i < L3GD20_GYRO_NUMBER_OF_AXES; i++) for(i = 0; i < L3GD20_GYRO_NUMBER_OF_AXES; i++)
devp->gyrosensitivity[i] = L3GD20_SENS_250DPS; devp->gyrosensitivity[i] = L3GD20_GYRO_SENS_250DPS;
else if(devp->config->gyrofullscale == L3GD20_FS_500DPS) else if(devp->config->gyrofullscale == L3GD20_FS_500DPS)
for(i = 0; i < L3GD20_GYRO_NUMBER_OF_AXES; i++) for(i = 0; i < L3GD20_GYRO_NUMBER_OF_AXES; i++)
devp->gyrosensitivity[i] = L3GD20_SENS_500DPS; devp->gyrosensitivity[i] = L3GD20_GYRO_SENS_500DPS;
else if(devp->config->gyrofullscale == L3GD20_FS_2000DPS) else if(devp->config->gyrofullscale == L3GD20_FS_2000DPS)
for(i = 0; i < L3GD20_GYRO_NUMBER_OF_AXES; i++) for(i = 0; i < L3GD20_GYRO_NUMBER_OF_AXES; i++)
devp->gyrosensitivity[i] = L3GD20_SENS_2000DPS; devp->gyrosensitivity[i] = L3GD20_GYRO_SENS_2000DPS;
else { else {
osalDbgAssert(FALSE, "gyro_reset_sensivity(), full scale issue"); osalDbgAssert(FALSE, "gyro_reset_sensivity(), full scale issue");
return MSG_RESET; return MSG_RESET;
@ -468,14 +468,11 @@ static const struct BaseGyroscopeVMT vmt_gyroscope = {
* @init * @init
*/ */
void l3gd20ObjectInit(L3GD20Driver *devp) { void l3gd20ObjectInit(L3GD20Driver *devp) {
uint32_t i;
devp->vmt = &vmt_device; devp->vmt = &vmt_device;
devp->gyro_if.vmt = &vmt_gyroscope; devp->gyro_if.vmt = &vmt_gyroscope;
devp->config = NULL; devp->config = NULL;
for(i = 0; i < L3GD20_GYRO_NUMBER_OF_AXES; i++)
devp->gyrobias[i] = 0.0f;
devp->state = L3GD20_STOP; devp->state = L3GD20_STOP;
} }
@ -560,7 +557,7 @@ void l3gd20Start(L3GD20Driver *devp, const L3GD20Config *config) {
devp->gyrofullscale = L3GD20_250DPS; devp->gyrofullscale = L3GD20_250DPS;
for(i = 0; i < L3GD20_GYRO_NUMBER_OF_AXES; i++) { for(i = 0; i < L3GD20_GYRO_NUMBER_OF_AXES; i++) {
if (devp->config->gyrosensitivity == NULL) if (devp->config->gyrosensitivity == NULL)
devp->gyrosensitivity[i] = L3GD20_SENS_250DPS; devp->gyrosensitivity[i] = L3GD20_GYRO_SENS_250DPS;
else else
devp->gyrosensitivity[i] = devp->config->gyrosensitivity[i]; devp->gyrosensitivity[i] = devp->config->gyrosensitivity[i];
} }
@ -569,7 +566,7 @@ void l3gd20Start(L3GD20Driver *devp, const L3GD20Config *config) {
devp->gyrofullscale = L3GD20_500DPS; devp->gyrofullscale = L3GD20_500DPS;
for(i = 0; i < L3GD20_GYRO_NUMBER_OF_AXES; i++) { for(i = 0; i < L3GD20_GYRO_NUMBER_OF_AXES; i++) {
if (devp->config->gyrosensitivity == NULL) if (devp->config->gyrosensitivity == NULL)
devp->gyrosensitivity[i] = L3GD20_SENS_500DPS; devp->gyrosensitivity[i] = L3GD20_GYRO_SENS_500DPS;
else else
devp->gyrosensitivity[i] = devp->config->gyrosensitivity[i]; devp->gyrosensitivity[i] = devp->config->gyrosensitivity[i];
} }
@ -578,19 +575,24 @@ void l3gd20Start(L3GD20Driver *devp, const L3GD20Config *config) {
devp->gyrofullscale = L3GD20_2000DPS; devp->gyrofullscale = L3GD20_2000DPS;
for(i = 0; i < L3GD20_GYRO_NUMBER_OF_AXES; i++) { for(i = 0; i < L3GD20_GYRO_NUMBER_OF_AXES; i++) {
if (devp->config->gyrosensitivity == NULL) if (devp->config->gyrosensitivity == NULL)
devp->gyrosensitivity[i] = L3GD20_SENS_2000DPS; devp->gyrosensitivity[i] = L3GD20_GYRO_SENS_2000DPS;
else else
devp->gyrosensitivity[i] = devp->config->gyrosensitivity[i]; devp->gyrosensitivity[i] = devp->config->gyrosensitivity[i];
} }
} }
else else
osalDbgAssert(FALSE, "l3gd20Start(), full scale issue"); osalDbgAssert(FALSE, "l3gd20Start(), full scale issue");
/* Storing bias information.*/
if(devp->config->gyrobias != NULL) { if(devp->config->gyrobias != NULL) {
for(i = 0; i < L3GD20_GYRO_NUMBER_OF_AXES; i++) { for(i = 0; i < L3GD20_GYRO_NUMBER_OF_AXES; i++) {
devp->gyrobias[i] = devp->config->gyrobias[i]; devp->gyrobias[i] = devp->config->gyrobias[i];
} }
} }
else {
for(i = 0; i < L3GD20_GYRO_NUMBER_OF_AXES; i++)
devp->gyrobias[i] = L3GD20_GYRO_BIAS;
}
/* This is the Gyroscope transient recovery time.*/ /* This is the Gyroscope transient recovery time.*/
osalThreadSleepMilliseconds(10); osalThreadSleepMilliseconds(10);

View File

@ -64,6 +64,7 @@
* @brief L3GD20 gyroscope system characteristics. * @brief L3GD20 gyroscope system characteristics.
* @note Sensitivity is expressed as DPS/LSB whereas DPS stand for Degree * @note Sensitivity is expressed as DPS/LSB whereas DPS stand for Degree
* per second [°/s]. * per second [°/s].
* @note Bias is expressed as DPS.
* *
* @{ * @{
*/ */
@ -73,9 +74,11 @@
#define L3GD20_500DPS 500.0f #define L3GD20_500DPS 500.0f
#define L3GD20_2000DPS 2000.0f #define L3GD20_2000DPS 2000.0f
#define L3GD20_SENS_250DPS 0.00875f #define L3GD20_GYRO_SENS_250DPS 0.00875f
#define L3GD20_SENS_500DPS 0.01750f #define L3GD20_GYRO_SENS_500DPS 0.01750f
#define L3GD20_SENS_2000DPS 0.07000f #define L3GD20_GYRO_SENS_2000DPS 0.07000f
#define L3GD20_GYRO_BIAS 0.0f
/** @} */ /** @} */
/** /**

View File

@ -254,7 +254,7 @@ static msg_t acc_reset_bias(void *ip) {
"acc_reset_bias(), invalid state"); "acc_reset_bias(), invalid state");
for(i = 0; i < LSM303DLHC_ACC_NUMBER_OF_AXES; i++) for(i = 0; i < LSM303DLHC_ACC_NUMBER_OF_AXES; i++)
devp->accbias[i] = 0.0; devp->accbias[i] = LSM303DLHC_ACC_BIAS;
return msg; return msg;
} }
@ -498,7 +498,7 @@ static msg_t comp_read_raw(void *ip, int32_t axes[]) {
* @brief Retrieves cooked data from the BaseCompass. * @brief Retrieves cooked data from the BaseCompass.
* @note This data is manipulated according to the formula * @note This data is manipulated according to the formula
* cooked = (raw * sensitivity) - bias. * cooked = (raw * sensitivity) - bias.
* @note Final data is expressed as Ga. * @note Final data is expressed as G.
* @note The axes array must be at least the same size of the * @note The axes array must be at least the same size of the
* BaseCompass axes number. * BaseCompass axes number.
* *
@ -535,7 +535,7 @@ static msg_t comp_read_cooked(void *ip, float axes[]) {
/** /**
* @brief Set bias values for the BaseCompass. * @brief Set bias values for the BaseCompass.
* @note Bias must be expressed as Ga. * @note Bias must be expressed as G.
* @note The bias buffer must be at least the same size of the * @note The bias buffer must be at least the same size of the
* BaseCompass axes number. * BaseCompass axes number.
* *
@ -588,13 +588,13 @@ static msg_t comp_reset_bias(void *ip) {
"comp_reset_bias(), invalid state"); "comp_reset_bias(), invalid state");
for(i = 0; i < LSM303DLHC_COMP_NUMBER_OF_AXES; i++) for(i = 0; i < LSM303DLHC_COMP_NUMBER_OF_AXES; i++)
devp->compbias[i] = 0.0; devp->compbias[i] = LSM303DLHC_COMP_BIAS;
return msg; return msg;
} }
/** /**
* @brief Set sensitivity values for the BaseCompass. * @brief Set sensitivity values for the BaseCompass.
* @note Sensitivity must be expressed as Ga/LSB. * @note Sensitivity must be expressed as G/LSB.
* @note The sensitivity buffer must be at least the same size of the * @note The sensitivity buffer must be at least the same size of the
* BaseCompass axes number. * BaseCompass axes number.
* *
@ -860,11 +860,8 @@ void lsm303dlhcObjectInit(LSM303DLHCDriver *devp) {
devp->accaxes = LSM303DLHC_ACC_NUMBER_OF_AXES; devp->accaxes = LSM303DLHC_ACC_NUMBER_OF_AXES;
devp->compaxes = LSM303DLHC_COMP_NUMBER_OF_AXES; devp->compaxes = LSM303DLHC_COMP_NUMBER_OF_AXES;
for(i = 0; i < LSM303DLHC_ACC_NUMBER_OF_AXES; i++)
devp->accbias[i] = 0.0f;
for(i = 0; i < LSM303DLHC_COMP_NUMBER_OF_AXES; i++)
devp->compbias[i] = 0.0f;
devp->state = LSM303DLHC_STOP; devp->state = LSM303DLHC_STOP;
} }
@ -976,6 +973,9 @@ void lsm303dlhcStart(LSM303DLHCDriver *devp, const LSM303DLHCConfig *config) {
if(devp->config->accbias != NULL) if(devp->config->accbias != NULL)
for(i = 0; i < LSM303DLHC_ACC_NUMBER_OF_AXES; i++) for(i = 0; i < LSM303DLHC_ACC_NUMBER_OF_AXES; i++)
devp->accbias[i] = devp->config->accbias[i]; devp->accbias[i] = devp->config->accbias[i];
else
for(i = 0; i < LSM303DLHC_ACC_NUMBER_OF_AXES; i++)
devp->accbias[i] = LSM303DLHC_ACC_BIAS;
/* Configuring Compass subsystem */ /* Configuring Compass subsystem */
@ -1131,7 +1131,10 @@ void lsm303dlhcStart(LSM303DLHCDriver *devp, const LSM303DLHCConfig *config) {
if(devp->config->compbias != NULL) if(devp->config->compbias != NULL)
for(i = 0; i < LSM303DLHC_COMP_NUMBER_OF_AXES; i++) for(i = 0; i < LSM303DLHC_COMP_NUMBER_OF_AXES; i++)
devp->compbias[i] = devp->config->compbias[i]; devp->compbias[i] = devp->config->compbias[i];
else
for(i = 0; i < LSM303DLHC_COMP_NUMBER_OF_AXES; i++)
devp->compbias[i] = LSM303DLHC_COMP_BIAS;
/* This is the MEMS transient recovery time */ /* This is the MEMS transient recovery time */
osalThreadSleepMilliseconds(5); osalThreadSleepMilliseconds(5);

View File

@ -63,7 +63,9 @@
/** /**
* @brief LSM303DLHC accelerometer subsystem characteristics. * @brief LSM303DLHC accelerometer subsystem characteristics.
* @note Sensitivity is expressed as mG/LSB whereas 1 mG = 0.00980665 m/s^2. * @note Sensitivity is expressed as milli-G/LSB whereas
* 1 milli-G = 0.00980665 m/s^2.
* @note Bias is expressed as milli-G.
* *
* @{ * @{
*/ */
@ -78,11 +80,14 @@
#define LSM303DLHC_ACC_SENS_4G 0.1221f #define LSM303DLHC_ACC_SENS_4G 0.1221f
#define LSM303DLHC_ACC_SENS_8G 0.2442f #define LSM303DLHC_ACC_SENS_8G 0.2442f
#define LSM303DLHC_ACC_SENS_16G 0.4884f #define LSM303DLHC_ACC_SENS_16G 0.4884f
#define LSM303DLHC_ACC_BIAS 0.0f
/** @} */ /** @} */
/** /**
* @brief LSM303DLHC compass subsystem characteristics. * @brief LSM303DLHC compass subsystem characteristics.
* @note Sensitivity is expressed as GA/LSB whereas GA stands for Gauss. * @note Sensitivity is expressed as G/LSB whereas G stands for Gauss.
* @note Bias is expressed as G.
* *
* @{ * @{
*/ */
@ -111,6 +116,8 @@
#define LSM303DLHC_COMP_SENS_Z_4P7GA 0.0028169f #define LSM303DLHC_COMP_SENS_Z_4P7GA 0.0028169f
#define LSM303DLHC_COMP_SENS_Z_5P6GA 0.0033898f #define LSM303DLHC_COMP_SENS_Z_5P6GA 0.0033898f
#define LSM303DLHC_COMP_SENS_Z_8P1GA 0.0048780f #define LSM303DLHC_COMP_SENS_Z_8P1GA 0.0048780f
#define LSM303DLHC_COMP_BIAS 0.0f
/** @} */ /** @} */
/** /**
@ -795,7 +802,7 @@ struct LSM303DLHCDriver {
* @brief Retrieves cooked data from the BaseCompass. * @brief Retrieves cooked data from the BaseCompass.
* @note This data is manipulated according to the formula * @note This data is manipulated according to the formula
* cooked = (raw * sensitivity) - bias. * cooked = (raw * sensitivity) - bias.
* @note Final data is expressed as Ga. * @note Final data is expressed as G.
* @note The axes array must be at least the same size of the * @note The axes array must be at least the same size of the
* BaseCompass axes number. * BaseCompass axes number.
* *
@ -815,7 +822,7 @@ struct LSM303DLHCDriver {
/** /**
* @brief Set bias values for the BaseCompass. * @brief Set bias values for the BaseCompass.
* @note Bias must be expressed as Ga. * @note Bias must be expressed as G.
* @note The bias buffer must be at least the same size of the * @note The bias buffer must be at least the same size of the
* BaseCompass axes number. * BaseCompass axes number.
* *
@ -847,7 +854,7 @@ struct LSM303DLHCDriver {
/** /**
* @brief Set sensitivity values for the BaseCompass. * @brief Set sensitivity values for the BaseCompass.
* @note Sensitivity must be expressed as Ga/LSB. * @note Sensitivity must be expressed as G/LSB.
* @note The sensitivity buffer must be at least the same size of the * @note The sensitivity buffer must be at least the same size of the
* BaseCompass axes number. * BaseCompass axes number.
* *