提交 | 用户 | age
|
bfc108
|
1 |
/**
|
Q |
2 |
******************************************************************************
|
|
3 |
* @file stm32f0xx_hal_gpio.c
|
|
4 |
* @author MCD Application Team
|
|
5 |
* @brief GPIO HAL module driver.
|
|
6 |
* This file provides firmware functions to manage the following
|
|
7 |
* functionalities of the General Purpose Input/Output (GPIO) peripheral:
|
|
8 |
* + Initialization and de-initialization functions
|
|
9 |
* + IO operation functions
|
|
10 |
*
|
|
11 |
@verbatim
|
|
12 |
==============================================================================
|
|
13 |
##### GPIO Peripheral features #####
|
|
14 |
==============================================================================
|
|
15 |
[..]
|
|
16 |
(+) Each port bit of the general-purpose I/O (GPIO) ports can be individually
|
|
17 |
configured by software in several modes:
|
|
18 |
(++) Input mode
|
|
19 |
(++) Analog mode
|
|
20 |
(++) Output mode
|
|
21 |
(++) Alternate function mode
|
|
22 |
(++) External interrupt/event lines
|
|
23 |
|
|
24 |
(+) During and just after reset, the alternate functions and external interrupt
|
|
25 |
lines are not active and the I/O ports are configured in input floating mode.
|
|
26 |
|
|
27 |
(+) All GPIO pins have weak internal pull-up and pull-down resistors, which can be
|
|
28 |
activated or not.
|
|
29 |
|
|
30 |
(+) In Output or Alternate mode, each IO can be configured on open-drain or push-pull
|
|
31 |
type and the IO speed can be selected depending on the VDD value.
|
|
32 |
|
|
33 |
(+) The microcontroller IO pins are connected to onboard peripherals/modules through a
|
|
34 |
multiplexer that allows only one peripheral alternate function (AF) connected
|
|
35 |
to an IO pin at a time. In this way, there can be no conflict between peripherals
|
|
36 |
sharing the same IO pin.
|
|
37 |
|
|
38 |
(+) All ports have external interrupt/event capability. To use external interrupt
|
|
39 |
lines, the port must be configured in input mode. All available GPIO pins are
|
|
40 |
connected to the 16 external interrupt/event lines from EXTI0 to EXTI15.
|
|
41 |
|
|
42 |
(+) The external interrupt/event controller consists of up to 28 edge detectors
|
|
43 |
(16 lines are connected to GPIO) for generating event/interrupt requests (each
|
|
44 |
input line can be independently configured to select the type (interrupt or event)
|
|
45 |
and the corresponding trigger event (rising or falling or both). Each line can
|
|
46 |
also be masked independently.
|
|
47 |
|
|
48 |
##### How to use this driver #####
|
|
49 |
==============================================================================
|
|
50 |
[..]
|
|
51 |
(#) Enable the GPIO AHB clock using the following function : __HAL_RCC_GPIOx_CLK_ENABLE().
|
|
52 |
|
|
53 |
(#) Configure the GPIO pin(s) using HAL_GPIO_Init().
|
|
54 |
(++) Configure the IO mode using "Mode" member from GPIO_InitTypeDef structure
|
|
55 |
(++) Activate Pull-up, Pull-down resistor using "Pull" member from GPIO_InitTypeDef
|
|
56 |
structure.
|
|
57 |
(++) In case of Output or alternate function mode selection: the speed is
|
|
58 |
configured through "Speed" member from GPIO_InitTypeDef structure.
|
|
59 |
(++) In alternate mode is selection, the alternate function connected to the IO
|
|
60 |
is configured through "Alternate" member from GPIO_InitTypeDef structure.
|
|
61 |
(++) Analog mode is required when a pin is to be used as ADC channel
|
|
62 |
or DAC output.
|
|
63 |
(++) In case of external interrupt/event selection the "Mode" member from
|
|
64 |
GPIO_InitTypeDef structure select the type (interrupt or event) and
|
|
65 |
the corresponding trigger event (rising or falling or both).
|
|
66 |
|
|
67 |
(#) In case of external interrupt/event mode selection, configure NVIC IRQ priority
|
|
68 |
mapped to the EXTI line using HAL_NVIC_SetPriority() and enable it using
|
|
69 |
HAL_NVIC_EnableIRQ().
|
|
70 |
|
|
71 |
(#) HAL_GPIO_DeInit allows to set register values to their reset value. It's also
|
|
72 |
recommended to use it to unconfigure pin which was used as an external interrupt
|
|
73 |
or in event mode. That's the only way to reset corresponding bit in EXTI & SYSCFG
|
|
74 |
registers.
|
|
75 |
|
|
76 |
(#) To get the level of a pin configured in input mode use HAL_GPIO_ReadPin().
|
|
77 |
|
|
78 |
(#) To set/reset the level of a pin configured in output mode use
|
|
79 |
HAL_GPIO_WritePin()/HAL_GPIO_TogglePin().
|
|
80 |
|
|
81 |
(#) To lock pin configuration until next reset use HAL_GPIO_LockPin().
|
|
82 |
|
|
83 |
(#) During and just after reset, the alternate functions are not
|
|
84 |
active and the GPIO pins are configured in input floating mode (except JTAG
|
|
85 |
pins).
|
|
86 |
|
|
87 |
(#) The LSE oscillator pins OSC32_IN and OSC32_OUT can be used as general purpose
|
|
88 |
(PC14 and PC15, respectively) when the LSE oscillator is off. The LSE has
|
|
89 |
priority over the GPIO function.
|
|
90 |
|
|
91 |
(#) The HSE oscillator pins OSC_IN/OSC_OUT can be used as
|
|
92 |
general purpose PF0 and PF1, respectively, when the HSE oscillator is off.
|
|
93 |
The HSE has priority over the GPIO function.
|
|
94 |
|
|
95 |
@endverbatim
|
|
96 |
******************************************************************************
|
|
97 |
* @attention
|
|
98 |
*
|
|
99 |
* <h2><center>© COPYRIGHT(c) 2016 STMicroelectronics</center></h2>
|
|
100 |
*
|
|
101 |
* Redistribution and use in source and binary forms, with or without modification,
|
|
102 |
* are permitted provided that the following conditions are met:
|
|
103 |
* 1. Redistributions of source code must retain the above copyright notice,
|
|
104 |
* this list of conditions and the following disclaimer.
|
|
105 |
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
|
106 |
* this list of conditions and the following disclaimer in the documentation
|
|
107 |
* and/or other materials provided with the distribution.
|
|
108 |
* 3. Neither the name of STMicroelectronics nor the names of its contributors
|
|
109 |
* may be used to endorse or promote products derived from this software
|
|
110 |
* without specific prior written permission.
|
|
111 |
*
|
|
112 |
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
113 |
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
114 |
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
115 |
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
|
116 |
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
117 |
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
118 |
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
|
119 |
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
|
120 |
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
121 |
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
122 |
*
|
|
123 |
******************************************************************************
|
|
124 |
*/
|
|
125 |
|
|
126 |
/* Includes ------------------------------------------------------------------*/
|
|
127 |
#include "stm32f0xx_hal.h"
|
|
128 |
|
|
129 |
/** @addtogroup STM32F0xx_HAL_Driver
|
|
130 |
* @{
|
|
131 |
*/
|
|
132 |
|
|
133 |
/** @defgroup GPIO GPIO
|
|
134 |
* @brief GPIO HAL module driver
|
|
135 |
* @{
|
|
136 |
*/
|
|
137 |
|
|
138 |
#ifdef HAL_GPIO_MODULE_ENABLED
|
|
139 |
|
|
140 |
/* Private typedef -----------------------------------------------------------*/
|
|
141 |
/* Private defines -----------------------------------------------------------*/
|
|
142 |
/** @defgroup GPIO_Private_Defines GPIO Private Defines
|
|
143 |
* @{
|
|
144 |
*/
|
|
145 |
#define GPIO_MODE (0x00000003U)
|
|
146 |
#define EXTI_MODE (0x10000000U)
|
|
147 |
#define GPIO_MODE_IT (0x00010000U)
|
|
148 |
#define GPIO_MODE_EVT (0x00020000U)
|
|
149 |
#define RISING_EDGE (0x00100000U)
|
|
150 |
#define FALLING_EDGE (0x00200000U)
|
|
151 |
#define GPIO_OUTPUT_TYPE (0x00000010U)
|
|
152 |
|
|
153 |
#define GPIO_NUMBER (16U)
|
|
154 |
/**
|
|
155 |
* @}
|
|
156 |
*/
|
|
157 |
|
|
158 |
/* Private macros ------------------------------------------------------------*/
|
|
159 |
/* Private variables ---------------------------------------------------------*/
|
|
160 |
/* Private function prototypes -----------------------------------------------*/
|
|
161 |
/* Exported functions --------------------------------------------------------*/
|
|
162 |
|
|
163 |
/** @defgroup GPIO_Exported_Functions GPIO Exported Functions
|
|
164 |
* @{
|
|
165 |
*/
|
|
166 |
|
|
167 |
/** @defgroup GPIO_Exported_Functions_Group1 Initialization/de-initialization functions
|
|
168 |
* @brief Initialization and Configuration functions
|
|
169 |
*
|
|
170 |
@verbatim
|
|
171 |
===============================================================================
|
|
172 |
##### Initialization and de-initialization functions #####
|
|
173 |
===============================================================================
|
|
174 |
|
|
175 |
@endverbatim
|
|
176 |
* @{
|
|
177 |
*/
|
|
178 |
|
|
179 |
/**
|
|
180 |
* @brief Initialize the GPIOx peripheral according to the specified parameters in the GPIO_Init.
|
|
181 |
* @param GPIOx where x can be (A..F) to select the GPIO peripheral for STM32F0 family
|
|
182 |
* @param GPIO_Init pointer to a GPIO_InitTypeDef structure that contains
|
|
183 |
* the configuration information for the specified GPIO peripheral.
|
|
184 |
* @retval None
|
|
185 |
*/
|
|
186 |
void HAL_GPIO_Init(GPIO_TypeDef *GPIOx, GPIO_InitTypeDef *GPIO_Init)
|
|
187 |
{
|
|
188 |
uint32_t position = 0x00U;
|
|
189 |
uint32_t iocurrent = 0x00U;
|
|
190 |
uint32_t temp = 0x00U;
|
|
191 |
|
|
192 |
/* Check the parameters */
|
|
193 |
assert_param(IS_GPIO_ALL_INSTANCE(GPIOx));
|
|
194 |
assert_param(IS_GPIO_PIN(GPIO_Init->Pin));
|
|
195 |
assert_param(IS_GPIO_MODE(GPIO_Init->Mode));
|
|
196 |
assert_param(IS_GPIO_PULL(GPIO_Init->Pull));
|
|
197 |
|
|
198 |
/* Configure the port pins */
|
|
199 |
while (((GPIO_Init->Pin) >> position) != RESET)
|
|
200 |
{
|
|
201 |
/* Get current io position */
|
|
202 |
iocurrent = (GPIO_Init->Pin) & (1U << position);
|
|
203 |
|
|
204 |
if(iocurrent)
|
|
205 |
{
|
|
206 |
/*--------------------- GPIO Mode Configuration ------------------------*/
|
|
207 |
/* In case of Alternate function mode selection */
|
|
208 |
if((GPIO_Init->Mode == GPIO_MODE_AF_PP) || (GPIO_Init->Mode == GPIO_MODE_AF_OD))
|
|
209 |
{
|
|
210 |
/* Check the Alternate function parameters */
|
|
211 |
assert_param(IS_GPIO_AF_INSTANCE(GPIOx));
|
|
212 |
assert_param(IS_GPIO_AF(GPIO_Init->Alternate));
|
|
213 |
|
|
214 |
/* Configure Alternate function mapped with the current IO */
|
|
215 |
temp = GPIOx->AFR[position >> 3];
|
|
216 |
CLEAR_BIT(temp, 0xFU << ((uint32_t)(position & 0x07U) * 4U)) ;
|
|
217 |
SET_BIT(temp, (uint32_t)(GPIO_Init->Alternate) << (((uint32_t)position & 0x07U) * 4U));
|
|
218 |
GPIOx->AFR[position >> 3U] = temp;
|
|
219 |
}
|
|
220 |
|
|
221 |
/* Configure IO Direction mode (Input, Output, Alternate or Analog) */
|
|
222 |
temp = GPIOx->MODER;
|
|
223 |
CLEAR_BIT(temp, GPIO_MODER_MODER0 << (position * 2U));
|
|
224 |
SET_BIT(temp, (GPIO_Init->Mode & GPIO_MODE) << (position * 2U));
|
|
225 |
GPIOx->MODER = temp;
|
|
226 |
|
|
227 |
/* In case of Output or Alternate function mode selection */
|
|
228 |
if ((GPIO_Init->Mode == GPIO_MODE_OUTPUT_PP) || (GPIO_Init->Mode == GPIO_MODE_AF_PP) ||
|
|
229 |
(GPIO_Init->Mode == GPIO_MODE_OUTPUT_OD) || (GPIO_Init->Mode == GPIO_MODE_AF_OD))
|
|
230 |
{
|
|
231 |
/* Check the Speed parameter */
|
|
232 |
assert_param(IS_GPIO_SPEED(GPIO_Init->Speed));
|
|
233 |
/* Configure the IO Speed */
|
|
234 |
temp = GPIOx->OSPEEDR;
|
|
235 |
CLEAR_BIT(temp, GPIO_OSPEEDER_OSPEEDR0 << (position * 2U));
|
|
236 |
SET_BIT(temp, GPIO_Init->Speed << (position * 2U));
|
|
237 |
GPIOx->OSPEEDR = temp;
|
|
238 |
|
|
239 |
/* Configure the IO Output Type */
|
|
240 |
temp = GPIOx->OTYPER;
|
|
241 |
CLEAR_BIT(temp, GPIO_OTYPER_OT_0 << position) ;
|
|
242 |
SET_BIT(temp, ((GPIO_Init->Mode & GPIO_OUTPUT_TYPE) >> 4U) << position);
|
|
243 |
GPIOx->OTYPER = temp;
|
|
244 |
}
|
|
245 |
|
|
246 |
/* Activate the Pull-up or Pull down resistor for the current IO */
|
|
247 |
temp = GPIOx->PUPDR;
|
|
248 |
CLEAR_BIT(temp, GPIO_PUPDR_PUPDR0 << (position * 2U));
|
|
249 |
SET_BIT(temp, (GPIO_Init->Pull) << (position * 2U));
|
|
250 |
GPIOx->PUPDR = temp;
|
|
251 |
|
|
252 |
/*--------------------- EXTI Mode Configuration ------------------------*/
|
|
253 |
/* Configure the External Interrupt or event for the current IO */
|
|
254 |
if((GPIO_Init->Mode & EXTI_MODE) == EXTI_MODE)
|
|
255 |
{
|
|
256 |
/* Enable SYSCFG Clock */
|
|
257 |
__HAL_RCC_SYSCFG_CLK_ENABLE();
|
|
258 |
|
|
259 |
temp = SYSCFG->EXTICR[position >> 2];
|
|
260 |
CLEAR_BIT(temp, (0x0FU) << (4U * (position & 0x03U)));
|
|
261 |
SET_BIT(temp, (GPIO_GET_INDEX(GPIOx)) << (4U * (position & 0x03U)));
|
|
262 |
SYSCFG->EXTICR[position >> 2] = temp;
|
|
263 |
|
|
264 |
/* Clear EXTI line configuration */
|
|
265 |
temp = EXTI->IMR;
|
|
266 |
CLEAR_BIT(temp, (uint32_t)iocurrent);
|
|
267 |
if((GPIO_Init->Mode & GPIO_MODE_IT) == GPIO_MODE_IT)
|
|
268 |
{
|
|
269 |
SET_BIT(temp, iocurrent);
|
|
270 |
}
|
|
271 |
EXTI->IMR = temp;
|
|
272 |
|
|
273 |
temp = EXTI->EMR;
|
|
274 |
CLEAR_BIT(temp, (uint32_t)iocurrent);
|
|
275 |
if((GPIO_Init->Mode & GPIO_MODE_EVT) == GPIO_MODE_EVT)
|
|
276 |
{
|
|
277 |
SET_BIT(temp, iocurrent);
|
|
278 |
}
|
|
279 |
EXTI->EMR = temp;
|
|
280 |
|
|
281 |
/* Clear Rising Falling edge configuration */
|
|
282 |
temp = EXTI->RTSR;
|
|
283 |
CLEAR_BIT(temp, (uint32_t)iocurrent);
|
|
284 |
if((GPIO_Init->Mode & RISING_EDGE) == RISING_EDGE)
|
|
285 |
{
|
|
286 |
SET_BIT(temp, iocurrent);
|
|
287 |
}
|
|
288 |
EXTI->RTSR = temp;
|
|
289 |
|
|
290 |
temp = EXTI->FTSR;
|
|
291 |
CLEAR_BIT(temp, (uint32_t)iocurrent);
|
|
292 |
if((GPIO_Init->Mode & FALLING_EDGE) == FALLING_EDGE)
|
|
293 |
{
|
|
294 |
SET_BIT(temp, iocurrent);
|
|
295 |
}
|
|
296 |
EXTI->FTSR = temp;
|
|
297 |
}
|
|
298 |
}
|
|
299 |
|
|
300 |
position++;
|
|
301 |
}
|
|
302 |
}
|
|
303 |
|
|
304 |
/**
|
|
305 |
* @brief De-initialize the GPIOx peripheral registers to their default reset values.
|
|
306 |
* @param GPIOx where x can be (A..F) to select the GPIO peripheral for STM32F0 family
|
|
307 |
* @param GPIO_Pin specifies the port bit to be written.
|
|
308 |
* This parameter can be one of GPIO_PIN_x where x can be (0..15).
|
|
309 |
* @retval None
|
|
310 |
*/
|
|
311 |
void HAL_GPIO_DeInit(GPIO_TypeDef *GPIOx, uint32_t GPIO_Pin)
|
|
312 |
{
|
|
313 |
uint32_t position = 0x00U;
|
|
314 |
uint32_t iocurrent = 0x00U;
|
|
315 |
uint32_t tmp = 0x00U;
|
|
316 |
|
|
317 |
/* Check the parameters */
|
|
318 |
assert_param(IS_GPIO_ALL_INSTANCE(GPIOx));
|
|
319 |
assert_param(IS_GPIO_PIN(GPIO_Pin));
|
|
320 |
|
|
321 |
/* Configure the port pins */
|
|
322 |
while ((GPIO_Pin >> position) != RESET)
|
|
323 |
{
|
|
324 |
/* Get current io position */
|
|
325 |
iocurrent = GPIO_Pin & (1U << position);
|
|
326 |
|
|
327 |
if (iocurrent)
|
|
328 |
{
|
|
329 |
/*------------------------- GPIO Mode Configuration --------------------*/
|
|
330 |
/* Configure IO Direction in Input Floting Mode */
|
|
331 |
CLEAR_BIT(GPIOx->MODER, GPIO_MODER_MODER0 << (position * 2U));
|
|
332 |
|
|
333 |
/* Configure the default Alternate Function in current IO */
|
|
334 |
CLEAR_BIT(GPIOx->AFR[position >> 3U], 0xFU << ((uint32_t)(position & 0x07U) * 4U)) ;
|
|
335 |
|
|
336 |
/* Configure the default value for IO Speed */
|
|
337 |
CLEAR_BIT(GPIOx->OSPEEDR, GPIO_OSPEEDER_OSPEEDR0 << (position * 2U));
|
|
338 |
|
|
339 |
/* Configure the default value IO Output Type */
|
|
340 |
CLEAR_BIT(GPIOx->OTYPER, GPIO_OTYPER_OT_0 << position) ;
|
|
341 |
|
|
342 |
/* Deactivate the Pull-up oand Pull-down resistor for the current IO */
|
|
343 |
CLEAR_BIT(GPIOx->PUPDR, GPIO_PUPDR_PUPDR0 << (position * 2U));
|
|
344 |
|
|
345 |
/*------------------------- EXTI Mode Configuration --------------------*/
|
|
346 |
/* Clear the External Interrupt or Event for the current IO */
|
|
347 |
|
|
348 |
tmp = SYSCFG->EXTICR[position >> 2U];
|
|
349 |
tmp &= ((0x0FU) << (4U * (position & 0x03U)));
|
|
350 |
if(tmp == (GPIO_GET_INDEX(GPIOx) << (4U * (position & 0x03U))))
|
|
351 |
{
|
|
352 |
tmp = (0x0FU) << (4U * (position & 0x03U));
|
|
353 |
CLEAR_BIT(SYSCFG->EXTICR[position >> 2U], tmp);
|
|
354 |
|
|
355 |
/* Clear EXTI line configuration */
|
|
356 |
CLEAR_BIT(EXTI->IMR, (uint32_t)iocurrent);
|
|
357 |
CLEAR_BIT(EXTI->EMR, (uint32_t)iocurrent);
|
|
358 |
|
|
359 |
/* Clear Rising Falling edge configuration */
|
|
360 |
CLEAR_BIT(EXTI->RTSR, (uint32_t)iocurrent);
|
|
361 |
CLEAR_BIT(EXTI->FTSR, (uint32_t)iocurrent);
|
|
362 |
}
|
|
363 |
}
|
|
364 |
|
|
365 |
position++;
|
|
366 |
}
|
|
367 |
}
|
|
368 |
|
|
369 |
/**
|
|
370 |
* @}
|
|
371 |
*/
|
|
372 |
|
|
373 |
/** @defgroup GPIO_Exported_Functions_Group2 IO operation functions
|
|
374 |
* @brief GPIO Read, Write, Toggle, Lock and EXTI management functions.
|
|
375 |
*
|
|
376 |
@verbatim
|
|
377 |
===============================================================================
|
|
378 |
##### IO operation functions #####
|
|
379 |
===============================================================================
|
|
380 |
|
|
381 |
@endverbatim
|
|
382 |
* @{
|
|
383 |
*/
|
|
384 |
|
|
385 |
/**
|
|
386 |
* @brief Read the specified input port pin.
|
|
387 |
* @param GPIOx where x can be (A..F) to select the GPIO peripheral for STM32F0 family
|
|
388 |
* @param GPIO_Pin specifies the port bit to read.
|
|
389 |
* This parameter can be GPIO_PIN_x where x can be (0..15).
|
|
390 |
* @retval The input port pin value.
|
|
391 |
*/
|
|
392 |
GPIO_PinState HAL_GPIO_ReadPin(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin)
|
|
393 |
{
|
|
394 |
GPIO_PinState bitstatus;
|
|
395 |
|
|
396 |
/* Check the parameters */
|
|
397 |
assert_param(IS_GPIO_PIN(GPIO_Pin));
|
|
398 |
|
|
399 |
if ((GPIOx->IDR & GPIO_Pin) != (uint32_t)GPIO_PIN_RESET)
|
|
400 |
{
|
|
401 |
bitstatus = GPIO_PIN_SET;
|
|
402 |
}
|
|
403 |
else
|
|
404 |
{
|
|
405 |
bitstatus = GPIO_PIN_RESET;
|
|
406 |
}
|
|
407 |
return bitstatus;
|
|
408 |
}
|
|
409 |
|
|
410 |
/**
|
|
411 |
* @brief Set or clear the selected data port bit.
|
|
412 |
* @note This function uses GPIOx_BSRR and GPIOx_BRR registers to allow atomic read/modify
|
|
413 |
* accesses. In this way, there is no risk of an IRQ occurring between
|
|
414 |
* the read and the modify access.
|
|
415 |
*
|
|
416 |
* @param GPIOx where x can be (A..H) to select the GPIO peripheral for STM32F0 family
|
|
417 |
* @param GPIO_Pin specifies the port bit to be written.
|
|
418 |
* This parameter can be one of GPIO_PIN_x where x can be (0..15).
|
|
419 |
* @param PinState specifies the value to be written to the selected bit.
|
|
420 |
* This parameter can be one of the GPIO_PinState enum values:
|
|
421 |
* @arg GPIO_PIN_RESET: to clear the port pin
|
|
422 |
* @arg GPIO_PIN_SET: to set the port pin
|
|
423 |
* @retval None
|
|
424 |
*/
|
|
425 |
void HAL_GPIO_WritePin(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin, GPIO_PinState PinState)
|
|
426 |
{
|
|
427 |
/* Check the parameters */
|
|
428 |
assert_param(IS_GPIO_PIN(GPIO_Pin));
|
|
429 |
assert_param(IS_GPIO_PIN_ACTION(PinState));
|
|
430 |
|
|
431 |
if (PinState != GPIO_PIN_RESET)
|
|
432 |
{
|
|
433 |
GPIOx->BSRR = (uint32_t)GPIO_Pin;
|
|
434 |
}
|
|
435 |
else
|
|
436 |
{
|
|
437 |
GPIOx->BRR = (uint32_t)GPIO_Pin;
|
|
438 |
}
|
|
439 |
}
|
|
440 |
|
|
441 |
/**
|
|
442 |
* @brief Toggle the specified GPIO pin.
|
|
443 |
* @param GPIOx where x can be (A..F) to select the GPIO peripheral for STM32F0 family
|
|
444 |
* @param GPIO_Pin specifies the pin to be toggled.
|
|
445 |
* @retval None
|
|
446 |
*/
|
|
447 |
void HAL_GPIO_TogglePin(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin)
|
|
448 |
{
|
|
449 |
/* Check the parameters */
|
|
450 |
assert_param(IS_GPIO_PIN(GPIO_Pin));
|
|
451 |
|
|
452 |
GPIOx->ODR ^= GPIO_Pin;
|
|
453 |
}
|
|
454 |
|
|
455 |
/**
|
|
456 |
* @brief Locks GPIO Pins configuration registers.
|
|
457 |
* @note The locked registers are GPIOx_MODER, GPIOx_OTYPER, GPIOx_OSPEEDR,
|
|
458 |
* GPIOx_PUPDR, GPIOx_AFRL and GPIOx_AFRH.
|
|
459 |
* @note The configuration of the locked GPIO pins can no longer be modified
|
|
460 |
* until the next reset.
|
|
461 |
* @param GPIOx where x can be (A..F) to select the GPIO peripheral for STM32F0 family
|
|
462 |
* @param GPIO_Pin specifies the port bits to be locked.
|
|
463 |
* This parameter can be any combination of GPIO_Pin_x where x can be (0..15).
|
|
464 |
* @retval None
|
|
465 |
*/
|
|
466 |
HAL_StatusTypeDef HAL_GPIO_LockPin(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin)
|
|
467 |
{
|
|
468 |
__IO uint32_t tmp = GPIO_LCKR_LCKK;
|
|
469 |
|
|
470 |
/* Check the parameters */
|
|
471 |
assert_param(IS_GPIO_LOCK_INSTANCE(GPIOx));
|
|
472 |
assert_param(IS_GPIO_PIN(GPIO_Pin));
|
|
473 |
|
|
474 |
/* Apply lock key write sequence */
|
|
475 |
SET_BIT(tmp, GPIO_Pin);
|
|
476 |
/* Set LCKx bit(s): LCKK='1' + LCK[15-0] */
|
|
477 |
GPIOx->LCKR = tmp;
|
|
478 |
/* Reset LCKx bit(s): LCKK='0' + LCK[15-0] */
|
|
479 |
GPIOx->LCKR = GPIO_Pin;
|
|
480 |
/* Set LCKx bit(s): LCKK='1' + LCK[15-0] */
|
|
481 |
GPIOx->LCKR = tmp;
|
|
482 |
/* Read LCKK bit*/
|
|
483 |
tmp = GPIOx->LCKR;
|
|
484 |
|
|
485 |
if((GPIOx->LCKR & GPIO_LCKR_LCKK) != RESET)
|
|
486 |
{
|
|
487 |
return HAL_OK;
|
|
488 |
}
|
|
489 |
else
|
|
490 |
{
|
|
491 |
return HAL_ERROR;
|
|
492 |
}
|
|
493 |
}
|
|
494 |
|
|
495 |
/**
|
|
496 |
* @brief Handle EXTI interrupt request.
|
|
497 |
* @param GPIO_Pin Specifies the port pin connected to corresponding EXTI line.
|
|
498 |
* @retval None
|
|
499 |
*/
|
|
500 |
void HAL_GPIO_EXTI_IRQHandler(uint16_t GPIO_Pin)
|
|
501 |
{
|
|
502 |
/* EXTI line interrupt detected */
|
|
503 |
if(__HAL_GPIO_EXTI_GET_IT(GPIO_Pin) != RESET)
|
|
504 |
{
|
|
505 |
__HAL_GPIO_EXTI_CLEAR_IT(GPIO_Pin);
|
|
506 |
HAL_GPIO_EXTI_Callback(GPIO_Pin);
|
|
507 |
}
|
|
508 |
}
|
|
509 |
|
|
510 |
/**
|
|
511 |
* @brief EXTI line detection callback.
|
|
512 |
* @param GPIO_Pin Specifies the port pin connected to corresponding EXTI line.
|
|
513 |
* @retval None
|
|
514 |
*/
|
|
515 |
__weak void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin)
|
|
516 |
{
|
|
517 |
/* Prevent unused argument(s) compilation warning */
|
|
518 |
UNUSED(GPIO_Pin);
|
|
519 |
|
|
520 |
/* NOTE: This function should not be modified, when the callback is needed,
|
|
521 |
the HAL_GPIO_EXTI_Callback could be implemented in the user file
|
|
522 |
*/
|
|
523 |
}
|
|
524 |
|
|
525 |
/**
|
|
526 |
* @}
|
|
527 |
*/
|
|
528 |
|
|
529 |
|
|
530 |
/**
|
|
531 |
* @}
|
|
532 |
*/
|
|
533 |
|
|
534 |
#endif /* HAL_GPIO_MODULE_ENABLED */
|
|
535 |
/**
|
|
536 |
* @}
|
|
537 |
*/
|
|
538 |
|
|
539 |
/**
|
|
540 |
* @}
|
|
541 |
*/
|
|
542 |
|
|
543 |
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|