hts221.h 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  1. /**
  2. ******************************************************************************
  3. * @file hts221.h
  4. * @author MEMS Software Solutions Team
  5. * @brief HTS221 header driver file
  6. ******************************************************************************
  7. * @attention
  8. *
  9. * <h2><center>&copy; COPYRIGHT(c) 2018 STMicroelectronics</center></h2>
  10. *
  11. * Redistribution and use in source and binary forms, with or without modification,
  12. * are permitted provided that the following conditions are met:
  13. * 1. Redistributions of source code must retain the above copyright notice,
  14. * this list of conditions and the following disclaimer.
  15. * 2. Redistributions in binary form must reproduce the above copyright notice,
  16. * this list of conditions and the following disclaimer in the documentation
  17. * and/or other materials provided with the distribution.
  18. * 3. Neither the name of STMicroelectronics nor the names of its contributors
  19. * may be used to endorse or promote products derived from this software
  20. * without specific prior written permission.
  21. *
  22. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  23. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  24. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  25. * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
  26. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  27. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  28. * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  29. * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  30. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  31. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  32. *
  33. ******************************************************************************
  34. */
  35. /* Define to prevent recursive inclusion -------------------------------------*/
  36. #ifndef HTS221_H
  37. #define HTS221_H
  38. #ifdef __cplusplus
  39. extern "C"
  40. {
  41. #endif
  42. /* Includes ------------------------------------------------------------------*/
  43. #include "hts221_reg.h"
  44. #include <string.h>
  45. /** @addtogroup BSP BSP
  46. * @{
  47. */
  48. /** @addtogroup Component Component
  49. * @{
  50. */
  51. /** @addtogroup HTS221 HTS221
  52. * @{
  53. */
  54. /** @defgroup HTS221_Exported_Types HTS221 Exported Types
  55. * @{
  56. */
  57. typedef int32_t (*HTS221_Init_Func)(void);
  58. typedef int32_t (*HTS221_DeInit_Func)(void);
  59. typedef int32_t (*HTS221_GetTick_Func)(void);
  60. typedef int32_t (*HTS221_WriteReg_Func)(uint16_t, uint16_t, uint8_t *, uint16_t);
  61. typedef int32_t (*HTS221_ReadReg_Func)(uint16_t, uint16_t, uint8_t *, uint16_t);
  62. typedef struct
  63. {
  64. HTS221_Init_Func Init;
  65. HTS221_DeInit_Func DeInit;
  66. uint32_t BusType; /*0 means I2C, 1 means SPI-3-Wires */
  67. uint8_t Address;
  68. HTS221_WriteReg_Func WriteReg;
  69. HTS221_ReadReg_Func ReadReg;
  70. HTS221_GetTick_Func GetTick;
  71. } HTS221_IO_t;
  72. typedef struct
  73. {
  74. float x0;
  75. float y0;
  76. float x1;
  77. float y1;
  78. } lin_t;
  79. typedef struct
  80. {
  81. HTS221_IO_t IO;
  82. hts221_ctx_t Ctx;
  83. uint8_t is_initialized;
  84. uint8_t hum_is_enabled;
  85. uint8_t temp_is_enabled;
  86. } HTS221_Object_t;
  87. typedef struct
  88. {
  89. uint8_t Temperature;
  90. uint8_t Pressure;
  91. uint8_t Humidity;
  92. uint8_t LowPower;
  93. float HumMaxOdr;
  94. float TempMaxOdr;
  95. float PressMaxOdr;
  96. } HTS221_Capabilities_t;
  97. typedef struct
  98. {
  99. int32_t (*Init)(HTS221_Object_t *);
  100. int32_t (*DeInit)(HTS221_Object_t *);
  101. int32_t (*ReadID)(HTS221_Object_t *, uint8_t *);
  102. int32_t (*GetCapabilities)(HTS221_Object_t *, HTS221_Capabilities_t *);
  103. } HTS221_CommonDrv_t;
  104. typedef struct
  105. {
  106. int32_t (*Enable)(HTS221_Object_t *);
  107. int32_t (*Disable)(HTS221_Object_t *);
  108. int32_t (*GetOutputDataRate)(HTS221_Object_t *, float *);
  109. int32_t (*SetOutputDataRate)(HTS221_Object_t *, float);
  110. int32_t (*GetHumidity)(HTS221_Object_t *, float *);
  111. } HTS221_HUM_Drv_t;
  112. typedef struct
  113. {
  114. int32_t (*Enable)(HTS221_Object_t *);
  115. int32_t (*Disable)(HTS221_Object_t *);
  116. int32_t (*GetOutputDataRate)(HTS221_Object_t *, float *);
  117. int32_t (*SetOutputDataRate)(HTS221_Object_t *, float);
  118. int32_t (*GetTemperature)(HTS221_Object_t *, float *);
  119. } HTS221_TEMP_Drv_t;
  120. /**
  121. * @}
  122. */
  123. /** @defgroup HTS221_Exported_Constants HTS221 Exported Constants
  124. * @{
  125. */
  126. #define HTS221_I2C_BUS 0U
  127. #define HTS221_SPI_3WIRES_BUS 1U
  128. /** HTS221 error codes **/
  129. #define HTS221_OK 0
  130. #define HTS221_ERROR -1
  131. /**
  132. * @}
  133. */
  134. /** @addtogroup HTS221_Exported_Functions HTS221 Exported Functions
  135. * @{
  136. */
  137. int32_t HTS221_RegisterBusIO(HTS221_Object_t *pObj, HTS221_IO_t *pIO);
  138. int32_t HTS221_Init(HTS221_Object_t *pObj);
  139. int32_t HTS221_DeInit(HTS221_Object_t *pObj);
  140. int32_t HTS221_ReadID(HTS221_Object_t *pObj, uint8_t *Id);
  141. int32_t HTS221_GetCapabilities(HTS221_Object_t *pObj, HTS221_Capabilities_t *Capabilities);
  142. int32_t HTS221_Get_Init_Status(HTS221_Object_t *pObj, uint8_t *Status);
  143. int32_t HTS221_HUM_Enable(HTS221_Object_t *pObj);
  144. int32_t HTS221_HUM_Disable(HTS221_Object_t *pObj);
  145. int32_t HTS221_HUM_GetOutputDataRate(HTS221_Object_t *pObj, float *Odr);
  146. int32_t HTS221_HUM_SetOutputDataRate(HTS221_Object_t *pObj, float Odr);
  147. int32_t HTS221_HUM_GetHumidity(HTS221_Object_t *pObj, float *Value);
  148. int32_t HTS221_HUM_Get_DRDY_Status(HTS221_Object_t *pObj, uint8_t *Status);
  149. int32_t HTS221_TEMP_Enable(HTS221_Object_t *pObj);
  150. int32_t HTS221_TEMP_Disable(HTS221_Object_t *pObj);
  151. int32_t HTS221_TEMP_GetOutputDataRate(HTS221_Object_t *pObj, float *Odr);
  152. int32_t HTS221_TEMP_SetOutputDataRate(HTS221_Object_t *pObj, float Odr);
  153. int32_t HTS221_TEMP_GetTemperature(HTS221_Object_t *pObj, float *Value);
  154. int32_t HTS221_TEMP_Get_DRDY_Status(HTS221_Object_t *pObj, uint8_t *Status);
  155. int32_t HTS221_Read_Reg(HTS221_Object_t *pObj, uint8_t Reg, uint8_t *Data);
  156. int32_t HTS221_Write_Reg(HTS221_Object_t *pObj, uint8_t Reg, uint8_t Data);
  157. /**
  158. * @}
  159. */
  160. /** @addtogroup HTS221_Exported_Variables HTS221 Exported Variables
  161. * @{
  162. */
  163. extern HTS221_CommonDrv_t HTS221_COMMON_Driver;
  164. extern HTS221_HUM_Drv_t HTS221_HUM_Driver;
  165. extern HTS221_TEMP_Drv_t HTS221_TEMP_Driver;
  166. /**
  167. * @}
  168. */
  169. #ifdef __cplusplus
  170. }
  171. #endif
  172. #endif
  173. /**
  174. * @}
  175. */
  176. /**
  177. * @}
  178. */
  179. /**
  180. * @}
  181. */
  182. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/