1 /* 2 * Copyright 2019-2022 NXP 3 * All rights reserved. 4 * 5 * SPDX-License-Identifier: BSD-3-Clause 6 */ 7 8 #ifndef _FSL_MIPI_DSI_SMARTDMA_H_ 9 #define _FSL_MIPI_DSI_SMARTDMA_H_ 10 11 #include "fsl_mipi_dsi.h" 12 #include "fsl_smartdma.h" 13 14 /*! 15 * @addtogroup mipi_dsi_smartdma 16 * @{ 17 */ 18 19 /******************************************************************************* 20 * Definitions 21 ******************************************************************************/ 22 23 /*! @name Driver version */ 24 /*@{*/ 25 #define FSL_MIPI_DSI_SMARTDMA_DRIVER_VERSION (MAKE_VERSION(2, 3, 0)) 26 /*@}*/ 27 28 /* Forward declaration of the handle typedef. */ 29 typedef struct _dsi_smartdma_handle dsi_smartdma_handle_t; 30 31 /*! 32 * @brief MIPI DSI callback for finished transfer. 33 * 34 * When transfer finished, one of these status values will be passed to the user: 35 * - @ref kStatus_Success Data transfer finished with no error. 36 */ 37 typedef void (*dsi_smartdma_callback_t)(MIPI_DSI_HOST_Type *base, 38 dsi_smartdma_handle_t *handle, 39 status_t status, 40 void *userData); 41 42 /*! @brief The pixel format feed SMARTDMA. */ 43 typedef enum _dsi_smartdma_input_pixel_format 44 { 45 kDSI_SMARTDMA_InputPixelFormatRGB565, /*!< RGB565. */ 46 kDSI_SMARTDMA_InputPixelFormatRGB888, /*!< RGB888. */ 47 kDSI_SMARTDMA_InputPixelFormatXRGB8888, /*!< XRGB8888. */ 48 } dsi_smartdma_input_pixel_format_t; 49 50 /*! @brief The pixel format sent on MIPI DSI data lanes. */ 51 typedef enum _dsi_smartdma_output_pixel_format 52 { 53 kDSI_SMARTDMA_OutputPixelFormatRGB565, /*!< RGB565. */ 54 kDSI_SMARTDMA_OutputPixelFormatRGB888, /*!< RGB888. */ 55 } dsi_smartdma_output_pixel_format_t; 56 57 /*! @brief The pixel format sent on MIPI DSI data lanes. */ 58 typedef struct _dsi_smartdma_write_mem_transfer 59 { 60 dsi_smartdma_input_pixel_format_t inputFormat; /*!< Input format. */ 61 dsi_smartdma_output_pixel_format_t outputFormat; /*!< Output format. */ 62 const uint8_t *data; /*!< Pointer to the data to send. */ 63 bool twoDimension; /*!< Whether to use 2-dimensional transfer. */ 64 size_t dataSize; /*!< The byte count to be write. In 2-dimensional transfer, this parameter is ignored. */ 65 size_t minorLoop; /*!< SRC data transfer byte count in a minor loop, only used in 2-dimensional transfer. */ 66 size_t minorLoopOffset; /*!< SRC data byte offset added after a minor loop, only used in 2-dimensional transfer. */ 67 size_t majorLoop; /*!< SRC data transfer in a major loop of maw many minor loop is transfered, only used in 68 2-dimensional transfer. */ 69 uint8_t virtualChannel; /*!< Virtual channel used in the transfer, 70 current driver always use channel 0, added 71 for future enhancement. */ 72 /*! 73 * If set to true, the pixels are filled to MIPI DSI FIFO directly. 74 * If set to false, the pixel bytes are swapped then filled to 75 * MIPI DSI FIFO. For example, when set to false and frame buffer pixel 76 * format is RGB565: 77 * LSB MSB 78 * B0 B1 B2 B3 B4 G0 G1 G2 | G3 G4 G5 R0 R1 R2 R3 R4 79 * Then the pixel filled to DSI FIFO is: 80 * LSB MSB 81 * G3 G4 G5 R0 R1 R2 R3 R4 | B0 B1 B2 B3 B4 G0 G1 G2 82 */ 83 bool disablePixelByteSwap; 84 } dsi_smartdma_write_mem_transfer_t; 85 86 /*! @brief MIPI DSI transfer handle structure */ 87 struct _dsi_smartdma_handle 88 { 89 MIPI_DSI_HOST_Type *dsi; /*!< MIPI DSI peripheral. */ 90 volatile bool isBusy; /*!< MIPI DSI is busy with data transfer. */ 91 dsi_smartdma_callback_t callback; /*!< DSI callback */ 92 void *userData; /*!< Callback parameter */ 93 union 94 { 95 smartdma_dsi_param_t param; /*!< Parameter for smartdma function. */ 96 smartdma_dsi_2d_param_t param2d; /*!< Parameter for 2-dimensional smartdma function. */ 97 }; 98 uint32_t smartdmaStack[16]; /*!< Stack for smartdma function. */ 99 }; 100 101 /******************************************************************************* 102 * API 103 ******************************************************************************/ 104 105 #if defined(__cplusplus) 106 extern "C" { 107 #endif 108 109 /*! 110 * @name Transactional 111 * @{ 112 */ 113 114 /*! 115 * @brief Create the MIPI DSI SMARTDMA handle. 116 * 117 * @param base MIPI DSI host peripheral base address. 118 * @param handle Handle pointer. 119 * @param callback Callback function. 120 * @param userData User data. 121 */ 122 status_t DSI_TransferCreateHandleSMARTDMA(MIPI_DSI_HOST_Type *base, 123 dsi_smartdma_handle_t *handle, 124 dsi_smartdma_callback_t callback, 125 void *userData); 126 127 /*! 128 * @brief Write display controller video memory using SMARTDMA. 129 * 130 * Perform data transfer using SMARTDMA, when transfer finished, 131 * upper layer could be informed through callback function. 132 * 133 * @param base MIPI DSI host peripheral base address. 134 * @param handle pointer to dsi_smartdma_handle_t structure which stores the transfer state. 135 * @param xfer Pointer to the transfer structure. 136 * 137 * @retval kStatus_Success Data transfer started successfully. 138 * @retval kStatus_DSI_Busy Failed to start transfer because DSI is busy with pervious transfer. 139 * @retval kStatus_DSI_NotSupported Transfer format not supported. 140 */ 141 status_t DSI_TransferWriteMemorySMARTDMA(MIPI_DSI_HOST_Type *base, 142 dsi_smartdma_handle_t *handle, 143 dsi_smartdma_write_mem_transfer_t *xfer); 144 145 /*! 146 * @brief Abort current APB data transfer. 147 * 148 * @param base MIPI DSI host peripheral base address. 149 * @param handle pointer to dsi_smartdma_handle_t structure which stores the transfer state. 150 */ 151 void DSI_TransferAbortSMARTDMA(MIPI_DSI_HOST_Type *base, dsi_smartdma_handle_t *handle); 152 153 /*! @} */ 154 155 #if defined(__cplusplus) 156 } 157 #endif 158 159 /*! @} */ 160 161 #endif /* _FSL_MIPI_DSI_SMARTDMA_H_ */ 162