#include "project.h" u8 GPIO_ReadInputData (GPIO_TypeDef *GPIOx) { return ((u8) GPIOx->IDR); } void GPIO_WriteHigh (GPIO_TypeDef *GPIOx, GPIO_Pin_TypeDef PortPins) { GPIOx->ODR |= (u8) PortPins; } void GPIO_WriteLow (GPIO_TypeDef *GPIOx, GPIO_Pin_TypeDef PortPins) { GPIOx->ODR &= (u8) (~PortPins); } /** * @brief Initializes the GPIOx according to the specified parameters. * @param GPIOx : Select the GPIO peripheral number (x = A to I). * @param GPIO_Pin : This parameter contains the pin number, it can be any value * of the @ref GPIO_Pin_TypeDef enumeration. * @param GPIO_Mode : This parameter can be a value of the * @ref GPIO_Mode_TypeDef enumeration. * @retval None */ void GPIO_Init (GPIO_TypeDef *GPIOx, GPIO_Pin_TypeDef GPIO_Pin, GPIO_Mode_TypeDef GPIO_Mode) { /*----------------------*/ /* Check the parameters */ /*----------------------*/ /* Reset corresponding bit to GPIO_Pin in CR2 register */ GPIOx->CR2 &= (u8) (~ (GPIO_Pin)); /*-----------------------------*/ /* Input/Output mode selection */ /*-----------------------------*/ if ((((u8) (GPIO_Mode)) & (u8) 0x80) != (u8) 0x00) { /* Output mode */ if ((((u8) (GPIO_Mode)) & (u8) 0x10) != (u8) 0x00) /* High level */ GPIOx->ODR |= (u8) GPIO_Pin; else /* Low level */ GPIOx->ODR &= (u8) (~ (GPIO_Pin)); /* Set Output mode */ GPIOx->DDR |= (u8) GPIO_Pin; } else { /* Input mode */ /* Set Input mode */ GPIOx->DDR &= (u8) (~ (GPIO_Pin)); } /*------------------------------------------------------------------------*/ /* Pull-Up/Float (Input) or Push-Pull/Open-Drain (Output) modes selection */ /*------------------------------------------------------------------------*/ if ((((u8) (GPIO_Mode)) & (u8) 0x40) != (u8) 0x00) /* Pull-Up or Push-Pull */ GPIOx->CR1 |= (u8) GPIO_Pin; else /* Float or Open-Drain */ GPIOx->CR1 &= (u8) (~ (GPIO_Pin)); /*-----------------------------------------------------*/ /* Interrupt (Input) or Slope (Output) modes selection */ /*-----------------------------------------------------*/ if ((((u8) (GPIO_Mode)) & (u8) 0x20) != (u8) 0x00) /* Interrupt or Slow slope */ GPIOx->CR2 |= (u8) GPIO_Pin; else /* No external interrupt or No slope control */ GPIOx->CR2 &= (u8) (~ (GPIO_Pin)); }