This repository has been archived by the owner on Nov 11, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 102
/
Copy pathu_device.h
334 lines (306 loc) · 14.5 KB
/
u_device.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
/*
* Copyright 2019-2022 u-blox
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef _U_DEVICE_H_
#define _U_DEVICE_H_
/* Only header files representing a direct and unavoidable
* dependency between the API of this module and the API
* of another module should be included here; otherwise
* please keep #includes to your .c files. */
/** \addtogroup device Device
* @{
*/
/** @file
* @brief This is a high-level API for initializing a u-blox device
* (chip or module). These functions are generally used in conjunction
* with those in the network API, see u_network.h for further information.
* These functions are thread-safe.
*/
#ifdef __cplusplus
extern "C" {
#endif
/* ----------------------------------------------------------------
* COMPILE-TIME MACROS
* -------------------------------------------------------------- */
/* ----------------------------------------------------------------
* TYPES
* -------------------------------------------------------------- */
/** Forward declaration for the compiler.
*/
struct uDeviceCfg_t;
/** The u-blox device handle; this is intended to be anonymous,
* the contents should never be referenced by the application.
*/
typedef struct uDeviceCfg_t *uDeviceHandle_t;
/** Device types.
*/
typedef enum {
U_DEVICE_TYPE_NONE,
U_DEVICE_TYPE_CELL,
U_DEVICE_TYPE_GNSS,
U_DEVICE_TYPE_SHORT_RANGE,
U_DEVICE_TYPE_SHORT_RANGE_OPEN_CPU,
U_DEVICE_TYPE_MAX_NUM
} uDeviceType_t;
/** Device transport types.
*/
typedef enum {
U_DEVICE_TRANSPORT_TYPE_NONE,
U_DEVICE_TRANSPORT_TYPE_UART,
U_DEVICE_TRANSPORT_TYPE_I2C,
U_DEVICE_TRANSPORT_TYPE_MAX_NUM
} uDeviceTransportType_t;
/** A version number for the device configuration structure. In
* general you should allow the compiler to initialise any variable
* of this type to zero and ignore it. It is only set to a value
* other than zero when variables in a new and extended version of
* the structure it is a part of are being used, the version number
* being employed by this code to detect that and, more importantly,
* to adopt default values for any new elements when the version
* number is STILL ZERO, maintaining backwards compatibility with
* existing application code. The structure this is a part of will
* include instructions as to when a non-zero version number should
* be set.
*/
typedef int32_t uDeviceVersion_t;
/* Note: try, wherever possible, to use only basic types in the
* configuration structures in this file (i.e. int32_t, const char,
* bool, etc.) since otherwise you'll end up dragging
* device/transport-type-specific headers into every application,
* irrespective of whether that device/transport-type is used there.
* Never use any types that are network-specific here; if you find
* you need to do so there's something wrong, the device should
* know nothing about the network.
*/
/** UART transport configuration.
*/
typedef struct {
uDeviceVersion_t version; /**< Version of this structure; allow your
compiler to initialise this to zero
unless otherwise specified below. */
int32_t uart; /**< The UART HW block to use. */
int32_t baudRate; /**< Uart speed value
Currently only applicable for short-range modules. */
int32_t pinTxd; /**< The output pin that sends UART data to
the module. */
int32_t pinRxd; /**< The input pin that receives UART data from
the module. */
int32_t pinCts; /**< The input pin that the module
will use to indicate that data can be sent
to it; use -1 if there is no such connection. */
int32_t pinRts; /**< The output pin output pin that tells the
module that it can send more UART
data; use -1 if there is no such connection. */
/* This is the end of version 0 of this structure:
should any fields be added to this structure in
future they must be added AFTER this point and
instructions must be given against each one
as to how to set the version field if any of
the new fields are populated. For example,
if int32_t pinMagic were added, the comment
against it might and with the clause"; if this
field is populated then the version field of
this structure must be set to 1 or higher". */
} uDeviceCfgUart_t;
/** I2C transport configuration.
*/
typedef struct {
uDeviceVersion_t version; /**< Version of this structure; allow your
compiler to initialise this to zero
unless otherwise specified below. */
int32_t pinSda; /**< I2C data pin. */
int32_t pinScl; /**< I2C clock pin. */
/* This is the end of version 0 of this structure:
should any fields be added to this structure in
future they must be added AFTER this point and
instructions must be given against each one
as to how to set the version field if any of
the new fields are populated. For example,
if int32_t pinMagic were added, the comment
against it might end with the clause "; if this
field is populated then the version field of
this structure must be set to 1 or higher". */
} uDeviceCfgI2c_t;
/** Cellular device configuration.
*/
typedef struct {
uDeviceVersion_t version; /**< Version of this structure; allow your
compiler to initialise this to zero
unless otherwise specified below. */
int32_t moduleType; /**< The module type that is connected,
see #uCellModuleType_t in u_cell_module_type.h. */
const char *pSimPinCode; /**< The PIN of the SIM. */
int32_t pinEnablePower; /**< The output pin that enables power
to the cellular module; use -1 if
there is no such connection. */
int32_t pinPwrOn; /**< The output pin that is connected to the
PWR_ON pin of the cellular module; use -1
if there is no such connection. */
int32_t pinVInt; /**< The input pin that is connected to the
VINT pin of the cellular module; use -1
if there is no such connection. */
int32_t pinDtrPowerSaving; /**< If you have a GPIO pin of this MCU
connected to the DTR pin of the cellular
module because you intend to use the DTR
pin to tell the module whether it can enter
power-saving or not then put that pin number
here, else set it to -1. */
/* This is the end of version 0 of this structure:
should any fields be added to this structure in
future they must be added AFTER this point and
instructions must be given against each one
as to how to set the version field if any of
the new fields are populated. For example,
if int32_t pinMagic were added, the comment
against it might end with the clause "; if this
field is populated then the version field
of this structure must be set to 1 or higher". */
} uDeviceCfgCell_t;
/** GNSS device configuration.
*/
typedef struct {
uDeviceVersion_t version; /**< Version of this structure; allow your
compiler to initialise this to zero
unless otherwise specified below. */
int32_t moduleType; /**< The module type that is connected,
see #uGnssModuleType_t in
u_gnss_module_type.h. */
int32_t pinEnablePower; /**< The output pin that is used to control
power to the GNSS module; use -1 if
there is no such connection, or if the
connection is via an intermediate
(e.g. cellular) module that does the
controlling (in which case the
gnssAtPinPwr field of the network
configuration structure for GNSS,
#uNetworkCfgGnss_t, should be
populated instead). */
int32_t pinDataReady; /**< The input pin that is used to receive
the Data Ready state of the GNSS module;
this field is present for
forwards-compatibility only; it is
currently ignored. */
bool includeNmea; /**< Set this to true if you are using the
GNSS interface directly and want to be
able to read NMEA commands; ubxlib
does not use NMEA commands (it uses only
ubx protocol commands), and hence this
should normally be left to false to
reduce noise on the interface. */
/* This is the end of version 0 of this structure:
should any fields be added to this structure in
future they must be added AFTER this point and
instructions must be given against each one
as to how to set the version field if any of
the new fields are populated. For example,
if int32_t pinMagic were added, the comment
against it might end with the clause "; if this
field is populated then the version field of
this structure must be set to 1 or higher". */
} uDeviceCfgGnss_t;
/** Short-range device configuration.
*/
typedef struct {
uDeviceVersion_t version; /**< Version of this structure; allow your
compiler to initialise this to zero
unless otherwise specified below. */
int32_t moduleType; /**< The module type that is connected,
see #uShortRangeModuleType_t in
u_short_range_module_type.h. */
/* This is the end of version 0 of this structure:
should any fields be added to this structure in
future they must be added AFTER this point and
instructions must be given against each one
as to how to set the version field if any of
the new fields are populated. For example,
if int32_t pinMagic were added, the comment
against it might end with the clause "; if this
field is populated then the version field of
this structure must be set to 1 or higher". */
} uDeviceCfgShortRange_t;
/** The complete device configuration.
*/
typedef struct uDeviceCfg_t {
uDeviceVersion_t version; /**< Version of this structure; allow your
compiler to initialise this to zero
unless otherwise specified below. */
uDeviceType_t deviceType;
union {
uDeviceCfgCell_t cfgCell;
uDeviceCfgGnss_t cfgGnss;
uDeviceCfgShortRange_t cfgSho;
} deviceCfg;
uDeviceTransportType_t transportType;
union {
uDeviceCfgUart_t cfgUart;
uDeviceCfgI2c_t cfgI2c;
} transportCfg;
/* This is the end of version 0 of this structure:
should any fields be added to this structure in
future they must be added AFTER this point and
instructions must be given against each one
as to how to set the version field if any of
the new fields are populated. For example,
if int32_t magic were added, the comment
against it might end with the clause "; if this
field is populated then the version field of
this structure must be set to 1 or higher". */
} uDeviceCfg_t;
/* ----------------------------------------------------------------
* FUNCTIONS
* -------------------------------------------------------------- */
/** Initialise the device API. If the device API has already
* been initialised this function returns success without doing
* anything.
*
* @return zero on success else negative error code.
*/
int32_t uDeviceInit();
/** Deinitialise the device API. Note that this performs no
* clean-up, it is up to the caller to ensure that all devices
* have been closed with a call to uDeviceClose().
*
* @return zero on success else negative error code.
*/
int32_t uDeviceDeinit();
/** Open a device instance.
*
* @param pDeviceCfg device configuration, cannot be NULL.
* @param[out] pDeviceHandle a place to put the device handle;
* cannot be NULL.
* @return zero on success else a negative error code.
*/
int32_t uDeviceOpen(const uDeviceCfg_t *pDeviceCfg,
uDeviceHandle_t *pDeviceHandle);
/** Close an open device instance.
*
* @param devHandle handle to a previously opened device.
* @param powerOff if true then also power the device off; leave
* this as false to simply logically disconnect
* the device, in which case the device will be
* able to return to a useful state on
* uDeviceOpen() very quickly. Note that Short
* Range devices do not support powering off;
* setting this parameter to true will result in
* an error.
* @return zero on success else a negative error code.
*/
int32_t uDeviceClose(uDeviceHandle_t devHandle, bool powerOff);
#ifdef __cplusplus
}
#endif
/** @}*/
#endif // _U_DEVICE_H_
// End of file