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
 
@@ -249,110 +249,112 @@ typedef struct
 
  * @{
 
  */
 
 
/** 
 
  * @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
 
@@ -430,113 +430,129 @@ void GPIO_ResetBits(GPIO_TypeDef* GPIOx,
 
  * @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)