STM32vldiscovery.c 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  1. /**
  2. ******************************************************************************
  3. * @file stm32vldiscovery.c
  4. * @author MCD Application Team
  5. * @version V1.0.0
  6. * @date 09/13/2010
  7. * @brief STM32VLDISCOVERY abstraction layer.
  8. * This file should be added to the main application to use the provided
  9. * functions that manage the Leds LD3 and LD4 and the USER push-button.
  10. ******************************************************************************
  11. * @copy
  12. *
  13. * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
  14. * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE
  15. * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY
  16. * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING
  17. * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE
  18. * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
  19. *
  20. * <h2><center>&copy; COPYRIGHT 2010 STMicroelectronics</center></h2>
  21. */
  22. /* Includes ------------------------------------------------------------------*/
  23. #include "STM32vldiscovery.h"
  24. /** @defgroup STM32vldiscovery_Private_TypesDefinitions
  25. * @{
  26. */
  27. /**
  28. * @}
  29. */
  30. /** @defgroup STM32vldiscovery_Private_Defines
  31. * @{
  32. */
  33. /**
  34. * @}
  35. */
  36. /** @defgroup STM32vldiscovery_Private_Macros
  37. * @{
  38. */
  39. /**
  40. * @}
  41. */
  42. /** @defgroup STM32vldiscovery_Private_Variables
  43. * @{
  44. */
  45. GPIO_TypeDef* GPIO_PORT[LEDn] = {LED3_GPIO_PORT, LED4_GPIO_PORT};
  46. const uint16_t GPIO_PIN[LEDn] = {LED3_PIN, LED4_PIN};
  47. const uint32_t GPIO_CLK[LEDn] = {LED3_GPIO_CLK, LED4_GPIO_CLK};
  48. const uint16_t BUTTON_PIN_SOURCE[BUTTONn] = {USER_BUTTON_EXTI_PIN_SOURCE};
  49. const uint16_t BUTTON_PORT_SOURCE[BUTTONn] = {USER_BUTTON_EXTI_PORT_SOURCE};
  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. const uint16_t BUTTON_EXTI_LINE[BUTTONn] = {USER_BUTTON_EXTI_LINE};
  54. const uint16_t BUTTON_IRQn[BUTTONn] = {USER_BUTTON_EXTI_IRQn};
  55. /** @defgroup STM32vldiscovery_Private_FunctionPrototypes
  56. * @{
  57. */
  58. /**
  59. * @}
  60. */
  61. /** @defgroup STM32vldiscovery_Private_Functions
  62. * @{
  63. */
  64. /**
  65. * @brief Configures LED GPIO.
  66. * @param Led: Specifies the Led to be configured.
  67. * This parameter can be one of following parameters:
  68. * @arg LED3
  69. * @arg LED4
  70. * @retval None
  71. */
  72. void STM32vldiscovery_LEDInit(Led_TypeDef Led)
  73. {
  74. GPIO_InitTypeDef GPIO_InitStructure;
  75. /* Enable the GPIO_LED Clock */
  76. RCC_APB2PeriphClockCmd(GPIO_CLK[Led], ENABLE);
  77. /* Configure the GPIO_LED pin */
  78. GPIO_InitStructure.GPIO_Pin = GPIO_PIN[Led];
  79. GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
  80. GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  81. GPIO_Init(GPIO_PORT[Led], &GPIO_InitStructure);
  82. }
  83. /**
  84. * @brief Turns selected LED On.
  85. * @param Led: Specifies the Led to be set on.
  86. * This parameter can be one of following parameters:
  87. * @arg LED3
  88. * @arg LED4
  89. * @retval None
  90. */
  91. void STM32vldiscovery_LEDOn(Led_TypeDef Led)
  92. {
  93. GPIO_PORT[Led]->BSRR = GPIO_PIN[Led];
  94. }
  95. /**
  96. * @brief Turns selected LED Off.
  97. * @param Led: Specifies the Led to be set off.
  98. * This parameter can be one of following parameters:
  99. * @arg LED3
  100. * @arg LED4
  101. * @retval None
  102. */
  103. void STM32vldiscovery_LEDOff(Led_TypeDef Led)
  104. {
  105. GPIO_PORT[Led]->BRR = GPIO_PIN[Led];
  106. }
  107. /**
  108. * @brief Toggles the selected LED.
  109. * @param Led: Specifies the Led to be toggled.
  110. * This parameter can be one of following parameters:
  111. * @arg LED3
  112. * @arg LED4
  113. * @retval None
  114. */
  115. void STM32vldiscovery_LEDToggle(Led_TypeDef Led)
  116. {
  117. GPIO_PORT[Led]->ODR ^= GPIO_PIN[Led];
  118. }
  119. /**
  120. * @brief Configures Button GPIO and EXTI Line.
  121. * @param Button: Specifies the Button to be configured.
  122. * This parameter can be one of following parameters:
  123. * @arg BUTTON_USER: USER Push Button
  124. * @param Button_Mode: Specifies Button mode.
  125. * This parameter can be one of following parameters:
  126. * @arg BUTTON_MODE_GPIO: Button will be used as simple IO
  127. * @arg BUTTON_MODE_EXTI: Button will be connected to EXTI line with interrupt
  128. * generation capability
  129. * @retval None
  130. */
  131. void STM32vldiscovery_PBInit(Button_TypeDef Button, ButtonMode_TypeDef Button_Mode)
  132. {
  133. GPIO_InitTypeDef GPIO_InitStructure;
  134. EXTI_InitTypeDef EXTI_InitStructure;
  135. NVIC_InitTypeDef NVIC_InitStructure;
  136. /* Enable the BUTTON Clock */
  137. RCC_APB2PeriphClockCmd(BUTTON_CLK[Button] | RCC_APB2Periph_AFIO, ENABLE);
  138. /* Configure Button pin as input floating */
  139. GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
  140. GPIO_InitStructure.GPIO_Pin = BUTTON_PIN[Button];
  141. GPIO_Init(BUTTON_PORT[Button], &GPIO_InitStructure);
  142. if (Button_Mode == BUTTON_MODE_EXTI)
  143. {
  144. /* Connect Button EXTI Line to Button GPIO Pin */
  145. GPIO_EXTILineConfig(BUTTON_PORT_SOURCE[Button], BUTTON_PIN_SOURCE[Button]);
  146. /* Configure Button EXTI line */
  147. EXTI_InitStructure.EXTI_Line = BUTTON_EXTI_LINE[Button];
  148. EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
  149. EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising;
  150. EXTI_InitStructure.EXTI_LineCmd = ENABLE;
  151. EXTI_Init(&EXTI_InitStructure);
  152. /* Enable and set Button EXTI Interrupt to the lowest priority */
  153. NVIC_InitStructure.NVIC_IRQChannel = BUTTON_IRQn[Button];
  154. NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0x0F;
  155. NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0x0F;
  156. NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
  157. NVIC_Init(&NVIC_InitStructure);
  158. }
  159. }
  160. /**
  161. * @brief Returns the selected Button state.
  162. * @param Button: Specifies the Button to be checked.
  163. * This parameter can be one of following parameters:
  164. * @arg BUTTON_USER: USER Push Button
  165. * @retval The Button GPIO pin value.
  166. */
  167. uint32_t STM32vldiscovery_PBGetState(Button_TypeDef Button)
  168. {
  169. return GPIO_ReadInputDataBit(BUTTON_PORT[Button], BUTTON_PIN[Button]);
  170. }
  171. /**
  172. * @}
  173. */
  174. /**
  175. * @}
  176. */
  177. /**
  178. * @}
  179. */
  180. /**
  181. * @}
  182. */
  183. /**
  184. * @}
  185. */
  186. /******************* (C) COPYRIGHT 2010 STMicroelectronics *****END OF FILE****/