ble

Dependencies:   HC_SR04_Ultrasonic_Library Servo mbed

Fork of FIP_REV1 by Robotique FIP

Committer:
julientiron
Date:
Tue May 19 16:43:59 2015 +0000
Revision:
0:3d641e170a74
BLE;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
julientiron 0:3d641e170a74 1 /**
julientiron 0:3d641e170a74 2 ******************************************************************************
julientiron 0:3d641e170a74 3 * @file stm32f4xx_nucleo.c
julientiron 0:3d641e170a74 4 * @author MCD Application Team
julientiron 0:3d641e170a74 5 * @version V1.0.0
julientiron 0:3d641e170a74 6 * @date 18-February-2014
julientiron 0:3d641e170a74 7 * @brief This file provides set of firmware functions to manage Leds and
julientiron 0:3d641e170a74 8 * push-button available on STM32F4xx-Nucleo Kit from STMicroelectronics.
julientiron 0:3d641e170a74 9 ******************************************************************************
julientiron 0:3d641e170a74 10 * @attention
julientiron 0:3d641e170a74 11 *
julientiron 0:3d641e170a74 12 * <h2><center>&copy; COPYRIGHT(c) 2014 STMicroelectronics</center></h2>
julientiron 0:3d641e170a74 13 *
julientiron 0:3d641e170a74 14 * Redistribution and use in source and binary forms, with or without modification,
julientiron 0:3d641e170a74 15 * are permitted provided that the following conditions are met:
julientiron 0:3d641e170a74 16 * 1. Redistributions of source code must retain the above copyright notice,
julientiron 0:3d641e170a74 17 * this list of conditions and the following disclaimer.
julientiron 0:3d641e170a74 18 * 2. Redistributions in binary form must reproduce the above copyright notice,
julientiron 0:3d641e170a74 19 * this list of conditions and the following disclaimer in the documentation
julientiron 0:3d641e170a74 20 * and/or other materials provided with the distribution.
julientiron 0:3d641e170a74 21 * 3. Neither the name of STMicroelectronics nor the names of its contributors
julientiron 0:3d641e170a74 22 * may be used to endorse or promote products derived from this software
julientiron 0:3d641e170a74 23 * without specific prior written permission.
julientiron 0:3d641e170a74 24 *
julientiron 0:3d641e170a74 25 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
julientiron 0:3d641e170a74 26 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
julientiron 0:3d641e170a74 27 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
julientiron 0:3d641e170a74 28 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
julientiron 0:3d641e170a74 29 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
julientiron 0:3d641e170a74 30 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
julientiron 0:3d641e170a74 31 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
julientiron 0:3d641e170a74 32 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
julientiron 0:3d641e170a74 33 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
julientiron 0:3d641e170a74 34 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
julientiron 0:3d641e170a74 35 *
julientiron 0:3d641e170a74 36 ******************************************************************************
julientiron 0:3d641e170a74 37 */
julientiron 0:3d641e170a74 38
julientiron 0:3d641e170a74 39 /* Includes ------------------------------------------------------------------*/
julientiron 0:3d641e170a74 40 #include "stm32f4xx_nucleo.h"
julientiron 0:3d641e170a74 41
julientiron 0:3d641e170a74 42 /** @addtogroup BSP
julientiron 0:3d641e170a74 43 * @{
julientiron 0:3d641e170a74 44 */
julientiron 0:3d641e170a74 45
julientiron 0:3d641e170a74 46 /** @addtogroup STM32F4XX_NUCLEO
julientiron 0:3d641e170a74 47 * @{
julientiron 0:3d641e170a74 48 */
julientiron 0:3d641e170a74 49
julientiron 0:3d641e170a74 50 /** @addtogroup STM32F4XX_NUCLEO_LOW_LEVEL
julientiron 0:3d641e170a74 51 * @brief This file provides set of firmware functions to manage Leds and push-button
julientiron 0:3d641e170a74 52 * available on STM32F4xx-Nucleo Kit from STMicroelectronics.
julientiron 0:3d641e170a74 53 * @{
julientiron 0:3d641e170a74 54 */
julientiron 0:3d641e170a74 55
julientiron 0:3d641e170a74 56 /** @defgroup STM32F4XX_NUCLEO_LOW_LEVEL_Private_TypesDefinitions STM32F4XX_NUCLEO_LOW_LEVEL_Private_TypesDefinitions
julientiron 0:3d641e170a74 57 * @{
julientiron 0:3d641e170a74 58 */
julientiron 0:3d641e170a74 59 /**
julientiron 0:3d641e170a74 60 * @}
julientiron 0:3d641e170a74 61 */
julientiron 0:3d641e170a74 62
julientiron 0:3d641e170a74 63
julientiron 0:3d641e170a74 64 /** @defgroup STM32F4XX_NUCLEO_LOW_LEVEL_Private_Defines STM32F4XX_NUCLEO_LOW_LEVEL_Private_Defines
julientiron 0:3d641e170a74 65 * @{
julientiron 0:3d641e170a74 66 */
julientiron 0:3d641e170a74 67
julientiron 0:3d641e170a74 68 /**
julientiron 0:3d641e170a74 69 * @brief STM32F4xx NUCLEO BSP Driver version number V1.0.0
julientiron 0:3d641e170a74 70 */
julientiron 0:3d641e170a74 71 #define __STM32F4xx_NUCLEO_BSP_VERSION_MAIN (0x01) /*!< [31:24] main version */
julientiron 0:3d641e170a74 72 #define __STM32F4xx_NUCLEO_BSP_VERSION_SUB1 (0x00) /*!< [23:16] sub1 version */
julientiron 0:3d641e170a74 73 #define __STM32F4xx_NUCLEO_BSP_VERSION_SUB2 (0x00) /*!< [15:8] sub2 version */
julientiron 0:3d641e170a74 74 #define __STM32F4xx_NUCLEO_BSP_VERSION_RC (0x00) /*!< [7:0] release candidate */
julientiron 0:3d641e170a74 75 #define __STM32F4xx_NUCLEO_BSP_VERSION ((__STM32F4xx_NUCLEO_BSP_VERSION_MAIN << 24)\
julientiron 0:3d641e170a74 76 |(__STM32F4xx_NUCLEO_BSP_VERSION_SUB1 << 16)\
julientiron 0:3d641e170a74 77 |(__STM32F4xx_NUCLEO_BSP_VERSION_SUB2 << 8 )\
julientiron 0:3d641e170a74 78 |(__STM32F4xx_NUCLEO_BSP_VERSION_RC))
julientiron 0:3d641e170a74 79
julientiron 0:3d641e170a74 80 /**
julientiron 0:3d641e170a74 81 * @}
julientiron 0:3d641e170a74 82 */
julientiron 0:3d641e170a74 83
julientiron 0:3d641e170a74 84
julientiron 0:3d641e170a74 85 /** @defgroup STM32F4XX_NUCLEO_LOW_LEVEL_Private_Macros STM32F4XX_NUCLEO_LOW_LEVEL_Private_Macros
julientiron 0:3d641e170a74 86 * @{
julientiron 0:3d641e170a74 87 */
julientiron 0:3d641e170a74 88 /**
julientiron 0:3d641e170a74 89 * @}
julientiron 0:3d641e170a74 90 */
julientiron 0:3d641e170a74 91
julientiron 0:3d641e170a74 92
julientiron 0:3d641e170a74 93 /** @defgroup STM32F4XX_NUCLEO_LOW_LEVEL_Private_Variables STM32F4XX_NUCLEO_LOW_LEVEL_Private_Variables
julientiron 0:3d641e170a74 94 * @{
julientiron 0:3d641e170a74 95 */
julientiron 0:3d641e170a74 96 GPIO_TypeDef* GPIO_PORT[LEDn] = {LED2_GPIO_PORT};
julientiron 0:3d641e170a74 97 const uint16_t GPIO_PIN[LEDn] = {LED2_PIN};
julientiron 0:3d641e170a74 98
julientiron 0:3d641e170a74 99 GPIO_TypeDef* BUTTON_PORT[BUTTONn] = {KEY_BUTTON_GPIO_PORT };
julientiron 0:3d641e170a74 100 const uint16_t BUTTON_PIN[BUTTONn] = {KEY_BUTTON_PIN };
julientiron 0:3d641e170a74 101 const uint8_t BUTTON_IRQn[BUTTONn] = {KEY_BUTTON_EXTI_IRQn };
julientiron 0:3d641e170a74 102
julientiron 0:3d641e170a74 103 /**
julientiron 0:3d641e170a74 104 * @}
julientiron 0:3d641e170a74 105 */
julientiron 0:3d641e170a74 106
julientiron 0:3d641e170a74 107
julientiron 0:3d641e170a74 108 /** @defgroup STM32F4XX_NUCLEO_LOW_LEVEL_Private_FunctionPrototypes STM32F4XX_NUCLEO_LOW_LEVEL_Private_FunctionPrototypes
julientiron 0:3d641e170a74 109 * @{
julientiron 0:3d641e170a74 110 */
julientiron 0:3d641e170a74 111
julientiron 0:3d641e170a74 112 /**
julientiron 0:3d641e170a74 113 * @}
julientiron 0:3d641e170a74 114 */
julientiron 0:3d641e170a74 115
julientiron 0:3d641e170a74 116 /** @defgroup STM32F4XX_NUCLEO_LOW_LEVEL_Private_Functions STM32F4XX_NUCLEO_LOW_LEVEL_Private_Functions
julientiron 0:3d641e170a74 117 * @{
julientiron 0:3d641e170a74 118 */
julientiron 0:3d641e170a74 119
julientiron 0:3d641e170a74 120 /**
julientiron 0:3d641e170a74 121 * @brief This method returns the STM32F4xx NUCLEO BSP Driver revision
julientiron 0:3d641e170a74 122 * @param None
julientiron 0:3d641e170a74 123 * @retval version : 0xXYZR (8bits for each decimal, R for RC)
julientiron 0:3d641e170a74 124 */
julientiron 0:3d641e170a74 125 uint32_t BSP_GetVersion(void)
julientiron 0:3d641e170a74 126 {
julientiron 0:3d641e170a74 127 return __STM32F4xx_NUCLEO_BSP_VERSION;
julientiron 0:3d641e170a74 128 }
julientiron 0:3d641e170a74 129
julientiron 0:3d641e170a74 130 /**
julientiron 0:3d641e170a74 131 * @brief Configures LED GPIO.
julientiron 0:3d641e170a74 132 * @param Led: Specifies the Led to be configured.
julientiron 0:3d641e170a74 133 * This parameter can be one of following parameters:
julientiron 0:3d641e170a74 134 * @arg LED2
julientiron 0:3d641e170a74 135 * @retval None
julientiron 0:3d641e170a74 136 */
julientiron 0:3d641e170a74 137 void BSP_LED_Init(Led_TypeDef Led)
julientiron 0:3d641e170a74 138 {
julientiron 0:3d641e170a74 139 GPIO_InitTypeDef GPIO_InitStruct;
julientiron 0:3d641e170a74 140
julientiron 0:3d641e170a74 141 /* Enable the GPIO_LED Clock */
julientiron 0:3d641e170a74 142 LEDx_GPIO_CLK_ENABLE(Led);
julientiron 0:3d641e170a74 143
julientiron 0:3d641e170a74 144 /* Configure the GPIO_LED pin */
julientiron 0:3d641e170a74 145 GPIO_InitStruct.Pin = GPIO_PIN[Led];
julientiron 0:3d641e170a74 146 GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
julientiron 0:3d641e170a74 147 GPIO_InitStruct.Pull = GPIO_PULLUP;
julientiron 0:3d641e170a74 148 GPIO_InitStruct.Speed = GPIO_SPEED_FAST;
julientiron 0:3d641e170a74 149
julientiron 0:3d641e170a74 150 HAL_GPIO_Init(GPIO_PORT[Led], &GPIO_InitStruct);
julientiron 0:3d641e170a74 151
julientiron 0:3d641e170a74 152 HAL_GPIO_WritePin(GPIO_PORT[Led], GPIO_PIN[Led], GPIO_PIN_RESET);
julientiron 0:3d641e170a74 153 }
julientiron 0:3d641e170a74 154
julientiron 0:3d641e170a74 155 /**
julientiron 0:3d641e170a74 156 * @brief Turns selected LED On.
julientiron 0:3d641e170a74 157 * @param Led: Specifies the Led to be set on.
julientiron 0:3d641e170a74 158 * This parameter can be one of following parameters:
julientiron 0:3d641e170a74 159 * @arg LED2
julientiron 0:3d641e170a74 160 * @retval None
julientiron 0:3d641e170a74 161 */
julientiron 0:3d641e170a74 162 void BSP_LED_On(Led_TypeDef Led)
julientiron 0:3d641e170a74 163 {
julientiron 0:3d641e170a74 164 HAL_GPIO_WritePin(GPIO_PORT[Led], GPIO_PIN[Led], GPIO_PIN_RESET);
julientiron 0:3d641e170a74 165 }
julientiron 0:3d641e170a74 166
julientiron 0:3d641e170a74 167 /**
julientiron 0:3d641e170a74 168 * @brief Turns selected LED Off.
julientiron 0:3d641e170a74 169 * @param Led: Specifies the Led to be set off.
julientiron 0:3d641e170a74 170 * This parameter can be one of following parameters:
julientiron 0:3d641e170a74 171 * @arg LED2
julientiron 0:3d641e170a74 172 * @retval None
julientiron 0:3d641e170a74 173 */
julientiron 0:3d641e170a74 174 void BSP_LED_Off(Led_TypeDef Led)
julientiron 0:3d641e170a74 175 {
julientiron 0:3d641e170a74 176 HAL_GPIO_WritePin(GPIO_PORT[Led], GPIO_PIN[Led], GPIO_PIN_SET);
julientiron 0:3d641e170a74 177 }
julientiron 0:3d641e170a74 178
julientiron 0:3d641e170a74 179 /**
julientiron 0:3d641e170a74 180 * @brief Toggles the selected LED.
julientiron 0:3d641e170a74 181 * @param Led: Specifies the Led to be toggled.
julientiron 0:3d641e170a74 182 * This parameter can be one of following parameters:
julientiron 0:3d641e170a74 183 * @arg LED2
julientiron 0:3d641e170a74 184 * @retval None
julientiron 0:3d641e170a74 185 */
julientiron 0:3d641e170a74 186 void BSP_LED_Toggle(Led_TypeDef Led)
julientiron 0:3d641e170a74 187 {
julientiron 0:3d641e170a74 188 HAL_GPIO_TogglePin(GPIO_PORT[Led], GPIO_PIN[Led]);
julientiron 0:3d641e170a74 189 }
julientiron 0:3d641e170a74 190
julientiron 0:3d641e170a74 191 /**
julientiron 0:3d641e170a74 192 * @brief Configures Button GPIO and EXTI Line.
julientiron 0:3d641e170a74 193 * @param Button: Specifies the Button to be configured.
julientiron 0:3d641e170a74 194 * This parameter should be: BUTTON_KEY
julientiron 0:3d641e170a74 195 * @param ButtonMode: Specifies Button mode.
julientiron 0:3d641e170a74 196 * This parameter can be one of following parameters:
julientiron 0:3d641e170a74 197 * @arg BUTTON_MODE_GPIO: Button will be used as simple IO
julientiron 0:3d641e170a74 198 * @arg BUTTON_MODE_EXTI: Button will be connected to EXTI line with interrupt
julientiron 0:3d641e170a74 199 * generation capability
julientiron 0:3d641e170a74 200 * @retval None
julientiron 0:3d641e170a74 201 */
julientiron 0:3d641e170a74 202 void BSP_PB_Init(Button_TypeDef Button, ButtonMode_TypeDef ButtonMode)
julientiron 0:3d641e170a74 203 {
julientiron 0:3d641e170a74 204 GPIO_InitTypeDef GPIO_InitStruct;
julientiron 0:3d641e170a74 205
julientiron 0:3d641e170a74 206 /* Enable the BUTTON Clock */
julientiron 0:3d641e170a74 207 BUTTONx_GPIO_CLK_ENABLE(Button);
julientiron 0:3d641e170a74 208 __SYSCFG_CLK_ENABLE();
julientiron 0:3d641e170a74 209
julientiron 0:3d641e170a74 210 if(ButtonMode == BUTTON_MODE_GPIO)
julientiron 0:3d641e170a74 211 {
julientiron 0:3d641e170a74 212 /* Configure Button pin as input */
julientiron 0:3d641e170a74 213 GPIO_InitStruct.Pin = BUTTON_PIN[Button];
julientiron 0:3d641e170a74 214 GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
julientiron 0:3d641e170a74 215 GPIO_InitStruct.Pull = GPIO_PULLDOWN;
julientiron 0:3d641e170a74 216 GPIO_InitStruct.Speed = GPIO_SPEED_FAST;
julientiron 0:3d641e170a74 217 HAL_GPIO_Init(BUTTON_PORT[Button], &GPIO_InitStruct);
julientiron 0:3d641e170a74 218 }
julientiron 0:3d641e170a74 219
julientiron 0:3d641e170a74 220 if(ButtonMode == BUTTON_MODE_EXTI)
julientiron 0:3d641e170a74 221 {
julientiron 0:3d641e170a74 222 /* Configure Button pin as input with External interrupt */
julientiron 0:3d641e170a74 223 GPIO_InitStruct.Pin = BUTTON_PIN[Button];
julientiron 0:3d641e170a74 224 GPIO_InitStruct.Pull = GPIO_NOPULL;
julientiron 0:3d641e170a74 225 GPIO_InitStruct.Mode = GPIO_MODE_IT_RISING;
julientiron 0:3d641e170a74 226 HAL_GPIO_Init(BUTTON_PORT[Button], &GPIO_InitStruct);
julientiron 0:3d641e170a74 227
julientiron 0:3d641e170a74 228 /* Enable and set Button EXTI Interrupt to the lowest priority */
julientiron 0:3d641e170a74 229 HAL_NVIC_SetPriority((IRQn_Type)(BUTTON_IRQn[Button]), 0x0F, 0x00);
julientiron 0:3d641e170a74 230 HAL_NVIC_EnableIRQ((IRQn_Type)(BUTTON_IRQn[Button]));
julientiron 0:3d641e170a74 231 }
julientiron 0:3d641e170a74 232 }
julientiron 0:3d641e170a74 233
julientiron 0:3d641e170a74 234 /**
julientiron 0:3d641e170a74 235 * @brief Returns the selected Button state.
julientiron 0:3d641e170a74 236 * @param Button: Specifies the Button to be checked.
julientiron 0:3d641e170a74 237 * This parameter should be: BUTTON_KEY
julientiron 0:3d641e170a74 238 * @retval The Button GPIO pin value.
julientiron 0:3d641e170a74 239 */
julientiron 0:3d641e170a74 240 uint32_t BSP_PB_GetState(Button_TypeDef Button)
julientiron 0:3d641e170a74 241 {
julientiron 0:3d641e170a74 242 return HAL_GPIO_ReadPin(BUTTON_PORT[Button], BUTTON_PIN[Button]);
julientiron 0:3d641e170a74 243 }
julientiron 0:3d641e170a74 244
julientiron 0:3d641e170a74 245
julientiron 0:3d641e170a74 246 /******************************************************************************
julientiron 0:3d641e170a74 247 BUS OPERATIONS
julientiron 0:3d641e170a74 248 *******************************************************************************/
julientiron 0:3d641e170a74 249
julientiron 0:3d641e170a74 250 /******************************************************************************
julientiron 0:3d641e170a74 251 LINK OPERATIONS
julientiron 0:3d641e170a74 252 *******************************************************************************/
julientiron 0:3d641e170a74 253
julientiron 0:3d641e170a74 254 /**
julientiron 0:3d641e170a74 255 * @}
julientiron 0:3d641e170a74 256 */
julientiron 0:3d641e170a74 257
julientiron 0:3d641e170a74 258 /**
julientiron 0:3d641e170a74 259 * @}
julientiron 0:3d641e170a74 260 */
julientiron 0:3d641e170a74 261
julientiron 0:3d641e170a74 262 /**
julientiron 0:3d641e170a74 263 * @}
julientiron 0:3d641e170a74 264 */
julientiron 0:3d641e170a74 265
julientiron 0:3d641e170a74 266 /**
julientiron 0:3d641e170a74 267 * @}
julientiron 0:3d641e170a74 268 */
julientiron 0:3d641e170a74 269
julientiron 0:3d641e170a74 270 /******************* (C) COPYRIGHT 2013 STMicroelectronics *****END OF FILE****/