1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
25
26
29
30
33
34
37
40
41
44
47
48
51
54
55
58
59
60
63
64
67
70
71
74
75
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
170
180
181
184
191
192
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
229
230
231
232
233
234
235
236
237
238
239
246
247
251
258
259
262
263
266
267
270
271
/* ... */
#include "stm32f429i_discovery_gyroscope.h"
/* ... */
/* ... */
/* ... */
/* ... */
/* ... */
/* ... */
/* ... */
/* ... */
/* ... */
/* ... */
static GYRO_DrvTypeDef *GyroscopeDrv;
/* ... */
/* ... */
/* ... */
/* ... */
/* ... */
uint8_t BSP_GYRO_Init(void)
{
uint8_t ret = GYRO_ERROR;
uint16_t ctrl = 0x0000;
GYRO_InitTypeDef Gyro_InitStructure;
GYRO_FilterConfigTypeDef Gyro_FilterStructure = {0, 0};
if ((L3gd20Drv.ReadID() == I_AM_L3GD20) || (L3gd20Drv.ReadID() == I_AM_L3GD20_TR))
{
GyroscopeDrv = &L3gd20Drv;
Gyro_InitStructure.Power_Mode = L3GD20_MODE_ACTIVE;
Gyro_InitStructure.Output_DataRate = L3GD20_OUTPUT_DATARATE_1;
Gyro_InitStructure.Axes_Enable = L3GD20_AXES_ENABLE;
Gyro_InitStructure.Band_Width = L3GD20_BANDWIDTH_4;
Gyro_InitStructure.BlockData_Update = L3GD20_BlockDataUpdate_Continous;
Gyro_InitStructure.Endianness = L3GD20_BLE_LSB;
Gyro_InitStructure.Full_Scale = L3GD20_FULLSCALE_500;
ctrl = (uint16_t)(Gyro_InitStructure.Power_Mode | Gyro_InitStructure.Output_DataRate | \
Gyro_InitStructure.Axes_Enable | Gyro_InitStructure.Band_Width);
ctrl |= (uint16_t)((Gyro_InitStructure.BlockData_Update | Gyro_InitStructure.Endianness | \
Gyro_InitStructure.Full_Scale) << 8);
GyroscopeDrv->Init(ctrl);
Gyro_FilterStructure.HighPassFilter_Mode_Selection = L3GD20_HPM_NORMAL_MODE_RES;
Gyro_FilterStructure.HighPassFilter_CutOff_Frequency = L3GD20_HPFCF_0;
ctrl = (uint8_t)((Gyro_FilterStructure.HighPassFilter_Mode_Selection | \
Gyro_FilterStructure.HighPassFilter_CutOff_Frequency));
GyroscopeDrv->FilterConfig(ctrl) ;
GyroscopeDrv->FilterCmd(L3GD20_HIGHPASSFILTER_ENABLE);
ret = GYRO_OK;
}if ((L3gd20Drv.ReadID() == I_AM_L3GD20) || (L3gd20Drv.ReadID() == I_AM_L3GD20_TR)) { ... }
#if defined(USE_STM32F429I_DISCOVERY_REVD)
else if (I3g4250Drv.ReadID() == I_AM_I3G4250D)
{
GyroscopeDrv = &I3g4250Drv;
Gyro_InitStructure.Power_Mode = I3G4250D_MODE_ACTIVE;
Gyro_InitStructure.Output_DataRate = I3G4250D_OUTPUT_DATARATE_1;
Gyro_InitStructure.Axes_Enable = I3G4250D_AXES_ENABLE;
Gyro_InitStructure.Band_Width = I3G4250D_BANDWIDTH_4;
Gyro_InitStructure.BlockData_Update = I3G4250D_BlockDataUpdate_Continous;
Gyro_InitStructure.Endianness = I3G4250D_BLE_LSB;
Gyro_InitStructure.Full_Scale = I3G4250D_FULLSCALE_500;
ctrl = (uint16_t)(Gyro_InitStructure.Power_Mode | Gyro_InitStructure.Output_DataRate | \
Gyro_InitStructure.Axes_Enable | Gyro_InitStructure.Band_Width);
ctrl |= (uint16_t)((Gyro_InitStructure.BlockData_Update | Gyro_InitStructure.Endianness | \
Gyro_InitStructure.Full_Scale) << 8);
GyroscopeDrv->Init(ctrl);
Gyro_FilterStructure.HighPassFilter_Mode_Selection = I3G4250D_HPM_NORMAL_MODE_RES;
Gyro_FilterStructure.HighPassFilter_CutOff_Frequency = I3G4250D_HPFCF_0;
ctrl = (uint8_t)((Gyro_FilterStructure.HighPassFilter_Mode_Selection | \
Gyro_FilterStructure.HighPassFilter_CutOff_Frequency));
GyroscopeDrv->FilterConfig(ctrl);
GyroscopeDrv->FilterCmd(I3G4250D_HIGHPASSFILTER_ENABLE);
ret = GYRO_OK;
}else if (I3g4250Drv.ReadID() == I_AM_I3G4250D) { ... }
/* ... */#endif
return ret;
}{ ... }
/* ... */
uint8_t BSP_GYRO_ReadID(void)
{
uint8_t id = 0x00;
if (GyroscopeDrv->ReadID != NULL)
{
id = GyroscopeDrv->ReadID();
}if (GyroscopeDrv->ReadID != NULL) { ... }
return id;
}{ ... }
/* ... */
void BSP_GYRO_Reset(void)
{
if (GyroscopeDrv->Reset != NULL)
{
GyroscopeDrv->Reset();
}if (GyroscopeDrv->Reset != NULL) { ... }
}{ ... }
/* ... */
void BSP_GYRO_ITConfig(GYRO_InterruptConfigTypeDef *pIntConfig)
{
uint16_t interruptconfig = 0x0000;
if (GyroscopeDrv->ConfigIT != NULL)
{
interruptconfig |= ((uint8_t)(pIntConfig->Latch_Request | \
pIntConfig->Interrupt_Axes) << 8);
interruptconfig |= (uint8_t)(pIntConfig->Interrupt_ActiveEdge);
GyroscopeDrv->ConfigIT(interruptconfig);
}if (GyroscopeDrv->ConfigIT != NULL) { ... }
}{ ... }
/* ... */
void BSP_GYRO_EnableIT(uint8_t IntPin)
{
if (GyroscopeDrv->EnableIT != NULL)
{
GyroscopeDrv->EnableIT(IntPin);
}if (GyroscopeDrv->EnableIT != NULL) { ... }
}{ ... }
/* ... */
void BSP_GYRO_DisableIT(uint8_t IntPin)
{
if (GyroscopeDrv->DisableIT != NULL)
{
GyroscopeDrv->DisableIT(IntPin);
}if (GyroscopeDrv->DisableIT != NULL) { ... }
}{ ... }
/* ... */
void BSP_GYRO_GetXYZ(float *pfData)
{
if (GyroscopeDrv->GetXYZ != NULL)
{
GyroscopeDrv->GetXYZ(pfData);
}if (GyroscopeDrv->GetXYZ != NULL) { ... }
}{ ... }
/* ... */
/* ... */
/* ... */
/* ... */