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.
 
 
 

276 lines
9.6 KiB

  1. /**
  2. ******************************************************************************
  3. * @file stm32wbxx_ll_gpio.c
  4. * @author MCD Application Team
  5. * @brief GPIO LL module driver.
  6. ******************************************************************************
  7. * @attention
  8. *
  9. * <h2><center>&copy; Copyright (c) 2019 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 "stm32wbxx_ll_gpio.h"
  22. #include "stm32wbxx_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 STM32WBxx_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. /** MISRA C:2012 deviation rule has been granted for following rules:
  36. * Rule-12.2 - Medium: RHS argument is in interval [0,INF] which is out of
  37. * range of the shift operator in following API :
  38. * LL_GPIO_Init
  39. */
  40. /* Private types -------------------------------------------------------------*/
  41. /* Private variables ---------------------------------------------------------*/
  42. /* Private constants ---------------------------------------------------------*/
  43. /* Private macros ------------------------------------------------------------*/
  44. /** @addtogroup GPIO_LL_Private_Macros
  45. * @{
  46. */
  47. #define IS_LL_GPIO_PIN(__VALUE__) (((0x00u) < (__VALUE__)) && ((__VALUE__) <= (LL_GPIO_PIN_ALL)))
  48. #define IS_LL_GPIO_MODE(__VALUE__) (((__VALUE__) == LL_GPIO_MODE_INPUT) ||\
  49. ((__VALUE__) == LL_GPIO_MODE_OUTPUT) ||\
  50. ((__VALUE__) == LL_GPIO_MODE_ALTERNATE) ||\
  51. ((__VALUE__) == LL_GPIO_MODE_ANALOG))
  52. #define IS_LL_GPIO_OUTPUT_TYPE(__VALUE__) (((__VALUE__) == LL_GPIO_OUTPUT_PUSHPULL) ||\
  53. ((__VALUE__) == LL_GPIO_OUTPUT_OPENDRAIN))
  54. #define IS_LL_GPIO_SPEED(__VALUE__) (((__VALUE__) == LL_GPIO_SPEED_FREQ_LOW) ||\
  55. ((__VALUE__) == LL_GPIO_SPEED_FREQ_MEDIUM) ||\
  56. ((__VALUE__) == LL_GPIO_SPEED_FREQ_HIGH) ||\
  57. ((__VALUE__) == LL_GPIO_SPEED_FREQ_VERY_HIGH))
  58. #define IS_LL_GPIO_PULL(__VALUE__) (((__VALUE__) == LL_GPIO_PULL_NO) ||\
  59. ((__VALUE__) == LL_GPIO_PULL_UP) ||\
  60. ((__VALUE__) == LL_GPIO_PULL_DOWN))
  61. #define IS_LL_GPIO_ALTERNATE(__VALUE__) (((__VALUE__) == LL_GPIO_AF_0 ) ||\
  62. ((__VALUE__) == LL_GPIO_AF_1 ) ||\
  63. ((__VALUE__) == LL_GPIO_AF_2 ) ||\
  64. ((__VALUE__) == LL_GPIO_AF_3 ) ||\
  65. ((__VALUE__) == LL_GPIO_AF_4 ) ||\
  66. ((__VALUE__) == LL_GPIO_AF_5 ) ||\
  67. ((__VALUE__) == LL_GPIO_AF_6 ) ||\
  68. ((__VALUE__) == LL_GPIO_AF_7 ) ||\
  69. ((__VALUE__) == LL_GPIO_AF_8 ) ||\
  70. ((__VALUE__) == LL_GPIO_AF_9 ) ||\
  71. ((__VALUE__) == LL_GPIO_AF_10 ) ||\
  72. ((__VALUE__) == LL_GPIO_AF_11 ) ||\
  73. ((__VALUE__) == LL_GPIO_AF_12 ) ||\
  74. ((__VALUE__) == LL_GPIO_AF_13 ) ||\
  75. ((__VALUE__) == LL_GPIO_AF_14 ) ||\
  76. ((__VALUE__) == LL_GPIO_AF_15 ))
  77. /**
  78. * @}
  79. */
  80. /* Private function prototypes -----------------------------------------------*/
  81. /* Exported functions --------------------------------------------------------*/
  82. /** @addtogroup GPIO_LL_Exported_Functions
  83. * @{
  84. */
  85. /** @addtogroup GPIO_LL_EF_Init
  86. * @{
  87. */
  88. /**
  89. * @brief De-initialize GPIO registers (Registers restored to their default values).
  90. * @param GPIOx GPIO Port
  91. * @retval An ErrorStatus enumeration value:
  92. * - SUCCESS: GPIO registers are de-initialized
  93. * - ERROR: Wrong GPIO Port
  94. */
  95. ErrorStatus LL_GPIO_DeInit(GPIO_TypeDef *GPIOx)
  96. {
  97. ErrorStatus status = SUCCESS;
  98. /* Check the parameters */
  99. assert_param(IS_GPIO_ALL_INSTANCE(GPIOx));
  100. /* Force and Release reset on clock of GPIOx Port */
  101. if (GPIOx == GPIOA)
  102. {
  103. LL_AHB2_GRP1_ForceReset(LL_AHB2_GRP1_PERIPH_GPIOA);
  104. LL_AHB2_GRP1_ReleaseReset(LL_AHB2_GRP1_PERIPH_GPIOA);
  105. }
  106. else if (GPIOx == GPIOB)
  107. {
  108. LL_AHB2_GRP1_ForceReset(LL_AHB2_GRP1_PERIPH_GPIOB);
  109. LL_AHB2_GRP1_ReleaseReset(LL_AHB2_GRP1_PERIPH_GPIOB);
  110. }
  111. else if (GPIOx == GPIOC)
  112. {
  113. LL_AHB2_GRP1_ForceReset(LL_AHB2_GRP1_PERIPH_GPIOC);
  114. LL_AHB2_GRP1_ReleaseReset(LL_AHB2_GRP1_PERIPH_GPIOC);
  115. }
  116. #if defined(GPIOD)
  117. else if (GPIOx == GPIOD)
  118. {
  119. LL_AHB2_GRP1_ForceReset(LL_AHB2_GRP1_PERIPH_GPIOD);
  120. LL_AHB2_GRP1_ReleaseReset(LL_AHB2_GRP1_PERIPH_GPIOD);
  121. }
  122. #endif /* GPIOD */
  123. #if defined(GPIOE)
  124. else if (GPIOx == GPIOE)
  125. {
  126. LL_AHB2_GRP1_ForceReset(LL_AHB2_GRP1_PERIPH_GPIOE);
  127. LL_AHB2_GRP1_ReleaseReset(LL_AHB2_GRP1_PERIPH_GPIOE);
  128. }
  129. #endif /* GPIOE */
  130. #if defined(GPIOH)
  131. else if (GPIOx == GPIOH)
  132. {
  133. LL_AHB2_GRP1_ForceReset(LL_AHB2_GRP1_PERIPH_GPIOH);
  134. LL_AHB2_GRP1_ReleaseReset(LL_AHB2_GRP1_PERIPH_GPIOH);
  135. }
  136. #endif /* GPIOH */
  137. else
  138. {
  139. status = ERROR;
  140. }
  141. return (status);
  142. }
  143. /**
  144. * @brief Initialize GPIO registers according to the specified parameters in GPIO_InitStruct.
  145. * @param GPIOx GPIO Port
  146. * @param GPIO_InitStruct pointer to a @ref LL_GPIO_InitTypeDef structure
  147. * that contains the configuration information for the specified GPIO peripheral.
  148. * @retval An ErrorStatus enumeration value:
  149. * - SUCCESS: GPIO registers are initialized according to GPIO_InitStruct content
  150. * - ERROR: Not applicable
  151. */
  152. ErrorStatus LL_GPIO_Init(GPIO_TypeDef *GPIOx, LL_GPIO_InitTypeDef *GPIO_InitStruct)
  153. {
  154. uint32_t pinpos;
  155. uint32_t currentpin;
  156. /* Check the parameters */
  157. assert_param(IS_GPIO_ALL_INSTANCE(GPIOx));
  158. assert_param(IS_LL_GPIO_PIN(GPIO_InitStruct->Pin));
  159. assert_param(IS_LL_GPIO_MODE(GPIO_InitStruct->Mode));
  160. assert_param(IS_LL_GPIO_PULL(GPIO_InitStruct->Pull));
  161. /* ------------------------- Configure the port pins ---------------- */
  162. /* Initialize pinpos on first pin set */
  163. pinpos = POSITION_VAL(GPIO_InitStruct->Pin);
  164. /* Configure the port pins */
  165. while (((GPIO_InitStruct->Pin) >> pinpos) != 0x00u)
  166. {
  167. /* Get current io position */
  168. currentpin = (GPIO_InitStruct->Pin) & (0x00000001uL << pinpos);
  169. if (currentpin != 0x00u)
  170. {
  171. if ((GPIO_InitStruct->Mode == LL_GPIO_MODE_OUTPUT) || (GPIO_InitStruct->Mode == LL_GPIO_MODE_ALTERNATE))
  172. {
  173. /* Check Speed mode parameters */
  174. assert_param(IS_LL_GPIO_SPEED(GPIO_InitStruct->Speed));
  175. /* Speed mode configuration */
  176. LL_GPIO_SetPinSpeed(GPIOx, currentpin, GPIO_InitStruct->Speed);
  177. /* Check Output mode parameters */
  178. assert_param(IS_LL_GPIO_OUTPUT_TYPE(GPIO_InitStruct->OutputType));
  179. /* Output mode configuration*/
  180. LL_GPIO_SetPinOutputType(GPIOx, currentpin, GPIO_InitStruct->OutputType);
  181. }
  182. /* Pull-up Pull down resistor configuration*/
  183. LL_GPIO_SetPinPull(GPIOx, currentpin, GPIO_InitStruct->Pull);
  184. if (GPIO_InitStruct->Mode == LL_GPIO_MODE_ALTERNATE)
  185. {
  186. /* Check Alternate parameter */
  187. assert_param(IS_LL_GPIO_ALTERNATE(GPIO_InitStruct->Alternate));
  188. /* Speed mode configuration */
  189. if (POSITION_VAL(currentpin) < 0x00000008uL)
  190. {
  191. LL_GPIO_SetAFPin_0_7(GPIOx, currentpin, GPIO_InitStruct->Alternate);
  192. }
  193. else
  194. {
  195. LL_GPIO_SetAFPin_8_15(GPIOx, currentpin, GPIO_InitStruct->Alternate);
  196. }
  197. }
  198. /* Pin Mode configuration */
  199. LL_GPIO_SetPinMode(GPIOx, currentpin, GPIO_InitStruct->Mode);
  200. }
  201. pinpos++;
  202. }
  203. return (SUCCESS);
  204. }
  205. /**
  206. * @brief Set each @ref LL_GPIO_InitTypeDef field to default value.
  207. * @param GPIO_InitStruct pointer to a @ref LL_GPIO_InitTypeDef structure
  208. * whose fields will be set to default values.
  209. * @retval None
  210. */
  211. void LL_GPIO_StructInit(LL_GPIO_InitTypeDef *GPIO_InitStruct)
  212. {
  213. /* Reset GPIO init structure parameters values */
  214. GPIO_InitStruct->Pin = LL_GPIO_PIN_ALL;
  215. GPIO_InitStruct->Mode = LL_GPIO_MODE_ANALOG;
  216. GPIO_InitStruct->Speed = LL_GPIO_SPEED_FREQ_LOW;
  217. GPIO_InitStruct->OutputType = LL_GPIO_OUTPUT_PUSHPULL;
  218. GPIO_InitStruct->Pull = LL_GPIO_PULL_NO;
  219. GPIO_InitStruct->Alternate = LL_GPIO_AF_0;
  220. }
  221. /**
  222. * @}
  223. */
  224. /**
  225. * @}
  226. */
  227. /**
  228. * @}
  229. */
  230. #endif /* defined (GPIOA) || defined (GPIOB) || defined (GPIOC) || defined (GPIOD) || defined (GPIOE) || defined (GPIOH) */
  231. /**
  232. * @}
  233. */
  234. #endif /* USE_FULL_LL_DRIVER */
  235. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/