1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
26
27
30
31
34
35
38
41
42
45
48
49
52
55
56
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
132
133
134
135
136
139
146
147
150
157
158
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
186
187
190
191
194
195
/* ... */
#include "stm32f401_discovery_accelerometer.h"
/* ... */
/* ... */
/* ... */
/* ... */
/* ... */
/* ... */
/* ... */
/* ... */
/* ... */
/* ... */
static ACCELERO_DrvTypeDef *AccelerometerDrv;
/* ... */
/* ... */
/* ... */
/* ... */
/* ... */
uint8_t BSP_ACCELERO_Init(void)
{
uint8_t ret = ACCELERO_ERROR;
uint16_t ctrl = 0x0000;
ACCELERO_InitTypeDef LSM303DLHC_InitStructure;
ACCELERO_FilterConfigTypeDef LSM303DLHC_FilterStructure = {0,0,0,0};
if(Lsm303dlhcDrv.ReadID() == I_AM_LMS303DLHC)
{
AccelerometerDrv = &Lsm303dlhcDrv;
LSM303DLHC_InitStructure.Power_Mode = LSM303DLHC_NORMAL_MODE;
LSM303DLHC_InitStructure.AccOutput_DataRate = LSM303DLHC_ODR_50_HZ;
LSM303DLHC_InitStructure.Axes_Enable = LSM303DLHC_AXES_ENABLE;
LSM303DLHC_InitStructure.AccFull_Scale = LSM303DLHC_FULLSCALE_2G;
LSM303DLHC_InitStructure.BlockData_Update = LSM303DLHC_BlockUpdate_Continous;
LSM303DLHC_InitStructure.Endianness = LSM303DLHC_BLE_LSB;
LSM303DLHC_InitStructure.High_Resolution = LSM303DLHC_HR_ENABLE;
ctrl |= (LSM303DLHC_InitStructure.Power_Mode | LSM303DLHC_InitStructure.AccOutput_DataRate | \
LSM303DLHC_InitStructure.Axes_Enable);
ctrl |= ((LSM303DLHC_InitStructure.BlockData_Update | LSM303DLHC_InitStructure.Endianness | \
LSM303DLHC_InitStructure.AccFull_Scale | LSM303DLHC_InitStructure.High_Resolution) << 8);
AccelerometerDrv->Init(ctrl);
LSM303DLHC_FilterStructure.HighPassFilter_Mode_Selection =LSM303DLHC_HPM_NORMAL_MODE;
LSM303DLHC_FilterStructure.HighPassFilter_CutOff_Frequency = LSM303DLHC_HPFCF_16;
LSM303DLHC_FilterStructure.HighPassFilter_AOI1 = LSM303DLHC_HPF_AOI1_DISABLE;
LSM303DLHC_FilterStructure.HighPassFilter_AOI2 = LSM303DLHC_HPF_AOI2_DISABLE;
ctrl = (uint8_t) (LSM303DLHC_FilterStructure.HighPassFilter_Mode_Selection |\
LSM303DLHC_FilterStructure.HighPassFilter_CutOff_Frequency|\
LSM303DLHC_FilterStructure.HighPassFilter_AOI1|\
LSM303DLHC_FilterStructure.HighPassFilter_AOI2);
AccelerometerDrv->FilterConfig(ctrl);
ret = ACCELERO_OK;
}if (Lsm303dlhcDrv.ReadID() == I_AM_LMS303DLHC) { ... }
else
{
ret = ACCELERO_ERROR;
}else { ... }
return ret;
}{ ... }
/* ... */
void BSP_ACCELERO_Reset(void)
{
if(AccelerometerDrv->Reset != NULL)
{
AccelerometerDrv->Reset();
}if (AccelerometerDrv->Reset != NULL) { ... }
}{ ... }
/* ... */
void BSP_ACCELERO_Click_ITConfig(void)
{
if(AccelerometerDrv->ConfigIT!= NULL)
{
AccelerometerDrv->ConfigIT();
}if (AccelerometerDrv->ConfigIT!= NULL) { ... }
}{ ... }
/* ... */
void BSP_ACCELERO_GetXYZ(int16_t *pDataXYZ)
{
int16_t SwitchXY = 0;
if(AccelerometerDrv->GetXYZ!= NULL)
{
AccelerometerDrv->GetXYZ(pDataXYZ);
if(AccelerometerDrv == &Lsm303dlhcDrv)
{
SwitchXY = pDataXYZ[0];
pDataXYZ[0] = pDataXYZ[1];
pDataXYZ[1] = -SwitchXY;
}if (AccelerometerDrv == &Lsm303dlhcDrv) { ... }
}if (AccelerometerDrv->GetXYZ!= NULL) { ... }
}{ ... }
/* ... */
/* ... */
/* ... */
/* ... */