1 /* 2 * Copyright 2018-2019 NXP 3 * All rights reserved. 4 * 5 * 6 * SPDX-License-Identifier: BSD-3-Clause 7 */ 8 9 #ifndef __HAL_I2C_ADAPTER_H__ 10 #define __HAL_I2C_ADAPTER_H__ 11 12 /*! 13 * @addtogroup I2C_Adapter 14 * @{ 15 */ 16 17 /******************************************************************************* 18 * Definitions 19 ******************************************************************************/ 20 /*! @brief HAL I2C master handle size. */ 21 #define HAL_I2C_MASTER_HANDLE_SIZE (112U) 22 23 /*! @brief HAL I2C slave handle size. */ 24 #define HAL_I2C_SLAVE_HANDLE_SIZE (144U) 25 26 /*! @brief HAL I2C status. */ 27 typedef enum _hal_i2c_status 28 { 29 kStatus_HAL_I2cSuccess = kStatus_Success, /*!< Successfully */ 30 kStatus_HAL_I2cError = MAKE_STATUS(kStatusGroup_HAL_I2C, 1), /*!< Error occurs on HAL I2C */ 31 kStatus_HAL_I2cBusy = MAKE_STATUS(kStatusGroup_HAL_I2C, 2), /*!< HAL I2C is busy with current transfer */ 32 kStatus_HAL_I2cIdle = MAKE_STATUS(kStatusGroup_HAL_I2C, 3), /*!< HAL I2C transmitter is idle */ 33 kStatus_HAL_I2cNak = MAKE_STATUS(kStatusGroup_HAL_I2C, 4), /*!< NAK received during transfer */ 34 kStatus_HAL_I2cArbitrationLost = MAKE_STATUS(kStatusGroup_HAL_I2C, 5), /*!< Arbitration lost during transfer */ 35 kStatus_HAL_I2cTimeout = MAKE_STATUS(kStatusGroup_HAL_I2C, 6), /*!< Timeout */ 36 kStatus_HAL_I2cAddrressNak = MAKE_STATUS(kStatusGroup_HAL_I2C, 7), /*!< NAK received during the address probe */ 37 } hal_i2c_status_t; 38 39 /*! @brief HAL I2C master user configuration. */ 40 typedef struct _hal_i2c_master_config 41 { 42 uint32_t srcClock_Hz; /*!< Clock source for I2C in Hz */ 43 uint32_t baudRate_Bps; /*!< Baud rate configuration of HAL I2C peripheral. */ 44 bool enableMaster; /*!< Enables the HAL I2C peripheral at initialization time. */ 45 uint8_t instance; /*!< Instance of the i2c */ 46 } hal_i2c_master_config_t; 47 48 /*! @brief HAL I2C slave user configuration. */ 49 typedef struct _hal_i2c_slave_config 50 { 51 uint32_t srcClock_Hz; /*!< Clock source for I2C in Hz */ 52 uint16_t slaveAddress; /*!< A slave address configuration. */ 53 bool enableSlave; /*!< Enables the HAL I2C peripheral at initialization time. */ 54 uint8_t instance; /*!< Instance of the i2c */ 55 } hal_i2c_slave_config_t; 56 57 /*! @brief Direction of master and slave transfers. */ 58 typedef enum _hal_i2c_direction 59 { 60 kHAL_I2cWrite = 0U, /*!< Master transmit. */ 61 kHAL_I2cRead = 1U /*!< Master receive. */ 62 } hal_i2c_direction_t; 63 64 /*! @brief I2C transfer control flag. */ 65 typedef enum _hal_i2c_master_transfer_flag 66 { 67 kHAL_I2cTransferDefaultFlag = 0x0U, /*!< A transfer starts with a start signal, stops with a stop signal. */ 68 kHAL_I2cTransferNoStartFlag = 0x1U, /*!< A transfer starts without a start signal, only support write only or 69 write+read with no start flag, do not support read only with no start flag. */ 70 kHAL_I2cTransferRepeatedStartFlag = 0x2U, /*!< A transfer starts with a repeated start signal. */ 71 kHAL_I2cTransferNoStopFlag = 0x4U, /*!< A transfer ends without a stop signal. */ 72 } hal_i2c_master_transfer_flag_t; 73 74 /*! 75 * @brief Set of events sent to the callback for nonblocking slave transfers. 76 * 77 * These event enumerations are used for two related purposes. First, a bit mask created by OR'ing together 78 * events is passed to I2C_SlaveTransferNonBlocking() to specify which events to enable. 79 * Then, when the slave callback is invoked, it is passed the current event through its @a transfer 80 * parameter. 81 * 82 * @note These enumerations are meant to be OR'd together to form a bit mask of events. 83 */ 84 typedef enum _hal_i2c_slave_transfer_event 85 { 86 kHAL_I2cSlaveAddressMatchEvent = 0x01U, /*!< Received the slave address after a start or repeated start. */ 87 kHAL_I2cSlaveTransmitEvent = 0x02U, /*!< A callback is requested to provide data to transmit 88 (slave-transmitter role). */ 89 kHAL_I2cSlaveReceiveEvent = 0x04U, /*!< A callback is requested to provide a buffer in which to place received 90 data (slave-receiver role). */ 91 kHAL_I2cSlaveTransmitAckEvent = 0x08U, /*!< A callback needs to either transmit an ACK or NACK. */ 92 kHAL_I2cSlaveCompletionEvent = 0x20U, /*!< A stop was detected or finished transfer, completing the transfer. */ 93 kHAL_I2cSlaveStartEvent = 0x10U, /*!< A start/repeated start was detected. */ 94 kHAL_I2cSlaveGenaralcallEvent = 0x40U, /*!< Received the general call address after a start or repeated start. */ 95 /*! A bit mask of all available events. */ 96 kHAL_I2cSlaveAllEvents = kHAL_I2cSlaveAddressMatchEvent | kHAL_I2cSlaveTransmitEvent | kHAL_I2cSlaveReceiveEvent | 97 kHAL_I2cSlaveTransmitAckEvent | kHAL_I2cSlaveCompletionEvent | kHAL_I2cSlaveStartEvent | 98 kHAL_I2cSlaveGenaralcallEvent, 99 } hal_i2c_slave_transfer_event_t; 100 101 /*! @brief HAL I2C master transfer structure. */ 102 typedef struct _hal_i2c_master_transfer 103 { 104 uint8_t *volatile data; /*!< A transfer buffer. */ 105 volatile size_t dataSize; /*!< A transfer size. */ 106 uint32_t flags; /*!< A transfer flag which controls the transfer. */ 107 uint32_t subaddress; /*!< A sub address. Transferred MSB first. */ 108 uint8_t subaddressSize; /*!< A size of the command buffer. */ 109 uint8_t slaveAddress; /*!< 7-bit slave address. */ 110 hal_i2c_direction_t direction; /*!< A transfer direction, read or write. */ 111 } hal_i2c_master_transfer_t; 112 113 /*! @brief HAL I2C slave transfer structure. */ 114 typedef struct _hal_i2c_slave_transfer 115 { 116 hal_i2c_slave_transfer_event_t event; /*!< A reason that the callback is invoked. */ 117 uint8_t *volatile data; /*!< A transfer buffer. */ 118 volatile size_t dataSize; /*!< A transfer size. */ 119 hal_i2c_status_t completionStatus; /*!< Success or error code describing how the transfer completed. Only applies 120 for #kHAL_I2cSlaveCompletionEvent. */ 121 size_t transferredCount; /*!< A number of bytes actually transferred since the start or since the last repeated 122 start. */ 123 } hal_i2c_slave_transfer_t; 124 125 /*! @brief HAL I2C master handle. */ 126 typedef void *hal_i2c_master_handle_t; 127 128 /*! @brief HAL I2C slave handle. */ 129 typedef void *hal_i2c_slave_handle_t; 130 131 /*! 132 * @brief Defines the I2C master handle 133 * 134 * This macro is used to define a 4 byte or 8 byte (aarch64) aligned I2C master handle. 135 * Then use "(hal_i2c_master_handle_t)name" to get the I2C master handle. 136 * 137 * The macro should be global and could be optional. You could also define I2C master handle by yourself. 138 * 139 * This is an example, 140 * @code 141 * HAL_I2C_MASTER_HANDLE_DEFINE(i2cMasterHandle); 142 * @endcode 143 * 144 * @param name The name string of the I2C master handle. 145 */ 146 #define HAL_I2C_MASTER_HANDLE_DEFINE(name) \ 147 uintptr_t name[(HAL_I2C_MASTER_HANDLE_SIZE + sizeof(uintptr_t) - 1U) / sizeof(uintptr_t)] 148 149 /*! 150 * @brief Defines the I2C slave handle 151 * 152 * This macro is used to define a 4 byte or 8 byte (aarch64) aligned I2C slave handle. 153 * Then use "(hal_i2c_slave_handle_t)name" to get the I2C slave handle. 154 * 155 * The macro should be global and could be optional. You could also define I2C slave handle by yourself. 156 * 157 * This is an example, 158 * @code 159 * HAL_I2C_SLAVE_HANDLE_DEFINE(i2cSlaveHandle); 160 * @endcode 161 * 162 * @param name The name string of the I2C slave handle. 163 */ 164 #define HAL_I2C_SLAVE_HANDLE_DEFINE(name) \ 165 uintptr_t name[(HAL_I2C_SLAVE_HANDLE_SIZE + sizeof(uintptr_t) - 1U) / sizeof(uintptr_t)] 166 167 /*! 168 * @brief Master completion callback function pointer type. 169 * 170 * This callback is used only for the non-blocking master transfer API. Specify the callback you wish to use 171 * in the call to HAL_I2cMasterTransferInstallCallback(). 172 * 173 * @param handle i2c master handle pointer, this should be a static variable. 174 * @param completionStatus Either #kStatus_HAL_I2cSuccess or an error code describing how the transfer completed. 175 * @param callbackParam Arbitrary pointer-sized value passed from the application. 176 */ 177 typedef void (*hal_i2c_master_transfer_callback_t)(hal_i2c_master_handle_t handle, 178 hal_i2c_status_t completionStatus, 179 void *callbackParam); 180 181 /*! 182 * @brief Slave event callback function pointer type. 183 * 184 * This callback is used only for the slave non-blocking transfer API. Specify the callback you wish to use 185 * in the call to HAL_I2cSlaveTransferInstallCallback(). 186 * 187 * @param handle i2c slave master handle pointer, this should be a static variable. 188 * @param transfer Pointer to transfer descriptor containing values passed to and/or from the callback. 189 * @param callbackParam Arbitrary pointer-sized value passed from the application. 190 */ 191 typedef void (*hal_i2c_slave_transfer_callback_t)(hal_i2c_slave_handle_t handle, 192 hal_i2c_slave_transfer_t *transfer, 193 void *callbackParam); 194 195 /******************************************************************************* 196 * API 197 ******************************************************************************/ 198 199 #if defined(__cplusplus) 200 extern "C" { 201 #endif /*_cplusplus. */ 202 203 /*! 204 * @name Initialization and de-initialization 205 * @{ 206 */ 207 208 /*! 209 * @brief Initializes the HAL I2C master peripheral. 210 * 211 * @note This API should be called at the beginning of the application. 212 * Otherwise, any operation to the HAL I2C module can cause a hard fault 213 * because the clock is not enabled. This function configures the i2c master 214 * with user-defined settings. The user can configure the configuration 215 * structure. The parameter handle is a pointer to point to a memory space 216 * of size #HAL_I2C_MASTER_HANDLE_SIZE allocated by the caller. 217 * 218 * Example below shows how to use this API to configure the I2C master. 219 * @code 220 * HAL_I2C_MASTER_HANDLE_DEFINE(i2cMasterHandle); 221 * hal_i2c_master_config_t masterConfig; 222 * masterConfig.enableMaster = true; 223 * masterConfig.baudRate_Bps = 100000U; 224 * masterConfig.srcClock_Hz = 12000000U; 225 * masterConfig.instance = 0; 226 * HAL_I2cMasterInit((hal_i2c_master_handle_t)i2cMasterHandle, &masterConfig); 227 * @endcode 228 * 229 * @param handle Pointer to point to a memory space of size #HAL_I2C_MASTER_HANDLE_SIZE allocated by the caller. 230 * The handle should be 4 byte aligned, because unaligned access doesn't be supported on some devices. 231 * You can define the handle in the following two ways: 232 * #HAL_I2C_MASTER_HANDLE_DEFINE(handle); 233 * or 234 * uint32_t handle[((HAL_I2C_MASTER_HANDLE_SIZE + sizeof(uint32_t) - 1U) / sizeof(uint32_t))]; 235 * @param halI2cConfig A pointer to the master configuration structure 236 * @retval kStatus_HAL_I2cError An error occurred. 237 * @retval kStatus_HAL_I2cSuccess i2c master initialization succeed 238 */ 239 hal_i2c_status_t HAL_I2cMasterInit(hal_i2c_master_handle_t handle, const hal_i2c_master_config_t *halI2cConfig); 240 241 /*! 242 * @brief Initializes the HAL I2C peripheral. 243 * 244 * @note This API should be called at the beginning of the application. 245 * Otherwise, any operation to the HAL I2C module can cause a hard fault 246 * because the clock is not enabled. This function configures the i2c slave 247 * with user-defined settings. The user can configure the configuration 248 * structure. The parameter handle is a pointer to point to a memory space 249 * of size #HAL_I2C_SLAVE_HANDLE_SIZE allocated by the caller. 250 * 251 * Example below shows how to use this API to configure the I2C slave. 252 * @code 253 * HAL_I2C_SLAVE_HANDLE_DEFINE(i2cSlaveHandle); 254 * hal_i2c_slave_config_t slaveConfig; 255 * slaveConfig.enableSlave = true; 256 * slaveConfig.slaveAddress = 0x01U; 257 * slaveConfig.srcClock_Hz = 12000000U; 258 * slaveConfig.instance = 0; 259 * HAL_I2cSlaveInit((hal_i2c_slave_handle_t)i2cSlaveHandle, &slaveConfig); 260 * @endcode 261 * 262 * @param handle Pointer to point to a memory space of size #HAL_I2C_SLAVE_HANDLE_SIZE allocated by the caller. 263 * The handle should be 4 byte aligned, because unaligned access doesn't be supported on some devices. 264 * You can define the handle in the following two ways: 265 * #HAL_I2C_SLAVE_HANDLE_DEFINE(handle); 266 * or 267 * uint32_t handle[((HAL_I2C_SLAVE_HANDLE_SIZE + sizeof(uint32_t) - 1U) / sizeof(uint32_t))]; 268 * @param halI2cConfig A pointer to the slave configuration structure 269 * @retval kStatus_HAL_I2cError An error occurred. 270 * @retval kStatus_HAL_I2cSuccess i2c slave initialization succeed 271 */ 272 hal_i2c_status_t HAL_I2cSlaveInit(hal_i2c_slave_handle_t handle, const hal_i2c_slave_config_t *halI2cConfig); 273 274 /*! 275 * @brief De-initializes the HAL I2C master peripheral. Call this API to gate the HAL I2C clock. 276 * The HAL I2C master module can't work unless the HAL_I2cMasterInit is called. 277 * 278 * @param handle i2c master handle pointer, this should be a static variable. 279 * @retval kStatus_HAL_I2cSuccess i2c master de-initialization succeed */ 280 hal_i2c_status_t HAL_I2cMasterDeinit(hal_i2c_master_handle_t handle); 281 282 /*! 283 * @brief De-initializes the HAL I2C slave peripheral. Calling this API gates the HAL I2C clock. 284 * The HAL I2C slave module can't work unless the HAL_I2cSlaveInit is called to enable the clock. 285 * 286 * @param handle i2c slave handle pointer, this should be a static variable. 287 * @retval kStatus_HAL_I2cSuccess i2c slave de-initialization succeed 288 */ 289 hal_i2c_status_t HAL_I2cSlaveDeinit(hal_i2c_slave_handle_t handle); 290 291 /*! @} */ 292 293 /*! 294 * @name Bus Operations 295 * @{ 296 */ 297 298 /*! 299 * @brief Performs a polling send transaction on the HAL I2C bus. 300 * 301 * @param handle i2c master handle pointer, this should be a static variable. 302 * @param txBuff The pointer to the data to be transferred. 303 * @param txSize The length in bytes of the data to be transferred. 304 * @param flags Transfer control flag to decide whether need to send a stop, use kHAL_I2cTransferDefaultFlag 305 * to issue a stop and kHAL_I2cTransferNoStopFlag to not send a stop. 306 * @retval kStatus_HAL_I2cSuccess Successfully complete the data transmission. 307 * @retval kStatus_HAL_I2cArbitrationLost Transfer error, arbitration lost. 308 * @retval kStatus_HAL_I2cNak Transfer error, receive NAK during transfer. 309 */ 310 hal_i2c_status_t HAL_I2cMasterWriteBlocking(hal_i2c_master_handle_t handle, 311 const uint8_t *txBuff, 312 size_t txSize, 313 uint32_t flags); 314 315 /*! 316 * @brief Performs a polling receive transaction on the HAL I2C bus. 317 * 318 * @note The HAL_I2cMasterReadBlocking function stops the bus before reading the final byte. 319 * Without stopping the bus prior for the final read, the bus issues another read, resulting 320 * in garbage data being read into the data register. 321 * 322 * @param handle i2c master handle pointer, this should be a static variable. 323 * @param rxBuff The pointer to the data to store the received data. 324 * @param rxSize The length in bytes of the data to be received. 325 * @param flags Transfer control flag to decide whether need to send a stop, use kHAL_I2cTransferDefaultFlag 326 * to issue a stop and kHAL_I2cTransferNoStopFlag to not send a stop. 327 * @retval kStatus_HAL_I2cSuccess Successfully complete the data transmission. 328 * @retval kStatus_HAL_I2cTimeout Send stop signal failed, timeout. 329 */ 330 hal_i2c_status_t HAL_I2cMasterReadBlocking(hal_i2c_master_handle_t handle, 331 uint8_t *rxBuff, 332 size_t rxSize, 333 uint32_t flags); 334 335 /*! 336 * @brief Performs a polling send transaction on the HAL I2C bus. 337 * 338 * @param handle i2c slave handle pointer, this should be a static variable. 339 * @param txBuff The pointer to the data to be transferred. 340 * @param txSize The length in bytes of the data to be transferred. 341 * @retval kStatus_HAL_I2cSuccess Successfully complete the data transmission. 342 * @retval kStatus_HAL_I2cArbitrationLost Transfer error, arbitration lost. 343 * @retval kStatus_HAL_I2cNak Transfer error, receive NAK during transfer. 344 */ 345 hal_i2c_status_t HAL_I2cSlaveWriteBlocking(hal_i2c_slave_handle_t handle, const uint8_t *txBuff, size_t txSize); 346 347 /*! 348 * @brief Performs a polling receive transaction on the HAL I2C bus. 349 * 350 * @param handle i2c slave handle pointer, this should be a static variable. 351 * @param rxBuff The pointer to the data to store the received data. 352 * @param rxSize The length in bytes of the data to be received. 353 * @retval kStatus_HAL_I2cSuccess Successfully complete data receive. 354 * @retval kStatus_HAL_I2cTimeout Wait status flag timeout. 355 */ 356 hal_i2c_status_t HAL_I2cSlaveReadBlocking(hal_i2c_slave_handle_t handle, uint8_t *rxBuff, size_t rxSize); 357 358 /*! 359 * @brief Performs a master polling transfer on the HAL I2C bus. 360 * 361 * @note The API does not return until the transfer succeeds or fails due 362 * to arbitration lost or receiving a NAK. 363 * 364 * @param handle i2c master handle pointer, this should be a static variable. 365 * @param xfer Pointer to the transfer structure. 366 * @retval kStatus_HAL_I2cSuccess Successfully complete the data transmission. 367 * @retval kStatus_HAL_I2cBusy Previous transmission still not finished. 368 * @retval kStatus_HAL_I2cTimeout Transfer error, wait signal timeout. 369 * @retval kStatus_HAL_I2cArbitrationLost Transfer error, arbitration lost. 370 * @retval kStatus_HAL_I2cNak Transfer error, receive NAK during transfer. 371 */ 372 hal_i2c_status_t HAL_I2cMasterTransferBlocking(hal_i2c_master_handle_t handle, hal_i2c_master_transfer_t *xfer); 373 374 /*! @} */ 375 376 /*! 377 * @name Transactional 378 * @{ 379 */ 380 381 /*! 382 * @brief Installs a callback and callback parameter. 383 * 384 * This function is used to install the callback and callback parameter for i2c master module. 385 * When any status of the i2c master changed, the driver will notify the upper layer by the installed callback 386 * function. And the status is also passed as status parameter when the callback is called. 387 * 388 * @param handle i2c master handle pointer, this should be a static variable. 389 * @param callback pointer to user callback function. 390 * @param callbackParam user parameter passed to the callback function. 391 * @retval kStatus_HAL_I2cSuccess i2c master handle created 392 */ 393 hal_i2c_status_t HAL_I2cMasterTransferInstallCallback(hal_i2c_master_handle_t handle, 394 hal_i2c_master_transfer_callback_t callback, 395 void *callbackParam); 396 397 /*! 398 * @brief Performs a master interrupt non-blocking transfer on the HAL I2C bus. 399 * 400 * @note Calling the API returns immediately after transfer initiates. The user needs 401 * to call HAL_I2cMasterGetTransferCount to poll the transfer status to check whether 402 * the transfer is finished. If the return status is not kStatus_HAL_I2cBusy, the transfer 403 * is finished. 404 * 405 * @param handle i2c master handle pointer, this should be a static variable. 406 * @param xfer pointer to hal_i2c_master_transfer_t structure. 407 * @retval kStatus_HAL_I2cSuccess Successfully start the data transmission. 408 * @retval kStatus_HAL_I2cBusy Previous transmission still not finished. 409 * @retval kStatus_HAL_I2cTimeout Transfer error, wait signal timeout. 410 */ 411 hal_i2c_status_t HAL_I2cMasterTransferNonBlocking(hal_i2c_master_handle_t handle, hal_i2c_master_transfer_t *xfer); 412 413 /*! 414 * @brief Gets the master transfer status during a interrupt non-blocking transfer. 415 * 416 * @param handle i2c master handle pointer, this should be a static variable. 417 * @param count Number of bytes transferred so far by the non-blocking transaction. 418 * @retval kStatus_HAL_I2cError An error occurred. 419 * @retval kStatus_HAL_I2cSuccess Successfully return the count. 420 */ 421 hal_i2c_status_t HAL_I2cMasterTransferGetCount(hal_i2c_master_handle_t handle, size_t *count); 422 423 /*! 424 * @brief Aborts an interrupt non-blocking transfer early. 425 * 426 * @note This API can be called at any time when an interrupt non-blocking transfer initiates 427 * to abort the transfer early. 428 * 429 * @param handle i2c master handle pointer, this should be a static variable. 430 * @retval kStatus_HAL_I2cTimeout Timeout during polling flag. 431 * @retval kStatus_HAL_I2cSuccess Successfully abort the transfer. 432 */ 433 hal_i2c_status_t HAL_I2cMasterTransferAbort(hal_i2c_master_handle_t handle); 434 435 /*! 436 * @brief Installs a callback and callback parameter. 437 * 438 * This function is used to install the callback and callback parameter for i2c slave module. 439 * When any status of the i2c slave changed, the driver will notify the upper layer by the installed callback 440 * function. And the status is also passed as status parameter when the callback is called. 441 * 442 * @param handle i2c slave handle pointer, this should be a static variable. 443 * @param callback pointer to user callback function. 444 * @param callbackParam user parameter passed to the callback function. 445 * @retval kStatus_HAL_I2cSuccess i2c slave handle created 446 */ 447 hal_i2c_status_t HAL_I2cSlaveTransferInstallCallback(hal_i2c_slave_handle_t handle, 448 hal_i2c_slave_transfer_callback_t callback, 449 void *callbackParam); 450 451 /*! 452 * @brief Starts accepting slave transfers. 453 * 454 * Call this API after calling the HAL_I2cSlaveInit() and HAL_I2cSlaveTransferInstallCallback() to start processing 455 * transactions driven by an HAL I2C slave. The slave monitors the HAL I2C bus and passes events to the 456 * callback that was passed into the call to HAL_I2cSlaveTransferInstallCallback(). The callback is always invoked 457 * from the interrupt context. 458 * 459 * The set of events received by the callback is customizable. To do so, set the @a eventMask parameter to 460 * the OR'd combination of #hal_i2c_slave_transfer_event_t enumerators for the events you wish to receive. 461 * The #kHAL_I2cSlaveTransmitEvent and #kHAL_I2cSlaveReceiveEvent events are always enabled and do not need 462 * to be included in the mask. Alternatively, pass 0 to get a default set of only the transmit and 463 * receive events that are always enabled. In addition, the #kHAL_I2cSlaveAllEvents constant is provided as 464 * a convenient way to enable all events. 465 * 466 * @param handle i2c slave handle pointer, this should be a static variable. 467 * @param eventMask Bit mask formed by OR'ing together #hal_i2c_slave_transfer_event_t enumerators to specify 468 * which events to send to the callback. Other accepted values are 0 to get a default set of 469 * only the transmit and receive events, and #kHAL_I2cSlaveAllEvents to enable all events. 470 * 471 * @retval #kStatus_HAL_I2cSuccess Slave transfers were successfully started. 472 * @retval #kStatus_HAL_I2cBusy Slave transfers have already been started on this handle. 473 */ 474 hal_i2c_status_t HAL_I2cSlaveTransferNonBlocking(hal_i2c_slave_handle_t handle, uint32_t eventMask); 475 476 /*! 477 * @brief Aborts the slave transfer. 478 * 479 * @note This API can be called at any time to stop slave for handling the bus events. 480 * 481 * @param handle i2c slave handle pointer, this should be a static variable. 482 * @retval kStatus_HAL_I2cSuccess Successfully return the count. 483 */ 484 hal_i2c_status_t HAL_I2cSlaveTransferAbort(hal_i2c_slave_handle_t handle); 485 486 /*! 487 * @brief Gets the slave transfer remaining bytes during a interrupt non-blocking transfer. 488 * 489 * @param handle i2c slave handle pointer, this should be a static variable. 490 * @param count Number of bytes transferred so far by the non-blocking transaction. 491 * @retval kStatus_HAL_I2cError An error occurred. 492 * @retval kStatus_HAL_I2cSuccess Successfully return the count. 493 */ 494 hal_i2c_status_t HAL_I2cSlaveTransferGetCount(hal_i2c_slave_handle_t handle, size_t *count); 495 496 /*! @} */ 497 #if defined(__cplusplus) 498 } 499 #endif /*_cplusplus. */ 500 /*! @} */ 501 502 #endif /* __HAL_I2C_ADAPTER_H__*/ 503