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