STM32769I_EVAL BSP User Manual
|
stm32f769i_eval_io.c
Go to the documentation of this file.
00001 /** 00002 ****************************************************************************** 00003 * @file stm32f769i_eval_io.c 00004 * @author MCD Application Team 00005 * @version V2.0.1 00006 * @date 06-April-2017 00007 * @brief This file provides a set of functions needed to manage the IO pins 00008 * on STM32F769I-EVAL evaluation board. 00009 @verbatim 00010 How To use this driver: 00011 ----------------------- 00012 - This driver is used to drive the IO module of the STM32F769I-EVAL evaluation 00013 board. 00014 - The MFXSTM32L152 IO expander device component driver must be included with this 00015 driver in order to run the IO functionalities commanded by the IO expander (MFX) 00016 device mounted on the evaluation board. 00017 00018 Driver description: 00019 ------------------- 00020 + Initialization steps: 00021 o Initialize the IO module using the BSP_IO_Init() function. This 00022 function includes the MSP layer hardware resources initialization and the 00023 communication layer configuration to start the IO functionalities use. 00024 00025 + IO functionalities use 00026 o The IO pin mode is configured when calling the function BSP_IO_ConfigPin(), you 00027 must specify the desired IO mode by choosing the "IO_ModeTypedef" parameter 00028 predefined value. 00029 o If an IO pin is used in interrupt mode, the function BSP_IO_ITGetStatus() is 00030 needed to get the interrupt status. To clear the IT pending bits, you should 00031 call the function BSP_IO_ITClear() with specifying the IO pending bit to clear. 00032 o The IT is handled using the corresponding external interrupt IRQ handler, 00033 the user IT callback treatment is implemented on the same external interrupt 00034 callback. 00035 o The IRQ_OUT pin (common for all functionalities: JOY, SD, LEDs, etc) can be 00036 configured using the function BSP_IO_ConfigIrqOutPin() 00037 o To get/set an IO pin combination state you can use the functions 00038 BSP_IO_ReadPin()/BSP_IO_WritePin() or the function BSP_IO_TogglePin() to toggle the pin 00039 state. 00040 @endverbatim 00041 ****************************************************************************** 00042 * @attention 00043 * 00044 * <h2><center>© COPYRIGHT(c) 2017 STMicroelectronics</center></h2> 00045 * 00046 * Redistribution and use in source and binary forms, with or without modification, 00047 * are permitted provided that the following conditions are met: 00048 * 1. Redistributions of source code must retain the above copyright notice, 00049 * this list of conditions and the following disclaimer. 00050 * 2. Redistributions in binary form must reproduce the above copyright notice, 00051 * this list of conditions and the following disclaimer in the documentation 00052 * and/or other materials provided with the distribution. 00053 * 3. Neither the name of STMicroelectronics nor the names of its contributors 00054 * may be used to endorse or promote products derived from this software 00055 * without specific prior written permission. 00056 * 00057 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 00058 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 00059 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 00060 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 00061 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 00062 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 00063 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 00064 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 00065 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 00066 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00067 * 00068 ****************************************************************************** 00069 */ 00070 00071 /* Dependencies 00072 - stm32f769i_eval.h 00073 - mfxstm32l152.c 00074 EndDependencies */ 00075 00076 /* Includes ------------------------------------------------------------------*/ 00077 #include "stm32f769i_eval_io.h" 00078 00079 /** @addtogroup BSP 00080 * @{ 00081 */ 00082 00083 /** @addtogroup STM32F769I_EVAL 00084 * @{ 00085 */ 00086 00087 /** @defgroup STM32F769I_EVAL_IO STM32F769I_EVAL IO 00088 * @{ 00089 */ 00090 00091 /** @defgroup STM32F769I_EVAL_IO_Private_Types_Definitions IO Private Types Definitions 00092 * @{ 00093 */ 00094 /** 00095 * @} 00096 */ 00097 00098 /** @defgroup STM32F769I_EVAL_IO_Private_Defines IO Private Defines 00099 * @{ 00100 */ 00101 /** 00102 * @} 00103 */ 00104 00105 /** @defgroup STM32F769I_EVAL_IO_Private_Macros IO Private Macros 00106 * @{ 00107 */ 00108 /** 00109 * @} 00110 */ 00111 00112 /** @defgroup STM32F769I_EVAL_IO_Private_Variables IO Private Variables 00113 * @{ 00114 */ 00115 static IO_DrvTypeDef *IoDrv = NULL; 00116 static uint8_t mfxstm32l152Identifier; 00117 00118 /** 00119 * @} 00120 */ 00121 00122 /** @defgroup STM32F769I_EVAL_IO_Private_Functions_Prototypes IO Private Functions Prototypes 00123 * @{ 00124 */ 00125 /** 00126 * @} 00127 */ 00128 00129 /** @defgroup STM32F769I_EVAL_IO_Private_Functions IO Private Functions 00130 * @{ 00131 */ 00132 00133 /** 00134 * @brief Initializes and configures the IO functionalities and configures all 00135 * necessary hardware resources (MFX, ...). 00136 * @note BSP_IO_Init() is using HAL_Delay() function to ensure that MFXSTM32L152 00137 * IO Expander is correctly reset. HAL_Delay() function provides accurate 00138 * delay (in milliseconds) based on variable incremented in SysTick ISR. 00139 * This implies that if BSP_IO_Init() is called from a peripheral ISR process, 00140 * then the SysTick interrupt must have higher priority (numerically lower) 00141 * than the peripheral interrupt. Otherwise the caller ISR process will be blocked. 00142 * @retval IO_OK if all initializations are OK. Other value if error. 00143 */ 00144 uint8_t BSP_IO_Init(void) 00145 { 00146 uint8_t ret = IO_OK; 00147 00148 if (IoDrv == NULL) /* Checks if MFX initialization never done */ 00149 { 00150 /* Read ID and verify the MFX is ready */ 00151 mfxstm32l152Identifier = mfxstm32l152_io_drv.ReadID(IO_I2C_ADDRESS); 00152 if((mfxstm32l152Identifier == MFXSTM32L152_ID_1) || (mfxstm32l152Identifier == MFXSTM32L152_ID_2)) 00153 { 00154 /* Initialize the IO driver structure */ 00155 IoDrv = &mfxstm32l152_io_drv; 00156 00157 /* Initialize MFX */ 00158 IoDrv->Init(IO_I2C_ADDRESS); 00159 IoDrv->Start(IO_I2C_ADDRESS, IO_PIN_ALL); 00160 } 00161 else 00162 { 00163 ret = IO_ERROR; 00164 } 00165 } 00166 else 00167 { 00168 /* MFX initialization already done : do nothing */ 00169 } 00170 00171 return ret; 00172 } 00173 00174 /** 00175 * @brief DeInit allows Mfx Initialization to be executed again 00176 * @note BSP_IO_Init() has no effect if the IoDrv is already initialized 00177 * BSP_IO_DeInit() allows to erase the pointer such to allow init to be effective 00178 * @retval IO_OK 00179 */ 00180 uint8_t BSP_IO_DeInit(void) 00181 { 00182 IoDrv = NULL; 00183 return IO_OK; 00184 } 00185 00186 /** 00187 * @brief Gets the selected pins IT status. 00188 * @param IoPin: Selected pins to check the status. 00189 * This parameter can be any combination of the IO pins. 00190 * @retval IO_OK if read status OK. Other value if error. 00191 */ 00192 uint32_t BSP_IO_ITGetStatus(uint32_t IoPin) 00193 { 00194 /* Return the IO Pin IT status */ 00195 return (IoDrv->ITStatus(IO_I2C_ADDRESS, IoPin)); 00196 } 00197 00198 /** 00199 * @brief Clears all the IO IT pending bits. 00200 * @retval None 00201 */ 00202 void BSP_IO_ITClear(void) 00203 { 00204 /* Clear all IO IT pending bits */ 00205 IoDrv->ClearIT(IO_I2C_ADDRESS, MFXSTM32L152_GPIO_PINS_ALL); 00206 } 00207 00208 /** 00209 * @brief Clear only one or a selection of IO IT pending bits. 00210 * @param IO_Pins_To_Clear : MFX IRQ status IO pin to clear (or combination of several IOs) 00211 */ 00212 void BSP_IO_ITClearPin(uint32_t IO_Pins_To_Clear) 00213 { 00214 /* Clear only the selected list of IO IT pending bits */ 00215 IoDrv->ClearIT(IO_I2C_ADDRESS, IO_Pins_To_Clear); 00216 } 00217 00218 /** 00219 * @brief Configures the IO pin(s) according to IO mode structure value. 00220 * @param IoPin: IO pin(s) to be configured. 00221 * This parameter can be one of the following values: 00222 * @arg MFXSTM32L152_GPIO_PIN_x: where x can be from 0 to 23. 00223 * @param IoMode: IO pin mode to configure 00224 * This parameter can be one of the following values: 00225 * @arg IO_MODE_INPUT 00226 * @arg IO_MODE_OUTPUT 00227 * @arg IO_MODE_IT_RISING_EDGE 00228 * @arg IO_MODE_IT_FALLING_EDGE 00229 * @arg IO_MODE_IT_LOW_LEVEL 00230 * @arg IO_MODE_IT_HIGH_LEVEL 00231 * @arg IO_MODE_ANALOG 00232 * @arg IO_MODE_OFF 00233 * @arg IO_MODE_INPUT_PU, 00234 * @arg IO_MODE_INPUT_PD, 00235 * @arg IO_MODE_OUTPUT_OD, 00236 * @arg IO_MODE_OUTPUT_OD_PU, 00237 * @arg IO_MODE_OUTPUT_OD_PD, 00238 * @arg IO_MODE_OUTPUT_PP, 00239 * @arg IO_MODE_OUTPUT_PP_PU, 00240 * @arg IO_MODE_OUTPUT_PP_PD, 00241 * @arg IO_MODE_IT_RISING_EDGE_PU 00242 * @arg IO_MODE_IT_FALLING_EDGE_PU 00243 * @arg IO_MODE_IT_LOW_LEVEL_PU 00244 * @arg IO_MODE_IT_HIGH_LEVEL_PU 00245 * @arg IO_MODE_IT_RISING_EDGE_PD 00246 * @arg IO_MODE_IT_FALLING_EDGE_PD 00247 * @arg IO_MODE_IT_LOW_LEVEL_PD 00248 * @arg IO_MODE_IT_HIGH_LEVEL_PD 00249 * @retval IO_OK if all initializations are OK. Other value if error. 00250 */ 00251 uint8_t BSP_IO_ConfigPin(uint32_t IoPin, IO_ModeTypedef IoMode) 00252 { 00253 /* Configure the selected IO pin(s) mode */ 00254 IoDrv->Config(IO_I2C_ADDRESS, IoPin, IoMode); 00255 00256 return IO_OK; 00257 } 00258 00259 /** 00260 * @brief Sets the IRQ_OUT pin polarity and type 00261 * @param IoIrqOutPinPolarity: High/Low 00262 * @param IoIrqOutPinType: OpenDrain/PushPull 00263 * @retval OK 00264 */ 00265 uint8_t BSP_IO_ConfigIrqOutPin(uint8_t IoIrqOutPinPolarity, uint8_t IoIrqOutPinType) 00266 { 00267 if((mfxstm32l152Identifier == MFXSTM32L152_ID_1) || (mfxstm32l152Identifier == MFXSTM32L152_ID_2)) 00268 { 00269 /* Initialize the IO driver structure */ 00270 mfxstm32l152_SetIrqOutPinPolarity(IO_I2C_ADDRESS, IoIrqOutPinPolarity); 00271 mfxstm32l152_SetIrqOutPinType(IO_I2C_ADDRESS, IoIrqOutPinType); 00272 } 00273 00274 return IO_OK; 00275 } 00276 00277 /** 00278 * @brief Sets the selected pins state. 00279 * @param IoPin: Selected pins to write. 00280 * This parameter can be any combination of the IO pins. 00281 * @param PinState: New pins state to write 00282 * @retval None 00283 */ 00284 void BSP_IO_WritePin(uint32_t IoPin, BSP_IO_PinStateTypeDef PinState) 00285 { 00286 /* Set the Pin state */ 00287 IoDrv->WritePin(IO_I2C_ADDRESS, IoPin, PinState); 00288 } 00289 00290 /** 00291 * @brief Gets the selected pins current state. 00292 * @param IoPin: Selected pins to read. 00293 * This parameter can be any combination of the IO pins. 00294 * @retval The current pins state 00295 */ 00296 uint32_t BSP_IO_ReadPin(uint32_t IoPin) 00297 { 00298 return(IoDrv->ReadPin(IO_I2C_ADDRESS, IoPin)); 00299 } 00300 00301 /** 00302 * @brief Toggles the selected pins state. 00303 * @param IoPin: Selected pins to toggle. 00304 * This parameter can be any combination of the IO pins. 00305 * @note This function is only used to toggle one pin in the same time 00306 * @retval None 00307 */ 00308 void BSP_IO_TogglePin(uint32_t IoPin) 00309 { 00310 /* Toggle the current pin state */ 00311 if(IoDrv->ReadPin(IO_I2C_ADDRESS, IoPin) != 0) /* Set */ 00312 { 00313 IoDrv->WritePin(IO_I2C_ADDRESS, IoPin, 0); /* Reset */ 00314 } 00315 else 00316 { 00317 IoDrv->WritePin(IO_I2C_ADDRESS, IoPin, 1); /* Set */ 00318 } 00319 } 00320 00321 /** 00322 * @} 00323 */ 00324 00325 /** 00326 * @} 00327 */ 00328 00329 /** 00330 * @} 00331 */ 00332 00333 /** 00334 * @} 00335 */ 00336 00337 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
Generated on Thu May 25 2017 11:03:11 for STM32769I_EVAL BSP User Manual by 1.7.6.1