STM32L073Z_EVAL BSP User Manual: stm32l073z_eval_io.c Source File

STM32L073Z EVAL BSP Drivers

stm32l073z_eval_io.c
Go to the documentation of this file.
00001 /**
00002   ******************************************************************************
00003   * @file    stm32l073z_eval_io.c
00004   * @author  MCD Application Team
00005   * @brief   This file provides a set of functions needed to manage the IO pins
00006   *          on STM32L073Z-EVAL evaluation board.
00007   ******************************************************************************
00008   * @attention
00009   *
00010   * <h2><center>&copy; COPYRIGHT(c) 2016 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 /* File Info : -----------------------------------------------------------------
00038                                    User NOTES
00039 1. How To use this driver:
00040 --------------------------
00041    - This driver is used to drive the IO module of the STM32L073Z-EVAL evaluation
00042      board.
00043    - The MFXSTM32L152 IO expander device component driver must be included with this 
00044      driver in order to run the IO functionalities commanded by the IO expander 
00045      device mounted on the evaluation board.
00046 
00047 2. Driver description:
00048 ---------------------
00049   + Initialization steps:
00050      o Initialize the IO module using the BSP_IO_Init() function. This 
00051        function includes the MSP layer hardware resources initialization and the
00052        communication layer configuration to start the IO functionalities use.    
00053   
00054   + IO functionalities use
00055      o The IO pin mode is configured when calling the function BSP_IO_ConfigPin(), you 
00056        must specify the desired IO mode by choosing the "IO_ModeTypedef" parameter 
00057        predefined value.
00058      o If an IO pin is used in interrupt mode, the function BSP_IO_ITGetStatus() is 
00059        needed to get the interrupt status. To clear the IT pending bits, you should 
00060        call the function BSP_IO_ITClear() with specifying the IO pending bit to clear.
00061      o The IT is handled using the corresponding external interrupt IRQ handler,
00062        the user IT callback treatment is implemented on the same external interrupt
00063        callback.
00064      o To get/set an IO pin combination state you can use the functions 
00065        BSP_IO_ReadPin()/BSP_IO_WritePin() or the function BSP_IO_TogglePin() to toggle the pin 
00066        state.
00067  
00068 ------------------------------------------------------------------------------*/
00069 
00070 /* Includes ------------------------------------------------------------------*/
00071 #include "stm32l073z_eval_io.h"
00072 
00073 /** @addtogroup BSP
00074   * @{
00075   */
00076 
00077 /** @addtogroup STM32L073Z_EVAL
00078   * @{
00079   */ 
00080   
00081 /** @defgroup STM32L073Z_EVAL_IO
00082   * @{
00083   */   
00084 
00085 /** @defgroup STM32L073Z_EVAL_IO_Private_Types_Definitions
00086   * @{
00087   */ 
00088 /**
00089   * @}
00090   */ 
00091 
00092 /** @defgroup STM32L073Z_EVAL_IO_Private_Defines
00093   * @{
00094   */ 
00095 /**
00096   * @}
00097   */ 
00098 
00099 /** @defgroup STM32L073Z_EVAL_IO_Private_Macros
00100   * @{
00101   */ 
00102 /**
00103   * @}
00104   */ 
00105 
00106 /** @defgroup STM32L073Z_EVAL_IO_Private_Variables
00107   * @{
00108   */ 
00109 static IO_DrvTypeDef *io_driver;
00110 
00111 /**
00112   * @}
00113   */
00114 
00115 /** @defgroup STM32L073Z_EVAL_IO_Private_Function_Prototypes
00116   * @{
00117   */ 
00118 /**
00119   * @}
00120   */
00121 
00122 /** @defgroup STM32L073Z_EVAL_IO_Private_Functions
00123   * @{
00124   */ 
00125 
00126 /**
00127   * @brief  Initializes and configures the IO functionalities and configures all
00128   *         necessary hardware resources (GPIOs, clocks..).
00129   * @note   BSP_IO_Init() is using HAL_Delay() function to ensure that MFXSTM32L152
00130   *         IO Expander is correctly reset. HAL_Delay() function provides accurate
00131   *         delay (in milliseconds) based on variable incremented in SysTick ISR. 
00132   *         This implies that if BSP_IO_Init() is called from a peripheral ISR process,
00133   *         then the SysTick interrupt must have higher priority (numerically lower)
00134   *         than the peripheral interrupt. Otherwise the caller ISR process will be blocked.
00135   * @param  None
00136   * @retval IO_OK if all initializations are OK. Other value if error.
00137   */
00138 uint8_t BSP_IO_Init(void)
00139 {
00140   static uint8_t Is_MFX_Initialized = 0;
00141   uint8_t ret = IO_ERROR;
00142   uint8_t mfxstm32l152_id = 0;
00143   
00144   /* Read ID and verify the IO expander is ready */
00145   mfxstm32l152_id = mfxstm32l152_io_drv.ReadID(IO_I2C_ADDRESS);
00146   if((mfxstm32l152_id == MFXSTM32L152_ID_1) || (mfxstm32l152_id == MFXSTM32L152_ID_2))
00147   {
00148     /* Initialize the IO driver structure */
00149     ret = IO_OK;
00150   }
00151   
00152   if((ret == IO_OK) && (Is_MFX_Initialized == 0))
00153   {
00154     Is_MFX_Initialized = 1;
00155     io_driver = &mfxstm32l152_io_drv;
00156     io_driver->Init(IO_I2C_ADDRESS);
00157     io_driver->Start(IO_I2C_ADDRESS, IO_PIN_ALL);
00158   }
00159   return ret;
00160 }
00161 
00162 /**
00163   * @brief  Gets the selected pins IT status.
00164   * @param  IO_Pin: Selected pins to check the status. 
00165   *          This parameter can be any combination of the IO pins.  
00166   * @retval IO_OK if read status OK. Other value if error.
00167   */
00168 uint32_t BSP_IO_ITGetStatus(uint32_t IO_Pin)
00169 {
00170   /* Return the IO Pin IT status */
00171   return (io_driver->ITStatus(IO_I2C_ADDRESS, IO_Pin));
00172 }
00173 
00174 /**
00175   * @brief  Clears all the IO IT pending bits.
00176   * @param  None
00177   * @retval None
00178   */
00179 void BSP_IO_ITClear(void)
00180 {
00181   /* Clear all IO IT pending bits */
00182   io_driver->ClearIT(IO_I2C_ADDRESS, MFXSTM32L152_GPIO_PINS_ALL);
00183 }
00184 
00185 /**
00186   * @brief  Configures the IO pin(s) according to IO mode structure value.
00187   * @param  IO_Pin: IO pin(s) to be configured. 
00188   *          This parameter can be one of the following values:
00189   *            @arg  MFXSTM32L152_GPIO_PIN_x: where x can be from 0 to 23.
00190   * @param  IO_Mode: IO pin mode to configure
00191   *          This parameter can be one of the following values:
00192   *            @arg  IO_MODE_INPUT
00193   *            @arg  IO_MODE_INPUT
00194   *            @arg  IO_MODE_OUTPUT
00195   *            @arg  IO_MODE_IT_RISING_EDGE
00196   *            @arg  IO_MODE_IT_FALLING_EDGE
00197   *            @arg  IO_MODE_IT_LOW_LEVEL
00198   *            @arg  IO_MODE_IT_HIGH_LEVEL            
00199   *            @arg  IO_MODE_INPUT_PR_PU,
00200   *            @arg  IO_MODE_INPUT_PR_PD,
00201   *            @arg  IO_MODE_OUTPUT_OD_PU,
00202   *            @arg  IO_MODE_OUTPUT_OD_PD,
00203   *            @arg  IO_MODE_OUTPUT_PP_PU,
00204   *            @arg  IO_MODE_OUTPUT_PP_PD,
00205   *            @arg  IO_MODE_IT_RISING_EDGE_PU
00206   *            @arg  IO_MODE_IT_FALLING_EDGE_PU
00207   *            @arg  IO_MODE_IT_LOW_LEVEL_PU
00208   *            @arg  IO_MODE_IT_HIGH_LEVEL_PU
00209   *            @arg  IO_MODE_IT_RISING_EDGE_PD
00210   *            @arg  IO_MODE_IT_FALLING_EDGE_PD
00211   *            @arg  IO_MODE_IT_LOW_LEVEL_PD
00212   *            @arg  IO_MODE_IT_HIGH_LEVEL_PD
00213   * @retval IO_OK if all initializations are OK. Other value if error.  
00214   */
00215 uint8_t BSP_IO_ConfigPin(uint32_t IO_Pin, IO_ModeTypedef IO_Mode)
00216 {
00217   /* Configure the selected IO pin(s) mode */
00218   io_driver->Config(IO_I2C_ADDRESS, IO_Pin, IO_Mode);
00219   
00220   return IO_OK;  
00221 }
00222 
00223 /**
00224   * @brief  Sets the selected pins state.
00225   * @param  IO_Pin: Selected pins to write. 
00226   *          This parameter can be any combination of the IO pins. 
00227   * @param  PinState: New pins state to write  
00228   * @retval None
00229   */
00230 void BSP_IO_WritePin(uint32_t IO_Pin, uint8_t PinState)
00231 {
00232   /* Set the Pin state */
00233   io_driver->WritePin(IO_I2C_ADDRESS, IO_Pin, PinState);
00234 }
00235 
00236 /**
00237   * @brief  Gets the selected pins current state.
00238   * @param  IO_Pin: Selected pins to read. 
00239   *          This parameter can be any combination of the IO pins. 
00240   * @retval The current pins state 
00241   */
00242 uint32_t BSP_IO_ReadPin(uint32_t IO_Pin)
00243 {
00244  return(io_driver->ReadPin(IO_I2C_ADDRESS, IO_Pin));
00245 }
00246 
00247 /**
00248   * @brief  Toggles the selected pins state.
00249   * @param  IO_Pin: Selected pins to toggle. 
00250   *          This parameter can be any combination of the IO pins.  
00251   * @retval None
00252   */
00253 void BSP_IO_TogglePin(uint32_t IO_Pin)
00254 {
00255   /* Toggle the current pin state */
00256   if(io_driver->ReadPin(IO_I2C_ADDRESS, IO_Pin) == 1) /* Set */
00257   {
00258     io_driver->WritePin(IO_I2C_ADDRESS, IO_Pin, 0); /* Reset */
00259   }
00260   else
00261   {
00262     io_driver->WritePin(IO_I2C_ADDRESS, IO_Pin, 1); /* Set */
00263   } 
00264 }
00265 
00266 /**
00267   * @}
00268   */ 
00269 
00270 /**
00271   * @}
00272   */ 
00273 
00274 /**
00275   * @}
00276   */ 
00277 
00278 /**
00279   * @}
00280   */ 
00281 
00282 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
Generated on Mon Aug 28 2017 14:54:25 for STM32L073Z_EVAL BSP User Manual by   doxygen 1.7.6.1