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