hal_compass.h 6.9 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_compass.h
  15. * @brief Generic compass interface header.
  16. *
  17. * @addtogroup HAL_COMPASS
  18. * @{
  19. */
  20. #ifndef HAL_COMPASS_H
  21. #define HAL_COMPASS_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 BaseCompass specific methods.
  37. */
  38. #define _base_compass_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 BaseCompass specific methods with inherited ones.
  49. */
  50. #define _base_compass_methods \
  51. _base_sensor_methods \
  52. _base_compass_methods_alone
  53. /**
  54. * @brief @p BaseCompass virtual methods table.
  55. */
  56. struct BaseCompassVMT {
  57. _base_compass_methods
  58. };
  59. /**
  60. * @brief @p BaseCompass specific data.
  61. */
  62. #define _base_compass_data \
  63. _base_sensor_data
  64. /**
  65. * @extends BaseSensor
  66. *
  67. * @brief Base compass class.
  68. * @details This class represents a generic compass.
  69. */
  70. typedef struct {
  71. /** @brief Virtual Methods Table.*/
  72. const struct BaseCompassVMT *vmt;
  73. _base_compass_data
  74. } BaseCompass;
  75. /*===========================================================================*/
  76. /* Driver macros. */
  77. /*===========================================================================*/
  78. /**
  79. * @name Macro Functions (BaseCompass)
  80. * @{
  81. */
  82. /**
  83. * @brief Compass get axes number.
  84. *
  85. * @param[in] ip pointer to a @p BaseCompass class.
  86. * @return The number of axes of the BaseCompass
  87. *
  88. * @api
  89. */
  90. #define compassGetAxesNumber(ip) \
  91. (ip)->vmt->get_channels_number(ip)
  92. /**
  93. * @brief Compass read raw data.
  94. *
  95. * @param[in] ip pointer to a @p BaseCompass 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 compassReadRaw(ip, dp) \
  105. (ip)->vmt->read_raw(ip, dp)
  106. /**
  107. * @brief Compass read cooked data.
  108. *
  109. * @param[in] ip pointer to a @p BaseCompass 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 compassReadCooked(ip, dp) \
  119. (ip)->vmt->read_cooked(ip, dp)
  120. /**
  121. * @brief Updates compass bias data from received buffer.
  122. * @note The bias buffer must have the same length of the
  123. * the compass axes number.
  124. *
  125. * @param[in] ip pointer to a @p BaseCompass 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 compassSetBias(ip, bp) \
  135. (ip)->vmt->set_bias(ip, bp)
  136. /**
  137. * @brief Reset compass bias data restoring it to zero.
  138. *
  139. * @param[in] ip pointer to a @p BaseCompass 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 compassResetBias(ip) \
  148. (ip)->vmt->reset_bias(ip)
  149. /**
  150. * @brief Updates compass sensitivity data from received buffer.
  151. * @note The sensitivity buffer must have the same length of the
  152. * the compass axes number.
  153. *
  154. * @param[in] ip pointer to a @p BaseCompass 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 compassSetSensitivity(ip, sp) \
  164. (ip)->vmt->set_sensitivity(ip, sp)
  165. /**
  166. * @brief Reset compass sensitivity data restoring it to its typical
  167. * value.
  168. *
  169. * @param[in] ip pointer to a @p BaseCompass 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 compassResetSensitivity(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_COMPASS_H */
  190. /** @} */