STM32L476G-Discovery board drivers V1.0.0
Dependents: DiscoLogger DISCO_L476VG_GlassLCD DISCO_L476VG_MicrophoneRecorder DISCO_L476VG_UART ... more
Drivers/BSP/Components/l3gd20/l3gd20.c@5:4943b15cce9f, 2019-09-24 (annotated)
- Committer:
- jeromecoutant
- Date:
- Tue Sep 24 18:00:58 2019 +0200
- Revision:
- 5:4943b15cce9f
- Parent:
- 1:917af0ca86df
Update BSP files with CubeL4 V1.14.0
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Jerome Coutant
1:917af0ca86df
|
1
|
/**
|
|
Jerome Coutant
1:917af0ca86df
|
2
|
******************************************************************************
|
|
Jerome Coutant
1:917af0ca86df
|
3
|
* @file l3gd20.c
|
|
Jerome Coutant
1:917af0ca86df
|
4
|
* @author MCD Application Team
|
|
Jerome Coutant
1:917af0ca86df
|
5
|
* @brief This file provides a set of functions needed to manage the L3GD20,
|
|
Jerome Coutant
1:917af0ca86df
|
6
|
* ST MEMS motion sensor, 3-axis digital output gyroscope.
|
|
Jerome Coutant
1:917af0ca86df
|
7
|
******************************************************************************
|
|
Jerome Coutant
1:917af0ca86df
|
8
|
* @attention
|
|
Jerome Coutant
1:917af0ca86df
|
9
|
*
|
|
jeromecoutant | 5:4943b15cce9f | 10 | * <h2><center>© Copyright (c) 2015 STMicroelectronics. |
jeromecoutant | 5:4943b15cce9f | 11 | * All rights reserved.</center></h2> |
Jerome Coutant
1:917af0ca86df
|
12
|
*
|
|
jeromecoutant | 5:4943b15cce9f | 13 | * This software component is licensed by ST under BSD 3-Clause license, |
jeromecoutant | 5:4943b15cce9f | 14 | * the "License"; You may not use this file except in compliance with the |
jeromecoutant | 5:4943b15cce9f | 15 | * License. You may obtain a copy of the License at: |
jeromecoutant | 5:4943b15cce9f | 16 | * opensource.org/licenses/BSD-3-Clause |
Jerome Coutant
1:917af0ca86df
|
17
|
*
|
|
Jerome Coutant
1:917af0ca86df
|
18
|
******************************************************************************
|
|
Jerome Coutant
1:917af0ca86df
|
19
|
*/
|
|
Jerome Coutant
1:917af0ca86df
|
20
|
/* Includes ------------------------------------------------------------------*/
|
|
Jerome Coutant
1:917af0ca86df
|
21
|
#include "l3gd20.h"
|
|
Jerome Coutant
1:917af0ca86df
|
22
|
|
|
Jerome Coutant
1:917af0ca86df
|
23
|
/** @addtogroup BSP
|
|
Jerome Coutant
1:917af0ca86df
|
24
|
* @{
|
|
Jerome Coutant
1:917af0ca86df
|
25
|
*/
|
|
Jerome Coutant
1:917af0ca86df
|
26
|
|
|
Jerome Coutant
1:917af0ca86df
|
27
|
/** @addtogroup Components
|
|
Jerome Coutant
1:917af0ca86df
|
28
|
* @{
|
|
Jerome Coutant
1:917af0ca86df
|
29
|
*/
|
|
Jerome Coutant
1:917af0ca86df
|
30
|
|
|
Jerome Coutant
1:917af0ca86df
|
31
|
/** @addtogroup L3GD20
|
|
Jerome Coutant
1:917af0ca86df
|
32
|
* @{
|
|
Jerome Coutant
1:917af0ca86df
|
33
|
*/
|
|
Jerome Coutant
1:917af0ca86df
|
34
|
|
|
Jerome Coutant
1:917af0ca86df
|
35
|
/** @defgroup L3GD20_Private_TypesDefinitions
|
|
Jerome Coutant
1:917af0ca86df
|
36
|
* @{
|
|
Jerome Coutant
1:917af0ca86df
|
37
|
*/
|
|
Jerome Coutant
1:917af0ca86df
|
38
|
|
|
Jerome Coutant
1:917af0ca86df
|
39
|
/**
|
|
Jerome Coutant
1:917af0ca86df
|
40
|
* @}
|
|
Jerome Coutant
1:917af0ca86df
|
41
|
*/
|
|
Jerome Coutant
1:917af0ca86df
|
42
|
|
|
Jerome Coutant
1:917af0ca86df
|
43
|
/** @defgroup L3GD20_Private_Defines
|
|
Jerome Coutant
1:917af0ca86df
|
44
|
* @{
|
|
Jerome Coutant
1:917af0ca86df
|
45
|
*/
|
|
Jerome Coutant
1:917af0ca86df
|
46
|
|
|
Jerome Coutant
1:917af0ca86df
|
47
|
/**
|
|
Jerome Coutant
1:917af0ca86df
|
48
|
* @}
|
|
Jerome Coutant
1:917af0ca86df
|
49
|
*/
|
|
Jerome Coutant
1:917af0ca86df
|
50
|
|
|
Jerome Coutant
1:917af0ca86df
|
51
|
/** @defgroup L3GD20_Private_Macros
|
|
Jerome Coutant
1:917af0ca86df
|
52
|
* @{
|
|
Jerome Coutant
1:917af0ca86df
|
53
|
*/
|
|
Jerome Coutant
1:917af0ca86df
|
54
|
|
|
Jerome Coutant
1:917af0ca86df
|
55
|
/**
|
|
Jerome Coutant
1:917af0ca86df
|
56
|
* @}
|
|
Jerome Coutant
1:917af0ca86df
|
57
|
*/
|
|
Jerome Coutant
1:917af0ca86df
|
58
|
|
|
Jerome Coutant
1:917af0ca86df
|
59
|
/** @defgroup L3GD20_Private_Variables
|
|
Jerome Coutant
1:917af0ca86df
|
60
|
* @{
|
|
Jerome Coutant
1:917af0ca86df
|
61
|
*/
|
|
Jerome Coutant
1:917af0ca86df
|
62
|
GYRO_DrvTypeDef L3gd20Drv =
|
|
Jerome Coutant
1:917af0ca86df
|
63
|
{
|
|
Jerome Coutant
1:917af0ca86df
|
64
|
L3GD20_Init,
|
|
Jerome Coutant
1:917af0ca86df
|
65
|
L3GD20_DeInit,
|
|
Jerome Coutant
1:917af0ca86df
|
66
|
L3GD20_ReadID,
|
|
Jerome Coutant
1:917af0ca86df
|
67
|
L3GD20_RebootCmd,
|
|
Jerome Coutant
1:917af0ca86df
|
68
|
L3GD20_LowPower,
|
|
Jerome Coutant
1:917af0ca86df
|
69
|
L3GD20_INT1InterruptConfig,
|
|
Jerome Coutant
1:917af0ca86df
|
70
|
L3GD20_EnableIT,
|
|
Jerome Coutant
1:917af0ca86df
|
71
|
L3GD20_DisableIT,
|
|
Jerome Coutant
1:917af0ca86df
|
72
|
0,
|
|
Jerome Coutant
1:917af0ca86df
|
73
|
0,
|
|
Jerome Coutant
1:917af0ca86df
|
74
|
L3GD20_FilterConfig,
|
|
Jerome Coutant
1:917af0ca86df
|
75
|
L3GD20_FilterCmd,
|
|
Jerome Coutant
1:917af0ca86df
|
76
|
L3GD20_ReadXYZAngRate
|
|
Jerome Coutant
1:917af0ca86df
|
77
|
};
|
|
Jerome Coutant
1:917af0ca86df
|
78
|
|
|
Jerome Coutant
1:917af0ca86df
|
79
|
/**
|
|
Jerome Coutant
1:917af0ca86df
|
80
|
* @}
|
|
Jerome Coutant
1:917af0ca86df
|
81
|
*/
|
|
Jerome Coutant
1:917af0ca86df
|
82
|
|
|
Jerome Coutant
1:917af0ca86df
|
83
|
/** @defgroup L3GD20_Private_FunctionPrototypes
|
|
Jerome Coutant
1:917af0ca86df
|
84
|
* @{
|
|
Jerome Coutant
1:917af0ca86df
|
85
|
*/
|
|
Jerome Coutant
1:917af0ca86df
|
86
|
|
|
Jerome Coutant
1:917af0ca86df
|
87
|
/**
|
|
Jerome Coutant
1:917af0ca86df
|
88
|
* @}
|
|
Jerome Coutant
1:917af0ca86df
|
89
|
*/
|
|
Jerome Coutant
1:917af0ca86df
|
90
|
|
|
Jerome Coutant
1:917af0ca86df
|
91
|
/** @defgroup L3GD20_Private_Functions
|
|
Jerome Coutant
1:917af0ca86df
|
92
|
* @{
|
|
Jerome Coutant
1:917af0ca86df
|
93
|
*/
|
|
Jerome Coutant
1:917af0ca86df
|
94
|
|
|
Jerome Coutant
1:917af0ca86df
|
95
|
/**
|
|
Jerome Coutant
1:917af0ca86df
|
96
|
* @brief Set L3GD20 Initialization.
|
|
Jerome Coutant
1:917af0ca86df
|
97
|
* @param L3GD20_InitStruct: pointer to a L3GD20_InitTypeDef structure
|
|
Jerome Coutant
1:917af0ca86df
|
98
|
* that contains the configuration setting for the L3GD20.
|
|
Jerome Coutant
1:917af0ca86df
|
99
|
* @retval None
|
|
Jerome Coutant
1:917af0ca86df
|
100
|
*/
|
|
Jerome Coutant
1:917af0ca86df
|
101
|
void L3GD20_Init(uint16_t InitStruct)
|
|
Jerome Coutant
1:917af0ca86df
|
102
|
{
|
|
Jerome Coutant
1:917af0ca86df
|
103
|
uint8_t ctrl = 0x00;
|
|
Jerome Coutant
1:917af0ca86df
|
104
|
|
|
Jerome Coutant
1:917af0ca86df
|
105
|
/* Configure the low level interface */
|
|
Jerome Coutant
1:917af0ca86df
|
106
|
GYRO_IO_Init();
|
|
Jerome Coutant
1:917af0ca86df
|
107
|
|
|
Jerome Coutant
1:917af0ca86df
|
108
|
/* Write value to MEMS CTRL_REG1 register */
|
|
Jerome Coutant
1:917af0ca86df
|
109
|
ctrl = (uint8_t) InitStruct;
|
|
Jerome Coutant
1:917af0ca86df
|
110
|
GYRO_IO_Write(&ctrl, L3GD20_CTRL_REG1_ADDR, 1);
|
|
Jerome Coutant
1:917af0ca86df
|
111
|
|
|
Jerome Coutant
1:917af0ca86df
|
112
|
/* Write value to MEMS CTRL_REG4 register */
|
|
Jerome Coutant
1:917af0ca86df
|
113
|
ctrl = (uint8_t) (InitStruct >> 8);
|
|
Jerome Coutant
1:917af0ca86df
|
114
|
GYRO_IO_Write(&ctrl, L3GD20_CTRL_REG4_ADDR, 1);
|
|
Jerome Coutant
1:917af0ca86df
|
115
|
}
|
|
Jerome Coutant
1:917af0ca86df
|
116
|
|
|
Jerome Coutant
1:917af0ca86df
|
117
|
|
|
Jerome Coutant
1:917af0ca86df
|
118
|
|
|
Jerome Coutant
1:917af0ca86df
|
119
|
/**
|
|
Jerome Coutant
1:917af0ca86df
|
120
|
* @brief L3GD20 De-initialization
|
|
Jerome Coutant
1:917af0ca86df
|
121
|
* @param None
|
|
Jerome Coutant
1:917af0ca86df
|
122
|
* @retval None
|
|
Jerome Coutant
1:917af0ca86df
|
123
|
*/
|
|
Jerome Coutant
1:917af0ca86df
|
124
|
void L3GD20_DeInit(void)
|
|
Jerome Coutant
1:917af0ca86df
|
125
|
{
|
|
Jerome Coutant
1:917af0ca86df
|
126
|
}
|
|
Jerome Coutant
1:917af0ca86df
|
127
|
|
|
Jerome Coutant
1:917af0ca86df
|
128
|
/**
|
|
Jerome Coutant
1:917af0ca86df
|
129
|
* @brief Read ID address of L3GD20
|
|
Jerome Coutant
1:917af0ca86df
|
130
|
* @param None
|
|
Jerome Coutant
1:917af0ca86df
|
131
|
* @retval ID name
|
|
Jerome Coutant
1:917af0ca86df
|
132
|
*/
|
|
Jerome Coutant
1:917af0ca86df
|
133
|
uint8_t L3GD20_ReadID(void)
|
|
Jerome Coutant
1:917af0ca86df
|
134
|
{
|
|
Jerome Coutant
1:917af0ca86df
|
135
|
uint8_t tmp;
|
|
Jerome Coutant
1:917af0ca86df
|
136
|
|
|
Jerome Coutant
1:917af0ca86df
|
137
|
/* Configure the low level interface */
|
|
Jerome Coutant
1:917af0ca86df
|
138
|
GYRO_IO_Init();
|
|
Jerome Coutant
1:917af0ca86df
|
139
|
|
|
Jerome Coutant
1:917af0ca86df
|
140
|
/* Read WHO I AM register */
|
|
Jerome Coutant
1:917af0ca86df
|
141
|
GYRO_IO_Read(&tmp, L3GD20_WHO_AM_I_ADDR, 1);
|
|
Jerome Coutant
1:917af0ca86df
|
142
|
|
|
Jerome Coutant
1:917af0ca86df
|
143
|
/* Return the ID */
|
|
Jerome Coutant
1:917af0ca86df
|
144
|
return (uint8_t)tmp;
|
|
Jerome Coutant
1:917af0ca86df
|
145
|
}
|
|
Jerome Coutant
1:917af0ca86df
|
146
|
|
|
Jerome Coutant
1:917af0ca86df
|
147
|
/**
|
|
Jerome Coutant
1:917af0ca86df
|
148
|
* @brief Reboot memory content of L3GD20
|
|
Jerome Coutant
1:917af0ca86df
|
149
|
* @param None
|
|
Jerome Coutant
1:917af0ca86df
|
150
|
* @retval None
|
|
Jerome Coutant
1:917af0ca86df
|
151
|
*/
|
|
Jerome Coutant
1:917af0ca86df
|
152
|
void L3GD20_RebootCmd(void)
|
|
Jerome Coutant
1:917af0ca86df
|
153
|
{
|
|
Jerome Coutant
1:917af0ca86df
|
154
|
uint8_t tmpreg;
|
|
Jerome Coutant
1:917af0ca86df
|
155
|
|
|
Jerome Coutant
1:917af0ca86df
|
156
|
/* Read CTRL_REG5 register */
|
|
Jerome Coutant
1:917af0ca86df
|
157
|
GYRO_IO_Read(&tmpreg, L3GD20_CTRL_REG5_ADDR, 1);
|
|
Jerome Coutant
1:917af0ca86df
|
158
|
|
|
Jerome Coutant
1:917af0ca86df
|
159
|
/* Enable or Disable the reboot memory */
|
|
Jerome Coutant
1:917af0ca86df
|
160
|
tmpreg |= L3GD20_BOOT_REBOOTMEMORY;
|
|
Jerome Coutant
1:917af0ca86df
|
161
|
|
|
Jerome Coutant
1:917af0ca86df
|
162
|
/* Write value to MEMS CTRL_REG5 register */
|
|
Jerome Coutant
1:917af0ca86df
|
163
|
GYRO_IO_Write(&tmpreg, L3GD20_CTRL_REG5_ADDR, 1);
|
|
Jerome Coutant
1:917af0ca86df
|
164
|
}
|
|
Jerome Coutant
1:917af0ca86df
|
165
|
|
|
Jerome Coutant
1:917af0ca86df
|
166
|
/**
|
|
Jerome Coutant
1:917af0ca86df
|
167
|
* @brief Set L3GD20 in low-power mode
|
|
Jerome Coutant
1:917af0ca86df
|
168
|
* @param
|
|
Jerome Coutant
1:917af0ca86df
|
169
|
* @retval None
|
|
Jerome Coutant
1:917af0ca86df
|
170
|
*/
|
|
Jerome Coutant
1:917af0ca86df
|
171
|
void L3GD20_LowPower(uint16_t InitStruct)
|
|
Jerome Coutant
1:917af0ca86df
|
172
|
{
|
|
Jerome Coutant
1:917af0ca86df
|
173
|
uint8_t ctrl = 0x00;
|
|
Jerome Coutant
1:917af0ca86df
|
174
|
|
|
Jerome Coutant
1:917af0ca86df
|
175
|
/* Write value to MEMS CTRL_REG1 register */
|
|
Jerome Coutant
1:917af0ca86df
|
176
|
ctrl = (uint8_t) InitStruct;
|
|
Jerome Coutant
1:917af0ca86df
|
177
|
GYRO_IO_Write(&ctrl, L3GD20_CTRL_REG1_ADDR, 1);
|
|
Jerome Coutant
1:917af0ca86df
|
178
|
}
|
|
Jerome Coutant
1:917af0ca86df
|
179
|
|
|
Jerome Coutant
1:917af0ca86df
|
180
|
/**
|
|
Jerome Coutant
1:917af0ca86df
|
181
|
* @brief Set L3GD20 Interrupt INT1 configuration
|
|
Jerome Coutant
1:917af0ca86df
|
182
|
* @param Int1Config: the configuration setting for the L3GD20 Interrupt.
|
|
Jerome Coutant
1:917af0ca86df
|
183
|
* @retval None
|
|
Jerome Coutant
1:917af0ca86df
|
184
|
*/
|
|
Jerome Coutant
1:917af0ca86df
|
185
|
void L3GD20_INT1InterruptConfig(uint16_t Int1Config)
|
|
Jerome Coutant
1:917af0ca86df
|
186
|
{
|
|
Jerome Coutant
1:917af0ca86df
|
187
|
uint8_t ctrl_cfr = 0x00, ctrl3 = 0x00;
|
|
Jerome Coutant
1:917af0ca86df
|
188
|
|
|
Jerome Coutant
1:917af0ca86df
|
189
|
/* Read INT1_CFG register */
|
|
Jerome Coutant
1:917af0ca86df
|
190
|
GYRO_IO_Read(&ctrl_cfr, L3GD20_INT1_CFG_ADDR, 1);
|
|
Jerome Coutant
1:917af0ca86df
|
191
|
|
|
Jerome Coutant
1:917af0ca86df
|
192
|
/* Read CTRL_REG3 register */
|
|
Jerome Coutant
1:917af0ca86df
|
193
|
GYRO_IO_Read(&ctrl3, L3GD20_CTRL_REG3_ADDR, 1);
|
|
Jerome Coutant
1:917af0ca86df
|
194
|
|
|
Jerome Coutant
1:917af0ca86df
|
195
|
ctrl_cfr &= 0x80;
|
|
Jerome Coutant
1:917af0ca86df
|
196
|
ctrl_cfr |= ((uint8_t) Int1Config >> 8);
|
|
Jerome Coutant
1:917af0ca86df
|
197
|
|
|
Jerome Coutant
1:917af0ca86df
|
198
|
ctrl3 &= 0xDF;
|
|
Jerome Coutant
1:917af0ca86df
|
199
|
ctrl3 |= ((uint8_t) Int1Config);
|
|
Jerome Coutant
1:917af0ca86df
|
200
|
|
|
Jerome Coutant
1:917af0ca86df
|
201
|
/* Write value to MEMS INT1_CFG register */
|
|
Jerome Coutant
1:917af0ca86df
|
202
|
GYRO_IO_Write(&ctrl_cfr, L3GD20_INT1_CFG_ADDR, 1);
|
|
Jerome Coutant
1:917af0ca86df
|
203
|
|
|
Jerome Coutant
1:917af0ca86df
|
204
|
/* Write value to MEMS CTRL_REG3 register */
|
|
Jerome Coutant
1:917af0ca86df
|
205
|
GYRO_IO_Write(&ctrl3, L3GD20_CTRL_REG3_ADDR, 1);
|
|
Jerome Coutant
1:917af0ca86df
|
206
|
}
|
|
Jerome Coutant
1:917af0ca86df
|
207
|
|
|
Jerome Coutant
1:917af0ca86df
|
208
|
/**
|
|
Jerome Coutant
1:917af0ca86df
|
209
|
* @brief Enable INT1 or INT2 interrupt
|
|
Jerome Coutant
1:917af0ca86df
|
210
|
* @param IntSel: choice of INT1 or INT2
|
|
Jerome Coutant
1:917af0ca86df
|
211
|
* This parameter can be:
|
|
Jerome Coutant
1:917af0ca86df
|
212
|
* @arg L3GD20_INT1
|
|
Jerome Coutant
1:917af0ca86df
|
213
|
* @arg L3GD20_INT2
|
|
Jerome Coutant
1:917af0ca86df
|
214
|
* @retval None
|
|
Jerome Coutant
1:917af0ca86df
|
215
|
*/
|
|
Jerome Coutant
1:917af0ca86df
|
216
|
void L3GD20_EnableIT(uint8_t IntSel)
|
|
Jerome Coutant
1:917af0ca86df
|
217
|
{
|
|
Jerome Coutant
1:917af0ca86df
|
218
|
uint8_t tmpreg;
|
|
Jerome Coutant
1:917af0ca86df
|
219
|
|
|
Jerome Coutant
1:917af0ca86df
|
220
|
/* Read CTRL_REG3 register */
|
|
Jerome Coutant
1:917af0ca86df
|
221
|
GYRO_IO_Read(&tmpreg, L3GD20_CTRL_REG3_ADDR, 1);
|
|
Jerome Coutant
1:917af0ca86df
|
222
|
|
|
Jerome Coutant
1:917af0ca86df
|
223
|
if(IntSel == L3GD20_INT1)
|
|
Jerome Coutant
1:917af0ca86df
|
224
|
{
|
|
Jerome Coutant
1:917af0ca86df
|
225
|
tmpreg &= 0x7F;
|
|
Jerome Coutant
1:917af0ca86df
|
226
|
tmpreg |= L3GD20_INT1INTERRUPT_ENABLE;
|
|
Jerome Coutant
1:917af0ca86df
|
227
|
}
|
|
Jerome Coutant
1:917af0ca86df
|
228
|
else if(IntSel == L3GD20_INT2)
|
|
Jerome Coutant
1:917af0ca86df
|
229
|
{
|
|
Jerome Coutant
1:917af0ca86df
|
230
|
tmpreg &= 0xF7;
|
|
Jerome Coutant
1:917af0ca86df
|
231
|
tmpreg |= L3GD20_INT2INTERRUPT_ENABLE;
|
|
Jerome Coutant
1:917af0ca86df
|
232
|
}
|
|
Jerome Coutant
1:917af0ca86df
|
233
|
|
|
Jerome Coutant
1:917af0ca86df
|
234
|
/* Write value to MEMS CTRL_REG3 register */
|
|
Jerome Coutant
1:917af0ca86df
|
235
|
GYRO_IO_Write(&tmpreg, L3GD20_CTRL_REG3_ADDR, 1);
|
|
Jerome Coutant
1:917af0ca86df
|
236
|
}
|
|
Jerome Coutant
1:917af0ca86df
|
237
|
|
|
Jerome Coutant
1:917af0ca86df
|
238
|
/**
|
|
Jerome Coutant
1:917af0ca86df
|
239
|
* @brief Disable INT1 or INT2 interrupt
|
|
Jerome Coutant
1:917af0ca86df
|
240
|
* @param IntSel: choice of INT1 or INT2
|
|
Jerome Coutant
1:917af0ca86df
|
241
|
* This parameter can be:
|
|
Jerome Coutant
1:917af0ca86df
|
242
|
* @arg L3GD20_INT1
|
|
Jerome Coutant
1:917af0ca86df
|
243
|
* @arg L3GD20_INT2
|
|
Jerome Coutant
1:917af0ca86df
|
244
|
* @retval None
|
|
Jerome Coutant
1:917af0ca86df
|
245
|
*/
|
|
Jerome Coutant
1:917af0ca86df
|
246
|
void L3GD20_DisableIT(uint8_t IntSel)
|
|
Jerome Coutant
1:917af0ca86df
|
247
|
{
|
|
Jerome Coutant
1:917af0ca86df
|
248
|
uint8_t tmpreg;
|
|
Jerome Coutant
1:917af0ca86df
|
249
|
|
|
Jerome Coutant
1:917af0ca86df
|
250
|
/* Read CTRL_REG3 register */
|
|
Jerome Coutant
1:917af0ca86df
|
251
|
GYRO_IO_Read(&tmpreg, L3GD20_CTRL_REG3_ADDR, 1);
|
|
Jerome Coutant
1:917af0ca86df
|
252
|
|
|
Jerome Coutant
1:917af0ca86df
|
253
|
if(IntSel == L3GD20_INT1)
|
|
Jerome Coutant
1:917af0ca86df
|
254
|
{
|
|
Jerome Coutant
1:917af0ca86df
|
255
|
tmpreg &= 0x7F;
|
|
Jerome Coutant
1:917af0ca86df
|
256
|
tmpreg |= L3GD20_INT1INTERRUPT_DISABLE;
|
|
Jerome Coutant
1:917af0ca86df
|
257
|
}
|
|
Jerome Coutant
1:917af0ca86df
|
258
|
else if(IntSel == L3GD20_INT2)
|
|
Jerome Coutant
1:917af0ca86df
|
259
|
{
|
|
Jerome Coutant
1:917af0ca86df
|
260
|
tmpreg &= 0xF7;
|
|
Jerome Coutant
1:917af0ca86df
|
261
|
tmpreg |= L3GD20_INT2INTERRUPT_DISABLE;
|
|
Jerome Coutant
1:917af0ca86df
|
262
|
}
|
|
Jerome Coutant
1:917af0ca86df
|
263
|
|
|
Jerome Coutant
1:917af0ca86df
|
264
|
/* Write value to MEMS CTRL_REG3 register */
|
|
Jerome Coutant
1:917af0ca86df
|
265
|
GYRO_IO_Write(&tmpreg, L3GD20_CTRL_REG3_ADDR, 1);
|
|
Jerome Coutant
1:917af0ca86df
|
266
|
}
|
|
Jerome Coutant
1:917af0ca86df
|
267
|
|
|
Jerome Coutant
1:917af0ca86df
|
268
|
/**
|
|
Jerome Coutant
1:917af0ca86df
|
269
|
* @brief Set High Pass Filter Modality
|
|
Jerome Coutant
1:917af0ca86df
|
270
|
* @param FilterStruct: contains the configuration setting for the L3GD20.
|
|
Jerome Coutant
1:917af0ca86df
|
271
|
* @retval None
|
|
Jerome Coutant
1:917af0ca86df
|
272
|
*/
|
|
Jerome Coutant
1:917af0ca86df
|
273
|
void L3GD20_FilterConfig(uint8_t FilterStruct)
|
|
Jerome Coutant
1:917af0ca86df
|
274
|
{
|
|
Jerome Coutant
1:917af0ca86df
|
275
|
uint8_t tmpreg;
|
|
Jerome Coutant
1:917af0ca86df
|
276
|
|
|
Jerome Coutant
1:917af0ca86df
|
277
|
/* Read CTRL_REG2 register */
|
|
Jerome Coutant
1:917af0ca86df
|
278
|
GYRO_IO_Read(&tmpreg, L3GD20_CTRL_REG2_ADDR, 1);
|
|
Jerome Coutant
1:917af0ca86df
|
279
|
|
|
Jerome Coutant
1:917af0ca86df
|
280
|
tmpreg &= 0xC0;
|
|
Jerome Coutant
1:917af0ca86df
|
281
|
|
|
Jerome Coutant
1:917af0ca86df
|
282
|
/* Configure MEMS: mode and cutoff frequency */
|
|
Jerome Coutant
1:917af0ca86df
|
283
|
tmpreg |= FilterStruct;
|
|
Jerome Coutant
1:917af0ca86df
|
284
|
|
|
Jerome Coutant
1:917af0ca86df
|
285
|
/* Write value to MEMS CTRL_REG2 register */
|
|
Jerome Coutant
1:917af0ca86df
|
286
|
GYRO_IO_Write(&tmpreg, L3GD20_CTRL_REG2_ADDR, 1);
|
|
Jerome Coutant
1:917af0ca86df
|
287
|
}
|
|
Jerome Coutant
1:917af0ca86df
|
288
|
|
|
Jerome Coutant
1:917af0ca86df
|
289
|
/**
|
|
Jerome Coutant
1:917af0ca86df
|
290
|
* @brief Enable or Disable High Pass Filter
|
|
Jerome Coutant
1:917af0ca86df
|
291
|
* @param HighPassFilterState: new state of the High Pass Filter feature.
|
|
Jerome Coutant
1:917af0ca86df
|
292
|
* This parameter can be:
|
|
Jerome Coutant
1:917af0ca86df
|
293
|
* @arg: L3GD20_HIGHPASSFILTER_DISABLE
|
|
Jerome Coutant
1:917af0ca86df
|
294
|
* @arg: L3GD20_HIGHPASSFILTER_ENABLE
|
|
Jerome Coutant
1:917af0ca86df
|
295
|
* @retval None
|
|
Jerome Coutant
1:917af0ca86df
|
296
|
*/
|
|
Jerome Coutant
1:917af0ca86df
|
297
|
void L3GD20_FilterCmd(uint8_t HighPassFilterState)
|
|
Jerome Coutant
1:917af0ca86df
|
298
|
{
|
|
Jerome Coutant
1:917af0ca86df
|
299
|
uint8_t tmpreg;
|
|
Jerome Coutant
1:917af0ca86df
|
300
|
|
|
Jerome Coutant
1:917af0ca86df
|
301
|
/* Read CTRL_REG5 register */
|
|
Jerome Coutant
1:917af0ca86df
|
302
|
GYRO_IO_Read(&tmpreg, L3GD20_CTRL_REG5_ADDR, 1);
|
|
Jerome Coutant
1:917af0ca86df
|
303
|
|
|
Jerome Coutant
1:917af0ca86df
|
304
|
tmpreg &= 0xEF;
|
|
Jerome Coutant
1:917af0ca86df
|
305
|
|
|
Jerome Coutant
1:917af0ca86df
|
306
|
tmpreg |= HighPassFilterState;
|
|
Jerome Coutant
1:917af0ca86df
|
307
|
|
|
Jerome Coutant
1:917af0ca86df
|
308
|
/* Write value to MEMS CTRL_REG5 register */
|
|
Jerome Coutant
1:917af0ca86df
|
309
|
GYRO_IO_Write(&tmpreg, L3GD20_CTRL_REG5_ADDR, 1);
|
|
Jerome Coutant
1:917af0ca86df
|
310
|
}
|
|
Jerome Coutant
1:917af0ca86df
|
311
|
|
|
Jerome Coutant
1:917af0ca86df
|
312
|
/**
|
|
Jerome Coutant
1:917af0ca86df
|
313
|
* @brief Get status for L3GD20 data
|
|
Jerome Coutant
1:917af0ca86df
|
314
|
* @param None
|
|
Jerome Coutant
1:917af0ca86df
|
315
|
* @retval Data status in a L3GD20 Data
|
|
Jerome Coutant
1:917af0ca86df
|
316
|
*/
|
|
Jerome Coutant
1:917af0ca86df
|
317
|
uint8_t L3GD20_GetDataStatus(void)
|
|
Jerome Coutant
1:917af0ca86df
|
318
|
{
|
|
Jerome Coutant
1:917af0ca86df
|
319
|
uint8_t tmpreg;
|
|
Jerome Coutant
1:917af0ca86df
|
320
|
|
|
Jerome Coutant
1:917af0ca86df
|
321
|
/* Read STATUS_REG register */
|
|
Jerome Coutant
1:917af0ca86df
|
322
|
GYRO_IO_Read(&tmpreg, L3GD20_STATUS_REG_ADDR, 1);
|
|
Jerome Coutant
1:917af0ca86df
|
323
|
|
|
Jerome Coutant
1:917af0ca86df
|
324
|
return tmpreg;
|
|
Jerome Coutant
1:917af0ca86df
|
325
|
}
|
|
Jerome Coutant
1:917af0ca86df
|
326
|
|
|
Jerome Coutant
1:917af0ca86df
|
327
|
/**
|
|
Jerome Coutant
1:917af0ca86df
|
328
|
* @brief Calculate the L3GD20 angular data.
|
|
Jerome Coutant
1:917af0ca86df
|
329
|
* @param pfData: Data out pointer
|
|
Jerome Coutant
1:917af0ca86df
|
330
|
* @retval None
|
|
Jerome Coutant
1:917af0ca86df
|
331
|
*/
|
|
Jerome Coutant
1:917af0ca86df
|
332
|
void L3GD20_ReadXYZAngRate(float *pfData)
|
|
Jerome Coutant
1:917af0ca86df
|
333
|
{
|
|
Jerome Coutant
1:917af0ca86df
|
334
|
uint8_t tmpbuffer[6] ={0};
|
|
Jerome Coutant
1:917af0ca86df
|
335
|
int16_t RawData[3] = {0};
|
|
Jerome Coutant
1:917af0ca86df
|
336
|
uint8_t tmpreg = 0;
|
|
Jerome Coutant
1:917af0ca86df
|
337
|
float sensitivity = 0;
|
|
Jerome Coutant
1:917af0ca86df
|
338
|
int i =0;
|
|
Jerome Coutant
1:917af0ca86df
|
339
|
|
|
Jerome Coutant
1:917af0ca86df
|
340
|
GYRO_IO_Read(&tmpreg,L3GD20_CTRL_REG4_ADDR,1);
|
|
Jerome Coutant
1:917af0ca86df
|
341
|
|
|
Jerome Coutant
1:917af0ca86df
|
342
|
GYRO_IO_Read(tmpbuffer,L3GD20_OUT_X_L_ADDR,6);
|
|
Jerome Coutant
1:917af0ca86df
|
343
|
|
|
Jerome Coutant
1:917af0ca86df
|
344
|
/* check in the control register 4 the data alignment (Big Endian or Little Endian)*/
|
|
Jerome Coutant
1:917af0ca86df
|
345
|
if(!(tmpreg & L3GD20_BLE_MSB))
|
|
Jerome Coutant
1:917af0ca86df
|
346
|
{
|
|
Jerome Coutant
1:917af0ca86df
|
347
|
for(i=0; i<3; i++)
|
|
Jerome Coutant
1:917af0ca86df
|
348
|
{
|
|
Jerome Coutant
1:917af0ca86df
|
349
|
RawData[i]=(int16_t)(((uint16_t)tmpbuffer[2*i+1] << 8) + tmpbuffer[2*i]);
|
|
Jerome Coutant
1:917af0ca86df
|
350
|
}
|
|
Jerome Coutant
1:917af0ca86df
|
351
|
}
|
|
Jerome Coutant
1:917af0ca86df
|
352
|
else
|
|
Jerome Coutant
1:917af0ca86df
|
353
|
{
|
|
Jerome Coutant
1:917af0ca86df
|
354
|
for(i=0; i<3; i++)
|
|
Jerome Coutant
1:917af0ca86df
|
355
|
{
|
|
Jerome Coutant
1:917af0ca86df
|
356
|
RawData[i]=(int16_t)(((uint16_t)tmpbuffer[2*i] << 8) + tmpbuffer[2*i+1]);
|
|
Jerome Coutant
1:917af0ca86df
|
357
|
}
|
|
Jerome Coutant
1:917af0ca86df
|
358
|
}
|
|
Jerome Coutant
1:917af0ca86df
|
359
|
|
|
Jerome Coutant
1:917af0ca86df
|
360
|
/* Switch the sensitivity value set in the CRTL4 */
|
|
Jerome Coutant
1:917af0ca86df
|
361
|
switch(tmpreg & L3GD20_FULLSCALE_SELECTION)
|
|
Jerome Coutant
1:917af0ca86df
|
362
|
{
|
|
Jerome Coutant
1:917af0ca86df
|
363
|
case L3GD20_FULLSCALE_250:
|
|
Jerome Coutant
1:917af0ca86df
|
364
|
sensitivity=L3GD20_SENSITIVITY_250DPS;
|
|
Jerome Coutant
1:917af0ca86df
|
365
|
break;
|
|
Jerome Coutant
1:917af0ca86df
|
366
|
|
|
Jerome Coutant
1:917af0ca86df
|
367
|
case L3GD20_FULLSCALE_500:
|
|
Jerome Coutant
1:917af0ca86df
|
368
|
sensitivity=L3GD20_SENSITIVITY_500DPS;
|
|
Jerome Coutant
1:917af0ca86df
|
369
|
break;
|
|
Jerome Coutant
1:917af0ca86df
|
370
|
|
|
Jerome Coutant
1:917af0ca86df
|
371
|
case L3GD20_FULLSCALE_2000:
|
|
Jerome Coutant
1:917af0ca86df
|
372
|
sensitivity=L3GD20_SENSITIVITY_2000DPS;
|
|
Jerome Coutant
1:917af0ca86df
|
373
|
break;
|
|
Jerome Coutant
1:917af0ca86df
|
374
|
}
|
|
Jerome Coutant
1:917af0ca86df
|
375
|
/* Divide by sensitivity */
|
|
Jerome Coutant
1:917af0ca86df
|
376
|
for(i=0; i<3; i++)
|
|
Jerome Coutant
1:917af0ca86df
|
377
|
{
|
|
Jerome Coutant
1:917af0ca86df
|
378
|
pfData[i]=(float)(RawData[i] * sensitivity);
|
|
Jerome Coutant
1:917af0ca86df
|
379
|
}
|
|
Jerome Coutant
1:917af0ca86df
|
380
|
}
|
|
Jerome Coutant
1:917af0ca86df
|
381
|
|
|
Jerome Coutant
1:917af0ca86df
|
382
|
/**
|
|
Jerome Coutant
1:917af0ca86df
|
383
|
* @}
|
|
Jerome Coutant
1:917af0ca86df
|
384
|
*/
|
|
Jerome Coutant
1:917af0ca86df
|
385
|
|
|
Jerome Coutant
1:917af0ca86df
|
386
|
/**
|
|
Jerome Coutant
1:917af0ca86df
|
387
|
* @}
|
|
Jerome Coutant
1:917af0ca86df
|
388
|
*/
|
|
Jerome Coutant
1:917af0ca86df
|
389
|
|
|
Jerome Coutant
1:917af0ca86df
|
390
|
/**
|
|
Jerome Coutant
1:917af0ca86df
|
391
|
* @}
|
|
Jerome Coutant
1:917af0ca86df
|
392
|
*/
|
|
Jerome Coutant
1:917af0ca86df
|
393
|
|
|
Jerome Coutant
1:917af0ca86df
|
394
|
/**
|
|
Jerome Coutant
1:917af0ca86df
|
395
|
* @}
|
|
Jerome Coutant
1:917af0ca86df
|
396
|
*/
|
|
Jerome Coutant
1:917af0ca86df
|
397
|
|
|
Jerome Coutant
1:917af0ca86df
|
398
|
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
|