NinjaFlight
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
accgyro_lsm303dlhc.h
Go to the documentation of this file.
1 /*
2  * This file is part of Ninjaflight.
3  *
4  * Ninjaflight is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation, either version 3 of the License, or
7  * (at your option) any later version.
8  *
9  * Ninjaflight is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with Ninjaflight. If not, see <http://www.gnu.org/licenses/>.
16  */
17 
18 #pragma once
19 
24 /* LSM303DLHC ACC struct */
25 typedef struct
26 {
27  uint8_t Power_Mode; /* Power-down/Normal Mode */
28  uint8_t AccOutput_DataRate; /* OUT data rate */
29  uint8_t Axes_Enable; /* Axes enable */
30  uint8_t High_Resolution; /* High Resolution enabling/disabling */
31  uint8_t BlockData_Update; /* Block Data Update */
32  uint8_t Endianness; /* Endian Data selection */
33  uint8_t AccFull_Scale; /* Full Scale selection */
35 
36 /* LSM303DLHC Acc High Pass Filter struct */
37 typedef struct
38 {
39  uint8_t HighPassFilter_Mode_Selection; /* Internal filter mode */
40  uint8_t HighPassFilter_CutOff_Frequency; /* High pass filter cut-off frequency */
41  uint8_t HighPassFilter_AOI1; /* HPF_enabling/disabling for AOI function on interrupt 1 */
42  uint8_t HighPassFilter_AOI2; /* HPF_enabling/disabling for AOI function on interrupt 2 */
44 
45 /* LSM303DLHC Mag struct */
46 typedef struct
47 {
48  uint8_t Temperature_Sensor; /* Temperature sensor enable/disable */
49  uint8_t MagOutput_DataRate; /* OUT data rate */
50  uint8_t Working_Mode; /* operating mode */
51  uint8_t MagFull_Scale; /* Full Scale selection */
60 #define LSM303DLHC_OK ((uint32_t) 0)
61 #define LSM303DLHC_FAIL ((uint32_t) 0)
62 
63 /* Uncomment the following line to use the default LSM303DLHC_TIMEOUT_UserCallback()
64  function implemented in stm32f3_discovery_lgd20.c file.
65  LSM303DLHC_TIMEOUT_UserCallback() function is called whenever a timeout condition
66  occure during communication (waiting transmit data register empty flag(TXE)
67  or waiting receive data register is not empty flag (RXNE)). */
68 /* #define USE_DEFAULT_TIMEOUT_CALLBACK */
69 
70 /* Maximum Timeout values for flags waiting loops. These timeouts are not based
71  on accurate values, they just guarantee that the application will not remain
72  stuck if the I2C communication is corrupted.
73  You may modify these timeout values depending on CPU frequency and application
74  conditions (interrupts routines ...). */
75 #define LSM303DLHC_FLAG_TIMEOUT ((uint32_t)0x1000)
76 #define LSM303DLHC_LONG_TIMEOUT ((uint32_t)(10 * LSM303DLHC_FLAG_TIMEOUT))
77 
80 #define LSM303DLHC_I2C I2C1
81 #define LSM303DLHC_I2C_CLK RCC_APB1Periph_I2C1
82 
83 #define LSM303DLHC_I2C_SCK_PIN GPIO_Pin_6 /* PB.06 */
84 #define LSM303DLHC_I2C_SCK_GPIO_PORT GPIOB /* GPIOB */
85 #define LSM303DLHC_I2C_SCK_GPIO_CLK RCC_AHBPeriph_GPIOB
86 #define LSM303DLHC_I2C_SCK_SOURCE GPIO_PinSource6
87 #define LSM303DLHC_I2C_SCK_AF GPIO_AF_4
88 
89 #define LSM303DLHC_I2C_SDA_PIN GPIO_Pin_7 /* PB.7 */
90 #define LSM303DLHC_I2C_SDA_GPIO_PORT GPIOB /* GPIOB */
91 #define LSM303DLHC_I2C_SDA_GPIO_CLK RCC_AHBPeriph_GPIOB
92 #define LSM303DLHC_I2C_SDA_SOURCE GPIO_PinSource7
93 #define LSM303DLHC_I2C_SDA_AF GPIO_AF_4
94 
95 #define LSM303DLHC_DRDY_PIN GPIO_Pin_2 /* PE.02 */
96 #define LSM303DLHC_DRDY_GPIO_PORT GPIOE /* GPIOE */
97 #define LSM303DLHC_DRDY_GPIO_CLK RCC_AHBPeriph_GPIOE
98 #define LSM303DLHC_DRDY_EXTI_LINE EXTI_Line2
99 #define LSM303DLHC_DRDY_EXTI_PORT_SOURCE EXTI_PortSourceGPIOE
100 #define LSM303DLHC_DRDY_EXTI_PIN_SOURCE EXTI_PinSource2
101 #define LSM303DLHC_DRDY_EXTI_IRQn EXTI2_TS_IRQn
102 
103 #define LSM303DLHC_I2C_INT1_PIN GPIO_Pin_4 /* PE.04 */
104 #define LSM303DLHC_I2C_INT1_GPIO_PORT GPIOE /* GPIOE */
105 #define LSM303DLHC_I2C_INT1_GPIO_CLK RCC_AHBPeriph_GPIOE
106 #define LSM303DLHC_I2C_INT1_EXTI_LINE EXTI_Line4
107 #define LSM303DLHC_I2C_INT1_EXTI_PORT_SOURCE EXTI_PortSourceGPIOE
108 #define LSM303DLHC_I2C_INT1_EXTI_PIN_SOURCE EXTI_PinSource4
109 #define LSM303DLHC_I2C_INT1_EXTI_IRQn EXTI4_IRQn
110 
111 #define LSM303DLHC_I2C_INT2_PIN GPIO_Pin_5 /* PE.05 */
112 #define LSM303DLHC_I2C_INT2_GPIO_PORT GPIOE /* GPIOE */
113 #define LSM303DLHC_I2C_INT2_GPIO_CLK RCC_AHBPeriph_GPIOE
114 #define LSM303DLHC_I2C_INT2_EXTI_LINE EXTI_Line5
115 #define LSM303DLHC_I2C_INT2_EXTI_PORT_SOURCE EXTI_PortSourceGPIOE
116 #define LSM303DLHC_I2C_INT2_EXTI_PIN_SOURCE EXTI_PinSource5ss
117 #define LSM303DLHC_I2C_INT2_EXTI_IRQn EXTI9_5_IRQn
118 
119 /******************************************************************************/
120 /*************************** START REGISTER MAPPING **************************/
121 /******************************************************************************/
122 /* Acceleration Registers */
123 #define LSM303DLHC_CTRL_REG1_A 0x20 /* Control register 1 acceleration */
124 #define LSM303DLHC_CTRL_REG2_A 0x21 /* Control register 2 acceleration */
125 #define LSM303DLHC_CTRL_REG3_A 0x22 /* Control register 3 acceleration */
126 #define LSM303DLHC_CTRL_REG4_A 0x23 /* Control register 4 acceleration */
127 #define LSM303DLHC_CTRL_REG5_A 0x24 /* Control register 5 acceleration */
128 #define LSM303DLHC_CTRL_REG6_A 0x25 /* Control register 6 acceleration */
129 #define LSM303DLHC_REFERENCE_A 0x26 /* Reference register acceleration */
130 #define LSM303DLHC_STATUS_REG_A 0x27 /* Status register acceleration */
131 #define LSM303DLHC_OUT_X_L_A 0x28 /* Output Register X acceleration */
132 #define LSM303DLHC_OUT_X_H_A 0x29 /* Output Register X acceleration */
133 #define LSM303DLHC_OUT_Y_L_A 0x2A /* Output Register Y acceleration */
134 #define LSM303DLHC_OUT_Y_H_A 0x2B /* Output Register Y acceleration */
135 #define LSM303DLHC_OUT_Z_L_A 0x2C /* Output Register Z acceleration */
136 #define LSM303DLHC_OUT_Z_H_A 0x2D /* Output Register Z acceleration */
137 #define LSM303DLHC_FIFO_CTRL_REG_A 0x2E /* Fifo control Register acceleration */
138 #define LSM303DLHC_FIFO_SRC_REG_A 0x2F /* Fifo src Register acceleration */
139 
140 #define LSM303DLHC_INT1_CFG_A 0x30 /* Interrupt 1 configuration Register acceleration */
141 #define LSM303DLHC_INT1_SOURCE_A 0x31 /* Interrupt 1 source Register acceleration */
142 #define LSM303DLHC_INT1_THS_A 0x32 /* Interrupt 1 Threshold register acceleration */
143 #define LSM303DLHC_INT1_DURATION_A 0x33 /* Interrupt 1 DURATION register acceleration */
144 
145 #define LSM303DLHC_INT2_CFG_A 0x34 /* Interrupt 2 configuration Register acceleration */
146 #define LSM303DLHC_INT2_SOURCE_A 0x35 /* Interrupt 2 source Register acceleration */
147 #define LSM303DLHC_INT2_THS_A 0x36 /* Interrupt 2 Threshold register acceleration */
148 #define LSM303DLHC_INT2_DURATION_A 0x37 /* Interrupt 2 DURATION register acceleration */
149 
150 #define LSM303DLHC_CLICK_CFG_A 0x38 /* Click configuration Register acceleration */
151 #define LSM303DLHC_CLICK_SOURCE_A 0x39 /* Click 2 source Register acceleration */
152 #define LSM303DLHC_CLICK_THS_A 0x3A /* Click 2 Threshold register acceleration */
153 
154 #define LSM303DLHC_TIME_LIMIT_A 0x3B /* Time Limit Register acceleration */
155 #define LSM303DLHC_TIME_LATENCY_A 0x3C /* Time Latency Register acceleration */
156 #define LSM303DLHC_TIME_WINDOW_A 0x3D /* Time window register acceleration */
157 
158 /* Magnetic field Registers */
159 #define LSM303DLHC_CRA_REG_M 0x00 /* Control register A magnetic field */
160 #define LSM303DLHC_CRB_REG_M 0x01 /* Control register B magnetic field */
161 #define LSM303DLHC_MR_REG_M 0x02 /* Control register MR magnetic field */
162 #define LSM303DLHC_OUT_X_H_M 0x03 /* Output Register X magnetic field */
163 #define LSM303DLHC_OUT_X_L_M 0x04 /* Output Register X magnetic field */
164 #define LSM303DLHC_OUT_Z_H_M 0x05 /* Output Register Z magnetic field */
165 #define LSM303DLHC_OUT_Z_L_M 0x06 /* Output Register Z magnetic field */
166 #define LSM303DLHC_OUT_Y_H_M 0x07 /* Output Register Y magnetic field */
167 #define LSM303DLHC_OUT_Y_L_M 0x08 /* Output Register Y magnetic field */
168 
169 #define LSM303DLHC_SR_REG_M 0x09 /* Status Register magnetic field */
170 #define LSM303DLHC_IRA_REG_M 0x0A /* IRA Register magnetic field */
171 #define LSM303DLHC_IRB_REG_M 0x0B /* IRB Register magnetic field */
172 #define LSM303DLHC_IRC_REG_M 0x0C /* IRC Register magnetic field */
173 
174 #define LSM303DLHC_TEMP_OUT_H_M 0x31 /* Temperature Register magnetic field */
175 #define LSM303DLHC_TEMP_OUT_L_M 0x32 /* Temperature Register magnetic field */
176 /******************************************************************************/
177 /**************************** END REGISTER MAPPING ***************************/
178 /******************************************************************************/
179 
180 #define ACC_I2C_ADDRESS 0x32
181 #define MAG_I2C_ADDRESS 0x3C
182 
186 #define LSM303DLHC_NORMAL_MODE ((uint8_t)0x00)
187 #define LSM303DLHC_LOWPOWER_MODE ((uint8_t)0x08)
188 
195 #define LSM303DLHC_ODR_1_HZ ((uint8_t)0x10)
196 #define LSM303DLHC_ODR_10_HZ ((uint8_t)0x20)
197 #define LSM303DLHC_ODR_25_HZ ((uint8_t)0x30)
198 #define LSM303DLHC_ODR_50_HZ ((uint8_t)0x40)
199 #define LSM303DLHC_ODR_100_HZ ((uint8_t)0x50)
200 #define LSM303DLHC_ODR_200_HZ ((uint8_t)0x60)
201 #define LSM303DLHC_ODR_400_HZ ((uint8_t)0x70)
202 #define LSM303DLHC_ODR_1620_HZ_LP ((uint8_t)0x80)
203 #define LSM303DLHC_ODR_1344_HZ ((uint8_t)0x90)
212 #define LSM303DLHC_X_ENABLE ((uint8_t)0x01)
213 #define LSM303DLHC_Y_ENABLE ((uint8_t)0x02)
214 #define LSM303DLHC_Z_ENABLE ((uint8_t)0x04)
215 #define LSM303DLHC_AXES_ENABLE ((uint8_t)0x07)
216 #define LSM303DLHC_AXES_DISABLE ((uint8_t)0x00)
217 
224 #define LSM303DLHC_HR_ENABLE ((uint8_t)0x08)
225 #define LSM303DLHC_HR_DISABLE ((uint8_t)0x00)
226 
233 #define LSM303DLHC_FULLSCALE_2G ((uint8_t)0x00)
234 #define LSM303DLHC_FULLSCALE_4G ((uint8_t)0x10)
235 #define LSM303DLHC_FULLSCALE_8G ((uint8_t)0x20)
236 #define LSM303DLHC_FULLSCALE_16G ((uint8_t)0x30)
244 #define LSM303DLHC_BlockUpdate_Continous ((uint8_t)0x00)
245 #define LSM303DLHC_BlockUpdate_Single ((uint8_t)0x80)
253 #define LSM303DLHC_BLE_LSB ((uint8_t)0x00)
254 #define LSM303DLHC_BLE_MSB ((uint8_t)0x40)
262 #define LSM303DLHC_BOOT_NORMALMODE ((uint8_t)0x00)
263 #define LSM303DLHC_BOOT_REBOOTMEMORY ((uint8_t)0x80)
264 
271 #define LSM303DLHC_HPM_NORMAL_MODE_RES ((uint8_t)0x00)
272 #define LSM303DLHC_HPM_REF_SIGNAL ((uint8_t)0x40)
273 #define LSM303DLHC_HPM_NORMAL_MODE ((uint8_t)0x80)
274 #define LSM303DLHC_HPM_AUTORESET_INT ((uint8_t)0xC0)
275 
282 #define LSM303DLHC_HPFCF_8 ((uint8_t)0x00)
283 #define LSM303DLHC_HPFCF_16 ((uint8_t)0x10)
284 #define LSM303DLHC_HPFCF_32 ((uint8_t)0x20)
285 #define LSM303DLHC_HPFCF_64 ((uint8_t)0x30)
286 
293 #define LSM303DLHC_HIGHPASSFILTER_DISABLE ((uint8_t)0x00)
294 #define LSM303DLHC_HIGHPASSFILTER_ENABLE ((uint8_t)0x08)
295 
302 #define LSM303DLHC_HPF_CLICK_DISABLE ((uint8_t)0x00)
303 #define LSM303DLHC_HPF_CLICK_ENABLE ((uint8_t)0x04)
304 
311 #define LSM303DLHC_HPF_AOI1_DISABLE ((uint8_t)0x00)
312 #define LSM303DLHC_HPF_AOI1_ENABLE ((uint8_t)0x01)
313 
320 #define LSM303DLHC_HPF_AOI2_DISABLE ((uint8_t)0x00)
321 #define LSM303DLHC_HPF_AOI2_ENABLE ((uint8_t)0x02)
322 
329 #define LSM303DLHC_IT1_CLICK ((uint8_t)0x80)
330 #define LSM303DLHC_IT1_AOI1 ((uint8_t)0x40)
331 #define LSM303DLHC_IT1_AOI2 ((uint8_t)0x20)
332 #define LSM303DLHC_IT1_DRY1 ((uint8_t)0x10)
333 #define LSM303DLHC_IT1_DRY2 ((uint8_t)0x08)
334 #define LSM303DLHC_IT1_WTM ((uint8_t)0x04)
335 #define LSM303DLHC_IT1_OVERRUN ((uint8_t)0x02)
336 
343 #define LSM303DLHC_IT2_CLICK ((uint8_t)0x80)
344 #define LSM303DLHC_IT2_INT1 ((uint8_t)0x40)
345 #define LSM303DLHC_IT2_INT2 ((uint8_t)0x20)
346 #define LSM303DLHC_IT2_BOOT ((uint8_t)0x10)
347 #define LSM303DLHC_IT2_ACT ((uint8_t)0x08)
348 #define LSM303DLHC_IT2_HLACTIVE ((uint8_t)0x02)
349 
356 #define LSM303DLHC_OR_COMBINATION ((uint8_t)0x00)
357 #define LSM303DLHC_AND_COMBINATION ((uint8_t)0x80)
358 #define LSM303DLHC_MOV_RECOGNITION ((uint8_t)0x40)
359 #define LSM303DLHC_POS_RECOGNITION ((uint8_t)0xC0)
367 #define LSM303DLHC_Z_HIGH ((uint8_t)0x20)
368 #define LSM303DLHC_Z_LOW ((uint8_t)0x10)
369 #define LSM303DLHC_Y_HIGH ((uint8_t)0x08)
370 #define LSM303DLHC_Y_LOW ((uint8_t)0x04)
371 #define LSM303DLHC_X_HIGH ((uint8_t)0x02)
372 #define LSM303DLHC_X_LOW ((uint8_t)0x01)
380 #define LSM303DLHC_Z_DOUBLE_CLICK ((uint8_t)0x20)
381 #define LSM303DLHC_Z_SINGLE_CLICK ((uint8_t)0x10)
382 #define LSM303DLHC_Y_DOUBLE_CLICK ((uint8_t)0x08)
383 #define LSM303DLHC_Y_SINGLE_CLICK ((uint8_t)0x04)
384 #define LSM303DLHC_X_DOUBLE_CLICK ((uint8_t)0x02)
385 #define LSM303DLHC_X_SINGLE_CLICK ((uint8_t)0x01)
393 #define LSM303DLHC_INT1INTERRUPT_DISABLE ((uint8_t)0x00)
394 #define LSM303DLHC_INT1INTERRUPT_ENABLE ((uint8_t)0x80)
395 
402 #define LSM303DLHC_INT1INTERRUPT_LOW_EDGE ((uint8_t)0x20)
403 #define LSM303DLHC_INT1INTERRUPT_HIGH_EDGE ((uint8_t)0x00)
404 
411 #define LSM303DLHC_ODR_0_75_HZ ((uint8_t) 0x00)
412 #define LSM303DLHC_ODR_1_5_HZ ((uint8_t) 0x04)
413 #define LSM303DLHC_ODR_3_0_HZ ((uint8_t) 0x08)
414 #define LSM303DLHC_ODR_7_5_HZ ((uint8_t) 0x0C)
415 #define LSM303DLHC_ODR_15_HZ ((uint8_t) 0x10)
416 #define LSM303DLHC_ODR_30_HZ ((uint8_t) 0x14)
417 #define LSM303DLHC_ODR_75_HZ ((uint8_t) 0x18)
418 #define LSM303DLHC_ODR_220_HZ ((uint8_t) 0x1C)
426 #define LSM303DLHC_FS_1_3_GA ((uint8_t) 0x20)
427 #define LSM303DLHC_FS_1_9_GA ((uint8_t) 0x40)
428 #define LSM303DLHC_FS_2_5_GA ((uint8_t) 0x60)
429 #define LSM303DLHC_FS_4_0_GA ((uint8_t) 0x80)
430 #define LSM303DLHC_FS_4_7_GA ((uint8_t) 0xA0)
431 #define LSM303DLHC_FS_5_6_GA ((uint8_t) 0xC0)
432 #define LSM303DLHC_FS_8_1_GA ((uint8_t) 0xE0)
441 #define LSM303DLHC_M_SENSITIVITY_XY_1_3Ga 1100
442 #define LSM303DLHC_M_SENSITIVITY_XY_1_9Ga 855
443 #define LSM303DLHC_M_SENSITIVITY_XY_2_5Ga 670
444 #define LSM303DLHC_M_SENSITIVITY_XY_4Ga 450
445 #define LSM303DLHC_M_SENSITIVITY_XY_4_7Ga 400
446 #define LSM303DLHC_M_SENSITIVITY_XY_5_6Ga 330
447 #define LSM303DLHC_M_SENSITIVITY_XY_8_1Ga 230
448 #define LSM303DLHC_M_SENSITIVITY_Z_1_3Ga 980
449 #define LSM303DLHC_M_SENSITIVITY_Z_1_9Ga 760
450 #define LSM303DLHC_M_SENSITIVITY_Z_2_5Ga 600
451 #define LSM303DLHC_M_SENSITIVITY_Z_4Ga 400
452 #define LSM303DLHC_M_SENSITIVITY_Z_4_7Ga 355
453 #define LSM303DLHC_M_SENSITIVITY_Z_5_6Ga 295
454 #define LSM303DLHC_M_SENSITIVITY_Z_8_1Ga 205
462 #define LSM303DLHC_CONTINUOS_CONVERSION ((uint8_t) 0x00)
463 #define LSM303DLHC_SINGLE_CONVERSION ((uint8_t) 0x01)
464 #define LSM303DLHC_SLEEP ((uint8_t) 0x02)
472 #define LSM303DLHC_TEMPSENSOR_ENABLE ((uint8_t) 0x80)
473 #define LSM303DLHC_TEMPSENSOR_DISABLE ((uint8_t) 0x00)
476 bool lsm303dlhcAccDetect(acc_t *acc);
477 
uint8_t High_Resolution
Definition: accgyro_lsm303dlhc.h:30
uint8_t HighPassFilter_CutOff_Frequency
Definition: accgyro_lsm303dlhc.h:40
uint8_t Endianness
Definition: accgyro_lsm303dlhc.h:32
LSM303DLHC Status.
Definition: accgyro_lsm303dlhc.h:25
uint8_t HighPassFilter_AOI2
Definition: accgyro_lsm303dlhc.h:42
uint8_t HighPassFilter_AOI1
Definition: accgyro_lsm303dlhc.h:41
uint8_t AccOutput_DataRate
Definition: accgyro_lsm303dlhc.h:28
uint8_t HighPassFilter_Mode_Selection
Definition: accgyro_lsm303dlhc.h:39
uint8_t BlockData_Update
Definition: accgyro_lsm303dlhc.h:31
uint8_t Working_Mode
Definition: accgyro_lsm303dlhc.h:50
uint8_t MagOutput_DataRate
Definition: accgyro_lsm303dlhc.h:49
uint8_t Axes_Enable
Definition: accgyro_lsm303dlhc.h:29
uint8_t Temperature_Sensor
Definition: accgyro_lsm303dlhc.h:48
Definition: accgyro_lsm303dlhc.h:46
Definition: accgyro_lsm303dlhc.h:37
uint8_t AccFull_Scale
Definition: accgyro_lsm303dlhc.h:33
uint8_t Power_Mode
Definition: accgyro_lsm303dlhc.h:27
uint8_t MagFull_Scale
Definition: accgyro_lsm303dlhc.h:51