ChibiOS/HAL  6.1.0
hal_sensors.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_sensors.h
19  * @brief Generic sensors interface header.
20  *
21  * @addtogroup HAL_SENSORS
22  * @{
23  */
24 
25 #ifndef HAL_SENSORS_H
26 #define HAL_SENSORS_H
27 
28 /*===========================================================================*/
29 /* Driver constants. */
30 /*===========================================================================*/
31 
32 /*===========================================================================*/
33 /* Driver pre-compile time settings. */
34 /*===========================================================================*/
35 
36 /*===========================================================================*/
37 /* Derived constants and error checks. */
38 /*===========================================================================*/
39 
40 /*===========================================================================*/
41 /* Driver data structures and types. */
42 /*===========================================================================*/
43 
44 /**
45  * @brief BaseSensor specific methods.
46  */
47 #define _base_sensor_methods_alone \
48  /* Get number of channels.*/ \
49  size_t (*get_channels_number)(void *instance); \
50  /* Reads the sensor raw data.*/ \
51  msg_t (*read_raw)(void *instance, int32_t axes[]); \
52  /* Reads the sensor returning normalized data.*/ \
53  msg_t (*read_cooked)(void *instance, float axes[]);
54 
55 /**
56  * @brief BaseSensor specific methods with inherited ones.
57  */
58 #define _base_sensor_methods \
59  _base_object_methods \
60  _base_sensor_methods_alone
61 
62 /**
63  * @brief @p BaseSensor virtual methods table.
64  */
65 struct BaseSensorVMT {
67 };
68 
69 /**
70  * @brief @p BaseSensor specific data.
71  * @note It is empty because @p BaseSensor is only an interface
72  * without implementation.
73  */
74 #define _base_sensor_data
76 
77 /**
78  * @extends BaseObject
79  *
80  * @brief Base stream class.
81  * @details This class represents a generic blocking unbuffered sequential
82  * data stream.
83  */
84 typedef struct {
85  /** @brief Virtual Methods Table.*/
86  const struct BaseSensorVMT *vmt;
88 } BaseSensor;
89 
90 /*===========================================================================*/
91 /* Driver macros. */
92 /*===========================================================================*/
93 
94 /**
95  * @name Macro Functions (BaseSensor)
96  * @{
97  */
98 /**
99  * @brief Sensors get channels number.
100  *
101  * @param[in] ip pointer to a @p BaseSensor or derived class.
102  * @return The number of channels of the BaseSensor
103  *
104  * @api
105  */
106 #define sensorGetChannelNumber(ip) (ip)->vmt->get_channels_number(ip)
107 
108 /**
109  * @brief Sensors read raw data.
110  *
111  * @param[in] ip pointer to a @p BaseSensor or derived 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 sensorReadRaw(ip, dp) (ip)->vmt->read_raw(ip, dp)
121 
122 /**
123  * @brief Sensors read cooked data.
124  *
125  * @param[in] ip pointer to a @p BaseSensor or derived class.
126  * @param[in] dp pointer to a data array.
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 sensorReadCooked(ip, dp) (ip)->vmt->read_cooked(ip, dp)
135 /** @} */
136 
137 /*===========================================================================*/
138 /* External declarations. */
139 /*===========================================================================*/
140 
141 #ifdef __cplusplus
142 extern "C" {
143 #endif
144 
145 #ifdef __cplusplus
146 }
147 #endif
148 
149 #endif /* HAL_SENSORS_H */
150 
151 /** @} */
Base stream class.
Definition: hal_sensors.h:84
#define _base_object_data
BaseObject specific data.
Definition: hal_objects.h:49
const struct BaseSensorVMT * vmt
Virtual Methods Table.
Definition: hal_sensors.h:86
#define _base_sensor_methods
BaseSensor specific methods with inherited ones.
Definition: hal_sensors.h:58
#define _base_sensor_data
BaseSensor specific data.
Definition: hal_sensors.h:74
BaseSensor virtual methods table.
Definition: hal_sensors.h:65