1 /*
2  * Copyright (c) 2016, Freescale Semiconductor, Inc.
3  * Copyright 2016-2020 NXP
4  * All rights reserved.
5  *
6  * SPDX-License-Identifier: BSD-3-Clause
7  */
8 #ifndef FSL_I2C_H_
9 #define FSL_I2C_H_
10 
11 #include "fsl_common.h"
12 
13 /*!
14  * @addtogroup i2c_driver
15  * @{
16  */
17 
18 /*******************************************************************************
19  * Definitions
20  ******************************************************************************/
21 
22 /*! @name Driver version */
23 /*! @{ */
24 /*! @brief I2C driver version. */
25 #define FSL_I2C_DRIVER_VERSION (MAKE_VERSION(2, 0, 7))
26 /*! @} */
27 
28 /*! @brief Retry times for waiting flag. */
29 #ifndef I2C_RETRY_TIMES
30 #define I2C_RETRY_TIMES 0U /* Define to zero means keep waiting until the flag is assert/deassert. */
31 #endif
32 
33 /*! @brief  I2C status return codes. */
34 enum
35 {
36     kStatus_I2C_Busy            = MAKE_STATUS(kStatusGroup_I2C, 0), /*!< I2C is busy with current transfer. */
37     kStatus_I2C_Idle            = MAKE_STATUS(kStatusGroup_I2C, 1), /*!< Bus is Idle. */
38     kStatus_I2C_Nak             = MAKE_STATUS(kStatusGroup_I2C, 2), /*!< NAK received during transfer. */
39     kStatus_I2C_ArbitrationLost = MAKE_STATUS(kStatusGroup_I2C, 3), /*!< Arbitration lost during transfer. */
40     kStatus_I2C_Timeout         = MAKE_STATUS(kStatusGroup_I2C, 4), /*!< Timeout polling status flags. */
41     kStatus_I2C_Addr_Nak        = MAKE_STATUS(kStatusGroup_I2C, 5), /*!< NAK received during the address probe. */
42 };
43 
44 /*!
45  * @brief I2C peripheral flags
46  *
47  * The following status register flags can be cleared:
48  * - #kI2C_ArbitrationLostFlag
49  * - #kI2C_IntPendingFlag
50  *
51  * @note These enumerations are meant to be OR'd together to form a bit mask.
52  *
53  */
54 enum _i2c_flags
55 {
56     kI2C_ReceiveNakFlag        = I2C_I2SR_RXAK_MASK, /*!< I2C receive NAK flag. */
57     kI2C_IntPendingFlag        = I2C_I2SR_IIF_MASK,  /*!< I2C interrupt pending flag. */
58     kI2C_TransferDirectionFlag = I2C_I2SR_SRW_MASK,  /*!< I2C transfer direction flag. */
59     kI2C_ArbitrationLostFlag   = I2C_I2SR_IAL_MASK,  /*!< I2C arbitration lost flag. */
60     kI2C_BusBusyFlag           = I2C_I2SR_IBB_MASK,  /*!< I2C bus busy flag. */
61     kI2C_AddressMatchFlag      = I2C_I2SR_IAAS_MASK, /*!< I2C address match flag. */
62     kI2C_TransferCompleteFlag  = I2C_I2SR_ICF_MASK,
63     /*!< I2C transfer complete flag. */
64 };
65 
66 /*! @brief I2C feature interrupt source. */
67 enum _i2c_interrupt_enable
68 {
69     kI2C_GlobalInterruptEnable = I2C_I2CR_IIEN_MASK, /*!< I2C global interrupt. */
70 };
71 
72 /*! @brief The direction of master and slave transfers. */
73 typedef enum _i2c_direction
74 {
75     kI2C_Write = 0x0U, /*!< Master transmits to the slave. */
76     kI2C_Read  = 0x1U, /*!< Master receives from the slave. */
77 } i2c_direction_t;
78 
79 /*! @brief I2C transfer control flag. */
80 enum _i2c_master_transfer_flags
81 {
82     kI2C_TransferDefaultFlag = 0x0U,       /*!< A transfer starts with a start signal, stops with a stop signal. */
83     kI2C_TransferNoStartFlag = 0x1U,       /*!< A transfer starts without a start signal, only support write only or
84                                         write+read with no start flag, do not support read only with no start flag. */
85     kI2C_TransferRepeatedStartFlag = 0x2U, /*!< A transfer starts with a repeated start signal. */
86     kI2C_TransferNoStopFlag        = 0x4U, /*!< A transfer ends without a stop signal. */
87 };
88 
89 /*! @brief I2C master user configuration. */
90 typedef struct _i2c_master_config
91 {
92     bool enableMaster;     /*!< Enables the I2C peripheral at initialization time. */
93     uint32_t baudRate_Bps; /*!< Baud rate configuration of I2C peripheral. */
94 } i2c_master_config_t;
95 
96 /*! @brief I2C master handle typedef. */
97 typedef struct _i2c_master_handle i2c_master_handle_t;
98 
99 /*! @brief I2C master transfer callback typedef. */
100 typedef void (*i2c_master_transfer_callback_t)(I2C_Type *base,
101                                                i2c_master_handle_t *handle,
102                                                status_t status,
103                                                void *userData);
104 
105 /*! @brief I2C master transfer structure. */
106 typedef struct _i2c_master_transfer
107 {
108     uint32_t flags;            /*!< A transfer flag which controls the transfer. */
109     uint8_t slaveAddress;      /*!< 7-bit slave address. */
110     i2c_direction_t direction; /*!< A transfer direction, read or write. */
111     uint32_t subaddress;       /*!< A sub address. Transferred MSB first. */
112     uint8_t subaddressSize;    /*!< A size of the command buffer. */
113     uint8_t *volatile data;    /*!< A transfer buffer. */
114     volatile size_t dataSize;  /*!< A transfer size. */
115 } i2c_master_transfer_t;
116 
117 /*! @brief I2C master handle structure. */
118 struct _i2c_master_handle
119 {
120     i2c_master_transfer_t transfer;                    /*!< I2C master transfer copy. */
121     size_t transferSize;                               /*!< Total bytes to be transferred. */
122     uint8_t state;                                     /*!< A transfer state maintained during transfer. */
123     i2c_master_transfer_callback_t completionCallback; /*!< A callback function called when the transfer is finished. */
124     void *userData;                                    /*!< A callback parameter passed to the callback function. */
125 };
126 
127 /*!
128  * @brief Set of events sent to the callback for nonblocking slave transfers.
129  *
130  * These event enumerations are used for two related purposes. First, a bit mask created by OR'ing together
131  * events is passed to I2C_SlaveTransferNonBlocking() to specify which events to enable.
132  * Then, when the slave callback is invoked, it is passed the current event through its @a transfer
133  * parameter.
134  *
135  * @note These enumerations are meant to be OR'd together to form a bit mask of events.
136  */
137 typedef enum _i2c_slave_transfer_event
138 {
139     kI2C_SlaveAddressMatchEvent = 0x01U, /*!< Received the slave address after a start or repeated start. */
140     kI2C_SlaveTransmitEvent     = 0x02U, /*!< A callback is requested to provide data to transmit
141                                                 (slave-transmitter role). */
142     kI2C_SlaveReceiveEvent = 0x04U,      /*!< A callback is requested to provide a buffer in which to place received
143                                                  data (slave-receiver role). */
144     kI2C_SlaveTransmitAckEvent = 0x08U,  /*!< A callback needs to either transmit an ACK or NACK. */
145     kI2C_SlaveCompletionEvent  = 0x20U,  /*!< A stop was detected or finished transfer, completing the transfer. */
146     /*! A bit mask of all available events. */
147     kI2C_SlaveAllEvents =
148         kI2C_SlaveAddressMatchEvent | kI2C_SlaveTransmitEvent | kI2C_SlaveReceiveEvent | kI2C_SlaveCompletionEvent,
149 } i2c_slave_transfer_event_t;
150 
151 /*! @brief I2C slave handle typedef. */
152 typedef struct _i2c_slave_handle i2c_slave_handle_t;
153 
154 /*! @brief I2C slave user configuration. */
155 typedef struct _i2c_slave_config
156 {
157     bool enableSlave;      /*!< Enables the I2C peripheral at initialization time. */
158     uint16_t slaveAddress; /*!< A slave address configuration. */
159 } i2c_slave_config_t;
160 
161 /*! @brief I2C slave transfer structure. */
162 typedef struct _i2c_slave_transfer
163 {
164     i2c_slave_transfer_event_t event; /*!< A reason that the callback is invoked. */
165     uint8_t *volatile data;           /*!< A transfer buffer. */
166     volatile size_t dataSize;         /*!< A transfer size. */
167     status_t completionStatus;        /*!< Success or error code describing how the transfer completed. Only applies for
168                                          #kI2C_SlaveCompletionEvent. */
169     size_t transferredCount; /*!< A number of bytes actually transferred since the start or since the last repeated
170                                 start. */
171 } i2c_slave_transfer_t;
172 
173 /*! @brief I2C slave transfer callback typedef. */
174 typedef void (*i2c_slave_transfer_callback_t)(I2C_Type *base, i2c_slave_transfer_t *xfer, void *userData);
175 
176 /*! @brief I2C slave handle structure. */
177 struct _i2c_slave_handle
178 {
179     volatile uint8_t state;                 /*!< A transfer state maintained during transfer. */
180     i2c_slave_transfer_t transfer;          /*!< I2C slave transfer copy. */
181     uint32_t eventMask;                     /*!< A mask of enabled events. */
182     i2c_slave_transfer_callback_t callback; /*!< A callback function called at the transfer event. */
183     void *userData;                         /*!< A callback parameter passed to the callback. */
184 };
185 
186 /*******************************************************************************
187  * API
188  ******************************************************************************/
189 
190 #if defined(__cplusplus)
191 extern "C" {
192 #endif /*_cplusplus. */
193 
194 /*!
195  * @name Initialization and deinitialization
196  * @{
197  */
198 
199 /*!
200  * @brief Initializes the I2C peripheral. Call this API to ungate the I2C clock
201  * and configure the I2C with master configuration.
202  *
203  * @note This API should be called at the beginning of the application.
204  * Otherwise, any operation to the I2C module can cause a hard fault
205  * because the clock is not enabled. The configuration structure can be custom filled
206  * or it can be set with default values by using the I2C_MasterGetDefaultConfig().
207  * After calling this API, the master is ready to transfer.
208  * This is an example.
209  * @code
210  * i2c_master_config_t config = {
211  * .enableMaster = true,
212  * .baudRate_Bps = 100000
213  * };
214  * I2C_MasterInit(I2C0, &config, 12000000U);
215  * @endcode
216  *
217  * @param base I2C base pointer
218  * @param masterConfig A pointer to the master configuration structure
219  * @param srcClock_Hz I2C peripheral clock frequency in Hz
220  */
221 void I2C_MasterInit(I2C_Type *base, const i2c_master_config_t *masterConfig, uint32_t srcClock_Hz);
222 
223 /*!
224  * @brief De-initializes the I2C master peripheral. Call this API to gate the I2C clock.
225  * The I2C master module can't work unless the I2C_MasterInit is called.
226  * @param base I2C base pointer
227  */
228 void I2C_MasterDeinit(I2C_Type *base);
229 
230 /*!
231  * @brief  Sets the I2C master configuration structure to default values.
232  *
233  * The purpose of this API is to get the configuration structure initialized for use in the I2C_MasterInit().
234  * Use the initialized structure unchanged in the I2C_MasterInit() or modify
235  * the structure before calling the I2C_MasterInit().
236  * This is an example.
237  * @code
238  * i2c_master_config_t config;
239  * I2C_MasterGetDefaultConfig(&config);
240  * @endcode
241  * @param masterConfig A pointer to the master configuration structure.
242  */
243 void I2C_MasterGetDefaultConfig(i2c_master_config_t *masterConfig);
244 
245 /*!
246  * @brief Initializes the I2C peripheral. Call this API to ungate the I2C clock
247  * and initialize the I2C with the slave configuration.
248  *
249  * @note This API should be called at the beginning of the application.
250  * Otherwise, any operation to the I2C module can cause a hard fault
251  * because the clock is not enabled. The configuration structure can partly be set
252  * with default values by I2C_SlaveGetDefaultConfig() or it can be custom filled by the user.
253  * This is an example.
254  * @code
255  * i2c_slave_config_t config = {
256  * .enableSlave = true,
257  * .slaveAddress = 0x1DU,
258  * };
259  * I2C_SlaveInit(I2C0, &config);
260  * @endcode
261  *
262  * @param base I2C base pointer
263  * @param slaveConfig A pointer to the slave configuration structure
264  */
265 void I2C_SlaveInit(I2C_Type *base, const i2c_slave_config_t *slaveConfig);
266 
267 /*!
268  * @brief De-initializes the I2C slave peripheral. Calling this API gates the I2C clock.
269  * The I2C slave module can't work unless the I2C_SlaveInit is called to enable the clock.
270  * @param base I2C base pointer
271  */
272 void I2C_SlaveDeinit(I2C_Type *base);
273 
274 /*!
275  * @brief  Sets the I2C slave configuration structure to default values.
276  *
277  * The purpose of this API is to get the configuration structure initialized for use in the I2C_SlaveInit().
278  * Modify fields of the structure before calling the I2C_SlaveInit().
279  * This is an example.
280  * @code
281  * i2c_slave_config_t config;
282  * I2C_SlaveGetDefaultConfig(&config);
283  * @endcode
284  * @param slaveConfig A pointer to the slave configuration structure.
285  */
286 void I2C_SlaveGetDefaultConfig(i2c_slave_config_t *slaveConfig);
287 
288 /*!
289  * @brief Enables or disables the I2C peripheral operation.
290  *
291  * @param base I2C base pointer
292  * @param enable Pass true to enable and false to disable the module.
293  */
I2C_Enable(I2C_Type * base,bool enable)294 static inline void I2C_Enable(I2C_Type *base, bool enable)
295 {
296     if (enable)
297     {
298         base->I2CR |= I2C_I2CR_IEN_MASK;
299     }
300     else
301     {
302         base->I2CR &= ~(uint16_t)I2C_I2CR_IEN_MASK;
303     }
304 }
305 
306 /*! @} */
307 
308 /*!
309  * @name Status
310  * @{
311  */
312 
313 /*!
314  * @brief Gets the I2C status flags.
315  *
316  * @param base I2C base pointer
317  * @return status flag, use status flag to AND #_i2c_flags to get the related status.
318  */
I2C_MasterGetStatusFlags(I2C_Type * base)319 static inline uint32_t I2C_MasterGetStatusFlags(I2C_Type *base)
320 {
321     return base->I2SR;
322 }
323 
324 /*!
325  * @brief Clears the I2C status flag state.
326  *
327  * The following status register flags can be cleared kI2C_ArbitrationLostFlag and kI2C_IntPendingFlag.
328  *
329  * @param base I2C base pointer
330  * @param statusMask The status flag mask, defined in type i2c_status_flag_t.
331  *      The parameter can be any combination of the following values:
332  *          @arg kI2C_ArbitrationLostFlag
333  *          @arg kI2C_IntPendingFlag
334  */
I2C_MasterClearStatusFlags(I2C_Type * base,uint32_t statusMask)335 static inline void I2C_MasterClearStatusFlags(I2C_Type *base, uint32_t statusMask)
336 {
337     base->I2SR &= (~(uint16_t)statusMask);
338 }
339 
340 /*!
341  * @brief Gets the I2C status flags.
342  *
343  * @param base I2C base pointer
344  * @return status flag, use status flag to AND #_i2c_flags to get the related status.
345  */
I2C_SlaveGetStatusFlags(I2C_Type * base)346 static inline uint32_t I2C_SlaveGetStatusFlags(I2C_Type *base)
347 {
348     return I2C_MasterGetStatusFlags(base);
349 }
350 
351 /*!
352  * @brief Clears the I2C status flag state.
353  *
354  * The following status register flags can be cleared kI2C_ArbitrationLostFlag and kI2C_IntPendingFlag
355  *
356  * @param base I2C base pointer
357  * @param statusMask The status flag mask, defined in type i2c_status_flag_t.
358  *      The parameter can be any combination of the following values:
359  *          @arg kI2C_IntPendingFlagFlag
360  */
I2C_SlaveClearStatusFlags(I2C_Type * base,uint32_t statusMask)361 static inline void I2C_SlaveClearStatusFlags(I2C_Type *base, uint32_t statusMask)
362 {
363     I2C_MasterClearStatusFlags(base, statusMask);
364 }
365 
366 /*! @} */
367 
368 /*!
369  * @name Interrupts
370  * @{
371  */
372 
373 /*!
374  * @brief Enables I2C interrupt requests.
375  *
376  * @param base I2C base pointer
377  * @param mask interrupt source
378  *     The parameter can be combination of the following source if defined:
379  *     @arg kI2C_GlobalInterruptEnable
380  *     @arg kI2C_StopDetectInterruptEnable/kI2C_StartDetectInterruptEnable
381  *     @arg kI2C_SdaTimeoutInterruptEnable
382  */
383 void I2C_EnableInterrupts(I2C_Type *base, uint32_t mask);
384 
385 /*!
386  * @brief Disables I2C interrupt requests.
387  *
388  * @param base I2C base pointer
389  * @param mask interrupt source
390  *     The parameter can be combination of the following source if defined:
391  *     @arg kI2C_GlobalInterruptEnable
392  *     @arg kI2C_StopDetectInterruptEnable/kI2C_StartDetectInterruptEnable
393  *     @arg kI2C_SdaTimeoutInterruptEnable
394  */
395 void I2C_DisableInterrupts(I2C_Type *base, uint32_t mask);
396 
397 /*! @} */
398 /*!
399  * @name Bus Operations
400  * @{
401  */
402 
403 /*!
404  * @brief Sets the I2C master transfer baud rate.
405  *
406  * @param base I2C base pointer
407  * @param baudRate_Bps the baud rate value in bps
408  * @param srcClock_Hz Source clock
409  */
410 void I2C_MasterSetBaudRate(I2C_Type *base, uint32_t baudRate_Bps, uint32_t srcClock_Hz);
411 
412 /*!
413  * @brief Sends a START on the I2C bus.
414  *
415  * This function is used to initiate a new master mode transfer by sending the START signal.
416  * The slave address is sent following the I2C START signal.
417  *
418  * @param base I2C peripheral base pointer
419  * @param address 7-bit slave device address.
420  * @param direction Master transfer directions(transmit/receive).
421  * @retval kStatus_Success Successfully send the start signal.
422  * @retval kStatus_I2C_Busy Current bus is busy.
423  */
424 status_t I2C_MasterStart(I2C_Type *base, uint8_t address, i2c_direction_t direction);
425 
426 /*!
427  * @brief Sends a STOP signal on the I2C bus.
428  *
429  * @retval kStatus_Success Successfully send the stop signal.
430  * @retval kStatus_I2C_Timeout Send stop signal failed, timeout.
431  */
432 status_t I2C_MasterStop(I2C_Type *base);
433 
434 /*!
435  * @brief Sends a REPEATED START on the I2C bus.
436  *
437  * @param base I2C peripheral base pointer
438  * @param address 7-bit slave device address.
439  * @param direction Master transfer directions(transmit/receive).
440  * @retval kStatus_Success Successfully send the start signal.
441  * @retval kStatus_I2C_Busy Current bus is busy but not occupied by current I2C master.
442  */
443 status_t I2C_MasterRepeatedStart(I2C_Type *base, uint8_t address, i2c_direction_t direction);
444 
445 /*!
446  * @brief Performs a polling send transaction on the I2C bus.
447  *
448  * @param base  The I2C peripheral base pointer.
449  * @param txBuff The pointer to the data to be transferred.
450  * @param txSize The length in bytes of the data to be transferred.
451  * @param flags Transfer control flag to decide whether need to send a stop, use kI2C_TransferDefaultFlag
452  *  to issue a stop and kI2C_TransferNoStop to not send a stop.
453  * @retval kStatus_Success Successfully complete the data transmission.
454  * @retval kStatus_I2C_ArbitrationLost Transfer error, arbitration lost.
455  * @retval kStataus_I2C_Nak Transfer error, receive NAK during transfer.
456  */
457 status_t I2C_MasterWriteBlocking(I2C_Type *base, const uint8_t *txBuff, size_t txSize, uint32_t flags);
458 
459 /*!
460  * @brief Performs a polling receive transaction on the I2C bus.
461  *
462  * @note The I2C_MasterReadBlocking function stops the bus before reading the final byte.
463  * Without stopping the bus prior for the final read, the bus issues another read, resulting
464  * in garbage data being read into the data register.
465  *
466  * @param base I2C peripheral base pointer.
467  * @param rxBuff The pointer to the data to store the received data.
468  * @param rxSize The length in bytes of the data to be received.
469  * @param flags Transfer control flag to decide whether need to send a stop, use kI2C_TransferDefaultFlag
470  *  to issue a stop and kI2C_TransferNoStop to not send a stop.
471  * @retval kStatus_Success Successfully complete the data transmission.
472  * @retval kStatus_I2C_Timeout Send stop signal failed, timeout.
473  */
474 status_t I2C_MasterReadBlocking(I2C_Type *base, uint8_t *rxBuff, size_t rxSize, uint32_t flags);
475 
476 /*!
477  * @brief Performs a polling send transaction on the I2C bus.
478  *
479  * @param base  The I2C peripheral base pointer.
480  * @param txBuff The pointer to the data to be transferred.
481  * @param txSize The length in bytes of the data to be transferred.
482  * @retval kStatus_Success Successfully complete the data transmission.
483  * @retval kStatus_I2C_ArbitrationLost Transfer error, arbitration lost.
484  * @retval kStataus_I2C_Nak Transfer error, receive NAK during transfer.
485  */
486 status_t I2C_SlaveWriteBlocking(I2C_Type *base, const uint8_t *txBuff, size_t txSize);
487 
488 /*!
489  * @brief Performs a polling receive transaction on the I2C bus.
490  *
491  * @param base I2C peripheral base pointer.
492  * @param rxBuff The pointer to the data to store the received data.
493  * @param rxSize The length in bytes of the data to be received.
494  */
495 status_t I2C_SlaveReadBlocking(I2C_Type *base, uint8_t *rxBuff, size_t rxSize);
496 
497 /*!
498  * @brief Performs a master polling transfer on the I2C bus.
499  *
500  * @note The API does not return until the transfer succeeds or fails due
501  * to arbitration lost or receiving a NAK.
502  *
503  * @param base I2C peripheral base address.
504  * @param xfer Pointer to the transfer structure.
505  * @retval kStatus_Success Successfully complete the data transmission.
506  * @retval kStatus_I2C_Busy Previous transmission still not finished.
507  * @retval kStatus_I2C_Timeout Transfer error, wait signal timeout.
508  * @retval kStatus_I2C_ArbitrationLost Transfer error, arbitration lost.
509  * @retval kStataus_I2C_Nak Transfer error, receive NAK during transfer.
510  */
511 status_t I2C_MasterTransferBlocking(I2C_Type *base, i2c_master_transfer_t *xfer);
512 
513 /*! @} */
514 
515 /*!
516  * @name Transactional
517  * @{
518  */
519 
520 /*!
521  * @brief Initializes the I2C handle which is used in transactional functions.
522  *
523  * @param base I2C base pointer.
524  * @param handle pointer to i2c_master_handle_t structure to store the transfer state.
525  * @param callback pointer to user callback function.
526  * @param userData user parameter passed to the callback function.
527  */
528 void I2C_MasterTransferCreateHandle(I2C_Type *base,
529                                     i2c_master_handle_t *handle,
530                                     i2c_master_transfer_callback_t callback,
531                                     void *userData);
532 
533 /*!
534  * @brief Performs a master interrupt non-blocking transfer on the I2C bus.
535  *
536  * @note Calling the API returns immediately after transfer initiates. The user needs
537  * to call I2C_MasterGetTransferCount to poll the transfer status to check whether
538  * the transfer is finished. If the return status is not kStatus_I2C_Busy, the transfer
539  * is finished.
540  *
541  * @param base I2C base pointer.
542  * @param handle pointer to i2c_master_handle_t structure which stores the transfer state.
543  * @param xfer pointer to i2c_master_transfer_t structure.
544  * @retval kStatus_Success Successfully start the data transmission.
545  * @retval kStatus_I2C_Busy Previous transmission still not finished.
546  * @retval kStatus_I2C_Timeout Transfer error, wait signal timeout.
547  */
548 status_t I2C_MasterTransferNonBlocking(I2C_Type *base, i2c_master_handle_t *handle, i2c_master_transfer_t *xfer);
549 
550 /*!
551  * @brief Gets the master transfer status during a interrupt non-blocking transfer.
552  *
553  * @param base I2C base pointer.
554  * @param handle pointer to i2c_master_handle_t structure which stores the transfer state.
555  * @param count Number of bytes transferred so far by the non-blocking transaction.
556  * @retval kStatus_InvalidArgument count is Invalid.
557  * @retval kStatus_Success Successfully return the count.
558  */
559 status_t I2C_MasterTransferGetCount(I2C_Type *base, i2c_master_handle_t *handle, size_t *count);
560 
561 /*!
562  * @brief Aborts an interrupt non-blocking transfer early.
563  *
564  * @note This API can be called at any time when an interrupt non-blocking transfer initiates
565  * to abort the transfer early.
566  *
567  * @param base I2C base pointer.
568  * @param handle pointer to i2c_master_handle_t structure which stores the transfer state
569  * @retval kStatus_I2C_Timeout Timeout during polling flag.
570  * @retval kStatus_Success Successfully abort the transfer.
571  */
572 status_t I2C_MasterTransferAbort(I2C_Type *base, i2c_master_handle_t *handle);
573 
574 /*!
575  * @brief Master interrupt handler.
576  *
577  * @param base I2C base pointer.
578  * @param i2cHandle pointer to i2c_master_handle_t structure.
579  */
580 void I2C_MasterTransferHandleIRQ(I2C_Type *base, void *i2cHandle);
581 
582 /*!
583  * @brief Initializes the I2C handle which is used in transactional functions.
584  *
585  * @param base I2C base pointer.
586  * @param handle pointer to i2c_slave_handle_t structure to store the transfer state.
587  * @param callback pointer to user callback function.
588  * @param userData user parameter passed to the callback function.
589  */
590 void I2C_SlaveTransferCreateHandle(I2C_Type *base,
591                                    i2c_slave_handle_t *handle,
592                                    i2c_slave_transfer_callback_t callback,
593                                    void *userData);
594 
595 /*!
596  * @brief Starts accepting slave transfers.
597  *
598  * Call this API after calling the I2C_SlaveInit() and I2C_SlaveTransferCreateHandle() to start processing
599  * transactions driven by an I2C master. The slave monitors the I2C bus and passes events to the
600  * callback that was passed into the call to I2C_SlaveTransferCreateHandle(). The callback is always invoked
601  * from the interrupt context.
602  *
603  * The set of events received by the callback is customizable. To do so, set the @a eventMask parameter to
604  * the OR'd combination of #i2c_slave_transfer_event_t enumerators for the events you wish to receive.
605  * The #kI2C_SlaveTransmitEvent and kLPI2C_SlaveReceiveEvent events are always enabled and do not need
606  * to be included in the mask. Alternatively, pass 0 to get a default set of only the transmit and
607  * receive events that are always enabled. In addition, the #kI2C_SlaveAllEvents constant is provided as
608  * a convenient way to enable all events.
609  *
610  * @param base The I2C peripheral base address.
611  * @param handle Pointer to i2c_slave_handle_t structure which stores the transfer state.
612  * @param eventMask Bit mask formed by OR'ing together #i2c_slave_transfer_event_t enumerators to specify
613  *      which events to send to the callback. Other accepted values are 0 to get a default set of
614  *      only the transmit and receive events, and #kI2C_SlaveAllEvents to enable all events.
615  *
616  * @retval kStatus_Success Slave transfers were successfully started.
617  * @retval #kStatus_I2C_Busy Slave transfers have already been started on this handle.
618  */
619 status_t I2C_SlaveTransferNonBlocking(I2C_Type *base, i2c_slave_handle_t *handle, uint32_t eventMask);
620 
621 /*!
622  * @brief Aborts the slave transfer.
623  *
624  * @note This API can be called at any time to stop slave for handling the bus events.
625  *
626  * @param base I2C base pointer.
627  * @param handle pointer to i2c_slave_handle_t structure which stores the transfer state.
628  */
629 void I2C_SlaveTransferAbort(I2C_Type *base, i2c_slave_handle_t *handle);
630 
631 /*!
632  * @brief Gets the slave transfer remaining bytes during a interrupt non-blocking transfer.
633  *
634  * @param base I2C base pointer.
635  * @param handle pointer to i2c_slave_handle_t structure.
636  * @param count Number of bytes transferred so far by the non-blocking transaction.
637  * @retval kStatus_InvalidArgument count is Invalid.
638  * @retval kStatus_Success Successfully return the count.
639  */
640 status_t I2C_SlaveTransferGetCount(I2C_Type *base, i2c_slave_handle_t *handle, size_t *count);
641 
642 /*!
643  * @brief Slave interrupt handler.
644  *
645  * @param base I2C base pointer.
646  * @param i2cHandle pointer to i2c_slave_handle_t structure which stores the transfer state
647  */
648 void I2C_SlaveTransferHandleIRQ(I2C_Type *base, void *i2cHandle);
649 
650 /*! @} */
651 #if defined(__cplusplus)
652 }
653 #endif /*_cplusplus. */
654 /*! @} */
655 
656 #endif /* FSL_I2C_H_*/
657