You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

266 lines
8.8 KiB

  1. /**
  2. ******************************************************************************
  3. * @file stm32l0xx_ll_gpio.c
  4. * @author MCD Application Team
  5. * @brief GPIO LL module driver.
  6. ******************************************************************************
  7. * @attention
  8. *
  9. * <h2><center>&copy; Copyright(c) 2016 STMicroelectronics.
  10. * All rights reserved.</center></h2>
  11. *
  12. * This software component is licensed by ST under BSD 3-Clause license,
  13. * the "License"; You may not use this file except in compliance with the
  14. * License. You may obtain a copy of the License at:
  15. * opensource.org/licenses/BSD-3-Clause
  16. *
  17. ******************************************************************************
  18. */
  19. #if defined(USE_FULL_LL_DRIVER)
  20. /* Includes ------------------------------------------------------------------*/
  21. #include "stm32l0xx_ll_gpio.h"
  22. #include "stm32l0xx_ll_bus.h"
  23. #ifdef USE_FULL_ASSERT
  24. #include "stm32_assert.h"
  25. #else
  26. #define assert_param(expr) ((void)0U)
  27. #endif
  28. /** @addtogroup STM32L0xx_LL_Driver
  29. * @{
  30. */
  31. #if defined (GPIOA) || defined (GPIOB) || defined (GPIOC) || defined (GPIOD) || defined (GPIOE) || defined (GPIOH)
  32. /** @addtogroup GPIO_LL
  33. * @{
  34. */
  35. /* Private types -------------------------------------------------------------*/
  36. /* Private variables ---------------------------------------------------------*/
  37. /* Private constants ---------------------------------------------------------*/
  38. /* Private macros ------------------------------------------------------------*/
  39. /** @addtogroup GPIO_LL_Private_Macros
  40. * @{
  41. */
  42. #define IS_LL_GPIO_PIN(__VALUE__) ((((uint32_t)0x00000000U) < (__VALUE__)) && ((__VALUE__) <= (LL_GPIO_PIN_ALL)))
  43. #define IS_LL_GPIO_MODE(__VALUE__) (((__VALUE__) == LL_GPIO_MODE_INPUT) ||\
  44. ((__VALUE__) == LL_GPIO_MODE_OUTPUT) ||\
  45. ((__VALUE__) == LL_GPIO_MODE_ALTERNATE) ||\
  46. ((__VALUE__) == LL_GPIO_MODE_ANALOG))
  47. #define IS_LL_GPIO_OUTPUT_TYPE(__VALUE__) (((__VALUE__) == LL_GPIO_OUTPUT_PUSHPULL) ||\
  48. ((__VALUE__) == LL_GPIO_OUTPUT_OPENDRAIN))
  49. #define IS_LL_GPIO_SPEED(__VALUE__) (((__VALUE__) == LL_GPIO_SPEED_FREQ_LOW) ||\
  50. ((__VALUE__) == LL_GPIO_SPEED_FREQ_MEDIUM) ||\
  51. ((__VALUE__) == LL_GPIO_SPEED_FREQ_HIGH) ||\
  52. ((__VALUE__) == LL_GPIO_SPEED_FREQ_VERY_HIGH))
  53. #define IS_LL_GPIO_PULL(__VALUE__) (((__VALUE__) == LL_GPIO_PULL_NO) ||\
  54. ((__VALUE__) == LL_GPIO_PULL_UP) ||\
  55. ((__VALUE__) == LL_GPIO_PULL_DOWN))
  56. #define IS_LL_GPIO_ALTERNATE(__VALUE__) (((__VALUE__) == LL_GPIO_AF_0 ) ||\
  57. ((__VALUE__) == LL_GPIO_AF_1 ) ||\
  58. ((__VALUE__) == LL_GPIO_AF_2 ) ||\
  59. ((__VALUE__) == LL_GPIO_AF_3 ) ||\
  60. ((__VALUE__) == LL_GPIO_AF_4 ) ||\
  61. ((__VALUE__) == LL_GPIO_AF_5 ) ||\
  62. ((__VALUE__) == LL_GPIO_AF_6 ) ||\
  63. ((__VALUE__) == LL_GPIO_AF_7 ))
  64. /**
  65. * @}
  66. */
  67. /* Private function prototypes -----------------------------------------------*/
  68. /* Exported functions --------------------------------------------------------*/
  69. /** @addtogroup GPIO_LL_Exported_Functions
  70. * @{
  71. */
  72. /** @addtogroup GPIO_LL_EF_Init
  73. * @{
  74. */
  75. /**
  76. * @brief De-initialize GPIO registers (Registers restored to their default values).
  77. * @param GPIOx GPIO Port
  78. * @retval An ErrorStatus enumeration value:
  79. * - SUCCESS: GPIO registers are de-initialized
  80. * - ERROR: Wrong GPIO Port
  81. */
  82. ErrorStatus LL_GPIO_DeInit(GPIO_TypeDef *GPIOx)
  83. {
  84. ErrorStatus status = SUCCESS;
  85. /* Check the parameters */
  86. assert_param(IS_GPIO_ALL_INSTANCE(GPIOx));
  87. /* Force and Release reset on clock of GPIOx Port */
  88. if (GPIOx == GPIOA)
  89. {
  90. LL_IOP_GRP1_ForceReset(LL_IOP_GRP1_PERIPH_GPIOA);
  91. LL_IOP_GRP1_ReleaseReset(LL_IOP_GRP1_PERIPH_GPIOA);
  92. }
  93. else if (GPIOx == GPIOB)
  94. {
  95. LL_IOP_GRP1_ForceReset(LL_IOP_GRP1_PERIPH_GPIOB);
  96. LL_IOP_GRP1_ReleaseReset(LL_IOP_GRP1_PERIPH_GPIOB);
  97. }
  98. else if (GPIOx == GPIOC)
  99. {
  100. LL_IOP_GRP1_ForceReset(LL_IOP_GRP1_PERIPH_GPIOC);
  101. LL_IOP_GRP1_ReleaseReset(LL_IOP_GRP1_PERIPH_GPIOC);
  102. }
  103. #if defined(GPIOD)
  104. else if (GPIOx == GPIOD)
  105. {
  106. LL_IOP_GRP1_ForceReset(LL_IOP_GRP1_PERIPH_GPIOD);
  107. LL_IOP_GRP1_ReleaseReset(LL_IOP_GRP1_PERIPH_GPIOD);
  108. }
  109. #endif /* GPIOD */
  110. #if defined(GPIOE)
  111. else if (GPIOx == GPIOE)
  112. {
  113. LL_IOP_GRP1_ForceReset(LL_IOP_GRP1_PERIPH_GPIOE);
  114. LL_IOP_GRP1_ReleaseReset(LL_IOP_GRP1_PERIPH_GPIOE);
  115. }
  116. #endif /* GPIOE */
  117. #if defined(GPIOH)
  118. else if (GPIOx == GPIOH)
  119. {
  120. LL_IOP_GRP1_ForceReset(LL_IOP_GRP1_PERIPH_GPIOH);
  121. LL_IOP_GRP1_ReleaseReset(LL_IOP_GRP1_PERIPH_GPIOH);
  122. }
  123. #endif /* GPIOH */
  124. else
  125. {
  126. status = ERROR;
  127. }
  128. return (status);
  129. }
  130. /**
  131. * @brief Initialize GPIO registers according to the specified parameters in GPIO_InitStruct.
  132. * @param GPIOx GPIO Port
  133. * @param GPIO_InitStruct pointer to a @ref LL_GPIO_InitTypeDef structure
  134. * that contains the configuration information for the specified GPIO peripheral.
  135. * @retval An ErrorStatus enumeration value:
  136. * - SUCCESS: GPIO registers are initialized according to GPIO_InitStruct content
  137. * - ERROR: Not applicable
  138. */
  139. ErrorStatus LL_GPIO_Init(GPIO_TypeDef *GPIOx, LL_GPIO_InitTypeDef *GPIO_InitStruct)
  140. {
  141. uint32_t pinpos = 0x00000000U;
  142. uint32_t currentpin = 0x00000000U;
  143. /* Check the parameters */
  144. assert_param(IS_GPIO_ALL_INSTANCE(GPIOx));
  145. assert_param(IS_LL_GPIO_PIN(GPIO_InitStruct->Pin));
  146. assert_param(IS_LL_GPIO_MODE(GPIO_InitStruct->Mode));
  147. assert_param(IS_LL_GPIO_PULL(GPIO_InitStruct->Pull));
  148. /* ------------------------- Configure the port pins ---------------- */
  149. /* Initialize pinpos on first pin set */
  150. /* pinpos = 0; useless as already done in default initialization */
  151. /* Configure the port pins */
  152. while (((GPIO_InitStruct->Pin) >> pinpos) != 0x00000000U)
  153. {
  154. /* Get current io position */
  155. currentpin = (GPIO_InitStruct->Pin) & (0x00000001U << pinpos);
  156. if (currentpin)
  157. {
  158. /* Pin Mode configuration */
  159. LL_GPIO_SetPinMode(GPIOx, currentpin, GPIO_InitStruct->Mode);
  160. if ((GPIO_InitStruct->Mode == LL_GPIO_MODE_OUTPUT) || (GPIO_InitStruct->Mode == LL_GPIO_MODE_ALTERNATE))
  161. {
  162. /* Check Speed mode parameters */
  163. assert_param(IS_LL_GPIO_SPEED(GPIO_InitStruct->Speed));
  164. /* Speed mode configuration */
  165. LL_GPIO_SetPinSpeed(GPIOx, currentpin, GPIO_InitStruct->Speed);
  166. }
  167. /* Pull-up Pull down resistor configuration*/
  168. LL_GPIO_SetPinPull(GPIOx, currentpin, GPIO_InitStruct->Pull);
  169. if (GPIO_InitStruct->Mode == LL_GPIO_MODE_ALTERNATE)
  170. {
  171. /* Check Alternate parameter */
  172. assert_param(IS_LL_GPIO_ALTERNATE(GPIO_InitStruct->Alternate));
  173. /* Speed mode configuration */
  174. if (currentpin < LL_GPIO_PIN_8)
  175. {
  176. LL_GPIO_SetAFPin_0_7(GPIOx, currentpin, GPIO_InitStruct->Alternate);
  177. }
  178. else
  179. {
  180. LL_GPIO_SetAFPin_8_15(GPIOx, currentpin, GPIO_InitStruct->Alternate);
  181. }
  182. }
  183. }
  184. pinpos++;
  185. }
  186. if ((GPIO_InitStruct->Mode == LL_GPIO_MODE_OUTPUT) || (GPIO_InitStruct->Mode == LL_GPIO_MODE_ALTERNATE))
  187. {
  188. /* Check Output mode parameters */
  189. assert_param(IS_LL_GPIO_OUTPUT_TYPE(GPIO_InitStruct->OutputType));
  190. /* Output mode configuration*/
  191. LL_GPIO_SetPinOutputType(GPIOx, GPIO_InitStruct->Pin, GPIO_InitStruct->OutputType);
  192. }
  193. return (SUCCESS);
  194. }
  195. /**
  196. * @brief Set each @ref LL_GPIO_InitTypeDef field to default value.
  197. * @param GPIO_InitStruct: pointer to a @ref LL_GPIO_InitTypeDef structure
  198. * whose fields will be set to default values.
  199. * @retval None
  200. */
  201. void LL_GPIO_StructInit(LL_GPIO_InitTypeDef *GPIO_InitStruct)
  202. {
  203. /* Reset GPIO init structure parameters values */
  204. GPIO_InitStruct->Pin = LL_GPIO_PIN_ALL;
  205. GPIO_InitStruct->Mode = LL_GPIO_MODE_ANALOG;
  206. GPIO_InitStruct->Speed = LL_GPIO_SPEED_FREQ_LOW;
  207. GPIO_InitStruct->OutputType = LL_GPIO_OUTPUT_PUSHPULL;
  208. GPIO_InitStruct->Pull = LL_GPIO_PULL_NO;
  209. GPIO_InitStruct->Alternate = LL_GPIO_AF_0;
  210. }
  211. /**
  212. * @}
  213. */
  214. /**
  215. * @}
  216. */
  217. /**
  218. * @}
  219. */
  220. #endif /* defined (GPIOA) || defined (GPIOB) || defined (GPIOC) || defined (GPIOD) || defined (GPIOE) || defined (GPIOH) */
  221. /**
  222. * @}
  223. */
  224. #endif /* USE_FULL_LL_DRIVER */
  225. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/