Changeset - 9336fdac7c05
[Not reviewed]
cortex-f0
0 2 0
Ethan Zonca - 10 years ago 2015-01-03 00:04:24
ez@ethanzonca.com
Add toggle GPIO func
2 files changed with 18 insertions and 0 deletions:
0 comments (0 inline, 0 general)
libraries/STM32F0xx_StdPeriph_Driver/inc/stm32f0xx_gpio.h
Show inline comments
 
/**
 
  ******************************************************************************
 
  * @file    stm32f0xx_gpio.h
 
  * @author  MCD Application Team
 
  * @version V1.4.0
 
  * @date    24-July-2014
 
  * @brief   This file contains all the functions prototypes for the GPIO 
 
  *          firmware library. 
 
  ******************************************************************************
 
  * @attention
 
  *
 
  * <h2><center>&copy; COPYRIGHT 2014 STMicroelectronics</center></h2>
 
  *
 
  * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
 
  * You may not use this file except in compliance with the License.
 
  * You may obtain a copy of the License at:
 
  *
 
  *        http://www.st.com/software_license_agreement_liberty_v2
 
  *
 
  * Unless required by applicable law or agreed to in writing, software 
 
  * distributed under the License is distributed on an "AS IS" BASIS, 
 
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 
  * See the License for the specific language governing permissions and
 
  * limitations under the License.
 
  *
 
  ******************************************************************************
 
  */
 
 
/* Define to prevent recursive inclusion -------------------------------------*/
 
#ifndef __STM32F0XX_GPIO_H
 
#define __STM32F0XX_GPIO_H
 
 
#ifdef __cplusplus
 
 extern "C" {
 
#endif
 
 
/* Includes ------------------------------------------------------------------*/
 
#include "stm32f0xx.h"
 
 
/** @addtogroup STM32F0xx_StdPeriph_Driver
 
  * @{
 
  */
 
 
/** @addtogroup GPIO
 
  * @{
 
  */
 
/* Exported types ------------------------------------------------------------*/
 
 
#define IS_GPIO_ALL_PERIPH(PERIPH) (((PERIPH) == GPIOA) || \
 
                                    ((PERIPH) == GPIOB) || \
 
                                    ((PERIPH) == GPIOC) || \
 
                                    ((PERIPH) == GPIOD) || \
 
                                    ((PERIPH) == GPIOE) || \
 
                                    ((PERIPH) == GPIOF))
 
 
#define IS_GPIO_LIST_PERIPH(PERIPH) (((PERIPH) == GPIOA) || \
 
                                     ((PERIPH) == GPIOB))
 
 
/** @defgroup Configuration_Mode_enumeration 
 
  * @{
 
  */
 
typedef enum
 
{
 
  GPIO_Mode_IN   = 0x00, /*!< GPIO Input Mode              */
 
  GPIO_Mode_OUT  = 0x01, /*!< GPIO Output Mode             */
 
  GPIO_Mode_AF   = 0x02, /*!< GPIO Alternate function Mode */
 
  GPIO_Mode_AN   = 0x03  /*!< GPIO Analog In/Out Mode      */
 
}GPIOMode_TypeDef;
 
 
#define IS_GPIO_MODE(MODE) (((MODE) == GPIO_Mode_IN)|| ((MODE) == GPIO_Mode_OUT) || \
 
                            ((MODE) == GPIO_Mode_AF)|| ((MODE) == GPIO_Mode_AN))
 
/**
 
  * @}
 
  */
 
 
/** @defgroup Output_type_enumeration
 
  * @{
 
  */
 
typedef enum
 
{
 
  GPIO_OType_PP = 0x00,
 
  GPIO_OType_OD = 0x01
 
}GPIOOType_TypeDef;
 
 
#define IS_GPIO_OTYPE(OTYPE) (((OTYPE) == GPIO_OType_PP) || ((OTYPE) == GPIO_OType_OD))
 
 
/**
 
  * @}
 
  */
 
 
/** @defgroup Output_Maximum_frequency_enumeration 
 
  * @{
 
  */
 
typedef enum
 
{
 
  GPIO_Speed_Level_1  = 0x00, /*!< I/O output speed: Low 2 MHz */
 
  GPIO_Speed_Level_2  = 0x01, /*!< I/O output speed: Medium 10 MHz */
 
  GPIO_Speed_Level_3  = 0x03  /*!< I/O output speed: High 50 MHz */
 
}GPIOSpeed_TypeDef;
 
 
#define IS_GPIO_SPEED(SPEED) (((SPEED) == GPIO_Speed_Level_1) || ((SPEED) == GPIO_Speed_Level_2) || \
 
                              ((SPEED) == GPIO_Speed_Level_3))
 
/**
 
  * @}
 
  */
 
 
/** @defgroup Configuration_Pull-Up_Pull-Down_enumeration 
 
  * @{
 
  */
 
typedef enum
 
{
 
  GPIO_PuPd_NOPULL = 0x00,
 
  GPIO_PuPd_UP     = 0x01,
 
  GPIO_PuPd_DOWN   = 0x02
 
}GPIOPuPd_TypeDef;
 
 
#define IS_GPIO_PUPD(PUPD) (((PUPD) == GPIO_PuPd_NOPULL) || ((PUPD) == GPIO_PuPd_UP) || \
 
                            ((PUPD) == GPIO_PuPd_DOWN))
 
/**
 
  * @}
 
  */
 
 
/** @defgroup Bit_SET_and_Bit_RESET_enumeration
 
  * @{
 
  */
 
typedef enum
 
{ 
 
  Bit_RESET = 0,
 
  Bit_SET
 
}BitAction;
 
 
#define IS_GPIO_BIT_ACTION(ACTION) (((ACTION) == Bit_RESET) || ((ACTION) == Bit_SET))
 
/**
 
  * @}
 
  */
 
 
/**
 
  * @brief  GPIO Init structure definition  
 
  */
 
typedef struct
 
{
 
  uint32_t GPIO_Pin;              /*!< Specifies the GPIO pins to be configured.
 
                                       This parameter can be any value of @ref GPIO_pins_define */
 
                                       
 
  GPIOMode_TypeDef GPIO_Mode;     /*!< Specifies the operating mode for the selected pins.
 
                                       This parameter can be a value of @ref GPIOMode_TypeDef   */
 
 
  GPIOSpeed_TypeDef GPIO_Speed;   /*!< Specifies the speed for the selected pins.
 
                                       This parameter can be a value of @ref GPIOSpeed_TypeDef  */
 
 
  GPIOOType_TypeDef GPIO_OType;   /*!< Specifies the operating output type for the selected pins.
 
                                       This parameter can be a value of @ref GPIOOType_TypeDef  */
 
 
  GPIOPuPd_TypeDef GPIO_PuPd;     /*!< Specifies the operating Pull-up/Pull down for the selected pins.
 
                                       This parameter can be a value of @ref GPIOPuPd_TypeDef   */
 
}GPIO_InitTypeDef;
 
 
/* Exported constants --------------------------------------------------------*/
 
 
/** @defgroup GPIO_Exported_Constants
 
  * @{
 
  */
 
 
/** @defgroup GPIO_pins_define 
 
  * @{
 
  */
 
#define GPIO_Pin_0                 ((uint16_t)0x0001)  /*!< Pin 0 selected    */
 
#define GPIO_Pin_1                 ((uint16_t)0x0002)  /*!< Pin 1 selected    */
 
#define GPIO_Pin_2                 ((uint16_t)0x0004)  /*!< Pin 2 selected    */
 
#define GPIO_Pin_3                 ((uint16_t)0x0008)  /*!< Pin 3 selected    */
 
#define GPIO_Pin_4                 ((uint16_t)0x0010)  /*!< Pin 4 selected    */
 
#define GPIO_Pin_5                 ((uint16_t)0x0020)  /*!< Pin 5 selected    */
 
#define GPIO_Pin_6                 ((uint16_t)0x0040)  /*!< Pin 6 selected    */
 
#define GPIO_Pin_7                 ((uint16_t)0x0080)  /*!< Pin 7 selected    */
 
#define GPIO_Pin_8                 ((uint16_t)0x0100)  /*!< Pin 8 selected    */
 
#define GPIO_Pin_9                 ((uint16_t)0x0200)  /*!< Pin 9 selected    */
 
#define GPIO_Pin_10                ((uint16_t)0x0400)  /*!< Pin 10 selected   */
 
#define GPIO_Pin_11                ((uint16_t)0x0800)  /*!< Pin 11 selected   */
 
#define GPIO_Pin_12                ((uint16_t)0x1000)  /*!< Pin 12 selected   */
 
#define GPIO_Pin_13                ((uint16_t)0x2000)  /*!< Pin 13 selected   */
 
#define GPIO_Pin_14                ((uint16_t)0x4000)  /*!< Pin 14 selected   */
 
#define GPIO_Pin_15                ((uint16_t)0x8000)  /*!< Pin 15 selected   */
 
#define GPIO_Pin_All               ((uint16_t)0xFFFF)  /*!< All pins selected */
 
 
#define IS_GPIO_PIN(PIN) ((PIN) != (uint16_t)0x00)
 
 
#define IS_GET_GPIO_PIN(PIN) (((PIN) == GPIO_Pin_0) || \
 
                              ((PIN) == GPIO_Pin_1) || \
 
                              ((PIN) == GPIO_Pin_2) || \
 
                              ((PIN) == GPIO_Pin_3) || \
 
                              ((PIN) == GPIO_Pin_4) || \
 
                              ((PIN) == GPIO_Pin_5) || \
 
                              ((PIN) == GPIO_Pin_6) || \
 
                              ((PIN) == GPIO_Pin_7) || \
 
                              ((PIN) == GPIO_Pin_8) || \
 
                              ((PIN) == GPIO_Pin_9) || \
 
                              ((PIN) == GPIO_Pin_10) || \
 
                              ((PIN) == GPIO_Pin_11) || \
 
                              ((PIN) == GPIO_Pin_12) || \
 
                              ((PIN) == GPIO_Pin_13) || \
 
                              ((PIN) == GPIO_Pin_14) || \
 
                              ((PIN) == GPIO_Pin_15))
 
 
/**
 
  * @}
 
  */
 
 
/** @defgroup GPIO_Pin_sources 
 
  * @{
 
  */
 
#define GPIO_PinSource0            ((uint8_t)0x00)
 
#define GPIO_PinSource1            ((uint8_t)0x01)
 
#define GPIO_PinSource2            ((uint8_t)0x02)
 
#define GPIO_PinSource3            ((uint8_t)0x03)
 
#define GPIO_PinSource4            ((uint8_t)0x04)
 
#define GPIO_PinSource5            ((uint8_t)0x05)
 
#define GPIO_PinSource6            ((uint8_t)0x06)
 
#define GPIO_PinSource7            ((uint8_t)0x07)
 
#define GPIO_PinSource8            ((uint8_t)0x08)
 
#define GPIO_PinSource9            ((uint8_t)0x09)
 
#define GPIO_PinSource10           ((uint8_t)0x0A)
 
#define GPIO_PinSource11           ((uint8_t)0x0B)
 
#define GPIO_PinSource12           ((uint8_t)0x0C)
 
#define GPIO_PinSource13           ((uint8_t)0x0D)
 
#define GPIO_PinSource14           ((uint8_t)0x0E)
 
#define GPIO_PinSource15           ((uint8_t)0x0F)
 
 
#define IS_GPIO_PIN_SOURCE(PINSOURCE) (((PINSOURCE) == GPIO_PinSource0) || \
 
                                       ((PINSOURCE) == GPIO_PinSource1) || \
 
                                       ((PINSOURCE) == GPIO_PinSource2) || \
 
                                       ((PINSOURCE) == GPIO_PinSource3) || \
 
                                       ((PINSOURCE) == GPIO_PinSource4) || \
 
                                       ((PINSOURCE) == GPIO_PinSource5) || \
 
                                       ((PINSOURCE) == GPIO_PinSource6) || \
 
                                       ((PINSOURCE) == GPIO_PinSource7) || \
 
                                       ((PINSOURCE) == GPIO_PinSource8) || \
 
                                       ((PINSOURCE) == GPIO_PinSource9) || \
 
                                       ((PINSOURCE) == GPIO_PinSource10) || \
 
                                       ((PINSOURCE) == GPIO_PinSource11) || \
 
                                       ((PINSOURCE) == GPIO_PinSource12) || \
 
                                       ((PINSOURCE) == GPIO_PinSource13) || \
 
                                       ((PINSOURCE) == GPIO_PinSource14) || \
 
                                       ((PINSOURCE) == GPIO_PinSource15))
 
/**
 
  * @}
 
  */
 
 
/** @defgroup GPIO_Alternate_function_selection_define 
 
  * @{
 
  */
 
 
/** 
 
  * @brief  AF 0 selection
 
  */
 
#define GPIO_AF_0            ((uint8_t)0x00) /* WKUP, EVENTOUT, TIM15, SPI1, TIM17,
 
                                                MCO, SWDAT, SWCLK, TIM14, BOOT,
 
                                                USART1, CEC, IR_OUT, SPI2, TS, TIM3,
 
                                                USART4, CAN, TIM3, USART2, USART3, 
 
                                                CRS, TIM16, TIM1 */
 
/** 
 
  * @brief  AF 1 selection
 
  */
 
#define GPIO_AF_1            ((uint8_t)0x01) /* USART2, CEC, TIM3, USART1, IR,
 
                                                EVENTOUT, I2C1, I2C2, TIM15, SPI2,
 
                                                USART3, TS, SPI1 */
 
/** 
 
  * @brief  AF 2 selection
 
  */
 
#define GPIO_AF_2            ((uint8_t)0x02) /* TIM2, TIM1, EVENTOUT, TIM16, TIM17,
 
                                                USB */
 
/** 
 
  * @brief  AF 3 selection
 
  */
 
#define GPIO_AF_3            ((uint8_t)0x03) /* TS, I2C1, TIM15, EVENTOUT */
 
 
/** 
 
  * @brief  AF 4 selection
 
  */
 
#define GPIO_AF_4            ((uint8_t)0x04) /* TIM14, USART4, USART3, CRS, CAN,
 
                                                I2C1 */
 
 
/** 
 
  * @brief  AF 5 selection
 
  */
 
#define GPIO_AF_5            ((uint8_t)0x05) /* TIM16, TIM17, TIM15, SPI2, I2C2, 
 
                                                MCO, I2C1, USB */
 
 
/** 
 
  * @brief  AF 6 selection
 
  */
 
#define GPIO_AF_6            ((uint8_t)0x06) /* EVENTOUT */
 
/** 
 
  * @brief  AF 7 selection
 
  */
 
#define GPIO_AF_7            ((uint8_t)0x07) /* COMP1 OUT and COMP2 OUT */
 
 
#define IS_GPIO_AF(AF)   (((AF) == GPIO_AF_0) || ((AF) == GPIO_AF_1) || \
 
                          ((AF) == GPIO_AF_2) || ((AF) == GPIO_AF_3) || \
 
                          ((AF) == GPIO_AF_4) || ((AF) == GPIO_AF_5) || \
 
                          ((AF) == GPIO_AF_6) || ((AF) == GPIO_AF_7))
 
 
/**
 
  * @}
 
  */
 
 
/** @defgroup GPIO_Speed_Legacy 
 
  * @{
 
  */
 
 
#define GPIO_Speed_2MHz  GPIO_Speed_Level_1   /*!< I/O output speed: Low 2 MHz  */
 
#define GPIO_Speed_10MHz GPIO_Speed_Level_2   /*!< I/O output speed: Medium 10 MHz */
 
#define GPIO_Speed_50MHz GPIO_Speed_Level_3   /*!< I/O output speed: High 50 MHz */
 
  
 
/**
 
  * @}
 
  */
 
 
/**
 
  * @}
 
  */
 
 
/* Exported macro ------------------------------------------------------------*/
 
/* Exported functions ------------------------------------------------------- */
 
/* Function used to set the GPIO configuration to the default reset state *****/
 
void GPIO_DeInit(GPIO_TypeDef* GPIOx);
 
 
/* Initialization and Configuration functions *********************************/
 
void GPIO_Init(GPIO_TypeDef* GPIOx, GPIO_InitTypeDef* GPIO_InitStruct);
 
void GPIO_StructInit(GPIO_InitTypeDef* GPIO_InitStruct);
 
void GPIO_PinLockConfig(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin);
 
 
/* GPIO Read and Write functions **********************************************/
 
uint8_t GPIO_ReadInputDataBit(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin);
 
uint16_t GPIO_ReadInputData(GPIO_TypeDef* GPIOx);
 
uint8_t GPIO_ReadOutputDataBit(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin);
 
uint16_t GPIO_ReadOutputData(GPIO_TypeDef* GPIOx);
 
void GPIO_SetBits(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin);
 
void GPIO_ResetBits(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin);
 
void GPIO_WriteBit(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin, BitAction BitVal);
 
void GPIO_Write(GPIO_TypeDef* GPIOx, uint16_t PortVal);
 
 
/* GPIO Alternate functions configuration functions ***************************/
 
void GPIO_PinAFConfig(GPIO_TypeDef* GPIOx, uint16_t GPIO_PinSource, uint8_t GPIO_AF);
 
 
void GPIO_ToggleBits(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin);
 
 
#ifdef __cplusplus
 
}
 
#endif
 
 
#endif /* __STM32F0XX_GPIO_H */
 
/**
 
  * @}
 
  */
 
 
/**
 
  * @}
 
  */
 
 
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
libraries/STM32F0xx_StdPeriph_Driver/src/stm32f0xx_gpio.c
Show inline comments
 
/**
 
  ******************************************************************************
 
  * @file    stm32f0xx_gpio.c
 
  * @author  MCD Application Team
 
  * @version V1.4.0
 
  * @date    24-July-2014
 
  * @brief   This file provides firmware functions to manage the following 
 
  *          functionalities of the GPIO peripheral:
 
  *           + Initialization and Configuration functions
 
  *           + GPIO Read and Write functions
 
  *           + GPIO Alternate functions configuration functions
 
  *
 
  *  @verbatim
 
  *
 
  *
 
    ===========================================================================
 
                         ##### How to use this driver #####
 
    ===========================================================================
 
      [..]
 
      (#) Enable the GPIO AHB clock using RCC_AHBPeriphClockCmd()
 
      (#) Configure the GPIO pin(s) using GPIO_Init()
 
          Four possible configuration are available for each pin:
 
         (++) Input: Floating, Pull-up, Pull-down.
 
         (++) Output: Push-Pull (Pull-up, Pull-down or no Pull)
 
                      Open Drain (Pull-up, Pull-down or no Pull).
 
              In output mode, the speed is configurable: Low, Medium, Fast or High.
 
         (++) Alternate Function: Push-Pull (Pull-up, Pull-down or no Pull)
 
                                  Open Drain (Pull-up, Pull-down or no Pull).
 
         (++) Analog: required mode when a pin is to be used as ADC channel,
 
              DAC output or comparator input.
 
      (#) Peripherals alternate function:
 
         (++) For ADC, DAC and comparators, configure the desired pin in analog 
 
              mode using GPIO_InitStruct->GPIO_Mode = GPIO_Mode_AN
 
         (++) For other peripherals (TIM, USART...):
 
              (+++) Connect the pin to the desired peripherals' Alternate 
 
                    Function (AF) using GPIO_PinAFConfig() function. For PortC, 
 
                    PortD and PortF, no configuration is needed.
 
              (+++) Configure the desired pin in alternate function mode using
 
                    GPIO_InitStruct->GPIO_Mode = GPIO_Mode_AF
 
              (+++) Select the type, pull-up/pull-down and output speed via 
 
                    GPIO_PuPd, GPIO_OType and GPIO_Speed members
 
              (+++) Call GPIO_Init() function
 
      (#) To get the level of a pin configured in input mode use GPIO_ReadInputDataBit()
 
      (#) To set/reset the level of a pin configured in output mode use
 
          GPIO_SetBits()/GPIO_ResetBits()
 
      (#) During and just after reset, the alternate functions are not active and 
 
          the GPIO pins are configured in input floating mode (except JTAG pins).
 
      (#) The LSE oscillator pins OSC32_IN and OSC32_OUT can be used as 
 
          general-purpose (PC14 and PC15, respectively) when the LSE oscillator 
 
          is off. The LSE has priority over the GPIO function.
 
      (#) The HSE oscillator pins OSC_IN/OSC_OUT can be used as general-purpose 
 
          PD0 and PD1, respectively, when the HSE oscillator is off. The HSE has 
 
          priority over the GPIO function.
 
    @endverbatim
 
  ******************************************************************************
 
  * @attention
 
  *
 
  * <h2><center>&copy; COPYRIGHT 2014 STMicroelectronics</center></h2>
 
  *
 
  * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
 
  * You may not use this file except in compliance with the License.
 
  * You may obtain a copy of the License at:
 
  *
 
  *        http://www.st.com/software_license_agreement_liberty_v2
 
  *
 
  * Unless required by applicable law or agreed to in writing, software 
 
  * distributed under the License is distributed on an "AS IS" BASIS, 
 
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 
  * See the License for the specific language governing permissions and
 
  * limitations under the License.
 
  *
 
  ******************************************************************************
 
  */
 
 
/* Includes ------------------------------------------------------------------*/
 
#include "stm32f0xx_gpio.h"
 
#include "stm32f0xx_rcc.h"
 
 
/** @addtogroup STM32F0xx_StdPeriph_Driver
 
  * @{
 
  */
 
 
/** @defgroup GPIO 
 
  * @brief GPIO driver modules
 
  * @{
 
  */
 
 
/* Private typedef -----------------------------------------------------------*/
 
/* Private define ------------------------------------------------------------*/
 
/* Private macro -------------------------------------------------------------*/
 
/* Private variables ---------------------------------------------------------*/
 
/* Private function prototypes -----------------------------------------------*/
 
/* Private functions ---------------------------------------------------------*/
 
 
/** @defgroup GPIO_Private_Functions 
 
  * @{
 
  */
 
 
/** @defgroup GPIO_Group1 Initialization and Configuration
 
 *  @brief   Initialization and Configuration
 
 *
 
@verbatim
 
 ===============================================================================
 
                    ##### Initialization and Configuration #####
 
 ===============================================================================
 
 
@endverbatim
 
  * @{
 
  */
 
 
/**
 
  * @brief  Deinitializes the GPIOx peripheral registers to their default reset 
 
  *         values.
 
  * @param  GPIOx: where x can be (A, B, C, D, E or F) to select the GPIO peripheral.
 
  * @note   GPIOE is available only for STM32F072.
 
  * @note   GPIOD is not available for STM32F031.    
 
  * @retval None
 
  */
 
void GPIO_DeInit(GPIO_TypeDef* GPIOx)
 
{
 
  /* Check the parameters */
 
  assert_param(IS_GPIO_ALL_PERIPH(GPIOx));
 
 
  if(GPIOx == GPIOA)
 
  {
 
    RCC_AHBPeriphResetCmd(RCC_AHBPeriph_GPIOA, ENABLE);
 
    RCC_AHBPeriphResetCmd(RCC_AHBPeriph_GPIOA, DISABLE);
 
  }
 
  else if(GPIOx == GPIOB)
 
  {
 
    RCC_AHBPeriphResetCmd(RCC_AHBPeriph_GPIOB, ENABLE);
 
    RCC_AHBPeriphResetCmd(RCC_AHBPeriph_GPIOB, DISABLE);
 
  }
 
  else if(GPIOx == GPIOC)
 
  {
 
    RCC_AHBPeriphResetCmd(RCC_AHBPeriph_GPIOC, ENABLE);
 
    RCC_AHBPeriphResetCmd(RCC_AHBPeriph_GPIOC, DISABLE);
 
  }
 
  else if(GPIOx == GPIOD)
 
  {
 
    RCC_AHBPeriphResetCmd(RCC_AHBPeriph_GPIOD, ENABLE);
 
    RCC_AHBPeriphResetCmd(RCC_AHBPeriph_GPIOD, DISABLE);
 
  }
 
  else if(GPIOx == GPIOE)
 
  {
 
    RCC_AHBPeriphResetCmd(RCC_AHBPeriph_GPIOE, ENABLE);
 
    RCC_AHBPeriphResetCmd(RCC_AHBPeriph_GPIOE, DISABLE);
 
  }
 
  else
 
  {
 
    if(GPIOx == GPIOF)
 
    {
 
      RCC_AHBPeriphResetCmd(RCC_AHBPeriph_GPIOF, ENABLE);
 
      RCC_AHBPeriphResetCmd(RCC_AHBPeriph_GPIOF, DISABLE);
 
    }
 
  }
 
}
 
 
/**
 
  * @brief  Initializes the GPIOx peripheral according to the specified 
 
  *         parameters in the GPIO_InitStruct.
 
  * @param  GPIOx: where x can be (A, B, C, D, E or F) to select the GPIO peripheral.
 
  * @note   GPIOE is available only for STM32F072.
 
  * @note   GPIOD is not available for STM32F031.   
 
  * @param  GPIO_InitStruct: pointer to a GPIO_InitTypeDef structure that contains
 
  *         the configuration information for the specified GPIO peripheral.
 
  * @retval None
 
  */
 
void GPIO_Init(GPIO_TypeDef* GPIOx, GPIO_InitTypeDef* GPIO_InitStruct)
 
{
 
  uint32_t pinpos = 0x00, pos = 0x00 , currentpin = 0x00;
 
 
  /* Check the parameters */
 
  assert_param(IS_GPIO_ALL_PERIPH(GPIOx));
 
  assert_param(IS_GPIO_PIN(GPIO_InitStruct->GPIO_Pin));
 
  assert_param(IS_GPIO_MODE(GPIO_InitStruct->GPIO_Mode));
 
  assert_param(IS_GPIO_PUPD(GPIO_InitStruct->GPIO_PuPd));
 
 
  /*-------------------------- Configure the port pins -----------------------*/
 
  /*-- GPIO Mode Configuration --*/
 
  for (pinpos = 0x00; pinpos < 0x10; pinpos++)
 
  {
 
    pos = ((uint32_t)0x01) << pinpos;
 
 
    /* Get the port pins position */
 
    currentpin = (GPIO_InitStruct->GPIO_Pin) & pos;
 
 
    if (currentpin == pos)
 
    {
 
      if ((GPIO_InitStruct->GPIO_Mode == GPIO_Mode_OUT) || (GPIO_InitStruct->GPIO_Mode == GPIO_Mode_AF))
 
      {
 
        /* Check Speed mode parameters */
 
        assert_param(IS_GPIO_SPEED(GPIO_InitStruct->GPIO_Speed));
 
 
        /* Speed mode configuration */
 
        GPIOx->OSPEEDR &= ~(GPIO_OSPEEDER_OSPEEDR0 << (pinpos * 2));
 
        GPIOx->OSPEEDR |= ((uint32_t)(GPIO_InitStruct->GPIO_Speed) << (pinpos * 2));
 
 
        /* Check Output mode parameters */
 
        assert_param(IS_GPIO_OTYPE(GPIO_InitStruct->GPIO_OType));
 
 
        /* Output mode configuration */
 
        GPIOx->OTYPER &= ~((GPIO_OTYPER_OT_0) << ((uint16_t)pinpos));
 
        GPIOx->OTYPER |= (uint16_t)(((uint16_t)GPIO_InitStruct->GPIO_OType) << ((uint16_t)pinpos));
 
      }
 
 
      GPIOx->MODER  &= ~(GPIO_MODER_MODER0 << (pinpos * 2));
 
 
      GPIOx->MODER |= (((uint32_t)GPIO_InitStruct->GPIO_Mode) << (pinpos * 2));
 
 
      /* Pull-up Pull down resistor configuration */
 
      GPIOx->PUPDR &= ~(GPIO_PUPDR_PUPDR0 << ((uint16_t)pinpos * 2));
 
      GPIOx->PUPDR |= (((uint32_t)GPIO_InitStruct->GPIO_PuPd) << (pinpos * 2));
 
    }
 
  }
 
}
 
 
/**
 
  * @brief  Fills each GPIO_InitStruct member with its default value.
 
  * @param  GPIO_InitStruct: pointer to a GPIO_InitTypeDef structure which will 
 
  *         be initialized.
 
  * @retval None
 
  */
 
void GPIO_StructInit(GPIO_InitTypeDef* GPIO_InitStruct)
 
{
 
  /* Reset GPIO init structure parameters values */
 
  GPIO_InitStruct->GPIO_Pin  = GPIO_Pin_All;
 
  GPIO_InitStruct->GPIO_Mode = GPIO_Mode_IN;
 
  GPIO_InitStruct->GPIO_Speed = GPIO_Speed_Level_2;
 
  GPIO_InitStruct->GPIO_OType = GPIO_OType_PP;
 
  GPIO_InitStruct->GPIO_PuPd = GPIO_PuPd_NOPULL;
 
}
 
 
/**
 
  * @brief  Locks GPIO Pins configuration registers.
 
  * @note   The locked registers are GPIOx_MODER, GPIOx_OTYPER, GPIOx_OSPEEDR,
 
  *         GPIOx_PUPDR, GPIOx_AFRL and GPIOx_AFRH.
 
  * @note   The configuration of the locked GPIO pins can no longer be modified
 
  *         until the next device reset.
 
  * @param  GPIOx: where x can be (A or B) to select the GPIO peripheral.
 
  * @param  GPIO_Pin: specifies the port bit to be written.
 
  *          This parameter can be any combination of GPIO_Pin_x where x can be (0..15).
 
  * @retval None
 
  */
 
void GPIO_PinLockConfig(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin)
 
{
 
  __IO uint32_t tmp = 0x00010000;
 
 
  /* Check the parameters */
 
  assert_param(IS_GPIO_LIST_PERIPH(GPIOx));
 
  assert_param(IS_GPIO_PIN(GPIO_Pin));
 
 
  tmp |= GPIO_Pin;
 
  /* Set LCKK bit */
 
  GPIOx->LCKR = tmp;
 
  /* Reset LCKK bit */
 
  GPIOx->LCKR =  GPIO_Pin;
 
  /* Set LCKK bit */
 
  GPIOx->LCKR = tmp;
 
  /* Read LCKK bit */
 
  tmp = GPIOx->LCKR;
 
  /* Read LCKK bit */
 
  tmp = GPIOx->LCKR;
 
}
 
 
/**
 
  * @}
 
  */
 
 
/** @defgroup GPIO_Group2 GPIO Read and Write
 
 *  @brief   GPIO Read and Write
 
 *
 
@verbatim   
 
 ===============================================================================
 
                      ##### GPIO Read and Write #####
 
 ===============================================================================  
 
 
@endverbatim
 
  * @{
 
  */
 
 
/**
 
  * @brief  Reads the specified input port pin.
 
  * @param  GPIOx: where x can be (A, B, C, D, E or F) to select the GPIO peripheral.
 
  * @note   GPIOE is available only for STM32F072.
 
  * @note   GPIOD is not available for STM32F031.   
 
  * @param  GPIO_Pin: specifies the port bit to read.
 
  * @note   This parameter can be GPIO_Pin_x where x can be:
 
  *         For STM32F051 and STM32F030: (0..15) for GPIOA, GPIOB, GPIOC, (2) for GPIOD and (0..1, 4..7) for GIIOF.
 
  *         For STM32F072: (0..15) for GPIOA, GPIOB, GPIOC, GPIOD, GPIOE, (0..10) for GPIOF.
 
  *         For STM32F031: (0..15) for GPIOA, GPIOB, (13..15) for GPIOC and (0..1, 6..7) for GPIOF.  
 
  * @retval The input port pin value.
 
  */
 
uint8_t GPIO_ReadInputDataBit(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin)
 
{
 
  uint8_t bitstatus = 0x00;
 
 
  /* Check the parameters */
 
  assert_param(IS_GPIO_ALL_PERIPH(GPIOx));
 
  assert_param(IS_GET_GPIO_PIN(GPIO_Pin));
 
 
  if ((GPIOx->IDR & GPIO_Pin) != (uint32_t)Bit_RESET)
 
  {
 
    bitstatus = (uint8_t)Bit_SET;
 
  }
 
  else
 
  {
 
    bitstatus = (uint8_t)Bit_RESET;
 
  }
 
  return bitstatus;
 
}
 
 
/**
 
  * @brief  Reads the specified input port pin.
 
  * @param  GPIOx: where x can be (A, B, C, D, E or F) to select the GPIO peripheral.
 
  * @note   GPIOE is available only for STM32F072.
 
  * @note   GPIOD is not available for STM32F031.   
 
  * @retval The input port pin value.
 
  */
 
uint16_t GPIO_ReadInputData(GPIO_TypeDef* GPIOx)
 
{
 
  /* Check the parameters */
 
  assert_param(IS_GPIO_ALL_PERIPH(GPIOx));
 
 
  return ((uint16_t)GPIOx->IDR);
 
}
 
 
/**
 
  * @brief  Reads the specified output data port bit.
 
  * @param  GPIOx: where x can be (A, B, C, D, E or F) to select the GPIO peripheral.
 
  * @note   GPIOE is available only for STM32F072.
 
  * @note   GPIOD is not available for STM32F031.   
 
  * @param  GPIO_Pin: Specifies the port bit to read.
 
  * @note   This parameter can be GPIO_Pin_x where x can be:
 
  *         For STM32F051 and STM32F030: (0..15) for GPIOA, GPIOB, GPIOC, (2) for GPIOD and (0..1, 4..7) for GIIOF.
 
  *         For STM32F072: (0..15) for GPIOA, GPIOB, GPIOC, GPIOD, GPIOE, (0..10) for GPIOF.
 
  *         For STM32F031: (0..15) for GPIOA, GPIOB, (13..15) for GPIOC and (0..1, 6..7) for GPIOF. 
 
  * @retval The output port pin value.
 
  */
 
uint8_t GPIO_ReadOutputDataBit(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin)
 
{
 
  uint8_t bitstatus = 0x00;
 
 
  /* Check the parameters */
 
  assert_param(IS_GPIO_ALL_PERIPH(GPIOx));
 
  assert_param(IS_GET_GPIO_PIN(GPIO_Pin));
 
 
  if ((GPIOx->ODR & GPIO_Pin) != (uint32_t)Bit_RESET)
 
  {
 
    bitstatus = (uint8_t)Bit_SET;
 
  }
 
  else
 
  {
 
    bitstatus = (uint8_t)Bit_RESET;
 
  }
 
  return bitstatus;
 
}
 
 
/**
 
  * @brief  Reads the specified GPIO output data port.
 
  * @param  GPIOx: where x can be (A, B, C, D, E or F) to select the GPIO peripheral.
 
  * @note   GPIOE is available only for STM32F072.
 
  * @note   GPIOD is not available for STM32F031.    
 
  * @retval GPIO output data port value.
 
  */
 
uint16_t GPIO_ReadOutputData(GPIO_TypeDef* GPIOx)
 
{
 
  /* Check the parameters */
 
  assert_param(IS_GPIO_ALL_PERIPH(GPIOx));
 
 
  return ((uint16_t)GPIOx->ODR);
 
}
 
 
/**
 
  * @brief  Sets the selected data port bits.
 
  * @param  GPIOx: where x can be (A, B, C, D, E or F) to select the GPIO peripheral.
 
  * @note   GPIOE is available only for STM32F072.
 
  * @note   GPIOD is not available for STM32F031.    
 
  * @param  GPIO_Pin: specifies the port bits to be written.
 
  * @note   This parameter can be GPIO_Pin_x where x can be:
 
  *         For STM32F051 and STM32F030: (0..15) for GPIOA, GPIOB, GPIOC, (2) for GPIOD and (0..1, 4..7) for GIIOF.
 
  *         For STM32F072: (0..15) for GPIOA, GPIOB, GPIOC, GPIOD, GPIOE, (0..10) for GPIOF.
 
  *         For STM32F031: (0..15) for GPIOA, GPIOB, (13..15) for GPIOC and (0..1, 6..7) for GPIOF. 
 
  * @retval None
 
  */
 
void GPIO_SetBits(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin)
 
{
 
  /* Check the parameters */
 
  assert_param(IS_GPIO_ALL_PERIPH(GPIOx));
 
  assert_param(IS_GPIO_PIN(GPIO_Pin));
 
 
  GPIOx->BSRR = GPIO_Pin;
 
}
 
 
/**
 
  * @brief  Clears the selected data port bits.
 
  * @param  GPIOx: where x can be (A, B, C, D, E or F) to select the GPIO peripheral.
 
  * @note   GPIOE is available only for STM32F072.
 
  * @note   GPIOD is not available for STM32F031.
 
  * @param  GPIO_Pin: specifies the port bits to be written.
 
  * @note   This parameter can be GPIO_Pin_x where x can be:
 
  *         For STM32F051 and STM32F030: (0..15) for GPIOA, GPIOB, GPIOC, (2) for GPIOD and (0..1, 4..7) for GIIOF.
 
  *         For STM32F072: (0..15) for GPIOA, GPIOB, GPIOC, GPIOD, GPIOE, (0..10) for GPIOF.
 
  *         For STM32F031: (0..15) for GPIOA, GPIOB, (13..15) for GPIOC and (0..1, 6..7) for GPIOF. 
 
  * @retval None
 
  */
 
void GPIO_ResetBits(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin)
 
{
 
  /* Check the parameters */
 
  assert_param(IS_GPIO_ALL_PERIPH(GPIOx));
 
  assert_param(IS_GPIO_PIN(GPIO_Pin));
 
 
  GPIOx->BRR = GPIO_Pin;
 
}
 
 
/**
 
  * @brief  Sets or clears the selected data port bit.
 
  * @param  GPIOx: where x can be (A, B, C, D, E or F) to select the GPIO peripheral.
 
  * @note   GPIOE is available only for STM32F072.
 
  * @note   GPIOD is not available for STM32F031.  
 
  * @param  GPIO_Pin: specifies the port bit to be written.
 
  * @param  BitVal: specifies the value to be written to the selected bit.
 
  *          This parameter can be one of the BitAction enumeration values:
 
  *            @arg Bit_RESET: to clear the port pin
 
  *            @arg Bit_SET: to set the port pin
 
  * @note   This parameter can be GPIO_Pin_x where x can be:
 
  *         For STM32F051 and STM32F030: (0..15) for GPIOA, GPIOB, GPIOC, (2) for GPIOD and (0..1, 4..7) for GIIOF.
 
  *         For STM32F072: (0..15) for GPIOA, GPIOB, GPIOC, GPIOD, GPIOE, (0..10) for GPIOF.
 
  *         For STM32F031: (0..15) for GPIOA, GPIOB, (13..15) for GPIOC and (0..1, 6..7) for GPIOF.
 
  * @retval None
 
  */
 
void GPIO_WriteBit(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin, BitAction BitVal)
 
{
 
  /* Check the parameters */
 
  assert_param(IS_GPIO_ALL_PERIPH(GPIOx));
 
  assert_param(IS_GET_GPIO_PIN(GPIO_Pin));
 
  assert_param(IS_GPIO_BIT_ACTION(BitVal));
 
 
  if (BitVal != Bit_RESET)
 
  {
 
    GPIOx->BSRR = GPIO_Pin;
 
  }
 
  else
 
  {
 
    GPIOx->BRR = GPIO_Pin ;
 
  }
 
}
 
 
/**
 
  * @brief  Writes data to the specified GPIO data port.
 
  * @param  GPIOx: where x can be (A, B, C, D, E or F) to select the GPIO peripheral.
 
  * @note   GPIOE is available only for STM32F072.
 
  * @note   GPIOD is not available for STM32F031.  
 
  * @param  PortVal: specifies the value to be written to the port output data register.
 
  * @retval None
 
  */
 
void GPIO_Write(GPIO_TypeDef* GPIOx, uint16_t PortVal)
 
{
 
  /* Check the parameters */
 
  assert_param(IS_GPIO_ALL_PERIPH(GPIOx));
 
 
  GPIOx->ODR = PortVal;
 
}
 
 
/**
 
  * @}
 
  */
 
 
/** @defgroup GPIO_Group3 GPIO Alternate functions configuration functions
 
 *  @brief   GPIO Alternate functions configuration functions
 
 *
 
@verbatim   
 
 ===============================================================================
 
          ##### GPIO Alternate functions configuration functions #####
 
 ===============================================================================  
 
 
@endverbatim
 
  * @{
 
  */
 
 
/**
 
  * @brief  Writes data to the specified GPIO data port.
 
  * @param  GPIOx: where x can be (A, B, C, D, E or F) to select the GPIO peripheral.
 
  * @note   GPIOC, GPIOD, GPIOE and GPIOF  are available only for STM32F072 and STM32F091. 
 
  * @param  GPIO_PinSource: specifies the pin for the Alternate function.
 
  *          This parameter can be GPIO_PinSourcex where x can be (0..15) for GPIOA, GPIOB, GPIOD, GPIOE
 
  *          and (0..12) for GPIOC and (0, 2..5, 9..10) for GPIOF.    
 
  * @param  GPIO_AF: selects the pin to used as Alternate function.
 
  *          This parameter can be one of the following value:
 
  *            @arg GPIO_AF_0:  WKUP, EVENTOUT, TIM15, SPI1, TIM17, MCO, SWDAT, SWCLK,
 
  *                             TIM14, BOOT, USART1, CEC, IR_OUT, SPI2, TIM3, USART4,
 
  *                             CAN, USART2, CRS, TIM16, TIM1, TS, USART8 
 
  *            @arg GPIO_AF_1: USART2, CEC, TIM3, USART1, USART2, EVENTOUT, I2C1,
 
  *                            I2C2, TIM15, SPI2, USART3, TS, SPI1, USART7, USART8
 
  *                            USART5, USART4, USART6, I2C1   
 
  *            @arg GPIO_AF_2: TIM2, TIM1, EVENTOUT, TIM16, TIM17, USB, USART6, USART5,
 
  *                            USART8, USART7, USART6  
 
  *            @arg GPIO_AF_3: TS, I2C1, TIM15, EVENTOUT 
 
  *            @arg GPIO_AF_4: TIM14, USART4, USART3, CRS, CAN, I2C1, USART5
 
  *            @arg GPIO_AF_5: TIM16, TIM17, TIM15, SPI2, I2C2, USART6, MCO
 
  *            @arg GPIO_AF_6: EVENTOUT
 
  *            @arg GPIO_AF_7: COMP1 OUT, COMP2 OUT 
 
  * @note   The pin should already been configured in Alternate Function mode(AF)
 
  *         using GPIO_InitStruct->GPIO_Mode = GPIO_Mode_AF
 
  * @note   Refer to the Alternate function mapping table in the device datasheet 
 
  *         for the detailed mapping of the system and peripherals'alternate 
 
  *         function I/O pins.
 
  * @retval None
 
  */
 
void GPIO_PinAFConfig(GPIO_TypeDef* GPIOx, uint16_t GPIO_PinSource, uint8_t GPIO_AF)
 
{
 
  uint32_t temp = 0x00;
 
  uint32_t temp_2 = 0x00;
 
 
  /* Check the parameters */
 
  assert_param(IS_GPIO_ALL_PERIPH(GPIOx));
 
  assert_param(IS_GPIO_PIN_SOURCE(GPIO_PinSource));
 
  assert_param(IS_GPIO_AF(GPIO_AF));
 
 
  temp = ((uint32_t)(GPIO_AF) << ((uint32_t)((uint32_t)GPIO_PinSource & (uint32_t)0x07) * 4));
 
  GPIOx->AFR[GPIO_PinSource >> 0x03] &= ~((uint32_t)0xF << ((uint32_t)((uint32_t)GPIO_PinSource & (uint32_t)0x07) * 4));
 
  temp_2 = GPIOx->AFR[GPIO_PinSource >> 0x03] | temp;
 
  GPIOx->AFR[GPIO_PinSource >> 0x03] = temp_2;
 
}
 
 
 
/**
 
  * @brief  Toggles the specified GPIO pins. NOTE: Imported by EMZ
 
  * @param  GPIOx: where x can be (A..H) to select the GPIO peripheral.
 
  * @param  GPIO_Pin: Specifies the pins to be toggled.
 
  * @retval None
 
  */
 
void GPIO_ToggleBits(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin)
 
{
 
  /* Check the parameters */
 
  assert_param(IS_GPIO_ALL_PERIPH(GPIOx));
 
 
  GPIOx->ODR ^= GPIO_Pin;
 
}
 
 
 
/**
 
  * @}
 
  */
 
 
/**
 
  * @}
 
  */
 
 
/**
 
  * @}
 
  */
 
 
/**
 
  * @}
 
  */
 
 
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
0 comments (0 inline, 0 general)