训练营PLSR题目
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

218 lines
7.5 KiB

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