hal_accelerometer.h 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  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_accelerometer.h
  15. * @brief Generic accelerometer interface header.
  16. *
  17. * @addtogroup HAL_ACCELEROMETER
  18. * @{
  19. */
  20. #ifndef HAL_ACCELEROMETER_H
  21. #define HAL_ACCELEROMETER_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 BaseAccelerometer specific methods.
  37. */
  38. #define _base_accelerometer_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 BaseAccelerometer specific methods with inherited ones.
  49. */
  50. #define _base_accelerometer_methods \
  51. _base_sensor_methods \
  52. _base_accelerometer_methods_alone
  53. /**
  54. * @brief @p BaseAccelerometer virtual methods table.
  55. */
  56. struct BaseAccelerometerVMT {
  57. _base_accelerometer_methods
  58. };
  59. /**
  60. * @brief @p BaseAccelerometer specific data.
  61. */
  62. #define _base_accelerometer_data \
  63. _base_sensor_data
  64. /**
  65. * @extends BaseSensor
  66. *
  67. * @brief Base accelerometer class.
  68. * @details This class represents a generic a generic accelerometer.
  69. */
  70. typedef struct {
  71. /** @brief Virtual Methods Table.*/
  72. const struct BaseAccelerometerVMT *vmt;
  73. _base_accelerometer_data
  74. } BaseAccelerometer;
  75. /*===========================================================================*/
  76. /* Driver macros. */
  77. /*===========================================================================*/
  78. /**
  79. * @name Macro Functions (BaseAccelerometer)
  80. * @{
  81. */
  82. /**
  83. * @brief Accelerometer get axes number.
  84. *
  85. * @param[in] ip pointer to a @p BaseAccelerometer class.
  86. * @return The number of axes of the BaseAccelerometer
  87. *
  88. * @api
  89. */
  90. #define accelerometerGetAxesNumber(ip) \
  91. (ip)->vmt->get_channels_number(ip)
  92. /**
  93. * @brief Accelerometer read raw data.
  94. *
  95. * @param[in] ip pointer to a @p BaseAccelerometer 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 accelerometerReadRaw(ip, dp) \
  105. (ip)->vmt->read_raw(ip, dp)
  106. /**
  107. * @brief Accelerometer read cooked data.
  108. *
  109. * @param[in] ip pointer to a @p BaseAccelerometer 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 accelerometerReadCooked(ip, dp) \
  119. (ip)->vmt->read_cooked(ip, dp)
  120. /**
  121. * @brief Updates accelerometer bias data from received buffer.
  122. * @note The bias buffer must have the same length of the
  123. * the accelerometer axes number.
  124. *
  125. *
  126. * @param[in] ip pointer to a @p BaseAccelerometer class.
  127. * @param[in] bp pointer to a buffer of bias values.
  128. *
  129. * @return The operation status.
  130. * @retval MSG_OK if the function succeeded.
  131. * @retval MSG_RESET if one or more errors occurred.
  132. *
  133. * @api
  134. */
  135. #define accelerometerSetBias(ip, bp) \
  136. (ip)->vmt->set_bias(ip, bp)
  137. /**
  138. * @brief Reset accelerometer bias data restoring it to zero.
  139. *
  140. * @param[in] ip pointer to a @p BaseAccelerometer class.
  141. *
  142. * @return The operation status.
  143. * @retval MSG_OK if the function succeeded.
  144. * @retval MSG_RESET if one or more errors occurred.
  145. *
  146. * @api
  147. */
  148. #define accelerometerResetBias(ip) \
  149. (ip)->vmt->reset_bias(ip)
  150. /**
  151. * @brief Updates accelerometer sensitivity data from received buffer.
  152. * @note The sensitivity buffer must have the same length of the
  153. * the accelerometer axes number.
  154. *
  155. * @param[in] ip pointer to a @p BaseAccelerometer class.
  156. * @param[in] sp pointer to a buffer of sensitivity values.
  157. *
  158. * @return The operation status.
  159. * @retval MSG_OK if the function succeeded.
  160. * @retval MSG_RESET if one or more errors occurred.
  161. *
  162. * @api
  163. */
  164. #define accelerometerSetSensitivity(ip, sp) \
  165. (ip)->vmt->set_sensitivity(ip, sp)
  166. /**
  167. * @brief Reset accelerometer sensitivity data restoring it to its typical
  168. * value.
  169. *
  170. * @param[in] ip pointer to a @p BaseAccelerometer class.
  171. *
  172. * @return The operation status.
  173. * @retval MSG_OK if the function succeeded.
  174. * @retval MSG_RESET if one or more errors occurred.
  175. *
  176. * @api
  177. */
  178. #define accelerometerResetSensitivity(ip) \
  179. (ip)->vmt->reset_sensitivity(ip)
  180. /** @} */
  181. /*===========================================================================*/
  182. /* External declarations. */
  183. /*===========================================================================*/
  184. #ifdef __cplusplus
  185. extern "C" {
  186. #endif
  187. #ifdef __cplusplus
  188. }
  189. #endif
  190. #endif /* HAL_ACCELEROMETER_H */
  191. /** @} */