119 #ifdef HAL_GPIO_MODULE_ENABLED
127 #define GPIO_NUMBER 16U
167 uint32_t ioposition = 0x00U;
168 uint32_t iocurrent = 0x00U;
169 uint32_t temp = 0x00U;
172 assert_param(IS_GPIO_ALL_INSTANCE(GPIOx));
173 assert_param(IS_GPIO_PIN(GPIO_Init->Pin));
174 assert_param(IS_GPIO_MODE(GPIO_Init->Mode));
177 for(position = 0U; position < GPIO_NUMBER; position++)
180 ioposition = 0x01U << position;
182 iocurrent = (uint32_t)(GPIO_Init->Pin) & ioposition;
184 if(iocurrent == ioposition)
188 if(((GPIO_Init->Mode & GPIO_MODE) == MODE_OUTPUT) || \
189 (GPIO_Init->Mode & GPIO_MODE) == MODE_AF)
192 assert_param(IS_GPIO_SPEED(GPIO_Init->Speed));
194 temp = GPIOx->OSPEEDR;
195 temp &= ~(GPIO_OSPEEDER_OSPEEDR0 << (position * 2U));
196 temp |= (GPIO_Init->Speed << (position * 2U));
197 GPIOx->OSPEEDR = temp;
200 temp = GPIOx->OTYPER;
201 temp &= ~(GPIO_OTYPER_OT_0 << position) ;
202 temp |= (((GPIO_Init->Mode & OUTPUT_TYPE) >> OUTPUT_TYPE_Pos) << position);
203 GPIOx->OTYPER = temp;
206 if((GPIO_Init->Mode & GPIO_MODE) != MODE_ANALOG)
209 assert_param(IS_GPIO_PULL(GPIO_Init->Pull));
213 temp &= ~(GPIO_PUPDR_PUPDR0 << (position * 2U));
214 temp |= ((GPIO_Init->Pull) << (position * 2U));
219 if((GPIO_Init->Mode & GPIO_MODE) == MODE_AF)
222 assert_param(IS_GPIO_AF(GPIO_Init->Alternate));
224 temp = GPIOx->AFR[position >> 3U];
225 temp &= ~(0xFU << ((uint32_t)(position & 0x07U) * 4U)) ;
226 temp |= ((uint32_t)(GPIO_Init->Alternate) << (((uint32_t)position & 0x07U) * 4U));
227 GPIOx->AFR[position >> 3U] = temp;
232 temp &= ~(GPIO_MODER_MODER0 << (position * 2U));
233 temp |= ((GPIO_Init->Mode & GPIO_MODE) << (position * 2U));
238 if((GPIO_Init->Mode & EXTI_MODE) != 0x00U)
241 __HAL_RCC_SYSCFG_CLK_ENABLE();
243 temp = SYSCFG->EXTICR[position >> 2U];
244 temp &= ~(0x0FU << (4U * (position & 0x03U)));
245 temp |= ((uint32_t)(GPIO_GET_INDEX(GPIOx)) << (4U * (position & 0x03U)));
246 SYSCFG->EXTICR[position >> 2U] = temp;
250 temp &= ~((uint32_t)iocurrent);
251 if((GPIO_Init->Mode & TRIGGER_RISING) != 0x00U)
258 temp &= ~((uint32_t)iocurrent);
259 if((GPIO_Init->Mode & TRIGGER_FALLING) != 0x00U)
266 temp &= ~((uint32_t)iocurrent);
267 if((GPIO_Init->Mode & EXTI_EVT) != 0x00U)
275 temp &= ~((uint32_t)iocurrent);
276 if((GPIO_Init->Mode & EXTI_IT) != 0x00U)
297 uint32_t ioposition = 0x00U;
298 uint32_t iocurrent = 0x00U;
299 uint32_t tmp = 0x00U;
302 assert_param(IS_GPIO_ALL_INSTANCE(GPIOx));
305 for(position = 0U; position < GPIO_NUMBER; position++)
308 ioposition = 0x01U << position;
310 iocurrent = (GPIO_Pin) & ioposition;
312 if(iocurrent == ioposition)
315 tmp = SYSCFG->EXTICR[position >> 2U];
316 tmp &= (0x0FU << (4U * (position & 0x03U)));
317 if(tmp == ((uint32_t)(GPIO_GET_INDEX(GPIOx)) << (4U * (position & 0x03U))))
320 EXTI->IMR &= ~((uint32_t)iocurrent);
321 EXTI->EMR &= ~((uint32_t)iocurrent);
324 EXTI->FTSR &= ~((uint32_t)iocurrent);
325 EXTI->RTSR &= ~((uint32_t)iocurrent);
328 tmp = 0x0FU << (4U * (position & 0x03U));
329 SYSCFG->EXTICR[position >> 2U] &= ~tmp;
334 GPIOx->MODER &= ~(GPIO_MODER_MODER0 << (position * 2U));
337 GPIOx->AFR[position >> 3U] &= ~(0xFU << ((uint32_t)(position & 0x07U) * 4U)) ;
340 GPIOx->PUPDR &= ~(GPIO_PUPDR_PUPDR0 << (position * 2U));
343 GPIOx->OTYPER &= ~(GPIO_OTYPER_OT_0 << position) ;
346 GPIOx->OSPEEDR &= ~(GPIO_OSPEEDER_OSPEEDR0 << (position * 2U));
380 assert_param(IS_GPIO_PIN(GPIO_Pin));
382 if((GPIOx->IDR & GPIO_Pin) != (uint32_t)GPIO_PIN_RESET)
384 bitstatus = GPIO_PIN_SET;
388 bitstatus = GPIO_PIN_RESET;
413 assert_param(IS_GPIO_PIN(GPIO_Pin));
414 assert_param(IS_GPIO_PIN_ACTION(PinState));
416 if(PinState != GPIO_PIN_RESET)
418 GPIOx->BSRR = GPIO_Pin;
422 GPIOx->BSRR = (uint32_t)GPIO_Pin << 16U;
438 assert_param(IS_GPIO_PIN(GPIO_Pin));
444 GPIOx->BSRR = ((odr & GPIO_Pin) << GPIO_NUMBER) | (~odr & GPIO_Pin);
460 __IO uint32_t tmp = GPIO_LCKR_LCKK;
463 assert_param(IS_GPIO_PIN(GPIO_Pin));
470 GPIOx->LCKR = GPIO_Pin;
477 if((GPIOx->LCKR & GPIO_LCKR_LCKK) != RESET)
495 if(__HAL_GPIO_EXTI_GET_IT(GPIO_Pin) != RESET)
497 __HAL_GPIO_EXTI_CLEAR_IT(GPIO_Pin);
void HAL_GPIO_Init(GPIO_TypeDef *GPIOx, GPIO_InitTypeDef *GPIO_Init)
Initializes the GPIOx peripheral according to the specified parameters in the GPIO_Init.
void HAL_GPIO_DeInit(GPIO_TypeDef *GPIOx, uint32_t GPIO_Pin)
De-initializes the GPIOx peripheral registers to their default reset values.
void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin)
EXTI line detection callbacks.
void HAL_GPIO_EXTI_IRQHandler(uint16_t GPIO_Pin)
This function handles EXTI interrupt request.
HAL_StatusTypeDef HAL_GPIO_LockPin(GPIO_TypeDef *GPIOx, uint16_t GPIO_Pin)
Locks GPIO Pins configuration registers.
GPIO_PinState HAL_GPIO_ReadPin(GPIO_TypeDef *GPIOx, uint16_t GPIO_Pin)
Reads the specified input port pin.
void HAL_GPIO_WritePin(GPIO_TypeDef *GPIOx, uint16_t GPIO_Pin, GPIO_PinState PinState)
Sets or clears the selected data port bit.
void HAL_GPIO_TogglePin(GPIO_TypeDef *GPIOx, uint16_t GPIO_Pin)
Toggles the specified GPIO pins.
This file contains all the functions prototypes for the HAL module driver.
GPIO_PinState
GPIO Bit SET and Bit RESET enumeration.