Subversion Repositories AFRtranscoder

Rev

Blame | Last modification | View Log | Download | RSS feed

  1. /**
  2.   ******************************************************************************
  3.   * @file    stm32f1xx_ll_gpio.c
  4.   * @author  MCD Application Team
  5.   * @brief   GPIO LL module driver.
  6.   ******************************************************************************
  7.   * @attention
  8.   *
  9.   * Copyright (c) 2016 STMicroelectronics.
  10.   * All rights reserved.
  11.   *
  12.   * This software is licensed under terms that can be found in the LICENSE file
  13.   * in the root directory of this software component.
  14.   * If no LICENSE file comes with this software, it is provided AS-IS.
  15.   *
  16.   ******************************************************************************
  17.   */
  18.  
  19. #if defined(USE_FULL_LL_DRIVER)
  20.  
  21. /* Includes ------------------------------------------------------------------*/
  22. #include "stm32f1xx_ll_gpio.h"
  23. #include "stm32f1xx_ll_bus.h"
  24. #ifdef  USE_FULL_ASSERT
  25. #include "stm32_assert.h"
  26. #else
  27. #define assert_param(expr) ((void)0U)
  28. #endif
  29.  
  30. /** @addtogroup STM32F1xx_LL_Driver
  31.   * @{
  32.   */
  33.  
  34. #if defined (GPIOA) || defined (GPIOB) || defined (GPIOC) || defined (GPIOD) || defined (GPIOE) || defined (GPIOF) || defined (GPIOG)
  35.  
  36. /** @addtogroup GPIO_LL
  37.   * @{
  38.   */
  39.  
  40. /* Private types -------------------------------------------------------------*/
  41. /* Private variables ---------------------------------------------------------*/
  42. /* Private constants ---------------------------------------------------------*/
  43. /* Private macros ------------------------------------------------------------*/
  44. /** @addtogroup GPIO_LL_Private_Macros
  45.   * @{
  46.   */
  47.  
  48. #define IS_LL_GPIO_PIN(__VALUE__)          ((((__VALUE__) & LL_GPIO_PIN_ALL)!= 0u) &&\
  49.                                             (((__VALUE__) & (~LL_GPIO_PIN_ALL))== 0u))
  50.  
  51. #define IS_LL_GPIO_MODE(__VALUE__)         (((__VALUE__) == LL_GPIO_MODE_ANALOG)       ||\
  52.                                             ((__VALUE__) == LL_GPIO_MODE_FLOATING)     ||\
  53.                                             ((__VALUE__) == LL_GPIO_MODE_INPUT)        ||\
  54.                                             ((__VALUE__) == LL_GPIO_MODE_OUTPUT)       ||\
  55.                                             ((__VALUE__) == LL_GPIO_MODE_ALTERNATE))
  56.  
  57. #define IS_LL_GPIO_SPEED(__VALUE__)        (((__VALUE__) == LL_GPIO_SPEED_FREQ_LOW)       ||\
  58.                                             ((__VALUE__) == LL_GPIO_SPEED_FREQ_MEDIUM)    ||\
  59.                                             ((__VALUE__) == LL_GPIO_SPEED_FREQ_HIGH))
  60.  
  61. #define IS_LL_GPIO_OUTPUT_TYPE(__VALUE__)  (((__VALUE__) == LL_GPIO_OUTPUT_PUSHPULL)  ||\
  62.                                             ((__VALUE__) == LL_GPIO_OUTPUT_OPENDRAIN))
  63.  
  64. #define IS_LL_GPIO_PULL(__VALUE__)         (((__VALUE__) == LL_GPIO_PULL_DOWN)   ||\
  65.                                             ((__VALUE__) == LL_GPIO_PULL_UP))
  66.  
  67. /**
  68.   * @}
  69.   */
  70.  
  71. /* Private function prototypes -----------------------------------------------*/
  72.  
  73. /* Exported functions --------------------------------------------------------*/
  74. /** @addtogroup GPIO_LL_Exported_Functions
  75.   * @{
  76.   */
  77.  
  78. /** @addtogroup GPIO_LL_EF_Init
  79.   * @{
  80.   */
  81.  
  82. /**
  83.   * @brief  De-initialize GPIO registers (Registers restored to their default values).
  84.   * @param  GPIOx GPIO Port
  85.   * @retval An ErrorStatus enumeration value:
  86.   *          - SUCCESS: GPIO registers are de-initialized
  87.   *          - ERROR:   Wrong GPIO Port
  88.   */
  89. ErrorStatus LL_GPIO_DeInit(GPIO_TypeDef *GPIOx)
  90. {
  91.   ErrorStatus status = SUCCESS;
  92.  
  93.   /* Check the parameters */
  94.   assert_param(IS_GPIO_ALL_INSTANCE(GPIOx));
  95.  
  96.   /* Force and Release reset on clock of GPIOx Port */
  97.   if (GPIOx == GPIOA)
  98.   {
  99.     LL_APB2_GRP1_ForceReset(LL_APB2_GRP1_PERIPH_GPIOA);
  100.     LL_APB2_GRP1_ReleaseReset(LL_APB2_GRP1_PERIPH_GPIOA);
  101.   }
  102.   else if (GPIOx == GPIOB)
  103.   {
  104.     LL_APB2_GRP1_ForceReset(LL_APB2_GRP1_PERIPH_GPIOB);
  105.     LL_APB2_GRP1_ReleaseReset(LL_APB2_GRP1_PERIPH_GPIOB);
  106.   }
  107.   else if (GPIOx == GPIOC)
  108.   {
  109.     LL_APB2_GRP1_ForceReset(LL_APB2_GRP1_PERIPH_GPIOC);
  110.     LL_APB2_GRP1_ReleaseReset(LL_APB2_GRP1_PERIPH_GPIOC);
  111.   }
  112.   else if (GPIOx == GPIOD)
  113.   {
  114.     LL_APB2_GRP1_ForceReset(LL_APB2_GRP1_PERIPH_GPIOD);
  115.     LL_APB2_GRP1_ReleaseReset(LL_APB2_GRP1_PERIPH_GPIOD);
  116.   }
  117. #if defined(GPIOE)
  118.   else if (GPIOx == GPIOE)
  119.   {
  120.     LL_APB2_GRP1_ForceReset(LL_APB2_GRP1_PERIPH_GPIOE);
  121.     LL_APB2_GRP1_ReleaseReset(LL_APB2_GRP1_PERIPH_GPIOE);
  122.   }
  123. #endif
  124. #if defined(GPIOF)
  125.   else if (GPIOx == GPIOF)
  126.   {
  127.     LL_APB2_GRP1_ForceReset(LL_APB2_GRP1_PERIPH_GPIOF);
  128.     LL_APB2_GRP1_ReleaseReset(LL_APB2_GRP1_PERIPH_GPIOF);
  129.   }
  130. #endif
  131. #if defined(GPIOG)
  132.   else if (GPIOx == GPIOG)
  133.   {
  134.     LL_APB2_GRP1_ForceReset(LL_APB2_GRP1_PERIPH_GPIOG);
  135.     LL_APB2_GRP1_ReleaseReset(LL_APB2_GRP1_PERIPH_GPIOG);
  136.   }
  137. #endif
  138.   else
  139.   {
  140.     status = ERROR;
  141.   }
  142.  
  143.   return (status);
  144. }
  145.  
  146. /**
  147.   * @brief  Initialize GPIO registers according to the specified parameters in GPIO_InitStruct.
  148.   * @param  GPIOx GPIO Port
  149.   * @param  GPIO_InitStruct: pointer to a @ref LL_GPIO_InitTypeDef structure
  150.   *         that contains the configuration information for the specified GPIO peripheral.
  151.   * @retval An ErrorStatus enumeration value:
  152.   *          - SUCCESS: GPIO registers are initialized according to GPIO_InitStruct content
  153.   *          - ERROR:   Not applicable
  154.   */
  155. ErrorStatus LL_GPIO_Init(GPIO_TypeDef *GPIOx, LL_GPIO_InitTypeDef *GPIO_InitStruct)
  156. {
  157.   uint32_t pinmask;
  158.   uint32_t pinpos;
  159.   uint32_t currentpin;
  160.  
  161.   /* Check the parameters */
  162.   assert_param(IS_GPIO_ALL_INSTANCE(GPIOx));
  163.   assert_param(IS_LL_GPIO_PIN(GPIO_InitStruct->Pin));
  164.  
  165.   /* ------------------------- Configure the port pins ---------------- */
  166.   /* Initialize  pinpos on first pin set */
  167.  
  168.   pinmask = ((GPIO_InitStruct->Pin) << GPIO_PIN_MASK_POS) >> GPIO_PIN_NB;
  169.   pinpos = POSITION_VAL(pinmask);
  170.  
  171.   /* Configure the port pins */
  172.   while ((pinmask  >> pinpos) != 0u)
  173.   {
  174.     /* skip if bit is not set */
  175.     if ((pinmask & (1u << pinpos)) != 0u)
  176.     {
  177.       /* Get current io position */
  178.       if (pinpos < GPIO_PIN_MASK_POS)
  179.       {
  180.         currentpin = (0x00000101uL << pinpos);
  181.       }
  182.       else
  183.       {
  184.         currentpin = ((0x00010001u << (pinpos - GPIO_PIN_MASK_POS)) | 0x04000000u);
  185.       }
  186.  
  187.       if (GPIO_InitStruct->Mode == LL_GPIO_MODE_INPUT)
  188.       {
  189.         /* Check The Pull parameter */
  190.         assert_param(IS_LL_GPIO_PULL(GPIO_InitStruct->Pull));
  191.  
  192.         /* Pull-up Pull-down resistor configuration*/
  193.         LL_GPIO_SetPinPull(GPIOx, currentpin, GPIO_InitStruct->Pull);
  194.       }
  195.      
  196.       /* Check Pin Mode parameters */
  197.       assert_param(IS_LL_GPIO_MODE(GPIO_InitStruct->Mode));
  198.      
  199.       /* Pin Mode configuration */
  200.       LL_GPIO_SetPinMode(GPIOx, currentpin, GPIO_InitStruct->Mode);
  201.  
  202.       if ((GPIO_InitStruct->Mode == LL_GPIO_MODE_OUTPUT) || (GPIO_InitStruct->Mode == LL_GPIO_MODE_ALTERNATE))
  203.       {
  204.         /* Check speed and Output mode parameters */
  205.         assert_param(IS_LL_GPIO_SPEED(GPIO_InitStruct->Speed));
  206.         assert_param(IS_LL_GPIO_OUTPUT_TYPE(GPIO_InitStruct->OutputType));
  207.  
  208.         /* Speed mode configuration */
  209.         LL_GPIO_SetPinSpeed(GPIOx, currentpin, GPIO_InitStruct->Speed);
  210.  
  211.         /* Output mode configuration*/
  212.         LL_GPIO_SetPinOutputType(GPIOx, currentpin, GPIO_InitStruct->OutputType);
  213.       }
  214.     }
  215.     pinpos++;
  216.   }
  217.   return (SUCCESS);
  218. }
  219.  
  220. /**
  221.   * @brief Set each @ref LL_GPIO_InitTypeDef field to default value.
  222.   * @param GPIO_InitStruct: pointer to a @ref LL_GPIO_InitTypeDef structure
  223.   *                          whose fields will be set to default values.
  224.   * @retval None
  225.   */
  226.  
  227. void LL_GPIO_StructInit(LL_GPIO_InitTypeDef *GPIO_InitStruct)
  228. {
  229.   /* Reset GPIO init structure parameters values */
  230.   GPIO_InitStruct->Pin        = LL_GPIO_PIN_ALL;
  231.   GPIO_InitStruct->Mode       = LL_GPIO_MODE_FLOATING;
  232.   GPIO_InitStruct->Speed      = LL_GPIO_SPEED_FREQ_LOW;
  233.   GPIO_InitStruct->OutputType = LL_GPIO_OUTPUT_OPENDRAIN;
  234.   GPIO_InitStruct->Pull       = LL_GPIO_PULL_DOWN;
  235. }
  236.  
  237. /**
  238.   * @}
  239.   */
  240.  
  241. /**
  242.   * @}
  243.   */
  244.  
  245. /**
  246.   * @}
  247.   */
  248.  
  249. #endif /* defined (GPIOA) || defined (GPIOB) || defined (GPIOC) || defined (GPIOD) || defined (GPIOE) || defined (GPIOF) || defined (GPIOG) */
  250.  
  251. /**
  252.   * @}
  253.   */
  254.  
  255. #endif /* USE_FULL_LL_DRIVER */
  256.  
  257.