Statistics
| Branch: | Tag: | Revision:

amiro-lld / drivers / LIS331DLH / v1 / alld_LIS331DLH.h @ ed9a1bf5

History | View | Annotate | Download (9.817 KB)

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

5
This program is free software: you can redistribute it and/or modify
6 f0ca400f Thomas Schöpping
it under the terms of the GNU Lesser General Public License as published by
7 d6728c5b Thomas Schöpping
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 f0ca400f Thomas Schöpping
GNU Lesser General Public License for more details.
14 d6728c5b Thomas Schöpping

15 f0ca400f Thomas Schöpping
You should have received a copy of the GNU Lesser General Public License
16 d6728c5b Thomas Schöpping
along with this program.  If not, see <http://www.gnu.org/licenses/>.
17
*/
18
19 5e2f673b Marc Rothmann
/**
20 9466e34d Thomas Schöpping
 * @file    alld_LIS331DLH.h
21 5e2f673b Marc Rothmann
 * @brief   Accelerometer macros and structures.
22
 *
23
 * @addtogroup lld_accel
24
 * @{
25
 */
26
27 9466e34d Thomas Schöpping
#ifndef AMIROLLD_LIS331DLH_H
28
#define AMIROLLD_LIS331DLH_H
29 d6728c5b Thomas Schöpping
30
#include <amiro-lld.h>
31
32 ef078306 Thomas Schöpping
/******************************************************************************/
33
/* CONSTANTS                                                                  */
34
/******************************************************************************/
35
36 d6728c5b Thomas Schöpping
/**
37
 * @brief A falling edge indicates an interrupt.
38
 */
39
#define LIS331DLH_LLD_INT_EDGE  APAL_GPIO_EDGE_FALLING
40
41 ef078306 Thomas Schöpping
/******************************************************************************/
42
/* SETTINGS                                                                   */
43
/******************************************************************************/
44
45
/******************************************************************************/
46
/* CHECKS                                                                     */
47
/******************************************************************************/
48
49
/******************************************************************************/
50
/* DATA STRUCTURES AND TYPES                                                  */
51
/******************************************************************************/
52
53 d6728c5b Thomas Schöpping
/**
54
 * @brief The LIS331DLH driver struct
55
 */
56
typedef struct {
57
  apalSPIDriver_t* spid;        /**< @brief The SPI Driver */
58
} LIS331DLHDriver;
59
60
/**
61
 * @brief SPI access modes.
62
 */
63
typedef enum {
64
  LIS331DLH_LLD_SPI_MULT  = 0x40u,
65
  LIS331DLH_LLD_SPI_READ  = 0x80u,
66
  LIS331DLH_LLD_SPI_WRITE = 0x00u,
67
} lis331dlh_lld_SPI_mode_t;
68
69
/**
70
 * @brief Registers.
71
 */
72
typedef enum {
73
  LIS331DLH_LLD_REGISTER_WHO_AM_I        = 0x0fu,
74
  LIS331DLH_LLD_REGISTER_CTRL_REG1       = 0x20u,
75
  LIS331DLH_LLD_REGISTER_CTRL_REG2       = 0x21u,
76
  LIS331DLH_LLD_REGISTER_CTRL_REG3       = 0x22u,
77
  LIS331DLH_LLD_REGISTER_CTRL_REG4       = 0x23u,
78
  LIS331DLH_LLD_REGISTER_CTRL_REG5       = 0x24u,
79
  LIS331DLH_LLD_REGISTER_HP_FILTER_RESET = 0x25u,
80
  LIS331DLH_LLD_REGISTER_REFERENCE       = 0x26u,
81
  LIS331DLH_LLD_REGISTER_STATUS_REG      = 0x27u,
82
  LIS331DLH_LLD_REGISTER_OUT_X_L         = 0x28u,
83
  LIS331DLH_LLD_REGISTER_OUT_X_H         = 0x29u,
84
  LIS331DLH_LLD_REGISTER_OUT_Y_L         = 0x2Au,
85
  LIS331DLH_LLD_REGISTER_OUT_Y_H         = 0x2Bu,
86
  LIS331DLH_LLD_REGISTER_OUT_Z_L         = 0x2Cu,
87
  LIS331DLH_LLD_REGISTER_OUT_Z_H         = 0x2Du,
88
  LIS331DLH_LLD_REGISTER_INT1_CFG        = 0x30u,
89
  LIS331DLH_LLD_REGISTER_INT1_SOURCE     = 0x31u,
90
  LIS331DLH_LLD_REGISTER_INT1_THS        = 0x32u,
91
  LIS331DLH_LLD_REGISTER_INT1_DURATION   = 0x33u,
92
  LIS331DLH_LLD_REGISTER_INT2_CFG        = 0x34u,
93
  LIS331DLH_LLD_REGISTER_INT2_SOURCE     = 0x35u,
94
  LIS331DLH_LLD_REGISTER_INT2_THS        = 0x36u,
95
  LIS331DLH_LLD_REGISTER_INT2_DURATION   = 0x37u,
96
} lis331dlh_lld_register_t;
97
98
/**
99
 * @brief WHO_AM_I register constant content.
100
 */
101
typedef enum {
102
  LIS331DLH_LLD_WHO_AM_I = 0x32,
103
} lis331dlh_lld_whoami_t;
104
105
/**
106
 * @brief Control register 1 flags.
107
 */
108
typedef enum {
109
  LIS331DLH_LLD_PM_OFF          = 0x00u,
110
  LIS331DLH_LLD_PM_ODR          = 0x20u,
111
  LIS331DLH_LLD_PM_0_5_HZ       = 0x40u,
112
  LIS331DLH_LLD_PM_1_HZ         = 0x60u,
113
  LIS331DLH_LLD_PM_2_HZ         = 0x80u,
114
  LIS331DLH_LLD_PM_5_HZ         = 0xA0u,
115
  LIS331DLH_LLD_PM_10_HZ        = 0xC0u,
116
  LIS331DLH_LLD_DR_50HZ_37LP    = 0x00u,
117
  LIS331DLH_LLD_DR_100HZ_74LP   = 0x08u,
118
  LIS331DLH_LLD_DR_400HZ_292LP  = 0x10u,
119
  LIS331DLH_LLD_DR_1000HZ_780LP = 0x18u,
120
  LIS331DLH_LLD_X_AXIS_ENABLE   = 0x01u,
121
  LIS331DLH_LLD_Y_AXIS_ENABLE   = 0x02u,
122
  LIS331DLH_LLD_Z_AXIS_ENABLE   = 0x04u,
123
} lis331dlh_lld_ctrl_reg1_t;
124
125
/**
126
 * @brief Control register 2 flags.
127
 */
128
typedef enum {
129
  LIS331DLH_LLD_REBOOT = 0x80u,
130
  LIS331DLH_LLD_HPM_NORMAL0  = 0x00u,
131
  LIS331DLH_LLD_HPM_REF      = 0x20u,
132
  LIS331DLH_LLD_HPM_NORMAL1  = 0x40u,
133
  LIS331DLH_LLD_FDS_BYPASS = 0x00u,
134
  LIS331DLH_LLD_FDS_FILTER = 0x10u,
135
  LIS331DLH_LLD_HP_EN_INT2  = 0x08u,
136
  LIS331DLH_LLD_HP_EN_INT1  = 0x04u,
137
  LIS331DLH_LLD_HPCF_8       = 0x00u,
138
  LIS331DLH_LLD_HPCF_16      = 0x01u,
139
  LIS331DLH_LLD_HPCF_32      = 0x02u,
140
  LIS331DLH_LLD_HPCF_64      = 0x03u,
141
} lis331dlh_lld_ctrl_reg2_t;
142
143
/**
144
 * @brief Control register 3 flags.
145
 */
146
typedef enum {
147
  LIS331DLH_LLD_INT_HIGH     = 0x00u,
148
  LIS331DLH_LLD_INT_LOW      = 0x80u,
149
  LIS331DLH_LLD_PUSH_PULL    = 0x00u,
150
  LIS331DLH_LLD_OPEN_DRAIN   = 0x40u,
151
  LIS331DLH_LLD_LIR2_LATCH    = 0x20u,
152
  LIS331DLH_LLD_I2_CFG_I2    = 0x00u,
153
  LIS331DLH_LLD_I2_CFG_I1_I2 = 0x08u,
154
  LIS331DLH_LLD_I2_CFG_DRY   = 0x10u,
155
  LIS331DLH_LLD_I2_CFG_BOOT  = 0x18u,
156
  LIS331DLH_LLD_LIR1_LATCH    = 0x04u,
157
  LIS331DLH_LLD_LIR1_NO_LATCH = 0x00u,
158
  LIS331DLH_LLD_I1_CFG_I1    = 0x00u,
159
  LIS331DLH_LLD_I1_CFG_I1_I2 = 0x01u,
160
  LIS331DLH_LLD_I1_CFG_DRY   = 0x02u,
161
  LIS331DLH_LLD_I1_CFG_BOOT  = 0x03u,
162
} lis331dlh_lld_ctrl_reg3_t;
163
164
/**
165
 * @brief Control register 4 flags.
166
 */
167
typedef enum {
168
  LIS331DLH_LLD_BDU_CONT = 0x00u,
169
  LIS331DLH_LLD_BDU_STOP = 0x80u,
170
  LIS331DLH_LLD_BLE_LE   = 0x00u,
171
  LIS331DLH_LLD_BLE_BE   = 0x40u,
172
  LIS331DLH_LLD_FS_2G    = 0x00u,
173
  LIS331DLH_LLD_FS_4G    = 0x10u,
174
  LIS331DLH_LLD_FS_8G    = 0x30u,
175
  LIS331DLH_LLD_STSIGN_POS = 0x00u,
176
  LIS331DLH_LLD_STSIGN_NEG = 0x08u,
177
  LIS331DLH_LLD_ST_DISABLE = 0x00u,
178
  LIS331DLH_LLD_ST_ENABLE  = 0x02u,
179
  LIS331DLH_LLD_SIM_4WI    = 0x00u,
180
  LIS331DLH_LLD_SIM_3WI    = 0x01u,
181
} lis331dlh_lld_ctrl_reg4_t;
182
183
/**
184
 * @brief Control register 5 flags.
185
 */
186
typedef enum {
187
  LIS331DLH_LLD_SLEEP_TO_WAKE_OFF = 0x00u,
188
  LIS331DLH_LLD_SLEEP_TO_WAKE_ON  = 0x03u,
189
} lis331dlh_lld_ctrl_reg5_t;
190
191
/**
192
 * @brief Axis enum.
193
 */
194
typedef enum {
195
  LIS331DLH_LLD_X_AXIS = 0,
196
  LIS331DLH_LLD_Y_AXIS = 1,
197
  LIS331DLH_LLD_Z_AXIS = 2,
198
} lis331dlh_lld_axis_t;
199
200
/**
201
 * @brief Interrupt enum.
202
 */
203
typedef enum {
204
  LIS331DLH_LLD_INT1 = 0x01,
205
  LIS331DLH_LLD_INT2 = 0x02,
206
} lis331dlh_lld_int_t;
207
208
/**
209
 * @brief Config register struct.
210
 */
211
typedef union {
212
  uint8_t data[5];
213
  struct {
214
    uint8_t ctrl_reg1;
215
    uint8_t ctrl_reg2;
216
    uint8_t ctrl_reg3;
217
    uint8_t ctrl_reg4;
218
    uint8_t ctrl_reg5;
219
  } registers;
220
} lis331dlh_lld_cfg_t;
221
222
/**
223
 * @brief Interrupt config register flags.
224
 */
225
typedef enum {
226
  LIS331DLH_LLD_INT_CFG_X_LOW_ENABLE  = 0x01,
227
  LIS331DLH_LLD_INT_CFG_X_HIGH_ENABLE = 0x02,
228
  LIS331DLH_LLD_INT_CFG_Y_LOW_ENABLE  = 0x04,
229
  LIS331DLH_LLD_INT_CFG_Y_HIGH_ENABLE = 0x08,
230
  LIS331DLH_LLD_INT_CFG_Z_LOW_ENABLE  = 0x10,
231
  LIS331DLH_LLD_INT_CFG_Z_HIGH_ENABLE = 0x20,
232
  LIS331DLH_LLD_INT_CFG_D6            = 0x40,
233
  LIS331DLH_LLD_INT_CFG_AOI           = 0x80,
234
} lis331dlh_lld_int_cfg_reg_t;
235
236
/**
237
 * @brief Status register flags.
238
 */
239
typedef enum {
240
  LIS331DLH_LLD_STATUS_ZYXOR = 0x01,
241
  LIS331DLH_LLD_STATUS_Z_OR  = 0x02,
242
  LIS331DLH_LLD_STATUS_Y_OR  = 0x04,
243
  LIS331DLH_LLD_STATUS_X_OR  = 0x08,
244
  LIS331DLH_LLD_STATUS_ZYXDA = 0x10,
245
  LIS331DLH_LLD_STATUS_Z_DA  = 0x20,
246
  LIS331DLH_LLD_STATUS_Y_DA  = 0x40,
247
  LIS331DLH_LLD_STATUS_X_DA  = 0x80,
248
} lis331dlh_lld_status_t;
249
250
/**
251
 * @brief Interrupt config struct.
252
 */
253
typedef struct {
254
  uint8_t cfg_reg;
255
  uint8_t threshold;
256
  uint8_t duration;
257
} lis331dlh_lld_int_cfg_t;
258
259 ef078306 Thomas Schöpping
/******************************************************************************/
260
/* MACROS                                                                     */
261
/******************************************************************************/
262
263
/******************************************************************************/
264
/* EXTERN DECLARATIONS                                                        */
265
/******************************************************************************/
266
267 d6728c5b Thomas Schöpping
#ifdef __cplusplus
268
extern "C" {
269
#endif
270
  apalExitStatus_t lis331dlh_lld_read_register(const LIS331DLHDriver* const lisd, const lis331dlh_lld_register_t regaddr, uint8_t *data, const uint8_t length);
271
  apalExitStatus_t lis331dlh_lld_write_register(const LIS331DLHDriver* const lisd, const lis331dlh_lld_register_t regaddr, const uint8_t *data, const uint8_t length);
272
  apalExitStatus_t lis331dlh_lld_reset_hp_filter(const LIS331DLHDriver* const lisd);
273
  apalExitStatus_t lis331dlh_lld_read_all_data(const LIS331DLHDriver* const lisd, int16_t *data, const lis331dlh_lld_cfg_t *cfg);
274
  apalExitStatus_t lis331dlh_lld_read_data(const LIS331DLHDriver* const lisd, int16_t *data, const lis331dlh_lld_axis_t axis, const lis331dlh_lld_cfg_t *cfg);
275
  apalExitStatus_t lis331dlh_lld_read_config(const LIS331DLHDriver* const lisd, lis331dlh_lld_cfg_t *cfg);
276
  apalExitStatus_t lis331dlh_lld_write_config(const LIS331DLHDriver* const lisd, const lis331dlh_lld_cfg_t *cfg);
277
  apalExitStatus_t lis331dlh_lld_read_int_config(const LIS331DLHDriver* const lisd, lis331dlh_lld_int_cfg_t *cfg, const lis331dlh_lld_int_t interrupt);
278
  apalExitStatus_t lis331dlh_lld_write_int_config(const LIS331DLHDriver* const lisd, const lis331dlh_lld_int_cfg_t *cfg, const lis331dlh_lld_int_t interrupt);
279
  apalExitStatus_t lis331dlh_lld_read_status_register(const LIS331DLHDriver* const lisd, uint8_t *status);
280
#ifdef __cplusplus
281
}
282
#endif
283
284 ef078306 Thomas Schöpping
/******************************************************************************/
285
/* INLINE FUNCTIONS                                                           */
286
/******************************************************************************/
287
288 9466e34d Thomas Schöpping
#endif /* AMIROLLD_LIS331DLH_H */
289 5e2f673b Marc Rothmann
290
/** @} */