STM32F479xx HAL User Manual
stm32f4xx_ll_fmpi2c.c
Go to the documentation of this file.
00001 /**
00002   ******************************************************************************
00003   * @file    stm32f4xx_ll_fmpi2c.c
00004   * @author  MCD Application Team
00005   * @brief   FMPI2C LL module driver.
00006   ******************************************************************************
00007   * @attention
00008   *
00009   * <h2><center>&copy; Copyright (c) 2016 STMicroelectronics.
00010   * All rights reserved.</center></h2>
00011   *
00012   * This software component is licensed by ST under BSD 3-Clause license,
00013   * the "License"; You may not use this file except in compliance with the
00014   * License. You may obtain a copy of the License at:
00015   *                        opensource.org/licenses/BSD-3-Clause
00016   *
00017   ******************************************************************************
00018   */
00019 #if defined(USE_FULL_LL_DRIVER)
00020 
00021 #if defined(FMPI2C_CR1_PE)
00022 /* Includes ------------------------------------------------------------------*/
00023 #include "stm32f4xx_ll_fmpi2c.h"
00024 #include "stm32f4xx_ll_bus.h"
00025 #ifdef  USE_FULL_ASSERT
00026 #include "stm32_assert.h"
00027 #else
00028 #define assert_param(expr) ((void)0U)
00029 #endif /* USE_FULL_ASSERT */
00030 
00031 /** @addtogroup STM32F4xx_LL_Driver
00032   * @{
00033   */
00034 
00035 #if defined (FMPI2C1)
00036 
00037 /** @defgroup FMPI2C_LL FMPI2C
00038   * @{
00039   */
00040 
00041 /* Private types -------------------------------------------------------------*/
00042 /* Private variables ---------------------------------------------------------*/
00043 /* Private constants ---------------------------------------------------------*/
00044 /* Private macros ------------------------------------------------------------*/
00045 /** @addtogroup FMPI2C_LL_Private_Macros
00046   * @{
00047   */
00048 
00049 #define IS_LL_FMPI2C_PERIPHERAL_MODE(__VALUE__)    (((__VALUE__) == LL_FMPI2C_MODE_I2C)          || \
00050                                                  ((__VALUE__) == LL_FMPI2C_MODE_SMBUS_HOST)   || \
00051                                                  ((__VALUE__) == LL_FMPI2C_MODE_SMBUS_DEVICE) || \
00052                                                  ((__VALUE__) == LL_FMPI2C_MODE_SMBUS_DEVICE_ARP))
00053 
00054 #define IS_LL_FMPI2C_ANALOG_FILTER(__VALUE__)      (((__VALUE__) == LL_FMPI2C_ANALOGFILTER_ENABLE) || \
00055                                                  ((__VALUE__) == LL_FMPI2C_ANALOGFILTER_DISABLE))
00056 
00057 #define IS_LL_FMPI2C_DIGITAL_FILTER(__VALUE__)     ((__VALUE__) <= 0x0000000FU)
00058 
00059 #define IS_LL_FMPI2C_OWN_ADDRESS1(__VALUE__)       ((__VALUE__) <= 0x000003FFU)
00060 
00061 #define IS_LL_FMPI2C_TYPE_ACKNOWLEDGE(__VALUE__)   (((__VALUE__) == LL_FMPI2C_ACK) || \
00062                                                  ((__VALUE__) == LL_FMPI2C_NACK))
00063 
00064 #define IS_LL_FMPI2C_OWN_ADDRSIZE(__VALUE__)       (((__VALUE__) == LL_FMPI2C_OWNADDRESS1_7BIT) || \
00065                                                  ((__VALUE__) == LL_FMPI2C_OWNADDRESS1_10BIT))
00066 /**
00067   * @}
00068   */
00069 
00070 /* Private function prototypes -----------------------------------------------*/
00071 
00072 /* Exported functions --------------------------------------------------------*/
00073 /** @addtogroup FMPI2C_LL_Exported_Functions
00074   * @{
00075   */
00076 
00077 /** @addtogroup FMPI2C_LL_EF_Init
00078   * @{
00079   */
00080 
00081 /**
00082   * @brief  De-initialize the FMPI2C registers to their default reset values.
00083   * @param  FMPI2Cx FMPI2C Instance.
00084   * @retval An ErrorStatus enumeration value:
00085   *          - SUCCESS: FMPI2C registers are de-initialized
00086   *          - ERROR: FMPI2C registers are not de-initialized
00087   */
00088 ErrorStatus LL_FMPI2C_DeInit(FMPI2C_TypeDef *FMPI2Cx)
00089 {
00090   ErrorStatus status = SUCCESS;
00091 
00092   /* Check the FMPI2C Instance FMPI2Cx */
00093   assert_param(IS_FMPI2C_ALL_INSTANCE(FMPI2Cx));
00094 
00095   if (FMPI2Cx == FMPI2C1)
00096   {
00097     /* Force reset of FMPI2C clock */
00098     LL_APB1_GRP1_ForceReset(LL_APB1_GRP1_PERIPH_FMPI2C1);
00099 
00100     /* Release reset of FMPI2C clock */
00101     LL_APB1_GRP1_ReleaseReset(LL_APB1_GRP1_PERIPH_FMPI2C1);
00102   }
00103   else
00104   {
00105     status = ERROR;
00106   }
00107 
00108   return status;
00109 }
00110 
00111 /**
00112   * @brief  Initialize the FMPI2C registers according to the specified parameters in FMPI2C_InitStruct.
00113   * @param  FMPI2Cx FMPI2C Instance.
00114   * @param  FMPI2C_InitStruct pointer to a @ref LL_FMPI2C_InitTypeDef structure.
00115   * @retval An ErrorStatus enumeration value:
00116   *          - SUCCESS: FMPI2C registers are initialized
00117   *          - ERROR: Not applicable
00118   */
00119 ErrorStatus LL_FMPI2C_Init(FMPI2C_TypeDef *FMPI2Cx, LL_FMPI2C_InitTypeDef *FMPI2C_InitStruct)
00120 {
00121   /* Check the FMPI2C Instance FMPI2Cx */
00122   assert_param(IS_FMPI2C_ALL_INSTANCE(FMPI2Cx));
00123 
00124   /* Check the FMPI2C parameters from FMPI2C_InitStruct */
00125   assert_param(IS_LL_FMPI2C_PERIPHERAL_MODE(FMPI2C_InitStruct->PeripheralMode));
00126   assert_param(IS_LL_FMPI2C_ANALOG_FILTER(FMPI2C_InitStruct->AnalogFilter));
00127   assert_param(IS_LL_FMPI2C_DIGITAL_FILTER(FMPI2C_InitStruct->DigitalFilter));
00128   assert_param(IS_LL_FMPI2C_OWN_ADDRESS1(FMPI2C_InitStruct->OwnAddress1));
00129   assert_param(IS_LL_FMPI2C_TYPE_ACKNOWLEDGE(FMPI2C_InitStruct->TypeAcknowledge));
00130   assert_param(IS_LL_FMPI2C_OWN_ADDRSIZE(FMPI2C_InitStruct->OwnAddrSize));
00131 
00132   /* Disable the selected FMPI2Cx Peripheral */
00133   LL_FMPI2C_Disable(FMPI2Cx);
00134 
00135   /*---------------------------- FMPI2Cx CR1 Configuration ------------------------
00136    * Configure the analog and digital noise filters with parameters :
00137    * - AnalogFilter: FMPI2C_CR1_ANFOFF bit
00138    * - DigitalFilter: FMPI2C_CR1_DNF[3:0] bits
00139    */
00140   LL_FMPI2C_ConfigFilters(FMPI2Cx, FMPI2C_InitStruct->AnalogFilter, FMPI2C_InitStruct->DigitalFilter);
00141 
00142   /*---------------------------- FMPI2Cx TIMINGR Configuration --------------------
00143    * Configure the SDA setup, hold time and the SCL high, low period with parameter :
00144    * - Timing: FMPI2C_TIMINGR_PRESC[3:0], FMPI2C_TIMINGR_SCLDEL[3:0], FMPI2C_TIMINGR_SDADEL[3:0],
00145    *           FMPI2C_TIMINGR_SCLH[7:0] and FMPI2C_TIMINGR_SCLL[7:0] bits
00146    */
00147   LL_FMPI2C_SetTiming(FMPI2Cx, FMPI2C_InitStruct->Timing);
00148 
00149   /* Enable the selected FMPI2Cx Peripheral */
00150   LL_FMPI2C_Enable(FMPI2Cx);
00151 
00152   /*---------------------------- FMPI2Cx OAR1 Configuration -----------------------
00153    * Disable, Configure and Enable FMPI2Cx device own address 1 with parameters :
00154    * - OwnAddress1:  FMPI2C_OAR1_OA1[9:0] bits
00155    * - OwnAddrSize:  FMPI2C_OAR1_OA1MODE bit
00156    */
00157   LL_FMPI2C_DisableOwnAddress1(FMPI2Cx);
00158   LL_FMPI2C_SetOwnAddress1(FMPI2Cx, FMPI2C_InitStruct->OwnAddress1, FMPI2C_InitStruct->OwnAddrSize);
00159 
00160   /* OwnAdress1 == 0 is reserved for General Call address */
00161   if (FMPI2C_InitStruct->OwnAddress1 != 0U)
00162   {
00163     LL_FMPI2C_EnableOwnAddress1(FMPI2Cx);
00164   }
00165 
00166   /*---------------------------- FMPI2Cx MODE Configuration -----------------------
00167   * Configure FMPI2Cx peripheral mode with parameter :
00168    * - PeripheralMode: FMPI2C_CR1_SMBDEN and FMPI2C_CR1_SMBHEN bits
00169    */
00170   LL_FMPI2C_SetMode(FMPI2Cx, FMPI2C_InitStruct->PeripheralMode);
00171 
00172   /*---------------------------- FMPI2Cx CR2 Configuration ------------------------
00173    * Configure the ACKnowledge or Non ACKnowledge condition
00174    * after the address receive match code or next received byte with parameter :
00175    * - TypeAcknowledge: FMPI2C_CR2_NACK bit
00176    */
00177   LL_FMPI2C_AcknowledgeNextData(FMPI2Cx, FMPI2C_InitStruct->TypeAcknowledge);
00178 
00179   return SUCCESS;
00180 }
00181 
00182 /**
00183   * @brief  Set each @ref LL_FMPI2C_InitTypeDef field to default value.
00184   * @param  FMPI2C_InitStruct Pointer to a @ref LL_FMPI2C_InitTypeDef structure.
00185   * @retval None
00186   */
00187 void LL_FMPI2C_StructInit(LL_FMPI2C_InitTypeDef *FMPI2C_InitStruct)
00188 {
00189   /* Set FMPI2C_InitStruct fields to default values */
00190   FMPI2C_InitStruct->PeripheralMode  = LL_FMPI2C_MODE_I2C;
00191   FMPI2C_InitStruct->Timing          = 0U;
00192   FMPI2C_InitStruct->AnalogFilter    = LL_FMPI2C_ANALOGFILTER_ENABLE;
00193   FMPI2C_InitStruct->DigitalFilter   = 0U;
00194   FMPI2C_InitStruct->OwnAddress1     = 0U;
00195   FMPI2C_InitStruct->TypeAcknowledge = LL_FMPI2C_NACK;
00196   FMPI2C_InitStruct->OwnAddrSize     = LL_FMPI2C_OWNADDRESS1_7BIT;
00197 }
00198 
00199 /**
00200   * @}
00201   */
00202 
00203 /**
00204   * @}
00205   */
00206 
00207 /**
00208   * @}
00209   */
00210 
00211 #endif /* FMPI2C1 */
00212 
00213 /**
00214   * @}
00215   */
00216 
00217 #endif /* FMPI2C_CR1_PE */
00218 #endif /* USE_FULL_LL_DRIVER */
00219 
00220 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/