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