PageRenderTime 24ms CodeModel.GetById 39ms RepoModel.GetById 0ms app.codeStats 0ms

/external/mbed-os/targets/TARGET_STM/TARGET_STM32F0/device/stm32f0xx_ll_gpio.c

https://github.com/adamgreen/gcc4mbed
C | 283 lines | 130 code | 40 blank | 113 comment | 58 complexity | 9f8c1f4ff5842b9deb662dfc267a15e7 MD5 | raw file
  1. /**
  2. ******************************************************************************
  3. * @file stm32f0xx_ll_gpio.c
  4. * @author MCD Application Team
  5. * @version V1.4.0
  6. * @date 27-May-2016
  7. * @brief GPIO LL module driver.
  8. ******************************************************************************
  9. * @attention
  10. *
  11. * <h2><center>&copy; COPYRIGHT(c) 2016 STMicroelectronics</center></h2>
  12. *
  13. * Redistribution and use in source and binary forms, with or without modification,
  14. * are permitted provided that the following conditions are met:
  15. * 1. Redistributions of source code must retain the above copyright notice,
  16. * this list of conditions and the following disclaimer.
  17. * 2. Redistributions in binary form must reproduce the above copyright notice,
  18. * this list of conditions and the following disclaimer in the documentation
  19. * and/or other materials provided with the distribution.
  20. * 3. Neither the name of STMicroelectronics nor the names of its contributors
  21. * may be used to endorse or promote products derived from this software
  22. * without specific prior written permission.
  23. *
  24. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  25. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  26. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  27. * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
  28. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  29. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  30. * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  31. * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  32. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  33. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  34. *
  35. ******************************************************************************
  36. */
  37. #if defined(USE_FULL_LL_DRIVER)
  38. /* Includes ------------------------------------------------------------------*/
  39. #include "stm32f0xx_ll_gpio.h"
  40. #include "stm32f0xx_ll_bus.h"
  41. #ifdef USE_FULL_ASSERT
  42. #include "stm32_assert.h"
  43. #else
  44. #define assert_param(expr) ((void)0U)
  45. #endif
  46. /** @addtogroup STM32F0xx_LL_Driver
  47. * @{
  48. */
  49. #if defined (GPIOA) || defined (GPIOB) || defined (GPIOC) || defined (GPIOD) || defined (GPIOE) || defined (GPIOF)
  50. /** @addtogroup GPIO_LL
  51. * @{
  52. */
  53. /* Private types -------------------------------------------------------------*/
  54. /* Private variables ---------------------------------------------------------*/
  55. /* Private constants ---------------------------------------------------------*/
  56. /* Private macros ------------------------------------------------------------*/
  57. /** @addtogroup GPIO_LL_Private_Macros
  58. * @{
  59. */
  60. #define IS_LL_GPIO_PIN(__VALUE__) ((((uint32_t)0x00000000U) < (__VALUE__)) && ((__VALUE__) <= (LL_GPIO_PIN_ALL)))
  61. #define IS_LL_GPIO_MODE(__VALUE__) (((__VALUE__) == LL_GPIO_MODE_INPUT) ||\
  62. ((__VALUE__) == LL_GPIO_MODE_OUTPUT) ||\
  63. ((__VALUE__) == LL_GPIO_MODE_ALTERNATE) ||\
  64. ((__VALUE__) == LL_GPIO_MODE_ANALOG))
  65. #define IS_LL_GPIO_OUTPUT_TYPE(__VALUE__) (((__VALUE__) == LL_GPIO_OUTPUT_PUSHPULL) ||\
  66. ((__VALUE__) == LL_GPIO_OUTPUT_OPENDRAIN))
  67. #define IS_LL_GPIO_SPEED(__VALUE__) (((__VALUE__) == LL_GPIO_SPEED_FREQ_LOW) ||\
  68. ((__VALUE__) == LL_GPIO_SPEED_FREQ_MEDIUM) ||\
  69. ((__VALUE__) == LL_GPIO_SPEED_FREQ_HIGH) ||\
  70. ((__VALUE__) == LL_GPIO_SPEED_FREQ_VERY_HIGH))
  71. #define IS_LL_GPIO_PULL(__VALUE__) (((__VALUE__) == LL_GPIO_PULL_NO) ||\
  72. ((__VALUE__) == LL_GPIO_PULL_UP) ||\
  73. ((__VALUE__) == LL_GPIO_PULL_DOWN))
  74. #define IS_LL_GPIO_ALTERNATE(__VALUE__) (((__VALUE__) == LL_GPIO_AF_0 ) ||\
  75. ((__VALUE__) == LL_GPIO_AF_1 ) ||\
  76. ((__VALUE__) == LL_GPIO_AF_2 ) ||\
  77. ((__VALUE__) == LL_GPIO_AF_3 ) ||\
  78. ((__VALUE__) == LL_GPIO_AF_4 ) ||\
  79. ((__VALUE__) == LL_GPIO_AF_5 ) ||\
  80. ((__VALUE__) == LL_GPIO_AF_6 ) ||\
  81. ((__VALUE__) == LL_GPIO_AF_7 ))
  82. /**
  83. * @}
  84. */
  85. /* Private function prototypes -----------------------------------------------*/
  86. /* Exported functions --------------------------------------------------------*/
  87. /** @addtogroup GPIO_LL_Exported_Functions
  88. * @{
  89. */
  90. /** @addtogroup GPIO_LL_EF_Init
  91. * @{
  92. */
  93. /**
  94. * @brief De-initialize GPIO registers (Registers restored to their default values).
  95. * @param GPIOx GPIO Port
  96. * @retval An ErrorStatus enumeration value:
  97. * - SUCCESS: GPIO registers are de-initialized
  98. * - ERROR: Wrong GPIO Port
  99. */
  100. ErrorStatus LL_GPIO_DeInit(GPIO_TypeDef *GPIOx)
  101. {
  102. ErrorStatus status = SUCCESS;
  103. /* Check the parameters */
  104. assert_param(IS_GPIO_ALL_INSTANCE(GPIOx));
  105. /* Force and Release reset on clock of GPIOx Port */
  106. if (GPIOx == GPIOA)
  107. {
  108. LL_AHB1_GRP1_ForceReset(LL_AHB1_GRP1_PERIPH_GPIOA);
  109. LL_AHB1_GRP1_ReleaseReset(LL_AHB1_GRP1_PERIPH_GPIOA);
  110. }
  111. else if (GPIOx == GPIOB)
  112. {
  113. LL_AHB1_GRP1_ForceReset(LL_AHB1_GRP1_PERIPH_GPIOB);
  114. LL_AHB1_GRP1_ReleaseReset(LL_AHB1_GRP1_PERIPH_GPIOB);
  115. }
  116. else if (GPIOx == GPIOC)
  117. {
  118. LL_AHB1_GRP1_ForceReset(LL_AHB1_GRP1_PERIPH_GPIOC);
  119. LL_AHB1_GRP1_ReleaseReset(LL_AHB1_GRP1_PERIPH_GPIOC);
  120. }
  121. #if defined(GPIOD)
  122. else if (GPIOx == GPIOD)
  123. {
  124. LL_AHB1_GRP1_ForceReset(LL_AHB1_GRP1_PERIPH_GPIOD);
  125. LL_AHB1_GRP1_ReleaseReset(LL_AHB1_GRP1_PERIPH_GPIOD);
  126. }
  127. #endif /* GPIOD */
  128. #if defined(GPIOE)
  129. else if (GPIOx == GPIOE)
  130. {
  131. LL_AHB1_GRP1_ForceReset(LL_AHB1_GRP1_PERIPH_GPIOE);
  132. LL_AHB1_GRP1_ReleaseReset(LL_AHB1_GRP1_PERIPH_GPIOE);
  133. }
  134. #endif /* GPIOE */
  135. #if defined(GPIOF)
  136. else if (GPIOx == GPIOF)
  137. {
  138. LL_AHB1_GRP1_ForceReset(LL_AHB1_GRP1_PERIPH_GPIOF);
  139. LL_AHB1_GRP1_ReleaseReset(LL_AHB1_GRP1_PERIPH_GPIOF);
  140. }
  141. #endif /* GPIOF */
  142. else
  143. {
  144. status = ERROR;
  145. }
  146. return (status);
  147. }
  148. /**
  149. * @brief Initialize GPIO registers according to the specified parameters in GPIO_InitStruct.
  150. * @param GPIOx GPIO Port
  151. * @param GPIO_InitStruct: pointer to a @ref LL_GPIO_InitTypeDef structure
  152. * that contains the configuration information for the specified GPIO peripheral.
  153. * @retval An ErrorStatus enumeration value:
  154. * - SUCCESS: GPIO registers are initialized according to GPIO_InitStruct content
  155. * - ERROR: Not applicable
  156. */
  157. ErrorStatus LL_GPIO_Init(GPIO_TypeDef *GPIOx, LL_GPIO_InitTypeDef *GPIO_InitStruct)
  158. {
  159. uint32_t pinpos = 0x00000000U;
  160. uint32_t currentpin = 0x00000000U;
  161. /* Check the parameters */
  162. assert_param(IS_GPIO_ALL_INSTANCE(GPIOx));
  163. assert_param(IS_LL_GPIO_PIN(GPIO_InitStruct->Pin));
  164. assert_param(IS_LL_GPIO_MODE(GPIO_InitStruct->Mode));
  165. assert_param(IS_LL_GPIO_PULL(GPIO_InitStruct->Pull));
  166. /* ------------------------- Configure the port pins ---------------- */
  167. /* Initialize pinpos on first pin set */
  168. /* pinpos = 0; useless as already done in default initialization */
  169. /* Configure the port pins */
  170. while (((GPIO_InitStruct->Pin) >> pinpos) != 0x00000000U)
  171. {
  172. /* Get current io position */
  173. currentpin = (GPIO_InitStruct->Pin) & (0x00000001U << pinpos);
  174. if (currentpin)
  175. {
  176. /* Pin Mode configuration */
  177. LL_GPIO_SetPinMode(GPIOx, currentpin, GPIO_InitStruct->Mode);
  178. if ((GPIO_InitStruct->Mode == LL_GPIO_MODE_OUTPUT) || (GPIO_InitStruct->Mode == LL_GPIO_MODE_ALTERNATE))
  179. {
  180. /* Check Speed mode parameters */
  181. assert_param(IS_LL_GPIO_SPEED(GPIO_InitStruct->Speed));
  182. /* Speed mode configuration */
  183. LL_GPIO_SetPinSpeed(GPIOx, currentpin, GPIO_InitStruct->Speed);
  184. }
  185. /* Pull-up Pull down resistor configuration*/
  186. LL_GPIO_SetPinPull(GPIOx, currentpin, GPIO_InitStruct->Pull);
  187. if (GPIO_InitStruct->Mode == LL_GPIO_MODE_ALTERNATE)
  188. {
  189. /* Check Alternate parameter */
  190. assert_param(IS_LL_GPIO_ALTERNATE(GPIO_InitStruct->Alternate));
  191. /* Speed mode configuration */
  192. if (currentpin < LL_GPIO_PIN_8)
  193. {
  194. LL_GPIO_SetAFPin_0_7(GPIOx, currentpin, GPIO_InitStruct->Alternate);
  195. }
  196. else
  197. {
  198. LL_GPIO_SetAFPin_8_15(GPIOx, currentpin, GPIO_InitStruct->Alternate);
  199. }
  200. }
  201. }
  202. pinpos++;
  203. }
  204. if ((GPIO_InitStruct->Mode == LL_GPIO_MODE_OUTPUT) || (GPIO_InitStruct->Mode == LL_GPIO_MODE_ALTERNATE))
  205. {
  206. /* Check Output mode parameters */
  207. assert_param(IS_LL_GPIO_OUTPUT_TYPE(GPIO_InitStruct->OutputType));
  208. /* Output mode configuration*/
  209. LL_GPIO_SetPinOutputType(GPIOx, GPIO_InitStruct->Pin, GPIO_InitStruct->OutputType);
  210. }
  211. return (SUCCESS);
  212. }
  213. /**
  214. * @brief Set each @ref LL_GPIO_InitTypeDef field to default value.
  215. * @param GPIO_InitStruct: pointer to a @ref LL_GPIO_InitTypeDef structure
  216. * whose fields will be set to default values.
  217. * @retval None
  218. */
  219. void LL_GPIO_StructInit(LL_GPIO_InitTypeDef *GPIO_InitStruct)
  220. {
  221. /* Reset GPIO init structure parameters values */
  222. GPIO_InitStruct->Pin = LL_GPIO_PIN_ALL;
  223. GPIO_InitStruct->Mode = LL_GPIO_MODE_ANALOG;
  224. GPIO_InitStruct->Speed = LL_GPIO_SPEED_FREQ_LOW;
  225. GPIO_InitStruct->OutputType = LL_GPIO_OUTPUT_PUSHPULL;
  226. GPIO_InitStruct->Pull = LL_GPIO_PULL_NO;
  227. GPIO_InitStruct->Alternate = LL_GPIO_AF_0;
  228. }
  229. /**
  230. * @}
  231. */
  232. /**
  233. * @}
  234. */
  235. /**
  236. * @}
  237. */
  238. #endif /* defined (GPIOA) || defined (GPIOB) || defined (GPIOC) || defined (GPIOD) || defined (GPIOE) || defined (GPIOF) */
  239. /**
  240. * @}
  241. */
  242. #endif /* USE_FULL_LL_DRIVER */
  243. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/