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