1 /* 2 * Copyright 2019-2023 NXP 3 * All rights reserved. 4 * 5 * 6 * SPDX-License-Identifier: BSD-3-Clause 7 */ 8 9 #ifndef _FSL_SMARTDMA_H_ 10 #define _FSL_SMARTDMA_H_ 11 12 #include "fsl_common.h" 13 14 /*! 15 * @addtogroup smartdma 16 * @{ 17 */ 18 19 /******************************************************************************* 20 * Definitions 21 ******************************************************************************/ 22 23 /*! @name Driver version */ 24 /*@{*/ 25 /*! @brief SMARTDMA driver version */ 26 #define FSL_SMARTDMA_DRIVER_VERSION (MAKE_VERSION(2, 7, 0)) 27 /*@}*/ 28 29 /*! @brief The firmware used for display. */ 30 extern const uint8_t s_smartdmaDisplayFirmware[]; 31 32 /*! @brief The s_smartdmaDisplayFirmware firmware memory address. */ 33 #define SMARTDMA_DISPLAY_MEM_ADDR 0x24100000 34 35 /*! @brief Size of s_smartdmaDisplayFirmware */ 36 #define SMARTDMA_DISPLAY_FIRMWARE_SIZE (s_smartdmaDisplayFirmwareSize) 37 38 /*! @brief Size of s_smartdmaDisplayFirmware */ 39 extern const uint32_t s_smartdmaDisplayFirmwareSize; 40 41 /*! @brief Compatibility redefinition. */ 42 #define s_smartdmaFlexioMcuLcdFirmware s_smartdmaDisplayFirmware 43 #define SMARTDMA_FLEXIO_MCULCD_MEM_ADDR SMARTDMA_DISPLAY_MEM_ADDR 44 #define SMARTDMA_FLEXIO_MCULCD_FIRMWARE_SIZE SMARTDMA_DISPLAY_FIRMWARE_SIZE 45 #define s_smartdmaFlexioMcuLcdFirmwareSize s_smartdmaDisplayFirmwareSize 46 47 /*! 48 * @brief The API index when using s_smartdmaFlexioMcuLcdFirmware. 49 */ 50 enum _smartdma_flexio_mculcd_api 51 { 52 kSMARTDMA_FlexIO_DMA_Endian_Swap = 0U, 53 kSMARTDMA_FlexIO_DMA_Reverse32, 54 kSMARTDMA_FlexIO_DMA, 55 kSMARTDMA_FlexIO_DMA_Reverse, /*!< Send data to FlexIO with reverse order. */ 56 kSMARTDMA_RGB565To888, /*!< Convert RGB565 to RGB888 and save to output memory, use parameter 57 smartdma_rgb565_rgb888_param_t. */ 58 kSMARTDMA_FlexIO_DMA_RGB565To888, /*!< Convert RGB565 to RGB888 and send to FlexIO, use parameter 59 smartdma_flexio_mculcd_param_t. */ 60 kSMARTDMA_FlexIO_DMA_ARGB2RGB, /*!< Convert ARGB to RGB and send to FlexIO, use parameter 61 smartdma_flexio_mculcd_param_t. */ 62 kSMARTDMA_FlexIO_DMA_ARGB2RGB_Endian_Swap, /*!< Convert ARGB to RGB, then swap endian, and send to FlexIO, use 63 parameter smartdma_flexio_mculcd_param_t. */ 64 kSMARTDMA_FlexIO_DMA_ARGB2RGB_Endian_Swap_Reverse, /*!< Convert ARGB to RGB, then swap endian and reverse, and send 65 to FlexIO, use parameter smartdma_flexio_mculcd_param_t. */ 66 kSMARTDMA_MIPI_RGB565_DMA, /*!< Send RGB565 data to MIPI DSI, use parameter smartdma_dsi_param_t. */ 67 kSMARTDMA_MIPI_RGB565_DMA2D, /*!< Send RGB565 data to MIPI DSI, use parameter smartdma_dsi_2d_param_t. */ 68 kSMARTDMA_MIPI_RGB888_DMA, /*!< Send RGB888 data to MIPI DSI, use parameter smartdma_dsi_param_t. */ 69 kSMARTDMA_MIPI_RGB888_DMA2D, /*!< Send RGB565 data to MIPI DSI, use parameter smartdma_dsi_2d_param_t. */ 70 kSMARTDMA_MIPI_XRGB2RGB_DMA, /*!< Send XRGB8888 data to MIPI DSI, use parameter smartdma_dsi_param_t */ 71 kSMARTDMA_MIPI_XRGB2RGB_DMA2D, /*!< Send XRGB8888 data to MIPI DSI, use parameter smartdma_dsi_2d_param_t. */ 72 kSMARTDMA_MIPI_RGB565_R180_DMA, /*!< Send RGB565 data to MIPI DSI, Rotate 180, use parameter smartdma_dsi_param_t. 73 */ 74 kSMARTDMA_MIPI_RGB888_R180_DMA, /*!< Send RGB888 data to MIPI DSI, Rotate 180, use parameter smartdma_dsi_param_t. 75 */ 76 kSMARTDMA_MIPI_XRGB2RGB_R180_DMA, /*!< Send XRGB8888 data to MIPI DSI, Rotate 180, use parameter 77 smartdma_dsi_param_t */ 78 kSMARTDMA_MIPI_RGB5652RGB888_DMA, /*!< Send RGB565 data to MIPI DSI, use parameter smartdma_dsi_param_t. */ 79 kSMARTDMA_MIPI_RGB888_CHECKER_BOARD_DMA, /*!< Send RGB888 data to MIPI DSI with checker board pattern, use parameter 80 smartdma_dsi_checkerboard_param_t. */ 81 kSMARTDMA_FlexIO_DMA_ONELANE, /*!< FlexIO DMA for one SHIFTBUF, Write Data to SHIFTBUF[OFFSET] */ 82 }; 83 84 /*! 85 * @brief Parameter for FlexIO MCULCD except kSMARTDMA_FlexIO_DMA_ONELANE 86 */ 87 typedef struct _smartdma_flexio_mculcd_param 88 { 89 uint32_t *p_buffer; 90 uint32_t buffersize; 91 uint32_t *smartdma_stack; 92 } smartdma_flexio_mculcd_param_t; 93 94 /*! 95 * @brief Parameter for kSMARTDMA_FlexIO_DMA_ONELANE 96 */ 97 typedef struct _smartdma_flexio_onelane_mculcd_param 98 { 99 uint32_t *p_buffer; 100 uint32_t buffersize; 101 uint32_t offset; 102 uint32_t *smartdma_stack; 103 } smartdma_flexio_onelane_mculcd_param_t; 104 105 /*! 106 * @brief Parameter for MIPI DSI 107 */ 108 typedef struct _smartdma_dsi_param 109 { 110 /*! Pointer to the buffer to send. */ 111 const uint8_t *p_buffer; 112 /*! Buffer size in byte. */ 113 uint32_t buffersize; 114 /*! Stack used by SMARTDMA. */ 115 uint32_t *smartdma_stack; 116 /*! 117 * If set to 1, the pixels are filled to MIPI DSI FIFO directly. 118 * If set to 0, the pixel bytes are swapped then filled to 119 * MIPI DSI FIFO. For example, when set to 0 and frame buffer pixel 120 * format is RGB565: 121 * LSB MSB 122 * B0 B1 B2 B3 B4 G0 G1 G2 | G3 G4 G5 R0 R1 R2 R3 R4 123 * Then the pixel filled to DSI FIFO is: 124 * LSB MSB 125 * G3 G4 G5 R0 R1 R2 R3 R4 | B0 B1 B2 B3 B4 G0 G1 G2 126 */ 127 uint32_t disablePixelByteSwap; 128 } smartdma_dsi_param_t; 129 130 /*! 131 * @brief Parameter for kSMARTDMA_MIPI_RGB565_DMA2D, kSMARTDMA_MIPI_RGB888_DMA2D 132 * and kSMARTDMA_MIPI_XRGB2RGB_DMA2D. 133 */ 134 typedef struct _smartdma_dsi_2d_param 135 { 136 /*! Pointer to the buffer to send. */ 137 const uint8_t *p_buffer; 138 /*! SRC data transfer in a minor loop */ 139 uint32_t minorLoop; 140 /*! SRC data offset added after a minor loop */ 141 uint32_t minorLoopOffset; 142 /*! SRC data transfer in a major loop */ 143 uint32_t majorLoop; 144 /*! Stack used by SMARTDMA. */ 145 uint32_t *smartdma_stack; 146 /*! 147 * If set to 1, the pixels are filled to MIPI DSI FIFO directly. 148 * If set to 0, the pixel bytes are swapped then filled to 149 * MIPI DSI FIFO. For example, when set to 0 and frame buffer pixel 150 * format is RGB565: 151 * LSB MSB 152 * B0 B1 B2 B3 B4 G0 G1 G2 | G3 G4 G5 R0 R1 R2 R3 R4 153 * Then the pixel filled to DSI FIFO is: 154 * LSB MSB 155 * G3 G4 G5 R0 R1 R2 R3 R4 | B0 B1 B2 B3 B4 G0 G1 G2 156 */ 157 uint32_t disablePixelByteSwap; 158 } smartdma_dsi_2d_param_t; 159 160 /*! 161 * @brief Parameter for kSMARTDMA_MIPI_RGB888_CHECKER_BOARD_DMA 162 */ 163 typedef struct _smartdma_dsi_checkerboard_param 164 { 165 /*! Pointer to the buffer to send, pixel format is ARGB8888. */ 166 const uint8_t *p_buffer; 167 uint32_t height; /*! Height resolution in pixel. */ 168 uint32_t width; /*! Width resolution in pixel. */ 169 /*! Cube block type. 170 * cbType=1 : 1/2 pixel mask cases 171 * cbType=2 : 1/4 pixel mask cases 172 */ 173 uint32_t cbType; 174 /*! which pixel is turned off in each type 175 * cbType=2: indexOff= 1,2,3,4 176 * cbType=1: indexOff= 0,1 177 */ 178 uint32_t indexOff; 179 /*! Stack used by SMARTDMA. */ 180 uint32_t *smartdma_stack; 181 /*! 182 * If set to 1, the pixels are filled to MIPI DSI FIFO directly. 183 * If set to 0, the pixel bytes are swapped then filled to 184 * MIPI DSI FIFO. For example, when set to 0 and frame buffer pixel 185 * for example 186 * format is RGB888: 187 * LSB MSB 188 * B0 B1 B2 B3 B4 B5 B6 B7 | G0 G1 G2 G3 G4 G5 G6 G7 | R0 R1 R2 R3 R4 R5 R6 R7 189 * Then the pixel filled to DSI FIFO is: 190 * LSB MSB 191 * R0 R1 R2 R3 R4 R5 R6 R7 | G0 G1 G2 G3 G4 G5 G6 G7 | B0 B1 B2 B3 B4 B5 B6 B7 192 */ 193 uint32_t disablePixelByteSwap; 194 } smartdma_dsi_checkerboard_param_t; 195 196 /*! 197 * @brief Parameter for RGB565To888 198 */ 199 typedef struct _smartdma_rgb565_rgb888_param 200 { 201 uint32_t *inBuf; 202 uint32_t *outBuf; 203 uint32_t buffersize; 204 uint32_t *smartdma_stack; 205 } smartdma_rgb565_rgb888_param_t; 206 207 /*! @brief Callback function prototype for the smartdma driver. */ 208 typedef void (*smartdma_callback_t)(void *param); 209 210 /******************************************************************************* 211 * APIs 212 ******************************************************************************/ 213 214 #if defined(__cplusplus) 215 extern "C" { 216 #endif /* __cplusplus */ 217 218 /*! 219 * @brief Initialize the SMARTDMA. 220 * 221 * @param apiMemAddr The address firmware will be copied to. 222 * @param firmware The firmware to use. 223 * @param firmwareSizeByte Size of firmware. 224 * @deprecated Do not use this function. It has been superceded by @ref GPIO_PinWrite. 225 * @ref SMARTDMA_InitWithoutFirmware and @ref SMARTDMA_InstallFirmware. 226 */ 227 void SMARTDMA_Init(uint32_t apiMemAddr, const void *firmware, uint32_t firmwareSizeByte); 228 229 /*! 230 * @brief Initialize the SMARTDMA. 231 * 232 * This function is similar with @ref SMARTDMA_Init, the difference is this function 233 * does not install the firmware, the firmware could be installed using 234 * @ref SMARTDMA_InstallFirmware. 235 */ 236 void SMARTDMA_InitWithoutFirmware(void); 237 238 /*! 239 * @brief Install the firmware. 240 * 241 * @param apiMemAddr The address firmware will be copied to. 242 * @param firmware The firmware to use. 243 * @param firmwareSizeByte Size of firmware. 244 * @note Only call this function when SMARTDMA is not busy. 245 */ 246 void SMARTDMA_InstallFirmware(uint32_t apiMemAddr, const void *firmware, uint32_t firmwareSizeByte); 247 248 /*! 249 * @brief Install the complete callback function. 250 * 251 * @param callback The callback called when smartdma program finished. 252 * @param param Parameter for the callback. 253 * @note Only call this function when SMARTDMA is not busy. 254 */ 255 void SMARTDMA_InstallCallback(smartdma_callback_t callback, void *param); 256 257 /*! 258 * @brief Boot the SMARTDMA to run program. 259 * 260 * @param apiIndex Index of the API to call. 261 * @param pParam Pointer to the parameter. 262 * @param mask Value set to SMARTDMA_ARM2SMARTDMA[0:1]. 263 * @note Only call this function when SMARTDMA is not busy. 264 */ 265 void SMARTDMA_Boot(uint32_t apiIndex, void *pParam, uint8_t mask); 266 267 /*! 268 * @brief Deinitialize the SMARTDMA. 269 */ 270 void SMARTDMA_Deinit(void); 271 272 /*! 273 * @brief Reset the SMARTDMA. 274 */ 275 void SMARTDMA_Reset(void); 276 277 /*! 278 * @brief SMARTDMA IRQ. 279 */ 280 void SMARTDMA_HandleIRQ(void); 281 282 #if defined(__cplusplus) 283 } 284 #endif 285 286 /* @} */ 287 288 #endif /* _FSL_SMARTDMA_H_ */ 289