test sending sensor results over lora radio. Accelerometer and temp/pressure.

Dependencies:   SX127x

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers x_nucleo_iks01a2_temperature.c Source File

x_nucleo_iks01a2_temperature.c

Go to the documentation of this file.
00001 /**
00002  ******************************************************************************
00003  * @file    x_nucleo_iks01a2_temperature.c
00004  * @author  MEMS Application Team
00005  * @brief   This file provides a set of functions needed to manage the temperature sensor
00006  ******************************************************************************
00007  * @attention
00008  *
00009  * <h2><center>&copy; COPYRIGHT(c) 2018 STMicroelectronics</center></h2>
00010  *
00011  * Redistribution and use in source and binary forms, with or without modification,
00012  * are permitted provided that the following conditions are met:
00013  *   1. Redistributions of source code must retain the above copyright notice,
00014  *      this list of conditions and the following disclaimer.
00015  *   2. Redistributions in binary form must reproduce the above copyright notice,
00016  *      this list of conditions and the following disclaimer in the documentation
00017  *      and/or other materials provided with the distribution.
00018  *   3. Neither the name of STMicroelectronics nor the names of its contributors
00019  *      may be used to endorse or promote products derived from this software
00020  *      without specific prior written permission.
00021  *
00022  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00023  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00024  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
00025  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
00026  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
00027  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
00028  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00029  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
00030  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
00031  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00032  *
00033  ******************************************************************************
00034  */
00035 
00036 /* Includes ------------------------------------------------------------------*/
00037 #include "x_nucleo_iks01a2_temperature.h"
00038 
00039 /** @addtogroup BSP BSP
00040  * @{
00041  */
00042 
00043 /** @addtogroup X_NUCLEO_IKS01A2 X_NUCLEO_IKS01A2
00044  * @{
00045  */
00046 
00047 /** @addtogroup X_NUCLEO_IKS01A2_TEMPERATURE Temperature
00048  * @{
00049  */
00050 
00051 /** @addtogroup X_NUCLEO_IKS01A2_TEMPERATURE_Private_Variables Private variables
00052  * @{
00053  */
00054 
00055 static DrvContextTypeDef TEMPERATURE_SensorHandle[ TEMPERATURE_SENSORS_MAX_NUM ];
00056 static TEMPERATURE_Data_t TEMPERATURE_Data[ TEMPERATURE_SENSORS_MAX_NUM ]; /* Temperature - all */
00057 //static HTS221_T_Data_t HTS221_T_0_Data;                                    /* Temperature - sensor 0 */
00058 //static LPS22HB_T_Data_t LPS22HB_T_0_Data;                                  /* Temperature - sensor 1 */
00059 static LPS22HH_T_Data_t LPS22HH_T_0_Data;                                  /* Temperature - sensor 2 */
00060 //static LPS33HW_T_Data_t LPS33HW_T_0_Data;                                  /* Temperature - sensor 3 */
00061 
00062 /**
00063  * @}
00064  */
00065 
00066 /** @addtogroup X_NUCLEO_IKS01A2_TEMPERATURE_Private_FunctionPrototypes Private function prototypes
00067  * @{
00068  */
00069 
00070 //static DrvStatusTypeDef BSP_HTS221_TEMPERATURE_Init(void **handle);
00071 //static DrvStatusTypeDef BSP_LPS22HB_TEMPERATURE_Init(void **handle);
00072 static DrvStatusTypeDef BSP_LPS22HH_TEMPERATURE_Init(void **handle);
00073 //static DrvStatusTypeDef BSP_LPS33HW_TEMPERATURE_Init(void **handle);
00074 
00075 /**
00076  * @}
00077  */
00078 
00079 /** @addtogroup X_NUCLEO_IKS01A2_TEMPERATURE_Public_Functions Public functions
00080  * @{
00081  */
00082 
00083 /**
00084  * @brief Initialize a temperature sensor
00085  * @param id the temperature sensor identifier
00086  * @param handle the device handle
00087  * @retval COMPONENT_OK in case of success
00088  * @retval COMPONENT_ERROR in case of failure
00089  */
00090 DrvStatusTypeDef BSP_TEMPERATURE_Init(TEMPERATURE_ID_t id, void **handle)
00091 {
00092   *handle = NULL;
00093 
00094   switch (id)
00095   {
00096     default:
00097     case TEMPERATURE_SENSORS_AUTO:/* Try to init temperature sensors with following priority order: */
00098       if (BSP_LPS22HH_TEMPERATURE_Init(handle) == COMPONENT_OK)
00099       {
00100         return COMPONENT_OK;
00101       }
00102       break;
00103 
00104     case LPS22HH_T_0:
00105       return BSP_LPS22HH_TEMPERATURE_Init(handle);
00106   }
00107 
00108   return COMPONENT_ERROR;
00109 }
00110 
00111 
00112 /**
00113  * @brief Deinitialize a temperature sensor
00114  * @param handle the device handle
00115  * @retval COMPONENT_OK in case of success
00116  * @retval COMPONENT_ERROR in case of failure
00117  */
00118 DrvStatusTypeDef BSP_TEMPERATURE_DeInit(void **handle)
00119 {
00120   DrvContextTypeDef *ctx = (DrvContextTypeDef *)(*handle);
00121   TEMPERATURE_Drv_t *driver = NULL;
00122 
00123   if (ctx == NULL)
00124   {
00125     return COMPONENT_ERROR;
00126   }
00127 
00128   driver = (TEMPERATURE_Drv_t *)ctx->pVTable;
00129 
00130   if (driver->DeInit == NULL)
00131   {
00132     return COMPONENT_ERROR;
00133   }
00134 
00135   if (driver->DeInit(ctx) == COMPONENT_ERROR)
00136   {
00137     return COMPONENT_ERROR;
00138   }
00139 
00140   memset(ctx, 0, sizeof(DrvContextTypeDef));
00141 
00142   *handle = NULL;
00143 
00144   return COMPONENT_OK;
00145 }
00146 
00147 
00148 /**
00149  * @brief Enable temperature sensor
00150  * @param handle the device handle
00151  * @retval COMPONENT_OK in case of success
00152  * @retval COMPONENT_ERROR in case of failure
00153  */
00154 DrvStatusTypeDef BSP_TEMPERATURE_Sensor_Enable(void *handle)
00155 {
00156 
00157   DrvContextTypeDef *ctx = (DrvContextTypeDef *)handle;
00158   TEMPERATURE_Drv_t *driver = NULL;
00159 
00160   if (ctx == NULL)
00161   {
00162     return COMPONENT_ERROR;
00163   }
00164 
00165   driver = (TEMPERATURE_Drv_t *)ctx->pVTable;
00166 
00167   if (driver->Sensor_Enable == NULL)
00168   {
00169     return COMPONENT_ERROR;
00170   }
00171 
00172   if (driver->Sensor_Enable(ctx) == COMPONENT_ERROR)
00173   {
00174     return COMPONENT_ERROR;
00175   }
00176 
00177   return COMPONENT_OK;
00178 }
00179 
00180 
00181 /**
00182  * @brief Disable temperature sensor
00183  * @param handle the device handle
00184  * @retval COMPONENT_OK in case of success
00185  * @retval COMPONENT_ERROR in case of failure
00186  */
00187 DrvStatusTypeDef BSP_TEMPERATURE_Sensor_Disable(void *handle)
00188 {
00189 
00190   DrvContextTypeDef *ctx = (DrvContextTypeDef *)handle;
00191   TEMPERATURE_Drv_t *driver = NULL;
00192 
00193   if (ctx == NULL)
00194   {
00195     return COMPONENT_ERROR;
00196   }
00197 
00198   driver = (TEMPERATURE_Drv_t *)ctx->pVTable;
00199 
00200   if (driver->Sensor_Disable == NULL)
00201   {
00202     return COMPONENT_ERROR;
00203   }
00204 
00205   if (driver->Sensor_Disable(ctx) == COMPONENT_ERROR)
00206   {
00207     return COMPONENT_ERROR;
00208   }
00209 
00210   return COMPONENT_OK;
00211 }
00212 
00213 
00214 /**
00215  * @brief Check if the temperature sensor is initialized
00216  * @param handle the device handle
00217  * @param status the pointer to the initialization status
00218  * @retval COMPONENT_OK in case of success
00219  * @retval COMPONENT_ERROR in case of failure
00220  */
00221 DrvStatusTypeDef BSP_TEMPERATURE_IsInitialized(void *handle, uint8_t *status)
00222 {
00223   DrvContextTypeDef *ctx = (DrvContextTypeDef *)handle;
00224 
00225   if (ctx == NULL)
00226   {
00227     return COMPONENT_ERROR;
00228   }
00229 
00230   if (status == NULL)
00231   {
00232     return COMPONENT_ERROR;
00233   }
00234 
00235   *status = ctx->isInitialized;
00236 
00237   return COMPONENT_OK;
00238 }
00239 
00240 
00241 /**
00242  * @brief Check if the temperature sensor is enabled
00243  * @param handle the device handle
00244  * @param status the pointer to the enable status
00245  * @retval COMPONENT_OK in case of success
00246  * @retval COMPONENT_ERROR in case of failure
00247  */
00248 DrvStatusTypeDef BSP_TEMPERATURE_IsEnabled(void *handle, uint8_t *status)
00249 {
00250   DrvContextTypeDef *ctx = (DrvContextTypeDef *)handle;
00251 
00252   if (ctx == NULL)
00253   {
00254     return COMPONENT_ERROR;
00255   }
00256 
00257   if (status == NULL)
00258   {
00259     return COMPONENT_ERROR;
00260   }
00261 
00262   *status = ctx->isEnabled;
00263 
00264   return COMPONENT_OK;
00265 }
00266 
00267 
00268 /**
00269  * @brief Check if the temperature sensor is combo
00270  * @param handle the device handle
00271  * @param status the pointer to the combo status
00272  * @retval COMPONENT_OK in case of success
00273  * @retval COMPONENT_ERROR in case of failure
00274  */
00275 DrvStatusTypeDef BSP_TEMPERATURE_IsCombo(void *handle, uint8_t *status)
00276 {
00277   DrvContextTypeDef *ctx = (DrvContextTypeDef *)handle;
00278 
00279   if (ctx == NULL)
00280   {
00281     return COMPONENT_ERROR;
00282   }
00283 
00284   if (status == NULL)
00285   {
00286     return COMPONENT_ERROR;
00287   }
00288 
00289   *status = ctx->isCombo;
00290 
00291   return COMPONENT_OK;
00292 }
00293 
00294 
00295 /**
00296  * @brief Get the temperature sensor instance
00297  * @param handle the device handle
00298  * @param instance the pointer to the device instance
00299  * @retval COMPONENT_OK in case of success
00300  * @retval COMPONENT_ERROR in case of failure
00301  */
00302 DrvStatusTypeDef BSP_TEMPERATURE_Get_Instance(void *handle, uint8_t *instance)
00303 {
00304   DrvContextTypeDef *ctx = (DrvContextTypeDef *)handle;
00305 
00306   if (ctx == NULL)
00307   {
00308     return COMPONENT_ERROR;
00309   }
00310 
00311   if (instance == NULL)
00312   {
00313     return COMPONENT_ERROR;
00314   }
00315 
00316   *instance = ctx->instance;
00317 
00318   return COMPONENT_OK;
00319 }
00320 
00321 
00322 
00323 /**
00324  * @brief Get the WHO_AM_I ID of the temperature sensor
00325  * @param handle the device handle
00326  * @param who_am_i pointer to the value of WHO_AM_I register
00327  * @retval COMPONENT_OK in case of success
00328  * @retval COMPONENT_ERROR in case of failure
00329  */
00330 DrvStatusTypeDef BSP_TEMPERATURE_Get_WhoAmI(void *handle, uint8_t *who_am_i)
00331 {
00332 
00333   DrvContextTypeDef *ctx = (DrvContextTypeDef *)handle;
00334   TEMPERATURE_Drv_t *driver = NULL;
00335 
00336   if (ctx == NULL)
00337   {
00338     return COMPONENT_ERROR;
00339   }
00340 
00341   driver = (TEMPERATURE_Drv_t *)ctx->pVTable;
00342 
00343   if (who_am_i == NULL)
00344   {
00345     return COMPONENT_ERROR;
00346   }
00347   if (driver->Get_WhoAmI == NULL)
00348   {
00349     return COMPONENT_ERROR;
00350   }
00351   if (driver->Get_WhoAmI(ctx, who_am_i) == COMPONENT_ERROR)
00352   {
00353     return COMPONENT_ERROR;
00354   }
00355 
00356   return COMPONENT_OK;
00357 }
00358 
00359 
00360 /**
00361  * @brief Check the WHO_AM_I ID of the temperature sensor
00362  * @param handle the device handle
00363  * @retval COMPONENT_OK in case of success
00364  * @retval COMPONENT_ERROR in case of failure
00365  */
00366 DrvStatusTypeDef BSP_TEMPERATURE_Check_WhoAmI(void *handle)
00367 {
00368 
00369   DrvContextTypeDef *ctx = (DrvContextTypeDef *)handle;
00370   TEMPERATURE_Drv_t *driver = NULL;
00371 
00372   if (ctx == NULL)
00373   {
00374     return COMPONENT_ERROR;
00375   }
00376 
00377   driver = (TEMPERATURE_Drv_t *)ctx->pVTable;
00378 
00379   if (driver->Check_WhoAmI == NULL)
00380   {
00381     return COMPONENT_ERROR;
00382   }
00383   if (driver->Check_WhoAmI(ctx) == COMPONENT_ERROR)
00384   {
00385     return COMPONENT_ERROR;
00386   }
00387 
00388   return COMPONENT_OK;
00389 }
00390 
00391 
00392 /**
00393  * @brief Get the temperature value
00394  * @param handle the device handle
00395  * @param temperature pointer where the value is written [C]
00396  * @retval COMPONENT_OK in case of success
00397  * @retval COMPONENT_ERROR in case of failure
00398  */
00399 DrvStatusTypeDef BSP_TEMPERATURE_Get_Temp(void *handle, float *temperature)
00400 {
00401 
00402   DrvContextTypeDef *ctx = (DrvContextTypeDef *)handle;
00403   TEMPERATURE_Drv_t *driver = NULL;
00404 
00405   if (ctx == NULL)
00406   {
00407     return COMPONENT_ERROR;
00408   }
00409 
00410   driver = (TEMPERATURE_Drv_t *)ctx->pVTable;
00411 
00412   if (temperature == NULL)
00413   {
00414     return COMPONENT_ERROR;
00415   }
00416   if (driver->Get_Temp == NULL)
00417   {
00418     return COMPONENT_ERROR;
00419   }
00420   if (driver->Get_Temp(ctx, temperature) == COMPONENT_ERROR)
00421   {
00422     return COMPONENT_ERROR;
00423   }
00424 
00425   return COMPONENT_OK;
00426 }
00427 
00428 
00429 /**
00430  * @brief Get the temperature sensor output data rate
00431  * @param handle the device handle
00432  * @param odr pointer where the output data rate is written
00433  * @retval COMPONENT_OK in case of success
00434  * @retval COMPONENT_ERROR in case of failure
00435  */
00436 DrvStatusTypeDef BSP_TEMPERATURE_Get_ODR(void *handle, float *odr)
00437 {
00438 
00439   DrvContextTypeDef *ctx = (DrvContextTypeDef *)handle;
00440   TEMPERATURE_Drv_t *driver = NULL;
00441 
00442   if (ctx == NULL)
00443   {
00444     return COMPONENT_ERROR;
00445   }
00446 
00447   driver = (TEMPERATURE_Drv_t *)ctx->pVTable;
00448 
00449   if (odr == NULL)
00450   {
00451     return COMPONENT_ERROR;
00452   }
00453   if (driver->Get_ODR == NULL)
00454   {
00455     return COMPONENT_ERROR;
00456   }
00457   if (driver->Get_ODR(ctx, odr) == COMPONENT_ERROR)
00458   {
00459     return COMPONENT_ERROR;
00460   }
00461 
00462   return COMPONENT_OK;
00463 }
00464 
00465 
00466 /**
00467  * @brief Set the temperature sensor output data rate
00468  * @param handle the device handle
00469  * @param odr the functional output data rate to be set
00470  * @retval COMPONENT_OK in case of success
00471  * @retval COMPONENT_ERROR in case of failure
00472  */
00473 DrvStatusTypeDef BSP_TEMPERATURE_Set_ODR(void *handle, SensorOdr_t odr)
00474 {
00475 
00476   DrvContextTypeDef *ctx = (DrvContextTypeDef *)handle;
00477   TEMPERATURE_Drv_t *driver = NULL;
00478 
00479   if (ctx == NULL)
00480   {
00481     return COMPONENT_ERROR;
00482   }
00483 
00484   driver = (TEMPERATURE_Drv_t *)ctx->pVTable;
00485 
00486   if (driver->Set_ODR == NULL)
00487   {
00488     return COMPONENT_ERROR;
00489   }
00490   if (driver->Set_ODR(ctx, odr) == COMPONENT_ERROR)
00491   {
00492     return COMPONENT_ERROR;
00493   }
00494 
00495   return COMPONENT_OK;
00496 }
00497 
00498 
00499 /**
00500  * @brief Set the temperature sensor output data rate
00501  * @param handle the device handle
00502  * @param odr the output data rate value to be set
00503  * @retval COMPONENT_OK in case of success
00504  * @retval COMPONENT_ERROR in case of failure
00505  */
00506 DrvStatusTypeDef BSP_TEMPERATURE_Set_ODR_Value(void *handle, float odr)
00507 {
00508 
00509   DrvContextTypeDef *ctx = (DrvContextTypeDef *)handle;
00510   TEMPERATURE_Drv_t *driver = NULL;
00511 
00512   if (ctx == NULL)
00513   {
00514     return COMPONENT_ERROR;
00515   }
00516 
00517   driver = (TEMPERATURE_Drv_t *)ctx->pVTable;
00518 
00519   if (driver->Set_ODR_Value == NULL)
00520   {
00521     return COMPONENT_ERROR;
00522   }
00523   if (driver->Set_ODR_Value(ctx, odr) == COMPONENT_ERROR)
00524   {
00525     return COMPONENT_ERROR;
00526   }
00527 
00528   return COMPONENT_OK;
00529 }
00530 
00531 
00532 
00533 /**
00534  * @brief Read the data from register
00535  * @param handle the device handle
00536  * @param reg register address
00537  * @param data register data
00538  * @retval COMPONENT_OK in case of success
00539  * @retval COMPONENT_ERROR in case of failure
00540  */
00541 DrvStatusTypeDef BSP_TEMPERATURE_Read_Reg(void *handle, uint8_t reg, uint8_t *data)
00542 {
00543 
00544   DrvContextTypeDef *ctx = (DrvContextTypeDef *)handle;
00545   TEMPERATURE_Drv_t *driver = NULL;
00546 
00547   if (ctx == NULL)
00548   {
00549     return COMPONENT_ERROR;
00550   }
00551 
00552   driver = (TEMPERATURE_Drv_t *)ctx->pVTable;
00553 
00554   if (data == NULL)
00555   {
00556     return COMPONENT_ERROR;
00557   }
00558 
00559   if (driver->Read_Reg == NULL)
00560   {
00561     return COMPONENT_ERROR;
00562   }
00563 
00564   if (driver->Read_Reg(ctx, reg, data) == COMPONENT_ERROR)
00565   {
00566     return COMPONENT_ERROR;
00567   }
00568 
00569   return COMPONENT_OK;
00570 }
00571 
00572 
00573 
00574 /**
00575  * @brief Write the data to register
00576  * @param handle the device handle
00577  * @param reg register address
00578  * @param data register data
00579  * @retval COMPONENT_OK in case of success
00580  * @retval COMPONENT_ERROR in case of failure
00581  */
00582 DrvStatusTypeDef BSP_TEMPERATURE_Write_Reg(void *handle, uint8_t reg, uint8_t data)
00583 {
00584 
00585   DrvContextTypeDef *ctx = (DrvContextTypeDef *)handle;
00586   TEMPERATURE_Drv_t *driver = NULL;
00587 
00588   if (ctx == NULL)
00589   {
00590     return COMPONENT_ERROR;
00591   }
00592 
00593   driver = (TEMPERATURE_Drv_t *)ctx->pVTable;
00594 
00595   if (driver->Write_Reg == NULL)
00596   {
00597     return COMPONENT_ERROR;
00598   }
00599 
00600   if (driver->Write_Reg(ctx, reg, data) == COMPONENT_ERROR)
00601   {
00602     return COMPONENT_ERROR;
00603   }
00604 
00605   return COMPONENT_OK;
00606 }
00607 
00608 
00609 
00610 /**
00611  * @brief Get temperature data ready status
00612  * @param handle the device handle
00613  * @param status the data ready status
00614  * @retval COMPONENT_OK in case of success
00615  * @retval COMPONENT_ERROR in case of failure
00616  */
00617 DrvStatusTypeDef BSP_TEMPERATURE_Get_DRDY_Status(void *handle, uint8_t *status)
00618 {
00619 
00620   DrvContextTypeDef *ctx = (DrvContextTypeDef *)handle;
00621   TEMPERATURE_Drv_t *driver = NULL;
00622 
00623   if (ctx == NULL)
00624   {
00625     return COMPONENT_ERROR;
00626   }
00627 
00628   driver = (TEMPERATURE_Drv_t *)ctx->pVTable;
00629 
00630   if (driver->Get_DRDY_Status == NULL)
00631   {
00632     return COMPONENT_ERROR;
00633   }
00634 
00635   if (driver->Get_DRDY_Status(ctx, status) == COMPONENT_ERROR)
00636   {
00637     return COMPONENT_ERROR;
00638   }
00639 
00640   return COMPONENT_OK;
00641 }
00642 
00643 #if 0
00644 /**
00645  * @brief Get FIFO THR status (available only for LPS22HB sensor)
00646  * @param handle the device handle
00647  * @param *status FIFO THR status
00648  * @retval COMPONENT_OK in case of success
00649  * @retval COMPONENT_ERROR in case of failure
00650  */
00651 DrvStatusTypeDef BSP_TEMPERATURE_FIFO_Get_Fth_Status_Ext(void *handle, uint8_t *status)
00652 {
00653   DrvContextTypeDef *ctx = (DrvContextTypeDef *)handle;
00654 
00655   if (ctx == NULL)
00656   {
00657     return COMPONENT_ERROR;
00658   }
00659 
00660   if (ctx->pExtVTable == NULL)
00661   {
00662     return COMPONENT_ERROR;
00663   }
00664 
00665   if (status == NULL)
00666   {
00667     return COMPONENT_ERROR;
00668   }
00669 
00670   /* At the moment this feature is only implemented for LPS22HB */
00671   if (ctx->who_am_i == LPS22HB_WHO_AM_I_VAL)
00672   {
00673     LPS22HB_T_ExtDrv_t *extDriver = (LPS22HB_T_ExtDrv_t *)ctx->pExtVTable;
00674 
00675     if (extDriver->FIFO_Get_Fth_Status == NULL)
00676     {
00677       return COMPONENT_ERROR;
00678     }
00679 
00680     else
00681     {
00682       return extDriver->FIFO_Get_Fth_Status(ctx, status);
00683     }
00684   }
00685 
00686   else
00687   {
00688     return COMPONENT_ERROR;
00689   }
00690 }
00691 
00692 /**
00693  * @brief Get FIFO FULL status (available only for LPS22HB sensor)
00694  * @param handle the device handle
00695  * @param *status FIFO FULL status
00696  * @retval COMPONENT_OK in case of success
00697  * @retval COMPONENT_ERROR in case of failure
00698  */
00699 DrvStatusTypeDef BSP_TEMPERATURE_FIFO_Get_Full_Status_Ext(void *handle, uint8_t *status)
00700 {
00701 
00702   DrvContextTypeDef *ctx = (DrvContextTypeDef *)handle;
00703 
00704   if (ctx == NULL)
00705   {
00706     return COMPONENT_ERROR;
00707   }
00708 
00709   if (ctx->pExtVTable == NULL)
00710   {
00711     return COMPONENT_ERROR;
00712   }
00713 
00714   if (status == NULL)
00715   {
00716     return COMPONENT_ERROR;
00717   }
00718 
00719   /* At the moment this feature is only implemented for LPS22HB */
00720   if (ctx->who_am_i == LPS22HB_WHO_AM_I_VAL)
00721   {
00722     LPS22HB_T_ExtDrv_t *extDriver = (LPS22HB_T_ExtDrv_t *)ctx->pExtVTable;
00723 
00724     if (extDriver->FIFO_Get_Full_Status == NULL)
00725     {
00726       return COMPONENT_ERROR;
00727     }
00728 
00729     else
00730     {
00731       return extDriver->FIFO_Get_Full_Status(ctx, status);
00732     }
00733   }
00734 
00735   else
00736   {
00737     return COMPONENT_ERROR;
00738   }
00739 }
00740 
00741 /**
00742  * @brief Get FIFO OVR status (available only for LPS22HB sensor)
00743  * @param handle the device handle
00744  * @param *status FIFO OVR status
00745  * @retval COMPONENT_OK in case of success
00746  * @retval COMPONENT_ERROR in case of failure
00747  */
00748 DrvStatusTypeDef BSP_TEMPERATURE_FIFO_Get_Ovr_Status_Ext(void *handle, uint8_t *status)
00749 {
00750 
00751   DrvContextTypeDef *ctx = (DrvContextTypeDef *)handle;
00752 
00753   if (ctx == NULL)
00754   {
00755     return COMPONENT_ERROR;
00756   }
00757 
00758   if (ctx->pExtVTable == NULL)
00759   {
00760     return COMPONENT_ERROR;
00761   }
00762 
00763   if (status == NULL)
00764   {
00765     return COMPONENT_ERROR;
00766   }
00767 
00768   /* At the moment this feature is only implemented for LPS22HB */
00769   if (ctx->who_am_i == LPS22HB_WHO_AM_I_VAL)
00770   {
00771     LPS22HB_T_ExtDrv_t *extDriver = (LPS22HB_T_ExtDrv_t *)ctx->pExtVTable;
00772 
00773     if (extDriver->FIFO_Get_Ovr_Status == NULL)
00774     {
00775       return COMPONENT_ERROR;
00776     }
00777 
00778     else
00779     {
00780       return extDriver->FIFO_Get_Ovr_Status(ctx, status);
00781     }
00782   }
00783 
00784   else
00785   {
00786     return COMPONENT_ERROR;
00787   }
00788 }
00789 
00790 /**
00791  * @brief Get FIFO data (available only for LPS22HB sensor)
00792  * @param handle the device handle
00793  * @param *pressure pointer to FIFO pressure data
00794  * @param *temperature pointer to FIFO temperature data
00795  * @retval COMPONENT_OK in case of success
00796  * @retval COMPONENT_ERROR in case of failure
00797  */
00798 DrvStatusTypeDef BSP_TEMPERATURE_FIFO_Get_Data_Ext(void *handle, float *pressure, float *temperature)
00799 {
00800 
00801   DrvContextTypeDef *ctx = (DrvContextTypeDef *)handle;
00802 
00803   if (ctx == NULL)
00804   {
00805     return COMPONENT_ERROR;
00806   }
00807 
00808   if (ctx->pExtVTable == NULL)
00809   {
00810     return COMPONENT_ERROR;
00811   }
00812 
00813   if (pressure == NULL || temperature == NULL)
00814   {
00815     return COMPONENT_ERROR;
00816   }
00817 
00818   /* At the moment this feature is only implemented for LPS22HB */
00819   if (ctx->who_am_i == LPS22HB_WHO_AM_I_VAL)
00820   {
00821     LPS22HB_T_ExtDrv_t *extDriver = (LPS22HB_T_ExtDrv_t *)ctx->pExtVTable;
00822 
00823     if (extDriver->FIFO_Get_Data == NULL)
00824     {
00825       return COMPONENT_ERROR;
00826     }
00827 
00828     else
00829     {
00830       return extDriver->FIFO_Get_Data(ctx, pressure, temperature);
00831     }
00832   }
00833 
00834   else
00835   {
00836     return COMPONENT_ERROR;
00837   }
00838 }
00839 
00840 /**
00841  * @brief Get number of unread FIFO samples (available only for LPS22HB sensor)
00842  * @param handle the device handle
00843  * @param *nSamples Number of unread FIFO samples
00844  * @retval COMPONENT_OK in case of success
00845  * @retval COMPONENT_ERROR in case of failure
00846  */
00847 DrvStatusTypeDef BSP_TEMPERATURE_FIFO_Get_Num_Of_Samples_Ext(void *handle, uint8_t *nSamples)
00848 {
00849 
00850   DrvContextTypeDef *ctx = (DrvContextTypeDef *)handle;
00851 
00852   if (ctx == NULL)
00853   {
00854     return COMPONENT_ERROR;
00855   }
00856 
00857   if (ctx->pExtVTable == NULL)
00858   {
00859     return COMPONENT_ERROR;
00860   }
00861 
00862   if (nSamples == NULL)
00863   {
00864     return COMPONENT_ERROR;
00865   }
00866 
00867   /* At the moment this feature is only implemented for LPS22HB */
00868   if (ctx->who_am_i == LPS22HB_WHO_AM_I_VAL)
00869   {
00870     LPS22HB_T_ExtDrv_t *extDriver = (LPS22HB_T_ExtDrv_t *)ctx->pExtVTable;
00871 
00872     if (extDriver->FIFO_Get_Num_Of_Samples == NULL)
00873     {
00874       return COMPONENT_ERROR;
00875     }
00876 
00877     else
00878     {
00879       return extDriver->FIFO_Get_Num_Of_Samples(ctx, nSamples);
00880     }
00881   }
00882 
00883   else
00884   {
00885     return COMPONENT_ERROR;
00886   }
00887 }
00888 
00889 /**
00890  * @brief Set FIFO mode (available only for LPS22HB sensor)
00891  * @param handle the device handle
00892  * @param mode FIFO mode
00893  * @retval COMPONENT_OK in case of success
00894  * @retval COMPONENT_ERROR in case of failure
00895  */
00896 DrvStatusTypeDef BSP_TEMPERATURE_FIFO_Set_Mode_Ext(void *handle, uint8_t mode)
00897 {
00898 
00899   DrvContextTypeDef *ctx = (DrvContextTypeDef *)handle;
00900 
00901   if (ctx == NULL)
00902   {
00903     return COMPONENT_ERROR;
00904   }
00905 
00906   if (ctx->pExtVTable == NULL)
00907   {
00908     return COMPONENT_ERROR;
00909   }
00910 
00911   /* At the moment this feature is only implemented for LPS22HB */
00912   if (ctx->who_am_i == LPS22HB_WHO_AM_I_VAL)
00913   {
00914     LPS22HB_T_ExtDrv_t *extDriver = (LPS22HB_T_ExtDrv_t *)ctx->pExtVTable;
00915 
00916     if (extDriver->FIFO_Set_Mode == NULL)
00917     {
00918       return COMPONENT_ERROR;
00919     }
00920 
00921     else
00922     {
00923       return extDriver->FIFO_Set_Mode(ctx, mode);
00924     }
00925   }
00926 
00927   else
00928   {
00929     return COMPONENT_ERROR;
00930   }
00931 }
00932 
00933 /**
00934  * @brief Set FIFO interrupt (available only for LPS22HB sensor)
00935  * @param handle the device handle
00936  * @param interrupt FIFO interrupt
00937  * @retval COMPONENT_OK in case of success
00938  * @retval COMPONENT_ERROR in case of failure
00939  */
00940 DrvStatusTypeDef BSP_TEMPERATURE_FIFO_Set_Interrupt_Ext(void *handle, uint8_t interrupt)
00941 {
00942 
00943   DrvContextTypeDef *ctx = (DrvContextTypeDef *)handle;
00944 
00945   if (ctx == NULL)
00946   {
00947     return COMPONENT_ERROR;
00948   }
00949 
00950   if (ctx->pExtVTable == NULL)
00951   {
00952     return COMPONENT_ERROR;
00953   }
00954 
00955   /* At the moment this feature is only implemented for LPS22HB */
00956   if (ctx->who_am_i == LPS22HB_WHO_AM_I_VAL)
00957   {
00958     LPS22HB_T_ExtDrv_t *extDriver = (LPS22HB_T_ExtDrv_t *)ctx->pExtVTable;
00959 
00960     if (extDriver->FIFO_Set_Interrupt == NULL)
00961     {
00962       return COMPONENT_ERROR;
00963     }
00964 
00965     else
00966     {
00967       return extDriver->FIFO_Set_Interrupt(ctx, interrupt);
00968     }
00969   }
00970 
00971   else
00972   {
00973     return COMPONENT_ERROR;
00974   }
00975 }
00976 
00977 /**
00978  * @brief Set FIFO interrupt (available only for LPS22HB sensor)
00979  * @param handle the device handle
00980  * @param interrupt FIFO interrupt
00981  * @retval COMPONENT_OK in case of success
00982  * @retval COMPONENT_ERROR in case of failure
00983  */
00984 DrvStatusTypeDef BSP_TEMPERATURE_FIFO_Reset_Interrupt_Ext(void *handle, uint8_t interrupt)
00985 {
00986 
00987   DrvContextTypeDef *ctx = (DrvContextTypeDef *)handle;
00988 
00989   if (ctx == NULL)
00990   {
00991     return COMPONENT_ERROR;
00992   }
00993 
00994   if (ctx->pExtVTable == NULL)
00995   {
00996     return COMPONENT_ERROR;
00997   }
00998 
00999   /* At the moment this feature is only implemented for LPS22HB */
01000   if (ctx->who_am_i == LPS22HB_WHO_AM_I_VAL)
01001   {
01002     LPS22HB_T_ExtDrv_t *extDriver = (LPS22HB_T_ExtDrv_t *)ctx->pExtVTable;
01003 
01004     if (extDriver->FIFO_Reset_Interrupt == NULL)
01005     {
01006       return COMPONENT_ERROR;
01007     }
01008 
01009     else
01010     {
01011       return extDriver->FIFO_Reset_Interrupt(ctx, interrupt);
01012     }
01013   }
01014 
01015   else
01016   {
01017     return COMPONENT_ERROR;
01018   }
01019 }
01020 
01021 /**
01022  * @brief Set FIFO watermark (available only for LPS22HB sensor)
01023  * @param handle the device handle
01024  * @param watermark FIFO watermark
01025  * @retval COMPONENT_OK in case of success
01026  * @retval COMPONENT_ERROR in case of failure
01027  */
01028 DrvStatusTypeDef BSP_TEMPERATURE_FIFO_Set_Watermark_Level_Ext(void *handle, uint8_t watermark)
01029 {
01030 
01031   DrvContextTypeDef *ctx = (DrvContextTypeDef *)handle;
01032 
01033   if (ctx == NULL)
01034   {
01035     return COMPONENT_ERROR;
01036   }
01037 
01038   if (ctx->pExtVTable == NULL)
01039   {
01040     return COMPONENT_ERROR;
01041   }
01042 
01043   /* At the moment this feature is only implemented for LPS22HB */
01044   if (ctx->who_am_i == LPS22HB_WHO_AM_I_VAL)
01045   {
01046     LPS22HB_T_ExtDrv_t *extDriver = (LPS22HB_T_ExtDrv_t *)ctx->pExtVTable;
01047 
01048     if (extDriver->FIFO_Set_Watermark_Level == NULL)
01049     {
01050       return COMPONENT_ERROR;
01051     }
01052 
01053     else
01054     {
01055       return extDriver->FIFO_Set_Watermark_Level(ctx, watermark);
01056     }
01057   }
01058 
01059   else
01060   {
01061     return COMPONENT_ERROR;
01062   }
01063 }
01064 
01065 /**
01066  * @brief Set FIFO to stop on FTH (available only for LPS22HB sensor)
01067  * @param handle the device handle
01068  * @param status enable or disable stopping on FTH interrupt
01069  * @retval COMPONENT_OK in case of success
01070  * @retval COMPONENT_ERROR in case of failure
01071  */
01072 DrvStatusTypeDef BSP_TEMPERATURE_FIFO_Stop_On_Fth_Ext(void *handle, uint8_t status)
01073 {
01074 
01075   DrvContextTypeDef *ctx = (DrvContextTypeDef *)handle;
01076 
01077   if (ctx == NULL)
01078   {
01079     return COMPONENT_ERROR;
01080   }
01081 
01082   if (ctx->pExtVTable == NULL)
01083   {
01084     return COMPONENT_ERROR;
01085   }
01086 
01087   /* At the moment this feature is only implemented for LPS22HB */
01088   if (ctx->who_am_i == LPS22HB_WHO_AM_I_VAL)
01089   {
01090     LPS22HB_T_ExtDrv_t *extDriver = (LPS22HB_T_ExtDrv_t *)ctx->pExtVTable;
01091 
01092     if (extDriver->FIFO_Stop_On_Fth == NULL)
01093     {
01094       return COMPONENT_ERROR;
01095     }
01096 
01097     else
01098     {
01099       return extDriver->FIFO_Stop_On_Fth(ctx, status);
01100     }
01101   }
01102 
01103   else
01104   {
01105     return COMPONENT_ERROR;
01106   }
01107 }
01108 
01109 /**
01110  * @brief FIFO usage (available only for LPS22HB sensor)
01111  * @param handle the device handle
01112  * @param status enable or disable FIFO
01113  * @retval COMPONENT_OK in case of success
01114  * @retval COMPONENT_ERROR in case of failure
01115  */
01116 DrvStatusTypeDef BSP_TEMPERATURE_FIFO_Usage_Ext(void *handle, uint8_t status)
01117 {
01118 
01119   DrvContextTypeDef *ctx = (DrvContextTypeDef *)handle;
01120 
01121   if (ctx == NULL)
01122   {
01123     return COMPONENT_ERROR;
01124   }
01125 
01126   if (ctx->pExtVTable == NULL)
01127   {
01128     return COMPONENT_ERROR;
01129   }
01130 
01131   /* At the moment this feature is only implemented for LPS22HB */
01132   if (ctx->who_am_i == LPS22HB_WHO_AM_I_VAL)
01133   {
01134     LPS22HB_T_ExtDrv_t *extDriver = (LPS22HB_T_ExtDrv_t *)ctx->pExtVTable;
01135 
01136     if (extDriver->FIFO_Usage == NULL)
01137     {
01138       return COMPONENT_ERROR;
01139     }
01140 
01141     else
01142     {
01143       return extDriver->FIFO_Usage(ctx, status);
01144     }
01145   }
01146 
01147   else
01148   {
01149     return COMPONENT_ERROR;
01150   }
01151 }
01152 #endif /* if 0 */
01153 
01154 /**
01155  * @}
01156  */
01157 
01158 /** @addtogroup X_NUCLEO_IKS01A2_TEMPERATURE_Private_Functions Private functions
01159  * @{
01160  */
01161 
01162 /**
01163  * @brief Initialize LPS22HH temperature sensor
01164  * @param handle the device handle
01165  * @retval COMPONENT_OK in case of success
01166  * @retval COMPONENT_ERROR in case of failure
01167  */
01168 static DrvStatusTypeDef BSP_LPS22HH_TEMPERATURE_Init(void **handle)
01169 {
01170   TEMPERATURE_Drv_t *driver = NULL;
01171 
01172 
01173   if (TEMPERATURE_SensorHandle[ LPS22HH_T_0 ].isInitialized == 1)
01174   {
01175     /* We have reached the max num of instance for this component */
01176     return COMPONENT_ERROR;
01177   }
01178 
01179   if (Sensor_IO_Init() == COMPONENT_ERROR)
01180   {
01181     return COMPONENT_ERROR;
01182   }
01183 
01184   /* Setup sensor handle. */
01185   TEMPERATURE_SensorHandle[ LPS22HH_T_0 ].who_am_i      = LPS22HH_ID;
01186   TEMPERATURE_SensorHandle[ LPS22HH_T_0 ].ifType        = 0; /* I2C interface */
01187   TEMPERATURE_SensorHandle[ LPS22HH_T_0 ].address       = LPS22HH_I2C_ADD_H /* LPS22HH_I2C_ADD_L */;
01188   TEMPERATURE_SensorHandle[ LPS22HH_T_0 ].instance      = LPS22HH_T_0;
01189   TEMPERATURE_SensorHandle[ LPS22HH_T_0 ].isInitialized = 0;
01190   TEMPERATURE_SensorHandle[ LPS22HH_T_0 ].isEnabled     = 0;
01191   TEMPERATURE_SensorHandle[ LPS22HH_T_0 ].isCombo       = 1;
01192   TEMPERATURE_SensorHandle[ LPS22HH_T_0 ].pData         = (void *)&TEMPERATURE_Data[ LPS22HH_T_0 ];
01193   TEMPERATURE_SensorHandle[ LPS22HH_T_0 ].pVTable       = (void *)&LPS22HH_T_Drv;
01194   TEMPERATURE_SensorHandle[ LPS22HH_T_0 ].pExtVTable    = 0;
01195 
01196   LPS22HH_T_0_Data.comboData = &LPS22HH_Combo_Data[0];
01197   TEMPERATURE_Data[ LPS22HH_T_0 ].pComponentData = (void *)&LPS22HH_T_0_Data;
01198   TEMPERATURE_Data[ LPS22HH_T_0 ].pExtData       = 0;
01199 
01200   *handle = (void *)&TEMPERATURE_SensorHandle[ LPS22HH_T_0 ];
01201 
01202   driver = (TEMPERATURE_Drv_t *)((DrvContextTypeDef *)(*handle))->pVTable;
01203 
01204   if (driver->Init == NULL)
01205   {
01206     memset((*handle), 0, sizeof(DrvContextTypeDef));
01207     *handle = NULL;
01208     return COMPONENT_ERROR;
01209   }
01210 
01211   if (driver->Init((DrvContextTypeDef *)(*handle)) == COMPONENT_ERROR)
01212   {
01213     memset((*handle), 0, sizeof(DrvContextTypeDef));
01214     *handle = NULL;
01215     return COMPONENT_ERROR;
01216   }
01217 
01218   /* Configure interrupt lines common for all sensors in DIL24 socket */
01219   DIL24_Sensor_IO_ITConfig();
01220 
01221   return COMPONENT_OK;
01222 }
01223 
01224 /**
01225  * @}
01226  */
01227 
01228 /**
01229  * @}
01230  */
01231 
01232 /**
01233  * @}
01234  */
01235 
01236 /**
01237  * @}
01238  */
01239 
01240 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/