123 #ifdef HAL_GPIO_MODULE_ENABLED 130 #define GPIO_MODE (0x00000003u) 131 #define ANALOG_MODE (0x00000008u) 132 #define EXTI_MODE (0x10000000u) 133 #define GPIO_MODE_IT (0x00010000u) 134 #define GPIO_MODE_EVT (0x00020000u) 135 #define RISING_EDGE (0x00100000u) 136 #define FALLING_EDGE (0x00200000u) 137 #define GPIO_OUTPUT_TYPE (0x00000010u) 139 #define GPIO_NUMBER (16u) 174 uint32_t position = 0x00u;
185 while (((GPIO_Init->Pin) >> position) != 0x00u)
188 iocurrent = (GPIO_Init->Pin) & (1uL << position);
190 if (iocurrent != 0x00u)
194 if((GPIO_Init->Mode == GPIO_MODE_AF_PP) || (GPIO_Init->Mode == GPIO_MODE_AF_OD))
201 temp = GPIOx->AFR[position >> 3u];
202 temp &= ~(0xFu << ((position & 0x07u) * 4u));
203 temp |= ((GPIO_Init->Alternate) << ((position & 0x07u) * 4u));
204 GPIOx->AFR[position >> 3u] = temp;
209 temp &= ~(GPIO_MODER_MODE0 << (position * 2u));
210 temp |= ((GPIO_Init->Mode & GPIO_MODE) << (position * 2u));
214 if((GPIO_Init->Mode == GPIO_MODE_OUTPUT_PP) || (GPIO_Init->Mode == GPIO_MODE_AF_PP) ||
215 (GPIO_Init->Mode == GPIO_MODE_OUTPUT_OD) || (GPIO_Init->Mode == GPIO_MODE_AF_OD))
220 temp = GPIOx->OSPEEDR;
221 temp &= ~(GPIO_OSPEEDR_OSPEED0 << (position * 2u));
222 temp |= (GPIO_Init->Speed << (position * 2u));
223 GPIOx->OSPEEDR = temp;
226 temp = GPIOx->OTYPER;
227 temp &= ~(GPIO_OTYPER_OT0 << position) ;
228 temp |= (((GPIO_Init->Mode & GPIO_OUTPUT_TYPE) >> 4u) << position);
229 GPIOx->OTYPER = temp;
232 #if defined(STM32L471xx) || defined(STM32L475xx) || defined(STM32L476xx) || defined(STM32L485xx) || defined(STM32L486xx) 235 if((GPIO_Init->Mode & GPIO_MODE_ANALOG) == GPIO_MODE_ANALOG)
239 temp &= ~(GPIO_ASCR_ASC0 << position) ;
240 temp |= (((GPIO_Init->Mode & ANALOG_MODE) >> 3) << position);
248 temp &= ~(GPIO_PUPDR_PUPD0 << (position * 2u));
249 temp |= ((GPIO_Init->Pull) << (position * 2u));
254 if((GPIO_Init->Mode & EXTI_MODE) == EXTI_MODE)
257 __HAL_RCC_SYSCFG_CLK_ENABLE();
259 temp = SYSCFG->EXTICR[position >> 2u];
260 temp &= ~(0x0FuL << (4u * (position & 0x03u)));
261 temp |= (GPIO_GET_INDEX(GPIOx) << (4u * (position & 0x03u)));
262 SYSCFG->EXTICR[position >> 2u] = temp;
266 temp &= ~(iocurrent);
267 if((GPIO_Init->Mode & GPIO_MODE_IT) == GPIO_MODE_IT)
274 temp &= ~(iocurrent);
275 if((GPIO_Init->Mode & GPIO_MODE_EVT) == GPIO_MODE_EVT)
283 temp &= ~(iocurrent);
284 if((GPIO_Init->Mode & RISING_EDGE) == RISING_EDGE)
291 temp &= ~(iocurrent);
292 if((GPIO_Init->Mode & FALLING_EDGE) == FALLING_EDGE)
313 uint32_t position = 0x00u;
322 while ((GPIO_Pin >> position) != 0x00u)
325 iocurrent = (GPIO_Pin) & (1uL << position);
327 if (iocurrent != 0x00u)
332 tmp = SYSCFG->EXTICR[position >> 2u];
333 tmp &= (0x0FuL << (4u * (position & 0x03u)));
334 if (tmp == (GPIO_GET_INDEX(GPIOx) << (4u * (position & 0x03u))))
337 EXTI->IMR1 &= ~(iocurrent);
338 EXTI->EMR1 &= ~(iocurrent);
341 EXTI->RTSR1 &= ~(iocurrent);
342 EXTI->FTSR1 &= ~(iocurrent);
344 tmp = 0x0FuL << (4u * (position & 0x03u));
345 SYSCFG->EXTICR[position >> 2u] &= ~tmp;
350 GPIOx->MODER |= (GPIO_MODER_MODE0 << (position * 2u));
353 GPIOx->AFR[position >> 3u] &= ~(0xFu << ((position & 0x07u) * 4u)) ;
356 GPIOx->OSPEEDR &= ~(GPIO_OSPEEDR_OSPEED0 << (position * 2u));
359 GPIOx->OTYPER &= ~(GPIO_OTYPER_OT0 << position) ;
362 GPIOx->PUPDR &= ~(GPIO_PUPDR_PUPD0 << (position * 2u));
364 #if defined(STM32L471xx) || defined(STM32L475xx) || defined(STM32L476xx) || defined(STM32L485xx) || defined(STM32L486xx) 366 GPIOx->ASCR &= ~(GPIO_ASCR_ASC0<< position);
404 if ((GPIOx->IDR & GPIO_Pin) != 0x00u)
439 GPIOx->BSRR = (uint32_t)GPIO_Pin;
443 GPIOx->BRR = (uint32_t)GPIO_Pin;
458 if ((GPIOx->ODR & GPIO_Pin) != 0x00u)
460 GPIOx->BRR = (uint32_t)GPIO_Pin;
464 GPIOx->BSRR = (uint32_t)GPIO_Pin;
481 __IO uint32_t tmp = GPIO_LCKR_LCKK;
492 GPIOx->LCKR = GPIO_Pin;
499 if ((GPIOx->LCKR & GPIO_LCKR_LCKK) != 0x00u)
517 if(__HAL_GPIO_EXTI_GET_IT(GPIO_Pin) != 0x00u)
519 __HAL_GPIO_EXTI_CLEAR_IT(GPIO_Pin);
GPIO_PinState HAL_GPIO_ReadPin(GPIO_TypeDef *GPIOx, uint16_t GPIO_Pin)
Read the specified input port pin.
void HAL_GPIO_DeInit(GPIO_TypeDef *GPIOx, uint32_t GPIO_Pin)
De-initialize the GPIOx peripheral registers to their default reset values.
void HAL_GPIO_EXTI_IRQHandler(uint16_t GPIO_Pin)
Handle EXTI interrupt request.
void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin)
EXTI line detection callback.
This file contains all the functions prototypes for the HAL module driver.
void HAL_GPIO_WritePin(GPIO_TypeDef *GPIOx, uint16_t GPIO_Pin, GPIO_PinState PinState)
Set or clear the selected data port bit.
GPIO_PinState
GPIO Bit SET and Bit RESET enumeration.
HAL_StatusTypeDef HAL_GPIO_LockPin(GPIO_TypeDef *GPIOx, uint16_t GPIO_Pin)
Lock GPIO Pins configuration registers.
void HAL_GPIO_Init(GPIO_TypeDef *GPIOx, GPIO_InitTypeDef *GPIO_Init)
Initialize the GPIOx peripheral according to the specified parameters in the GPIO_Init.
assert_param(IS_RTC_WAKEUP_CLOCK(WakeUpClock))
void HAL_GPIO_TogglePin(GPIO_TypeDef *GPIOx, uint16_t GPIO_Pin)
Toggle the specified GPIO pin.