Merge pull request #11297 from SteveCEvans/baro_state
[betaflight.git] / src / main / drivers / accgyro_legacy / accgyro_lsm303dlhc.h
blobaa7786361557ebe54509b2441f4f445e89c39dd4
1 /*
2 * This file is part of Cleanflight and Betaflight.
4 * Cleanflight and Betaflight are free software. You can redistribute
5 * this software and/or modify this software under the terms of the
6 * GNU General Public License as published by the Free Software
7 * Foundation, either version 3 of the License, or (at your option)
8 * any later version.
10 * Cleanflight and Betaflight are distributed in the hope that they
11 * will be useful, but WITHOUT ANY WARRANTY; without even the implied
12 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13 * See the GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this software.
18 * If not, see <http://www.gnu.org/licenses/>.
21 #pragma once
23 /**
24 * @brief LSM303DLHC Status
27 /* LSM303DLHC ACC struct */
28 typedef struct {
29 uint8_t Power_Mode; /* Power-down/Normal Mode */
30 uint8_t AccOutput_DataRate; /* OUT data rate */
31 uint8_t Axes_Enable; /* Axes enable */
32 uint8_t High_Resolution; /* High Resolution enabling/disabling */
33 uint8_t BlockData_Update; /* Block Data Update */
34 uint8_t Endianness; /* Endian Data selection */
35 uint8_t AccFull_Scale; /* Full Scale selection */
36 } LSM303DLHCAcc_InitTypeDef;
38 /* LSM303DLHC Acc High Pass Filter struct */
39 typedef struct {
40 uint8_t HighPassFilter_Mode_Selection; /* Internal filter mode */
41 uint8_t HighPassFilter_CutOff_Frequency; /* High pass filter cut-off frequency */
42 uint8_t HighPassFilter_AOI1; /* HPF_enabling/disabling for AOI function on interrupt 1 */
43 uint8_t HighPassFilter_AOI2; /* HPF_enabling/disabling for AOI function on interrupt 2 */
44 } LSM303DLHCAcc_FilterConfigTypeDef;
46 /* LSM303DLHC Mag struct */
47 typedef struct {
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 */
52 } LSM303DLHCMag_InitTypeDef;
53 /**
54 * @}
57 /** @defgroup STM32F3_DISCOVERY_LSM303DLHC_Exported_Constants
58 * @{
60 #define LSM303DLHC_OK ((uint32_t) 0)
61 #define LSM303DLHC_FAIL ((uint32_t) 0)
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 */
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))
78 /******************************************************************************/
79 /*************************** START REGISTER MAPPING **************************/
80 /******************************************************************************/
81 /* Acceleration Registers */
82 #define LSM303DLHC_CTRL_REG1_A 0x20 /* Control register 1 acceleration */
83 #define LSM303DLHC_CTRL_REG2_A 0x21 /* Control register 2 acceleration */
84 #define LSM303DLHC_CTRL_REG3_A 0x22 /* Control register 3 acceleration */
85 #define LSM303DLHC_CTRL_REG4_A 0x23 /* Control register 4 acceleration */
86 #define LSM303DLHC_CTRL_REG5_A 0x24 /* Control register 5 acceleration */
87 #define LSM303DLHC_CTRL_REG6_A 0x25 /* Control register 6 acceleration */
88 #define LSM303DLHC_REFERENCE_A 0x26 /* Reference register acceleration */
89 #define LSM303DLHC_STATUS_REG_A 0x27 /* Status register acceleration */
90 #define LSM303DLHC_OUT_X_L_A 0x28 /* Output Register X acceleration */
91 #define LSM303DLHC_OUT_X_H_A 0x29 /* Output Register X acceleration */
92 #define LSM303DLHC_OUT_Y_L_A 0x2A /* Output Register Y acceleration */
93 #define LSM303DLHC_OUT_Y_H_A 0x2B /* Output Register Y acceleration */
94 #define LSM303DLHC_OUT_Z_L_A 0x2C /* Output Register Z acceleration */
95 #define LSM303DLHC_OUT_Z_H_A 0x2D /* Output Register Z acceleration */
96 #define LSM303DLHC_FIFO_CTRL_REG_A 0x2E /* Fifo control Register acceleration */
97 #define LSM303DLHC_FIFO_SRC_REG_A 0x2F /* Fifo src Register acceleration */
99 #define LSM303DLHC_INT1_CFG_A 0x30 /* Interrupt 1 configuration Register acceleration */
100 #define LSM303DLHC_INT1_SOURCE_A 0x31 /* Interrupt 1 source Register acceleration */
101 #define LSM303DLHC_INT1_THS_A 0x32 /* Interrupt 1 Threshold register acceleration */
102 #define LSM303DLHC_INT1_DURATION_A 0x33 /* Interrupt 1 DURATION register acceleration */
104 #define LSM303DLHC_INT2_CFG_A 0x34 /* Interrupt 2 configuration Register acceleration */
105 #define LSM303DLHC_INT2_SOURCE_A 0x35 /* Interrupt 2 source Register acceleration */
106 #define LSM303DLHC_INT2_THS_A 0x36 /* Interrupt 2 Threshold register acceleration */
107 #define LSM303DLHC_INT2_DURATION_A 0x37 /* Interrupt 2 DURATION register acceleration */
109 #define LSM303DLHC_CLICK_CFG_A 0x38 /* Click configuration Register acceleration */
110 #define LSM303DLHC_CLICK_SOURCE_A 0x39 /* Click 2 source Register acceleration */
111 #define LSM303DLHC_CLICK_THS_A 0x3A /* Click 2 Threshold register acceleration */
113 #define LSM303DLHC_TIME_LIMIT_A 0x3B /* Time Limit Register acceleration */
114 #define LSM303DLHC_TIME_LATENCY_A 0x3C /* Time Latency Register acceleration */
115 #define LSM303DLHC_TIME_WINDOW_A 0x3D /* Time window register acceleration */
117 /* Magnetic field Registers */
118 #define LSM303DLHC_CRA_REG_M 0x00 /* Control register A magnetic field */
119 #define LSM303DLHC_CRB_REG_M 0x01 /* Control register B magnetic field */
120 #define LSM303DLHC_MR_REG_M 0x02 /* Control register MR magnetic field */
121 #define LSM303DLHC_OUT_X_H_M 0x03 /* Output Register X magnetic field */
122 #define LSM303DLHC_OUT_X_L_M 0x04 /* Output Register X magnetic field */
123 #define LSM303DLHC_OUT_Z_H_M 0x05 /* Output Register Z magnetic field */
124 #define LSM303DLHC_OUT_Z_L_M 0x06 /* Output Register Z magnetic field */
125 #define LSM303DLHC_OUT_Y_H_M 0x07 /* Output Register Y magnetic field */
126 #define LSM303DLHC_OUT_Y_L_M 0x08 /* Output Register Y magnetic field */
128 #define LSM303DLHC_SR_REG_M 0x09 /* Status Register magnetic field */
129 #define LSM303DLHC_IRA_REG_M 0x0A /* IRA Register magnetic field */
130 #define LSM303DLHC_IRB_REG_M 0x0B /* IRB Register magnetic field */
131 #define LSM303DLHC_IRC_REG_M 0x0C /* IRC Register magnetic field */
133 #define LSM303DLHC_TEMP_OUT_H_M 0x31 /* Temperature Register magnetic field */
134 #define LSM303DLHC_TEMP_OUT_L_M 0x32 /* Temperature Register magnetic field */
135 /******************************************************************************/
136 /**************************** END REGISTER MAPPING ***************************/
137 /******************************************************************************/
139 #define ACC_I2C_ADDRESS 0x32
140 #define MAG_I2C_ADDRESS 0x3C
142 /** @defgroup Acc_Power_Mode_selection
143 * @{
145 #define LSM303DLHC_NORMAL_MODE ((uint8_t)0x00)
146 #define LSM303DLHC_LOWPOWER_MODE ((uint8_t)0x08)
148 * @}
151 /** @defgroup Acc_OutPut_DataRate_Selection
152 * @{
154 #define LSM303DLHC_ODR_1_HZ ((uint8_t)0x10) /*!< Output Data Rate = 1 Hz */
155 #define LSM303DLHC_ODR_10_HZ ((uint8_t)0x20) /*!< Output Data Rate = 10 Hz */
156 #define LSM303DLHC_ODR_25_HZ ((uint8_t)0x30) /*!< Output Data Rate = 25 Hz */
157 #define LSM303DLHC_ODR_50_HZ ((uint8_t)0x40) /*!< Output Data Rate = 50 Hz */
158 #define LSM303DLHC_ODR_100_HZ ((uint8_t)0x50) /*!< Output Data Rate = 100 Hz */
159 #define LSM303DLHC_ODR_200_HZ ((uint8_t)0x60) /*!< Output Data Rate = 200 Hz */
160 #define LSM303DLHC_ODR_400_HZ ((uint8_t)0x70) /*!< Output Data Rate = 400 Hz */
161 #define LSM303DLHC_ODR_1620_HZ_LP ((uint8_t)0x80) /*!< Output Data Rate = 1620 Hz only in Low Power Mode */
162 #define LSM303DLHC_ODR_1344_HZ ((uint8_t)0x90) /*!< Output Data Rate = 1344 Hz in Normal mode and 5376 Hz in Low Power Mode */
165 * @}
168 /** @defgroup Acc_Axes_Selection
169 * @{
171 #define LSM303DLHC_X_ENABLE ((uint8_t)0x01)
172 #define LSM303DLHC_Y_ENABLE ((uint8_t)0x02)
173 #define LSM303DLHC_Z_ENABLE ((uint8_t)0x04)
174 #define LSM303DLHC_AXES_ENABLE ((uint8_t)0x07)
175 #define LSM303DLHC_AXES_DISABLE ((uint8_t)0x00)
177 * @}
180 /** @defgroup Acc_High_Resolution
181 * @{
183 #define LSM303DLHC_HR_ENABLE ((uint8_t)0x08)
184 #define LSM303DLHC_HR_DISABLE ((uint8_t)0x00)
186 * @}
189 /** @defgroup Acc_Full_Scale_Selection
190 * @{
192 #define LSM303DLHC_FULLSCALE_2G ((uint8_t)0x00) /*!< +/-2 g */
193 #define LSM303DLHC_FULLSCALE_4G ((uint8_t)0x10) /*!< +/-4 g */
194 #define LSM303DLHC_FULLSCALE_8G ((uint8_t)0x20) /*!< +/-8 g */
195 #define LSM303DLHC_FULLSCALE_16G ((uint8_t)0x30) /*!< +/-16 g */
197 * @}
200 /** @defgroup Acc_Block_Data_Update
201 * @{
203 #define LSM303DLHC_BlockUpdate_Continous ((uint8_t)0x00) /*!< Continuos Update */
204 #define LSM303DLHC_BlockUpdate_Single ((uint8_t)0x80) /*!< Single Update: output registers not updated until MSB and LSB reading */
206 * @}
209 /** @defgroup Acc_Endian_Data_selection
210 * @{
212 #define LSM303DLHC_BLE_LSB ((uint8_t)0x00) /*!< Little Endian: data LSB @ lower address */
213 #define LSM303DLHC_BLE_MSB ((uint8_t)0x40) /*!< Big Endian: data MSB @ lower address */
215 * @}
218 /** @defgroup Acc_Boot_Mode_selection
219 * @{
221 #define LSM303DLHC_BOOT_NORMALMODE ((uint8_t)0x00)
222 #define LSM303DLHC_BOOT_REBOOTMEMORY ((uint8_t)0x80)
224 * @}
227 /** @defgroup Acc_High_Pass_Filter_Mode
228 * @{
230 #define LSM303DLHC_HPM_NORMAL_MODE_RES ((uint8_t)0x00)
231 #define LSM303DLHC_HPM_REF_SIGNAL ((uint8_t)0x40)
232 #define LSM303DLHC_HPM_NORMAL_MODE ((uint8_t)0x80)
233 #define LSM303DLHC_HPM_AUTORESET_INT ((uint8_t)0xC0)
235 * @}
238 /** @defgroup Acc_High_Pass_CUT OFF_Frequency
239 * @{
241 #define LSM303DLHC_HPFCF_8 ((uint8_t)0x00)
242 #define LSM303DLHC_HPFCF_16 ((uint8_t)0x10)
243 #define LSM303DLHC_HPFCF_32 ((uint8_t)0x20)
244 #define LSM303DLHC_HPFCF_64 ((uint8_t)0x30)
246 * @}
249 /** @defgroup Acc_High_Pass_Filter_status
250 * @{
252 #define LSM303DLHC_HIGHPASSFILTER_DISABLE ((uint8_t)0x00)
253 #define LSM303DLHC_HIGHPASSFILTER_ENABLE ((uint8_t)0x08)
255 * @}
258 /** @defgroup Acc_High_Pass_Filter_Click_status
259 * @{
261 #define LSM303DLHC_HPF_CLICK_DISABLE ((uint8_t)0x00)
262 #define LSM303DLHC_HPF_CLICK_ENABLE ((uint8_t)0x04)
264 * @}
267 /** @defgroup Acc_High_Pass_Filter_AOI1_status
268 * @{
270 #define LSM303DLHC_HPF_AOI1_DISABLE ((uint8_t)0x00)
271 #define LSM303DLHC_HPF_AOI1_ENABLE ((uint8_t)0x01)
273 * @}
276 /** @defgroup Acc_High_Pass_Filter_AOI2_status
277 * @{
279 #define LSM303DLHC_HPF_AOI2_DISABLE ((uint8_t)0x00)
280 #define LSM303DLHC_HPF_AOI2_ENABLE ((uint8_t)0x02)
282 * @}
285 /** @defgroup Acc_LSM303DLHC_Interrupt1_Configuration_definition
286 * @{
288 #define LSM303DLHC_IT1_CLICK ((uint8_t)0x80)
289 #define LSM303DLHC_IT1_AOI1 ((uint8_t)0x40)
290 #define LSM303DLHC_IT1_AOI2 ((uint8_t)0x20)
291 #define LSM303DLHC_IT1_DRY1 ((uint8_t)0x10)
292 #define LSM303DLHC_IT1_DRY2 ((uint8_t)0x08)
293 #define LSM303DLHC_IT1_WTM ((uint8_t)0x04)
294 #define LSM303DLHC_IT1_OVERRUN ((uint8_t)0x02)
296 * @}
299 /** @defgroup Acc_LSM303DLHC_Interrupt2_Configuration_definition
300 * @{
302 #define LSM303DLHC_IT2_CLICK ((uint8_t)0x80)
303 #define LSM303DLHC_IT2_INT1 ((uint8_t)0x40)
304 #define LSM303DLHC_IT2_INT2 ((uint8_t)0x20)
305 #define LSM303DLHC_IT2_BOOT ((uint8_t)0x10)
306 #define LSM303DLHC_IT2_ACT ((uint8_t)0x08)
307 #define LSM303DLHC_IT2_HLACTIVE ((uint8_t)0x02)
309 * @}
312 /** @defgroup Acc_INT_Combination_Status
313 * @{
315 #define LSM303DLHC_OR_COMBINATION ((uint8_t)0x00) /*!< OR combination of enabled IRQs */
316 #define LSM303DLHC_AND_COMBINATION ((uint8_t)0x80) /*!< AND combination of enabled IRQs */
317 #define LSM303DLHC_MOV_RECOGNITION ((uint8_t)0x40) /*!< 6D movement recognition */
318 #define LSM303DLHC_POS_RECOGNITION ((uint8_t)0xC0) /*!< 6D position recognition */
320 * @}
323 /** @defgroup Acc_INT_Axes
324 * @{
326 #define LSM303DLHC_Z_HIGH ((uint8_t)0x20) /*!< Z High enabled IRQs */
327 #define LSM303DLHC_Z_LOW ((uint8_t)0x10) /*!< Z low enabled IRQs */
328 #define LSM303DLHC_Y_HIGH ((uint8_t)0x08) /*!< Y High enabled IRQs */
329 #define LSM303DLHC_Y_LOW ((uint8_t)0x04) /*!< Y low enabled IRQs */
330 #define LSM303DLHC_X_HIGH ((uint8_t)0x02) /*!< X High enabled IRQs */
331 #define LSM303DLHC_X_LOW ((uint8_t)0x01) /*!< X low enabled IRQs */
333 * @}
336 /** @defgroup Acc_INT_Click
337 * @{
339 #define LSM303DLHC_Z_DOUBLE_CLICK ((uint8_t)0x20) /*!< Z double click IRQs */
340 #define LSM303DLHC_Z_SINGLE_CLICK ((uint8_t)0x10) /*!< Z single click IRQs */
341 #define LSM303DLHC_Y_DOUBLE_CLICK ((uint8_t)0x08) /*!< Y double click IRQs */
342 #define LSM303DLHC_Y_SINGLE_CLICK ((uint8_t)0x04) /*!< Y single click IRQs */
343 #define LSM303DLHC_X_DOUBLE_CLICK ((uint8_t)0x02) /*!< X double click IRQs */
344 #define LSM303DLHC_X_SINGLE_CLICK ((uint8_t)0x01) /*!< X single click IRQs */
346 * @}
349 /** @defgroup Acc_INT1_Interrupt_status
350 * @{
352 #define LSM303DLHC_INT1INTERRUPT_DISABLE ((uint8_t)0x00)
353 #define LSM303DLHC_INT1INTERRUPT_ENABLE ((uint8_t)0x80)
355 * @}
358 /** @defgroup Acc_INT1_Interrupt_ActiveEdge
359 * @{
361 #define LSM303DLHC_INT1INTERRUPT_LOW_EDGE ((uint8_t)0x20)
362 #define LSM303DLHC_INT1INTERRUPT_HIGH_EDGE ((uint8_t)0x00)
364 * @}
367 /** @defgroup Mag_Data_Rate
368 * @{
370 #define LSM303DLHC_ODR_0_75_HZ ((uint8_t) 0x00) /*!< Output Data Rate = 0.75 Hz */
371 #define LSM303DLHC_ODR_1_5_HZ ((uint8_t) 0x04) /*!< Output Data Rate = 1.5 Hz */
372 #define LSM303DLHC_ODR_3_0_HZ ((uint8_t) 0x08) /*!< Output Data Rate = 3 Hz */
373 #define LSM303DLHC_ODR_7_5_HZ ((uint8_t) 0x0C) /*!< Output Data Rate = 7.5 Hz */
374 #define LSM303DLHC_ODR_15_HZ ((uint8_t) 0x10) /*!< Output Data Rate = 15 Hz */
375 #define LSM303DLHC_ODR_30_HZ ((uint8_t) 0x14) /*!< Output Data Rate = 30 Hz */
376 #define LSM303DLHC_ODR_75_HZ ((uint8_t) 0x18) /*!< Output Data Rate = 75 Hz */
377 #define LSM303DLHC_ODR_220_HZ ((uint8_t) 0x1C) /*!< Output Data Rate = 220 Hz */
379 * @}
382 /** @defgroup Mag_Full_Scale
383 * @{
385 #define LSM303DLHC_FS_1_3_GA ((uint8_t) 0x20) /*!< Full scale = +/-1.3 Gauss */
386 #define LSM303DLHC_FS_1_9_GA ((uint8_t) 0x40) /*!< Full scale = +/-1.9 Gauss */
387 #define LSM303DLHC_FS_2_5_GA ((uint8_t) 0x60) /*!< Full scale = +/-2.5 Gauss */
388 #define LSM303DLHC_FS_4_0_GA ((uint8_t) 0x80) /*!< Full scale = +/-4.0 Gauss */
389 #define LSM303DLHC_FS_4_7_GA ((uint8_t) 0xA0) /*!< Full scale = +/-4.7 Gauss */
390 #define LSM303DLHC_FS_5_6_GA ((uint8_t) 0xC0) /*!< Full scale = +/-5.6 Gauss */
391 #define LSM303DLHC_FS_8_1_GA ((uint8_t) 0xE0) /*!< Full scale = +/-8.1 Gauss */
393 * @}
397 * @defgroup Magnetometer_Sensitivity
398 * @{
400 #define LSM303DLHC_M_SENSITIVITY_XY_1_3Ga 1100 /*!< magnetometer X Y axes sensitivity for 1.3 Ga full scale [LSB/Ga] */
401 #define LSM303DLHC_M_SENSITIVITY_XY_1_9Ga 855 /*!< magnetometer X Y axes sensitivity for 1.9 Ga full scale [LSB/Ga] */
402 #define LSM303DLHC_M_SENSITIVITY_XY_2_5Ga 670 /*!< magnetometer X Y axes sensitivity for 2.5 Ga full scale [LSB/Ga] */
403 #define LSM303DLHC_M_SENSITIVITY_XY_4Ga 450 /*!< magnetometer X Y axes sensitivity for 4 Ga full scale [LSB/Ga] */
404 #define LSM303DLHC_M_SENSITIVITY_XY_4_7Ga 400 /*!< magnetometer X Y axes sensitivity for 4.7 Ga full scale [LSB/Ga] */
405 #define LSM303DLHC_M_SENSITIVITY_XY_5_6Ga 330 /*!< magnetometer X Y axes sensitivity for 5.6 Ga full scale [LSB/Ga] */
406 #define LSM303DLHC_M_SENSITIVITY_XY_8_1Ga 230 /*!< magnetometer X Y axes sensitivity for 8.1 Ga full scale [LSB/Ga] */
407 #define LSM303DLHC_M_SENSITIVITY_Z_1_3Ga 980 /*!< magnetometer Z axis sensitivity for 1.3 Ga full scale [LSB/Ga] */
408 #define LSM303DLHC_M_SENSITIVITY_Z_1_9Ga 760 /*!< magnetometer Z axis sensitivity for 1.9 Ga full scale [LSB/Ga] */
409 #define LSM303DLHC_M_SENSITIVITY_Z_2_5Ga 600 /*!< magnetometer Z axis sensitivity for 2.5 Ga full scale [LSB/Ga] */
410 #define LSM303DLHC_M_SENSITIVITY_Z_4Ga 400 /*!< magnetometer Z axis sensitivity for 4 Ga full scale [LSB/Ga] */
411 #define LSM303DLHC_M_SENSITIVITY_Z_4_7Ga 355 /*!< magnetometer Z axis sensitivity for 4.7 Ga full scale [LSB/Ga] */
412 #define LSM303DLHC_M_SENSITIVITY_Z_5_6Ga 295 /*!< magnetometer Z axis sensitivity for 5.6 Ga full scale [LSB/Ga] */
413 #define LSM303DLHC_M_SENSITIVITY_Z_8_1Ga 205 /*!< magnetometer Z axis sensitivity for 8.1 Ga full scale [LSB/Ga] */
415 * @}
418 /** @defgroup Mag_Working_Mode
419 * @{
421 #define LSM303DLHC_CONTINUOS_CONVERSION ((uint8_t) 0x00) /*!< Continuous-Conversion Mode */
422 #define LSM303DLHC_SINGLE_CONVERSION ((uint8_t) 0x01) /*!< Single-Conversion Mode */
423 #define LSM303DLHC_SLEEP ((uint8_t) 0x02) /*!< Sleep Mode */
425 * @}
428 /** @defgroup Mag_Temperature_Sensor
429 * @{
431 #define LSM303DLHC_TEMPSENSOR_ENABLE ((uint8_t) 0x80) /*!< Temp sensor Enable */
432 #define LSM303DLHC_TEMPSENSOR_DISABLE ((uint8_t) 0x00) /*!< Temp sensor Disable */
435 bool lsm303dlhcAccDetect(accDev_t *acc);