1 /* 2 * Copyright (c) 2015, 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_DMA_H_ 9 #define FSL_I2C_DMA_H_ 10 11 #include "fsl_i2c.h" 12 #include "fsl_dma.h" 13 14 /*! 15 * @addtogroup i2c_dma_driver 16 * @{ 17 */ 18 19 /******************************************************************************* 20 * Definitions 21 ******************************************************************************/ 22 23 /*! @name Driver version */ 24 /*! @{ */ 25 /*! @brief I2C DMA driver version. */ 26 #define FSL_I2C_DMA_DRIVER_VERSION (MAKE_VERSION(2, 0, 9)) 27 /*! @} */ 28 29 /*! @brief Retry times for waiting flag. */ 30 #ifndef I2C_RETRY_TIMES 31 #define I2C_RETRY_TIMES 0U /* Define to zero means keep waiting until the flag is assert/deassert. */ 32 #endif 33 34 /*! @brief I2C master DMA handle typedef. */ 35 typedef struct _i2c_master_dma_handle i2c_master_dma_handle_t; 36 37 /*! @brief I2C master DMA transfer callback typedef. */ 38 typedef void (*i2c_master_dma_transfer_callback_t)(I2C_Type *base, 39 i2c_master_dma_handle_t *handle, 40 status_t status, 41 void *userData); 42 43 /*! @brief I2C master DMA transfer structure. */ 44 struct _i2c_master_dma_handle 45 { 46 i2c_master_transfer_t transfer; /*!< I2C master transfer struct. */ 47 size_t transferSize; /*!< Total bytes to be transferred. */ 48 uint8_t state; /*!< I2C master transfer status. */ 49 dma_handle_t *dmaHandle; /*!< The DMA handler used. */ 50 i2c_master_dma_transfer_callback_t 51 completionCallback; /*!< A callback function called after the DMA transfer finished. */ 52 void *userData; /*!< A callback parameter passed to the callback function. */ 53 }; 54 55 /******************************************************************************* 56 * API 57 ******************************************************************************/ 58 59 #if defined(__cplusplus) 60 extern "C" { 61 #endif /*_cplusplus. */ 62 63 /*! 64 * @name I2C Block DMA Transfer Operation 65 * @{ 66 */ 67 68 /*! 69 * @brief Initializes the I2C handle which is used in transactional functions. 70 * 71 * @param base I2C peripheral base address 72 * @param handle Pointer to the i2c_master_dma_handle_t structure 73 * @param callback Pointer to the user callback function 74 * @param userData A user parameter passed to the callback function 75 * @param dmaHandle DMA handle pointer 76 */ 77 void I2C_MasterTransferCreateHandleDMA(I2C_Type *base, 78 i2c_master_dma_handle_t *handle, 79 i2c_master_dma_transfer_callback_t callback, 80 void *userData, 81 dma_handle_t *dmaHandle); 82 83 /*! 84 * @brief Performs a master DMA non-blocking transfer on the I2C bus. 85 * 86 * @param base I2C peripheral base address 87 * @param handle A pointer to the i2c_master_dma_handle_t structure 88 * @param xfer A pointer to the transfer structure of the i2c_master_transfer_t 89 * @retval kStatus_Success Successfully completes the data transmission. 90 * @retval kStatus_I2C_Busy A previous transmission is still not finished. 91 * @retval kStatus_I2C_Timeout A transfer error, waits for the signal timeout. 92 * @retval kStatus_I2C_ArbitrationLost A transfer error, arbitration lost. 93 * @retval kStataus_I2C_Nak A transfer error, receives NAK during transfer. 94 */ 95 status_t I2C_MasterTransferDMA(I2C_Type *base, i2c_master_dma_handle_t *handle, i2c_master_transfer_t *xfer); 96 97 /*! 98 * @brief Gets a master transfer status during a DMA non-blocking transfer. 99 * 100 * @param base I2C peripheral base address 101 * @param handle A pointer to the i2c_master_dma_handle_t structure 102 * @param count A number of bytes transferred so far by the non-blocking transaction. 103 */ 104 status_t I2C_MasterTransferGetCountDMA(I2C_Type *base, i2c_master_dma_handle_t *handle, size_t *count); 105 106 /*! 107 * @brief Aborts a master DMA non-blocking transfer early. 108 * 109 * @param base I2C peripheral base address 110 * @param handle A pointer to the i2c_master_dma_handle_t structure. 111 */ 112 void I2C_MasterTransferAbortDMA(I2C_Type *base, i2c_master_dma_handle_t *handle); 113 114 /*! @} */ 115 #if defined(__cplusplus) 116 } 117 #endif /*_cplusplus. */ 118 /*! @} */ 119 #endif /*FSL_I2C_DMA_H_*/ 120