Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Drivers/BSP/Components/l3gd20/l3gd20.c@1:917af0ca86df, 2017-07-05 (annotated)
- Committer:
- Jerome Coutant
- Date:
- Wed Jul 05 10:51:49 2017 +0200
- Revision:
- 1:917af0ca86df
- Child:
- 5:4943b15cce9f
Update with STM32Cube_FW_L4_V1.8.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
|
* @version V2.0.0
|
|
Jerome Coutant
1:917af0ca86df
|
6
|
* @date 26-June-2015
|
|
Jerome Coutant
1:917af0ca86df
|
7
|
* @brief This file provides a set of functions needed to manage the L3GD20,
|
|
Jerome Coutant
1:917af0ca86df
|
8
|
* ST MEMS motion sensor, 3-axis digital output gyroscope.
|
|
Jerome Coutant
1:917af0ca86df
|
9
|
******************************************************************************
|
|
Jerome Coutant
1:917af0ca86df
|
10
|
* @attention
|
|
Jerome Coutant
1:917af0ca86df
|
11
|
*
|
|
Jerome Coutant
1:917af0ca86df
|
12
|
* <h2><center>© COPYRIGHT(c) 2015 STMicroelectronics</center></h2>
|
|
Jerome Coutant
1:917af0ca86df
|
13
|
*
|
|
Jerome Coutant
1:917af0ca86df
|
14
|
* Redistribution and use in source and binary forms, with or without modification,
|
|
Jerome Coutant
1:917af0ca86df
|
15
|
* are permitted provided that the following conditions are met:
|
|
Jerome Coutant
1:917af0ca86df
|
16
|
* 1. Redistributions of source code must retain the above copyright notice,
|
|
Jerome Coutant
1:917af0ca86df
|
17
|
* this list of conditions and the following disclaimer.
|
|
Jerome Coutant
1:917af0ca86df
|
18
|
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
|
Jerome Coutant
1:917af0ca86df
|
19
|
* this list of conditions and the following disclaimer in the documentation
|
|
Jerome Coutant
1:917af0ca86df
|
20
|
* and/or other materials provided with the distribution.
|
|
Jerome Coutant
1:917af0ca86df
|
21
|
* 3. Neither the name of STMicroelectronics nor the names of its contributors
|
|
Jerome Coutant
1:917af0ca86df
|
22
|
* may be used to endorse or promote products derived from this software
|
|
Jerome Coutant
1:917af0ca86df
|
23
|
* without specific prior written permission.
|
|
Jerome Coutant
1:917af0ca86df
|
24
|
*
|
|
Jerome Coutant
1:917af0ca86df
|
25
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
Jerome Coutant
1:917af0ca86df
|
26
|
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
Jerome Coutant
1:917af0ca86df
|
27
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
Jerome Coutant
1:917af0ca86df
|
28
|
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
|
Jerome Coutant
1:917af0ca86df
|
29
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
Jerome Coutant
1:917af0ca86df
|
30
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
Jerome Coutant
1:917af0ca86df
|
31
|
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
|
Jerome Coutant
1:917af0ca86df
|
32
|
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
|
Jerome Coutant
1:917af0ca86df
|
33
|
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
Jerome Coutant
1:917af0ca86df
|
34
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
Jerome Coutant
1:917af0ca86df
|
35
|
*
|
|
Jerome Coutant
1:917af0ca86df
|
36
|
******************************************************************************
|
|
Jerome Coutant
1:917af0ca86df
|
37
|
*/
|
|
Jerome Coutant
1:917af0ca86df
|
38
|
/* Includes ------------------------------------------------------------------*/
|
|
Jerome Coutant
1:917af0ca86df
|
39
|
#include "l3gd20.h"
|
|
Jerome Coutant
1:917af0ca86df
|
40
|
|
|
Jerome Coutant
1:917af0ca86df
|
41
|
/** @addtogroup BSP
|
|
Jerome Coutant
1:917af0ca86df
|
42
|
* @{
|
|
Jerome Coutant
1:917af0ca86df
|
43
|
*/
|
|
Jerome Coutant
1:917af0ca86df
|
44
|
|
|
Jerome Coutant
1:917af0ca86df
|
45
|
/** @addtogroup Components
|
|
Jerome Coutant
1:917af0ca86df
|
46
|
* @{
|
|
Jerome Coutant
1:917af0ca86df
|
47
|
*/
|
|
Jerome Coutant
1:917af0ca86df
|
48
|
|
|
Jerome Coutant
1:917af0ca86df
|
49
|
/** @addtogroup L3GD20
|
|
Jerome Coutant
1:917af0ca86df
|
50
|
* @{
|
|
Jerome Coutant
1:917af0ca86df
|
51
|
*/
|
|
Jerome Coutant
1:917af0ca86df
|
52
|
|
|
Jerome Coutant
1:917af0ca86df
|
53
|
/** @defgroup L3GD20_Private_TypesDefinitions
|
|
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
|
*/
|
|
Jerome Coutant
1:917af0ca86df
|
60
|
|
|
Jerome Coutant
1:917af0ca86df
|
61
|
/** @defgroup L3GD20_Private_Defines
|
|
Jerome Coutant
1:917af0ca86df
|
62
|
* @{
|
|
Jerome Coutant
1:917af0ca86df
|
63
|
*/
|
|
Jerome Coutant
1:917af0ca86df
|
64
|
|
|
Jerome Coutant
1:917af0ca86df
|
65
|
/**
|
|
Jerome Coutant
1:917af0ca86df
|
66
|
* @}
|
|
Jerome Coutant
1:917af0ca86df
|
67
|
*/
|
|
Jerome Coutant
1:917af0ca86df
|
68
|
|
|
Jerome Coutant
1:917af0ca86df
|
69
|
/** @defgroup L3GD20_Private_Macros
|
|
Jerome Coutant
1:917af0ca86df
|
70
|
* @{
|
|
Jerome Coutant
1:917af0ca86df
|
71
|
*/
|
|
Jerome Coutant
1:917af0ca86df
|
72
|
|
|
Jerome Coutant
1:917af0ca86df
|
73
|
/**
|
|
Jerome Coutant
1:917af0ca86df
|
74
|
* @}
|
|
Jerome Coutant
1:917af0ca86df
|
75
|
*/
|
|
Jerome Coutant
1:917af0ca86df
|
76
|
|
|
Jerome Coutant
1:917af0ca86df
|
77
|
/** @defgroup L3GD20_Private_Variables
|
|
Jerome Coutant
1:917af0ca86df
|
78
|
* @{
|
|
Jerome Coutant
1:917af0ca86df
|
79
|
*/
|
|
Jerome Coutant
1:917af0ca86df
|
80
|
GYRO_DrvTypeDef L3gd20Drv =
|
|
Jerome Coutant
1:917af0ca86df
|
81
|
{
|
|
Jerome Coutant
1:917af0ca86df
|
82
|
L3GD20_Init,
|
|
Jerome Coutant
1:917af0ca86df
|
83
|
L3GD20_DeInit,
|
|
Jerome Coutant
1:917af0ca86df
|
84
|
L3GD20_ReadID,
|
|
Jerome Coutant
1:917af0ca86df
|
85
|
L3GD20_RebootCmd,
|
|
Jerome Coutant
1:917af0ca86df
|
86
|
L3GD20_LowPower,
|
|
Jerome Coutant
1:917af0ca86df
|
87
|
L3GD20_INT1InterruptConfig,
|
|
Jerome Coutant
1:917af0ca86df
|
88
|
L3GD20_EnableIT,
|
|
Jerome Coutant
1:917af0ca86df
|
89
|
L3GD20_DisableIT,
|
|
Jerome Coutant
1:917af0ca86df
|
90
|
0,
|
|
Jerome Coutant
1:917af0ca86df
|
91
|
0,
|
|
Jerome Coutant
1:917af0ca86df
|
92
|
L3GD20_FilterConfig,
|
|
Jerome Coutant
1:917af0ca86df
|
93
|
L3GD20_FilterCmd,
|
|
Jerome Coutant
1:917af0ca86df
|
94
|
L3GD20_ReadXYZAngRate
|
|
Jerome Coutant
1:917af0ca86df
|
95
|
};
|
|
Jerome Coutant
1:917af0ca86df
|
96
|
|
|
Jerome Coutant
1:917af0ca86df
|
97
|
/**
|
|
Jerome Coutant
1:917af0ca86df
|
98
|
* @}
|
|
Jerome Coutant
1:917af0ca86df
|
99
|
*/
|
|
Jerome Coutant
1:917af0ca86df
|
100
|
|
|
Jerome Coutant
1:917af0ca86df
|
101
|
/** @defgroup L3GD20_Private_FunctionPrototypes
|
|
Jerome Coutant
1:917af0ca86df
|
102
|
* @{
|
|
Jerome Coutant
1:917af0ca86df
|
103
|
*/
|
|
Jerome Coutant
1:917af0ca86df
|
104
|
|
|
Jerome Coutant
1:917af0ca86df
|
105
|
/**
|
|
Jerome Coutant
1:917af0ca86df
|
106
|
* @}
|
|
Jerome Coutant
1:917af0ca86df
|
107
|
*/
|
|
Jerome Coutant
1:917af0ca86df
|
108
|
|
|
Jerome Coutant
1:917af0ca86df
|
109
|
/** @defgroup L3GD20_Private_Functions
|
|
Jerome Coutant
1:917af0ca86df
|
110
|
* @{
|
|
Jerome Coutant
1:917af0ca86df
|
111
|
*/
|
|
Jerome Coutant
1:917af0ca86df
|
112
|
|
|
Jerome Coutant
1:917af0ca86df
|
113
|
/**
|
|
Jerome Coutant
1:917af0ca86df
|
114
|
* @brief Set L3GD20 Initialization.
|
|
Jerome Coutant
1:917af0ca86df
|
115
|
* @param L3GD20_InitStruct: pointer to a L3GD20_InitTypeDef structure
|
|
Jerome Coutant
1:917af0ca86df
|
116
|
* that contains the configuration setting for the L3GD20.
|
|
Jerome Coutant
1:917af0ca86df
|
117
|
* @retval None
|
|
Jerome Coutant
1:917af0ca86df
|
118
|
*/
|
|
Jerome Coutant
1:917af0ca86df
|
119
|
void L3GD20_Init(uint16_t InitStruct)
|
|
Jerome Coutant
1:917af0ca86df
|
120
|
{
|
|
Jerome Coutant
1:917af0ca86df
|
121
|
uint8_t ctrl = 0x00;
|
|
Jerome Coutant
1:917af0ca86df
|
122
|
|
|
Jerome Coutant
1:917af0ca86df
|
123
|
/* Configure the low level interface */
|
|
Jerome Coutant
1:917af0ca86df
|
124
|
GYRO_IO_Init();
|
|
Jerome Coutant
1:917af0ca86df
|
125
|
|
|
Jerome Coutant
1:917af0ca86df
|
126
|
/* Write value to MEMS CTRL_REG1 register */
|
|
Jerome Coutant
1:917af0ca86df
|
127
|
ctrl = (uint8_t) InitStruct;
|
|
Jerome Coutant
1:917af0ca86df
|
128
|
GYRO_IO_Write(&ctrl, L3GD20_CTRL_REG1_ADDR, 1);
|
|
Jerome Coutant
1:917af0ca86df
|
129
|
|
|
Jerome Coutant
1:917af0ca86df
|
130
|
/* Write value to MEMS CTRL_REG4 register */
|
|
Jerome Coutant
1:917af0ca86df
|
131
|
ctrl = (uint8_t) (InitStruct >> 8);
|
|
Jerome Coutant
1:917af0ca86df
|
132
|
GYRO_IO_Write(&ctrl, L3GD20_CTRL_REG4_ADDR, 1);
|
|
Jerome Coutant
1:917af0ca86df
|
133
|
}
|
|
Jerome Coutant
1:917af0ca86df
|
134
|
|
|
Jerome Coutant
1:917af0ca86df
|
135
|
|
|
Jerome Coutant
1:917af0ca86df
|
136
|
|
|
Jerome Coutant
1:917af0ca86df
|
137
|
/**
|
|
Jerome Coutant
1:917af0ca86df
|
138
|
* @brief L3GD20 De-initialization
|
|
Jerome Coutant
1:917af0ca86df
|
139
|
* @param None
|
|
Jerome Coutant
1:917af0ca86df
|
140
|
* @retval None
|
|
Jerome Coutant
1:917af0ca86df
|
141
|
*/
|
|
Jerome Coutant
1:917af0ca86df
|
142
|
void L3GD20_DeInit(void)
|
|
Jerome Coutant
1:917af0ca86df
|
143
|
{
|
|
Jerome Coutant
1:917af0ca86df
|
144
|
}
|
|
Jerome Coutant
1:917af0ca86df
|
145
|
|
|
Jerome Coutant
1:917af0ca86df
|
146
|
/**
|
|
Jerome Coutant
1:917af0ca86df
|
147
|
* @brief Read ID address of L3GD20
|
|
Jerome Coutant
1:917af0ca86df
|
148
|
* @param None
|
|
Jerome Coutant
1:917af0ca86df
|
149
|
* @retval ID name
|
|
Jerome Coutant
1:917af0ca86df
|
150
|
*/
|
|
Jerome Coutant
1:917af0ca86df
|
151
|
uint8_t L3GD20_ReadID(void)
|
|
Jerome Coutant
1:917af0ca86df
|
152
|
{
|
|
Jerome Coutant
1:917af0ca86df
|
153
|
uint8_t tmp;
|
|
Jerome Coutant
1:917af0ca86df
|
154
|
|
|
Jerome Coutant
1:917af0ca86df
|
155
|
/* Configure the low level interface */
|
|
Jerome Coutant
1:917af0ca86df
|
156
|
GYRO_IO_Init();
|
|
Jerome Coutant
1:917af0ca86df
|
157
|
|
|
Jerome Coutant
1:917af0ca86df
|
158
|
/* Read WHO I AM register */
|
|
Jerome Coutant
1:917af0ca86df
|
159
|
GYRO_IO_Read(&tmp, L3GD20_WHO_AM_I_ADDR, 1);
|
|
Jerome Coutant
1:917af0ca86df
|
160
|
|
|
Jerome Coutant
1:917af0ca86df
|
161
|
/* Return the ID */
|
|
Jerome Coutant
1:917af0ca86df
|
162
|
return (uint8_t)tmp;
|
|
Jerome Coutant
1:917af0ca86df
|
163
|
}
|
|
Jerome Coutant
1:917af0ca86df
|
164
|
|
|
Jerome Coutant
1:917af0ca86df
|
165
|
/**
|
|
Jerome Coutant
1:917af0ca86df
|
166
|
* @brief Reboot memory content of L3GD20
|
|
Jerome Coutant
1:917af0ca86df
|
167
|
* @param None
|
|
Jerome Coutant
1:917af0ca86df
|
168
|
* @retval None
|
|
Jerome Coutant
1:917af0ca86df
|
169
|
*/
|
|
Jerome Coutant
1:917af0ca86df
|
170
|
void L3GD20_RebootCmd(void)
|
|
Jerome Coutant
1:917af0ca86df
|
171
|
{
|
|
Jerome Coutant
1:917af0ca86df
|
172
|
uint8_t tmpreg;
|
|
Jerome Coutant
1:917af0ca86df
|
173
|
|
|
Jerome Coutant
1:917af0ca86df
|
174
|
/* Read CTRL_REG5 register */
|
|
Jerome Coutant
1:917af0ca86df
|
175
|
GYRO_IO_Read(&tmpreg, L3GD20_CTRL_REG5_ADDR, 1);
|
|
Jerome Coutant
1:917af0ca86df
|
176
|
|
|
Jerome Coutant
1:917af0ca86df
|
177
|
/* Enable or Disable the reboot memory */
|
|
Jerome Coutant
1:917af0ca86df
|
178
|
tmpreg |= L3GD20_BOOT_REBOOTMEMORY;
|
|
Jerome Coutant
1:917af0ca86df
|
179
|
|
|
Jerome Coutant
1:917af0ca86df
|
180
|
/* Write value to MEMS CTRL_REG5 register */
|
|
Jerome Coutant
1:917af0ca86df
|
181
|
GYRO_IO_Write(&tmpreg, L3GD20_CTRL_REG5_ADDR, 1);
|
|
Jerome Coutant
1:917af0ca86df
|
182
|
}
|
|
Jerome Coutant
1:917af0ca86df
|
183
|
|
|
Jerome Coutant
1:917af0ca86df
|
184
|
/**
|
|
Jerome Coutant
1:917af0ca86df
|
185
|
* @brief Set L3GD20 in low-power mode
|
|
Jerome Coutant
1:917af0ca86df
|
186
|
* @param
|
|
Jerome Coutant
1:917af0ca86df
|
187
|
* @retval None
|
|
Jerome Coutant
1:917af0ca86df
|
188
|
*/
|
|
Jerome Coutant
1:917af0ca86df
|
189
|
void L3GD20_LowPower(uint16_t InitStruct)
|
|
Jerome Coutant
1:917af0ca86df
|
190
|
{
|
|
Jerome Coutant
1:917af0ca86df
|
191
|
uint8_t ctrl = 0x00;
|
|
Jerome Coutant
1:917af0ca86df
|
192
|
|
|
Jerome Coutant
1:917af0ca86df
|
193
|
/* Write value to MEMS CTRL_REG1 register */
|
|
Jerome Coutant
1:917af0ca86df
|
194
|
ctrl = (uint8_t) InitStruct;
|
|
Jerome Coutant
1:917af0ca86df
|
195
|
GYRO_IO_Write(&ctrl, L3GD20_CTRL_REG1_ADDR, 1);
|
|
Jerome Coutant
1:917af0ca86df
|
196
|
}
|
|
Jerome Coutant
1:917af0ca86df
|
197
|
|
|
Jerome Coutant
1:917af0ca86df
|
198
|
/**
|
|
Jerome Coutant
1:917af0ca86df
|
199
|
* @brief Set L3GD20 Interrupt INT1 configuration
|
|
Jerome Coutant
1:917af0ca86df
|
200
|
* @param Int1Config: the configuration setting for the L3GD20 Interrupt.
|
|
Jerome Coutant
1:917af0ca86df
|
201
|
* @retval None
|
|
Jerome Coutant
1:917af0ca86df
|
202
|
*/
|
|
Jerome Coutant
1:917af0ca86df
|
203
|
void L3GD20_INT1InterruptConfig(uint16_t Int1Config)
|
|
Jerome Coutant
1:917af0ca86df
|
204
|
{
|
|
Jerome Coutant
1:917af0ca86df
|
205
|
uint8_t ctrl_cfr = 0x00, ctrl3 = 0x00;
|
|
Jerome Coutant
1:917af0ca86df
|
206
|
|
|
Jerome Coutant
1:917af0ca86df
|
207
|
/* Read INT1_CFG register */
|
|
Jerome Coutant
1:917af0ca86df
|
208
|
GYRO_IO_Read(&ctrl_cfr, L3GD20_INT1_CFG_ADDR, 1);
|
|
Jerome Coutant
1:917af0ca86df
|
209
|
|
|
Jerome Coutant
1:917af0ca86df
|
210
|
/* Read CTRL_REG3 register */
|
|
Jerome Coutant
1:917af0ca86df
|
211
|
GYRO_IO_Read(&ctrl3, L3GD20_CTRL_REG3_ADDR, 1);
|
|
Jerome Coutant
1:917af0ca86df
|
212
|
|
|
Jerome Coutant
1:917af0ca86df
|
213
|
ctrl_cfr &= 0x80;
|
|
Jerome Coutant
1:917af0ca86df
|
214
|
ctrl_cfr |= ((uint8_t) Int1Config >> 8);
|
|
Jerome Coutant
1:917af0ca86df
|
215
|
|
|
Jerome Coutant
1:917af0ca86df
|
216
|
ctrl3 &= 0xDF;
|
|
Jerome Coutant
1:917af0ca86df
|
217
|
ctrl3 |= ((uint8_t) Int1Config);
|
|
Jerome Coutant
1:917af0ca86df
|
218
|
|
|
Jerome Coutant
1:917af0ca86df
|
219
|
/* Write value to MEMS INT1_CFG register */
|
|
Jerome Coutant
1:917af0ca86df
|
220
|
GYRO_IO_Write(&ctrl_cfr, L3GD20_INT1_CFG_ADDR, 1);
|
|
Jerome Coutant
1:917af0ca86df
|
221
|
|
|
Jerome Coutant
1:917af0ca86df
|
222
|
/* Write value to MEMS CTRL_REG3 register */
|
|
Jerome Coutant
1:917af0ca86df
|
223
|
GYRO_IO_Write(&ctrl3, L3GD20_CTRL_REG3_ADDR, 1);
|
|
Jerome Coutant
1:917af0ca86df
|
224
|
}
|
|
Jerome Coutant
1:917af0ca86df
|
225
|
|
|
Jerome Coutant
1:917af0ca86df
|
226
|
/**
|
|
Jerome Coutant
1:917af0ca86df
|
227
|
* @brief Enable INT1 or INT2 interrupt
|
|
Jerome Coutant
1:917af0ca86df
|
228
|
* @param IntSel: choice of INT1 or INT2
|
|
Jerome Coutant
1:917af0ca86df
|
229
|
* This parameter can be:
|
|
Jerome Coutant
1:917af0ca86df
|
230
|
* @arg L3GD20_INT1
|
|
Jerome Coutant
1:917af0ca86df
|
231
|
* @arg L3GD20_INT2
|
|
Jerome Coutant
1:917af0ca86df
|
232
|
* @retval None
|
|
Jerome Coutant
1:917af0ca86df
|
233
|
*/
|
|
Jerome Coutant
1:917af0ca86df
|
234
|
void L3GD20_EnableIT(uint8_t IntSel)
|
|
Jerome Coutant
1:917af0ca86df
|
235
|
{
|
|
Jerome Coutant
1:917af0ca86df
|
236
|
uint8_t tmpreg;
|
|
Jerome Coutant
1:917af0ca86df
|
237
|
|
|
Jerome Coutant
1:917af0ca86df
|
238
|
/* Read CTRL_REG3 register */
|
|
Jerome Coutant
1:917af0ca86df
|
239
|
GYRO_IO_Read(&tmpreg, L3GD20_CTRL_REG3_ADDR, 1);
|
|
Jerome Coutant
1:917af0ca86df
|
240
|
|
|
Jerome Coutant
1:917af0ca86df
|
241
|
if(IntSel == L3GD20_INT1)
|
|
Jerome Coutant
1:917af0ca86df
|
242
|
{
|
|
Jerome Coutant
1:917af0ca86df
|
243
|
tmpreg &= 0x7F;
|
|
Jerome Coutant
1:917af0ca86df
|
244
|
tmpreg |= L3GD20_INT1INTERRUPT_ENABLE;
|
|
Jerome Coutant
1:917af0ca86df
|
245
|
}
|
|
Jerome Coutant
1:917af0ca86df
|
246
|
else if(IntSel == L3GD20_INT2)
|
|
Jerome Coutant
1:917af0ca86df
|
247
|
{
|
|
Jerome Coutant
1:917af0ca86df
|
248
|
tmpreg &= 0xF7;
|
|
Jerome Coutant
1:917af0ca86df
|
249
|
tmpreg |= L3GD20_INT2INTERRUPT_ENABLE;
|
|
Jerome Coutant
1:917af0ca86df
|
250
|
}
|
|
Jerome Coutant
1:917af0ca86df
|
251
|
|
|
Jerome Coutant
1:917af0ca86df
|
252
|
/* Write value to MEMS CTRL_REG3 register */
|
|
Jerome Coutant
1:917af0ca86df
|
253
|
GYRO_IO_Write(&tmpreg, L3GD20_CTRL_REG3_ADDR, 1);
|
|
Jerome Coutant
1:917af0ca86df
|
254
|
}
|
|
Jerome Coutant
1:917af0ca86df
|
255
|
|
|
Jerome Coutant
1:917af0ca86df
|
256
|
/**
|
|
Jerome Coutant
1:917af0ca86df
|
257
|
* @brief Disable INT1 or INT2 interrupt
|
|
Jerome Coutant
1:917af0ca86df
|
258
|
* @param IntSel: choice of INT1 or INT2
|
|
Jerome Coutant
1:917af0ca86df
|
259
|
* This parameter can be:
|
|
Jerome Coutant
1:917af0ca86df
|
260
|
* @arg L3GD20_INT1
|
|
Jerome Coutant
1:917af0ca86df
|
261
|
* @arg L3GD20_INT2
|
|
Jerome Coutant
1:917af0ca86df
|
262
|
* @retval None
|
|
Jerome Coutant
1:917af0ca86df
|
263
|
*/
|
|
Jerome Coutant
1:917af0ca86df
|
264
|
void L3GD20_DisableIT(uint8_t IntSel)
|
|
Jerome Coutant
1:917af0ca86df
|
265
|
{
|
|
Jerome Coutant
1:917af0ca86df
|
266
|
uint8_t tmpreg;
|
|
Jerome Coutant
1:917af0ca86df
|
267
|
|
|
Jerome Coutant
1:917af0ca86df
|
268
|
/* Read CTRL_REG3 register */
|
|
Jerome Coutant
1:917af0ca86df
|
269
|
GYRO_IO_Read(&tmpreg, L3GD20_CTRL_REG3_ADDR, 1);
|
|
Jerome Coutant
1:917af0ca86df
|
270
|
|
|
Jerome Coutant
1:917af0ca86df
|
271
|
if(IntSel == L3GD20_INT1)
|
|
Jerome Coutant
1:917af0ca86df
|
272
|
{
|
|
Jerome Coutant
1:917af0ca86df
|
273
|
tmpreg &= 0x7F;
|
|
Jerome Coutant
1:917af0ca86df
|
274
|
tmpreg |= L3GD20_INT1INTERRUPT_DISABLE;
|
|
Jerome Coutant
1:917af0ca86df
|
275
|
}
|
|
Jerome Coutant
1:917af0ca86df
|
276
|
else if(IntSel == L3GD20_INT2)
|
|
Jerome Coutant
1:917af0ca86df
|
277
|
{
|
|
Jerome Coutant
1:917af0ca86df
|
278
|
tmpreg &= 0xF7;
|
|
Jerome Coutant
1:917af0ca86df
|
279
|
tmpreg |= L3GD20_INT2INTERRUPT_DISABLE;
|
|
Jerome Coutant
1:917af0ca86df
|
280
|
}
|
|
Jerome Coutant
1:917af0ca86df
|
281
|
|
|
Jerome Coutant
1:917af0ca86df
|
282
|
/* Write value to MEMS CTRL_REG3 register */
|
|
Jerome Coutant
1:917af0ca86df
|
283
|
GYRO_IO_Write(&tmpreg, L3GD20_CTRL_REG3_ADDR, 1);
|
|
Jerome Coutant
1:917af0ca86df
|
284
|
}
|
|
Jerome Coutant
1:917af0ca86df
|
285
|
|
|
Jerome Coutant
1:917af0ca86df
|
286
|
/**
|
|
Jerome Coutant
1:917af0ca86df
|
287
|
* @brief Set High Pass Filter Modality
|
|
Jerome Coutant
1:917af0ca86df
|
288
|
* @param FilterStruct: contains the configuration setting for the L3GD20.
|
|
Jerome Coutant
1:917af0ca86df
|
289
|
* @retval None
|
|
Jerome Coutant
1:917af0ca86df
|
290
|
*/
|
|
Jerome Coutant
1:917af0ca86df
|
291
|
void L3GD20_FilterConfig(uint8_t FilterStruct)
|
|
Jerome Coutant
1:917af0ca86df
|
292
|
{
|
|
Jerome Coutant
1:917af0ca86df
|
293
|
uint8_t tmpreg;
|
|
Jerome Coutant
1:917af0ca86df
|
294
|
|
|
Jerome Coutant
1:917af0ca86df
|
295
|
/* Read CTRL_REG2 register */
|
|
Jerome Coutant
1:917af0ca86df
|
296
|
GYRO_IO_Read(&tmpreg, L3GD20_CTRL_REG2_ADDR, 1);
|
|
Jerome Coutant
1:917af0ca86df
|
297
|
|
|
Jerome Coutant
1:917af0ca86df
|
298
|
tmpreg &= 0xC0;
|
|
Jerome Coutant
1:917af0ca86df
|
299
|
|
|
Jerome Coutant
1:917af0ca86df
|
300
|
/* Configure MEMS: mode and cutoff frequency */
|
|
Jerome Coutant
1:917af0ca86df
|
301
|
tmpreg |= FilterStruct;
|
|
Jerome Coutant
1:917af0ca86df
|
302
|
|
|
Jerome Coutant
1:917af0ca86df
|
303
|
/* Write value to MEMS CTRL_REG2 register */
|
|
Jerome Coutant
1:917af0ca86df
|
304
|
GYRO_IO_Write(&tmpreg, L3GD20_CTRL_REG2_ADDR, 1);
|
|
Jerome Coutant
1:917af0ca86df
|
305
|
}
|
|
Jerome Coutant
1:917af0ca86df
|
306
|
|
|
Jerome Coutant
1:917af0ca86df
|
307
|
/**
|
|
Jerome Coutant
1:917af0ca86df
|
308
|
* @brief Enable or Disable High Pass Filter
|
|
Jerome Coutant
1:917af0ca86df
|
309
|
* @param HighPassFilterState: new state of the High Pass Filter feature.
|
|
Jerome Coutant
1:917af0ca86df
|
310
|
* This parameter can be:
|
|
Jerome Coutant
1:917af0ca86df
|
311
|
* @arg: L3GD20_HIGHPASSFILTER_DISABLE
|
|
Jerome Coutant
1:917af0ca86df
|
312
|
* @arg: L3GD20_HIGHPASSFILTER_ENABLE
|
|
Jerome Coutant
1:917af0ca86df
|
313
|
* @retval None
|
|
Jerome Coutant
1:917af0ca86df
|
314
|
*/
|
|
Jerome Coutant
1:917af0ca86df
|
315
|
void L3GD20_FilterCmd(uint8_t HighPassFilterState)
|
|
Jerome Coutant
1:917af0ca86df
|
316
|
{
|
|
Jerome Coutant
1:917af0ca86df
|
317
|
uint8_t tmpreg;
|
|
Jerome Coutant
1:917af0ca86df
|
318
|
|
|
Jerome Coutant
1:917af0ca86df
|
319
|
/* Read CTRL_REG5 register */
|
|
Jerome Coutant
1:917af0ca86df
|
320
|
GYRO_IO_Read(&tmpreg, L3GD20_CTRL_REG5_ADDR, 1);
|
|
Jerome Coutant
1:917af0ca86df
|
321
|
|
|
Jerome Coutant
1:917af0ca86df
|
322
|
tmpreg &= 0xEF;
|
|
Jerome Coutant
1:917af0ca86df
|
323
|
|
|
Jerome Coutant
1:917af0ca86df
|
324
|
tmpreg |= HighPassFilterState;
|
|
Jerome Coutant
1:917af0ca86df
|
325
|
|
|
Jerome Coutant
1:917af0ca86df
|
326
|
/* Write value to MEMS CTRL_REG5 register */
|
|
Jerome Coutant
1:917af0ca86df
|
327
|
GYRO_IO_Write(&tmpreg, L3GD20_CTRL_REG5_ADDR, 1);
|
|
Jerome Coutant
1:917af0ca86df
|
328
|
}
|
|
Jerome Coutant
1:917af0ca86df
|
329
|
|
|
Jerome Coutant
1:917af0ca86df
|
330
|
/**
|
|
Jerome Coutant
1:917af0ca86df
|
331
|
* @brief Get status for L3GD20 data
|
|
Jerome Coutant
1:917af0ca86df
|
332
|
* @param None
|
|
Jerome Coutant
1:917af0ca86df
|
333
|
* @retval Data status in a L3GD20 Data
|
|
Jerome Coutant
1:917af0ca86df
|
334
|
*/
|
|
Jerome Coutant
1:917af0ca86df
|
335
|
uint8_t L3GD20_GetDataStatus(void)
|
|
Jerome Coutant
1:917af0ca86df
|
336
|
{
|
|
Jerome Coutant
1:917af0ca86df
|
337
|
uint8_t tmpreg;
|
|
Jerome Coutant
1:917af0ca86df
|
338
|
|
|
Jerome Coutant
1:917af0ca86df
|
339
|
/* Read STATUS_REG register */
|
|
Jerome Coutant
1:917af0ca86df
|
340
|
GYRO_IO_Read(&tmpreg, L3GD20_STATUS_REG_ADDR, 1);
|
|
Jerome Coutant
1:917af0ca86df
|
341
|
|
|
Jerome Coutant
1:917af0ca86df
|
342
|
return tmpreg;
|
|
Jerome Coutant
1:917af0ca86df
|
343
|
}
|
|
Jerome Coutant
1:917af0ca86df
|
344
|
|
|
Jerome Coutant
1:917af0ca86df
|
345
|
/**
|
|
Jerome Coutant
1:917af0ca86df
|
346
|
* @brief Calculate the L3GD20 angular data.
|
|
Jerome Coutant
1:917af0ca86df
|
347
|
* @param pfData: Data out pointer
|
|
Jerome Coutant
1:917af0ca86df
|
348
|
* @retval None
|
|
Jerome Coutant
1:917af0ca86df
|
349
|
*/
|
|
Jerome Coutant
1:917af0ca86df
|
350
|
void L3GD20_ReadXYZAngRate(float *pfData)
|
|
Jerome Coutant
1:917af0ca86df
|
351
|
{
|
|
Jerome Coutant
1:917af0ca86df
|
352
|
uint8_t tmpbuffer[6] ={0};
|
|
Jerome Coutant
1:917af0ca86df
|
353
|
int16_t RawData[3] = {0};
|
|
Jerome Coutant
1:917af0ca86df
|
354
|
uint8_t tmpreg = 0;
|
|
Jerome Coutant
1:917af0ca86df
|
355
|
float sensitivity = 0;
|
|
Jerome Coutant
1:917af0ca86df
|
356
|
int i =0;
|
|
Jerome Coutant
1:917af0ca86df
|
357
|
|
|
Jerome Coutant
1:917af0ca86df
|
358
|
GYRO_IO_Read(&tmpreg,L3GD20_CTRL_REG4_ADDR,1);
|
|
Jerome Coutant
1:917af0ca86df
|
359
|
|
|
Jerome Coutant
1:917af0ca86df
|
360
|
GYRO_IO_Read(tmpbuffer,L3GD20_OUT_X_L_ADDR,6);
|
|
Jerome Coutant
1:917af0ca86df
|
361
|
|
|
Jerome Coutant
1:917af0ca86df
|
362
|
/* check in the control register 4 the data alignment (Big Endian or Little Endian)*/
|
|
Jerome Coutant
1:917af0ca86df
|
363
|
if(!(tmpreg & L3GD20_BLE_MSB))
|
|
Jerome Coutant
1:917af0ca86df
|
364
|
{
|
|
Jerome Coutant
1:917af0ca86df
|
365
|
for(i=0; i<3; i++)
|
|
Jerome Coutant
1:917af0ca86df
|
366
|
{
|
|
Jerome Coutant
1:917af0ca86df
|
367
|
RawData[i]=(int16_t)(((uint16_t)tmpbuffer[2*i+1] << 8) + tmpbuffer[2*i]);
|
|
Jerome Coutant
1:917af0ca86df
|
368
|
}
|
|
Jerome Coutant
1:917af0ca86df
|
369
|
}
|
|
Jerome Coutant
1:917af0ca86df
|
370
|
else
|
|
Jerome Coutant
1:917af0ca86df
|
371
|
{
|
|
Jerome Coutant
1:917af0ca86df
|
372
|
for(i=0; i<3; i++)
|
|
Jerome Coutant
1:917af0ca86df
|
373
|
{
|
|
Jerome Coutant
1:917af0ca86df
|
374
|
RawData[i]=(int16_t)(((uint16_t)tmpbuffer[2*i] << 8) + tmpbuffer[2*i+1]);
|
|
Jerome Coutant
1:917af0ca86df
|
375
|
}
|
|
Jerome Coutant
1:917af0ca86df
|
376
|
}
|
|
Jerome Coutant
1:917af0ca86df
|
377
|
|
|
Jerome Coutant
1:917af0ca86df
|
378
|
/* Switch the sensitivity value set in the CRTL4 */
|
|
Jerome Coutant
1:917af0ca86df
|
379
|
switch(tmpreg & L3GD20_FULLSCALE_SELECTION)
|
|
Jerome Coutant
1:917af0ca86df
|
380
|
{
|
|
Jerome Coutant
1:917af0ca86df
|
381
|
case L3GD20_FULLSCALE_250:
|
|
Jerome Coutant
1:917af0ca86df
|
382
|
sensitivity=L3GD20_SENSITIVITY_250DPS;
|
|
Jerome Coutant
1:917af0ca86df
|
383
|
break;
|
|
Jerome Coutant
1:917af0ca86df
|
384
|
|
|
Jerome Coutant
1:917af0ca86df
|
385
|
case L3GD20_FULLSCALE_500:
|
|
Jerome Coutant
1:917af0ca86df
|
386
|
sensitivity=L3GD20_SENSITIVITY_500DPS;
|
|
Jerome Coutant
1:917af0ca86df
|
387
|
break;
|
|
Jerome Coutant
1:917af0ca86df
|
388
|
|
|
Jerome Coutant
1:917af0ca86df
|
389
|
case L3GD20_FULLSCALE_2000:
|
|
Jerome Coutant
1:917af0ca86df
|
390
|
sensitivity=L3GD20_SENSITIVITY_2000DPS;
|
|
Jerome Coutant
1:917af0ca86df
|
391
|
break;
|
|
Jerome Coutant
1:917af0ca86df
|
392
|
}
|
|
Jerome Coutant
1:917af0ca86df
|
393
|
/* Divide by sensitivity */
|
|
Jerome Coutant
1:917af0ca86df
|
394
|
for(i=0; i<3; i++)
|
|
Jerome Coutant
1:917af0ca86df
|
395
|
{
|
|
Jerome Coutant
1:917af0ca86df
|
396
|
pfData[i]=(float)(RawData[i] * sensitivity);
|
|
Jerome Coutant
1:917af0ca86df
|
397
|
}
|
|
Jerome Coutant
1:917af0ca86df
|
398
|
}
|
|
Jerome Coutant
1:917af0ca86df
|
399
|
|
|
Jerome Coutant
1:917af0ca86df
|
400
|
/**
|
|
Jerome Coutant
1:917af0ca86df
|
401
|
* @}
|
|
Jerome Coutant
1:917af0ca86df
|
402
|
*/
|
|
Jerome Coutant
1:917af0ca86df
|
403
|
|
|
Jerome Coutant
1:917af0ca86df
|
404
|
/**
|
|
Jerome Coutant
1:917af0ca86df
|
405
|
* @}
|
|
Jerome Coutant
1:917af0ca86df
|
406
|
*/
|
|
Jerome Coutant
1:917af0ca86df
|
407
|
|
|
Jerome Coutant
1:917af0ca86df
|
408
|
/**
|
|
Jerome Coutant
1:917af0ca86df
|
409
|
* @}
|
|
Jerome Coutant
1:917af0ca86df
|
410
|
*/
|
|
Jerome Coutant
1:917af0ca86df
|
411
|
|
|
Jerome Coutant
1:917af0ca86df
|
412
|
/**
|
|
Jerome Coutant
1:917af0ca86df
|
413
|
* @}
|
|
Jerome Coutant
1:917af0ca86df
|
414
|
*/
|
|
Jerome Coutant
1:917af0ca86df
|
415
|
|
|
Jerome Coutant
1:917af0ca86df
|
416
|
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|
|