Statistics
| Branch: | Tag: | Revision:

amiro-lld / include / alld_lis331dlh.h @ ef078306

History | View | Annotate | Download (9.929 KB)

1
/*
2
AMiRo-LLD is a compilation of low-level hardware drivers for the Autonomous Mini Robot (AMiRo) platform.
3
Copyright (C) 2016..2019  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_lis331dlh.h
21
 * @brief   Accelerometer macros and structures.
22
 *
23
 * @addtogroup lld_accel
24
 * @{
25
 */
26

    
27
#ifndef AMIROLLD_LIS331DLH_H
28
#define AMIROLLD_LIS331DLH_H
29

    
30
#include <amiro-lld.h>
31

    
32
#if defined(AMIROLLD_CFG_USE_LIS331DLH) || defined(__DOXYGEN__)
33

    
34
/******************************************************************************/
35
/* CONSTANTS                                                                  */
36
/******************************************************************************/
37

    
38
/**
39
 * @brief A falling edge indicates an interrupt.
40
 */
41
#define LIS331DLH_LLD_INT_EDGE  APAL_GPIO_EDGE_FALLING
42

    
43
/******************************************************************************/
44
/* SETTINGS                                                                   */
45
/******************************************************************************/
46

    
47
/******************************************************************************/
48
/* CHECKS                                                                     */
49
/******************************************************************************/
50

    
51
/******************************************************************************/
52
/* DATA STRUCTURES AND TYPES                                                  */
53
/******************************************************************************/
54

    
55
/**
56
 * @brief The LIS331DLH driver struct
57
 */
58
typedef struct {
59
  apalSPIDriver_t* spid;        /**< @brief The SPI Driver */
60
} LIS331DLHDriver;
61

    
62
/**
63
 * @brief SPI access modes.
64
 */
65
typedef enum {
66
  LIS331DLH_LLD_SPI_MULT  = 0x40u,
67
  LIS331DLH_LLD_SPI_READ  = 0x80u,
68
  LIS331DLH_LLD_SPI_WRITE = 0x00u,
69
} lis331dlh_lld_SPI_mode_t;
70

    
71
/**
72
 * @brief Registers.
73
 */
74
typedef enum {
75
  LIS331DLH_LLD_REGISTER_WHO_AM_I        = 0x0fu,
76
  LIS331DLH_LLD_REGISTER_CTRL_REG1       = 0x20u,
77
  LIS331DLH_LLD_REGISTER_CTRL_REG2       = 0x21u,
78
  LIS331DLH_LLD_REGISTER_CTRL_REG3       = 0x22u,
79
  LIS331DLH_LLD_REGISTER_CTRL_REG4       = 0x23u,
80
  LIS331DLH_LLD_REGISTER_CTRL_REG5       = 0x24u,
81
  LIS331DLH_LLD_REGISTER_HP_FILTER_RESET = 0x25u,
82
  LIS331DLH_LLD_REGISTER_REFERENCE       = 0x26u,
83
  LIS331DLH_LLD_REGISTER_STATUS_REG      = 0x27u,
84
  LIS331DLH_LLD_REGISTER_OUT_X_L         = 0x28u,
85
  LIS331DLH_LLD_REGISTER_OUT_X_H         = 0x29u,
86
  LIS331DLH_LLD_REGISTER_OUT_Y_L         = 0x2Au,
87
  LIS331DLH_LLD_REGISTER_OUT_Y_H         = 0x2Bu,
88
  LIS331DLH_LLD_REGISTER_OUT_Z_L         = 0x2Cu,
89
  LIS331DLH_LLD_REGISTER_OUT_Z_H         = 0x2Du,
90
  LIS331DLH_LLD_REGISTER_INT1_CFG        = 0x30u,
91
  LIS331DLH_LLD_REGISTER_INT1_SOURCE     = 0x31u,
92
  LIS331DLH_LLD_REGISTER_INT1_THS        = 0x32u,
93
  LIS331DLH_LLD_REGISTER_INT1_DURATION   = 0x33u,
94
  LIS331DLH_LLD_REGISTER_INT2_CFG        = 0x34u,
95
  LIS331DLH_LLD_REGISTER_INT2_SOURCE     = 0x35u,
96
  LIS331DLH_LLD_REGISTER_INT2_THS        = 0x36u,
97
  LIS331DLH_LLD_REGISTER_INT2_DURATION   = 0x37u,
98
} lis331dlh_lld_register_t;
99

    
100
/**
101
 * @brief WHO_AM_I register constant content.
102
 */
103
typedef enum {
104
  LIS331DLH_LLD_WHO_AM_I = 0x32,
105
} lis331dlh_lld_whoami_t;
106

    
107
/**
108
 * @brief Control register 1 flags.
109
 */
110
typedef enum {
111
  LIS331DLH_LLD_PM_OFF          = 0x00u,
112
  LIS331DLH_LLD_PM_ODR          = 0x20u,
113
  LIS331DLH_LLD_PM_0_5_HZ       = 0x40u,
114
  LIS331DLH_LLD_PM_1_HZ         = 0x60u,
115
  LIS331DLH_LLD_PM_2_HZ         = 0x80u,
116
  LIS331DLH_LLD_PM_5_HZ         = 0xA0u,
117
  LIS331DLH_LLD_PM_10_HZ        = 0xC0u,
118
  LIS331DLH_LLD_DR_50HZ_37LP    = 0x00u,
119
  LIS331DLH_LLD_DR_100HZ_74LP   = 0x08u,
120
  LIS331DLH_LLD_DR_400HZ_292LP  = 0x10u,
121
  LIS331DLH_LLD_DR_1000HZ_780LP = 0x18u,
122
  LIS331DLH_LLD_X_AXIS_ENABLE   = 0x01u,
123
  LIS331DLH_LLD_Y_AXIS_ENABLE   = 0x02u,
124
  LIS331DLH_LLD_Z_AXIS_ENABLE   = 0x04u,
125
} lis331dlh_lld_ctrl_reg1_t;
126

    
127
/**
128
 * @brief Control register 2 flags.
129
 */
130
typedef enum {
131
  LIS331DLH_LLD_REBOOT = 0x80u,
132
  LIS331DLH_LLD_HPM_NORMAL0  = 0x00u,
133
  LIS331DLH_LLD_HPM_REF      = 0x20u,
134
  LIS331DLH_LLD_HPM_NORMAL1  = 0x40u,
135
  LIS331DLH_LLD_FDS_BYPASS = 0x00u,
136
  LIS331DLH_LLD_FDS_FILTER = 0x10u,
137
  LIS331DLH_LLD_HP_EN_INT2  = 0x08u,
138
  LIS331DLH_LLD_HP_EN_INT1  = 0x04u,
139
  LIS331DLH_LLD_HPCF_8       = 0x00u,
140
  LIS331DLH_LLD_HPCF_16      = 0x01u,
141
  LIS331DLH_LLD_HPCF_32      = 0x02u,
142
  LIS331DLH_LLD_HPCF_64      = 0x03u,
143
} lis331dlh_lld_ctrl_reg2_t;
144

    
145
/**
146
 * @brief Control register 3 flags.
147
 */
148
typedef enum {
149
  LIS331DLH_LLD_INT_HIGH     = 0x00u,
150
  LIS331DLH_LLD_INT_LOW      = 0x80u,
151
  LIS331DLH_LLD_PUSH_PULL    = 0x00u,
152
  LIS331DLH_LLD_OPEN_DRAIN   = 0x40u,
153
  LIS331DLH_LLD_LIR2_LATCH    = 0x20u,
154
  LIS331DLH_LLD_I2_CFG_I2    = 0x00u,
155
  LIS331DLH_LLD_I2_CFG_I1_I2 = 0x08u,
156
  LIS331DLH_LLD_I2_CFG_DRY   = 0x10u,
157
  LIS331DLH_LLD_I2_CFG_BOOT  = 0x18u,
158
  LIS331DLH_LLD_LIR1_LATCH    = 0x04u,
159
  LIS331DLH_LLD_LIR1_NO_LATCH = 0x00u,
160
  LIS331DLH_LLD_I1_CFG_I1    = 0x00u,
161
  LIS331DLH_LLD_I1_CFG_I1_I2 = 0x01u,
162
  LIS331DLH_LLD_I1_CFG_DRY   = 0x02u,
163
  LIS331DLH_LLD_I1_CFG_BOOT  = 0x03u,
164
} lis331dlh_lld_ctrl_reg3_t;
165

    
166
/**
167
 * @brief Control register 4 flags.
168
 */
169
typedef enum {
170
  LIS331DLH_LLD_BDU_CONT = 0x00u,
171
  LIS331DLH_LLD_BDU_STOP = 0x80u,
172
  LIS331DLH_LLD_BLE_LE   = 0x00u,
173
  LIS331DLH_LLD_BLE_BE   = 0x40u,
174
  LIS331DLH_LLD_FS_2G    = 0x00u,
175
  LIS331DLH_LLD_FS_4G    = 0x10u,
176
  LIS331DLH_LLD_FS_8G    = 0x30u,
177
  LIS331DLH_LLD_STSIGN_POS = 0x00u,
178
  LIS331DLH_LLD_STSIGN_NEG = 0x08u,
179
  LIS331DLH_LLD_ST_DISABLE = 0x00u,
180
  LIS331DLH_LLD_ST_ENABLE  = 0x02u,
181
  LIS331DLH_LLD_SIM_4WI    = 0x00u,
182
  LIS331DLH_LLD_SIM_3WI    = 0x01u,
183
} lis331dlh_lld_ctrl_reg4_t;
184

    
185
/**
186
 * @brief Control register 5 flags.
187
 */
188
typedef enum {
189
  LIS331DLH_LLD_SLEEP_TO_WAKE_OFF = 0x00u,
190
  LIS331DLH_LLD_SLEEP_TO_WAKE_ON  = 0x03u,
191
} lis331dlh_lld_ctrl_reg5_t;
192

    
193
/**
194
 * @brief Axis enum.
195
 */
196
typedef enum {
197
  LIS331DLH_LLD_X_AXIS = 0,
198
  LIS331DLH_LLD_Y_AXIS = 1,
199
  LIS331DLH_LLD_Z_AXIS = 2,
200
} lis331dlh_lld_axis_t;
201

    
202
/**
203
 * @brief Interrupt enum.
204
 */
205
typedef enum {
206
  LIS331DLH_LLD_INT1 = 0x01,
207
  LIS331DLH_LLD_INT2 = 0x02,
208
} lis331dlh_lld_int_t;
209

    
210
/**
211
 * @brief Config register struct.
212
 */
213
typedef union {
214
  uint8_t data[5];
215
  struct {
216
    uint8_t ctrl_reg1;
217
    uint8_t ctrl_reg2;
218
    uint8_t ctrl_reg3;
219
    uint8_t ctrl_reg4;
220
    uint8_t ctrl_reg5;
221
  } registers;
222
} lis331dlh_lld_cfg_t;
223

    
224
/**
225
 * @brief Interrupt config register flags.
226
 */
227
typedef enum {
228
  LIS331DLH_LLD_INT_CFG_X_LOW_ENABLE  = 0x01,
229
  LIS331DLH_LLD_INT_CFG_X_HIGH_ENABLE = 0x02,
230
  LIS331DLH_LLD_INT_CFG_Y_LOW_ENABLE  = 0x04,
231
  LIS331DLH_LLD_INT_CFG_Y_HIGH_ENABLE = 0x08,
232
  LIS331DLH_LLD_INT_CFG_Z_LOW_ENABLE  = 0x10,
233
  LIS331DLH_LLD_INT_CFG_Z_HIGH_ENABLE = 0x20,
234
  LIS331DLH_LLD_INT_CFG_D6            = 0x40,
235
  LIS331DLH_LLD_INT_CFG_AOI           = 0x80,
236
} lis331dlh_lld_int_cfg_reg_t;
237

    
238
/**
239
 * @brief Status register flags.
240
 */
241
typedef enum {
242
  LIS331DLH_LLD_STATUS_ZYXOR = 0x01,
243
  LIS331DLH_LLD_STATUS_Z_OR  = 0x02,
244
  LIS331DLH_LLD_STATUS_Y_OR  = 0x04,
245
  LIS331DLH_LLD_STATUS_X_OR  = 0x08,
246
  LIS331DLH_LLD_STATUS_ZYXDA = 0x10,
247
  LIS331DLH_LLD_STATUS_Z_DA  = 0x20,
248
  LIS331DLH_LLD_STATUS_Y_DA  = 0x40,
249
  LIS331DLH_LLD_STATUS_X_DA  = 0x80,
250
} lis331dlh_lld_status_t;
251

    
252
/**
253
 * @brief Interrupt config struct.
254
 */
255
typedef struct {
256
  uint8_t cfg_reg;
257
  uint8_t threshold;
258
  uint8_t duration;
259
} lis331dlh_lld_int_cfg_t;
260

    
261
/******************************************************************************/
262
/* MACROS                                                                     */
263
/******************************************************************************/
264

    
265
/******************************************************************************/
266
/* EXTERN DECLARATIONS                                                        */
267
/******************************************************************************/
268

    
269
#ifdef __cplusplus
270
extern "C" {
271
#endif
272
  apalExitStatus_t lis331dlh_lld_read_register(const LIS331DLHDriver* const lisd, const lis331dlh_lld_register_t regaddr, uint8_t *data, const uint8_t length);
273
  apalExitStatus_t lis331dlh_lld_write_register(const LIS331DLHDriver* const lisd, const lis331dlh_lld_register_t regaddr, const uint8_t *data, const uint8_t length);
274
  apalExitStatus_t lis331dlh_lld_reset_hp_filter(const LIS331DLHDriver* const lisd);
275
  apalExitStatus_t lis331dlh_lld_read_all_data(const LIS331DLHDriver* const lisd, int16_t *data, const lis331dlh_lld_cfg_t *cfg);
276
  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);
277
  apalExitStatus_t lis331dlh_lld_read_config(const LIS331DLHDriver* const lisd, lis331dlh_lld_cfg_t *cfg);
278
  apalExitStatus_t lis331dlh_lld_write_config(const LIS331DLHDriver* const lisd, const lis331dlh_lld_cfg_t *cfg);
279
  apalExitStatus_t lis331dlh_lld_read_int_config(const LIS331DLHDriver* const lisd, lis331dlh_lld_int_cfg_t *cfg, const lis331dlh_lld_int_t interrupt);
280
  apalExitStatus_t lis331dlh_lld_write_int_config(const LIS331DLHDriver* const lisd, const lis331dlh_lld_int_cfg_t *cfg, const lis331dlh_lld_int_t interrupt);
281
  apalExitStatus_t lis331dlh_lld_read_status_register(const LIS331DLHDriver* const lisd, uint8_t *status);
282
#ifdef __cplusplus
283
}
284
#endif
285

    
286
/******************************************************************************/
287
/* INLINE FUNCTIONS                                                           */
288
/******************************************************************************/
289

    
290
#endif /* defined(AMIROLLD_CFG_USE_LIS331DLH) */
291

    
292
#endif /* AMIROLLD_LIS331DLH_H */
293

    
294
/** @} */