aboutsummaryrefslogtreecommitdiff
path: root/lib/chibios-contrib/os/various/devices_lib/mems/lsm303dlhc.h
diff options
context:
space:
mode:
Diffstat (limited to 'lib/chibios-contrib/os/various/devices_lib/mems/lsm303dlhc.h')
-rw-r--r--lib/chibios-contrib/os/various/devices_lib/mems/lsm303dlhc.h352
1 files changed, 352 insertions, 0 deletions
diff --git a/lib/chibios-contrib/os/various/devices_lib/mems/lsm303dlhc.h b/lib/chibios-contrib/os/various/devices_lib/mems/lsm303dlhc.h
new file mode 100644
index 000000000..46b51bce8
--- /dev/null
+++ b/lib/chibios-contrib/os/various/devices_lib/mems/lsm303dlhc.h
@@ -0,0 +1,352 @@
1/*
2 Pretty LAYer for ChibiOS/RT - Copyright (C) 2015 Rocco Marco Guglielmi
3
4 This file is part of PLAY for ChibiOS/RT.
5
6 PLAY is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3 of the License, or
9 (at your option) any later version.
10
11 PLAY is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program. If not, see <http://www.gnu.org/licenses/>.
18*/
19
20/*
21 Special thanks to Giovanni Di Sirio for teachings, his moral support and
22 friendship. Note that some or every piece of this file could be part of
23 the ChibiOS project that is intellectual property of Giovanni Di Sirio.
24 Please refer to ChibiOS/RT license before use this file.
25
26 For suggestion or Bug report - [email protected]
27 */
28
29/**
30 * @file lsm303dlhc.h
31 * @brief LSM303DLHC MEMS interface module through I2C header.
32 *
33 * @addtogroup lsm303dlhc
34 * @{
35 */
36
37#ifndef _LSM303DLHC_H_
38#define _LSM303DLHC_H_
39
40/*===========================================================================*/
41/* Driver constants. */
42/*===========================================================================*/
43
44#define LSM303DLHC_ACC_SENS_2G ((float)1671.836f) /*!< Accelerometer sensitivity with 2 G full scale [LSB * s^2 / m] */
45#define LSM303DLHC_ACC_SENS_4G ((float)835.918f) /*!< Accelerometer sensitivity with 4 G full scale [LSB * s^2 / m] */
46#define LSM303DLHC_ACC_SENS_8G ((float)417.959f) /*!< Accelerometer sensitivity with 8 G full scale [LSB * s^2 / m] */
47#define LSM303DLHC_ACC_SENS_16G ((float)208.979f) /*!< Accelerometer sensitivity with 16 G full scale [LSB * s^2 / m] */
48
49#define LSM303DLHC_COMP_SENS_XY_1_3GA ((float)1100.0f) /*!< Compass sensitivity with 1.3 GA full scale [LSB / Ga] */
50#define LSM303DLHC_COMP_SENS_XY_1_9GA ((float)855.0f) /*!< Compass sensitivity with 1.9 GA full scale [LSB / Ga] */
51#define LSM303DLHC_COMP_SENS_XY_2_5GA ((float)670.0f) /*!< Compass sensitivity with 2.5 GA full scale [LSB / Ga] */
52#define LSM303DLHC_COMP_SENS_XY_4_0GA ((float)450.0f) /*!< Compass sensitivity with 4.0 GA full scale [LSB / Ga] */
53#define LSM303DLHC_COMP_SENS_XY_4_7GA ((float)400.0f) /*!< Compass sensitivity with 4.7 GA full scale [LSB / Ga] */
54#define LSM303DLHC_COMP_SENS_XY_5_6GA ((float)330.0f) /*!< Compass sensitivity with 5.6 GA full scale [LSB / Ga] */
55#define LSM303DLHC_COMP_SENS_XY_8_1GA ((float)230.0f) /*!< Compass sensitivity with 8.1 GA full scale [LSB / Ga] */
56
57#define LSM303DLHC_COMP_SENS_Z_1_3GA ((float)980.0f) /*!< Compass sensitivity with 1.3 GA full scale [LSB / Ga] */
58#define LSM303DLHC_COMP_SENS_Z_1_9GA ((float)765.0f) /*!< Compass sensitivity with 1.9 GA full scale [LSB / Ga] */
59#define LSM303DLHC_COMP_SENS_Z_2_5GA ((float)600.0f) /*!< Compass sensitivity with 2.5 GA full scale [LSB / Ga] */
60#define LSM303DLHC_COMP_SENS_Z_4_0GA ((float)400.0f) /*!< Compass sensitivity with 4.0 GA full scale [LSB / Ga] */
61#define LSM303DLHC_COMP_SENS_Z_4_7GA ((float)355.0f) /*!< Compass sensitivity with 4.7 GA full scale [LSB / Ga] */
62#define LSM303DLHC_COMP_SENS_Z_5_6GA ((float)295.0f) /*!< Compass sensitivity with 5.6 GA full scale [LSB / Ga] */
63#define LSM303DLHC_COMP_SENS_Z_8_1GA ((float)205.0f) /*!< Compass sensitivity with 8.1 GA full scale [LSB / Ga] */
64/**
65 * @name LSM303DLHC register names
66 * @{
67 */
68/******************************************************************************/
69/* */
70/* LSM303DLHC on board MEMS */
71/* */
72/******************************************************************************/
73/******************* Bit definition for I2C communication *******************/
74#define LSM303DLHC_SAD ((uint8_t)0x7F) /*!< SAD[6:0] Slave Address Mask */
75#define LSM303DLHC_SAD_ACCEL ((uint8_t)0x19) /*!< ACCELEROMETER Slave Address */
76#define LSM303DLHC_SAD_COMPASS ((uint8_t)0x1E) /*!< MAGNETOMETER Slave Address */
77
78#define LSM303DLHC_SUB ((uint8_t)0x7F) /*!< SUB[6:0] Sub-registers address Mask */
79#define LSM303DLHC_SUB_0 ((uint8_t)0x01) /*!< bit 0 */
80#define LSM303DLHC_SUB_1 ((uint8_t)0x02) /*!< bit 1 */
81#define LSM303DLHC_SUB_2 ((uint8_t)0x08) /*!< bit 3 */
82#define LSM303DLHC_SUB_4 ((uint8_t)0x10) /*!< bit 4 */
83#define LSM303DLHC_SUB_5 ((uint8_t)0x20) /*!< bit 5 */
84#define LSM303DLHC_SUB_6 ((uint8_t)0x40) /*!< bit 6 */
85
86#define LSM303DLHC_SUB_MSB ((uint8_t)0x80) /*!< Multiple data read\write bit */
87
88/******** Bit definition for Accelerometer SUB-Registers Addresses **********/
89#define LSM303DLHC_SUB_ACC_CTRL_REG1 ((uint8_t)0x20) /*!< CONTROL REGISTER 1 FOR ACCELEROMETER */
90#define LSM303DLHC_SUB_ACC_CTRL_REG2 ((uint8_t)0x21) /*!< CONTROL REGISTER 2 FOR ACCELEROMETER */
91#define LSM303DLHC_SUB_ACC_CTRL_REG3 ((uint8_t)0x22) /*!< CONTROL REGISTER 3 FOR ACCELEROMETER */
92#define LSM303DLHC_SUB_ACC_CTRL_REG4 ((uint8_t)0x23) /*!< CONTROL REGISTER 4 FOR ACCELEROMETER */
93#define LSM303DLHC_SUB_ACC_CTRL_REG5 ((uint8_t)0x24) /*!< CONTROL REGISTER 5 FOR ACCELEROMETER */
94#define LSM303DLHC_SUB_ACC_CTRL_REG6 ((uint8_t)0x25) /*!< CONTROL REGISTER 6 FOR ACCELEROMETER */
95#define LSM303DLHC_SUB_ACC_REFERENCE ((uint8_t)0x26) /*!< REFERENCE/DATACAPTURE FOR ACCELEROMETER */
96#define LSM303DLHC_SUB_ACC_STATUS_REG ((uint8_t)0x27) /*!< STATUS REGISTER FOR ACCELEROMETER */
97#define LSM303DLHC_SUB_ACC_OUT_X_L ((uint8_t)0x28) /*!< OUTPUT X-AXIS LOW FOR ACCELEROMETER */
98#define LSM303DLHC_SUB_ACC_OUT_X_H ((uint8_t)0x29) /*!< OUTPUT X-AXIS HIGH FOR ACCELEROMETER */
99#define LSM303DLHC_SUB_ACC_OUT_Y_L ((uint8_t)0x2A) /*!< OUTPUT Y-AXIS LOW FOR ACCELEROMETER */
100#define LSM303DLHC_SUB_ACC_OUT_Y_H ((uint8_t)0x2B) /*!< OUTPUT Y-AXIS HIGH FOR ACCELEROMETER */
101#define LSM303DLHC_SUB_ACC_OUT_Z_L ((uint8_t)0x2C) /*!< OUTPUT Z-AXIS LOW FOR ACCELEROMETER */
102#define LSM303DLHC_SUB_ACC_OUT_Z_H ((uint8_t)0x2D) /*!< OUTPUT Z-AXIS HIGH FOR ACCELEROMETER */
103#define LSM303DLHC_SUB_ACC_FIFO_CTRL_REG ((uint8_t)0x2E) /*!< FIFO CONTROL REGISTER FOR ACCELEROMETER */
104#define LSM303DLHC_SUB_ACC_FIFO_SRC_REG ((uint8_t)0x2F) /*!< FIFO SOURCE REGISTER FOR ACCELEROMETER */
105#define LSM303DLHC_SUB_ACC_INT1_CFG ((uint8_t)0x30) /*!< INTERRUPT1 CONFIG FOR ACCELEROMETER */
106#define LSM303DLHC_SUB_ACC_INT1_SOURCE ((uint8_t)0x31) /*!< INTERRUPT1 SOURCE FOR ACCELEROMETER */
107#define LSM303DLHC_SUB_ACC_INT1_THS ((uint8_t)0x32) /*!< INTERRUPT1 THRESHOLD FOR ACCELEROMETER */
108#define LSM303DLHC_SUB_ACC_INT1_DURATION ((uint8_t)0x33) /*!< INTERRUPT1 DURATION FOR ACCELEROMETER */
109#define LSM303DLHC_SUB_ACC_INT2_CFG ((uint8_t)0x34) /*!< INTERRUPT2 CONFIG FOR ACCELEROMETER */
110#define LSM303DLHC_SUB_ACC_INT2_SOURCE ((uint8_t)0x35) /*!< INTERRUPT2 SOURCE FOR ACCELEROMETER */
111#define LSM303DLHC_SUB_ACC_INT2_THS ((uint8_t)0x36) /*!< INTERRUPT2 THRESHOLD FOR ACCELEROMETER */
112#define LSM303DLHC_SUB_ACC_INT2_DURATION ((uint8_t)0x37) /*!< INTERRUPT2 DURATION FOR ACCELEROMETER */
113#define LSM303DLHC_SUB_ACC_CLICK_CFG ((uint8_t)0x38) /*!< CLICK CONFIG FOR ACCELEROMETER */
114#define LSM303DLHC_SUB_ACC_CLICK_SRC ((uint8_t)0x39) /*!< CLICK SOURCE FOR ACCELEROMETER */
115#define LSM303DLHC_SUB_ACC_CLICK_THS ((uint8_t)0x3A) /*!< CLICK THRESHOLD FOR ACCELEROMETER */
116#define LSM303DLHC_SUB_ACC_TIME_LIMIT ((uint8_t)0x3B) /*!< TIME LIMIT FOR ACCELEROMETER */
117#define LSM303DLHC_SUB_ACC_TIME_LATENCY ((uint8_t)0x3C) /*!< TIME LATENCY FOR ACCELEROMETER */
118#define LSM303DLHC_SUB_ACC_TIME_WINDOW ((uint8_t)0x3D) /*!< TIME WINDOW FOR ACCELEROMETER */
119
120/********* Bit definition for Compass SUB-Registers Addresses **********/
121#define LSM303DLHC_SUB_COMP_CRA_REG ((uint8_t)0x00) /*!< CONTROL REGISTER A FOR MAGNETOMETER */
122#define LSM303DLHC_SUB_COMP_CRB_REG ((uint8_t)0x01) /*!< CONTROL REGISTER B FOR MAGNETOMETER */
123#define LSM303DLHC_SUB_COMP_MR_REG ((uint8_t)0x02) /*!< STATUS REGISTER FOR MAGNETOMETER */
124#define LSM303DLHC_SUB_COMP_OUT_X_H ((uint8_t)0x03) /*!< OUTPUT X-AXIS HIGH FOR MAGNETOMETER */
125#define LSM303DLHC_SUB_COMP_OUT_X_L ((uint8_t)0x04) /*!< OUTPUT X-AXIS LOW FOR MAGNETOMETER */
126#define LSM303DLHC_SUB_COMP_OUT_Z_H ((uint8_t)0x05) /*!< OUTPUT Z-AXIS HIGH FOR MAGNETOMETER */
127#define LSM303DLHC_SUB_COMP_OUT_Z_L ((uint8_t)0x06) /*!< OUTPUT Z-AXIS LOW FOR MAGNETOMETER */
128#define LSM303DLHC_SUB_COMP_OUT_Y_H ((uint8_t)0x07) /*!< OUTPUT Y-AXIS HIGH FOR MAGNETOMETER */
129#define LSM303DLHC_SUB_COMP_OUT_Y_L ((uint8_t)0x08) /*!< OUTPUT Y-AXIS LOW FOR MAGNETOMETER */
130#define LSM303DLHC_SUB_COMP_SR_REG ((uint8_t)0x09) /*!< SR REGISTER FOR MAGNETOMETER */
131#define LSM303DLHC_SUB_COMP_IRA_REG ((uint8_t)0x0A) /*!< IR A REGISTER FOR MAGNETOMETER */
132#define LSM303DLHC_SUB_COMP_IRB_REG ((uint8_t)0x0B) /*!< IR B REGISTER FOR MAGNETOMETER */
133#define LSM303DLHC_SUB_COMP_IRC_REG ((uint8_t)0x0C) /*!< IR C REGISTER FOR MAGNETOMETER */
134#define LSM303DLHC_SUB_COMP_TEMP_OUT_H ((uint8_t)0x31) /*!< OUTPUT TEMP HIGH FOR MAGNETOMETER */
135#define LSM303DLHC_SUB_COMP_TEMP_OUT_L ((uint8_t)0x32) /*!< OUTPUT TEMP LOW FOR MAGNETOMETER */
136
137/** @} */
138
139/*===========================================================================*/
140/* Driver pre-compile time settings. */
141/*===========================================================================*/
142
143/*===========================================================================*/
144/* Derived constants and error checks. */
145/*===========================================================================*/
146
147/*===========================================================================*/
148/* Driver data structures and types. */
149/*===========================================================================*/
150
151/**
152 * @name Accelerometer data structures and types
153 * @{
154 */
155
156/**
157 * @brief Accelerometer Output Data Rate
158 */
159typedef enum
160{
161 LSM303DLHC_ACC_ODR_PD = 0x00, /*!< Power down */
162 LSM303DLHC_ACC_ODR_1Hz = 0x10, /*!< Output Data Rate = 1 Hz */
163 LSM303DLHC_ACC_ODR_10Hz = 0x20, /*!< Output Data Rate = 10 Hz */
164 LSM303DLHC_ACC_ODR_25Hz = 0x30, /*!< Output Data Rate = 25 Hz */
165 LSM303DLHC_ACC_ODR_50Hz = 0x40, /*!< Output Data Rate = 50 Hz */
166 LSM303DLHC_ACC_ODR_100Hz = 0x50, /*!< Output Data Rate = 100 Hz */
167 LSM303DLHC_ACC_ODR_200Hz = 0x60, /*!< Output Data Rate = 200 Hz */
168 LSM303DLHC_ACC_ODR_400Hz = 0x70, /*!< Output Data Rate = 400 Hz */
169 LSM303DLHC_ACC_ODR_1620Hz = 0x80, /*!< Output Data Rate = 1620 Hz Low Power mode only */
170 LSM303DLHC_ACC_ODR_1344Hz = 0x90 /*!< Output Data Rate = 1344 Hz in Normal mode and 5376 Hz in Low Power Mode */
171}LSM303DLHC_ACC_ODR_t;
172
173/**
174 * @brief Accelerometer Power Mode
175 */
176typedef enum
177{
178 LSM303DLHC_ACC_PM_NORMAL = 0x00, /*!< Normal mode enabled */
179 LSM303DLHC_ACC_PM_LOW_POWER = 0x08 /*!< Low Power mode enabled */
180}LSM303DLHC_ACC_PM_t;
181
182/**
183 * @brief Accelerometer Full Scale
184 */
185typedef enum
186{
187 LSM303DLHC_ACC_FS_2G = 0x00, /*!< �2 g m/s^2 */
188 LSM303DLHC_ACC_FS_4G = 0x10, /*!< �4 g m/s^2 */
189 LSM303DLHC_ACC_FS_8G = 0x20, /*!< �8 g m/s^2 */
190 LSM303DLHC_ACC_FS_16G = 0x30 /*!< �16 g m/s^2 */
191}LSM303DLHC_ACC_FS_t;
192
193/**
194 * @brief Accelerometer Axes Enabling
195 */
196typedef enum{
197 LSM303DLHC_ACC_AE_DISABLED = 0x00, /*!< Axes all disabled */
198 LSM303DLHC_ACC_AE_X = 0x01, /*!< Only X-axis enabled */
199 LSM303DLHC_ACC_AE_Y = 0x02, /*!< Only Y-axis enabled */
200 LSM303DLHC_ACC_AE_XY = 0x03, /*!< X & Y axes enabled */
201 LSM303DLHC_ACC_AE_Z = 0x04, /*!< Only Z-axis enabled */
202 LSM303DLHC_ACC_AE_XZ = 0x05, /*!< X & Z axes enabled */
203 LSM303DLHC_ACC_AE_YZ = 0x06, /*!< Y & Z axes enabled */
204 LSM303DLHC_ACC_AE_XYZ = 0x07 /*!< All axes enabled */
205}LSM303DLHC_ACC_AE_t;
206
207/**
208 * @brief Accelerometer Block Data Update
209 */
210typedef enum
211{
212 LSM303DLHC_ACC_BDU_CONTINOUS = 0x00, /*!< Continuos Update */
213 LSM303DLHC_ACC_BDU_BLOCKED = 0x80 /*!< Single Update: output registers not updated until MSB and LSB reading */
214}LSM303DLHC_ACC_BDU_t;
215
216/**
217 * @brief Accelerometer Endianness
218 */
219typedef enum
220{
221 LSM303DLHC_ACC_End_LITTLE = 0x00, /*!< Little Endian: data LSB @ lower address */
222 LSM303DLHC_ACC_End_BIG = 0x40 /*!< Big Endian: data MSB @ lower address */
223}LSM303DLHC_ACC_End_t;
224
225/**
226 * @brief Accelerometer High Resolution mode
227 */
228typedef enum
229{
230 LSM303DLHC_ACC_HR_Enabled = 0x08, /*!< High resolution output mode enabled */
231 LSM303DLHC_ACC_HR_Disabled = 0x00 /*!< High resolution output mode disabled */
232}LSM303DLHC_ACC_HR_t;
233
234/**
235 * @brief Accelerometer configuration structure.
236 */
237typedef struct {
238 /**
239 * @brief Accelerometer fullscale value.
240 */
241 LSM303DLHC_ACC_FS_t fullscale;
242 /**
243 * @brief Accelerometer power mode selection.
244 */
245 LSM303DLHC_ACC_PM_t powermode;
246 /**
247 * @brief Accelerometer output data rate selection.
248 */
249 LSM303DLHC_ACC_ODR_t outputdatarate;
250 /**
251 * @brief Accelerometer axes enabling.
252 */
253 LSM303DLHC_ACC_AE_t axesenabling;
254 /**
255 * @brief Accelerometer block data update.
256 */
257 LSM303DLHC_ACC_BDU_t blockdataupdate;
258 /**
259 * @brief Accelerometer block data update.
260 */
261 LSM303DLHC_ACC_HR_t highresmode;
262} LSM303DLHC_ACC_Config;
263/** @} */
264
265
266/**
267 * @name Compass data types
268 * @{
269 */
270
271/**
272 * @brief Compass Output Data Rate
273 */
274typedef enum
275{
276 LSM303DLHC_COMP_ODR_0_75_Hz = 0x00, /*!< Output Data Rate = 0.75 Hz */
277 LSM303DLHC_COMP_ODR_1_5_Hz = 0x04, /*!< Output Data Rate = 1.5 Hz */
278 LSM303DLHC_COMP_ODR_3_0_Hz = 0x08, /*!< Output Data Rate = 3 Hz */
279 LSM303DLHC_COMP_ODR_7_5_Hz = 0x0C, /*!< Output Data Rate = 7.5 Hz */
280 LSM303DLHC_COMP_ODR_15_Hz = 0x10, /*!< Output Data Rate = 15 Hz */
281 LSM303DLHC_COMP_ODR_30_Hz = 0x14, /*!< Output Data Rate = 30 Hz */
282 LSM303DLHC_COMP_ODR_75_Hz = 0x18, /*!< Output Data Rate = 75 Hz */
283 LSM303DLHC_COMP_ODR_220_Hz = 0x1C /*!< Output Data Rate = 220 Hz */
284}LSM303DLHC_COMP_ODR_t;
285
286
287/**
288 * @brief Compass Full Scale
289 */
290typedef enum
291{
292 LSM303DLHC_COMP_FS_1_3_GA = 0x20, /*!< Full scale = �1.3 Gauss */
293 LSM303DLHC_COMP_FS_1_9_GA = 0x40, /*!< Full scale = �1.9 Gauss */
294 LSM303DLHC_COMP_FS_2_5_GA = 0x60, /*!< Full scale = �2.5 Gauss */
295 LSM303DLHC_COMP_FS_4_0_GA = 0x80, /*!< Full scale = �4.0 Gauss */
296 LSM303DLHC_COMP_FS_4_7_GA = 0xA0, /*!< Full scale = �4.7 Gauss */
297 LSM303DLHC_COMP_FS_5_6_GA = 0xC0, /*!< Full scale = �5.6 Gauss */
298 LSM303DLHC_COMP_FS_8_1_GA = 0xE0 /*!< Full scale = �8.1 Gauss */
299}LSM303DLHC_COMP_FS_t;
300
301
302/**
303 * @brief Compass Working Mode
304 */
305typedef enum
306{
307 LSM303DLHC_COMP_WM_CONTINUOS = 0x00, /*!< Continuous-Conversion Mode */
308 LSM303DLHC_COMP_WM_BLOCKED = 0x01, /*!< Single-Conversion Mode */
309 LSM303DLHC_COMP_WM_SLEEP = 0x02 /*!< Sleep Mode */
310}LSM303DLHC_COMP_WM_t;
311
312/**
313 * @brief Compass configuration structure.
314 */
315typedef struct {
316 /**
317 * @brief Compass fullscale value.
318 */
319 LSM303DLHC_COMP_FS_t fullscale;
320 /**
321 * @brief Compass output data rate selection.
322 */
323 LSM303DLHC_COMP_ODR_t outputdatarate;
324 /**
325 * @brief Compass working mode.
326 */
327 LSM303DLHC_COMP_WM_t workingmode;
328} LSM303DLHC_COMP_Config;
329/** @} */
330/*===========================================================================*/
331/* Driver macros. */
332/*===========================================================================*/
333
334/*===========================================================================*/
335/* External declarations. */
336/*===========================================================================*/
337
338#ifdef __cplusplus
339extern "C" {
340#endif
341
342 uint8_t lsm303dlhcReadRegister(I2CDriver *i2cp, uint8_t sad, uint8_t sub,
343 msg_t* message);
344 void lsm303dlhcWriteRegister(I2CDriver *i2cp,uint8_t sad, uint8_t sub,
345 uint8_t value, msg_t* message);
346
347#ifdef __cplusplus
348}
349#endif
350#endif /* _LSM303DLHC_H_ */
351/** @} */
352