Rev 2 | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
2 | mjames | 1 | /** |
2 | ****************************************************************************** |
||
3 | * @file stm32f1xx_hal_i2c.h |
||
4 | * @author MCD Application Team |
||
5 | mjames | 5 | * @version V1.0.4 |
6 | * @date 29-April-2016 |
||
2 | mjames | 7 | * @brief Header file of I2C HAL module. |
8 | ****************************************************************************** |
||
9 | * @attention |
||
10 | * |
||
5 | mjames | 11 | * <h2><center>© COPYRIGHT(c) 2016 STMicroelectronics</center></h2> |
2 | mjames | 12 | * |
13 | * Redistribution and use in source and binary forms, with or without modification, |
||
14 | * are permitted provided that the following conditions are met: |
||
15 | * 1. Redistributions of source code must retain the above copyright notice, |
||
16 | * this list of conditions and the following disclaimer. |
||
17 | * 2. Redistributions in binary form must reproduce the above copyright notice, |
||
18 | * this list of conditions and the following disclaimer in the documentation |
||
19 | * and/or other materials provided with the distribution. |
||
20 | * 3. Neither the name of STMicroelectronics nor the names of its contributors |
||
21 | * may be used to endorse or promote products derived from this software |
||
22 | * without specific prior written permission. |
||
23 | * |
||
24 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
||
25 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
||
26 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
||
27 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE |
||
28 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
||
29 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
||
30 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
||
31 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
||
32 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
||
33 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
||
34 | * |
||
35 | ****************************************************************************** |
||
36 | */ |
||
37 | |||
38 | /* Define to prevent recursive inclusion -------------------------------------*/ |
||
39 | #ifndef __STM32F1xx_HAL_I2C_H |
||
40 | #define __STM32F1xx_HAL_I2C_H |
||
41 | |||
42 | #ifdef __cplusplus |
||
43 | extern "C" { |
||
44 | #endif |
||
45 | |||
46 | /* Includes ------------------------------------------------------------------*/ |
||
47 | #include "stm32f1xx_hal_def.h" |
||
48 | |||
49 | /** @addtogroup STM32F1xx_HAL_Driver |
||
50 | * @{ |
||
51 | */ |
||
52 | |||
53 | /** @addtogroup I2C |
||
54 | * @{ |
||
55 | */ |
||
56 | |||
57 | /* Exported types ------------------------------------------------------------*/ |
||
58 | /** @defgroup I2C_Exported_Types I2C Exported Types |
||
59 | * @{ |
||
60 | */ |
||
61 | |||
62 | /** @defgroup I2C_Configuration_Structure_definition I2C Configuration Structure definition |
||
63 | * @brief I2C Configuration Structure definition |
||
64 | * @{ |
||
65 | */ |
||
66 | typedef struct |
||
67 | { |
||
68 | uint32_t ClockSpeed; /*!< Specifies the clock frequency. |
||
69 | This parameter must be set to a value lower than 400kHz */ |
||
70 | |||
71 | uint32_t DutyCycle; /*!< Specifies the I2C fast mode duty cycle. |
||
72 | This parameter can be a value of @ref I2C_duty_cycle_in_fast_mode */ |
||
73 | |||
74 | uint32_t OwnAddress1; /*!< Specifies the first device own address. |
||
75 | This parameter can be a 7-bit or 10-bit address. */ |
||
76 | |||
77 | uint32_t AddressingMode; /*!< Specifies if 7-bit or 10-bit addressing mode is selected. |
||
78 | This parameter can be a value of @ref I2C_addressing_mode */ |
||
79 | |||
80 | uint32_t DualAddressMode; /*!< Specifies if dual addressing mode is selected. |
||
81 | This parameter can be a value of @ref I2C_dual_addressing_mode */ |
||
82 | |||
83 | uint32_t OwnAddress2; /*!< Specifies the second device own address if dual addressing mode is selected |
||
84 | This parameter can be a 7-bit address. */ |
||
85 | |||
86 | uint32_t GeneralCallMode; /*!< Specifies if general call mode is selected. |
||
87 | This parameter can be a value of @ref I2C_general_call_addressing_mode */ |
||
88 | |||
89 | uint32_t NoStretchMode; /*!< Specifies if nostretch mode is selected. |
||
90 | This parameter can be a value of @ref I2C_nostretch_mode */ |
||
91 | |||
92 | }I2C_InitTypeDef; |
||
93 | |||
94 | /** |
||
95 | * @} |
||
96 | */ |
||
97 | |||
98 | /** @defgroup HAL_state_structure_definition HAL state structure definition |
||
99 | * @brief HAL State structure definition |
||
100 | * @{ |
||
101 | */ |
||
102 | |||
103 | typedef enum |
||
104 | { |
||
5 | mjames | 105 | HAL_I2C_STATE_RESET = 0x00, /*!< Peripheral is not yet Initialized */ |
106 | HAL_I2C_STATE_READY = 0x20, /*!< Peripheral Initialized and ready for use */ |
||
107 | HAL_I2C_STATE_BUSY = 0x24, /*!< An internal process is ongoing */ |
||
108 | HAL_I2C_STATE_BUSY_TX = 0x21, /*!< Data Transmission process is ongoing */ |
||
109 | HAL_I2C_STATE_BUSY_RX = 0x22, /*!< Data Reception process is ongoing */ |
||
110 | HAL_I2C_STATE_TIMEOUT = 0xA0, /*!< Timeout state */ |
||
111 | HAL_I2C_STATE_ERROR = 0xE0 /*!< Error */ |
||
2 | mjames | 112 | |
113 | }HAL_I2C_StateTypeDef; |
||
114 | |||
115 | /** |
||
116 | * @} |
||
117 | */ |
||
118 | |||
5 | mjames | 119 | /** @defgroup HAL_mode_structure_definition HAL mode structure definition |
120 | * @brief HAL Mode structure definition |
||
121 | * @{ |
||
122 | */ |
||
123 | typedef enum |
||
124 | { |
||
125 | HAL_I2C_MODE_NONE = 0x00, /*!< No I2C communication on going */ |
||
126 | HAL_I2C_MODE_MASTER = 0x10, /*!< I2C communication is in Master Mode */ |
||
127 | HAL_I2C_MODE_SLAVE = 0x20, /*!< I2C communication is in Slave Mode */ |
||
128 | HAL_I2C_MODE_MEM = 0x40 /*!< I2C communication is in Memory Mode */ |
||
129 | |||
130 | }HAL_I2C_ModeTypeDef; |
||
131 | |||
132 | /** |
||
133 | * @} |
||
134 | */ |
||
135 | |||
2 | mjames | 136 | /** @defgroup I2C_handle_Structure_definition I2C handle Structure definition |
137 | * @brief I2C handle Structure definition |
||
138 | * @{ |
||
139 | */ |
||
140 | typedef struct |
||
141 | { |
||
142 | I2C_TypeDef *Instance; /*!< I2C registers base address */ |
||
143 | |||
144 | I2C_InitTypeDef Init; /*!< I2C communication parameters */ |
||
145 | |||
146 | uint8_t *pBuffPtr; /*!< Pointer to I2C transfer buffer */ |
||
147 | |||
148 | uint16_t XferSize; /*!< I2C transfer size */ |
||
149 | |||
150 | __IO uint16_t XferCount; /*!< I2C transfer counter */ |
||
151 | |||
152 | DMA_HandleTypeDef *hdmatx; /*!< I2C Tx DMA handle parameters */ |
||
153 | |||
154 | DMA_HandleTypeDef *hdmarx; /*!< I2C Rx DMA handle parameters */ |
||
155 | |||
156 | HAL_LockTypeDef Lock; /*!< I2C locking object */ |
||
157 | |||
158 | __IO HAL_I2C_StateTypeDef State; /*!< I2C communication state */ |
||
159 | |||
5 | mjames | 160 | __IO HAL_I2C_ModeTypeDef Mode; /*!< I2C communication mode */ |
2 | mjames | 161 | |
5 | mjames | 162 | __IO uint32_t ErrorCode; /*!< I2C Error code */ |
163 | |||
2 | mjames | 164 | }I2C_HandleTypeDef; |
165 | /** |
||
166 | * @} |
||
167 | */ |
||
168 | |||
169 | /** |
||
170 | * @} |
||
171 | */ |
||
172 | /* Exported constants --------------------------------------------------------*/ |
||
173 | |||
174 | /** @defgroup I2C_Exported_Constants I2C Exported Constants |
||
175 | * @{ |
||
176 | */ |
||
177 | |||
178 | /** @defgroup I2C_Error_Codes I2C Error Codes |
||
179 | * @{ |
||
180 | */ |
||
181 | |||
182 | #define HAL_I2C_ERROR_NONE ((uint32_t)0x00) /*!< No error */ |
||
183 | #define HAL_I2C_ERROR_BERR ((uint32_t)0x01) /*!< BERR error */ |
||
184 | #define HAL_I2C_ERROR_ARLO ((uint32_t)0x02) /*!< ARLO error */ |
||
185 | #define HAL_I2C_ERROR_AF ((uint32_t)0x04) /*!< AF error */ |
||
186 | #define HAL_I2C_ERROR_OVR ((uint32_t)0x08) /*!< OVR error */ |
||
187 | #define HAL_I2C_ERROR_DMA ((uint32_t)0x10) /*!< DMA transfer error */ |
||
188 | #define HAL_I2C_ERROR_TIMEOUT ((uint32_t)0x20) /*!< Timeout error */ |
||
189 | |||
190 | /** |
||
191 | * @} |
||
192 | */ |
||
193 | |||
194 | |||
195 | |||
196 | /** @defgroup I2C_duty_cycle_in_fast_mode I2C Duty Cycle |
||
197 | * @{ |
||
198 | */ |
||
199 | #define I2C_DUTYCYCLE_2 ((uint32_t)0x00000000) |
||
200 | #define I2C_DUTYCYCLE_16_9 I2C_CCR_DUTY |
||
201 | /** |
||
202 | * @} |
||
203 | */ |
||
204 | |||
205 | /** @defgroup I2C_addressing_mode I2C addressing mode |
||
206 | * @{ |
||
207 | */ |
||
208 | #define I2C_ADDRESSINGMODE_7BIT ((uint32_t)0x00004000) |
||
209 | #define I2C_ADDRESSINGMODE_10BIT (I2C_OAR1_ADDMODE | ((uint32_t)0x00004000)) |
||
210 | /** |
||
211 | * @} |
||
212 | */ |
||
213 | |||
214 | /** @defgroup I2C_dual_addressing_mode I2C dual addressing mode |
||
215 | * @{ |
||
216 | */ |
||
217 | #define I2C_DUALADDRESS_DISABLE ((uint32_t)0x00000000) |
||
218 | #define I2C_DUALADDRESS_ENABLE I2C_OAR2_ENDUAL |
||
219 | /** |
||
220 | * @} |
||
221 | */ |
||
222 | |||
223 | /** @defgroup I2C_general_call_addressing_mode I2C general call addressing mode |
||
224 | * @{ |
||
225 | */ |
||
226 | #define I2C_GENERALCALL_DISABLE ((uint32_t)0x00000000) |
||
227 | #define I2C_GENERALCALL_ENABLE I2C_CR1_ENGC |
||
228 | /** |
||
229 | * @} |
||
230 | */ |
||
231 | |||
232 | /** @defgroup I2C_nostretch_mode I2C nostretch mode |
||
233 | * @{ |
||
234 | */ |
||
235 | #define I2C_NOSTRETCH_DISABLE ((uint32_t)0x00000000) |
||
236 | #define I2C_NOSTRETCH_ENABLE I2C_CR1_NOSTRETCH |
||
237 | /** |
||
238 | * @} |
||
239 | */ |
||
240 | |||
241 | /** @defgroup I2C_Memory_Address_Size I2C Memory Address Size |
||
242 | * @{ |
||
243 | */ |
||
244 | #define I2C_MEMADD_SIZE_8BIT ((uint32_t)0x00000001) |
||
245 | #define I2C_MEMADD_SIZE_16BIT ((uint32_t)0x00000010) |
||
246 | /** |
||
247 | * @} |
||
248 | */ |
||
249 | |||
250 | /** @defgroup I2C_Interrupt_configuration_definition I2C Interrupt configuration definition |
||
251 | * @{ |
||
252 | */ |
||
253 | #define I2C_IT_BUF I2C_CR2_ITBUFEN |
||
254 | #define I2C_IT_EVT I2C_CR2_ITEVTEN |
||
255 | #define I2C_IT_ERR I2C_CR2_ITERREN |
||
256 | /** |
||
257 | * @} |
||
258 | */ |
||
259 | |||
260 | /** @defgroup I2C_Flag_definition I2C Flag definition |
||
261 | * @brief I2C Interrupt definition |
||
262 | * - 0001XXXX : Flag control mask for SR1 Register |
||
263 | * - 0010XXXX : Flag control mask for SR2 Register |
||
264 | * @{ |
||
265 | */ |
||
266 | #define I2C_FLAG_SMBALERT ((uint32_t)0x00018000) |
||
267 | #define I2C_FLAG_TIMEOUT ((uint32_t)0x00014000) |
||
268 | #define I2C_FLAG_PECERR ((uint32_t)0x00011000) |
||
269 | #define I2C_FLAG_OVR ((uint32_t)0x00010800) |
||
270 | #define I2C_FLAG_AF ((uint32_t)0x00010400) |
||
271 | #define I2C_FLAG_ARLO ((uint32_t)0x00010200) |
||
272 | #define I2C_FLAG_BERR ((uint32_t)0x00010100) |
||
273 | #define I2C_FLAG_TXE ((uint32_t)0x00010080) |
||
274 | #define I2C_FLAG_RXNE ((uint32_t)0x00010040) |
||
275 | #define I2C_FLAG_STOPF ((uint32_t)0x00010010) |
||
276 | #define I2C_FLAG_ADD10 ((uint32_t)0x00010008) |
||
277 | #define I2C_FLAG_BTF ((uint32_t)0x00010004) |
||
278 | #define I2C_FLAG_ADDR ((uint32_t)0x00010002) |
||
279 | #define I2C_FLAG_SB ((uint32_t)0x00010001) |
||
280 | #define I2C_FLAG_DUALF ((uint32_t)0x00100080) |
||
281 | #define I2C_FLAG_SMBHOST ((uint32_t)0x00100040) |
||
282 | #define I2C_FLAG_SMBDEFAULT ((uint32_t)0x00100020) |
||
283 | #define I2C_FLAG_GENCALL ((uint32_t)0x00100010) |
||
284 | #define I2C_FLAG_TRA ((uint32_t)0x00100004) |
||
285 | #define I2C_FLAG_BUSY ((uint32_t)0x00100002) |
||
286 | #define I2C_FLAG_MSL ((uint32_t)0x00100001) |
||
287 | #define I2C_FLAG_MASK ((uint32_t)0x0000FFFF) |
||
288 | /** |
||
289 | * @} |
||
290 | */ |
||
291 | |||
292 | /** |
||
293 | * @} |
||
294 | */ |
||
295 | |||
296 | /* Exported macros -----------------------------------------------------------*/ |
||
297 | |||
298 | /** @defgroup I2C_Exported_Macros I2C Exported Macros |
||
299 | * @{ |
||
300 | */ |
||
301 | |||
5 | mjames | 302 | /** @brief Reset I2C handle state. |
303 | * @param __HANDLE__ specifies the I2C Handle. |
||
2 | mjames | 304 | * @retval None |
305 | */ |
||
306 | #define __HAL_I2C_RESET_HANDLE_STATE(__HANDLE__) ((__HANDLE__)->State = HAL_I2C_STATE_RESET) |
||
307 | |||
5 | mjames | 308 | /** @brief Enable the specified I2C interrupt. |
309 | * @param __HANDLE__ specifies the I2C Handle. |
||
2 | mjames | 310 | * @param __INTERRUPT__: specifies the interrupt source to enable. |
311 | * This parameter can be one of the following values: |
||
5 | mjames | 312 | * @arg @ref I2C_IT_BUF Buffer interrupt enable |
313 | * @arg @ref I2C_IT_EVT Event interrupt enable |
||
314 | * @arg @ref I2C_IT_ERR Error interrupt enable |
||
2 | mjames | 315 | * @retval None |
316 | */ |
||
317 | #define __HAL_I2C_ENABLE_IT(__HANDLE__, __INTERRUPT__) (SET_BIT((__HANDLE__)->Instance->CR2, (__INTERRUPT__))) |
||
318 | |||
5 | mjames | 319 | /** @brief Disable the specified I2C interrupt. |
320 | * @param __HANDLE__ specifies the I2C Handle. |
||
2 | mjames | 321 | * @param __INTERRUPT__: specifies the interrupt source to disable. |
322 | * This parameter can be one of the following values: |
||
5 | mjames | 323 | * @arg @ref I2C_IT_BUF Buffer interrupt enable |
324 | * @arg @ref I2C_IT_EVT Event interrupt enable |
||
325 | * @arg @ref I2C_IT_ERR Error interrupt enable |
||
2 | mjames | 326 | * @retval None |
327 | */ |
||
328 | #define __HAL_I2C_DISABLE_IT(__HANDLE__, __INTERRUPT__) (CLEAR_BIT((__HANDLE__)->Instance->CR2, (__INTERRUPT__))) |
||
329 | |||
5 | mjames | 330 | /** @brief Check whether the specified I2C interrupt source is enabled or not. |
331 | * @param __HANDLE__ specifies the I2C Handle. |
||
2 | mjames | 332 | * @param __INTERRUPT__: specifies the I2C interrupt source to check. |
333 | * This parameter can be one of the following values: |
||
5 | mjames | 334 | * @arg @ref I2C_IT_BUF Buffer interrupt enable |
335 | * @arg @ref I2C_IT_EVT Event interrupt enable |
||
336 | * @arg @ref I2C_IT_ERR Error interrupt enable |
||
2 | mjames | 337 | * @retval The new state of __INTERRUPT__ (TRUE or FALSE). |
338 | */ |
||
339 | #define __HAL_I2C_GET_IT_SOURCE(__HANDLE__, __INTERRUPT__) ((((__HANDLE__)->Instance->CR2 & (__INTERRUPT__)) == (__INTERRUPT__)) ? SET : RESET) |
||
340 | |||
5 | mjames | 341 | /** @brief Check whether the specified I2C flag is set or not. |
342 | * @param __HANDLE__ specifies the I2C Handle. |
||
343 | * @param __FLAG__ specifies the flag to check. |
||
2 | mjames | 344 | * This parameter can be one of the following values: |
5 | mjames | 345 | * @arg @ref I2C_FLAG_SMBALERT SMBus Alert flag |
346 | * @arg @ref I2C_FLAG_TIMEOUT Timeout or Tlow error flag |
||
347 | * @arg @ref I2C_FLAG_PECERR PEC error in reception flag |
||
348 | * @arg @ref I2C_FLAG_OVR Overrun/Underrun flag |
||
349 | * @arg @ref I2C_FLAG_AF Acknowledge failure flag |
||
350 | * @arg @ref I2C_FLAG_ARLO Arbitration lost flag |
||
351 | * @arg @ref I2C_FLAG_BERR Bus error flag |
||
352 | * @arg @ref I2C_FLAG_TXE Data register empty flag |
||
353 | * @arg @ref I2C_FLAG_RXNE Data register not empty flag |
||
354 | * @arg @ref I2C_FLAG_STOPF Stop detection flag |
||
355 | * @arg @ref I2C_FLAG_ADD10 10-bit header sent flag |
||
356 | * @arg @ref I2C_FLAG_BTF Byte transfer finished flag |
||
357 | * @arg @ref I2C_FLAG_ADDR Address sent flag |
||
358 | * Address matched flag |
||
359 | * @arg @ref I2C_FLAG_SB Start bit flag |
||
360 | * @arg @ref I2C_FLAG_DUALF Dual flag |
||
361 | * @arg @ref I2C_FLAG_SMBHOST SMBus host header |
||
362 | * @arg @ref I2C_FLAG_SMBDEFAULT SMBus default header |
||
363 | * @arg @ref I2C_FLAG_GENCALL General call header flag |
||
364 | * @arg @ref I2C_FLAG_TRA Transmitter/Receiver flag |
||
365 | * @arg @ref I2C_FLAG_BUSY Bus busy flag |
||
366 | * @arg @ref I2C_FLAG_MSL Master/Slave flag |
||
2 | mjames | 367 | * @retval The new state of __FLAG__ (TRUE or FALSE). |
368 | */ |
||
369 | #define __HAL_I2C_GET_FLAG(__HANDLE__, __FLAG__) ((((uint8_t)((__FLAG__) >> 16)) == 0x01)?((((__HANDLE__)->Instance->SR1) & ((__FLAG__) & I2C_FLAG_MASK)) == ((__FLAG__) & I2C_FLAG_MASK)): \ |
||
370 | ((((__HANDLE__)->Instance->SR2) & ((__FLAG__) & I2C_FLAG_MASK)) == ((__FLAG__) & I2C_FLAG_MASK))) |
||
371 | |||
5 | mjames | 372 | /** @brief Clear the I2C pending flags which are cleared by writing 0 in a specific bit. |
373 | * @param __HANDLE__ specifies the I2C Handle. |
||
374 | * @param __FLAG__ specifies the flag to clear. |
||
2 | mjames | 375 | * This parameter can be any combination of the following values: |
5 | mjames | 376 | * @arg @ref I2C_FLAG_SMBALERT SMBus Alert flag |
377 | * @arg @ref I2C_FLAG_TIMEOUT Timeout or Tlow error flag |
||
378 | * @arg @ref I2C_FLAG_PECERR PEC error in reception flag |
||
379 | * @arg @ref I2C_FLAG_OVR Overrun/Underrun flag (Slave mode) |
||
380 | * @arg @ref I2C_FLAG_AF Acknowledge failure flag |
||
381 | * @arg @ref I2C_FLAG_ARLO Arbitration lost flag (Master mode) |
||
382 | * @arg @ref I2C_FLAG_BERR Bus error flag |
||
383 | * |
||
2 | mjames | 384 | * @retval None |
385 | */ |
||
386 | #define __HAL_I2C_CLEAR_FLAG(__HANDLE__, __FLAG__) (__HANDLE__)->Instance->SR1 = (((__HANDLE__)->Instance->SR1) & (~((__FLAG__) & I2C_FLAG_MASK))) |
||
387 | |||
388 | /** @brief Clears the I2C ADDR pending flag. |
||
389 | * @param __HANDLE__: specifies the I2C Handle. |
||
390 | * @retval None |
||
391 | */ |
||
392 | #define __HAL_I2C_CLEAR_ADDRFLAG(__HANDLE__) \ |
||
393 | do{ \ |
||
394 | __IO uint32_t tmpreg; \ |
||
395 | tmpreg = (__HANDLE__)->Instance->SR1; \ |
||
396 | tmpreg = (__HANDLE__)->Instance->SR2; \ |
||
397 | UNUSED(tmpreg); \ |
||
398 | }while(0) |
||
399 | |||
400 | /** @brief Clears the I2C STOPF pending flag. |
||
401 | * @param __HANDLE__: specifies the I2C Handle. |
||
402 | * @retval None |
||
403 | */ |
||
404 | #define __HAL_I2C_CLEAR_STOPFLAG(__HANDLE__) \ |
||
405 | do{ \ |
||
406 | __IO uint32_t tmpreg; \ |
||
407 | tmpreg = (__HANDLE__)->Instance->SR1; \ |
||
408 | tmpreg = (__HANDLE__)->Instance->CR1 |= I2C_CR1_PE; \ |
||
409 | UNUSED(tmpreg); \ |
||
410 | }while(0) |
||
411 | |||
412 | /** @brief Enable the specified I2C peripheral. |
||
5 | mjames | 413 | * @param __HANDLE__ specifies the I2C Handle. |
2 | mjames | 414 | * @retval None |
415 | */ |
||
416 | #define __HAL_I2C_ENABLE(__HANDLE__) (SET_BIT((__HANDLE__)->Instance->CR1, I2C_CR1_PE)) |
||
417 | |||
418 | /** @brief Disable the specified I2C peripheral. |
||
5 | mjames | 419 | * @param __HANDLE__ specifies the I2C Handle. |
2 | mjames | 420 | * @retval None |
421 | */ |
||
422 | #define __HAL_I2C_DISABLE(__HANDLE__) (CLEAR_BIT((__HANDLE__)->Instance->CR1, I2C_CR1_PE)) |
||
423 | |||
424 | /** |
||
425 | * @} |
||
426 | */ |
||
427 | |||
428 | /* Exported functions --------------------------------------------------------*/ |
||
429 | /** @addtogroup I2C_Exported_Functions |
||
430 | * @{ |
||
431 | */ |
||
432 | |||
433 | /** @addtogroup I2C_Exported_Functions_Group1 Initialization and de-initialization functions |
||
434 | * @{ |
||
435 | */ |
||
436 | |||
437 | /* Initialization/de-initialization functions ********************************/ |
||
438 | HAL_StatusTypeDef HAL_I2C_Init(I2C_HandleTypeDef *hi2c); |
||
439 | HAL_StatusTypeDef HAL_I2C_DeInit (I2C_HandleTypeDef *hi2c); |
||
440 | void HAL_I2C_MspInit(I2C_HandleTypeDef *hi2c); |
||
441 | void HAL_I2C_MspDeInit(I2C_HandleTypeDef *hi2c); |
||
442 | |||
443 | /** |
||
444 | * @} |
||
445 | */ |
||
446 | |||
447 | /** @addtogroup I2C_Exported_Functions_Group2 Input and Output operation functions |
||
448 | * @{ |
||
449 | */ |
||
450 | |||
451 | /* IO operation functions ****************************************************/ |
||
452 | |||
453 | /******* Blocking mode: Polling */ |
||
454 | HAL_StatusTypeDef HAL_I2C_Master_Transmit(I2C_HandleTypeDef *hi2c, uint16_t DevAddress, uint8_t *pData, uint16_t Size, uint32_t Timeout); |
||
455 | HAL_StatusTypeDef HAL_I2C_Master_Receive(I2C_HandleTypeDef *hi2c, uint16_t DevAddress, uint8_t *pData, uint16_t Size, uint32_t Timeout); |
||
456 | HAL_StatusTypeDef HAL_I2C_Slave_Transmit(I2C_HandleTypeDef *hi2c, uint8_t *pData, uint16_t Size, uint32_t Timeout); |
||
457 | HAL_StatusTypeDef HAL_I2C_Slave_Receive(I2C_HandleTypeDef *hi2c, uint8_t *pData, uint16_t Size, uint32_t Timeout); |
||
458 | HAL_StatusTypeDef HAL_I2C_Mem_Write(I2C_HandleTypeDef *hi2c, uint16_t DevAddress, uint16_t MemAddress, uint16_t MemAddSize, uint8_t *pData, uint16_t Size, uint32_t Timeout); |
||
459 | HAL_StatusTypeDef HAL_I2C_Mem_Read(I2C_HandleTypeDef *hi2c, uint16_t DevAddress, uint16_t MemAddress, uint16_t MemAddSize, uint8_t *pData, uint16_t Size, uint32_t Timeout); |
||
460 | HAL_StatusTypeDef HAL_I2C_IsDeviceReady(I2C_HandleTypeDef *hi2c, uint16_t DevAddress, uint32_t Trials, uint32_t Timeout); |
||
461 | |||
462 | /******* Non-Blocking mode: Interrupt */ |
||
463 | HAL_StatusTypeDef HAL_I2C_Master_Transmit_IT(I2C_HandleTypeDef *hi2c, uint16_t DevAddress, uint8_t *pData, uint16_t Size); |
||
464 | HAL_StatusTypeDef HAL_I2C_Master_Receive_IT(I2C_HandleTypeDef *hi2c, uint16_t DevAddress, uint8_t *pData, uint16_t Size); |
||
465 | HAL_StatusTypeDef HAL_I2C_Slave_Transmit_IT(I2C_HandleTypeDef *hi2c, uint8_t *pData, uint16_t Size); |
||
466 | HAL_StatusTypeDef HAL_I2C_Slave_Receive_IT(I2C_HandleTypeDef *hi2c, uint8_t *pData, uint16_t Size); |
||
467 | HAL_StatusTypeDef HAL_I2C_Mem_Write_IT(I2C_HandleTypeDef *hi2c, uint16_t DevAddress, uint16_t MemAddress, uint16_t MemAddSize, uint8_t *pData, uint16_t Size); |
||
468 | HAL_StatusTypeDef HAL_I2C_Mem_Read_IT(I2C_HandleTypeDef *hi2c, uint16_t DevAddress, uint16_t MemAddress, uint16_t MemAddSize, uint8_t *pData, uint16_t Size); |
||
469 | |||
470 | /******* Non-Blocking mode: DMA */ |
||
471 | HAL_StatusTypeDef HAL_I2C_Master_Transmit_DMA(I2C_HandleTypeDef *hi2c, uint16_t DevAddress, uint8_t *pData, uint16_t Size); |
||
472 | HAL_StatusTypeDef HAL_I2C_Master_Receive_DMA(I2C_HandleTypeDef *hi2c, uint16_t DevAddress, uint8_t *pData, uint16_t Size); |
||
473 | HAL_StatusTypeDef HAL_I2C_Slave_Transmit_DMA(I2C_HandleTypeDef *hi2c, uint8_t *pData, uint16_t Size); |
||
474 | HAL_StatusTypeDef HAL_I2C_Slave_Receive_DMA(I2C_HandleTypeDef *hi2c, uint8_t *pData, uint16_t Size); |
||
475 | HAL_StatusTypeDef HAL_I2C_Mem_Write_DMA(I2C_HandleTypeDef *hi2c, uint16_t DevAddress, uint16_t MemAddress, uint16_t MemAddSize, uint8_t *pData, uint16_t Size); |
||
476 | HAL_StatusTypeDef HAL_I2C_Mem_Read_DMA(I2C_HandleTypeDef *hi2c, uint16_t DevAddress, uint16_t MemAddress, uint16_t MemAddSize, uint8_t *pData, uint16_t Size); |
||
477 | /** |
||
478 | * @} |
||
479 | */ |
||
480 | |||
481 | /** @addtogroup I2C_Exported_Functions_Group4 IRQ Handler and Callbacks |
||
482 | * @{ |
||
483 | */ |
||
484 | /******* I2C IRQHandler and Callbacks used in non blocking modes (Interrupt and DMA) */ |
||
485 | void HAL_I2C_EV_IRQHandler(I2C_HandleTypeDef *hi2c); |
||
486 | void HAL_I2C_ER_IRQHandler(I2C_HandleTypeDef *hi2c); |
||
487 | void HAL_I2C_MasterTxCpltCallback(I2C_HandleTypeDef *hi2c); |
||
488 | void HAL_I2C_MasterRxCpltCallback(I2C_HandleTypeDef *hi2c); |
||
489 | void HAL_I2C_SlaveTxCpltCallback(I2C_HandleTypeDef *hi2c); |
||
490 | void HAL_I2C_SlaveRxCpltCallback(I2C_HandleTypeDef *hi2c); |
||
491 | void HAL_I2C_MemTxCpltCallback(I2C_HandleTypeDef *hi2c); |
||
492 | void HAL_I2C_MemRxCpltCallback(I2C_HandleTypeDef *hi2c); |
||
493 | void HAL_I2C_ErrorCallback(I2C_HandleTypeDef *hi2c); |
||
494 | |||
495 | /** |
||
496 | * @} |
||
497 | */ |
||
498 | |||
499 | |||
500 | /** @addtogroup I2C_Exported_Functions_Group3 Peripheral State and Errors functions |
||
501 | * @{ |
||
502 | */ |
||
503 | |||
504 | /* Peripheral State and Errors functions *************************************/ |
||
505 | HAL_I2C_StateTypeDef HAL_I2C_GetState(I2C_HandleTypeDef *hi2c); |
||
506 | uint32_t HAL_I2C_GetError(I2C_HandleTypeDef *hi2c); |
||
507 | |||
508 | /** |
||
509 | * @} |
||
510 | */ |
||
511 | |||
512 | /** |
||
513 | * @} |
||
514 | */ |
||
515 | |||
516 | /* Private constants ---------------------------------------------------------*/ |
||
517 | /** @defgroup I2C_Private_Constants I2C Private Constants |
||
518 | * @{ |
||
519 | */ |
||
520 | #define I2C_STANDARD_MODE_MAX_CLK ((uint32_t)100000) /* Standard Clock Up to 100kHz */ |
||
521 | #define I2C_FAST_MODE_MAX_CLK ((uint32_t)400000) /* Fast Clock up to 400kHz */ |
||
522 | /** |
||
523 | * @} |
||
524 | */ |
||
525 | |||
526 | /* Private macros ------------------------------------------------------------*/ |
||
527 | /** @defgroup I2C_Private_Macro I2C Private Macros |
||
528 | * @{ |
||
529 | */ |
||
530 | #define IS_I2C_ADDRESSING_MODE(ADDRESS) (((ADDRESS) == I2C_ADDRESSINGMODE_7BIT) || \ |
||
531 | ((ADDRESS) == I2C_ADDRESSINGMODE_10BIT)) |
||
532 | |||
533 | #define IS_I2C_DUAL_ADDRESS(ADDRESS) (((ADDRESS) == I2C_DUALADDRESS_DISABLE) || \ |
||
534 | ((ADDRESS) == I2C_DUALADDRESS_ENABLE)) |
||
535 | |||
536 | #define IS_I2C_GENERAL_CALL(CALL) (((CALL) == I2C_GENERALCALL_DISABLE) || \ |
||
537 | ((CALL) == I2C_GENERALCALL_ENABLE)) |
||
538 | |||
539 | #define IS_I2C_MEMADD_SIZE(SIZE) (((SIZE) == I2C_MEMADD_SIZE_8BIT) || \ |
||
540 | ((SIZE) == I2C_MEMADD_SIZE_16BIT)) |
||
541 | |||
542 | #define IS_I2C_NO_STRETCH(STRETCH) (((STRETCH) == I2C_NOSTRETCH_DISABLE) || \ |
||
543 | ((STRETCH) == I2C_NOSTRETCH_ENABLE)) |
||
544 | |||
545 | #define IS_I2C_OWN_ADDRESS1(ADDRESS1) (((ADDRESS1) & (uint32_t)(0xFFFFFC00)) == 0) |
||
546 | |||
547 | #define IS_I2C_OWN_ADDRESS2(ADDRESS2) (((ADDRESS2) & (uint32_t)(0xFFFFFF01)) == 0) |
||
548 | |||
549 | #define IS_I2C_CLOCK_SPEED(SPEED) (((SPEED) > 0) && ((SPEED) <= I2C_FAST_MODE_MAX_CLK)) |
||
550 | |||
551 | #define IS_I2C_DUTY_CYCLE(CYCLE) (((CYCLE) == I2C_DUTYCYCLE_2) || \ |
||
552 | ((CYCLE) == I2C_DUTYCYCLE_16_9)) |
||
553 | |||
554 | #define I2C_FREQ_RANGE(__PCLK__) ((__PCLK__)/1000000) |
||
555 | #define I2C_RISE_TIME(__FREQRANGE__, __SPEED__) (((__SPEED__) <= I2C_STANDARD_MODE_MAX_CLK) ? ((__FREQRANGE__) + 1) : ((((__FREQRANGE__) * 300) / 1000) + 1)) |
||
556 | |||
557 | #define I2C_SPEED_STANDARD(__PCLK__, __SPEED__) (((((__PCLK__)/((__SPEED__) << 1)) & I2C_CCR_CCR) < 4)? 4:((__PCLK__) / ((__SPEED__) << 1))) |
||
558 | #define I2C_SPEED_FAST(__PCLK__, __SPEED__, __DUTYCYCLE__) (((__DUTYCYCLE__) == I2C_DUTYCYCLE_2)? ((__PCLK__) / ((__SPEED__) * 3)) : (((__PCLK__) / ((__SPEED__) * 25)) | I2C_DUTYCYCLE_16_9)) |
||
559 | #define I2C_SPEED(__PCLK__, __SPEED__, __DUTYCYCLE__) (((__SPEED__) <= 100000)? (I2C_SPEED_STANDARD((__PCLK__), (__SPEED__))) : \ |
||
560 | ((I2C_SPEED_FAST((__PCLK__), (__SPEED__), (__DUTYCYCLE__)) & I2C_CCR_CCR) == 0)? 1 : \ |
||
561 | ((I2C_SPEED_FAST((__PCLK__), (__SPEED__), (__DUTYCYCLE__))) | I2C_CCR_FS)) |
||
562 | |||
563 | #define I2C_MEM_ADD_MSB(__ADDRESS__) ((uint8_t)((uint16_t)(((uint16_t)((__ADDRESS__) & (uint16_t)(0xFF00))) >> 8))) |
||
564 | #define I2C_MEM_ADD_LSB(__ADDRESS__) ((uint8_t)((uint16_t)((__ADDRESS__) & (uint16_t)(0x00FF)))) |
||
565 | |||
566 | #define I2C_7BIT_ADD_WRITE(__ADDRESS__) ((uint8_t)((__ADDRESS__) & (~I2C_OAR1_ADD0))) |
||
567 | #define I2C_7BIT_ADD_READ(__ADDRESS__) ((uint8_t)((__ADDRESS__) | I2C_OAR1_ADD0)) |
||
568 | |||
569 | #define I2C_10BIT_ADDRESS(__ADDRESS__) ((uint8_t)((uint16_t)((__ADDRESS__) & (uint16_t)(0x00FF)))) |
||
570 | #define I2C_10BIT_HEADER_WRITE(__ADDRESS__) ((uint8_t)((uint16_t)((uint16_t)(((uint16_t)((__ADDRESS__) & (uint16_t)(0x0300))) >> 7) | (uint16_t)(0xF0)))) |
||
571 | #define I2C_10BIT_HEADER_READ(__ADDRESS__) ((uint8_t)((uint16_t)((uint16_t)(((uint16_t)((__ADDRESS__) & (uint16_t)(0x0300))) >> 7) | (uint16_t)(0xF1)))) |
||
572 | /** |
||
573 | * @} |
||
574 | */ |
||
575 | |||
576 | /* Private Fonctions ---------------------------------------------------------*/ |
||
577 | /** @defgroup I2C_Private_Functions I2C Private Functions |
||
578 | * @{ |
||
579 | */ |
||
580 | /* Private functions are defined in stm32f1xx_hal_i2c.c file */ |
||
581 | /** |
||
582 | * @} |
||
583 | */ |
||
584 | |||
585 | /** |
||
586 | * @} |
||
587 | */ |
||
588 | |||
589 | /** |
||
590 | * @} |
||
591 | */ |
||
592 | |||
593 | #ifdef __cplusplus |
||
594 | } |
||
595 | #endif |
||
596 | |||
597 | |||
598 | #endif /* __STM32F1xx_HAL_I2C_H */ |
||
599 | |||
600 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ |