Set blackbox file handler to NULL after closing file
[inav.git] / lib / main / STM32H7 / Drivers / STM32H7xx_HAL_Driver / Src / stm32h7xx_ll_i2c.c
blobed7104bbebae3f11d5c70f88e053c28a27c10141
1 /**
2 ******************************************************************************
3 * @file stm32h7xx_ll_i2c.c
4 * @author MCD Application Team
5 * @brief I2C LL module driver.
6 ******************************************************************************
7 * @attention
9 * <h2><center>&copy; Copyright (c) 2017 STMicroelectronics.
10 * All rights reserved.</center></h2>
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
17 ******************************************************************************
19 #if defined(USE_FULL_LL_DRIVER)
21 /* Includes ------------------------------------------------------------------*/
22 #include "stm32h7xx_ll_i2c.h"
23 #include "stm32h7xx_ll_bus.h"
25 /** @addtogroup STM32H7xx_LL_Driver
26 * @{
29 #if defined (I2C1) || defined (I2C2) || defined (I2C3) || defined (I2C4)
31 /** @defgroup I2C_LL I2C
32 * @{
35 /* Private types -------------------------------------------------------------*/
36 /* Private variables ---------------------------------------------------------*/
37 /* Private constants ---------------------------------------------------------*/
38 /* Private macros ------------------------------------------------------------*/
39 /** @addtogroup I2C_LL_Private_Macros
40 * @{
43 #define IS_LL_I2C_PERIPHERAL_MODE(__VALUE__) (((__VALUE__) == LL_I2C_MODE_I2C) || \
44 ((__VALUE__) == LL_I2C_MODE_SMBUS_HOST) || \
45 ((__VALUE__) == LL_I2C_MODE_SMBUS_DEVICE) || \
46 ((__VALUE__) == LL_I2C_MODE_SMBUS_DEVICE_ARP))
48 #define IS_LL_I2C_ANALOG_FILTER(__VALUE__) (((__VALUE__) == LL_I2C_ANALOGFILTER_ENABLE) || \
49 ((__VALUE__) == LL_I2C_ANALOGFILTER_DISABLE))
51 #define IS_LL_I2C_DIGITAL_FILTER(__VALUE__) ((__VALUE__) <= 0x0000000FU)
53 #define IS_LL_I2C_OWN_ADDRESS1(__VALUE__) ((__VALUE__) <= 0x000003FFU)
55 #define IS_LL_I2C_TYPE_ACKNOWLEDGE(__VALUE__) (((__VALUE__) == LL_I2C_ACK) || \
56 ((__VALUE__) == LL_I2C_NACK))
58 #define IS_LL_I2C_OWN_ADDRSIZE(__VALUE__) (((__VALUE__) == LL_I2C_OWNADDRESS1_7BIT) || \
59 ((__VALUE__) == LL_I2C_OWNADDRESS1_10BIT))
60 /**
61 * @}
64 /* Private function prototypes -----------------------------------------------*/
66 /* Exported functions --------------------------------------------------------*/
67 /** @addtogroup I2C_LL_Exported_Functions
68 * @{
71 /** @addtogroup I2C_LL_EF_Init
72 * @{
75 /**
76 * @brief De-initialize the I2C registers to their default reset values.
77 * @param I2Cx I2C Instance.
78 * @retval An ErrorStatus enumeration value:
79 * - SUCCESS: I2C registers are de-initialized
80 * - ERROR: I2C registers are not de-initialized
82 ErrorStatus LL_I2C_DeInit(I2C_TypeDef *I2Cx)
84 ErrorStatus status = SUCCESS;
86 /* Check the I2C Instance I2Cx */
87 assert_param(IS_I2C_ALL_INSTANCE(I2Cx));
89 if (I2Cx == I2C1)
91 /* Force reset of I2C clock */
92 LL_APB1_GRP1_ForceReset(LL_APB1_GRP1_PERIPH_I2C1);
94 /* Release reset of I2C clock */
95 LL_APB1_GRP1_ReleaseReset(LL_APB1_GRP1_PERIPH_I2C1);
97 else if (I2Cx == I2C2)
99 /* Force reset of I2C clock */
100 LL_APB1_GRP1_ForceReset(LL_APB1_GRP1_PERIPH_I2C2);
102 /* Release reset of I2C clock */
103 LL_APB1_GRP1_ReleaseReset(LL_APB1_GRP1_PERIPH_I2C2);
106 else if (I2Cx == I2C3)
108 /* Force reset of I2C clock */
109 LL_APB1_GRP1_ForceReset(LL_APB1_GRP1_PERIPH_I2C3);
111 /* Release reset of I2C clock */
112 LL_APB1_GRP1_ReleaseReset(LL_APB1_GRP1_PERIPH_I2C3);
114 else if (I2Cx == I2C4)
116 /* Force reset of I2C clock */
117 LL_APB4_GRP1_ForceReset(LL_APB4_GRP1_PERIPH_I2C4);
119 /* Release reset of I2C clock */
120 LL_APB4_GRP1_ReleaseReset(LL_APB4_GRP1_PERIPH_I2C4);
122 else
124 status = ERROR;
127 return status;
131 * @brief Initialize the I2C registers according to the specified parameters in I2C_InitStruct.
132 * @param I2Cx I2C Instance.
133 * @param I2C_InitStruct pointer to a @ref LL_I2C_InitTypeDef structure.
134 * @retval An ErrorStatus enumeration value:
135 * - SUCCESS: I2C registers are initialized
136 * - ERROR: Not applicable
138 ErrorStatus LL_I2C_Init(I2C_TypeDef *I2Cx, LL_I2C_InitTypeDef *I2C_InitStruct)
140 /* Check the I2C Instance I2Cx */
141 assert_param(IS_I2C_ALL_INSTANCE(I2Cx));
143 /* Check the I2C parameters from I2C_InitStruct */
144 assert_param(IS_LL_I2C_PERIPHERAL_MODE(I2C_InitStruct->PeripheralMode));
145 assert_param(IS_LL_I2C_ANALOG_FILTER(I2C_InitStruct->AnalogFilter));
146 assert_param(IS_LL_I2C_DIGITAL_FILTER(I2C_InitStruct->DigitalFilter));
147 assert_param(IS_LL_I2C_OWN_ADDRESS1(I2C_InitStruct->OwnAddress1));
148 assert_param(IS_LL_I2C_TYPE_ACKNOWLEDGE(I2C_InitStruct->TypeAcknowledge));
149 assert_param(IS_LL_I2C_OWN_ADDRSIZE(I2C_InitStruct->OwnAddrSize));
151 /* Disable the selected I2Cx Peripheral */
152 LL_I2C_Disable(I2Cx);
154 /*---------------------------- I2Cx CR1 Configuration ------------------------
155 * Configure the analog and digital noise filters with parameters :
156 * - AnalogFilter: I2C_CR1_ANFOFF bit
157 * - DigitalFilter: I2C_CR1_DNF[3:0] bits
159 LL_I2C_ConfigFilters(I2Cx, I2C_InitStruct->AnalogFilter, I2C_InitStruct->DigitalFilter);
161 /*---------------------------- I2Cx TIMINGR Configuration --------------------
162 * Configure the SDA setup, hold time and the SCL high, low period with parameter :
163 * - Timing: I2C_TIMINGR_PRESC[3:0], I2C_TIMINGR_SCLDEL[3:0], I2C_TIMINGR_SDADEL[3:0],
164 * I2C_TIMINGR_SCLH[7:0] and I2C_TIMINGR_SCLL[7:0] bits
166 LL_I2C_SetTiming(I2Cx, I2C_InitStruct->Timing);
168 /* Enable the selected I2Cx Peripheral */
169 LL_I2C_Enable(I2Cx);
171 /*---------------------------- I2Cx OAR1 Configuration -----------------------
172 * Disable, Configure and Enable I2Cx device own address 1 with parameters :
173 * - OwnAddress1: I2C_OAR1_OA1[9:0] bits
174 * - OwnAddrSize: I2C_OAR1_OA1MODE bit
176 LL_I2C_DisableOwnAddress1(I2Cx);
177 LL_I2C_SetOwnAddress1(I2Cx, I2C_InitStruct->OwnAddress1, I2C_InitStruct->OwnAddrSize);
179 /* OwnAdress1 == 0 is reserved for General Call address */
180 if (I2C_InitStruct->OwnAddress1 != 0U)
182 LL_I2C_EnableOwnAddress1(I2Cx);
185 /*---------------------------- I2Cx MODE Configuration -----------------------
186 * Configure I2Cx peripheral mode with parameter :
187 * - PeripheralMode: I2C_CR1_SMBDEN and I2C_CR1_SMBHEN bits
189 LL_I2C_SetMode(I2Cx, I2C_InitStruct->PeripheralMode);
191 /*---------------------------- I2Cx CR2 Configuration ------------------------
192 * Configure the ACKnowledge or Non ACKnowledge condition
193 * after the address receive match code or next received byte with parameter :
194 * - TypeAcknowledge: I2C_CR2_NACK bit
196 LL_I2C_AcknowledgeNextData(I2Cx, I2C_InitStruct->TypeAcknowledge);
198 return SUCCESS;
202 * @brief Set each @ref LL_I2C_InitTypeDef field to default value.
203 * @param I2C_InitStruct Pointer to a @ref LL_I2C_InitTypeDef structure.
204 * @retval None
206 void LL_I2C_StructInit(LL_I2C_InitTypeDef *I2C_InitStruct)
208 /* Set I2C_InitStruct fields to default values */
209 I2C_InitStruct->PeripheralMode = LL_I2C_MODE_I2C;
210 I2C_InitStruct->Timing = 0U;
211 I2C_InitStruct->AnalogFilter = LL_I2C_ANALOGFILTER_ENABLE;
212 I2C_InitStruct->DigitalFilter = 0U;
213 I2C_InitStruct->OwnAddress1 = 0U;
214 I2C_InitStruct->TypeAcknowledge = LL_I2C_NACK;
215 I2C_InitStruct->OwnAddrSize = LL_I2C_OWNADDRESS1_7BIT;
219 * @}
223 * @}
227 * @}
230 #endif /* I2C1 || I2C2 || I2C3 || I2C4 */
233 * @}
236 #endif /* USE_FULL_LL_DRIVER */
238 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/