fsl_mipi_dsi.h 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817
  1. /*
  2. * Copyright 2020-2021 NXP
  3. * All rights reserved.
  4. *
  5. * SPDX-License-Identifier: BSD-3-Clause
  6. */
  7. #ifndef _FSL_MIPI_DSI_H_
  8. #define _FSL_MIPI_DSI_H_
  9. #include "fsl_common.h"
  10. /*!
  11. * @addtogroup mipi_dsi
  12. * @{
  13. */
  14. /*******************************************************************************
  15. * Definitions
  16. ******************************************************************************/
  17. /*! @name Driver version */
  18. /*@{*/
  19. #define FSL_MIPI_DSI_DRIVER_VERSION (MAKE_VERSION(2, 2, 1))
  20. /*@}*/
  21. /* The max APB transfer size. */
  22. #define FSL_DSI_TX_MAX_PAYLOAD_BYTE (64U * 4U)
  23. #define FSL_DSI_RX_MAX_PAYLOAD_BYTE (64U * 4U)
  24. /*! @brief MIPI DSI structure definition. */
  25. typedef struct
  26. {
  27. DSI_HOST_Type *host; /*!< Pointer to HOST registers. */
  28. DSI_HOST_APB_PKT_IF_Type *apb; /*!< Pointer to APB registers. */
  29. DSI_HOST_DPI_INTFC_Type *dpi; /*!< Pointer to DPI registers. */
  30. DSI_HOST_NXP_FDSOI28_DPHY_INTFC_Type *dphy; /*!< Pointer to DPHY registers. */
  31. } MIPI_DSI_Type;
  32. /*! @brief Error codes for the MIPI DSI driver. */
  33. enum
  34. {
  35. kStatus_DSI_Busy = MAKE_STATUS(kStatusGroup_MIPI_DSI, 0), /*!< DSI is busy. */
  36. kStatus_DSI_RxDataError = MAKE_STATUS(kStatusGroup_MIPI_DSI, 1), /*!< Read data error. */
  37. kStatus_DSI_ErrorReportReceived = MAKE_STATUS(kStatusGroup_MIPI_DSI, 2), /*!< Error report package received. */
  38. kStatus_DSI_NotSupported = MAKE_STATUS(kStatusGroup_MIPI_DSI, 3), /*!< The transfer type not supported. */
  39. };
  40. /*! @brief MIPI DSI controller configuration. */
  41. typedef struct _dsi_config
  42. {
  43. uint8_t numLanes; /*!< Number of lanes. */
  44. bool enableNonContinuousHsClk; /*!< In enabled, the high speed clock will enter
  45. low power mode between transmissions. */
  46. bool enableTxUlps; /*!< Enable the TX ULPS. */
  47. bool autoInsertEoTp; /*!< Insert an EoTp short package when switching from HS to LP. */
  48. uint8_t numExtraEoTp; /*!< How many extra EoTp to send after the end of a packet. */
  49. uint32_t htxTo_ByteClk; /*!< HS TX timeout count (HTX_TO) in byte clock. */
  50. uint32_t lrxHostTo_ByteClk; /*!< LP RX host timeout count (LRX-H_TO) in byte clock. */
  51. uint32_t btaTo_ByteClk; /*!< Bus turn around timeout count (TA_TO) in byte clock. */
  52. } dsi_config_t;
  53. /*! @brief MIPI DPI interface color coding. */
  54. typedef enum _dsi_dpi_color_coding
  55. {
  56. kDSI_Dpi16BitConfig1 = 0U, /*!< 16-bit configuration 1. RGB565: XXXXXXXX_RRRRRGGG_GGGBBBBB. */
  57. kDSI_Dpi16BitConfig2 = 1U, /*!< 16-bit configuration 2. RGB565: XXXRRRRR_XXGGGGGG_XXXBBBBB. */
  58. kDSI_Dpi16BitConfig3 = 2U, /*!< 16-bit configuration 3. RGB565: XXRRRRRX_XXGGGGGG_XXBBBBBX. */
  59. kDSI_Dpi18BitConfig1 = 3U, /*!< 18-bit configuration 1. RGB666: XXXXXXRR_RRRRGGGG_GGBBBBBB. */
  60. kDSI_Dpi18BitConfig2 = 4U, /*!< 18-bit configuration 2. RGB666: XXRRRRRR_XXGGGGGG_XXBBBBBB. */
  61. kDSI_Dpi24Bit = 5U, /*!< 24-bit. */
  62. } dsi_dpi_color_coding_t;
  63. /*! @brief MIPI DSI pixel packet type send through DPI interface. */
  64. typedef enum _dsi_dpi_pixel_packet
  65. {
  66. kDSI_PixelPacket16Bit = 0U, /*!< 16 bit RGB565. */
  67. kDSI_PixelPacket18Bit = 1U, /*!< 18 bit RGB666 packed. */
  68. kDSI_PixelPacket18BitLoosely = 2U, /*!< 18 bit RGB666 loosely packed into three bytes. */
  69. kDSI_PixelPacket24Bit = 3U, /*!< 24 bit RGB888, each pixel uses three bytes. */
  70. } dsi_dpi_pixel_packet_t;
  71. /*! @brief _dsi_dpi_polarity_flag DPI signal polarity. */
  72. enum
  73. {
  74. kDSI_DpiVsyncActiveLow = 0U, /*!< VSYNC active low. */
  75. kDSI_DpiHsyncActiveLow = 0U, /*!< HSYNC active low. */
  76. kDSI_DpiVsyncActiveHigh = (1U << 0U), /*!< VSYNC active high. */
  77. kDSI_DpiHsyncActiveHigh = (1U << 1U), /*!< HSYNC active high. */
  78. };
  79. /*! @brief DPI video mode. */
  80. typedef enum _dsi_dpi_video_mode
  81. {
  82. kDSI_DpiNonBurstWithSyncPulse = 0U, /*!< Non-Burst mode with Sync Pulses. */
  83. kDSI_DpiNonBurstWithSyncEvent = 1U, /*!< Non-Burst mode with Sync Events. */
  84. kDSI_DpiBurst = 2U, /*!< Burst mode. */
  85. } dsi_dpi_video_mode_t;
  86. /*! @brief Behavior in BLLP (Blanking or Low-Power Interval). */
  87. typedef enum _dsi_dpi_bllp_mode
  88. {
  89. kDSI_DpiBllpLowPower, /*!< LP mode used in BLLP periods. */
  90. kDSI_DpiBllpBlanking, /*!< Blanking packets used in BLLP periods. */
  91. kDSI_DpiBllpNull, /*!< Null packets used in BLLP periods. */
  92. } dsi_dpi_bllp_mode_t;
  93. /*! @brief MIPI DSI controller DPI interface configuration. */
  94. typedef struct _dsi_dpi_config
  95. {
  96. uint16_t pixelPayloadSize; /*!< Maximum number of pixels that should be sent
  97. as one DSI packet. Recommended that the line size
  98. (in pixels) is evenly divisible by this parameter. */
  99. dsi_dpi_color_coding_t dpiColorCoding; /*!< DPI color coding. */
  100. dsi_dpi_pixel_packet_t pixelPacket; /*!< Pixel packet format. */
  101. dsi_dpi_video_mode_t videoMode; /*!< Video mode. */
  102. dsi_dpi_bllp_mode_t bllpMode; /*!< Behavior in BLLP. */
  103. uint8_t polarityFlags; /*!< OR'ed value of _dsi_dpi_polarity_flag controls signal polarity. */
  104. uint16_t hfp; /*!< Horizontal front porch, in dpi pixel clock. */
  105. uint16_t hbp; /*!< Horizontal back porch, in dpi pixel clock. */
  106. uint16_t hsw; /*!< Horizontal sync width, in dpi pixel clock. */
  107. uint8_t vfp; /*!< Number of lines in vertical front porch. */
  108. uint8_t vbp; /*!< Number of lines in vertical back porch. */
  109. uint16_t panelHeight; /*!< Line number in vertical active area. */
  110. uint8_t virtualChannel; /*!< Virtual channel. */
  111. } dsi_dpi_config_t;
  112. /*! @brief MIPI DSI D-PHY configuration. */
  113. typedef struct _dsi_dphy_config
  114. {
  115. uint32_t txHsBitClk_Hz; /*!< The generated HS TX bit clock in Hz. */
  116. uint8_t tClkPre_ByteClk; /*!< TLPX + TCLK-PREPARE + TCLK-ZERO + TCLK-PRE in byte clock.
  117. Set how long the controller
  118. will wait after enabling clock lane for HS before
  119. enabling data lanes for HS. */
  120. uint8_t tClkPost_ByteClk; /*!< TCLK-POST + T_CLK-TRAIL in byte clock. Set how long the controller
  121. will wait before putting clock lane into LP mode after
  122. data lanes detected in stop state. */
  123. uint8_t tHsExit_ByteClk; /*!< THS-EXIT in byte clock. Set how long the controller
  124. will wait after the clock lane has been put into LP
  125. mode before enabling clock lane for HS again. */
  126. uint32_t tWakeup_EscClk; /*!< Number of clk_esc clock periods to keep a clock
  127. or data lane in Mark-1 state after exiting ULPS. */
  128. uint8_t tHsPrepare_HalfEscClk; /*!< THS-PREPARE in clk_esc/2. Set how long
  129. to drive the LP-00 state before HS transmissions,
  130. available values are 2, 3, 4, 5. */
  131. uint8_t tClkPrepare_HalfEscClk; /*!< TCLK-PREPARE in clk_esc/2. Set how long
  132. to drive the LP-00 state before HS transmissions,
  133. available values are 2, 3. */
  134. uint8_t tHsZero_ByteClk; /*!< THS-ZERO in clk_byte. Set how long that controller
  135. drives data lane HS-0 state before transmit
  136. the Sync sequence. Available values are 6, 7, ..., 37. */
  137. uint8_t tClkZero_ByteClk; /*!< TCLK-ZERO in clk_byte. Set how long that controller
  138. drives clock lane HS-0 state before transmit
  139. the Sync sequence. Available values are 3, 4, ..., 66. */
  140. uint8_t tHsTrail_ByteClk; /*!< THS-TRAIL + 4*UI in clk_byte. Set the time
  141. of the flipped differential state after last payload
  142. data bit of HS transmission burst. Available values
  143. are 0, 1, ..., 15. */
  144. uint8_t tClkTrail_ByteClk; /*!< TCLK-TRAIL + 4*UI in clk_byte. Set the time
  145. of the flipped differential state after last payload
  146. data bit of HS transmission burst. Available values
  147. are 0, 1, ..., 15. */
  148. } dsi_dphy_config_t;
  149. /*! @brief _dsi_apb_status Status of APB to packet interface. */
  150. enum
  151. {
  152. kDSI_ApbNotIdle = (1U << 0U), /*!< State machine not idle */
  153. kDSI_ApbTxDone = (1U << 1U), /*!< Tx packet done */
  154. kDSI_ApbRxControl = (1U << 2U), /*!< DPHY direction 0 - tx had control, 1 - rx has control */
  155. kDSI_ApbTxOverflow = (1U << 3U), /*!< TX fifo overflow */
  156. kDSI_ApbTxUnderflow = (1U << 4U), /*!< TX fifo underflow */
  157. kDSI_ApbRxOverflow = (1U << 5U), /*!< RX fifo overflow */
  158. kDSI_ApbRxUnderflow = (1U << 6U), /*!< RX fifo underflow */
  159. kDSI_ApbRxHeaderReceived = (1U << 7U), /*!< RX packet header has been received */
  160. kDSI_ApbRxPacketReceived = (1U << 8U), /*!< All RX packet payload data has been received */
  161. };
  162. /*! @brief _dsi_rx_error_status Host receive error status. */
  163. enum
  164. {
  165. kDSI_RxErrorEccOneBit = (1U << 0U), /*!< ECC single bit error detected. */
  166. kDSI_RxErrorEccMultiBit = (1U << 1U), /*!< ECC multi bit error detected. */
  167. kDSI_RxErrorCrc = (1U << 7U), /*!< CRC error detected. */
  168. kDSI_RxErrorHtxTo = (1U << 8U), /*!< High Speed forward TX timeout detected. */
  169. kDSI_RxErrorLrxTo = (1U << 9U), /*!< Reverse Low power data receive timeout detected. */
  170. kDSI_RxErrorBtaTo = (1U << 10U) /*!< BTA timeout detected. */
  171. };
  172. /*! @brief DSI host controller status (status_out) */
  173. enum _dsi_host_status
  174. {
  175. kDSI_HostSoTError = (1U << 0U), /*!< SoT error from peripheral error report. */
  176. kDSI_HostSoTSyncError = (1U << 1U), /*!< SoT Sync error from peripheral error report. */
  177. kDSI_HostEoTSyncError = (1U << 2U), /*!< EoT Sync error from peripheral error report. */
  178. kDSI_HostEscEntryCmdError = (1U << 3U), /*!< Escape Mode Entry Command Error from peripheral error report. */
  179. kDSI_HostLpTxSyncError = (1U << 4U), /*!< Low-power transmit Sync Error from peripheral error report. */
  180. kDSI_HostPeriphToError = (1U << 5U), /*!< Peripheral timeout error from peripheral error report. */
  181. kDSI_HostFalseControlError = (1U << 6U), /*!< False control error from peripheral error report. */
  182. kDSI_HostContentionDetected = (1U << 7U), /*!< Contention detected from peripheral error report. */
  183. kDSI_HostEccErrorOneBit = (1U << 8U), /*!< Single bit ECC error (corrected) from peripheral error report. */
  184. kDSI_HostEccErrorMultiBit = (1U << 9U), /*!< Multi bit ECC error (not corrected) from peripheral error report. */
  185. kDSI_HostChecksumError = (1U << 10U), /*!< Checksum error from peripheral error report. */
  186. kDSI_HostInvalidDataType = (1U << 11U), /*!< DSI data type not recognized. */
  187. kDSI_HostInvalidVcId = (1U << 12U), /*!< DSI VC ID invalid. */
  188. kDSI_HostInvalidTxLength = (1U << 13U), /*!< Invalid transmission length. */
  189. kDSI_HostProtocalViolation = (1U << 15U), /*!< DSI protocal violation. */
  190. kDSI_HostResetTriggerReceived = (1U << 16U), /*!< Reset trigger received. */
  191. kDSI_HostTearTriggerReceived = (1U << 17U), /*!< Tear effect trigger receive. */
  192. kDSI_HostAckTriggerReceived = (1U << 18U), /*!< Acknowledge trigger message received. */
  193. };
  194. /*! @brief _dsi_interrupt DSI interrupt. */
  195. enum
  196. {
  197. kDSI_InterruptGroup1ApbNotIdle = (1U << 0U), /*!< State machine not idle */
  198. kDSI_InterruptGroup1ApbTxDone = (1U << 1U), /*!< Tx packet done */
  199. kDSI_InterruptGroup1ApbRxControl = (1U << 2U), /*!< DPHY direction 0 - tx control, 1 - rx control */
  200. kDSI_InterruptGroup1ApbTxOverflow = (1U << 3U), /*!< TX fifo overflow */
  201. kDSI_InterruptGroup1ApbTxUnderflow = (1U << 4U), /*!< TX fifo underflow */
  202. kDSI_InterruptGroup1ApbRxOverflow = (1U << 5U), /*!< RX fifo overflow */
  203. kDSI_InterruptGroup1ApbRxUnderflow = (1U << 6U), /*!< RX fifo underflow */
  204. kDSI_InterruptGroup1ApbRxHeaderReceived = (1U << 7U), /*!< RX packet header has been received */
  205. kDSI_InterruptGroup1ApbRxPacketReceived = (1U << 8U), /*!< All RX packet payload data has been received */
  206. kDSI_InterruptGroup1SoTError = (1U << 9U), /*!< SoT error from peripheral error report. */
  207. kDSI_InterruptGroup1SoTSyncError = (1U << 10U), /*!< SoT Sync error from peripheral error report. */
  208. kDSI_InterruptGroup1EoTSyncError = (1U << 11U), /*!< EoT Sync error from peripheral error report. */
  209. kDSI_InterruptGroup1EscEntryCmdError = (1U << 12U), /*!< Escape Mode Entry Command Error
  210. from peripheral error report. */
  211. kDSI_InterruptGroup1LpTxSyncError = (1U << 13U), /*!< Low-power transmit Sync Error from
  212. peripheral error report. */
  213. kDSI_InterruptGroup1PeriphToError = (1U << 14U), /*!< Peripheral timeout error from
  214. peripheral error report. */
  215. kDSI_InterruptGroup1FalseControlError = (1U << 15U), /*!< False control error from peripheral error report. */
  216. kDSI_InterruptGroup1ContentionDetected = (1U << 16U), /*!< Contention detected from peripheral error report. */
  217. kDSI_InterruptGroup1EccErrorOneBit = (1U << 17U), /*!< Single bit ECC error (corrected) from
  218. peripheral error report. */
  219. kDSI_InterruptGroup1EccErrorMultiBit = (1U << 18U), /*!< Multi bit ECC error (not corrected) from
  220. peripheral error report. */
  221. kDSI_InterruptGroup1ChecksumError = (1U << 19U), /*!< Checksum error from peripheral error report. */
  222. kDSI_InterruptGroup1InvalidDataType = (1U << 20U), /*!< DSI data type not recognized. */
  223. kDSI_InterruptGroup1InvalidVcId = (1U << 21U), /*!< DSI VC ID invalid. */
  224. kDSI_InterruptGroup1InvalidTxLength = (1U << 22U), /*!< Invalid transmission length. */
  225. kDSI_InterruptGroup1ProtocalViolation = (1U << 24U), /*!< DSI protocal violation. */
  226. kDSI_InterruptGroup1ResetTriggerReceived = (1U << 25U), /*!< Reset trigger received. */
  227. kDSI_InterruptGroup1TearTriggerReceived = (1U << 26U), /*!< Tear effect trigger receive. */
  228. kDSI_InterruptGroup1AckTriggerReceived = (1U << 27U), /*!< Acknowledge trigger message received. */
  229. kDSI_InterruptGroup1HtxTo = (1U << 29U), /*!< High speed TX timeout. */
  230. kDSI_InterruptGroup1LrxTo = (1U << 30U), /*!< Low power RX timeout. */
  231. kDSI_InterruptGroup1BtaTo = (1U << 31U), /*!< Host BTA timeout. */
  232. kDSI_InterruptGroup2EccOneBit = (1U << 0U), /*!< Sinle bit ECC error. */
  233. kDSI_InterruptGroup2EccMultiBit = (1U << 1U), /*!< Multi bit ECC error. */
  234. kDSI_InterruptGroup2CrcError = (1U << 2U), /*!< CRC error. */
  235. };
  236. /*! @brief DSI TX data type. */
  237. typedef enum _dsi_tx_data_type
  238. {
  239. kDSI_TxDataVsyncStart = 0x01U, /*!< V Sync start. */
  240. kDSI_TxDataVsyncEnd = 0x11U, /*!< V Sync end. */
  241. kDSI_TxDataHsyncStart = 0x21U, /*!< H Sync start. */
  242. kDSI_TxDataHsyncEnd = 0x31U, /*!< H Sync end. */
  243. kDSI_TxDataEoTp = 0x08U, /*!< End of transmission packet. */
  244. kDSI_TxDataCmOff = 0x02U, /*!< Color mode off. */
  245. kDSI_TxDataCmOn = 0x12U, /*!< Color mode on. */
  246. kDSI_TxDataShutDownPeriph = 0x22U, /*!< Shut down peripheral. */
  247. kDSI_TxDataTurnOnPeriph = 0x32U, /*!< Turn on peripheral. */
  248. kDSI_TxDataGenShortWrNoParam = 0x03U, /*!< Generic Short WRITE, no parameters. */
  249. kDSI_TxDataGenShortWrOneParam = 0x13U, /*!< Generic Short WRITE, one parameter. */
  250. kDSI_TxDataGenShortWrTwoParam = 0x23U, /*!< Generic Short WRITE, two parameter. */
  251. kDSI_TxDataGenShortRdNoParam = 0x04U, /*!< Generic Short READ, no parameters. */
  252. kDSI_TxDataGenShortRdOneParam = 0x14U, /*!< Generic Short READ, one parameter. */
  253. kDSI_TxDataGenShortRdTwoParam = 0x24U, /*!< Generic Short READ, two parameter. */
  254. kDSI_TxDataDcsShortWrNoParam = 0x05U, /*!< DCS Short WRITE, no parameters. */
  255. kDSI_TxDataDcsShortWrOneParam = 0x15U, /*!< DCS Short WRITE, one parameter. */
  256. kDSI_TxDataDcsShortRdNoParam = 0x06U, /*!< DCS Short READ, no parameters. */
  257. kDSI_TxDataSetMaxReturnPktSize = 0x37U, /*!< Set the Maximum Return Packet Size. */
  258. kDSI_TxDataNull = 0x09U, /*!< Null Packet, no data. */
  259. kDSI_TxDataBlanking = 0x19U, /*!< Blanking Packet, no data. */
  260. kDSI_TxDataGenLongWr = 0x29U, /*!< Generic long write. */
  261. kDSI_TxDataDcsLongWr = 0x39U, /*!< DCS Long Write/write_LUT Command Packet. */
  262. kDSI_TxDataLooselyPackedPixel20BitYCbCr = 0x0CU, /*!< Loosely Packed Pixel Stream, 20-bit YCbCr, 4:2:2 Format. */
  263. kDSI_TxDataPackedPixel24BitYCbCr = 0x1CU, /*!< Packed Pixel Stream, 24-bit YCbCr, 4:2:2 Format. */
  264. kDSI_TxDataPackedPixel16BitYCbCr = 0x2CU, /*!< Packed Pixel Stream, 16-bit YCbCr, 4:2:2 Format. */
  265. kDSI_TxDataPackedPixel30BitRGB = 0x0DU, /*!< Packed Pixel Stream, 30-bit RGB, 10-10-10 Format. */
  266. kDSI_TxDataPackedPixel36BitRGB = 0x1DU, /*!< Packed Pixel Stream, 36-bit RGB, 12-12-12 Format. */
  267. kDSI_TxDataPackedPixel12BitYCrCb = 0x3DU, /*!< Packed Pixel Stream, 12-bit YCbCr, 4:2:0 Format. */
  268. kDSI_TxDataPackedPixel16BitRGB = 0x0EU, /*!< Packed Pixel Stream, 16-bit RGB, 5-6-5 Format. */
  269. kDSI_TxDataPackedPixel18BitRGB = 0x1EU, /*!< Packed Pixel Stream, 18-bit RGB, 6-6-6 Format. */
  270. kDSI_TxDataLooselyPackedPixel18BitRGB = 0x2EU, /*!< Loosely Packed Pixel Stream, 18-bit RGB, 6-6-6 Format. */
  271. kDSI_TxDataPackedPixel24BitRGB = 0x3EU, /*!< Packed Pixel Stream, 24-bit RGB, 8-8-8 Format. */
  272. } dsi_tx_data_type_t;
  273. /*! @brief DSI RX data type. */
  274. typedef enum _dsi_rx_data_type
  275. {
  276. kDSI_RxDataAckAndErrorReport = 0x02U, /*!< Acknowledge and Error Report */
  277. kDSI_RxDataEoTp = 0x08U, /*!< End of Transmission packet. */
  278. kDSI_RxDataGenShortRdResponseOneByte = 0x11U, /*!< Generic Short READ Response, 1 byte returned. */
  279. kDSI_RxDataGenShortRdResponseTwoByte = 0x12U, /*!< Generic Short READ Response, 2 byte returned. */
  280. kDSI_RxDataGenLongRdResponse = 0x1AU, /*!< Generic Long READ Response. */
  281. kDSI_RxDataDcsLongRdResponse = 0x1CU, /*!< DCS Long READ Response. */
  282. kDSI_RxDataDcsShortRdResponseOneByte = 0x21U, /*!< DCS Short READ Response, 1 byte returned. */
  283. kDSI_RxDataDcsShortRdResponseTwoByte = 0x22U, /*!< DCS Short READ Response, 2 byte returned. */
  284. } dsi_rx_data_type_t;
  285. /*! @brief _dsi_transfer_flags DSI transfer control flags. */
  286. enum
  287. {
  288. kDSI_TransferUseHighSpeed = (1U << 0U), /*!< Use high speed mode or not. */
  289. kDSI_TransferPerformBTA = (1U << 1U), /*!< Perform BTA or not. */
  290. };
  291. /*! @brief Structure for the data transfer. */
  292. typedef struct _dsi_transfer
  293. {
  294. uint8_t virtualChannel; /*!< Virtual channel. */
  295. dsi_tx_data_type_t txDataType; /*!< TX data type. */
  296. uint8_t flags; /*!< Flags to control the transfer, see _dsi_transfer_flags. */
  297. const uint8_t *txData; /*!< The TX data buffer. */
  298. uint8_t *rxData; /*!< The TX data buffer. */
  299. uint16_t txDataSize; /*!< Size of the TX data. */
  300. uint16_t rxDataSize; /*!< Size of the RX data. */
  301. bool sendDscCmd; /*!< If set to true, the DSC command is specified by @ref dscCmd, otherwise
  302. the DSC command is included in the @ref txData. */
  303. uint8_t dscCmd; /*!< The DSC command to send, only valid when @ref sendDscCmd is true. */
  304. } dsi_transfer_t;
  305. /*! @brief MIPI DSI transfer handle. */
  306. typedef struct _dsi_handle dsi_handle_t;
  307. /*!
  308. * @brief MIPI DSI callback for finished transfer.
  309. *
  310. * When transfer finished, one of these status values will be passed to the user:
  311. * - @ref kStatus_Success Data transfer finished with no error.
  312. * - @ref kStatus_Timeout Transfer failed because of timeout.
  313. * - @ref kStatus_DSI_RxDataError RX data error, user could use @ref DSI_GetRxErrorStatus
  314. * to check the error details.
  315. * - @ref kStatus_DSI_ErrorReportReceived Error Report packet received, user could use
  316. * @ref DSI_GetAndClearHostStatus to check the error report status.
  317. * - @ref kStatus_Fail Transfer failed for other reasons.
  318. */
  319. typedef void (*dsi_callback_t)(const MIPI_DSI_Type *base, dsi_handle_t *handle, status_t status, void *userData);
  320. /*! @brief MIPI DSI transfer handle structure */
  321. struct _dsi_handle
  322. {
  323. volatile bool isBusy; /*!< MIPI DSI is busy with APB data transfer. */
  324. dsi_transfer_t xfer; /*!< Transfer information. */
  325. dsi_callback_t callback; /*!< DSI callback */
  326. void *userData; /*!< Callback parameter */
  327. const MIPI_DSI_Type *dsi; /*!< Pointer to MIPI DSI peripheral. */
  328. };
  329. /*******************************************************************************
  330. * API
  331. ******************************************************************************/
  332. #if defined(__cplusplus)
  333. extern "C" {
  334. #endif
  335. /*!
  336. * @name MIPI_DSI host initialization.
  337. * @{
  338. */
  339. /*!
  340. * @brief Initializes an MIPI DSI host with the user configuration.
  341. *
  342. * This function initializes the MIPI DSI host with the configuration, it should
  343. * be called first before other MIPI DSI driver functions.
  344. *
  345. * @param base MIPI DSI host peripheral base address.
  346. * @param config Pointer to a user-defined configuration structure.
  347. */
  348. void DSI_Init(const MIPI_DSI_Type *base, const dsi_config_t *config);
  349. /*!
  350. * @brief Deinitializes an MIPI DSI host.
  351. *
  352. * This function should be called after all bother MIPI DSI driver functions.
  353. *
  354. * @param base MIPI DSI host peripheral base address.
  355. */
  356. void DSI_Deinit(const MIPI_DSI_Type *base);
  357. /*!
  358. * @brief Get the default configuration to initialize the MIPI DSI host.
  359. *
  360. * The default value is:
  361. * @code
  362. config->numLanes = 4;
  363. config->enableNonContinuousHsClk = false;
  364. config->enableTxUlps = false;
  365. config->autoInsertEoTp = true;
  366. config->numExtraEoTp = 0;
  367. config->htxTo_ByteClk = 0;
  368. config->lrxHostTo_ByteClk = 0;
  369. config->btaTo_ByteClk = 0;
  370. @endcode
  371. *
  372. * @param config Pointer to a user-defined configuration structure.
  373. */
  374. void DSI_GetDefaultConfig(dsi_config_t *config);
  375. /*! @} */
  376. /*!
  377. * @name DPI interface
  378. * @{
  379. */
  380. /*!
  381. * @brief Configure the DPI interface core.
  382. *
  383. * This function sets the DPI interface configuration, it should be used in
  384. * video mode.
  385. *
  386. * @param base MIPI DSI host peripheral base address.
  387. * @param config Pointer to the DPI interface configuration.
  388. * @param numLanes Lane number, should be same with the setting in @ref dsi_dpi_config_t.
  389. * @param dpiPixelClkFreq_Hz The DPI pixel clock frequency in Hz.
  390. * @param dsiHsBitClkFreq_Hz The DSI high speed bit clock frequency in Hz. It is
  391. * the same with DPHY PLL output.
  392. */
  393. void DSI_SetDpiConfig(const MIPI_DSI_Type *base,
  394. const dsi_dpi_config_t *config,
  395. uint8_t numLanes,
  396. uint32_t dpiPixelClkFreq_Hz,
  397. uint32_t dsiHsBitClkFreq_Hz);
  398. /*! @} */
  399. /*!
  400. * @name D-PHY configuration.
  401. * @{
  402. */
  403. /*!
  404. * @brief Initializes the D-PHY
  405. *
  406. * This function configures the D-PHY timing and setups the D-PHY PLL based on
  407. * user configuration. The configuration structure could be got by the function
  408. * @ref DSI_GetDphyDefaultConfig.
  409. *
  410. * For some platforms there is not dedicated D-PHY PLL, indicated by the macro
  411. * FSL_FEATURE_MIPI_DSI_NO_DPHY_PLL. For these platforms, the @p refClkFreq_Hz
  412. * is useless.
  413. *
  414. * @param base MIPI DSI host peripheral base address.
  415. * @param config Pointer to the D-PHY configuration.
  416. * @param refClkFreq_Hz The REFCLK frequency in Hz.
  417. * @return The actual D-PHY PLL output frequency. If could not configure the
  418. * PLL to the target frequency, the return value is 0.
  419. */
  420. uint32_t DSI_InitDphy(const MIPI_DSI_Type *base, const dsi_dphy_config_t *config, uint32_t refClkFreq_Hz);
  421. /*!
  422. * @brief Deinitializes the D-PHY
  423. *
  424. * Power down the D-PHY PLL and shut down D-PHY.
  425. *
  426. * @param base MIPI DSI host peripheral base address.
  427. */
  428. void DSI_DeinitDphy(const MIPI_DSI_Type *base);
  429. /*!
  430. * @brief Get the default D-PHY configuration.
  431. *
  432. * Gets the default D-PHY configuration, the timing parameters are set according
  433. * to D-PHY specification. User could use the configuration directly, or change
  434. * some parameters according to the special device.
  435. *
  436. * @param config Pointer to the D-PHY configuration.
  437. * @param txHsBitClk_Hz High speed bit clock in Hz.
  438. * @param txEscClk_Hz Esc clock in Hz.
  439. */
  440. void DSI_GetDphyDefaultConfig(dsi_dphy_config_t *config, uint32_t txHsBitClk_Hz, uint32_t txEscClk_Hz);
  441. /*! @} */
  442. /*!
  443. * @name Interrupts
  444. * @{
  445. */
  446. /*!
  447. * @brief Enable the interrupts.
  448. *
  449. * The interrupts to enable are passed in as OR'ed mask value of _dsi_interrupt.
  450. *
  451. * @param base MIPI DSI host peripheral base address.
  452. * @param intGroup1 Interrupts to enable in group 1.
  453. * @param intGroup2 Interrupts to enable in group 2.
  454. */
  455. static inline void DSI_EnableInterrupts(const MIPI_DSI_Type *base, uint32_t intGroup1, uint32_t intGroup2)
  456. {
  457. base->apb->IRQ_MASK &= ~intGroup1;
  458. base->apb->IRQ_MASK2 &= ~intGroup2;
  459. }
  460. /*!
  461. * @brief Disable the interrupts.
  462. *
  463. * The interrupts to disable are passed in as OR'ed mask value of _dsi_interrupt.
  464. *
  465. * @param base MIPI DSI host peripheral base address.
  466. * @param intGroup1 Interrupts to disable in group 1.
  467. * @param intGroup2 Interrupts to disable in group 2.
  468. */
  469. static inline void DSI_DisableInterrupts(const MIPI_DSI_Type *base, uint32_t intGroup1, uint32_t intGroup2)
  470. {
  471. base->apb->IRQ_MASK |= intGroup1;
  472. base->apb->IRQ_MASK2 |= intGroup2;
  473. }
  474. /*!
  475. * @brief Get and clear the interrupt status.
  476. *
  477. * @param base MIPI DSI host peripheral base address.
  478. * @param intGroup1 Group 1 interrupt status.
  479. * @param intGroup2 Group 2 interrupt status.
  480. */
  481. static inline void DSI_GetAndClearInterruptStatus(const MIPI_DSI_Type *base, uint32_t *intGroup1, uint32_t *intGroup2)
  482. {
  483. *intGroup2 = base->apb->IRQ_STATUS2;
  484. *intGroup1 = base->apb->IRQ_STATUS;
  485. }
  486. /*! @} */
  487. /*!
  488. * @name MIPI DSI APB
  489. * @{
  490. */
  491. /*!
  492. * @brief Configure the APB packet to send.
  493. *
  494. * This function configures the next APB packet transfer. After configuration,
  495. * the packet transfer could be started with function @ref DSI_SendApbPacket.
  496. * If the packet is long packet, Use @ref DSI_WriteApbTxPayload to fill the payload
  497. * before start transfer.
  498. *
  499. * @param base MIPI DSI host peripheral base address.
  500. * @param wordCount For long packet, this is the byte count of the payload.
  501. * For short packet, this is (data1 << 8) | data0.
  502. * @param virtualChannel Virtual channel.
  503. * @param dataType The packet data type, (DI).
  504. * @param flags The transfer control flags, see _dsi_transfer_flags.
  505. */
  506. void DSI_SetApbPacketControl(
  507. const MIPI_DSI_Type *base, uint16_t wordCount, uint8_t virtualChannel, dsi_tx_data_type_t dataType, uint8_t flags);
  508. /*!
  509. * @brief Fill the long APB packet payload.
  510. *
  511. * Write the long packet payload to TX FIFO.
  512. *
  513. * @param base MIPI DSI host peripheral base address.
  514. * @param payload Pointer to the payload.
  515. * @param payloadSize Payload size in byte.
  516. */
  517. void DSI_WriteApbTxPayload(const MIPI_DSI_Type *base, const uint8_t *payload, uint16_t payloadSize);
  518. /*!
  519. * @brief Extended function to fill the payload to TX FIFO.
  520. *
  521. * Write the long packet payload to TX FIFO. This function could be used in two ways
  522. *
  523. * 1. Include the DSC command in parameter @p payload. In this case, the DSC command
  524. * is the first byte of @p payload. The parameter @p sendDscCmd is set to false,
  525. * the @p dscCmd is not used. This function is the same as @ref DSI_WriteApbTxPayload
  526. * when used in this way.
  527. *
  528. * 2. The DSC command in not in parameter @p payload, but specified by parameter @p dscCmd.
  529. * In this case, the parameter @p sendDscCmd is set to true, the @p dscCmd is the DSC
  530. * command to send. The @p payload is sent after @p dscCmd.
  531. *
  532. * @param base MIPI DSI host peripheral base address.
  533. * @param payload Pointer to the payload.
  534. * @param payloadSize Payload size in byte.
  535. * @param sendDscCmd If set to true, the DSC command is specified by @p dscCmd,
  536. * otherwise the DSC command is included in the @p payload.
  537. * @param dscCmd The DSC command to send, only used when @p sendDscCmd is true.
  538. */
  539. void DSI_WriteApbTxPayloadExt(
  540. const MIPI_DSI_Type *base, const uint8_t *payload, uint16_t payloadSize, bool sendDscCmd, uint8_t dscCmd);
  541. /*!
  542. * @brief Read the long APB packet payload.
  543. *
  544. * Read the long packet payload from RX FIFO. This function reads directly but
  545. * does not check the RX FIFO status. Upper layer should make sure there are
  546. * available data.
  547. *
  548. * @param base MIPI DSI host peripheral base address.
  549. * @param payload Pointer to the payload.
  550. * @param payloadSize Payload size in byte.
  551. */
  552. void DSI_ReadApbRxPayload(const MIPI_DSI_Type *base, uint8_t *payload, uint16_t payloadSize);
  553. /*!
  554. * @brief Trigger the controller to send out APB packet.
  555. *
  556. * Send the packet set by @ref DSI_SetApbPacketControl.
  557. *
  558. * @param base MIPI DSI host peripheral base address.
  559. */
  560. static inline void DSI_SendApbPacket(const MIPI_DSI_Type *base)
  561. {
  562. base->apb->SEND_PACKET = 0x1U;
  563. }
  564. /*!
  565. * @brief Get the APB status.
  566. *
  567. * The return value is OR'ed value of _dsi_apb_status.
  568. *
  569. * @param base MIPI DSI host peripheral base address.
  570. * @return The APB status.
  571. */
  572. static inline uint32_t DSI_GetApbStatus(const MIPI_DSI_Type *base)
  573. {
  574. return base->apb->PKT_STATUS;
  575. }
  576. /*!
  577. * @brief Get the error status during data transfer.
  578. *
  579. * The return value is OR'ed value of _dsi_rx_error_status.
  580. *
  581. * @param base MIPI DSI host peripheral base address.
  582. * @return The error status.
  583. */
  584. static inline uint32_t DSI_GetRxErrorStatus(const MIPI_DSI_Type *base)
  585. {
  586. return base->host->RX_ERROR_STATUS;
  587. }
  588. /*!
  589. * @brief Get the one-bit RX ECC error position.
  590. *
  591. * When one-bit ECC RX error detected using @ref DSI_GetRxErrorStatus, this
  592. * function could be used to get the error bit position.
  593. *
  594. * @code
  595. uint8_t eccErrorPos;
  596. uint32_t rxErrorStatus = DSI_GetRxErrorStatus(MIPI_DSI);
  597. if (kDSI_RxErrorEccOneBit & rxErrorStatus)
  598. {
  599. eccErrorPos = DSI_GetEccRxErrorPosition(rxErrorStatus);
  600. }
  601. @endcode
  602. *
  603. * @param rxErrorStatus The error status returned by @ref DSI_GetRxErrorStatus.
  604. * @return The 1-bit ECC error position.
  605. */
  606. static inline uint8_t DSI_GetEccRxErrorPosition(uint32_t rxErrorStatus)
  607. {
  608. return (uint8_t)((rxErrorStatus >> 2U) & 0x1FU);
  609. }
  610. /*!
  611. * @brief Get and clear the DSI host status.
  612. *
  613. * The host status are returned as mask value of @ref _dsi_host_status.
  614. *
  615. * @param base MIPI DSI host peripheral base address.
  616. * @return The DSI host status.
  617. */
  618. static inline uint32_t DSI_GetAndClearHostStatus(const MIPI_DSI_Type *base)
  619. {
  620. return base->host->CFG_STATUS_OUT;
  621. }
  622. /*!
  623. * @brief Get the RX packet header.
  624. *
  625. * @param base MIPI DSI host peripheral base address.
  626. * @return The RX packet header.
  627. */
  628. static inline uint32_t DSI_GetRxPacketHeader(const MIPI_DSI_Type *base)
  629. {
  630. return base->apb->PKT_RX_PKT_HEADER;
  631. }
  632. /*!
  633. * @brief Extract the RX packet type from the packet header.
  634. *
  635. * Extract the RX packet type from the packet header get by @ref DSI_GetRxPacketHeader.
  636. *
  637. * @param rxPktHeader The RX packet header get by @ref DSI_GetRxPacketHeader.
  638. * @return The RX packet type.
  639. */
  640. static inline dsi_rx_data_type_t DSI_GetRxPacketType(uint32_t rxPktHeader)
  641. {
  642. return (dsi_rx_data_type_t)(uint8_t)((rxPktHeader >> 16U) & 0x3FU);
  643. }
  644. /*!
  645. * @brief Extract the RX packet word count from the packet header.
  646. *
  647. * Extract the RX packet word count from the packet header get by @ref DSI_GetRxPacketHeader.
  648. *
  649. * @param rxPktHeader The RX packet header get by @ref DSI_GetRxPacketHeader.
  650. * @return For long packet, return the payload word count (byte). For short packet,
  651. * return the (data0 << 8) | data1.
  652. */
  653. static inline uint16_t DSI_GetRxPacketWordCount(uint32_t rxPktHeader)
  654. {
  655. return (uint16_t)(rxPktHeader & 0xFFFFU);
  656. }
  657. /*!
  658. * @brief Extract the RX packet virtual channel from the packet header.
  659. *
  660. * Extract the RX packet virtual channel from the packet header get by @ref DSI_GetRxPacketHeader.
  661. *
  662. * @param rxPktHeader The RX packet header get by @ref DSI_GetRxPacketHeader.
  663. * @return The virtual channel.
  664. */
  665. static inline uint8_t DSI_GetRxPacketVirtualChannel(uint32_t rxPktHeader)
  666. {
  667. return (uint8_t)((rxPktHeader >> 22U) & 0x3U);
  668. }
  669. /*!
  670. * @brief APB data transfer using blocking method.
  671. *
  672. * Perform APB data transfer using blocking method. This function waits until all
  673. * data send or received, or timeout happens.
  674. *
  675. * @param base MIPI DSI host peripheral base address.
  676. * @param xfer Pointer to the transfer structure.
  677. * @retval kStatus_Success Data transfer finished with no error.
  678. * @retval kStatus_Timeout Transfer failed because of timeout.
  679. * @retval kStatus_DSI_RxDataError RX data error, user could use @ref DSI_GetRxErrorStatus
  680. * to check the error details.
  681. * @retval kStatus_DSI_ErrorReportReceived Error Report packet received, user could use
  682. * @ref DSI_GetAndClearHostStatus to check the error report status.
  683. * @retval kStatus_DSI_NotSupported Transfer format not supported.
  684. * @retval kStatus_DSI_Fail Transfer failed for other reasons.
  685. */
  686. status_t DSI_TransferBlocking(const MIPI_DSI_Type *base, dsi_transfer_t *xfer);
  687. /*! @} */
  688. /*!
  689. * @name Transactional
  690. * @{
  691. */
  692. /*!
  693. * @brief Create the MIPI DSI handle.
  694. *
  695. * This function initializes the MIPI DSI handle which can be used for other transactional APIs.
  696. *
  697. * @param base MIPI DSI host peripheral base address.
  698. * @param handle Handle pointer.
  699. * @param callback Callback function.
  700. * @param userData User data.
  701. */
  702. status_t DSI_TransferCreateHandle(const MIPI_DSI_Type *base,
  703. dsi_handle_t *handle,
  704. dsi_callback_t callback,
  705. void *userData);
  706. /*!
  707. * @brief APB data transfer using interrupt method.
  708. *
  709. * Perform APB data transfer using interrupt method, when transfer finished,
  710. * upper layer could be informed through callback function.
  711. *
  712. * @param base MIPI DSI host peripheral base address.
  713. * @param handle pointer to dsi_handle_t structure which stores the transfer state.
  714. * @param xfer Pointer to the transfer structure.
  715. *
  716. * @retval kStatus_Success Data transfer started successfully.
  717. * @retval kStatus_DSI_Busy Failed to start transfer because DSI is busy with pervious transfer.
  718. * @retval kStatus_DSI_NotSupported Transfer format not supported.
  719. */
  720. status_t DSI_TransferNonBlocking(const MIPI_DSI_Type *base, dsi_handle_t *handle, dsi_transfer_t *xfer);
  721. /*!
  722. * @brief Abort current APB data transfer.
  723. *
  724. * @param base MIPI DSI host peripheral base address.
  725. * @param handle pointer to dsi_handle_t structure which stores the transfer state.
  726. */
  727. void DSI_TransferAbort(const MIPI_DSI_Type *base, dsi_handle_t *handle);
  728. /*!
  729. * @brief Interrupt handler for the DSI.
  730. *
  731. * @param base MIPI DSI host peripheral base address.
  732. * @param handle pointer to dsi_handle_t structure which stores the transfer state.
  733. */
  734. void DSI_TransferHandleIRQ(const MIPI_DSI_Type *base, dsi_handle_t *handle);
  735. /*! @} */
  736. #if defined(__cplusplus)
  737. }
  738. #endif
  739. /*! @} */
  740. #endif /* _FSL_MIPI_DSI_H_ */