hal_i2c.h
Go to the documentation of this file.
1 /**
2  ****************************************************************************************
3  *
4  * @file hal_i2c.h
5  * @author BLE Driver Team
6  * @brief Header file containing functions prototypes of I2C HAL library.
7  *
8  ****************************************************************************************
9  * @attention
10  #####Copyright (c) 2019 GOODIX
11  All rights reserved.
12 
13  Redistribution and use in source and binary forms, with or without
14  modification, are permitted provided that the following conditions are met:
15  * Redistributions of source code must retain the above copyright
16  notice, this list of conditions and the following disclaimer.
17  * Redistributions in binary form must reproduce the above copyright
18  notice, this list of conditions and the following disclaimer in the
19  documentation and/or other materials provided with the distribution.
20  * Neither the name of GOODIX nor the names of its contributors may be used
21  to endorse or promote products derived from this software without
22  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
27  ARE DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDERS AND CONTRIBUTORS BE
28  LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
29  CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
30  SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
31  INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
32  CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
33  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
34  POSSIBILITY OF SUCH DAMAGE.
35  ****************************************************************************************
36  */
37 
38 /** @addtogroup PERIPHERAL Peripheral Driver
39  * @{
40  */
41 
42 /** @addtogroup HAL_DRIVER HAL Driver
43  * @{
44  */
45 
46 /** @defgroup HAL_I2C I2C
47  * @brief I2C HAL module driver.
48  * @{
49  */
50 
51 /* Define to prevent recursive inclusion -------------------------------------*/
52 #ifndef HAL_I2C_H
53 #define HAL_I2C_H
54 
55 #ifdef __cplusplus
56 extern "C" {
57 #endif
58 
59 /* Includes ------------------------------------------------------------------*/
60 #include "hal_dma.h"
61 #include "ll_i2c.h"
62 #include "hal_def.h"
63 #include "hal_pwr_mgmt.h"
64 
65 /* Exported types ------------------------------------------------------------*/
66 /** @addtogroup HAL_I2C_ENUMERATIONS Enumerations
67  * @{
68  */
69 
70 /** @defgroup HAL_I2C_state HAL I2C state
71  * @{
72  */
73 
74 /**
75  * @brief HAL I2C State Enumerations definition
76  * @note HAL I2C State value coding follow below described bitmap :\n
77  * @verbatim
78  b7-b6 Error information
79  00 : No Error
80  01 : Abort (Abort user request on going)
81  10 : Timeout
82  11 : Error
83  b5 IP initilisation status
84  0 : Reset (IP not initialized)
85  1 : init done (IP initialized and ready to use. HAL I2C init function called)
86  b4 (not used)
87  x : Should be set to 0
88  b3
89  0 : Ready or Busy (No Listen mode ongoing)
90  1 : Listen (IP in Address Listen Mode)
91  b2 Intrinsic process state
92  0 : Ready
93  1 : Busy (IP busy with some configuration or internal operations)
94  b1 Rx state
95  0 : Ready (no Rx operation ongoing)
96  1 : Busy (Rx operation ongoing)
97  b0 Tx state
98  0 : Ready (no Tx operation ongoing)
99  1 : Busy (Tx operation ongoing)
100  * @endverbatim
101  */
102 typedef enum
103 {
104  HAL_I2C_STATE_RESET = 0x00U, /**< Peripheral is not yet Initialized */
105  HAL_I2C_STATE_READY = 0x20U, /**< Peripheral Initialized and ready for use */
106  HAL_I2C_STATE_BUSY = 0x24U, /**< An internal process is ongoing */
107  HAL_I2C_STATE_BUSY_TX = 0x21U, /**< Data Transmission process is ongoing */
108  HAL_I2C_STATE_BUSY_RX = 0x22U, /**< Data Reception process is ongoing */
109  HAL_I2C_STATE_ABORT = 0x60U, /**< Abort user request ongoing */
110  HAL_I2C_STATE_TIMEOUT = 0xA0U, /**< Timeout state */
111  HAL_I2C_STATE_ERROR = 0xE0U /**< Error */
112 
114 /** @} */
115 
116 /** @defgroup HAL_I2C_mode HAL I2C mode
117  * @{
118  */
119 
120 /**
121  * @brief HAL I2C Mode Enumerations definition
122  * @note HAL I2C Mode value coding follow below described bitmap :\n
123  * @verbatim
124  b7 (not used)
125  x : Should be set to 0
126  b6
127  0 : None
128  1 : Memory (HAL I2C communication is in Memory Mode)
129  b5
130  0 : None
131  1 : Slave (HAL I2C communication is in Slave Mode)
132  b4
133  0 : None
134  1 : Master (HAL I2C communication is in Master Mode)
135  b3-b2-b1-b0 (not used)
136  xxxx : Should be set to 0000
137  * @endverbatim
138  */
139 typedef enum
140 {
141  HAL_I2C_MODE_NONE = 0x00U, /**< No I2C communication on going */
142  HAL_I2C_MODE_MASTER = 0x10U, /**< I2C communication is in Master Mode */
143  HAL_I2C_MODE_SLAVE = 0x20U, /**< I2C communication is in Slave Mode */
145 /** @} */
146 
147 /** @} */
148 
149 
150 /** @addtogroup HAL_I2C_STRUCTURES Structures
151  * @{
152  */
153 
154 /** @defgroup I2C_Configuration I2C Configuration
155  * @{
156  */
157 
158 /**
159  * @brief I2C Configuration Structure definition
160  */
161 typedef struct _i2c_init
162 {
163  uint32_t speed; /**< Specifies the I2C transfer speed.
164  This parameter can be a value of @ref I2C_Speed */
165 
166  uint32_t own_address; /**< Specifies the device own address.
167  This parameter can be a 7-bit or 10-bit address. */
168 
169  uint32_t addressing_mode; /**< Specifies if 7-bit or 10-bit addressing mode is selected.
170  This parameter can be a value of @ref I2C_Addressing_Mode */
171 
172  uint32_t general_call_mode; /**< Specifies if general call mode is selected.
173  This parameter can be a value of @ref I2C_General_Call_Addressing_Mode */
174 
175  uint32_t tx_hold_time; /**< transmit SDA hold time. the unit is ns*/
176 
177  uint32_t rx_hold_time; /**< receive SDA hold time. the unit is ns*/
179 /** @} */
180 
181 /** @defgroup I2C_handle I2C handle
182  * @{
183  */
184 
185 /**
186  * @brief I2C handle Structure definition
187  */
188 typedef struct _i2c_handle
189 {
190  i2c_regs_t *p_instance; /**< I2C registers base address */
191 
192  i2c_init_t init; /**< I2C communication parameters */
193 
194  uint8_t *p_buffer; /**< Pointer to I2C transfer buffer */
195 
196  uint16_t xfer_size; /**< I2C transfer size */
197 
198  __IO uint16_t xfer_count; /**< I2C transfer counter */
199 
200  __IO uint16_t master_ack_count; /**< I2C master acknowledge counter in master receive progress */
201 
202  __IO uint32_t xfer_options; /**< I2C sequantial transfer options, this parameter can
203  be a value of @ref I2C_XferOptions */
204 
205  __IO uint32_t previous_state; /**< I2C communication Previous state */
206 
207  void(*xfer_isr)(struct _i2c_handle *p_i2c, uint32_t it_source, uint32_t abort_sources);
208  /**< I2C transfer IRQ handler function pointer */
209 
210  dma_handle_t *p_dmatx; /**< I2C Tx DMA handle parameters */
211 
212  dma_handle_t *p_dmarx; /**< I2C Rx DMA handle parameters */
213 
214  __IO hal_i2c_state_t state; /**< I2C communication state */
215 
216  __IO hal_i2c_mode_t mode; /**< I2C communication mode */
217 
218  __IO uint32_t error_code; /**< I2C Error code */
219 #ifndef HAL_HW_RES_SUSP_I2C
220  uint32_t retention[13]; /**< I2C important register information. */
221 #endif
223 /** @} */
224 
225 /** @} */
226 
227 /** @addtogroup HAL_I2C_CALLBACK_STRUCTURES Callback Structures
228  * @{
229  */
230 
231 /** @defgroup HAL_I2C_Callback Callback
232  * @{
233  */
234 
235 /**
236  * @brief HAL_I2C Callback function definition
237  */
238 
239 typedef struct _hal_i2c_callback
240 {
241  void (*i2c_msp_init)(i2c_handle_t *p_i2c); /**< I2C init MSP callback */
242  void (*i2c_msp_deinit)(i2c_handle_t *p_i2c); /**< I2C de-init MSP callback */
243  void (*i2c_master_tx_cplt_callback)(i2c_handle_t *p_i2c); /**< I2C master tx transfer completed callbac */
244  void (*i2c_master_rx_cplt_callback)(i2c_handle_t *p_i2c); /**< I2C master rx transfer completed callback */
245  void (*i2c_slave_tx_cplt_callback)(i2c_handle_t *p_i2c); /**< I2C slave tx transfer completed callback */
246  void (*i2c_slave_rx_cplt_callback)(i2c_handle_t *p_i2c); /**< I2C slave rx transfer completed callback */
247  void (*i2c_error_callback)(i2c_handle_t *p_i2c); /**< I2C error callback */
248  void (*i2c_abort_cplt_callback)(i2c_handle_t *p_i2c); /**< I2C abort completed callback */
250 
251 /** @} */
252 
253 /** @} */
254 
255 /** @defgroup HAL_I2C_MACRO Defines
256  * @{
257  */
258 
259 /* Exported constants --------------------------------------------------------*/
260 /** @defgroup I2C_Exported_Constants I2C Exported Constants
261  * @{
262  */
263 
264 /** @defgroup I2C_Error_Code_definition I2C Error Code definition
265  * @{
266  */
267 #define HAL_I2C_ERROR_NONE (0x00000000U) /**< No error */
268 #define HAL_I2C_ERROR_INVALID_PARAM (0x00000001U) /**< Invalid parameter error */
269 #define HAL_I2C_ERROR_ARB_LOST (0x00000002U) /**< Arbitration lost error */
270 #define HAL_I2C_ERROR_NOACK (0x00000004U) /**< No acknowledge error */
271 #define HAL_I2C_ERROR_OVER (0x00000008U) /**< RX_OVER error */
272 #define HAL_I2C_ERROR_SCL_STUCK_AT_LOW (0x00000010U) /**< SCL_STUCK_AT_LOW error */
273 #define HAL_I2C_ERROR_SDA_STUCK_AT_LOW (0x00000020U) /**< SCL_STUCK_AT_LOW error */
274 #define HAL_I2C_ERROR_DMA (0x00000040U) /**< DMA transfer error */
275 #define HAL_I2C_ERROR_TIMEOUT (0x00000080U) /**< Timeout error */
276 #define HAL_I2C_ERROR_NOTE (0x00000100U) /**< No TE error */
277 
278 /** @} */
279 
280 /** @defgroup I2C_Speed I2C Transfer Speed
281  * @{
282  */
283 #define I2C_SPEED_100K LL_I2C_SPEED_100K /**< Standard speed. */
284 #define I2C_SPEED_400K LL_I2C_SPEED_400K /**< Fast speed. */
285 #define I2C_SPEED_1000K LL_I2C_SPEED_1000K /**< Fast Plus speed. */
286 /** @} */
287 
288 /** @defgroup I2C_Addressing_Mode I2C Addressing Mode
289  * @{
290  */
291 #define I2C_ADDRESSINGMODE_7BIT (0x00000001U) /**< 7-bit addressing mode. */
292 #define I2C_ADDRESSINGMODE_10BIT (0x00000002U) /**< 10-bit addressing mode. */
293 /** @} */
294 
295 /** @defgroup I2C_General_Call_Addressing_Mode I2C General Call Addressing Mode
296  * @{
297  */
298 #define I2C_GENERALCALL_DISABLE (0x00000000U) /**< General call mode disable. */
299 #define I2C_GENERALCALL_ENABLE (0x00000001U) /**< General call mode enable. */
300 /** @} */
301 
302 /** @defgroup I2C_Mmmeory_Address_Size I2C Memory Address Size
303  * @{
304  */
305 #define I2C_MEMADD_SIZE_8BIT (0x00000001U) /**< 8-bit memory address. */
306 #define I2C_MEMADD_SIZE_16BIT (0x00000002U) /**< 16-bit memory address. */
307 /** @} */
308 
309 /** @defgroup I2C_XferOptions I2C Sequential Transfer Options
310  * @{
311  */
312 #define I2C_FIRST_FRAME (0x00000000U) /**< First transfer frame. */
313 #define I2C_FIRST_AND_NEXT_FRAME (0x00000001U) /**< First and next transfer frames. */
314 #define I2C_NEXT_FRAME (0x00000002U) /**< Next transfer frame. */
315 #define I2C_FIRST_AND_LAST_FRAME (0x00000003U) /**< First and last transfer frames. */
316 #define I2C_LAST_FRAME (0x00000004U) /**< Last transfer frame. */
317 /** @} */
318 
319 /**
320  * @brief I2C InitStruct default configuartion
321  */
322 #define I2C_DEFAULT_CONFIG \
323 { \
324  .speed = I2C_SPEED_400K, \
325  .own_address = 0x55U, \
326  .addressing_mode = I2C_ADDRESSINGMODE_7BIT, \
327  .general_call_mode = I2C_GENERALCALL_DISABLE, \
328  .tx_hold_time = 1, \
329  .rx_hold_time = 0, \
330 }
331 
332 /** @} */
333 
334 /* Exported macros -----------------------------------------------------------*/
335 /** @defgroup I2C_Exported_Macros I2C Exported Macros
336  * @{
337  */
338 
339 /** @brief Reset I2C handle state.
340  * @param __HANDLE__ Specifies the I2C Handle.
341  * @retval None
342  */
343 #define __HAL_I2C_RESET_HANDLE_STATE(__HANDLE__) ((__HANDLE__)->state = HAL_I2C_STATE_RESET)
344 /** @} */
345 
346 /* Private macros ------------------------------------------------------------*/
347 /** @defgroup I2C_Private_Macro I2C Private Macros
348  * @{
349  */
350 
351 /**
352  * @brief Check if the I2C speed is valid.
353  * @param __SPEED__ I2C transfer speed.
354  * @retval SET (__SPEED__ is valid) or RESET (__SPEED__ is invalid)
355  */
356 #define IS_I2C_SPEED(__SPEED__) (((__SPEED__) == I2C_SPEED_100K) || \
357  ((__SPEED__) == I2C_SPEED_400K) || \
358  ((__SPEED__) == I2C_SPEED_1000K) || \
359  ((__SPEED__) == I2C_SPEED_2000K))
360 
361 /**
362  * @brief Check if the I2C addressing mode is valid.
363  * @param __MODE__ I2C addressing mode.
364  * @retval SET (__MODE__ is valid) or RESET (__MODE__ is invalid)
365  */
366 #define IS_I2C_ADDRESSING_MODE(__MODE__) (((__MODE__) == I2C_ADDRESSINGMODE_7BIT) || \
367  ((__MODE__) == I2C_ADDRESSINGMODE_10BIT))
368 
369 /**
370  * @brief Check if the I2C general call mode is valid.
371  * @param __CALL__ I2C general call mode.
372  * @retval SET (__CALL__ is valid) or RESET (__CALL__ is invalid)
373  */
374 #define IS_I2C_GENERAL_CALL(__CALL__) (((__CALL__) == I2C_GENERALCALL_DISABLE) || \
375  ((__CALL__) == I2C_GENERALCALL_ENABLE))
376 
377 /**
378  * @brief Check if the I2C memory address size is valid.
379  * @param __SIZE__ I2C memory address size.
380  * @retval SET (__SIZE__ is valid) or RESET (__SIZE__ is invalid)
381  */
382 #define IS_I2C_MEMADD_SIZE(__SIZE__) (((__SIZE__) == I2C_MEMADD_SIZE_8BIT) || \
383  ((__SIZE__) == I2C_MEMADD_SIZE_16BIT))
384 
385 /**
386  * @brief Check if the I2C transfer request command is valid.
387  * @param __REQUEST__ I2C transfer request command.
388  * @retval SET (__REQUEST__ is valid) or RESET (__REQUEST__ is invalid)
389  */
390 #define IS_TRANSFER_REQUEST(__REQUEST__) (((__REQUEST__) == I2C_CMD_SLV_NONE) || \
391  ((__REQUEST__) == I2C_CMD_MST_WRITE) || \
392  ((__REQUEST__) == I2C_CMD_MST_READ) || \
393  ((__REQUEST__) == I2C_CMD_MST_GEN_STOP) || \
394  ((__REQUEST__) == I2C_CMD_MST_GEN_RESTART))
395 
396 /**
397  * @brief Check if the I2C transfer options request is valid.
398  * @param __REQUEST__ I2C transfer options request.
399  * @retval SET (__REQUEST__ is valid) or RESET (__REQUEST__ is invalid)
400  */
401 #define IS_I2C_TRANSFER_OPTIONS_REQUEST(__REQUEST__) (((__REQUEST__) == I2C_FIRST_FRAME) || \
402  ((__REQUEST__) == I2C_FIRST_AND_NEXT_FRAME) || \
403  ((__REQUEST__) == I2C_NEXT_FRAME) || \
404  ((__REQUEST__) == I2C_FIRST_AND_LAST_FRAME) || \
405  ((__REQUEST__) == I2C_LAST_FRAME))
406 
407 /**
408  * @brief Check if the I2C slave address is valid.
409  * @param __ADDRESS__ I2C slave address.
410  * @retval SET (__ADDRESS__ is valid) or RESET (__ADDRESS__ is invalid)
411  */
412 #define IS_I2C_SLV_ADDRESS(__ADDRESS__) ((__ADDRESS__) < 0x03FFU)
413 
414 /**
415  * @brief Check if the I2C own address is valid.
416  * @param __ADDRESS__ I2C own address.
417  * @retval SET (__ADDRESS__ is valid) or RESET (__ADDRESS__ is invalid)
418  */
419 #define IS_I2C_OWN_ADDRESS(__ADDRESS__) ((((__ADDRESS__) > 0x0007U) && ((__ADDRESS__) < 0x0078U)) || \
420  (((__ADDRESS__) > 0x007FU) && ((__ADDRESS__) < 0x03FFU)))
421 
422 /**
423  * @brief Get the Most Significant 8 Bits of memory address.
424  * @param __ADDRESS__ Memory address.
425  * @retval SET (__ADDRESS__ is valid) or RESET (__ADDRESS__ is invalid)
426  */
427 #define I2C_MEM_ADD_MSB(__ADDRESS__) ((uint8_t)((uint16_t)(((uint16_t)((__ADDRESS__) & (uint16_t)(0xFF00U))) >> 8U)))
428 
429 /**
430  * @brief Get the Least Significant 8 Bits of memory address.
431  * @param __ADDRESS__ Memory address.
432  * @retval SET (__ADDRESS__ is valid) or RESET (__ADDRESS__ is invalid)
433  */
434 #define I2C_MEM_ADD_LSB(__ADDRESS__) ((uint8_t)((uint16_t)((__ADDRESS__) & (uint16_t)(0x00FFU))))
435 
436 /** @} */
437 
438 /** @} */
439 
440 /* Exported functions --------------------------------------------------------*/
441 /** @addtogroup HAL_I2C_DRIVER_FUNCTIONS Functions
442  * @{
443  */
444 
445 /** @addtogroup I2C_Exported_Functions_Group1 Initialization and de-initialization functions
446  * @brief Initialization and de-initialization functions
447  * @verbatim
448  ===============================================================================
449  ##### Initialization and de-initialization functions #####
450  ===============================================================================
451  [..] This subsection provides a set of functions allowing to initialize and
452  de-initialize the I2Cx peripheral:
453 
454  (+) User must Implement hal_i2c_msp_init() function in which he configures
455  all related peripherals resources (CLOCK, GPIO, DMA, IT and NVIC ).
456 
457  (+) Call the function hal_i2c_init() to configure the selected device with
458  the selected configuration:
459  (++) Speed
460  (++) Own Address
461  (++) Addressing mode (Master, Slave)
462  (++) General call mode
463 
464  (+) Call the function hal_i2c_deinit() to restore the default configuration
465  of the selected I2Cx peripheral.
466 
467 @endverbatim
468  * @{
469  */
470 
471 /**
472  ****************************************************************************************
473  * @brief Initializes the I2C according to the specified parameters
474  * in the i2c_init_t and initialize the associated handle.
475  * @param[in] p_i2c: Pointer to an I2C handle which contains the configuration
476  * information for the specified I2C.
477  * @retval ::HAL_OK: Operation is OK.
478  * @retval ::HAL_ERROR: Parameter error or operation not supported.
479  * @retval ::HAL_BUSY: Driver is busy.
480  * @retval ::HAL_TIMEOUT: Timeout occurred.
481  ****************************************************************************************
482  */
484 
485 /**
486  ****************************************************************************************
487  * @brief De-initialize the I2C peripheral.
488  * @param[in] p_i2c: Pointer to an I2C handle which contains the configuration information for the specified I2C.
489  * @retval ::HAL_OK: Operation is OK.
490  * @retval ::HAL_ERROR: Parameter error or operation not supported.
491  * @retval ::HAL_BUSY: Driver is busy.
492  * @retval ::HAL_TIMEOUT: Timeout occurred.
493  ****************************************************************************************
494  */
496 
497 /**
498  ****************************************************************************************
499  * @brief Initialize the I2C MSP.
500  * @note This function should not be modified. When the callback is needed,
501  * the hal_i2c_msp_init could be implemented in the user file.
502  * @param[in] p_i2c: Pointer to an I2C handle which contains the configuration information for the specified I2C.
503  ****************************************************************************************
504  */
506 
507 /**
508  ****************************************************************************************
509  * @brief De-initialize the I2C MSP.
510  * @note This function should not be modified. When the callback is needed,
511  * the hal_i2c_msp_deinit could be implemented in the user file.
512  * @param[in] p_i2c: Pointer to an I2C handle which contains the configuration information for the specified I2C.
513  ****************************************************************************************
514  */
516 
517 /** @} */
518 
519 /** @addtogroup I2C_Exported_Functions_Group2 IO operation functions
520  * @brief Data transfers functions
521  *
522 @verbatim
523  ===============================================================================
524  ##### IO operation functions #####
525  ===============================================================================
526  [..]
527  This subsection provides a set of functions allowing to manage the I2C data
528  transfers.
529 
530  (#) There are two modes of transfer:
531  (++) Blocking mode: The communication is performed in the polling mode.
532  The status of all data processing is returned by the same function
533  after finishing transfer.
534  (++) No-Blocking mode: The communication is performed using Interrupts
535  or DMA. These functions return the status of the transfer startup.
536  The end of the data processing will be indicated through the
537  dedicated I2C IRQ when using Interrupt mode or the DMA IRQ when
538  using DMA mode.
539 
540  (#) Blocking mode functions are :
541  (++) hal_i2c_master_transmit()
542  (++) hal_i2c_master_receive()
543  (++) hal_i2c_slave_transmit()
544  (++) hal_i2c_slave_receive()
545  (++) hal_i2c_mem_write()
546  (++) hal_i2c_mem_read()
547  (++) hal_i2c_is_device_ready()
548 
549  (#) No-Blocking mode functions with Interrupt are :
550  (++) hal_i2c_master_transmit_it()
551  (++) hal_i2c_master_receive_it()
552  (++) hal_i2c_slave_transmit_it()
553  (++) hal_i2c_slave_receive_it()
554  (++) hal_i2c_mem_write_it()
555  (++) hal_i2c_mem_read_it()
556 
557  (#) No-Blocking mode functions with DMA are :
558  (++) hal_i2c_master_transmit_dma()
559  (++) hal_i2c_master_recevice_dma()
560  (++) hal_i2c_slave_transmit_dma()
561  (++) hal_i2c_slave_receive_dma()
562  (++) hal_i2c_mem_write_dma()
563  (++) hal_i2c_mem_read_dma()
564 
565  (#) A set of Transfer Complete Callbacks are provided in non Blocking mode:
566  (++) hal_i2c_mem_tx_cplt_callback()
567  (++) hal_i2c_mem_rx_cplt_callback()
568  (++) hal_i2c_master_tx_cplt_callback()
569  (++) hal_i2c_master_rx_cplt_callback()
570  (++) hal_i2c_slave_tx_cplt_callback()
571  (++) hal_i2c_slave_rx_cplt_callback()()
572  (++) hal_i2c_error_callback()
573 
574 @endverbatim
575  * @{
576  */
577 
578 /******* Blocking mode: Polling */
579 
580 /**
581  ****************************************************************************************
582  * @brief Transmits in master mode an amount of data in blocking mode.
583  * @param[in] p_i2c: Pointer to an I2C handle which contains the configuration information for the specified I2C.
584  * @param[in] dev_address: Target device address: The device 7 bits address value in datasheet must be shifted at right before call interface
585  * @param[in] p_data: Pointer to data buffer
586  * @param[in] size: Amount of data to be sent
587  * @param[in] timeout: Timeout duration
588  * @retval ::HAL_OK: Operation is OK.
589  * @retval ::HAL_ERROR: Parameter error or operation not supported.
590  * @retval ::HAL_BUSY: Driver is busy.
591  * @retval ::HAL_TIMEOUT: Timeout occurred.
592  ****************************************************************************************
593  */
594 hal_status_t hal_i2c_master_transmit(i2c_handle_t *p_i2c, uint16_t dev_address, uint8_t *p_data, uint16_t size, uint32_t timeout);
595 
596 /**
597  ****************************************************************************************
598  * @brief Receives in master mode an amount of data in blocking mode.
599  * @param[in] p_i2c: Pointer to an I2C handle which contains the configuration information for the specified I2C.
600  * @param[in] dev_address: Target device address: The device 7 bits address value in datasheet must be shifted at right before call interface
601  * @param[in] p_data: Pointer to data buffer
602  * @param[in] size: Amount of data to be sent
603  * @param[in] timeout: Timeout duration
604  * @retval ::HAL_OK: Operation is OK.
605  * @retval ::HAL_ERROR: Parameter error or operation not supported.
606  * @retval ::HAL_BUSY: Driver is busy.
607  * @retval ::HAL_TIMEOUT: Timeout occurred.
608  * @note This function will return HAL_OK even if the length of data sent by slave is
609  * less than the expected Size.
610  ****************************************************************************************
611  */
612 hal_status_t hal_i2c_master_receive(i2c_handle_t *p_i2c, uint16_t dev_address, uint8_t *p_data, uint16_t size, uint32_t timeout);
613 
614 /**
615  ****************************************************************************************
616  * @brief Transmits in slave mode an amount of data in blocking mode.
617  * @param[in] p_i2c: Pointer to an I2C handle which contains the configuration information for the specified I2C.
618  * @param[in] p_data: Pointer to data buffer
619  * @param[in] size: Amount of data to be sent
620  * @param[in] timeout: Timeout duration
621  * @retval ::HAL_OK: Operation is OK.
622  * @retval ::HAL_ERROR: Parameter error or operation not supported.
623  * @retval ::HAL_BUSY: Driver is busy.
624  * @retval ::HAL_TIMEOUT: Timeout occurred.
625  ****************************************************************************************
626  */
627 hal_status_t hal_i2c_slave_transmit(i2c_handle_t *p_i2c, uint8_t *p_data, uint16_t size, uint32_t timeout);
628 
629 /**
630  ****************************************************************************************
631  * @brief Receive in slave mode an amount of data in blocking mode
632  * @param[in] p_i2c: Pointer to an I2C handle which contains the configuration information for the specified I2C.
633  * @param[in] p_data: Pointer to data buffer
634  * @param[in] size: Amount of data to be sent
635  * @param[in] timeout: Timeout duration
636  * @retval ::HAL_OK: Operation is OK.
637  * @retval ::HAL_ERROR: Parameter error or operation not supported.
638  * @retval ::HAL_BUSY: Driver is busy.
639  * @retval ::HAL_TIMEOUT: Timeout occurred.
640  ****************************************************************************************
641  */
642 hal_status_t hal_i2c_slave_receive(i2c_handle_t *p_i2c, uint8_t *p_data, uint16_t size, uint32_t timeout);
643 
644 /**
645  ****************************************************************************************
646  * @brief Write an amount of data in blocking mode to a specific memory address
647  * @param[in] p_i2c: Pointer to an I2C handle which contains the configuration information for the specified I2C.
648  * @param[in] dev_address: Target device address: The device 7 bits address value in datasheet must be shifted at right before call interface
649  * @param[in] mem_address: Internal memory address
650  * @param[in] mem_addr_size: Size of internal memory address
651  * @param[in] p_data: Pointer to data buffer
652  * @param[in] size: Amount of data to be sent
653  * @param[in] timeout: Timeout duration
654  * @retval ::HAL_OK: Operation is OK.
655  * @retval ::HAL_ERROR: Parameter error or operation not supported.
656  * @retval ::HAL_BUSY: Driver is busy.
657  * @retval ::HAL_TIMEOUT: Timeout occurred.
658  ****************************************************************************************
659  */
660 hal_status_t hal_i2c_mem_write(i2c_handle_t *p_i2c, uint16_t dev_address, uint16_t mem_address, uint16_t mem_addr_size, uint8_t *p_data, uint16_t size, uint32_t timeout);
661 
662 /**
663  ****************************************************************************************
664  * @brief Read an amount of data in blocking mode from a specific memory address
665  * @param[in] p_i2c: Pointer to an I2C handle which contains the configuration information for the specified I2C.
666  * @param[in] dev_address: Target device address: The device 7 bits address value in datasheet must be shifted at right before call interface
667  * @param[in] mem_address: Internal memory address
668  * @param[in] mem_addr_size: Size of internal memory address
669  * @param[in] p_data: Pointer to data buffer
670  * @param[in] size: Amount of data to be sent
671  * @param[in] timeout: Timeout duration
672  * @retval ::HAL_OK: Operation is OK.
673  * @retval ::HAL_ERROR: Parameter error or operation not supported.
674  * @retval ::HAL_BUSY: Driver is busy.
675  * @retval ::HAL_TIMEOUT: Timeout occurred.
676  ****************************************************************************************
677  */
678 hal_status_t hal_i2c_mem_read(i2c_handle_t *p_i2c, uint16_t dev_address, uint16_t mem_address, uint16_t mem_addr_size, uint8_t *p_data, uint16_t size, uint32_t timeout);
679 
680 /******* Non-Blocking mode: Interrupt */
681 
682 /**
683  ****************************************************************************************
684  * @brief Transmit in master mode an amount of data in non-blocking mode with Interrupt
685  * @param[in] p_i2c: Pointer to an I2C handle which contains the configuration information for the specified I2C.
686  * @param[in] dev_address: Target device address: The device 7 bits address value in datasheet must be shifted at right before call interface
687  * @param[in] p_data: Pointer to data buffer
688  * @param[in] size: Amount of data to be sent
689  * @retval ::HAL_OK: Operation is OK.
690  * @retval ::HAL_ERROR: Parameter error or operation not supported.
691  * @retval ::HAL_BUSY: Driver is busy.
692  * @retval ::HAL_TIMEOUT: Timeout occurred.
693  ****************************************************************************************
694  */
695 hal_status_t hal_i2c_master_transmit_it(i2c_handle_t *p_i2c, uint16_t dev_address, uint8_t *p_data, uint16_t size);
696 
697 /**
698  ****************************************************************************************
699  * @brief Receive in master mode an amount of data in non-blocking mode with Interrupt
700  * @param[in] p_i2c: Pointer to an I2C handle which contains the configuration information for the specified I2C.
701  * @param[in] dev_address: Target device address: The device 7 bits address value in datasheet must be shifted at right before call interface
702  * @param[in] p_data: Pointer to data buffer
703  * @param[in] size: Amount of data to be sent
704  * @retval ::HAL_OK: Operation is OK.
705  * @retval ::HAL_ERROR: Parameter error or operation not supported.
706  * @retval ::HAL_BUSY: Driver is busy.
707  * @retval ::HAL_TIMEOUT: Timeout occurred.
708  ****************************************************************************************
709  */
710 hal_status_t hal_i2c_master_receive_it(i2c_handle_t *p_i2c, uint16_t dev_address, uint8_t *p_data, uint16_t size);
711 
712 /**
713  ****************************************************************************************
714  * @brief Transmit in slave mode an amount of data in non-blocking mode with Interrupt
715  * @param[in] p_i2c: Pointer to an I2C handle which contains the configuration information for the specified I2C.
716  * @param[in] p_data: Pointer to data buffer
717  * @param[in] size: Amount of data to be sent
718  * @retval ::HAL_OK: Operation is OK.
719  * @retval ::HAL_ERROR: Parameter error or operation not supported.
720  * @retval ::HAL_BUSY: Driver is busy.
721  * @retval ::HAL_TIMEOUT: Timeout occurred.
722  ****************************************************************************************
723  */
724 hal_status_t hal_i2c_slave_transmit_it(i2c_handle_t *p_i2c, uint8_t *p_data, uint16_t size);
725 
726 /**
727  ****************************************************************************************
728  * @brief Receive in slave mode an amount of data in non-blocking mode with Interrupt
729  * @param[in] p_i2c: Pointer to an I2C handle which contains the configuration information for the specified I2C.
730  * @param[in] p_data: Pointer to data buffer
731  * @param[in] size: Amount of data to be sent
732  * @retval ::HAL_OK: Operation is OK.
733  * @retval ::HAL_ERROR: Parameter error or operation not supported.
734  * @retval ::HAL_BUSY: Driver is busy.
735  * @retval ::HAL_TIMEOUT: Timeout occurred.
736  ****************************************************************************************
737  */
738 hal_status_t hal_i2c_slave_receive_it(i2c_handle_t *p_i2c, uint8_t *p_data, uint16_t size);
739 
740 /**
741  ****************************************************************************************
742  * @brief Write an amount of data in non-blocking mode with Interrupt to a specific memory address
743  * @param[in] p_i2c: Pointer to an I2C handle which contains the configuration information for the specified I2C.
744  * @param[in] dev_address: Target device address: The device 7 bits address value in datasheet must be shifted at right before call interface
745  * @param[in] mem_address: Internal memory address
746  * @param[in] mem_addr_size: Size of internal memory address
747  * @param[in] p_data: Pointer to data buffer
748  * @param[in] size: Amount of data to be sent
749  * @retval ::HAL_OK: Operation is OK.
750  * @retval ::HAL_ERROR: Parameter error or operation not supported.
751  * @retval ::HAL_BUSY: Driver is busy.
752  * @retval ::HAL_TIMEOUT: Timeout occurred.
753  ****************************************************************************************
754  */
755 hal_status_t hal_i2c_mem_write_it(i2c_handle_t *p_i2c, uint16_t dev_address, uint16_t mem_address, uint16_t mem_addr_size, uint8_t *p_data, uint16_t size);
756 
757 /**
758  ****************************************************************************************
759  * @brief Read an amount of data in non-blocking mode with Interrupt from a specific memory address
760  * @param[in] p_i2c: Pointer to an I2C handle which contains the configuration information for the specified I2C.
761  * @param[in] dev_address: Target device address: The device 7 bits address value in datasheet must be shifted at right before call interface
762  * @param[in] mem_address: Internal memory address
763  * @param[in] mem_addr_size: Size of internal memory address
764  * @param[in] p_data: Pointer to data buffer
765  * @param[in] size: Amount of data to be sent
766  * @retval ::HAL_OK: Operation is OK.
767  * @retval ::HAL_ERROR: Parameter error or operation not supported.
768  * @retval ::HAL_BUSY: Driver is busy.
769  * @retval ::HAL_TIMEOUT: Timeout occurred.
770  ****************************************************************************************
771  */
772 hal_status_t hal_i2c_mem_read_it(i2c_handle_t *p_i2c, uint16_t dev_address, uint16_t mem_address, uint16_t mem_addr_size, uint8_t *p_data, uint16_t size);
773 
774 /**
775  ****************************************************************************************
776  * @brief Abort a master I2C IT or DMA process communication with Interrupt.
777  * @param[in] p_i2c: Pointer to an I2C handle which contains the configuration information for the specified I2C.
778  * @retval ::HAL_OK: Operation is OK.
779  * @retval ::HAL_ERROR: Parameter error or operation not supported.
780  * @retval ::HAL_BUSY: Driver is busy.
781  * @retval ::HAL_TIMEOUT: Timeout occurred.
782  ****************************************************************************************
783  */
785 
786 /******* Non-Blocking mode: DMA */
787 
788 /**
789  ****************************************************************************************
790  * @brief Transmit in master mode an amount of data in non-blocking mode with DMA
791  * @param[in] p_i2c: Pointer to an I2C handle which contains the configuration information for the specified I2C.
792  * @param[in] dev_address: Target device address: The device 7 bits address value in datasheet must be shifted at right before call interface.
793  * @param[in] p_data: Pointer to data buffer
794  * @param[in] size: Amount of data to be sent, ranging between 0 and 4095.
795  * @retval ::HAL_OK: Operation is OK.
796  * @retval ::HAL_ERROR: Parameter error or operation not supported.
797  * @retval ::HAL_BUSY: Driver is busy.
798  * @retval ::HAL_TIMEOUT: Timeout occurred.
799  ****************************************************************************************
800  */
801 hal_status_t hal_i2c_master_transmit_dma(i2c_handle_t *p_i2c, uint16_t dev_address, uint8_t *p_data, uint16_t size);
802 
803 /**
804  ****************************************************************************************
805  * @brief Receive in master mode an amount of data in non-blocking mode with DMA
806  * @param[in] p_i2c: Pointer to an I2C handle which contains the configuration information for the specified I2C.
807  * @param[in] dev_address: Target device address: The device 7 bits address value in datasheet must be shifted at right before call interface.
808  * @param[in] p_data: Pointer to data buffer
809  * @param[in] size: Amount of data to be sent, ranging between 0 and 4095.
810  * @retval ::HAL_OK: Operation is OK.
811  * @retval ::HAL_ERROR: Parameter error or operation not supported.
812  * @retval ::HAL_BUSY: Driver is busy.
813  * @retval ::HAL_TIMEOUT: Timeout occurred.
814  ****************************************************************************************
815  */
816 hal_status_t hal_i2c_master_receive_dma(i2c_handle_t *p_i2c, uint16_t dev_address, uint8_t *p_data, uint16_t size);
817 
818 /**
819  ****************************************************************************************
820  * @brief Transmit in slave mode an amount of data in non-blocking mode with DMA
821  * @param[in] p_i2c: Pointer to an I2C handle which contains the configuration information for the specified I2C.
822  * @param[in] p_data: Pointer to data buffer
823  * @param[in] size: Amount of data to be sent, ranging between 0 and 4095.
824  * @retval ::HAL_OK: Operation is OK.
825  * @retval ::HAL_ERROR: Parameter error or operation not supported.
826  * @retval ::HAL_BUSY: Driver is busy.
827  * @retval ::HAL_TIMEOUT: Timeout occurred.
828  ****************************************************************************************
829  */
830 hal_status_t hal_i2c_slave_transmit_dma(i2c_handle_t *p_i2c, uint8_t *p_data, uint16_t size);
831 
832 /**
833  ****************************************************************************************
834  * @brief Receive in slave mode an amount of data in non-blocking mode with DMA
835  * @param[in] p_i2c: Pointer to an I2C handle which contains the configuration information for the specified I2C.
836  * @param[in] p_data: Pointer to data buffer
837  * @param[in] size: Amount of data to be sent, ranging between 0 and 4095.
838  * @retval ::HAL_OK: Operation is OK.
839  * @retval ::HAL_ERROR: Parameter error or operation not supported.
840  * @retval ::HAL_BUSY: Driver is busy.
841  * @retval ::HAL_TIMEOUT: Timeout occurred.
842  ****************************************************************************************
843  */
844 hal_status_t hal_i2c_slave_receive_dma(i2c_handle_t *p_i2c, uint8_t *p_data, uint16_t size);
845 
846 /**
847  ****************************************************************************************
848  * @brief Write an amount of data in non-blocking mode with DMA to a specific memory address
849  * @param[in] p_i2c: Pointer to an I2C handle which contains the configuration information for the specified I2C.
850  * @param[in] dev_address: Target device address: The device 7 bits address value in datasheet must be shifted at right before call interface
851  * @param[in] mem_address: Internal memory address
852  * @param[in] mem_addr_size: Size of internal memory address
853  * @param[in] p_data: Pointer to data buffer
854  * @param[in] size: Amount of data to be sent, ranging between 0 and 4095.
855  * @retval ::HAL_OK: Operation is OK.
856  * @retval ::HAL_ERROR: Parameter error or operation not supported.
857  * @retval ::HAL_BUSY: Driver is busy.
858  * @retval ::HAL_TIMEOUT: Timeout occurred.
859  ****************************************************************************************
860  */
861 hal_status_t hal_i2c_mem_write_dma(i2c_handle_t *p_i2c, uint16_t dev_address, uint16_t mem_address, uint16_t mem_addr_size, uint8_t *p_data, uint16_t size);
862 
863 /**
864  ****************************************************************************************
865  * @brief Reads an amount of data in non-blocking mode with DMA from a specific memory address.
866  * @param[in] p_i2c: Pointer to an I2C handle which contains the configuration information for the specified I2C.
867  * @param[in] dev_address: Target device address: The device 7 bits address value in datasheet must be shifted at right before call interface
868  * @param[in] mem_address: Internal memory address
869  * @param[in] mem_addr_size: Size of internal memory address
870  * @param[in] p_data: Pointer to data buffer
871  * @param[in] size: Amount of data to be sent, ranging between 0 and 4095.
872  * @retval ::HAL_OK: Operation is OK.
873  * @retval ::HAL_ERROR: Parameter error or operation not supported.
874  * @retval ::HAL_BUSY: Driver is busy.
875  * @retval ::HAL_TIMEOUT: Timeout occurred.
876  ****************************************************************************************
877  */
878 hal_status_t hal_i2c_mem_read_dma(i2c_handle_t *p_i2c, uint16_t dev_address, uint16_t mem_address, uint16_t mem_addr_size, uint8_t *p_data, uint16_t size);
879 
880 /** @} */
881 
882 /** @addtogroup I2C_IRQ_Handler_and_Callbacks IRQ Handler and Callbacks
883  * @brief IRQ Handler and Callbacks functions
884  * @{
885  */
886 
887 /**
888  ****************************************************************************************
889  * @brief This function handles I2C event interrupt request.
890  * @param[in] p_i2c: Pointer to an I2C handle which contains the configuration information for the specified I2C.
891  ****************************************************************************************
892  */
894 
895 /**
896  ****************************************************************************************
897  * @brief Master Tx Transfer completed callback.
898  * @note This function should not be modified. When the callback is needed,
899  * the hal_i2c_master_tx_cplt_callback can be implemented in the user file
900  * @param[in] p_i2c: Pointer to an I2C handle which contains the configuration information for the specified I2C.
901  ****************************************************************************************
902  */
904 
905 /**
906  ****************************************************************************************
907  * @brief Master Rx Transfer completed callback.
908  * @note This function should not be modified. When the callback is needed,
909  * the hal_i2c_master_rx_cplt_callback can be implemented in the user file
910  * @param[in] p_i2c: Pointer to an I2C handle which contains the configuration information for the specified I2C.
911  ****************************************************************************************
912  */
914 
915 /**
916  ****************************************************************************************
917  * @brief Slave Tx Transfer completed callback.
918  * @note This function should not be modified. When the callback is needed,
919  * the hal_i2c_slave_tx_cplt_callback can be implemented in the user file
920  * @param[in] p_i2c: Pointer to an I2C handle which contains the configuration information for the specified I2C.
921  ****************************************************************************************
922  */
924 
925 /**
926  ****************************************************************************************
927  * @brief Slave Rx Transfer completed callback.
928  * @note This function should not be modified. When the callback is needed,
929  * the hal_i2c_slave_rx_cplt_callback can be implemented in the user file
930  * @param[in] p_i2c: Pointer to an I2C handle which contains the configuration information for the specified I2C.
931  ****************************************************************************************
932  */
934 
935 /**
936  ****************************************************************************************
937  * @brief I2C error callback.
938  * @note This function should not be modified. When the callback is needed,
939  * the hal_i2c_error_callback can be implemented in the user file
940  * @param[in] p_i2c: Pointer to an I2C handle which contains the configuration information for the specified I2C.
941  ****************************************************************************************
942  */
944 
945 /**
946  ****************************************************************************************
947  * @brief I2C abort callback.
948  * @note This function should not be modified. When the callback is needed,
949  * the hal_i2c_abort_cplt_callback can be implemented in the user file
950  * @param[in] p_i2c: Pointer to an I2C handle which contains the configuration information for the specified I2C.
951  ****************************************************************************************
952  */
954 
955 /** @} */
956 
957 /** @addtogroup I2C_Exported_Functions_Group3 Peripheral State, Mode and Error functions
958  * @brief Peripheral State, Mode and Error functions
959  *
960 @verbatim
961  ===============================================================================
962  ##### Peripheral State, Mode and Error functions #####
963  ===============================================================================
964  [..]
965  This subsection permit to get in run-time the status of the peripheral
966  and the data flow.
967 
968 @endverbatim
969  * @{
970  */
971 
972 /**
973  ****************************************************************************************
974  * @brief Return the I2C handle state.
975  * @param[in] p_i2c: Pointer to an I2C handle which contains the configuration information for the specified I2C.
976  * @retval ::HAL_I2C_STATE_RESET: Peripheral is not yet Initialized.
977  * @retval ::HAL_I2C_STATE_READY: Peripheral Initialized and ready for use.
978  * @retval ::HAL_I2C_STATE_BUSY: An internal process is ongoing.
979  * @retval ::HAL_I2C_STATE_BUSY_TX: Data Transmission process is ongoing.
980  * @retval ::HAL_I2C_STATE_BUSY_RX: Data Reception process is ongoing.
981  * @retval ::HAL_I2C_STATE_LISTEN: Address Listen Mode is ongoing.
982  * @retval ::HAL_I2C_STATE_BUSY_TX_LISTEN: Address Listen Mode and Data Transmission process is ongoing.
983  * @retval ::HAL_I2C_STATE_BUSY_RX_LISTEN: Address Listen Mode and Data Reception process is ongoing.
984  * @retval ::HAL_I2C_STATE_ABORT: Abort user request ongoing.
985  * @retval ::HAL_I2C_STATE_TIMEOUT: Timeout state.
986  * @retval ::HAL_I2C_STATE_ERROR: Error.
987  ****************************************************************************************
988  */
990 
991 /**
992  ****************************************************************************************
993  * @brief Returns the I2C Master, Slave, Memory or no mode.
994  * @param[in] p_i2c: Pointer to an I2C handle which contains the configuration information for the specified I2C.
995  * @retval ::HAL_I2C_MODE_NONE: No I2C communication on going.
996  * @retval ::HAL_I2C_MODE_MASTER: I2C communication is in Master Mode.
997  * @retval ::HAL_I2C_MODE_SLAVE: I2C communication is in Slave Mode.
998  * @retval ::HAL_I2C_MODE_MEM: I2C communication is in Memory Mode.
999  ****************************************************************************************
1000  */
1002 
1003 /**
1004  ****************************************************************************************
1005  * @brief Return the I2C error code.
1006  * @param[in] p_i2c: Pointer to an I2C handle which contains the configuration information for the specified I2C.
1007  * @return I2C Error Code
1008  ****************************************************************************************
1009  */
1010 uint32_t hal_i2c_get_error(const i2c_handle_t *p_i2c);
1011 
1012 /**
1013  ****************************************************************************************
1014  * @brief Return i2c sda at low is not recovered flag.
1015  * @param[in] p_i2c: Pointer to an I2C handle which contains the configuration information for the specified I2C.
1016  * @retval 1: i2c sda at low is not recovered.
1017  * @retval 0: i2c sda at low is recovered.
1018  ****************************************************************************************
1019  */
1021 
1022 /**
1023  ****************************************************************************************
1024  * @brief Suspend some registers related to I2C configuration before sleep.
1025  * @param[in] p_i2c: Pointer to a I2C handle which contains the configuration
1026  * information for the specified I2C module.
1027  * @retval None
1028  ****************************************************************************************
1029  */
1031 
1032 /**
1033  ****************************************************************************************
1034  * @brief Restore some registers related to I2C configuration after sleep.
1035  * This function must be used in conjunction with the hal_i2c_suspend_reg().
1036  * @param[in] p_i2c: Pointer to a I2C handle which contains the configuration
1037  * information for the specified I2C module.
1038  * @retval None
1039  ****************************************************************************************
1040  */
1042 
1043 #ifdef HAL_PM_ENABLE
1044 /**
1045  ****************************************************************************************
1046  * @brief Suspend the specified I2C.
1047  * @param[in] p_i2c: Pointer to a I2C handle
1048  * @retval ::HAL_PM_ACTIVE: Device is active, not allow sleep.
1049  * @retval ::HAL_PM_SLEEP: Allow sleep.
1050  ****************************************************************************************
1051  */
1053 
1054 /**
1055  ****************************************************************************************
1056  * @brief Resume the specified I2C
1057  * @param[in] p_i2c: Pointer to a I2C handle
1058  * @retval ::None
1059  ****************************************************************************************
1060  */
1062 #endif /* HAL_PM_ENABLE */
1063 
1064 /**
1065  ****************************************************************************************
1066  * @brief Configure the I2C transmit rate for I2C.
1067  * @param[in] p_i2c: Pointer to a I2C handle which contains the configuration
1068  * information for the specified I2C module.
1069  * @param[in] speed: The transmit rate of I2C.
1070  * @param[in] scl_fall_time: The fall time of scl.
1071  * @param[in] scl_rise_time: The rise time of scl.
1072  * @retval ::HAL_OK: Operation is OK.
1073  * @retval ::HAL_ERROR: Parameter error or operation not supported.
1074  * @retval ::HAL_BUSY: Driver is busy.
1075  ****************************************************************************************
1076  */
1077 hal_status_t hal_i2c_speed_config(i2c_handle_t *p_i2c, uint32_t speed, uint32_t scl_fall_time, uint32_t scl_rise_time);
1078 
1079 /** @} */
1080 
1081 /** @} */
1082 
1083 #ifdef __cplusplus
1084 }
1085 #endif
1086 
1087 #endif /* HAL_I2C_H */
1088 
1089 /** @} */
1090 
1091 /** @} */
1092 
1093 /** @} */
_hal_i2c_callback::i2c_msp_init
void(* i2c_msp_init)(i2c_handle_t *p_i2c)
Definition: hal_i2c.h:241
_hal_i2c_callback::i2c_slave_tx_cplt_callback
void(* i2c_slave_tx_cplt_callback)(i2c_handle_t *p_i2c)
Definition: hal_i2c.h:245
hal_i2c_suspend_reg
void hal_i2c_suspend_reg(i2c_handle_t *p_i2c)
Suspend some registers related to I2C configuration before sleep.
hal_i2c_mem_read_it
hal_status_t hal_i2c_mem_read_it(i2c_handle_t *p_i2c, uint16_t dev_address, uint16_t mem_address, uint16_t mem_addr_size, uint8_t *p_data, uint16_t size)
Read an amount of data in non-blocking mode with Interrupt from a specific memory address.
hal_i2c_deinit
hal_status_t hal_i2c_deinit(i2c_handle_t *p_i2c)
De-initialize the I2C peripheral.
HAL_I2C_MODE_SLAVE
@ HAL_I2C_MODE_SLAVE
Definition: hal_i2c.h:143
hal_i2c_resume_reg
void hal_i2c_resume_reg(i2c_handle_t *p_i2c)
Restore some registers related to I2C configuration after sleep. This function must be used in conjun...
hal_i2c_master_receive_dma
hal_status_t hal_i2c_master_receive_dma(i2c_handle_t *p_i2c, uint16_t dev_address, uint8_t *p_data, uint16_t size)
Receive in master mode an amount of data in non-blocking mode with DMA.
hal_pwr_mgmt.h
This file contains all the functions prototypes for the HAL module driver.
HAL_I2C_STATE_READY
@ HAL_I2C_STATE_READY
Definition: hal_i2c.h:105
hal_i2c_init
hal_status_t hal_i2c_init(i2c_handle_t *p_i2c)
Initializes the I2C according to the specified parameters in the i2c_init_t and initialize the associ...
_i2c_handle::xfer_size
uint16_t xfer_size
Definition: hal_i2c.h:196
_i2c_handle::init
i2c_init_t init
Definition: hal_i2c.h:192
hal_i2c_slave_receive_it
hal_status_t hal_i2c_slave_receive_it(i2c_handle_t *p_i2c, uint8_t *p_data, uint16_t size)
Receive in slave mode an amount of data in non-blocking mode with Interrupt.
hal_i2c_master_receive
hal_status_t hal_i2c_master_receive(i2c_handle_t *p_i2c, uint16_t dev_address, uint8_t *p_data, uint16_t size, uint32_t timeout)
Receives in master mode an amount of data in blocking mode.
HAL_I2C_STATE_RESET
@ HAL_I2C_STATE_RESET
Definition: hal_i2c.h:104
hal_i2c_master_tx_cplt_callback
void hal_i2c_master_tx_cplt_callback(i2c_handle_t *p_i2c)
Master Tx Transfer completed callback.
_i2c_init::own_address
uint32_t own_address
Definition: hal_i2c.h:166
_i2c_handle::p_dmarx
dma_handle_t * p_dmarx
Definition: hal_i2c.h:212
_i2c_init
I2C Configuration Structure definition.
Definition: hal_i2c.h:162
hal_i2c_callback_t
struct _hal_i2c_callback hal_i2c_callback_t
HAL_I2C Callback function definition.
hal_i2c_slave_receive_dma
hal_status_t hal_i2c_slave_receive_dma(i2c_handle_t *p_i2c, uint8_t *p_data, uint16_t size)
Receive in slave mode an amount of data in non-blocking mode with DMA.
_i2c_handle
I2C handle Structure definition.
Definition: hal_i2c.h:189
_i2c_handle::previous_state
__IO uint32_t previous_state
Definition: hal_i2c.h:205
_i2c_handle::xfer_isr
void(* xfer_isr)(struct _i2c_handle *p_i2c, uint32_t it_source, uint32_t abort_sources)
Definition: hal_i2c.h:207
hal_i2c_mem_write_it
hal_status_t hal_i2c_mem_write_it(i2c_handle_t *p_i2c, uint16_t dev_address, uint16_t mem_address, uint16_t mem_addr_size, uint8_t *p_data, uint16_t size)
Write an amount of data in non-blocking mode with Interrupt to a specific memory address.
hal_pm_status_t
hal_pm_status_t
Definition: hal_pwr_mgmt.h:59
_hal_i2c_callback
HAL_I2C Callback function definition.
Definition: hal_i2c.h:240
hal_i2c_master_transmit_it
hal_status_t hal_i2c_master_transmit_it(i2c_handle_t *p_i2c, uint16_t dev_address, uint8_t *p_data, uint16_t size)
Transmit in master mode an amount of data in non-blocking mode with Interrupt.
_hal_i2c_callback::i2c_error_callback
void(* i2c_error_callback)(i2c_handle_t *p_i2c)
Definition: hal_i2c.h:247
hal_i2c_slave_transmit_dma
hal_status_t hal_i2c_slave_transmit_dma(i2c_handle_t *p_i2c, uint8_t *p_data, uint16_t size)
Transmit in slave mode an amount of data in non-blocking mode with DMA.
i2c_init_t
struct _i2c_init i2c_init_t
I2C Configuration Structure definition.
hal_i2c_speed_config
hal_status_t hal_i2c_speed_config(i2c_handle_t *p_i2c, uint32_t speed, uint32_t scl_fall_time, uint32_t scl_rise_time)
Configure the I2C transmit rate for I2C.
_hal_i2c_callback::i2c_abort_cplt_callback
void(* i2c_abort_cplt_callback)(i2c_handle_t *p_i2c)
Definition: hal_i2c.h:248
i2c_handle_t
struct _i2c_handle i2c_handle_t
I2C handle Structure definition.
hal_i2c_master_transmit_dma
hal_status_t hal_i2c_master_transmit_dma(i2c_handle_t *p_i2c, uint16_t dev_address, uint8_t *p_data, uint16_t size)
Transmit in master mode an amount of data in non-blocking mode with DMA.
_hal_i2c_callback::i2c_slave_rx_cplt_callback
void(* i2c_slave_rx_cplt_callback)(i2c_handle_t *p_i2c)
Definition: hal_i2c.h:246
_hal_i2c_callback::i2c_msp_deinit
void(* i2c_msp_deinit)(i2c_handle_t *p_i2c)
Definition: hal_i2c.h:242
_i2c_init::tx_hold_time
uint32_t tx_hold_time
Definition: hal_i2c.h:175
HAL_I2C_MODE_MASTER
@ HAL_I2C_MODE_MASTER
Definition: hal_i2c.h:142
_i2c_handle::error_code
__IO uint32_t error_code
Definition: hal_i2c.h:218
hal_i2c_mem_read_dma
hal_status_t hal_i2c_mem_read_dma(i2c_handle_t *p_i2c, uint16_t dev_address, uint16_t mem_address, uint16_t mem_addr_size, uint8_t *p_data, uint16_t size)
Reads an amount of data in non-blocking mode with DMA from a specific memory address.
hal_i2c_get_state
hal_i2c_state_t hal_i2c_get_state(const i2c_handle_t *p_i2c)
Return the I2C handle state.
hal_i2c_slave_rx_cplt_callback
void hal_i2c_slave_rx_cplt_callback(i2c_handle_t *p_i2c)
Slave Rx Transfer completed callback.
_i2c_handle::p_dmatx
dma_handle_t * p_dmatx
Definition: hal_i2c.h:210
HAL_I2C_STATE_BUSY_RX
@ HAL_I2C_STATE_BUSY_RX
Definition: hal_i2c.h:108
_i2c_handle::mode
__IO hal_i2c_mode_t mode
Definition: hal_i2c.h:216
HAL_I2C_STATE_BUSY_TX
@ HAL_I2C_STATE_BUSY_TX
Definition: hal_i2c.h:107
hal_i2c_state_t
hal_i2c_state_t
HAL I2C State Enumerations definition.
Definition: hal_i2c.h:103
_i2c_handle::state
__IO hal_i2c_state_t state
Definition: hal_i2c.h:214
_i2c_init::rx_hold_time
uint32_t rx_hold_time
Definition: hal_i2c.h:177
_i2c_init::general_call_mode
uint32_t general_call_mode
Definition: hal_i2c.h:172
hal_i2c_slave_transmit
hal_status_t hal_i2c_slave_transmit(i2c_handle_t *p_i2c, uint8_t *p_data, uint16_t size, uint32_t timeout)
Transmits in slave mode an amount of data in blocking mode.
hal_i2c_master_rx_cplt_callback
void hal_i2c_master_rx_cplt_callback(i2c_handle_t *p_i2c)
Master Rx Transfer completed callback.
hal_i2c_slave_receive
hal_status_t hal_i2c_slave_receive(i2c_handle_t *p_i2c, uint8_t *p_data, uint16_t size, uint32_t timeout)
Receive in slave mode an amount of data in blocking mode.
HAL_I2C_STATE_TIMEOUT
@ HAL_I2C_STATE_TIMEOUT
Definition: hal_i2c.h:110
hal_i2c_slave_transmit_it
hal_status_t hal_i2c_slave_transmit_it(i2c_handle_t *p_i2c, uint8_t *p_data, uint16_t size)
Transmit in slave mode an amount of data in non-blocking mode with Interrupt.
_i2c_handle::retention
uint32_t retention[13]
Definition: hal_i2c.h:220
hal_i2c_irq_handler
void hal_i2c_irq_handler(i2c_handle_t *p_i2c)
This function handles I2C event interrupt request.
_hal_i2c_callback::i2c_master_rx_cplt_callback
void(* i2c_master_rx_cplt_callback)(i2c_handle_t *p_i2c)
Definition: hal_i2c.h:244
_hal_i2c_callback::i2c_master_tx_cplt_callback
void(* i2c_master_tx_cplt_callback)(i2c_handle_t *p_i2c)
Definition: hal_i2c.h:243
ll_i2c.h
Header file containing functions prototypes of I2C LL library.
hal_i2c_mode_t
hal_i2c_mode_t
HAL I2C Mode Enumerations definition.
Definition: hal_i2c.h:140
hal_status_t
hal_status_t
HAL Status structures definition.
Definition: gr_common.h:140
hal_i2c_master_abort_it
hal_status_t hal_i2c_master_abort_it(i2c_handle_t *p_i2c)
Abort a master I2C IT or DMA process communication with Interrupt.
hal_def.h
This file contains HAL common definitions, enumeration, macros and structures definitions.
_i2c_init::speed
uint32_t speed
Definition: hal_i2c.h:163
hal_i2c_mem_write_dma
hal_status_t hal_i2c_mem_write_dma(i2c_handle_t *p_i2c, uint16_t dev_address, uint16_t mem_address, uint16_t mem_addr_size, uint8_t *p_data, uint16_t size)
Write an amount of data in non-blocking mode with DMA to a specific memory address.
_i2c_init::addressing_mode
uint32_t addressing_mode
Definition: hal_i2c.h:169
hal_i2c_mem_write
hal_status_t hal_i2c_mem_write(i2c_handle_t *p_i2c, uint16_t dev_address, uint16_t mem_address, uint16_t mem_addr_size, uint8_t *p_data, uint16_t size, uint32_t timeout)
Write an amount of data in blocking mode to a specific memory address.
hal_i2c_get_error
uint32_t hal_i2c_get_error(const i2c_handle_t *p_i2c)
Return the I2C error code.
hal_i2c_mem_read
hal_status_t hal_i2c_mem_read(i2c_handle_t *p_i2c, uint16_t dev_address, uint16_t mem_address, uint16_t mem_addr_size, uint8_t *p_data, uint16_t size, uint32_t timeout)
Read an amount of data in blocking mode from a specific memory address.
hal_i2c_get_mode
hal_i2c_mode_t hal_i2c_get_mode(const i2c_handle_t *p_i2c)
Returns the I2C Master, Slave, Memory or no mode.
HAL_I2C_STATE_ABORT
@ HAL_I2C_STATE_ABORT
Definition: hal_i2c.h:109
hal_i2c_master_transmit
hal_status_t hal_i2c_master_transmit(i2c_handle_t *p_i2c, uint16_t dev_address, uint8_t *p_data, uint16_t size, uint32_t timeout)
Transmits in master mode an amount of data in blocking mode.
hal_i2c_msp_init
void hal_i2c_msp_init(i2c_handle_t *p_i2c)
Initialize the I2C MSP.
hal_i2c_error_callback
void hal_i2c_error_callback(i2c_handle_t *p_i2c)
I2C error callback.
hal_i2c_master_receive_it
hal_status_t hal_i2c_master_receive_it(i2c_handle_t *p_i2c, uint16_t dev_address, uint8_t *p_data, uint16_t size)
Receive in master mode an amount of data in non-blocking mode with Interrupt.
hal_dma.h
Header file containing functions prototypes of DMA HAL library.
HAL_I2C_STATE_ERROR
@ HAL_I2C_STATE_ERROR
Definition: hal_i2c.h:111
_i2c_handle::p_instance
i2c_regs_t * p_instance
Definition: hal_i2c.h:190
hal_i2c_sda_at_low_is_not_recovered
uint32_t hal_i2c_sda_at_low_is_not_recovered(const i2c_handle_t *p_i2c)
Return i2c sda at low is not recovered flag.
hal_i2c_abort_cplt_callback
void hal_i2c_abort_cplt_callback(i2c_handle_t *p_i2c)
I2C abort callback.
_i2c_handle::xfer_options
__IO uint32_t xfer_options
Definition: hal_i2c.h:202
hal_i2c_slave_tx_cplt_callback
void hal_i2c_slave_tx_cplt_callback(i2c_handle_t *p_i2c)
Slave Tx Transfer completed callback.
_i2c_handle::master_ack_count
__IO uint16_t master_ack_count
Definition: hal_i2c.h:200
hal_i2c_msp_deinit
void hal_i2c_msp_deinit(i2c_handle_t *p_i2c)
De-initialize the I2C MSP.
_i2c_handle::p_buffer
uint8_t * p_buffer
Definition: hal_i2c.h:194
hal_pm_i2c_resume
void hal_pm_i2c_resume(i2c_handle_t *p_i2c)
Resume the specified I2C.
_dma_handle
DMA handle Structure definition.
Definition: hal_dma.h:195
HAL_I2C_MODE_NONE
@ HAL_I2C_MODE_NONE
Definition: hal_i2c.h:141
_i2c_handle::xfer_count
__IO uint16_t xfer_count
Definition: hal_i2c.h:198
hal_pm_i2c_suspend
hal_pm_status_t hal_pm_i2c_suspend(i2c_handle_t *p_i2c)
Suspend the specified I2C.
HAL_I2C_STATE_BUSY
@ HAL_I2C_STATE_BUSY
Definition: hal_i2c.h:106