hal_thermometer.h 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  1. /*
  2. ChibiOS - Copyright (C) 2006..2018 Giovanni Di Sirio
  3. Licensed under the Apache License, Version 2.0 (the "License");
  4. you may not use this file except in compliance with the License.
  5. You may obtain a copy of the License at
  6. http://www.apache.org/licenses/LICENSE-2.0
  7. Unless required by applicable law or agreed to in writing, software
  8. distributed under the License is distributed on an "AS IS" BASIS,
  9. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. See the License for the specific language governing permissions and
  11. limitations under the License.
  12. */
  13. /**
  14. * @file hal_thermometer.h
  15. * @brief Generic thermometer interface header.
  16. *
  17. * @addtogroup HAL_THERMOMETER
  18. * @{
  19. */
  20. #ifndef HAL_THERMOMETER_H
  21. #define HAL_THERMOMETER_H
  22. #include "hal_sensors.h"
  23. /*===========================================================================*/
  24. /* Driver constants. */
  25. /*===========================================================================*/
  26. /*===========================================================================*/
  27. /* Driver pre-compile time settings. */
  28. /*===========================================================================*/
  29. /*===========================================================================*/
  30. /* Derived constants and error checks. */
  31. /*===========================================================================*/
  32. /*===========================================================================*/
  33. /* Driver data structures and types. */
  34. /*===========================================================================*/
  35. /**
  36. * @brief BaseThermometer specific methods.
  37. */
  38. #define _base_thermometer_methods_alone \
  39. /* Invoke the set bias procedure.*/ \
  40. msg_t (*set_bias)(void *instance, float biases[]); \
  41. /* Remove bias stored data.*/ \
  42. msg_t (*reset_bias)(void *instance); \
  43. /* Invoke the set sensitivity procedure.*/ \
  44. msg_t (*set_sensitivity)(void *instance, float sensitivities[]); \
  45. /* Restore sensitivity stored data to default.*/ \
  46. msg_t (*reset_sensitivity)(void *instance);
  47. /**
  48. * @brief BaseThermometer specific methods with inherited ones.
  49. */
  50. #define _base_thermometer_methods \
  51. _base_sensor_methods \
  52. _base_thermometer_methods_alone
  53. /**
  54. * @brief @p BaseThermometer virtual methods table.
  55. */
  56. struct BaseThermometerVMT {
  57. _base_thermometer_methods
  58. };
  59. /**
  60. * @brief @p BaseThermometer specific data.
  61. */
  62. #define _base_thermometer_data \
  63. _base_sensor_data
  64. /**
  65. * @extends BaseSensor
  66. *
  67. * @brief Base thermometer class.
  68. * @details This class represents a generic thermometer.
  69. */
  70. typedef struct {
  71. /** @brief Virtual Methods Table.*/
  72. const struct BaseThermometerVMT *vmt;
  73. _base_thermometer_data
  74. } BaseThermometer;
  75. /*===========================================================================*/
  76. /* Driver macros. */
  77. /*===========================================================================*/
  78. /**
  79. * @name Macro Functions (BaseThermometer)
  80. * @{
  81. */
  82. /**
  83. * @brief Thermometer get channels number.
  84. *
  85. * @param[in] ip pointer to a @p BaseThermometer class.
  86. * @return The number of channels of the BaseThermometer
  87. *
  88. * @api
  89. */
  90. #define thermometerGetChannelsNumber(ip) \
  91. (ip)->vmt->get_channels_number(ip)
  92. /**
  93. * @brief Thermometer read raw data.
  94. *
  95. * @param[in] ip pointer to a @p BaseThermometer class.
  96. * @param[in] dp pointer to a data array.
  97. *
  98. * @return The operation status.
  99. * @retval MSG_OK if the function succeeded.
  100. * @retval MSG_RESET if one or more errors occurred.
  101. *
  102. * @api
  103. */
  104. #define thermometerReadRaw(ip, dp) \
  105. (ip)->vmt->read_raw(ip, dp)
  106. /**
  107. * @brief Thermometer read cooked data.
  108. *
  109. * @param[in] ip pointer to a @p BaseThermometer class.
  110. * @param[in] dp pointer to a data array.
  111. *
  112. * @return The operation status.
  113. * @retval MSG_OK if the function succeeded.
  114. * @retval MSG_RESET if one or more errors occurred.
  115. *
  116. * @api
  117. */
  118. #define thermometerReadCooked(ip, dp) \
  119. (ip)->vmt->read_cooked(ip, dp)
  120. /**
  121. * @brief Updates thermometer bias data from received buffer.
  122. * @note The bias buffer must have the same length of the
  123. * the thermometer channels number.
  124. *
  125. * @param[in] ip pointer to a @p BaseThermometer class.
  126. * @param[in] bp pointer to a buffer of bias values.
  127. *
  128. * @return The operation status.
  129. * @retval MSG_OK if the function succeeded.
  130. * @retval MSG_RESET if one or more errors occurred.
  131. *
  132. * @api
  133. */
  134. #define thermometerSetBias(ip, bp) \
  135. (ip)->vmt->set_bias(ip, bp)
  136. /**
  137. * @brief Reset thermometer bias data restoring it to zero.
  138. *
  139. * @param[in] ip pointer to a @p BaseThermometer class.
  140. *
  141. * @return The operation status.
  142. * @retval MSG_OK if the function succeeded.
  143. * @retval MSG_RESET if one or more errors occurred.
  144. *
  145. * @api
  146. */
  147. #define thermometerResetBias(ip) \
  148. (ip)->vmt->reset_bias(ip)
  149. /**
  150. * @brief Updates thermometer sensitivity data from received buffer.
  151. * @note The sensitivity buffer must have the same length of the
  152. * the thermometer channels number.
  153. *
  154. * @param[in] ip pointer to a @p BaseThermometer class.
  155. * @param[in] sp pointer to a buffer of sensitivity values.
  156. *
  157. * @return The operation status.
  158. * @retval MSG_OK if the function succeeded.
  159. * @retval MSG_RESET if one or more errors occurred.
  160. *
  161. * @api
  162. */
  163. #define thermometerSetSensitivity(ip, sp) \
  164. (ip)->vmt->set_sensitivity(ip, sp)
  165. /**
  166. * @brief Reset thermometer sensitivity data restoring it to its typical
  167. * value.
  168. *
  169. * @param[in] ip pointer to a @p BaseThermometer class.
  170. *
  171. * @return The operation status.
  172. * @retval MSG_OK if the function succeeded.
  173. * @retval MSG_RESET if one or more errors occurred.
  174. *
  175. * @api
  176. */
  177. #define thermometerResetSensitivity(ip) \
  178. (ip)->vmt->reset_sensitivity(ip)
  179. /** @} */
  180. /*===========================================================================*/
  181. /* External declarations. */
  182. /*===========================================================================*/
  183. #ifdef __cplusplus
  184. extern "C" {
  185. #endif
  186. #ifdef __cplusplus
  187. }
  188. #endif
  189. #endif /* HAL_THERMOMETER_H */
  190. /** @} */