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