提交 | 用户 | age
|
483170
|
1 |
/** |
Q |
2 |
****************************************************************************** |
|
3 |
* @file stm32f0xx_ll_gpio.c |
|
4 |
* @author MCD Application Team |
|
5 |
* @brief GPIO LL module driver. |
|
6 |
****************************************************************************** |
|
7 |
* @attention |
|
8 |
* |
|
9 |
* <h2><center>© COPYRIGHT(c) 2016 STMicroelectronics</center></h2> |
|
10 |
* |
|
11 |
* Redistribution and use in source and binary forms, with or without modification, |
|
12 |
* are permitted provided that the following conditions are met: |
|
13 |
* 1. Redistributions of source code must retain the above copyright notice, |
|
14 |
* this list of conditions and the following disclaimer. |
|
15 |
* 2. Redistributions in binary form must reproduce the above copyright notice, |
|
16 |
* this list of conditions and the following disclaimer in the documentation |
|
17 |
* and/or other materials provided with the distribution. |
|
18 |
* 3. Neither the name of STMicroelectronics nor the names of its contributors |
|
19 |
* may be used to endorse or promote products derived from this software |
|
20 |
* without specific prior written permission. |
|
21 |
* |
|
22 |
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
|
23 |
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
|
24 |
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
|
25 |
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE |
|
26 |
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
|
27 |
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
|
28 |
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
|
29 |
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
|
30 |
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
|
31 |
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
|
32 |
* |
|
33 |
****************************************************************************** |
|
34 |
*/ |
|
35 |
#if defined(USE_FULL_LL_DRIVER) |
|
36 |
|
|
37 |
/* Includes ------------------------------------------------------------------*/ |
|
38 |
#include "stm32f0xx_ll_gpio.h" |
|
39 |
#include "stm32f0xx_ll_bus.h" |
|
40 |
#ifdef USE_FULL_ASSERT |
|
41 |
#include "stm32_assert.h" |
|
42 |
#else |
|
43 |
#define assert_param(expr) ((void)0U) |
|
44 |
#endif |
|
45 |
|
|
46 |
/** @addtogroup STM32F0xx_LL_Driver |
|
47 |
* @{ |
|
48 |
*/ |
|
49 |
|
|
50 |
#if defined (GPIOA) || defined (GPIOB) || defined (GPIOC) || defined (GPIOD) || defined (GPIOE) || defined (GPIOF) |
|
51 |
|
|
52 |
/** @addtogroup GPIO_LL |
|
53 |
* @{ |
|
54 |
*/ |
|
55 |
|
|
56 |
/* Private types -------------------------------------------------------------*/ |
|
57 |
/* Private variables ---------------------------------------------------------*/ |
|
58 |
/* Private constants ---------------------------------------------------------*/ |
|
59 |
/* Private macros ------------------------------------------------------------*/ |
|
60 |
/** @addtogroup GPIO_LL_Private_Macros |
|
61 |
* @{ |
|
62 |
*/ |
|
63 |
#define IS_LL_GPIO_PIN(__VALUE__) (((0x00000000U) < (__VALUE__)) && ((__VALUE__) <= (LL_GPIO_PIN_ALL))) |
|
64 |
|
|
65 |
#define IS_LL_GPIO_MODE(__VALUE__) (((__VALUE__) == LL_GPIO_MODE_INPUT) ||\ |
|
66 |
((__VALUE__) == LL_GPIO_MODE_OUTPUT) ||\ |
|
67 |
((__VALUE__) == LL_GPIO_MODE_ALTERNATE) ||\ |
|
68 |
((__VALUE__) == LL_GPIO_MODE_ANALOG)) |
|
69 |
|
|
70 |
#define IS_LL_GPIO_OUTPUT_TYPE(__VALUE__) (((__VALUE__) == LL_GPIO_OUTPUT_PUSHPULL) ||\ |
|
71 |
((__VALUE__) == LL_GPIO_OUTPUT_OPENDRAIN)) |
|
72 |
|
|
73 |
#define IS_LL_GPIO_SPEED(__VALUE__) (((__VALUE__) == LL_GPIO_SPEED_FREQ_LOW) ||\ |
|
74 |
((__VALUE__) == LL_GPIO_SPEED_FREQ_MEDIUM) ||\ |
|
75 |
((__VALUE__) == LL_GPIO_SPEED_FREQ_HIGH)) |
|
76 |
|
|
77 |
#define IS_LL_GPIO_PULL(__VALUE__) (((__VALUE__) == LL_GPIO_PULL_NO) ||\ |
|
78 |
((__VALUE__) == LL_GPIO_PULL_UP) ||\ |
|
79 |
((__VALUE__) == LL_GPIO_PULL_DOWN)) |
|
80 |
|
|
81 |
#define IS_LL_GPIO_ALTERNATE(__VALUE__) (((__VALUE__) == LL_GPIO_AF_0 ) ||\ |
|
82 |
((__VALUE__) == LL_GPIO_AF_1 ) ||\ |
|
83 |
((__VALUE__) == LL_GPIO_AF_2 ) ||\ |
|
84 |
((__VALUE__) == LL_GPIO_AF_3 ) ||\ |
|
85 |
((__VALUE__) == LL_GPIO_AF_4 ) ||\ |
|
86 |
((__VALUE__) == LL_GPIO_AF_5 ) ||\ |
|
87 |
((__VALUE__) == LL_GPIO_AF_6 ) ||\ |
|
88 |
((__VALUE__) == LL_GPIO_AF_7 )) |
|
89 |
/** |
|
90 |
* @} |
|
91 |
*/ |
|
92 |
|
|
93 |
/* Private function prototypes -----------------------------------------------*/ |
|
94 |
|
|
95 |
/* Exported functions --------------------------------------------------------*/ |
|
96 |
/** @addtogroup GPIO_LL_Exported_Functions |
|
97 |
* @{ |
|
98 |
*/ |
|
99 |
|
|
100 |
/** @addtogroup GPIO_LL_EF_Init |
|
101 |
* @{ |
|
102 |
*/ |
|
103 |
|
|
104 |
/** |
|
105 |
* @brief De-initialize GPIO registers (Registers restored to their default values). |
|
106 |
* @param GPIOx GPIO Port |
|
107 |
* @retval An ErrorStatus enumeration value: |
|
108 |
* - SUCCESS: GPIO registers are de-initialized |
|
109 |
* - ERROR: Wrong GPIO Port |
|
110 |
*/ |
|
111 |
ErrorStatus LL_GPIO_DeInit(GPIO_TypeDef *GPIOx) |
|
112 |
{ |
|
113 |
ErrorStatus status = SUCCESS; |
|
114 |
|
|
115 |
/* Check the parameters */ |
|
116 |
assert_param(IS_GPIO_ALL_INSTANCE(GPIOx)); |
|
117 |
|
|
118 |
/* Force and Release reset on clock of GPIOx Port */ |
|
119 |
if (GPIOx == GPIOA) |
|
120 |
{ |
|
121 |
LL_AHB1_GRP1_ForceReset(LL_AHB1_GRP1_PERIPH_GPIOA); |
|
122 |
LL_AHB1_GRP1_ReleaseReset(LL_AHB1_GRP1_PERIPH_GPIOA); |
|
123 |
} |
|
124 |
else if (GPIOx == GPIOB) |
|
125 |
{ |
|
126 |
LL_AHB1_GRP1_ForceReset(LL_AHB1_GRP1_PERIPH_GPIOB); |
|
127 |
LL_AHB1_GRP1_ReleaseReset(LL_AHB1_GRP1_PERIPH_GPIOB); |
|
128 |
} |
|
129 |
else if (GPIOx == GPIOC) |
|
130 |
{ |
|
131 |
LL_AHB1_GRP1_ForceReset(LL_AHB1_GRP1_PERIPH_GPIOC); |
|
132 |
LL_AHB1_GRP1_ReleaseReset(LL_AHB1_GRP1_PERIPH_GPIOC); |
|
133 |
} |
|
134 |
#if defined(GPIOD) |
|
135 |
else if (GPIOx == GPIOD) |
|
136 |
{ |
|
137 |
LL_AHB1_GRP1_ForceReset(LL_AHB1_GRP1_PERIPH_GPIOD); |
|
138 |
LL_AHB1_GRP1_ReleaseReset(LL_AHB1_GRP1_PERIPH_GPIOD); |
|
139 |
} |
|
140 |
#endif /* GPIOD */ |
|
141 |
#if defined(GPIOE) |
|
142 |
else if (GPIOx == GPIOE) |
|
143 |
{ |
|
144 |
LL_AHB1_GRP1_ForceReset(LL_AHB1_GRP1_PERIPH_GPIOE); |
|
145 |
LL_AHB1_GRP1_ReleaseReset(LL_AHB1_GRP1_PERIPH_GPIOE); |
|
146 |
} |
|
147 |
#endif /* GPIOE */ |
|
148 |
#if defined(GPIOF) |
|
149 |
else if (GPIOx == GPIOF) |
|
150 |
{ |
|
151 |
LL_AHB1_GRP1_ForceReset(LL_AHB1_GRP1_PERIPH_GPIOF); |
|
152 |
LL_AHB1_GRP1_ReleaseReset(LL_AHB1_GRP1_PERIPH_GPIOF); |
|
153 |
} |
|
154 |
#endif /* GPIOF */ |
|
155 |
else |
|
156 |
{ |
|
157 |
status = ERROR; |
|
158 |
} |
|
159 |
|
|
160 |
return (status); |
|
161 |
} |
|
162 |
|
|
163 |
/** |
|
164 |
* @brief Initialize GPIO registers according to the specified parameters in GPIO_InitStruct. |
|
165 |
* @param GPIOx GPIO Port |
|
166 |
* @param GPIO_InitStruct pointer to a @ref LL_GPIO_InitTypeDef structure |
|
167 |
* that contains the configuration information for the specified GPIO peripheral. |
|
168 |
* @retval An ErrorStatus enumeration value: |
|
169 |
* - SUCCESS: GPIO registers are initialized according to GPIO_InitStruct content |
|
170 |
* - ERROR: Not applicable |
|
171 |
*/ |
|
172 |
ErrorStatus LL_GPIO_Init(GPIO_TypeDef *GPIOx, LL_GPIO_InitTypeDef *GPIO_InitStruct) |
|
173 |
{ |
|
174 |
uint32_t pinpos = 0x00000000U; |
|
175 |
uint32_t currentpin = 0x00000000U; |
|
176 |
|
|
177 |
/* Check the parameters */ |
|
178 |
assert_param(IS_GPIO_ALL_INSTANCE(GPIOx)); |
|
179 |
assert_param(IS_LL_GPIO_PIN(GPIO_InitStruct->Pin)); |
|
180 |
assert_param(IS_LL_GPIO_MODE(GPIO_InitStruct->Mode)); |
|
181 |
assert_param(IS_LL_GPIO_PULL(GPIO_InitStruct->Pull)); |
|
182 |
|
|
183 |
/* ------------------------- Configure the port pins ---------------- */ |
|
184 |
/* Initialize pinpos on first pin set */ |
|
185 |
/* pinpos = 0; useless as already done in default initialization */ |
|
186 |
|
|
187 |
/* Configure the port pins */ |
|
188 |
while (((GPIO_InitStruct->Pin) >> pinpos) != 0x00000000U) |
|
189 |
{ |
|
190 |
/* Get current io position */ |
|
191 |
currentpin = (GPIO_InitStruct->Pin) & (0x00000001U << pinpos); |
|
192 |
|
|
193 |
if (currentpin) |
|
194 |
{ |
|
195 |
/* Pin Mode configuration */ |
|
196 |
LL_GPIO_SetPinMode(GPIOx, currentpin, GPIO_InitStruct->Mode); |
|
197 |
|
|
198 |
if ((GPIO_InitStruct->Mode == LL_GPIO_MODE_OUTPUT) || (GPIO_InitStruct->Mode == LL_GPIO_MODE_ALTERNATE)) |
|
199 |
{ |
|
200 |
/* Check Speed mode parameters */ |
|
201 |
assert_param(IS_LL_GPIO_SPEED(GPIO_InitStruct->Speed)); |
|
202 |
|
|
203 |
/* Speed mode configuration */ |
|
204 |
LL_GPIO_SetPinSpeed(GPIOx, currentpin, GPIO_InitStruct->Speed); |
|
205 |
} |
|
206 |
|
|
207 |
/* Pull-up Pull down resistor configuration*/ |
|
208 |
LL_GPIO_SetPinPull(GPIOx, currentpin, GPIO_InitStruct->Pull); |
|
209 |
|
|
210 |
if (GPIO_InitStruct->Mode == LL_GPIO_MODE_ALTERNATE) |
|
211 |
{ |
|
212 |
/* Check Alternate parameter */ |
|
213 |
assert_param(IS_LL_GPIO_ALTERNATE(GPIO_InitStruct->Alternate)); |
|
214 |
|
|
215 |
/* Speed mode configuration */ |
|
216 |
if (currentpin < LL_GPIO_PIN_8) |
|
217 |
{ |
|
218 |
LL_GPIO_SetAFPin_0_7(GPIOx, currentpin, GPIO_InitStruct->Alternate); |
|
219 |
} |
|
220 |
else |
|
221 |
{ |
|
222 |
LL_GPIO_SetAFPin_8_15(GPIOx, currentpin, GPIO_InitStruct->Alternate); |
|
223 |
} |
|
224 |
} |
|
225 |
} |
|
226 |
pinpos++; |
|
227 |
} |
|
228 |
|
|
229 |
if ((GPIO_InitStruct->Mode == LL_GPIO_MODE_OUTPUT) || (GPIO_InitStruct->Mode == LL_GPIO_MODE_ALTERNATE)) |
|
230 |
{ |
|
231 |
/* Check Output mode parameters */ |
|
232 |
assert_param(IS_LL_GPIO_OUTPUT_TYPE(GPIO_InitStruct->OutputType)); |
|
233 |
|
|
234 |
/* Output mode configuration*/ |
|
235 |
LL_GPIO_SetPinOutputType(GPIOx, GPIO_InitStruct->Pin, GPIO_InitStruct->OutputType); |
|
236 |
|
|
237 |
} |
|
238 |
return (SUCCESS); |
|
239 |
} |
|
240 |
|
|
241 |
/** |
|
242 |
* @brief Set each @ref LL_GPIO_InitTypeDef field to default value. |
|
243 |
* @param GPIO_InitStruct pointer to a @ref LL_GPIO_InitTypeDef structure |
|
244 |
* whose fields will be set to default values. |
|
245 |
* @retval None |
|
246 |
*/ |
|
247 |
|
|
248 |
void LL_GPIO_StructInit(LL_GPIO_InitTypeDef *GPIO_InitStruct) |
|
249 |
{ |
|
250 |
/* Reset GPIO init structure parameters values */ |
|
251 |
GPIO_InitStruct->Pin = LL_GPIO_PIN_ALL; |
|
252 |
GPIO_InitStruct->Mode = LL_GPIO_MODE_ANALOG; |
|
253 |
GPIO_InitStruct->Speed = LL_GPIO_SPEED_FREQ_LOW; |
|
254 |
GPIO_InitStruct->OutputType = LL_GPIO_OUTPUT_PUSHPULL; |
|
255 |
GPIO_InitStruct->Pull = LL_GPIO_PULL_NO; |
|
256 |
GPIO_InitStruct->Alternate = LL_GPIO_AF_0; |
|
257 |
} |
|
258 |
|
|
259 |
/** |
|
260 |
* @} |
|
261 |
*/ |
|
262 |
|
|
263 |
/** |
|
264 |
* @} |
|
265 |
*/ |
|
266 |
|
|
267 |
/** |
|
268 |
* @} |
|
269 |
*/ |
|
270 |
|
|
271 |
#endif /* defined (GPIOA) || defined (GPIOB) || defined (GPIOC) || defined (GPIOD) || defined (GPIOE) || defined (GPIOF) */ |
|
272 |
|
|
273 |
/** |
|
274 |
* @} |
|
275 |
*/ |
|
276 |
|
|
277 |
#endif /* USE_FULL_LL_DRIVER */ |
|
278 |
|
|
279 |
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ |