Statistics
| Branch: | Tag: | Revision:

amiro-lld / include / alld_lis331dlh.h @ 5e2f673b

History | View | Annotate | Download (8.267 KB)

1
/*
2
AMiRo-LLD is a compilation of low-level hardware drivers for the Autonomous Mini Robot (AMiRo) platform.
3
Copyright (C) 2016..2018  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
 * @brief A falling edge indicates an interrupt.
36
 */
37
#define LIS331DLH_LLD_INT_EDGE  APAL_GPIO_EDGE_FALLING
38

    
39
/**
40
 * @brief The LIS331DLH driver struct
41
 */
42
typedef struct {
43
  apalSPIDriver_t* spid;        /**< @brief The SPI Driver */
44
} LIS331DLHDriver;
45

    
46
/**
47
 * @brief SPI access modes.
48
 */
49
typedef enum {
50
  LIS331DLH_LLD_SPI_MULT  = 0x40u,
51
  LIS331DLH_LLD_SPI_READ  = 0x80u,
52
  LIS331DLH_LLD_SPI_WRITE = 0x00u,
53
} lis331dlh_lld_SPI_mode_t;
54

    
55
/**
56
 * @brief Registers.
57
 */
58
typedef enum {
59
  LIS331DLH_LLD_REGISTER_WHO_AM_I        = 0x0fu,
60
  LIS331DLH_LLD_REGISTER_CTRL_REG1       = 0x20u,
61
  LIS331DLH_LLD_REGISTER_CTRL_REG2       = 0x21u,
62
  LIS331DLH_LLD_REGISTER_CTRL_REG3       = 0x22u,
63
  LIS331DLH_LLD_REGISTER_CTRL_REG4       = 0x23u,
64
  LIS331DLH_LLD_REGISTER_CTRL_REG5       = 0x24u,
65
  LIS331DLH_LLD_REGISTER_HP_FILTER_RESET = 0x25u,
66
  LIS331DLH_LLD_REGISTER_REFERENCE       = 0x26u,
67
  LIS331DLH_LLD_REGISTER_STATUS_REG      = 0x27u,
68
  LIS331DLH_LLD_REGISTER_OUT_X_L         = 0x28u,
69
  LIS331DLH_LLD_REGISTER_OUT_X_H         = 0x29u,
70
  LIS331DLH_LLD_REGISTER_OUT_Y_L         = 0x2Au,
71
  LIS331DLH_LLD_REGISTER_OUT_Y_H         = 0x2Bu,
72
  LIS331DLH_LLD_REGISTER_OUT_Z_L         = 0x2Cu,
73
  LIS331DLH_LLD_REGISTER_OUT_Z_H         = 0x2Du,
74
  LIS331DLH_LLD_REGISTER_INT1_CFG        = 0x30u,
75
  LIS331DLH_LLD_REGISTER_INT1_SOURCE     = 0x31u,
76
  LIS331DLH_LLD_REGISTER_INT1_THS        = 0x32u,
77
  LIS331DLH_LLD_REGISTER_INT1_DURATION   = 0x33u,
78
  LIS331DLH_LLD_REGISTER_INT2_CFG        = 0x34u,
79
  LIS331DLH_LLD_REGISTER_INT2_SOURCE     = 0x35u,
80
  LIS331DLH_LLD_REGISTER_INT2_THS        = 0x36u,
81
  LIS331DLH_LLD_REGISTER_INT2_DURATION   = 0x37u,
82
} lis331dlh_lld_register_t;
83

    
84
/**
85
 * @brief WHO_AM_I register constant content.
86
 */
87
typedef enum {
88
  LIS331DLH_LLD_WHO_AM_I = 0x32,
89
} lis331dlh_lld_whoami_t;
90

    
91
/**
92
 * @brief Control register 1 flags.
93
 */
94
typedef enum {
95
  LIS331DLH_LLD_PM_OFF          = 0x00u,
96
  LIS331DLH_LLD_PM_ODR          = 0x20u,
97
  LIS331DLH_LLD_PM_0_5_HZ       = 0x40u,
98
  LIS331DLH_LLD_PM_1_HZ         = 0x60u,
99
  LIS331DLH_LLD_PM_2_HZ         = 0x80u,
100
  LIS331DLH_LLD_PM_5_HZ         = 0xA0u,
101
  LIS331DLH_LLD_PM_10_HZ        = 0xC0u,
102
  LIS331DLH_LLD_DR_50HZ_37LP    = 0x00u,
103
  LIS331DLH_LLD_DR_100HZ_74LP   = 0x08u,
104
  LIS331DLH_LLD_DR_400HZ_292LP  = 0x10u,
105
  LIS331DLH_LLD_DR_1000HZ_780LP = 0x18u,
106
  LIS331DLH_LLD_X_AXIS_ENABLE   = 0x01u,
107
  LIS331DLH_LLD_Y_AXIS_ENABLE   = 0x02u,
108
  LIS331DLH_LLD_Z_AXIS_ENABLE   = 0x04u,
109
} lis331dlh_lld_ctrl_reg1_t;
110

    
111
/**
112
 * @brief Control register 2 flags.
113
 */
114
typedef enum {
115
  LIS331DLH_LLD_REBOOT = 0x80u,
116
  LIS331DLH_LLD_HPM_NORMAL0  = 0x00u,
117
  LIS331DLH_LLD_HPM_REF      = 0x20u,
118
  LIS331DLH_LLD_HPM_NORMAL1  = 0x40u,
119
  LIS331DLH_LLD_FDS_BYPASS = 0x00u,
120
  LIS331DLH_LLD_FDS_FILTER = 0x10u,
121
  LIS331DLH_LLD_HP_EN_INT2  = 0x08u,
122
  LIS331DLH_LLD_HP_EN_INT1  = 0x04u,
123
  LIS331DLH_LLD_HPCF_8       = 0x00u,
124
  LIS331DLH_LLD_HPCF_16      = 0x01u,
125
  LIS331DLH_LLD_HPCF_32      = 0x02u,
126
  LIS331DLH_LLD_HPCF_64      = 0x03u,
127
} lis331dlh_lld_ctrl_reg2_t;
128

    
129
/**
130
 * @brief Control register 3 flags.
131
 */
132
typedef enum {
133
  LIS331DLH_LLD_INT_HIGH     = 0x00u,
134
  LIS331DLH_LLD_INT_LOW      = 0x80u,
135
  LIS331DLH_LLD_PUSH_PULL    = 0x00u,
136
  LIS331DLH_LLD_OPEN_DRAIN   = 0x40u,
137
  LIS331DLH_LLD_LIR2_LATCH    = 0x20u,
138
  LIS331DLH_LLD_I2_CFG_I2    = 0x00u,
139
  LIS331DLH_LLD_I2_CFG_I1_I2 = 0x08u,
140
  LIS331DLH_LLD_I2_CFG_DRY   = 0x10u,
141
  LIS331DLH_LLD_I2_CFG_BOOT  = 0x18u,
142
  LIS331DLH_LLD_LIR1_LATCH    = 0x04u,
143
  LIS331DLH_LLD_LIR1_NO_LATCH = 0x00u,
144
  LIS331DLH_LLD_I1_CFG_I1    = 0x00u,
145
  LIS331DLH_LLD_I1_CFG_I1_I2 = 0x01u,
146
  LIS331DLH_LLD_I1_CFG_DRY   = 0x02u,
147
  LIS331DLH_LLD_I1_CFG_BOOT  = 0x03u,
148
} lis331dlh_lld_ctrl_reg3_t;
149

    
150
/**
151
 * @brief Control register 4 flags.
152
 */
153
typedef enum {
154
  LIS331DLH_LLD_BDU_CONT = 0x00u,
155
  LIS331DLH_LLD_BDU_STOP = 0x80u,
156
  LIS331DLH_LLD_BLE_LE   = 0x00u,
157
  LIS331DLH_LLD_BLE_BE   = 0x40u,
158
  LIS331DLH_LLD_FS_2G    = 0x00u,
159
  LIS331DLH_LLD_FS_4G    = 0x10u,
160
  LIS331DLH_LLD_FS_8G    = 0x30u,
161
  LIS331DLH_LLD_STSIGN_POS = 0x00u,
162
  LIS331DLH_LLD_STSIGN_NEG = 0x08u,
163
  LIS331DLH_LLD_ST_DISABLE = 0x00u,
164
  LIS331DLH_LLD_ST_ENABLE  = 0x02u,
165
  LIS331DLH_LLD_SIM_4WI    = 0x00u,
166
  LIS331DLH_LLD_SIM_3WI    = 0x01u,
167
} lis331dlh_lld_ctrl_reg4_t;
168

    
169
/**
170
 * @brief Control register 5 flags.
171
 */
172
typedef enum {
173
  LIS331DLH_LLD_SLEEP_TO_WAKE_OFF = 0x00u,
174
  LIS331DLH_LLD_SLEEP_TO_WAKE_ON  = 0x03u,
175
} lis331dlh_lld_ctrl_reg5_t;
176

    
177
/**
178
 * @brief Axis enum.
179
 */
180
typedef enum {
181
  LIS331DLH_LLD_X_AXIS = 0,
182
  LIS331DLH_LLD_Y_AXIS = 1,
183
  LIS331DLH_LLD_Z_AXIS = 2,
184
} lis331dlh_lld_axis_t;
185

    
186
/**
187
 * @brief Interrupt enum.
188
 */
189
typedef enum {
190
  LIS331DLH_LLD_INT1 = 0x01,
191
  LIS331DLH_LLD_INT2 = 0x02,
192
} lis331dlh_lld_int_t;
193

    
194
/**
195
 * @brief Config register struct.
196
 */
197
typedef union {
198
  uint8_t data[5];
199
  struct {
200
    uint8_t ctrl_reg1;
201
    uint8_t ctrl_reg2;
202
    uint8_t ctrl_reg3;
203
    uint8_t ctrl_reg4;
204
    uint8_t ctrl_reg5;
205
  } registers;
206
} lis331dlh_lld_cfg_t;
207

    
208
/**
209
 * @brief Interrupt config register flags.
210
 */
211
typedef enum {
212
  LIS331DLH_LLD_INT_CFG_X_LOW_ENABLE  = 0x01,
213
  LIS331DLH_LLD_INT_CFG_X_HIGH_ENABLE = 0x02,
214
  LIS331DLH_LLD_INT_CFG_Y_LOW_ENABLE  = 0x04,
215
  LIS331DLH_LLD_INT_CFG_Y_HIGH_ENABLE = 0x08,
216
  LIS331DLH_LLD_INT_CFG_Z_LOW_ENABLE  = 0x10,
217
  LIS331DLH_LLD_INT_CFG_Z_HIGH_ENABLE = 0x20,
218
  LIS331DLH_LLD_INT_CFG_D6            = 0x40,
219
  LIS331DLH_LLD_INT_CFG_AOI           = 0x80,
220
} lis331dlh_lld_int_cfg_reg_t;
221

    
222
/**
223
 * @brief Status register flags.
224
 */
225
typedef enum {
226
  LIS331DLH_LLD_STATUS_ZYXOR = 0x01,
227
  LIS331DLH_LLD_STATUS_Z_OR  = 0x02,
228
  LIS331DLH_LLD_STATUS_Y_OR  = 0x04,
229
  LIS331DLH_LLD_STATUS_X_OR  = 0x08,
230
  LIS331DLH_LLD_STATUS_ZYXDA = 0x10,
231
  LIS331DLH_LLD_STATUS_Z_DA  = 0x20,
232
  LIS331DLH_LLD_STATUS_Y_DA  = 0x40,
233
  LIS331DLH_LLD_STATUS_X_DA  = 0x80,
234
} lis331dlh_lld_status_t;
235

    
236
/**
237
 * @brief Interrupt config struct.
238
 */
239
typedef struct {
240
  uint8_t cfg_reg;
241
  uint8_t threshold;
242
  uint8_t duration;
243
} lis331dlh_lld_int_cfg_t;
244

    
245
#ifdef __cplusplus
246
extern "C" {
247
#endif
248
  apalExitStatus_t lis331dlh_lld_read_register(const LIS331DLHDriver* const lisd, const lis331dlh_lld_register_t regaddr, uint8_t *data, const uint8_t length);
249
  apalExitStatus_t lis331dlh_lld_write_register(const LIS331DLHDriver* const lisd, const lis331dlh_lld_register_t regaddr, const uint8_t *data, const uint8_t length);
250
  apalExitStatus_t lis331dlh_lld_reset_hp_filter(const LIS331DLHDriver* const lisd);
251
  apalExitStatus_t lis331dlh_lld_read_all_data(const LIS331DLHDriver* const lisd, int16_t *data, const lis331dlh_lld_cfg_t *cfg);
252
  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);
253
  apalExitStatus_t lis331dlh_lld_read_config(const LIS331DLHDriver* const lisd, lis331dlh_lld_cfg_t *cfg);
254
  apalExitStatus_t lis331dlh_lld_write_config(const LIS331DLHDriver* const lisd, const lis331dlh_lld_cfg_t *cfg);
255
  apalExitStatus_t lis331dlh_lld_read_int_config(const LIS331DLHDriver* const lisd, lis331dlh_lld_int_cfg_t *cfg, const lis331dlh_lld_int_t interrupt);
256
  apalExitStatus_t lis331dlh_lld_write_int_config(const LIS331DLHDriver* const lisd, const lis331dlh_lld_int_cfg_t *cfg, const lis331dlh_lld_int_t interrupt);
257
  apalExitStatus_t lis331dlh_lld_read_status_register(const LIS331DLHDriver* const lisd, uint8_t *status);
258
#ifdef __cplusplus
259
}
260
#endif
261

    
262
#endif /* defined(AMIROLLD_CFG_USE_LIS331DLH) */
263

    
264
#endif /* _AMIROLLD_LIS331DLH_H_ */
265

    
266
/** @} */