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-F429ZI_LCDTS_demo_richard
Fork of BSP_DISCO_F429ZI by
stm32f429i_discovery_io.c
00001 /** 00002 ****************************************************************************** 00003 * @file stm32f429i_discovery_io.c 00004 * @author MCD Application Team 00005 * @brief This file provides a set of functions needed to manage the STMPE811 00006 * IO Expander device mounted on STM32F429I-Discovery Kit. 00007 ****************************************************************************** 00008 * @attention 00009 * 00010 * <h2><center>© COPYRIGHT(c) 2017 STMicroelectronics</center></h2> 00011 * 00012 * Redistribution and use in source and binary forms, with or without modification, 00013 * are permitted provided that the following conditions are met: 00014 * 1. Redistributions of source code must retain the above copyright notice, 00015 * this list of conditions and the following disclaimer. 00016 * 2. Redistributions in binary form must reproduce the above copyright notice, 00017 * this list of conditions and the following disclaimer in the documentation 00018 * and/or other materials provided with the distribution. 00019 * 3. Neither the name of STMicroelectronics nor the names of its contributors 00020 * may be used to endorse or promote products derived from this software 00021 * without specific prior written permission. 00022 * 00023 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 00024 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 00025 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 00026 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 00027 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 00028 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 00029 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 00030 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 00031 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 00032 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00033 * 00034 ****************************************************************************** 00035 */ 00036 00037 /* Includes ------------------------------------------------------------------*/ 00038 #include "stm32f429i_discovery_io.h" 00039 00040 /** @addtogroup BSP 00041 * @{ 00042 */ 00043 00044 /** @addtogroup STM32F429I_DISCOVERY 00045 * @{ 00046 */ 00047 00048 /** @defgroup STM32F429I_DISCOVERY_IO STM32F429I DISCOVERY IO 00049 * @{ 00050 */ 00051 00052 /** @defgroup STM32F429I_DISCOVERY_IO_Private_Types_Definitions STM32F429I DISCOVERY IO Private Types Definitions 00053 * @{ 00054 */ 00055 /** 00056 * @} 00057 */ 00058 00059 /** @defgroup STM32F429I_DISCOVERY_IO_Private_Defines STM32F429I DISCOVERY IO Private Defines 00060 * @{ 00061 */ 00062 /** 00063 * @} 00064 */ 00065 00066 /** @defgroup STM32F429I_DISCOVERY_IO_Private_Macros STM32F429I DISCOVERY IO Private Macros 00067 * @{ 00068 */ 00069 /** 00070 * @} 00071 */ 00072 00073 00074 /** @defgroup STM32F429I_DISCOVERY_IO_Private_Variables STM32F429I DISCOVERY IO Private Variables 00075 * @{ 00076 */ 00077 static IO_DrvTypeDef *IoDrv; 00078 00079 /** 00080 * @} 00081 */ 00082 00083 00084 /** @defgroup STM32F429I_DISCOVERY_IO_Private_Function_Prototypes STM32F429I DISCOVERY IO Private Function Prototypes 00085 * @{ 00086 */ 00087 /** 00088 * @} 00089 */ 00090 00091 /** @defgroup STM32F429I_DISCOVERY_IO_Private_Functions STM32F429I DISCOVERY IO Private Functions 00092 * @{ 00093 */ 00094 00095 /** 00096 * @brief Initializes and configures the IO functionalities and configures all 00097 * necessary hardware resources (GPIOs, clocks..). 00098 * @note BSP_IO_Init() is using HAL_Delay() function to ensure that stmpe811 00099 * IO Expander is correctly reset. HAL_Delay() function provides accurate 00100 * delay (in milliseconds) based on variable incremented in SysTick ISR. 00101 * This implies that if BSP_IO_Init() is called from a peripheral ISR process, 00102 * then the SysTick interrupt must have higher priority (numerically lower) 00103 * than the peripheral interrupt. Otherwise the caller ISR process will be blocked. 00104 * @retval IO_OK if all initializations done correctly. Other value if error. 00105 */ 00106 uint8_t BSP_IO_Init(void) 00107 { 00108 uint8_t ret = IO_ERROR; 00109 00110 /* Read ID and verify the IO expander is ready */ 00111 if(stmpe811_io_drv.ReadID(IO_I2C_ADDRESS) == STMPE811_ID) 00112 { 00113 /* Initialize the IO driver structure */ 00114 IoDrv = &stmpe811_io_drv; 00115 ret = IO_OK; 00116 } 00117 00118 if(ret == IO_OK) 00119 { 00120 IoDrv->Init(IO_I2C_ADDRESS); 00121 IoDrv->Start(IO_I2C_ADDRESS, IO_PIN_ALL); 00122 } 00123 return ret; 00124 } 00125 00126 /** 00127 * @brief Gets the selected pins IT status. 00128 * @param IoPin: The selected pins to check the status. 00129 * This parameter could be any combination of the IO pins. 00130 * @retval Status of IO Pin checked. 00131 */ 00132 uint8_t BSP_IO_ITGetStatus(uint16_t IoPin) 00133 { 00134 /* Return the IO Pin IT status */ 00135 return (IoDrv->ITStatus(IO_I2C_ADDRESS, IoPin)); 00136 } 00137 00138 /** 00139 * @brief Clears all the IO IT pending bits 00140 */ 00141 void BSP_IO_ITClear(void) 00142 { 00143 /* Clear all IO IT pending bits */ 00144 IoDrv->ClearIT(IO_I2C_ADDRESS, IO_PIN_ALL); 00145 } 00146 00147 /** 00148 * @brief Configures the IO pin(s) according to IO mode structure value. 00149 * @param IoPin: IO pin(s) to be configured. 00150 * This parameter could be any combination of the following values: 00151 * @arg STMPE811_PIN_x: where x can be from 0 to 7. 00152 * @param IoMode: The IO pin mode to configure, could be one of the following values: 00153 * @arg IO_MODE_INPUT 00154 * @arg IO_MODE_OUTPUT 00155 * @arg IO_MODE_IT_RISING_EDGE 00156 * @arg IO_MODE_IT_FALLING_EDGE 00157 * @arg IO_MODE_IT_LOW_LEVEL 00158 * @arg IO_MODE_IT_HIGH_LEVEL 00159 */ 00160 void BSP_IO_ConfigPin(uint16_t IoPin, IO_ModeTypedef IoMode) 00161 { 00162 /* Configure the selected IO pin(s) mode */ 00163 IoDrv->Config(IO_I2C_ADDRESS, IoPin, IoMode); 00164 } 00165 00166 /** 00167 * @brief Sets the selected pins state. 00168 * @param IoPin: The selected pins to write. 00169 * This parameter could be any combination of the IO pins. 00170 * @param PinState: the new pins state to write 00171 */ 00172 void BSP_IO_WritePin(uint16_t IoPin, uint8_t PinState) 00173 { 00174 /* Set the Pin state */ 00175 IoDrv->WritePin(IO_I2C_ADDRESS, IoPin, PinState); 00176 } 00177 00178 /** 00179 * @brief Gets the selected pins current state. 00180 * @param IoPin: The selected pins to read. 00181 * This parameter could be any combination of the IO pins. 00182 * @retval The current pins state 00183 */ 00184 uint16_t BSP_IO_ReadPin(uint16_t IoPin) 00185 { 00186 return(IoDrv->ReadPin(IO_I2C_ADDRESS, IoPin)); 00187 } 00188 00189 /** 00190 * @brief Toggles the selected pins state. 00191 * @param IoPin: The selected pins to toggle. 00192 * This parameter could be any combination of the IO pins. 00193 */ 00194 void BSP_IO_TogglePin(uint16_t IoPin) 00195 { 00196 /* Toggle the current pin state */ 00197 if(IoDrv->ReadPin(IO_I2C_ADDRESS, IoPin) == 1 /* Set */) 00198 { 00199 IoDrv->WritePin(IO_I2C_ADDRESS, IoPin, 0 /* Reset */); 00200 } 00201 else 00202 { 00203 IoDrv->WritePin(IO_I2C_ADDRESS, IoPin, 1 /* Set */); 00204 } 00205 } 00206 00207 /** 00208 * @} 00209 */ 00210 00211 /** 00212 * @} 00213 */ 00214 00215 /** 00216 * @} 00217 */ 00218 00219 /** 00220 * @} 00221 */ 00222 00223 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
Generated on Wed Jul 13 2022 02:15:15 by
