/stm32vldiscovery/STM32_Discovery.c

https://github.com/coon42legacy/flyfi_sd_midi · C · 195 lines · 40 code · 30 blank · 125 comment · 0 complexity · e85ee20e45412b7405e9575dd83c0b89 MD5 · raw file

  1. /**
  2. ******************************************************************************
  3. * @file STM32_Discovery.c
  4. * @author MCD Team
  5. * @version V0.1
  6. * @date 06/17/2010
  7. * @brief STM32_Discovery abstraction layer.
  8. * This file should be added to the main application to use the provided
  9. * functions that manage Leds, push-buttons, COM ports and low level
  10. * HW resources initialization of the different modules available on
  11. * STM32_Discovery boards from STMicroelectronics.
  12. ******************************************************************************
  13. * @copy
  14. *
  15. * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
  16. * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE
  17. * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY
  18. * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING
  19. * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE
  20. * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
  21. *
  22. * <h2><center>&copy; COPYRIGHT 2010 STMicroelectronics</center></h2>
  23. */
  24. /* Includes ------------------------------------------------------------------*/
  25. #include "STM32_Discovery.h"
  26. /** @defgroup STM32_Discovery_Private_TypesDefinitions
  27. * @{
  28. */
  29. /**
  30. * @}
  31. */
  32. /** @defgroup STM32_Discovery_Private_Defines
  33. * @{
  34. */
  35. /**
  36. * @}
  37. */
  38. /** @defgroup STM32_Discovery_Private_Macros
  39. * @{
  40. */
  41. /**
  42. * @}
  43. */
  44. /** @defgroup STM32_Discovery_Private_Variables
  45. * @{
  46. */
  47. GPIO_TypeDef* GPIO_PORT[LEDn] = {LED3_GPIO_PORT, LED4_GPIO_PORT};
  48. const uint16_t GPIO_PIN[LEDn] = {LED3_PIN, LED4_PIN};
  49. const uint32_t GPIO_CLK[LEDn] = {LED3_GPIO_CLK, LED4_GPIO_CLK};
  50. GPIO_TypeDef* BUTTON_PORT[BUTTONn] = {USER_BUTTON_GPIO_PORT};
  51. const uint16_t BUTTON_PIN[BUTTONn] = {USER_BUTTON_PIN};
  52. const uint32_t BUTTON_CLK[BUTTONn] = {USER_BUTTON_GPIO_CLK};
  53. /** @defgroup STM32_Discovery_Private_FunctionPrototypes
  54. * @{
  55. */
  56. /**
  57. * @}
  58. */
  59. /** @defgroup STM32_Discovery_Private_Functions
  60. * @{
  61. */
  62. /**
  63. * @brief Configures LED GPIO.
  64. * @param Led: Specifies the Led to be configured.
  65. * This parameter can be one of following parameters:
  66. * @arg LED3
  67. * @arg LED4
  68. * @retval None
  69. */
  70. void STM32_Discovery_LEDInit(Led_TypeDef Led)
  71. {
  72. GPIO_InitTypeDef GPIO_InitStructure;
  73. /* Enable the GPIO_LED Clock */
  74. RCC_APB2PeriphClockCmd(GPIO_CLK[Led], ENABLE);
  75. /* Configure the GPIO_LED pin */
  76. GPIO_InitStructure.GPIO_Pin = GPIO_PIN[Led];
  77. GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
  78. GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  79. GPIO_Init(GPIO_PORT[Led], &GPIO_InitStructure);
  80. }
  81. /**
  82. * @brief Turns selected LED On.
  83. * @param Led: Specifies the Led to be set on.
  84. * This parameter can be one of following parameters:
  85. * @arg LED3
  86. * @arg LED4
  87. * @retval None
  88. */
  89. void STM32_Discovery_LEDOn(Led_TypeDef Led)
  90. {
  91. GPIO_PORT[Led]->BSRR = GPIO_PIN[Led];
  92. }
  93. /**
  94. * @brief Turns selected LED Off.
  95. * @param Led: Specifies the Led to be set off.
  96. * This parameter can be one of following parameters:
  97. * @arg LED3
  98. * @arg LED4
  99. * @retval None
  100. */
  101. void STM32_Discovery_LEDOff(Led_TypeDef Led)
  102. {
  103. GPIO_PORT[Led]->BRR = GPIO_PIN[Led];
  104. }
  105. /**
  106. * @brief Toggles the selected LED.
  107. * @param Led: Specifies the Led to be toggled.
  108. * This parameter can be one of following parameters:
  109. * @arg LED3
  110. * @arg LED4
  111. * @retval None
  112. */
  113. void STM32_Discovery_LEDToggle(Led_TypeDef Led)
  114. {
  115. GPIO_PORT[Led]->ODR ^= GPIO_PIN[Led];
  116. }
  117. /**
  118. * @brief Configures Button GPIO and EXTI Line.
  119. * @param Button: Specifies the Button to be configured.
  120. * This parameter can be one of following parameters:
  121. * @arg BUTTON_USER: USER Push Button
  122. * @param Button_Mode: Specifies Button mode.
  123. * This parameter can be one of following parameters:
  124. * @arg BUTTON_MODE_GPIO: Button will be used as simple IO
  125. * @arg BUTTON_MODE_EXTI: Button will be connected to EXTI line with interrupt
  126. * generation capability
  127. * @retval None
  128. */
  129. void STM32_Discovery_PBInit(Button_TypeDef Button, ButtonMode_TypeDef Button_Mode)
  130. {
  131. GPIO_InitTypeDef GPIO_InitStructure;
  132. /* Enable the BUTTON Clock */
  133. RCC_APB2PeriphClockCmd(BUTTON_CLK[Button] | RCC_APB2Periph_AFIO, ENABLE);
  134. /* Configure Button pin as input floating */
  135. GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
  136. GPIO_InitStructure.GPIO_Pin = BUTTON_PIN[Button];
  137. GPIO_Init(BUTTON_PORT[Button], &GPIO_InitStructure);
  138. }
  139. /**
  140. * @brief Returns the selected Button state.
  141. * @param Button: Specifies the Button to be checked.
  142. * This parameter can be one of following parameters:
  143. * @arg BUTTON_USER: USER Push Button
  144. * @retval The Button GPIO pin value.
  145. */
  146. uint32_t STM32_Discovery_PBGetState(Button_TypeDef Button)
  147. {
  148. return GPIO_ReadInputDataBit(BUTTON_PORT[Button], BUTTON_PIN[Button]);
  149. }
  150. /**
  151. * @}
  152. */
  153. /**
  154. * @}
  155. */
  156. /**
  157. * @}
  158. */
  159. /**
  160. * @}
  161. */
  162. /**
  163. * @}
  164. */
  165. /******************* (C) COPYRIGHT 2010 STMicroelectronics *****END OF FILE****/