Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: DISCO_L4R9I-LCD-demo
stm32l4r9i_discovery_io.c
00001 /** 00002 ****************************************************************************** 00003 * @file stm32l4r9i_discovery_io.c 00004 * @author MCD Application Team 00005 * @brief This file provides a set of functions needed to manage the IO pins 00006 * on STM32L4R9I_DISCOVERY discovery board. 00007 ****************************************************************************** 00008 * @attention 00009 * 00010 * <h2><center>© Copyright (c) 2017 STMicroelectronics. 00011 * All rights reserved.</center></h2> 00012 * 00013 * This software component is licensed by ST under BSD 3-Clause license, 00014 * the "License"; You may not use this file except in compliance with the 00015 * License. You may obtain a copy of the License at: 00016 * opensource.org/licenses/BSD-3-Clause 00017 * 00018 ****************************************************************************** 00019 */ 00020 00021 /* File Info : ----------------------------------------------------------------- 00022 User NOTES 00023 1. How To use this driver: 00024 -------------------------- 00025 - This driver is used to drive the IO module of the STM32L4R9I_DISCOVERY 00026 board. 00027 - The MFXSTM32L152 IO expander device component driver must be included with this 00028 driver in order to run the IO functionalities commanded by the IO expander 00029 device mounted on the discovery board. 00030 00031 2. Driver description: 00032 --------------------- 00033 + Initialization steps: 00034 o Initialize the IO module using the BSP_IO_Init() function. This 00035 function includes the MSP layer hardware resources initialization and the 00036 communication layer configuration to start the IO functionalities use. 00037 00038 + IO functionalities use 00039 o The IO pin mode is configured when calling the function BSP_IO_ConfigPin(), you 00040 must specify the desired IO mode by choosing the "IO_ModeTypedef" parameter 00041 predefined value. 00042 o If an IO pin is used in interrupt mode, the function BSP_IO_ITGetStatus() is 00043 needed to get the interrupt status. To clear the IT pending bits, you should 00044 call the function BSP_IO_ITClear() with specifying the IO pending bit to clear. 00045 o The IT is handled using the corresponding external interrupt IRQ handler, 00046 the user IT callback treatment is implemented on the same external interrupt 00047 callback. 00048 o To get/set an IO pin combination state you can use the functions 00049 BSP_IO_ReadPin()/BSP_IO_WritePin() or the function BSP_IO_TogglePin() to toggle the pin 00050 state. 00051 00052 ------------------------------------------------------------------------------*/ 00053 00054 /* Includes ------------------------------------------------------------------*/ 00055 #include "stm32l4r9i_discovery_io.h" 00056 00057 /** @addtogroup BSP 00058 * @{ 00059 */ 00060 00061 /** @addtogroup STM32L4R9I_DISCOVERY 00062 * @{ 00063 */ 00064 00065 /** @defgroup STM32L4R9I_DISCOVERY_IO STM32L4R9I_DISCOVERY IO 00066 * @{ 00067 */ 00068 00069 /* Private variables ---------------------------------------------------------*/ 00070 00071 /** @defgroup STM32L4R9I_DISCOVERY_IO_Private_Variables Private Variables 00072 * @{ 00073 */ 00074 static IO_DrvTypeDef *io_driver; 00075 00076 /** 00077 * @} 00078 */ 00079 00080 /* Exported functions --------------------------------------------------------*/ 00081 00082 /** @addtogroup STM32L4R9I_DISCOVERY_IO_Exported_Functions 00083 * @{ 00084 */ 00085 00086 /** 00087 * @brief Initialize and configure the IO functionalities and configures all 00088 * necessary hardware resources (GPIOs, clocks..). 00089 * @note BSP_IO_Init() is using HAL_Delay() function to ensure that stmpe811 00090 * IO Expander is correctly reset. HAL_Delay() function provides accurate 00091 * delay (in milliseconds) based on variable incremented in SysTick ISR. 00092 * This implies that if BSP_IO_Init() is called from a peripheral ISR process, 00093 * then the SysTick interrupt must have higher priority (numerically lower) 00094 * than the peripheral interrupt. Otherwise the caller ISR process will be blocked. 00095 * @retval IO_OK: if all initializations are OK. Other value if error. 00096 */ 00097 uint8_t BSP_IO_Init(void) 00098 { 00099 uint8_t ret = IO_OK; 00100 uint8_t mfxstm32l152_id = 0; 00101 00102 if (io_driver == NULL) /* Checks if MFX initialization has been already done */ 00103 { 00104 mfxstm32l152_idd_drv.WakeUp(IO_I2C_ADDRESS); 00105 00106 HAL_Delay(10); 00107 00108 /* Read ID and verify the IO expander is ready */ 00109 mfxstm32l152_id = mfxstm32l152_io_drv.ReadID(IO_I2C_ADDRESS); 00110 00111 if((mfxstm32l152_id == MFXSTM32L152_ID_1) || (mfxstm32l152_id == MFXSTM32L152_ID_2)) 00112 { 00113 /* Initialize the MFX */ 00114 io_driver = &mfxstm32l152_io_drv; 00115 00116 /* Initialize the MFX IO driver structure */ 00117 if(io_driver->Init != NULL) 00118 { 00119 io_driver->Init(IO_I2C_ADDRESS); 00120 io_driver->Start(IO_I2C_ADDRESS, IO_PIN_ALL); 00121 } 00122 else 00123 { 00124 ret = IO_ERROR; 00125 } 00126 } 00127 else 00128 { 00129 ret = IO_ERROR; 00130 } 00131 } 00132 else 00133 { 00134 /* MFX initialization already done : do nothing */ 00135 } 00136 00137 return ret; 00138 } 00139 00140 /** 00141 * @brief DeInitialize the IO to allow Mfx Initialization to be executed again 00142 * @note BSP_IO_Init() has no effect if the io_driver is already initialized 00143 * BSP_IO_DeInit() allows to erase the pointer such to allow init to be effective 00144 * @retval IO_OK 00145 */ 00146 uint8_t BSP_IO_DeInit(void) 00147 { 00148 io_driver = NULL; 00149 return IO_OK; 00150 } 00151 00152 /** 00153 * @brief Get the selected pins IT status. 00154 * @param IO_Pin: Selected pin(s) to check the status. 00155 * This parameter can be any combination of the IO pins. 00156 * @retval Status of the checked IO pin(s). 00157 */ 00158 uint32_t BSP_IO_ITGetStatus(uint32_t IO_Pin) 00159 { 00160 /* Return the IO Pin IT status */ 00161 return (io_driver->ITStatus(IO_I2C_ADDRESS, IO_Pin)); 00162 } 00163 00164 /** 00165 * @brief Clear the selected IO IT pending bit. 00166 * @param IO_Pin: Selected pin(s) to clear the status. 00167 * This parameter can be any combination of the IO pins. 00168 * @retval None 00169 */ 00170 void BSP_IO_ITClear(uint32_t IO_Pin) 00171 { 00172 /* Clear the selected IO IT pending bits */ 00173 io_driver->ClearIT(IO_I2C_ADDRESS, IO_Pin); 00174 } 00175 00176 /** 00177 * @brief Configure the IO pin(s) according to IO mode structure value. 00178 * @param IO_Pin: Output IO pin(s) to be set or reset. 00179 * This parameter can be any combination of the IO pin(s). 00180 * @param IO_Mode: IO pin mode to configure 00181 * This parameter can be one of the following values: 00182 * @arg IO_MODE_INPUT 00183 * @arg IO_MODE_OUTPUT 00184 * @arg IO_MODE_IT_RISING_EDGE 00185 * @arg IO_MODE_IT_FALLING_EDGE 00186 * @arg IO_MODE_IT_LOW_LEVEL 00187 * @arg IO_MODE_IT_HIGH_LEVEL 00188 * @retval IO_OK: if all initializations are OK. Other value if error. 00189 */ 00190 uint8_t BSP_IO_ConfigPin(uint32_t IO_Pin, IO_ModeTypedef IO_Mode) 00191 { 00192 /* Configure the selected IO pin(s) mode */ 00193 io_driver->Config(IO_I2C_ADDRESS, IO_Pin, IO_Mode); 00194 00195 return IO_OK; 00196 } 00197 00198 /** 00199 * @brief Set the selected IO pin(s) state. 00200 * @param IO_Pin: Selected IO pin(s) to write. 00201 * This parameter can be any combination of the IO pin(s). 00202 * @param PinState: New pin state to write 00203 * @retval None 00204 */ 00205 void BSP_IO_WritePin(uint32_t IO_Pin, uint8_t PinState) 00206 { 00207 /* Set the IO pin(s) state */ 00208 io_driver->WritePin(IO_I2C_ADDRESS, IO_Pin, PinState); 00209 } 00210 00211 /** 00212 * @brief Get the selected IO pin(s) current state. 00213 * @param IO_Pin: Selected pin(s) to read. 00214 * This parameter can be any combination of the IO pin(s). 00215 * @retval The current pins state 00216 */ 00217 uint32_t BSP_IO_ReadPin(uint32_t IO_Pin) 00218 { 00219 return(io_driver->ReadPin(IO_I2C_ADDRESS, IO_Pin)); 00220 } 00221 00222 /** 00223 * @brief Toggle the selected IO pin(s) state 00224 * @param IO_Pin: Selected IO pin(s) to toggle. 00225 * This parameter can be any combination of the IO pin(s). 00226 * @retval None 00227 */ 00228 void BSP_IO_TogglePin(uint32_t IO_Pin) 00229 { 00230 /* Toggle the IO selected pin(s) state */ 00231 if(io_driver->ReadPin(IO_I2C_ADDRESS, IO_Pin) != 0) /* Set */ 00232 { 00233 io_driver->WritePin(IO_I2C_ADDRESS, IO_Pin, 0); /* Reset */ 00234 } 00235 else 00236 { 00237 io_driver->WritePin(IO_I2C_ADDRESS, IO_Pin, 1); /* Set */ 00238 } 00239 } 00240 00241 /** 00242 * @} 00243 */ 00244 00245 /** 00246 * @} 00247 */ 00248 00249 /** 00250 * @} 00251 */ 00252 00253 /** 00254 * @} 00255 */ 00256 00257 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
Generated on Wed Jul 13 2022 19:15:17 by
