forked from SZV10X_Software/SZV103_FM33A0xxEV_SiZhu

jinlicong
2024-04-18 ee025b209ebf414ec37dd7bb9a6bfb99461b1db0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
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
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
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
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
#include "gpio.h"
 
 
 
//GPIOA~G  Ä£Ä⹦ÄÜÅäÖÃ
void AnalogIO( GPIO_Type* GPIOx, uint32_t GPIO_Pin )
{
    GPIO_InitTypeDef  GPIO_InitStructure;
    GPIO_InitTypeDef  GPIO_InitStructureRun;
 
    GPIO_Get_InitPara(GPIOx, GPIO_Pin, &GPIO_InitStructureRun);
 
    if( (GPIO_InitStructureRun.Pin        != GPIO_Pin) ||
    (GPIO_InitStructureRun.PxINEN    != GPIO_IN_Dis) ||
    (GPIO_InitStructureRun.PxODEN    != GPIO_OD_Dis) ||
    (GPIO_InitStructureRun.PxPUEN    != GPIO_PU_Dis) ||
    (GPIO_InitStructureRun.PxFCR    != GPIO_FCR_ANA) )
    {
        GPIO_InitStructure.Pin = GPIO_Pin;
        GPIO_InitStructure.PxINEN = GPIO_IN_Dis;
        GPIO_InitStructure.PxODEN = GPIO_OD_Dis;
        GPIO_InitStructure.PxPUEN = GPIO_PU_Dis;
        GPIO_InitStructure.PxFCR = GPIO_FCR_ANA;
 
        GPIO_Init(GPIOx, &GPIO_InitStructure);    
    }
}
 
//GPIOH Ä£Ä⹦ÄÜÅäÖÃ
void AnalogIO_H(uint32_t GPIO_Pin )
{
    uint32_t pinpos = 0x00,pinbit = 0x00;
 
    if(CDIF_CR_INTF_EN_Getable() == DISABLE)
    {
        CDIF_CR_INTF_EN_Setable(ENABLE);
    }
    for (pinpos = 0; pinpos < 4; pinpos++)
    {
        pinbit = ((uint32_t)0x01) << pinpos;
        if(GPIO_Pin & pinbit)
        {
            GPIOH->INEN &= (~(1<<pinpos));
            GPIOH->FCR |= (3<<(pinpos*2)) ;
        }    
    } 
    if(CDIF_CR_INTF_EN_Getable() == ENABLE)
    {
         CDIF_CR_INTF_EN_Setable(DISABLE);
    }
}
 
//GPIOA~G ÊäÈë¿ÚÅäÖà
//type 0 = ÆÕͨ 
//type 1 = ÉÏÀ­
//#define IN_NORMAL    0
//#define IN_PULLUP    1
void InputtIO( GPIO_Type* GPIOx, uint32_t GPIO_Pin, uint8_t Type )
{
    GPIO_InitTypeDef  GPIO_InitStructure;
    GPIO_InitTypeDef  GPIO_InitStructureRun;
 
    GPIO_Get_InitPara(GPIOx, GPIO_Pin, &GPIO_InitStructureRun);
 
    if( (GPIO_InitStructureRun.Pin        != GPIO_Pin) ||
    (GPIO_InitStructureRun.PxINEN    != GPIO_IN_En) ||
    (GPIO_InitStructureRun.PxODEN    != GPIO_OD_En) ||
    ((Type == IN_NORMAL)&&(GPIO_InitStructureRun.PxPUEN != GPIO_PU_Dis)) ||
    ((Type == IN_PULLUP)&&(GPIO_InitStructureRun.PxPUEN != GPIO_PU_En)) ||
    (GPIO_InitStructureRun.PxFCR    != GPIO_FCR_IN) )
    {
        GPIO_InitStructure.Pin = GPIO_Pin;    
        GPIO_InitStructure.PxINEN = GPIO_IN_En;
        GPIO_InitStructure.PxODEN = GPIO_OD_En;
        if(Type == IN_NORMAL)        GPIO_InitStructure.PxPUEN = GPIO_PU_Dis;
        else                        GPIO_InitStructure.PxPUEN = GPIO_PU_En;    
        GPIO_InitStructure.PxFCR = GPIO_FCR_IN;
 
        GPIO_Init(GPIOx, &GPIO_InitStructure);    
    }
}
 
//GPIOH ÊäÈë¿ÚÅäÖà
//type 0 = ÆÕͨ 
//type 1 = ÉÏÀ­
//#define IN_NORMAL    0
//#define IN_PULLUP    1
void InputtIO_H(uint32_t GPIO_Pin, uint8_t Type )
{
    uint32_t pinpos = 0x00,pinbit = 0x00;
 
    if(CDIF_CR_INTF_EN_Getable() == DISABLE)
    {
        CDIF_CR_INTF_EN_Setable(ENABLE);
    }
    for (pinpos = 0; pinpos < 4; pinpos++)
    {
        pinbit = ((uint32_t)0x01) << pinpos;
        if(GPIO_Pin & pinbit)
        {
            if(Type==0)
            {
                GPIOH->PUEN &= (~(1<<pinpos));
            }
            else
            {
                GPIOH->PUEN |= (1<<pinpos);
            }
            GPIOH->FCR &= (~(3<<(pinpos*2)));
            GPIOH->INEN |= (1<<pinpos);    
        }    
    }
    if(CDIF_CR_INTF_EN_Getable() == ENABLE)
    {
        CDIF_CR_INTF_EN_Setable(DISABLE);
    }
}
 
//GPIOA~GÊä³ö¿ÚÅäÖà
//type 0 = ÆÕͨ 
//type 1 = OD
//#define OUT_PUSHPULL    0
//#define OUT_OPENDRAIN    1
void OutputIO( GPIO_Type* GPIOx, uint32_t GPIO_Pin, uint8_t Type )
{
    GPIO_InitTypeDef  GPIO_InitStructure;
    GPIO_InitTypeDef  GPIO_InitStructureRun;
 
    GPIO_Get_InitPara(GPIOx, GPIO_Pin, &GPIO_InitStructureRun);
 
    if( (GPIO_InitStructureRun.Pin        != GPIO_Pin) ||
    (GPIO_InitStructureRun.PxINEN    != GPIO_IN_Dis) ||
    ((Type == OUT_PUSHPULL)&&(GPIO_InitStructureRun.PxODEN    != GPIO_OD_Dis)) ||
    ((Type == OUT_OPENDRAIN)&&(GPIO_InitStructureRun.PxODEN    != GPIO_OD_En)) ||
    (GPIO_InitStructureRun.PxPUEN    != GPIO_PU_Dis) ||
    (GPIO_InitStructureRun.PxFCR    != GPIO_FCR_OUT) )
    {
        GPIO_InitStructure.Pin = GPIO_Pin;
        GPIO_InitStructure.PxINEN = GPIO_IN_Dis;
        if(Type == OUT_PUSHPULL)    GPIO_InitStructure.PxODEN = GPIO_OD_Dis;
        else                        GPIO_InitStructure.PxODEN = GPIO_OD_En;
        GPIO_InitStructure.PxPUEN = GPIO_PU_Dis;
        GPIO_InitStructure.PxFCR = GPIO_FCR_OUT;
 
        GPIO_Init(GPIOx, &GPIO_InitStructure);        
    }
}
 
//GPIOHÊä³ö¿ÚÅäÖà
void OutputIO_H(uint32_t GPIO_Pin)
{
    uint32_t pinpos = 0x00,pinbit = 0x00;
 
    if(CDIF_CR_INTF_EN_Getable() == DISABLE)
    {
        CDIF_CR_INTF_EN_Setable(ENABLE);
    }
    for (pinpos = 0; pinpos < 4; pinpos++)
    { 
        pinbit = ((uint32_t)0x01) << pinpos;
        if(GPIO_Pin & pinbit)
        {
            GPIOH->INEN &= (~(1<<pinpos));
            GPIOH->PUEN &= (~(1<<pinpos));
            GPIOH->FCR &= (~(3<<(pinpos*2)));
            GPIOH->FCR |= (1<<(pinpos*2));
        }    
    }
    if(CDIF_CR_INTF_EN_Getable() == ENABLE)
    {
        CDIF_CR_INTF_EN_Setable(DISABLE);
    }
}
 
//IOÊý×ÖÌØÊ⹦Äܿڠ
//type 0 = ÆÕͨ 
//type 1 = OD (OD¹¦Äܽö²¿·ÖÌØÊ⹦ÄÜÖ§³Ö)
//type 2 = ÆÕͨ+ÉÏÀ­ 
//type 3 = OD+ÉÏÀ­
//#define ALTFUN_NORMAL                0
//#define ALTFUN_OPENDRAIN            1
//#define ALTFUN_PULLUP                2
//#define ALTFUN_OPENDRAIN_PULLUP    3
void AltFunIO( GPIO_Type* GPIOx, uint32_t GPIO_Pin, uint8_t Type  )
{                                                                
    GPIO_InitTypeDef  GPIO_InitStructure;
    GPIO_InitTypeDef  GPIO_InitStructureRun;
 
    GPIO_Get_InitPara(GPIOx, GPIO_Pin, &GPIO_InitStructureRun);
 
    if( (GPIO_InitStructureRun.Pin        != GPIO_Pin) ||
    (GPIO_InitStructureRun.PxINEN    != GPIO_IN_Dis) ||
    (((Type & 0x01) == 0)&&(GPIO_InitStructureRun.PxODEN    != GPIO_OD_Dis)) ||
    (((Type & 0x01) != 0)&&(GPIO_InitStructureRun.PxODEN    != GPIO_OD_En)) ||
    (((Type & 0x02) == 0)&&(GPIO_InitStructureRun.PxPUEN    != GPIO_PU_Dis)) ||
    (((Type & 0x02) != 0)&&(GPIO_InitStructureRun.PxPUEN    != GPIO_PU_En)) ||
    (GPIO_InitStructureRun.PxFCR    != GPIO_FCR_DIG) )
    {
        GPIO_InitStructure.Pin = GPIO_Pin;
        GPIO_InitStructure.PxINEN = GPIO_IN_Dis;
        if( (Type & 0x01) == 0 )    GPIO_InitStructure.PxODEN = GPIO_OD_Dis;
        else                        GPIO_InitStructure.PxODEN = GPIO_OD_En;
        if( (Type & 0x02) == 0 )    GPIO_InitStructure.PxPUEN = GPIO_PU_Dis;
        else                        GPIO_InitStructure.PxPUEN = GPIO_PU_En;    
        GPIO_InitStructure.PxFCR = GPIO_FCR_DIG;
 
        GPIO_Init(GPIOx, &GPIO_InitStructure);        
    }
}
 
//IOÊý×ÖÌØÊ⹦Äܿڠ
//type 0 = ÆÕͨ 
//type 1= ÆÕͨ+ÉÏÀ­ 
void AltFunIO_H(uint32_t GPIO_Pin, uint8_t Type  )
{                                                                
    uint32_t pinpos = 0x00,pinbit = 0x00;
 
    if(CDIF_CR_INTF_EN_Getable() == DISABLE)
    {
        CDIF_CR_INTF_EN_Setable(ENABLE);
    }
    for (pinpos = 0; pinpos < 4; pinpos++)
    { 
        pinbit = ((uint32_t)0x01) << pinpos;
        if(GPIO_Pin & pinbit)
        {
            GPIOH->INEN &= (~(1<<pinpos));
            if(Type==0)
            {
                GPIOH->PUEN &= (~(1<<pinpos));
            }
            else
            {
                GPIOH->PUEN |= (1<<pinpos);
            }
            GPIOH->FCR &= (~(3<<(pinpos*2)));
            GPIOH->FCR |= (2<<(pinpos*2));
        }    
    }
    if(CDIF_CR_INTF_EN_Getable() == ENABLE)
    {
        CDIF_CR_INTF_EN_Setable(DISABLE);
    }   
}
 
//IO¹Ø±Õ£¨GPIOA,B,C,D,E,F,G£©£¨odÊä³ö¸ß£©
//ÅäÖÃIOΪ¸ß×è̬
void CloseIO( GPIO_Type* GPIOx, uint32_t GPIO_Pin )
{
    uint32_t pinpos = 0x00,pinbit = 0x00;
 
    for (pinpos = 0; pinpos < 16; pinpos++)
    { 
        pinbit = ((uint32_t)0x01) << pinpos;
        if(GPIO_Pin & pinbit)
        {
            GPIOx->INEN &=~(1<<pinpos);
            GPIOx->FCR  &= ~(3<<(pinpos*2));
        }    
    }
}
 
//IO GPIOH¹Ø±Õ£¨odÊä³ö¸ß£©
//ÅäÖÃIOΪ¸ß×è̬
void CloseH_IO( GPIOH_Type* GPIOx, uint32_t GPIO_Pin )
{
    uint32_t pinpos = 0x00,pinbit = 0x00;
 
    if(CDIF_CR_INTF_EN_Getable() == DISABLE)
    {
        CDIF_CR_INTF_EN_Setable(ENABLE);
    }
    for (pinpos = 0; pinpos < 4; pinpos++)
    { 
        pinbit = ((uint32_t)0x01) << pinpos;
        if(GPIO_Pin & pinbit)
        {
            GPIOx->INEN &=~(1<<pinpos);
            GPIOx->FCR  &= ~(3<<(pinpos*2));
        }    
    }
    if(CDIF_CR_INTF_EN_Getable() == ENABLE)
    {
        CDIF_CR_INTF_EN_Setable(DISABLE);
    } 
}