123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231 |
- /**
- ******************************************************************************
- * @file stm32vldiscovery.c
- * @author MCD Application Team
- * @version V1.0.0
- * @date 09/13/2010
- * @brief STM32VLDISCOVERY abstraction layer.
- * This file should be added to the main application to use the provided
- * functions that manage the Leds LD3 and LD4 and the USER push-button.
- ******************************************************************************
- * @copy
- *
- * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
- * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE
- * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY
- * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING
- * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE
- * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
- *
- * <h2><center>© COPYRIGHT 2010 STMicroelectronics</center></h2>
- */
-
- /* Includes ------------------------------------------------------------------*/
- #include "STM32vldiscovery.h"
- /** @defgroup STM32vldiscovery_Private_TypesDefinitions
- * @{
- */
- /**
- * @}
- */
- /** @defgroup STM32vldiscovery_Private_Defines
- * @{
- */
- /**
- * @}
- */
- /** @defgroup STM32vldiscovery_Private_Macros
- * @{
- */
- /**
- * @}
- */
- /** @defgroup STM32vldiscovery_Private_Variables
- * @{
- */
- GPIO_TypeDef* GPIO_PORT[LEDn] = {LED3_GPIO_PORT, LED4_GPIO_PORT};
- const uint16_t GPIO_PIN[LEDn] = {LED3_PIN, LED4_PIN};
- const uint32_t GPIO_CLK[LEDn] = {LED3_GPIO_CLK, LED4_GPIO_CLK};
- const uint16_t BUTTON_PIN_SOURCE[BUTTONn] = {USER_BUTTON_EXTI_PIN_SOURCE};
- const uint16_t BUTTON_PORT_SOURCE[BUTTONn] = {USER_BUTTON_EXTI_PORT_SOURCE};
- GPIO_TypeDef* BUTTON_PORT[BUTTONn] = {USER_BUTTON_GPIO_PORT};
- const uint16_t BUTTON_PIN[BUTTONn] = {USER_BUTTON_PIN};
- const uint32_t BUTTON_CLK[BUTTONn] = {USER_BUTTON_GPIO_CLK};
- const uint16_t BUTTON_EXTI_LINE[BUTTONn] = {USER_BUTTON_EXTI_LINE};
- const uint16_t BUTTON_IRQn[BUTTONn] = {USER_BUTTON_EXTI_IRQn};
- /** @defgroup STM32vldiscovery_Private_FunctionPrototypes
- * @{
- */
- /**
- * @}
- */
- /** @defgroup STM32vldiscovery_Private_Functions
- * @{
- */
- /**
- * @brief Configures LED GPIO.
- * @param Led: Specifies the Led to be configured.
- * This parameter can be one of following parameters:
- * @arg LED3
- * @arg LED4
- * @retval None
- */
- void STM32vldiscovery_LEDInit(Led_TypeDef Led)
- {
- GPIO_InitTypeDef GPIO_InitStructure;
-
- /* Enable the GPIO_LED Clock */
- RCC_APB2PeriphClockCmd(GPIO_CLK[Led], ENABLE);
- /* Configure the GPIO_LED pin */
- GPIO_InitStructure.GPIO_Pin = GPIO_PIN[Led];
-
- GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
- GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
- GPIO_Init(GPIO_PORT[Led], &GPIO_InitStructure);
- }
- /**
- * @brief Turns selected LED On.
- * @param Led: Specifies the Led to be set on.
- * This parameter can be one of following parameters:
- * @arg LED3
- * @arg LED4
- * @retval None
- */
- void STM32vldiscovery_LEDOn(Led_TypeDef Led)
- {
- GPIO_PORT[Led]->BSRR = GPIO_PIN[Led];
- }
- /**
- * @brief Turns selected LED Off.
- * @param Led: Specifies the Led to be set off.
- * This parameter can be one of following parameters:
- * @arg LED3
- * @arg LED4
- * @retval None
- */
- void STM32vldiscovery_LEDOff(Led_TypeDef Led)
- {
- GPIO_PORT[Led]->BRR = GPIO_PIN[Led];
- }
- /**
- * @brief Toggles the selected LED.
- * @param Led: Specifies the Led to be toggled.
- * This parameter can be one of following parameters:
- * @arg LED3
- * @arg LED4
- * @retval None
- */
- void STM32vldiscovery_LEDToggle(Led_TypeDef Led)
- {
- GPIO_PORT[Led]->ODR ^= GPIO_PIN[Led];
- }
- /**
- * @brief Configures Button GPIO and EXTI Line.
- * @param Button: Specifies the Button to be configured.
- * This parameter can be one of following parameters:
- * @arg BUTTON_USER: USER Push Button
- * @param Button_Mode: Specifies Button mode.
- * This parameter can be one of following parameters:
- * @arg BUTTON_MODE_GPIO: Button will be used as simple IO
- * @arg BUTTON_MODE_EXTI: Button will be connected to EXTI line with interrupt
- * generation capability
- * @retval None
- */
- void STM32vldiscovery_PBInit(Button_TypeDef Button, ButtonMode_TypeDef Button_Mode)
- {
- GPIO_InitTypeDef GPIO_InitStructure;
- EXTI_InitTypeDef EXTI_InitStructure;
- NVIC_InitTypeDef NVIC_InitStructure;
- /* Enable the BUTTON Clock */
- RCC_APB2PeriphClockCmd(BUTTON_CLK[Button] | RCC_APB2Periph_AFIO, ENABLE);
- /* Configure Button pin as input floating */
- GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
- GPIO_InitStructure.GPIO_Pin = BUTTON_PIN[Button];
- GPIO_Init(BUTTON_PORT[Button], &GPIO_InitStructure);
- if (Button_Mode == BUTTON_MODE_EXTI)
- {
- /* Connect Button EXTI Line to Button GPIO Pin */
- GPIO_EXTILineConfig(BUTTON_PORT_SOURCE[Button], BUTTON_PIN_SOURCE[Button]);
- /* Configure Button EXTI line */
- EXTI_InitStructure.EXTI_Line = BUTTON_EXTI_LINE[Button];
- EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
- EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising;
- EXTI_InitStructure.EXTI_LineCmd = ENABLE;
- EXTI_Init(&EXTI_InitStructure);
- /* Enable and set Button EXTI Interrupt to the lowest priority */
- NVIC_InitStructure.NVIC_IRQChannel = BUTTON_IRQn[Button];
- NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0x0F;
- NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0x0F;
- NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
- NVIC_Init(&NVIC_InitStructure);
- }
- }
- /**
- * @brief Returns the selected Button state.
- * @param Button: Specifies the Button to be checked.
- * This parameter can be one of following parameters:
- * @arg BUTTON_USER: USER Push Button
- * @retval The Button GPIO pin value.
- */
- uint32_t STM32vldiscovery_PBGetState(Button_TypeDef Button)
- {
- return GPIO_ReadInputDataBit(BUTTON_PORT[Button], BUTTON_PIN[Button]);
- }
- /**
- * @}
- */
- /**
- * @}
- */
- /**
- * @}
- */
- /**
- * @}
- */
- /**
- * @}
- */
-
- /******************* (C) COPYRIGHT 2010 STMicroelectronics *****END OF FILE****/
|