From d4c4f24cffc301e2f578c81b65a60ccaabe997d7 Mon Sep 17 00:00:00 2001 From: Rocco Marco Guglielmi Date: Sat, 10 Mar 2018 13:54:21 +0000 Subject: Updated LPS25H and added a thermometer interface to the driver git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@11686 110e8d01-0319-4d1e-a829-52ad28d1bb01 --- os/ex/ST/lps25h.h | 370 ++++++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 316 insertions(+), 54 deletions(-) (limited to 'os/ex/ST/lps25h.h') diff --git a/os/ex/ST/lps25h.h b/os/ex/ST/lps25h.h index 519d8e846..54d96635c 100644 --- a/os/ex/ST/lps25h.h +++ b/os/ex/ST/lps25h.h @@ -1,5 +1,5 @@ /* - ChibiOS - Copyright (C) 2016 Rocco Marco Guglielmi + ChibiOS - Copyright (C) 2016-2018 Rocco Marco Guglielmi This file is part of ChibiOS. @@ -30,6 +30,7 @@ #define _LPS25H_H_ #include "hal_barometer.h" +#include "hal_thermometer.h" /*===========================================================================*/ /* Driver constants. */ @@ -42,7 +43,7 @@ /** * @brief LPS25H driver version string. */ -#define EX_LPS25H_VERSION "1.0.4" +#define EX_LPS25H_VERSION "1.0.5" /** * @brief LPS25H driver version major number. @@ -57,18 +58,35 @@ /** * @brief LPS25H driver version patch number. */ -#define EX_LPS25H_PATCH 4 +#define EX_LPS25H_PATCH 5 /** @} */ /** - * @brief LPS25H characteristics. + * @brief LPS25H baromether subsystem characteristics. + * @note Sensitivity is expressed as hPa/LSB whereas hPa stand for + * hectopascal. + * @note Bias is expressed as hPa. * * @{ */ -#define LPS25H_NUMBER_OF_AXES 1U +#define LPS25H_BARO_NUMBER_OF_AXES 1U -#define LPS25H_SENS 0.00024414f +#define LPS25H_BARO_SENS 0.00024414f +#define LPS25H_BARO_BIAS 0.0f /** @} */ + +/** + * @brief LPS25H thermometer subsystem characteristics. + * @note Sensitivity is expressed as °C/LSB. + * @note Bias is expressed as °C. + * + * @{ + */ +#define LPS25H_THERMO_NUMBER_OF_AXES 1U + +#define LPS25H_THERMO_SENS 0.00208333f +#define LPS25H_THERMO_BIAS -42.5f +/** @} */ /** * @name LPS25H communication interfaces related bit masks @@ -254,10 +272,6 @@ #error "LPS25H_SHARED_I2C requires I2C_USE_MUTUAL_EXCLUSION" #endif -/* - * TODO: Add SPI support. - */ - /*===========================================================================*/ /* Driver data structures and types. */ /*===========================================================================*/ @@ -266,6 +280,11 @@ * @name LPS25H data structures and types. * @{ */ +/** + * @brief Structure representing a LPS25H driver. + */ +typedef struct LPS25HDriver LPS25HDriver; + /** * @brief LPS25H slave address */ @@ -345,20 +364,28 @@ typedef struct { /** * @brief I2C configuration associated to this LPS25H. */ - const I2CConfig *i2ccfg; + const I2CConfig *i2ccfg; + /** + * @brief LPS25H slave address + */ + lps25h_sad_t slaveaddress; #endif /* LPS25H_USE_I2C */ /** - * @brief LPS25H initial sensitivity. + * @brief LPS25H barometer subsystem initial sensitivity. */ - float* sensitivity; + float *barosensitivity; /** - * @brief LPS25H initial bias. + * @brief LPS25H barometer subsystem initial bias. */ - float* bias; + float *barobias; /** - * @brief LPS25H slave address + * @brief LPS25H thermometer subsystem initial sensitivity. */ - lps25h_sad_t slaveaddress; + float *thermosensitivity; + /** + * @brief LPS25H thermometer subsystem initial bias. + */ + float *thermobias; /** * @brief LPS25H output data rate selection. */ @@ -369,36 +396,36 @@ typedef struct { */ lps25h_bdu_t blockdataupdate; /** - * @brief LPS25H pressure resolution. + * @brief LPS25H barometer subsystem resolution. */ - lps25h_avgp_t respressure; + lps25h_avgp_t baroresolution; /** - * @brief LPS25H temperature resolution. + * @brief LPS25H thermometer subsystem resolution. */ - lps25h_avgt_t restemperature; + lps25h_avgt_t thermoresolution; #endif } LPS25HConfig; /** - * @brief @p LPS25H barometer subsystem specific methods. + * @brief @p LPS25H specific methods. * @note No methods so far, just a common ancestor interface. */ -#define _lps25h_barometer_methods_alone +#define _lps25h_methods_alone /** - * @brief @p LPS25H barometer subsystem specific methods with inherited ones. + * @brief @p LPS25H specific methods with inherited ones. */ -#define _lps25h_barometer_methods \ - _base_barometer_methods \ - _lps25h_barometer_methods_alone +#define _lps25h_methods \ + _base_object_methods \ + _lps25h_methods_alone /** - * @extends BaseBarometerVMT + * @extends BaseObjectVMT * - * @brief @p LPS25H barometer virtual methods table. + * @brief @p LPS25H virtual methods table. */ -struct LPS25HBarometerVMT { - _lps25h_barometer_methods +struct LPS25HVMT { + _lps25h_methods }; /** @@ -409,38 +436,273 @@ struct LPS25HBarometerVMT { lps25h_state_t state; \ /* Current configuration data.*/ \ const LPS25HConfig *config; \ - /* Current sensitivity data.*/ \ - float sensitivity; \ - /* Current Bias data.*/ \ - float bias; + /* Barometer subsystem axes number.*/ \ + size_t baroaxes; \ + /* Barometer subsystem current sensitivity.*/ \ + float barosensitivity; \ + /* Barometer subsystem current bias .*/ \ + float barobias; \ + /* Thermometer subsystem axes number.*/ \ + size_t thermoaxes; \ + /* Thermometer subsystem current sensitivity.*/ \ + float thermosensitivity; \ + /* Thermometer subsystem current bias.*/ \ + float thermobias; -/** - * @extends BaseGyroscope - * - * @brief LPS25H 3-axis barometer class. - * @details This class extends @p BaseGyroscope by adding physical - * driver implementation. +/** + * @brief LPS25H 2-axis barometer/thermometer class. */ struct LPS25HDriver { - /** @brief BaseSensor Virtual Methods Table. */ - const struct BaseSensorVMT *vmt_sensor; - _base_sensor_data - /** @brief LPS25H Barometer Virtual Methods Table. */ - const struct LPS25HBarometerVMT *vmt_barometer; - _base_barometer_data + /** @brief Virtual Methods Table.*/ + const struct LPS25HVMT *vmt; + /** @brief Base barometer interface.*/ + BaseBarometer baro_if; + /** @brief Base thermometer interface.*/ + BaseThermometer thermo_if; _lps25h_data -}; - -/** - * @brief Structure representing a LPS25H driver. - */ -typedef struct LPS25HDriver LPS25HDriver; +}; /** @} */ /*===========================================================================*/ /* Driver macros. */ /*===========================================================================*/ - + +/** + * @brief Return the number of axes of the BaseBarometer. + * + * @param[in] devp pointer to @p LPS25HDriver. + * + * @return the number of axes. + * + * @api + */ +#define lps25hBarometerGetAxesNumber(devp) \ + barometerGetAxesNumber(&((devp)->baro_if)) + +/** + * @brief Retrieves raw data from the BaseBarometer. + * @note This data is retrieved from MEMS register without any algebraical + * manipulation. + * @note The axes array must be at least the same size of the + * BaseBarometer axes number. + * + * @param[in] devp pointer to @p LPS25HDriver. + * @param[out] axes a buffer which would be filled with raw data. + * + * @return The operation status. + * @retval MSG_OK if the function succeeded. + * @retval MSG_RESET if one or more I2C errors occurred, the errors can + * be retrieved using @p i2cGetErrors(). + * @retval MSG_TIMEOUT if a timeout occurred before operation end. + * + * @api + */ +#define lps25hBarometerReadRaw(devp, axes) \ + barometerReadRaw(&((devp)->baro_if), axes) + +/** + * @brief Retrieves cooked data from the BaseBarometer. + * @note This data is manipulated according to the formula + * cooked = (raw * sensitivity) - bias. + * @note Final data is expressed as hPa. + * @note The axes array must be at least the same size of the + * BaseBarometer axes number. + * + * @param[in] devp pointer to @p LPS25HDriver. + * @param[out] axes a buffer which would be filled with cooked data. + * + * @return The operation status. + * @retval MSG_OK if the function succeeded. + * @retval MSG_RESET if one or more I2C errors occurred, the errors can + * be retrieved using @p i2cGetErrors(). + * @retval MSG_TIMEOUT if a timeout occurred before operation end. + * + * @api + */ +#define lps25hBarometerReadCooked(devp, axes) \ + barometerReadCooked(&((devp)->baro_if), axes) + +/** + * @brief Set bias values for the BaseBarometer. + * @note Bias must be expressed as hPa. + * @note The bias buffer must be at least the same size of the + * BaseBarometer axes number. + * + * @param[in] devp pointer to @p LPS25HDriver. + * @param[in] bp a buffer which contains biases. + * + * @return The operation status. + * @retval MSG_OK if the function succeeded. + * + * @api + */ +#define lps25hBarometerSetBias(devp, bp) \ + barometerSetBias(&((devp)->baro_if), bp) + +/** + * @brief Reset bias values for the BaseBarometer. + * @note Default biases value are obtained from device datasheet when + * available otherwise they are considered zero. + * + * @param[in] devp pointer to @p LPS25HDriver. + * + * @return The operation status. + * @retval MSG_OK if the function succeeded. + * + * @api + */ +#define lps25hBarometerResetBias(devp) \ + barometerResetBias(&((devp)->baro_if)) + +/** + * @brief Set sensitivity values for the BaseBarometer. + * @note Sensitivity must be expressed as hPa/LSB. + * @note The sensitivity buffer must be at least the same size of the + * BaseBarometer axes number. + * + * @param[in] devp pointer to @p LPS25HDriver. + * @param[in] sp a buffer which contains sensitivities. + * + * @return The operation status. + * @retval MSG_OK if the function succeeded. + * + * @api + */ +#define lps25hBarometerSetSensitivity(devp, sp) \ + barometerSetSensitivity(&((devp)->baro_if), sp) + +/** + * @brief Reset sensitivity values for the BaseBarometer. + * @note Default sensitivities value are obtained from device datasheet. + * + * @param[in] devp pointer to @p LPS25HDriver. + * + * @return The operation status. + * @retval MSG_OK if the function succeeded. + * + * @api + */ +#define lps25hBarometerResetSensitivity(devp) \ + barometerResetSensitivity(&((devp)->baro_if)) + +/** + * @brief Return the number of axes of the BaseThermometer. + * + * @param[in] devp pointer to @p LPS25HDriver. + * + * @return the number of axes. + * + * @api + */ +#define lps25hThermometerGetAxesNumber(devp) \ + thermometerGetAxesNumber(&((devp)->thermo_if)) + +/** + * @brief Retrieves raw data from the BaseThermometer. + * @note This data is retrieved from MEMS register without any algebraical + * manipulation. + * @note The axes array must be at least the same size of the + * BaseThermometer axes number. + * + * @param[in] devp pointer to @p LPS25HDriver. + * @param[out] axes a buffer which would be filled with raw data. + * + * @return The operation status. + * @retval MSG_OK if the function succeeded. + * @retval MSG_RESET if one or more I2C errors occurred, the errors can + * be retrieved using @p i2cGetErrors(). + * @retval MSG_TIMEOUT if a timeout occurred before operation end. + * + * @api + */ +#define lps25hThermometerReadRaw(devp, axes) \ + thermometerReadRaw(&((devp)->thermo_if), axes) + +/** + * @brief Retrieves cooked data from the BaseThermometer. + * @note This data is manipulated according to the formula + * cooked = (raw * sensitivity) - bias. + * @note Final data is expressed as °C. + * @note The axes array must be at least the same size of the + * BaseThermometer axes number. + * + * @param[in] devp pointer to @p LPS25HDriver. + * @param[out] axes a buffer which would be filled with cooked data. + * + * @return The operation status. + * @retval MSG_OK if the function succeeded. + * @retval MSG_RESET if one or more I2C errors occurred, the errors can + * be retrieved using @p i2cGetErrors(). + * @retval MSG_TIMEOUT if a timeout occurred before operation end. + * + * @api + */ +#define lps25hThermometerReadCooked(devp, axes) \ + thermometerReadCooked(&((devp)->thermo_if), axes) + +/** + * @brief Set bias values for the BaseThermometer. + * @note Bias must be expressed as °C. + * @note The bias buffer must be at least the same size of the + * BaseThermometer axes number. + * + * @param[in] devp pointer to @p LPS25HDriver. + * @param[in] bp a buffer which contains biases. + * + * @return The operation status. + * @retval MSG_OK if the function succeeded. + * + * @api + */ +#define lps25hThermometerSetBias(devp, bp) \ + thermometerSetBias(&((devp)->thermo_if), bp) + +/** + * @brief Reset bias values for the BaseThermometer. + * @note Default biases value are obtained from device datasheet when + * available otherwise they are considered zero. + * + * @param[in] devp pointer to @p LPS25HDriver. + * + * @return The operation status. + * @retval MSG_OK if the function succeeded. + * + * @api + */ +#define lps25hThermometerResetBias(devp) \ + thermometerResetBias(&((devp)->thermo_if)) + +/** + * @brief Set sensitivity values for the BaseThermometer. + * @note Sensitivity must be expressed as °C/LSB. + * @note The sensitivity buffer must be at least the same size of the + * BaseThermometer axes number. + * + * @param[in] devp pointer to @p LPS25HDriver. + * @param[in] sp a buffer which contains sensitivities. + * + * @return The operation status. + * @retval MSG_OK if the function succeeded. + * + * @api + */ +#define lps25hThermometerSetSensitivity(devp, sp) \ + thermometerSetSensitivity(&((devp)->thermo_if), sp) + +/** + * @brief Reset sensitivity values for the BaseThermometer. + * @note Default sensitivities value are obtained from device datasheet. + * + * @param[in] devp pointer to @p LPS25HDriver. + * + * @return The operation status. + * @retval MSG_OK if the function succeeded. + * + * @api + */ +#define lps25hThermometerResetSensitivity(devp) \ + thermometerResetSensitivity(&((devp)->thermo_if)) + /*===========================================================================*/ /* External declarations. */ /*===========================================================================*/ -- cgit v1.2.3