hal_gyroscope.h 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  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_gyroscope.h
  15. * @brief Generic gyroscope interface header.
  16. *
  17. * @addtogroup HAL_GYROSCOPE
  18. * @{
  19. */
  20. #ifndef HAL_GYROSCOPE_H
  21. #define HAL_GYROSCOPE_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 BaseGyroscope specific methods.
  37. */
  38. #define _base_gyroscope_methods_alone \
  39. /* Invoke the sample bias procedure.*/ \
  40. msg_t (*sample_bias)(void *instance); \
  41. /* Invoke the set bias procedure.*/ \
  42. msg_t (*set_bias)(void *instance, float biases[]); \
  43. /* Remove bias stored data.*/ \
  44. msg_t (*reset_bias)(void *instance); \
  45. /* Invoke the set sensitivity procedure.*/ \
  46. msg_t (*set_sensitivity)(void *instance, float sensitivities[]); \
  47. /* Restore sensitivity stored data to default.*/ \
  48. msg_t (*reset_sensitivity)(void *instance);
  49. /**
  50. * @brief BaseGyroscope specific methods with inherited ones.
  51. */
  52. #define _base_gyroscope_methods \
  53. _base_sensor_methods \
  54. _base_gyroscope_methods_alone
  55. /**
  56. * @brief @p BaseGyroscope virtual methods table.
  57. */
  58. struct BaseGyroscopeVMT {
  59. _base_gyroscope_methods
  60. };
  61. /**
  62. * @brief @p BaseGyroscope specific data.
  63. */
  64. #define _base_gyroscope_data \
  65. _base_sensor_data
  66. /**
  67. * @extends BaseSensor
  68. *
  69. * @brief Base gyroscope class.
  70. * @details This class represents a generic gyroscope.
  71. */
  72. typedef struct {
  73. /** @brief Virtual Methods Table.*/
  74. const struct BaseGyroscopeVMT *vmt;
  75. _base_gyroscope_data
  76. } BaseGyroscope;
  77. /*===========================================================================*/
  78. /* Driver macros. */
  79. /*===========================================================================*/
  80. /**
  81. * @name Macro Functions (BaseGyroscope)
  82. * @{
  83. */
  84. /**
  85. * @brief Gyroscope get axes number.
  86. *
  87. * @param[in] ip pointer to a @p BaseGyroscope class.
  88. * @return The number of axes of the BaseGyroscope
  89. *
  90. * @api
  91. */
  92. #define gyroscopeGetAxesNumber(ip) \
  93. (ip)->vmt->get_channels_number(ip)
  94. /**
  95. * @brief Gyroscope read raw data.
  96. *
  97. * @param[in] ip pointer to a @p BaseGyroscope class.
  98. * @param[in] dp pointer to a data array.
  99. *
  100. * @return The operation status.
  101. * @retval MSG_OK if the function succeeded.
  102. * @retval MSG_RESET if one or more errors occurred.
  103. *
  104. * @api
  105. */
  106. #define gyroscopeReadRaw(ip, dp) \
  107. (ip)->vmt->read_raw(ip, dp)
  108. /**
  109. * @brief Gyroscope read cooked data.
  110. *
  111. * @param[in] ip pointer to a @p BaseGyroscope class.
  112. * @param[in] dp pointer to a data array.
  113. *
  114. * @return The operation status.
  115. * @retval MSG_OK if the function succeeded.
  116. * @retval MSG_RESET if one or more errors occurred.
  117. *
  118. * @api
  119. */
  120. #define gyroscopeReadCooked(ip, dp) \
  121. (ip)->vmt->read_cooked(ip, dp)
  122. /**
  123. * @brief Gyroscope bias sampling procedure.
  124. * @note During this procedure gyroscope must be kept hold in the rest
  125. * position. Sampled bias will be automatically removed after
  126. * calling this procedure.
  127. *
  128. * @param[in] ip pointer to a @p BaseGyroscope class.
  129. *
  130. * @return The operation status.
  131. * @retval MSG_OK if the function succeeded.
  132. * @retval MSG_RESET if one or more errors occurred.
  133. *
  134. * @api
  135. */
  136. #define gyroscopeSampleBias(ip) \
  137. (ip)->vmt->sample_bias(ip)
  138. /**
  139. * @brief Updates gyroscope bias data from received buffer.
  140. * @note The bias buffer must have the same length of the
  141. * the gyroscope axes number.
  142. *
  143. * @param[in] ip pointer to a @p BaseGyroscope class.
  144. * @param[in] bp pointer to a buffer of bias values.
  145. *
  146. * @return The operation status.
  147. * @retval MSG_OK if the function succeeded.
  148. * @retval MSG_RESET if one or more errors occurred.
  149. *
  150. * @api
  151. */
  152. #define gyroscopeSetBias(ip, bp) \
  153. (ip)->vmt->set_bias(ip, bp)
  154. /**
  155. * @brief Reset gyroscope bias data restoring it to zero.
  156. *
  157. * @param[in] ip pointer to a @p BaseGyroscope class.
  158. *
  159. * @return The operation status.
  160. * @retval MSG_OK if the function succeeded.
  161. * @retval MSG_RESET if one or more errors occurred.
  162. *
  163. * @api
  164. */
  165. #define gyroscopeResetBias(ip) \
  166. (ip)->vmt->reset_bias(ip)
  167. /**
  168. * @brief Updates gyroscope sensitivity data from received buffer.
  169. * @note The sensitivity buffer must have the same length of the
  170. * the gyroscope axes number.
  171. *
  172. * @param[in] ip pointer to a @p BaseGyroscope class.
  173. * @param[in] sp pointer to a buffer of sensitivity values.
  174. *
  175. * @return The operation status.
  176. * @retval MSG_OK if the function succeeded.
  177. * @retval MSG_RESET if one or more errors occurred.
  178. *
  179. * @api
  180. */
  181. #define gyroscopeSetSensitivity(ip, sp) \
  182. (ip)->vmt->set_sensitivity(ip, sp)
  183. /**
  184. * @brief Reset gyroscope sensitivity data restoring it to its typical
  185. * value.
  186. *
  187. * @param[in] ip pointer to a @p BaseGyroscope class.
  188. *
  189. * @return The operation status.
  190. * @retval MSG_OK if the function succeeded.
  191. * @retval MSG_RESET if one or more errors occurred.
  192. *
  193. * @api
  194. */
  195. #define gyroscopeResetSensitivity(ip) \
  196. (ip)->vmt->reset_sensitivity(ip)
  197. /** @} */
  198. /*===========================================================================*/
  199. /* External declarations. */
  200. /*===========================================================================*/
  201. #ifdef __cplusplus
  202. extern "C" {
  203. #endif
  204. #ifdef __cplusplus
  205. }
  206. #endif
  207. #endif /* HAL_GYROSCOPE_H */
  208. /** @} */