stm32f4xx_ll_fmpi2c.c 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  1. /**
  2. ******************************************************************************
  3. * @file stm32f4xx_ll_fmpi2c.c
  4. * @author MCD Application Team
  5. * @brief FMPI2C LL module driver.
  6. ******************************************************************************
  7. * @attention
  8. *
  9. * <h2><center>&copy; Copyright (c) 2016 STMicroelectronics.
  10. * All rights reserved.</center></h2>
  11. *
  12. * This software component is licensed by ST under BSD 3-Clause license,
  13. * the "License"; You may not use this file except in compliance with the
  14. * License. You may obtain a copy of the License at:
  15. * opensource.org/licenses/BSD-3-Clause
  16. *
  17. ******************************************************************************
  18. */
  19. #if defined(USE_FULL_LL_DRIVER)
  20. #if defined(FMPI2C_CR1_PE)
  21. /* Includes ------------------------------------------------------------------*/
  22. #include "stm32f4xx_ll_fmpi2c.h"
  23. #include "stm32f4xx_ll_bus.h"
  24. #ifdef USE_FULL_ASSERT
  25. #include "stm32_assert.h"
  26. #else
  27. #define assert_param(expr) ((void)0U)
  28. #endif
  29. /** @addtogroup STM32F4xx_LL_Driver
  30. * @{
  31. */
  32. #if defined (FMPI2C1)
  33. /** @defgroup FMPI2C_LL FMPI2C
  34. * @{
  35. */
  36. /* Private types -------------------------------------------------------------*/
  37. /* Private variables ---------------------------------------------------------*/
  38. /* Private constants ---------------------------------------------------------*/
  39. /* Private macros ------------------------------------------------------------*/
  40. /** @addtogroup FMPI2C_LL_Private_Macros
  41. * @{
  42. */
  43. #define IS_LL_FMPI2C_PERIPHERAL_MODE(__VALUE__) (((__VALUE__) == LL_FMPI2C_MODE_I2C) || \
  44. ((__VALUE__) == LL_FMPI2C_MODE_SMBUS_HOST) || \
  45. ((__VALUE__) == LL_FMPI2C_MODE_SMBUS_DEVICE) || \
  46. ((__VALUE__) == LL_FMPI2C_MODE_SMBUS_DEVICE_ARP))
  47. #define IS_LL_FMPI2C_ANALOG_FILTER(__VALUE__) (((__VALUE__) == LL_FMPI2C_ANALOGFILTER_ENABLE) || \
  48. ((__VALUE__) == LL_FMPI2C_ANALOGFILTER_DISABLE))
  49. #define IS_LL_FMPI2C_DIGITAL_FILTER(__VALUE__) ((__VALUE__) <= 0x0000000FU)
  50. #define IS_LL_FMPI2C_OWN_ADDRESS1(__VALUE__) ((__VALUE__) <= 0x000003FFU)
  51. #define IS_LL_FMPI2C_TYPE_ACKNOWLEDGE(__VALUE__) (((__VALUE__) == LL_FMPI2C_ACK) || \
  52. ((__VALUE__) == LL_FMPI2C_NACK))
  53. #define IS_LL_FMPI2C_OWN_ADDRSIZE(__VALUE__) (((__VALUE__) == LL_FMPI2C_OWNADDRESS1_7BIT) || \
  54. ((__VALUE__) == LL_FMPI2C_OWNADDRESS1_10BIT))
  55. /**
  56. * @}
  57. */
  58. /* Private function prototypes -----------------------------------------------*/
  59. /* Exported functions --------------------------------------------------------*/
  60. /** @addtogroup FMPI2C_LL_Exported_Functions
  61. * @{
  62. */
  63. /** @addtogroup FMPI2C_LL_EF_Init
  64. * @{
  65. */
  66. /**
  67. * @brief De-initialize the FMPI2C registers to their default reset values.
  68. * @param FMPI2Cx FMPI2C Instance.
  69. * @retval An ErrorStatus enumeration value:
  70. * - SUCCESS: FMPI2C registers are de-initialized
  71. * - ERROR: FMPI2C registers are not de-initialized
  72. */
  73. ErrorStatus LL_FMPI2C_DeInit(FMPI2C_TypeDef *FMPI2Cx)
  74. {
  75. ErrorStatus status = SUCCESS;
  76. /* Check the FMPI2C Instance FMPI2Cx */
  77. assert_param(IS_FMPI2C_ALL_INSTANCE(FMPI2Cx));
  78. if (FMPI2Cx == FMPI2C1)
  79. {
  80. /* Force reset of FMPI2C clock */
  81. LL_APB1_GRP1_ForceReset(LL_APB1_GRP1_PERIPH_FMPI2C1);
  82. /* Release reset of FMPI2C clock */
  83. LL_APB1_GRP1_ReleaseReset(LL_APB1_GRP1_PERIPH_FMPI2C1);
  84. }
  85. else
  86. {
  87. status = ERROR;
  88. }
  89. return status;
  90. }
  91. /**
  92. * @brief Initialize the FMPI2C registers according to the specified parameters in FMPI2C_InitStruct.
  93. * @param FMPI2Cx FMPI2C Instance.
  94. * @param FMPI2C_InitStruct pointer to a @ref LL_FMPI2C_InitTypeDef structure.
  95. * @retval An ErrorStatus enumeration value:
  96. * - SUCCESS: FMPI2C registers are initialized
  97. * - ERROR: Not applicable
  98. */
  99. ErrorStatus LL_FMPI2C_Init(FMPI2C_TypeDef *FMPI2Cx, LL_FMPI2C_InitTypeDef *FMPI2C_InitStruct)
  100. {
  101. /* Check the FMPI2C Instance FMPI2Cx */
  102. assert_param(IS_FMPI2C_ALL_INSTANCE(FMPI2Cx));
  103. /* Check the FMPI2C parameters from FMPI2C_InitStruct */
  104. assert_param(IS_LL_FMPI2C_PERIPHERAL_MODE(FMPI2C_InitStruct->PeripheralMode));
  105. assert_param(IS_LL_FMPI2C_ANALOG_FILTER(FMPI2C_InitStruct->AnalogFilter));
  106. assert_param(IS_LL_FMPI2C_DIGITAL_FILTER(FMPI2C_InitStruct->DigitalFilter));
  107. assert_param(IS_LL_FMPI2C_OWN_ADDRESS1(FMPI2C_InitStruct->OwnAddress1));
  108. assert_param(IS_LL_FMPI2C_TYPE_ACKNOWLEDGE(FMPI2C_InitStruct->TypeAcknowledge));
  109. assert_param(IS_LL_FMPI2C_OWN_ADDRSIZE(FMPI2C_InitStruct->OwnAddrSize));
  110. /* Disable the selected FMPI2Cx Peripheral */
  111. LL_FMPI2C_Disable(FMPI2Cx);
  112. /*---------------------------- FMPI2Cx CR1 Configuration ------------------------
  113. * Configure the analog and digital noise filters with parameters :
  114. * - AnalogFilter: FMPI2C_CR1_ANFOFF bit
  115. * - DigitalFilter: FMPI2C_CR1_DNF[3:0] bits
  116. */
  117. LL_FMPI2C_ConfigFilters(FMPI2Cx, FMPI2C_InitStruct->AnalogFilter, FMPI2C_InitStruct->DigitalFilter);
  118. /*---------------------------- FMPI2Cx TIMINGR Configuration --------------------
  119. * Configure the SDA setup, hold time and the SCL high, low period with parameter :
  120. * - Timing: FMPI2C_TIMINGR_PRESC[3:0], FMPI2C_TIMINGR_SCLDEL[3:0], FMPI2C_TIMINGR_SDADEL[3:0],
  121. * FMPI2C_TIMINGR_SCLH[7:0] and FMPI2C_TIMINGR_SCLL[7:0] bits
  122. */
  123. LL_FMPI2C_SetTiming(FMPI2Cx, FMPI2C_InitStruct->Timing);
  124. /* Enable the selected FMPI2Cx Peripheral */
  125. LL_FMPI2C_Enable(FMPI2Cx);
  126. /*---------------------------- FMPI2Cx OAR1 Configuration -----------------------
  127. * Disable, Configure and Enable FMPI2Cx device own address 1 with parameters :
  128. * - OwnAddress1: FMPI2C_OAR1_OA1[9:0] bits
  129. * - OwnAddrSize: FMPI2C_OAR1_OA1MODE bit
  130. */
  131. LL_FMPI2C_DisableOwnAddress1(FMPI2Cx);
  132. LL_FMPI2C_SetOwnAddress1(FMPI2Cx, FMPI2C_InitStruct->OwnAddress1, FMPI2C_InitStruct->OwnAddrSize);
  133. /* OwnAdress1 == 0 is reserved for General Call address */
  134. if (FMPI2C_InitStruct->OwnAddress1 != 0U)
  135. {
  136. LL_FMPI2C_EnableOwnAddress1(FMPI2Cx);
  137. }
  138. /*---------------------------- FMPI2Cx MODE Configuration -----------------------
  139. * Configure FMPI2Cx peripheral mode with parameter :
  140. * - PeripheralMode: FMPI2C_CR1_SMBDEN and FMPI2C_CR1_SMBHEN bits
  141. */
  142. LL_FMPI2C_SetMode(FMPI2Cx, FMPI2C_InitStruct->PeripheralMode);
  143. /*---------------------------- FMPI2Cx CR2 Configuration ------------------------
  144. * Configure the ACKnowledge or Non ACKnowledge condition
  145. * after the address receive match code or next received byte with parameter :
  146. * - TypeAcknowledge: FMPI2C_CR2_NACK bit
  147. */
  148. LL_FMPI2C_AcknowledgeNextData(FMPI2Cx, FMPI2C_InitStruct->TypeAcknowledge);
  149. return SUCCESS;
  150. }
  151. /**
  152. * @brief Set each @ref LL_FMPI2C_InitTypeDef field to default value.
  153. * @param FMPI2C_InitStruct Pointer to a @ref LL_FMPI2C_InitTypeDef structure.
  154. * @retval None
  155. */
  156. void LL_FMPI2C_StructInit(LL_FMPI2C_InitTypeDef *FMPI2C_InitStruct)
  157. {
  158. /* Set FMPI2C_InitStruct fields to default values */
  159. FMPI2C_InitStruct->PeripheralMode = LL_FMPI2C_MODE_I2C;
  160. FMPI2C_InitStruct->Timing = 0U;
  161. FMPI2C_InitStruct->AnalogFilter = LL_FMPI2C_ANALOGFILTER_ENABLE;
  162. FMPI2C_InitStruct->DigitalFilter = 0U;
  163. FMPI2C_InitStruct->OwnAddress1 = 0U;
  164. FMPI2C_InitStruct->TypeAcknowledge = LL_FMPI2C_NACK;
  165. FMPI2C_InitStruct->OwnAddrSize = LL_FMPI2C_OWNADDRESS1_7BIT;
  166. }
  167. /**
  168. * @}
  169. */
  170. /**
  171. * @}
  172. */
  173. /**
  174. * @}
  175. */
  176. #endif /* FMPI2C1 */
  177. /**
  178. * @}
  179. */
  180. #endif /* FMPI2C_CR1_PE */
  181. #endif /* USE_FULL_LL_DRIVER */
  182. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/