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
36
37
40
43
44
47
50
51
54
57
58
61
62
65
66
69
72
73
76
77
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
157
158
159
160
164
174
175
178
185
186
189
196
197
200
207
208
213
231
232
235
236
239
240
243
244
/* ... */
#include "stm32f4_discovery_accelerometer.h"
/* ... */
/* ... */
/* ... */
/* ... */
/* ... */
/* ... */
/* ... */
/* ... */
/* ... */
/* ... */
static ACCELERO_DrvTypeDef *AcceleroDrv;
/* ... */
/* ... */
/* ... */
/* ... */
/* ... */
uint8_t BSP_ACCELERO_Init(void)
{
uint8_t ret = ACCELERO_ERROR;
uint16_t ctrl = 0x0000;
LIS302DL_InitTypeDef lis302dl_initstruct;
LIS302DL_FilterConfigTypeDef lis302dl_filter = {0,0,0};
LIS3DSH_InitTypeDef l1s3dsh_InitStruct;
if(Lis302dlDrv.ReadID() == I_AM_LIS302DL)
{
AcceleroDrv = &Lis302dlDrv;
lis302dl_initstruct.Power_Mode = LIS302DL_LOWPOWERMODE_ACTIVE;
lis302dl_initstruct.Output_DataRate = LIS302DL_DATARATE_100;
lis302dl_initstruct.Axes_Enable = LIS302DL_XYZ_ENABLE;
lis302dl_initstruct.Full_Scale = LIS302DL_FULLSCALE_2_3;
lis302dl_initstruct.Self_Test = LIS302DL_SELFTEST_NORMAL;
ctrl = (uint16_t) (lis302dl_initstruct.Output_DataRate | lis302dl_initstruct.Power_Mode | \
lis302dl_initstruct.Full_Scale | lis302dl_initstruct.Self_Test | \
lis302dl_initstruct.Axes_Enable);
AcceleroDrv->Init(ctrl);
lis302dl_filter.HighPassFilter_Data_Selection = LIS302DL_FILTEREDDATASELECTION_OUTPUTREGISTER;
lis302dl_filter.HighPassFilter_CutOff_Frequency = LIS302DL_HIGHPASSFILTER_LEVEL_1;
lis302dl_filter.HighPassFilter_Interrupt = LIS302DL_HIGHPASSFILTERINTERRUPT_1_2;
ctrl = (uint8_t)(lis302dl_filter.HighPassFilter_Data_Selection | \
lis302dl_filter.HighPassFilter_CutOff_Frequency | \
lis302dl_filter.HighPassFilter_Interrupt);
AcceleroDrv->FilterConfig(ctrl);
ret = ACCELERO_OK;
}if (Lis302dlDrv.ReadID() == I_AM_LIS302DL) { ... }
else if(Lis3dshDrv.ReadID() == I_AM_LIS3DSH)
{
AcceleroDrv = &Lis3dshDrv;
l1s3dsh_InitStruct.Output_DataRate = LIS3DSH_DATARATE_100;
l1s3dsh_InitStruct.Axes_Enable = LIS3DSH_XYZ_ENABLE;
l1s3dsh_InitStruct.SPI_Wire = LIS3DSH_SERIALINTERFACE_4WIRE;
l1s3dsh_InitStruct.Self_Test = LIS3DSH_SELFTEST_NORMAL;
l1s3dsh_InitStruct.Full_Scale = LIS3DSH_FULLSCALE_2;
l1s3dsh_InitStruct.Filter_BW = LIS3DSH_FILTER_BW_800;
ctrl = (uint16_t) (l1s3dsh_InitStruct.Output_DataRate | \
l1s3dsh_InitStruct.Axes_Enable);
ctrl |= (uint16_t) ((l1s3dsh_InitStruct.SPI_Wire | \
l1s3dsh_InitStruct.Self_Test | \
l1s3dsh_InitStruct.Full_Scale | \
l1s3dsh_InitStruct.Filter_BW) << 8);
AcceleroDrv->Init(ctrl);
ret = ACCELERO_OK;
}else if (Lis3dshDrv.ReadID() == I_AM_LIS3DSH) { ... }
else
{
ret = ACCELERO_ERROR;
}else { ... }
return ret;
}{ ... }
/* ... */
uint8_t BSP_ACCELERO_ReadID(void)
{
uint8_t id = 0x00;
if(AcceleroDrv->ReadID != NULL)
{
id = AcceleroDrv->ReadID();
}if (AcceleroDrv->ReadID != NULL) { ... }
return id;
}{ ... }
/* ... */
void BSP_ACCELERO_Reset(void)
{
if(AcceleroDrv->Reset != NULL)
{
AcceleroDrv->Reset();
}if (AcceleroDrv->Reset != NULL) { ... }
}{ ... }
/* ... */
void BSP_ACCELERO_Click_ITConfig(void)
{
if(AcceleroDrv->ConfigIT != NULL)
{
AcceleroDrv->ConfigIT();
}if (AcceleroDrv->ConfigIT != NULL) { ... }
}{ ... }
/* ... */
void BSP_ACCELERO_Click_ITClear(void)
{
if(AcceleroDrv->ClearIT != NULL)
{
AcceleroDrv->ClearIT();
}if (AcceleroDrv->ClearIT != NULL) { ... }
}{ ... }
/* ... */
void BSP_ACCELERO_GetXYZ(int16_t *pDataXYZ)
{
int16_t SwitchXY = 0;
if(AcceleroDrv->GetXYZ != NULL)
{
AcceleroDrv->GetXYZ(pDataXYZ);
if(AcceleroDrv == &Lis302dlDrv)
{
SwitchXY = pDataXYZ[0];
pDataXYZ[0] = pDataXYZ[1];
pDataXYZ[1] = -SwitchXY;
}if (AcceleroDrv == &Lis302dlDrv) { ... }
}if (AcceleroDrv->GetXYZ != NULL) { ... }
}{ ... }
/* ... */
/* ... */
/* ... */
/* ... */