Statistics
| Branch: | Tag: | Revision:

amiro-lld / drivers / L3G4200D / v1 / alld_L3G4200D.h @ ed9a1bf5

History | View | Annotate | Download (10.879 KB)

1
/*
2
AMiRo-LLD is a compilation of low-level hardware drivers for the Autonomous Mini Robot (AMiRo) platform.
3
Copyright (C) 2016..2020  Thomas Schöpping et al.
4

5
This program is free software: you can redistribute it and/or modify
6
it under the terms of the GNU Lesser General Public License as published by
7
the Free Software Foundation, either version 3 of the License, or
8
(at your option) any later version.
9

10
This program is distributed in the hope that it will be useful,
11
but WITHOUT ANY WARRANTY; without even the implied warranty of
12
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
GNU Lesser General Public License for more details.
14

15
You should have received a copy of the GNU Lesser General Public License
16
along with this program.  If not, see <http://www.gnu.org/licenses/>.
17
*/
18

    
19
/**
20
 * @file    alld_L3G4200D.h
21
 * @brief   Gyroscope macros and structures.
22
 *
23
 * @addtogroup lld_gyroscope
24
 * @{
25
 */
26

    
27
#ifndef AMIROLLD_L3G4200D_H
28
#define AMIROLLD_L3G4200D_H
29

    
30
#include <amiro-lld.h>
31

    
32
/******************************************************************************/
33
/* CONSTANTS                                                                  */
34
/******************************************************************************/
35

    
36
/**
37
 * @brief A rising edge indicates an interrupt.
38
 */
39
#define L3G4200D_LLD_INT_EDGE   APAL_GPIO_EDGE_RISING
40

    
41
/******************************************************************************/
42
/* SETTINGS                                                                   */
43
/******************************************************************************/
44

    
45
/******************************************************************************/
46
/* CHECKS                                                                     */
47
/******************************************************************************/
48

    
49
/******************************************************************************/
50
/* DATA STRUCTURES AND TYPES                                                  */
51
/******************************************************************************/
52

    
53
/**
54
 * @brief The L3G4200D driver struct
55
 */
56
typedef struct {
57
  apalSPIDriver_t* spid;        /**< @brief The SPI Driver */
58
} L3G4200DDriver;
59

    
60
/**
61
 * @brief SPI access modes.
62
 */
63
typedef enum {
64
  L3G4200D_LLD_SPI_MULT  = 0x40u,
65
  L3G4200D_LLD_SPI_READ  = 0x80u,
66
  L3G4200D_LLD_SPI_WRITE = 0x00u,
67
} l3g4200d_lld_SPI_mode_t;
68

    
69
/**
70
 * @brief Registers.
71
 */
72
typedef enum {
73
  L3G4200D_LLD_REGISTER_WHO_AM_I = 0x0F,
74
  L3G4200D_LLD_REGISTER_CTRL_REG1 = 0x20,
75
  L3G4200D_LLD_REGISTER_CTRL_REG2 = 0x21,
76
  L3G4200D_LLD_REGISTER_CTRL_REG3 = 0x22,
77
  L3G4200D_LLD_REGISTER_CTRL_REG4 = 0x23,
78
  L3G4200D_LLD_REGISTER_CTRL_REG5 = 0x24,
79
  L3G4200D_LLD_REGISTER_REFERECE = 0x25,
80
  L3G4200D_LLD_REGISTER_OUT_TEMP = 0x26,
81
  L3G4200D_LLD_REGISTER_STATUS_REG = 0x27,
82
  L3G4200D_LLD_REGISTER_OUT_X_L = 0x28,
83
  L3G4200D_LLD_REGISTER_OUT_X_H = 0x29,
84
  L3G4200D_LLD_REGISTER_OUT_Y_L = 0x2A,
85
  L3G4200D_LLD_REGISTER_OUT_Y_H = 0x2B,
86
  L3G4200D_LLD_REGISTER_OUT_Z_L = 0x2C,
87
  L3G4200D_LLD_REGISTER_OUT_Z_H = 0x2D,
88
  L3G4200D_LLD_REGISTER_FIFO_CTRL_REG = 0x2E,
89
  L3G4200D_LLD_REGISTER_FIFO_SRC_REG = 0x2F,
90
  L3G4200D_LLD_REGISTER_INT1_CFG = 0x30,
91
  L3G4200D_LLD_REGISTER_INT1_SRC = 0x31,
92
  L3G4200D_LLD_REGISTER_INT1_TSH_XH = 0x32,
93
  L3G4200D_LLD_REGISTER_INT1_TSH_XL = 0x33,
94
  L3G4200D_LLD_REGISTER_INT1_TSH_YH = 0x34,
95
  L3G4200D_LLD_REGISTER_INT1_TSH_YL = 0x35,
96
  L3G4200D_LLD_REGISTER_INT1_TSH_ZH = 0x36,
97
  L3G4200D_LLD_REGISTER_INT1_TSH_ZL = 0x37,
98
  L3G4200D_LLD_REGISTER_INT1_DURATION = 0x38,
99
} l3g4200d_lld_register_t;
100

    
101
/**
102
 * @brief WHO_AM_I register constant content.
103
 */
104
typedef enum {
105
  L3G4200D_LLD_WHO_AM_I = 0xD3,
106
} l3g4200d_lld_whoami_t;
107

    
108
/**
109
 * @brief Control register 1 flags.
110
 */
111
typedef enum {
112
  L3G4200D_LLD_DR_100_HZ   = 0x00,
113
  L3G4200D_LLD_DR_200_HZ   = 0x40,
114
  L3G4200D_LLD_DR_400_HZ   = 0x80,
115
  L3G4200D_LLD_DR_800_HZ   = 0xC0,
116
  L3G4200D_LLD_BW_12_5  = 0x00,
117
  L3G4200D_LLD_BW_20    = 0x00,
118
  L3G4200D_LLD_BW_25    = 0x10,
119
  L3G4200D_LLD_BW_30    = 0x00,
120
  L3G4200D_LLD_BW_35    = 0x10,
121
  L3G4200D_LLD_BW_50    = 0x20,
122
  L3G4200D_LLD_BW_70    = 0x30,
123
  L3G4200D_LLD_BW_110   = 0x30,
124
  L3G4200D_LLD_PD  = 0x08,
125
  L3G4200D_LLD_ZEN = 0x04,
126
  L3G4200D_LLD_YEN = 0x02,
127
  L3G4200D_LLD_XEN = 0x01,
128
} l3g4200d_lld_ctrl_reg1_t;
129

    
130
/**
131
 * @brief Control register 2 flags.
132
 */
133
typedef enum {
134
  L3G4200D_LLD_HPM_NORMAL_RST = 0x00,
135
  L3G4200D_LLD_HPM_REFERENCE  = 0x10,
136
  L3G4200D_LLD_HPM_NORMAL     = 0x20,
137
  L3G4200D_LLD_HPM_AUTO_RST   = 0x30,
138
  L3G4200D_LLD_HPCF_2    = 0x00,
139
  L3G4200D_LLD_HPCF_4    = 0x01,
140
  L3G4200D_LLD_HPCF_8    = 0x02,
141
  L3G4200D_LLD_HPCF_16   = 0x03,
142
  L3G4200D_LLD_HPCF_32   = 0x04,
143
  L3G4200D_LLD_HPCF_64   = 0x05,
144
  L3G4200D_LLD_HPCF_128  = 0x06,
145
  L3G4200D_LLD_HPCF_256  = 0x07,
146
  L3G4200D_LLD_HPCF_512  = 0x08,
147
  L3G4200D_LLD_HPCF_1024 = 0x09,
148
} l3g4200d_lld_ctrl_reg2_t;
149

    
150
/**
151
 * @brief Control register 3 flags.
152
 */
153
typedef enum {
154
  L3G4200D_LLD_I1_INT1   = 0x80,
155
  L3G4200D_LLD_I1_BOOT   = 0x40,
156
  L3G4200D_LLD_H_IACTIVE = 0x20,
157
  L3G4200D_LLD_PP_OD     = 0x10,
158
  L3G4200D_LLD_I2_DRDY   = 0x08,
159
  L3G4200D_LLD_I2_WTM    = 0x04,
160
  L3G4200D_LLD_I2_ORUN   = 0x02,
161
  L3G4200D_LLD_I2_EMPTY  = 0x01,
162
} l3g4200d_lld_ctrl_reg3_t;
163

    
164
/**
165
 * @brief Control register 4 flags.
166
 */
167
typedef enum {
168
  L3G4200D_LLD_BDU_CONT    = 0x00,
169
  L3G4200D_LLD_BDU_SINGLE  = 0x80,
170
  L3G4200D_LLD_BLE_MSB     = 0x40,
171
  L3G4200D_LLD_BLE_LSB     = 0x00,
172
  L3G4200D_LLD_FS_250_DPS  = 0x00,
173
  L3G4200D_LLD_FS_500_DPS  = 0x10,
174
  L3G4200D_LLD_FS_2000_DPS = 0x20,
175
  L3G4200D_LLD_ST_SIGN_M   = 0x04,
176
  L3G4200D_LLD_ST_SIGN_P   = 0x00,
177
  L3G4200D_LLD_ST_EN       = 0x02,
178
  L3G4200D_LLD_SIM_3W      = 0x01,
179
  L3G4200D_LLD_SIM_4W      = 0x00,
180
} l3g4200d_lld_ctrl_reg4_t;
181

    
182
/**
183
 * @brief Control register 5 flags.
184
 */
185
typedef enum {
186
  L3G4200D_LLD_BOOT          = 0x80,
187
  L3G4200D_LLD_FIFO_EN       = 0x40,
188
  L3G4200D_LLD_HP_EN         = 0x10,
189
  L3G4200D_LLD_INT1_SEL_NOHP = 0x00,
190
  L3G4200D_LLD_INT1_SEL_HP   = 0x04,
191
  L3G4200D_LLD_INT1_SEL_LP   = 0x08,
192
  L3G4200D_LLD_OUT_SEL_NOHP  = 0x00,
193
  L3G4200D_LLD_OUT_SEL_HP    = 0x01,
194
  L3G4200D_LLD_OUT_SEL_LP    = 0x02,
195
} l3g4200d_lld_ctrl_reg5_t;
196

    
197
/**
198
 * @brief Status register flags.
199
 */
200
typedef enum {
201
  L3G4200D_LLD_ZYXOR = 0x80,
202
  L3G4200D_LLD_ZOR   = 0x40,
203
  L3G4200D_LLD_YOR   = 0x20,
204
  L3G4200D_LLD_XOR   = 0x10,
205
  L3G4200D_LLD_ZYXDA = 0x08,
206
  L3G4200D_LLD_ZDA   = 0x04,
207
  L3G4200D_LLD_YDA   = 0x02,
208
  L3G4200D_LLD_XDA   = 0x01,
209
} l3g4200d_lld_status_reg_t;
210

    
211
/**
212
 * @brief Fifo control register masks.
213
 */
214
typedef enum {
215
  L3G4200D_LLD_FM_BYPASS        = 0x00,
216
  L3G4200D_LLD_FM_FMMODE        = 0x20,
217
  L3G4200D_LLD_FM_STREAM        = 0x40,
218
  L3G4200D_LLD_FM_STREAM2FIFO   = 0x60,
219
  L3G4200D_LLD_FM_BYPASS2STREAM = 0x80,
220
  L3G4200D_LLD_WTM_MASK         = 0x1F,
221
} l3g4200d_lld_fifo_ctrl_reg_t;
222

    
223
/**
224
 * @brief  FIFO source register masks.
225
 */
226
typedef enum {
227
  L3G4200D_LLD_WTM      = 0x80,
228
  L3G4200D_LLD_OVRN     = 0x40,
229
  L3G4200D_LLD_EMPTY    = 0x20,
230
  L3G4200D_LLD_FSS_MASK = 0x1F,
231
} l3g4200d_lld_fifo_src_reg_t;
232

    
233
/**
234
 * @brief Interrupt 1 config register flags.
235
 */
236
typedef enum {
237
  L3G4200D_LLD_ANDOR = 0x80,
238
  L3G4200D_LLD_LIR   = 0x40,
239
  L3G4200D_LLD_ZHIE  = 0x20,
240
  L3G4200D_LLD_ZLIE  = 0x10,
241
  L3G4200D_LLD_YHIE  = 0x08,
242
  L3G4200D_LLD_YLIE  = 0x04,
243
  L3G4200D_LLD_XHIE  = 0x02,
244
  L3G4200D_LLD_XLIE  = 0x01,
245
} l3g4200d_lld_int1_cfg_reg_t;
246

    
247
/**
248
 * @brief Interrupt 1 source register flags.
249
 */
250
typedef enum {
251
  L3G4200D_LLD_IA = 0x40,
252
  L3G4200D_LLD_ZH = 0x20,
253
  L3G4200D_LLD_ZL = 0x10,
254
  L3G4200D_LLD_YH = 0x08,
255
  L3G4200D_LLD_YL = 0x04,
256
  L3G4200D_LLD_XH = 0x02,
257
  L3G4200D_LLD_XL = 0x01,
258
} l3g4200d_lld_int1_src_t;
259

    
260
/**
261
 * @brief Threshold mask.
262
 */
263
enum {
264
  L3G4200D_LLD_THS_L_MASK = 0x7F
265
};
266

    
267
/**
268
 * @brief Interrupt duration register masks.
269
 */
270
typedef enum {
271
  L3G4200D_LLD_INT1_WAIT          = 0x80,
272
  L3G4200D_LLD_INT1_DURATION_MASK = 0x7F,
273
} l3g4200d_lld_int1_duration_reg_t;
274

    
275
/**
276
 * @brief Axis enum.
277
 */
278
typedef enum {
279
  L3G4200D_LLD_X_AXIS = 0x00,
280
  L3G4200D_LLD_Y_AXIS = 0x01,
281
  L3G4200D_LLD_Z_AXIS = 0x02,
282
} l3g4200d_lld_axis_t;
283

    
284
/**
285
 * @brief Config register struct.
286
 */
287
typedef union {
288
  uint8_t data[5];
289
  struct {
290
    uint8_t ctrl_reg1;
291
    uint8_t ctrl_reg2;
292
    uint8_t ctrl_reg3;
293
    uint8_t ctrl_reg4;
294
    uint8_t ctrl_reg5;
295
  } registers;
296
} l3g4200d_lld_cfg_t;
297

    
298
/**
299
 * @brief Interrupt config struct.
300
 */
301
typedef union {
302
  uint8_t data[9];
303
  struct {
304
    uint8_t int1_cfg;
305
    uint8_t int1_src;
306
    uint8_t int1_tsh_xh;
307
    uint8_t int1_tsh_xl;
308
    uint8_t int1_tsh_yh;
309
    uint8_t int1_tsh_yl;
310
    uint8_t int1_tsh_zh;
311
    uint8_t int1_tsh_zl;
312
    uint8_t int1_duration;
313
  } registers;
314
} l3g4200d_lld_int_cfg_t;
315

    
316
/******************************************************************************/
317
/* MACROS                                                                     */
318
/******************************************************************************/
319

    
320
/******************************************************************************/
321
/* EXTERN DECLARATIONS                                                        */
322
/******************************************************************************/
323

    
324
#ifdef __cplusplus
325
extern "C" {
326
#endif
327
  apalExitStatus_t l3g4200d_lld_read_register(const L3G4200DDriver* const l3gd, const l3g4200d_lld_register_t regaddr, uint8_t* const data, const uint8_t length);
328
  apalExitStatus_t l3g4200d_lld_write_register(const L3G4200DDriver* const l3gd, const l3g4200d_lld_register_t regaddr, const uint8_t* const data, const uint8_t length);
329
  apalExitStatus_t l3g4200d_lld_read_all_data(const L3G4200DDriver* const l3gd, int16_t* const data, const l3g4200d_lld_cfg_t* const cfg);
330
  apalExitStatus_t l3g4200d_lld_read_data(const L3G4200DDriver* const l3gd, int16_t* const data, const l3g4200d_lld_axis_t axis, const l3g4200d_lld_cfg_t* const cfg);
331
  apalExitStatus_t l3g4200d_lld_read_config(const L3G4200DDriver* const l3gd, l3g4200d_lld_cfg_t* const cfg);
332
  apalExitStatus_t l3g4200d_lld_write_config(const L3G4200DDriver* const l3gd, const l3g4200d_lld_cfg_t cfg);
333
  apalExitStatus_t l3g4200d_lld_read_int_config(const L3G4200DDriver* const l3gd, l3g4200d_lld_int_cfg_t* const cfg);
334
  apalExitStatus_t l3g4200d_lld_write_int_config(const L3G4200DDriver* const l3gd, const l3g4200d_lld_int_cfg_t cfg);
335
  apalExitStatus_t l3g4200d_lld_read_int_src(const L3G4200DDriver* const l3gd, uint8_t* const cfg);
336
  apalExitStatus_t l3g4200d_lld_read_status_register(const L3G4200DDriver* const l3gd, uint8_t* const status);
337
  apalExitStatus_t l3g4200d_lld_read_fifo_ctrl_register(const L3G4200DDriver* const l3gd, uint8_t* const fifo);
338
  apalExitStatus_t l3g4200d_lld_write_fifo_ctrl_register(const L3G4200DDriver* const l3gd, const uint8_t fifo);
339
  apalExitStatus_t l3g4200d_lld_read_fifo_src_register(const L3G4200DDriver* const l3gdd, uint8_t* const fifo);
340
#ifdef __cplusplus
341
}
342
#endif
343

    
344
/******************************************************************************/
345
/* INLINE FUNCTIONS                                                           */
346
/******************************************************************************/
347

    
348
#endif /* AMIROLLD_L3G4200D_H */
349

    
350
/** @} */
351