fsl_mipi_csi2rx.h 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383
  1. /*
  2. * Copyright 2017, 2019-2020 NXP
  3. * All rights reserved.
  4. *
  5. *
  6. * SPDX-License-Identifier: BSD-3-Clause
  7. */
  8. #ifndef _FSL_MIPI_CSI2RX_H_
  9. #define _FSL_MIPI_CSI2RX_H_
  10. #include "fsl_common.h"
  11. /*!
  12. * @addtogroup csi2rx
  13. * @{
  14. */
  15. /*******************************************************************************
  16. * Definitions
  17. ******************************************************************************/
  18. /*! @name Driver version */
  19. /*@{*/
  20. /*! @brief CSI2RX driver version. */
  21. #define FSL_CSI2RX_DRIVER_VERSION (MAKE_VERSION(2, 0, 4))
  22. /*@}*/
  23. #if (defined(FSL_FEATURE_CSI2RX_HAS_NO_REG_PREFIX) && FSL_FEATURE_CSI2RX_HAS_NO_REG_PREFIX)
  24. #define CSI2RX_REG_CFG_NUM_LANES(base) (base)->CFG_NUM_LANES
  25. #define CSI2RX_REG_CFG_DISABLE_DATA_LANES(base) (base)->CFG_DISABLE_DATA_LANES
  26. #define CSI2RX_REG_BIT_ERR(base) (base)->BIT_ERR
  27. #define CSI2RX_REG_IRQ_STATUS(base) (base)->IRQ_STATUS
  28. #define CSI2RX_REG_IRQ_MASK(base) (base)->IRQ_MASK
  29. #define CSI2RX_REG_ULPS_STATUS(base) (base)->ULPS_STATUS
  30. #define CSI2RX_REG_PPI_ERRSOT_HS(base) (base)->PPI_ERRSOT_HS
  31. #define CSI2RX_REG_PPI_ERRSOTSYNC_HS(base) (base)->PPI_ERRSOTSYNC_HS
  32. #define CSI2RX_REG_PPI_ERRESC(base) (base)->PPI_ERRESC
  33. #define CSI2RX_REG_PPI_ERRSYNCESC(base) (base)->PPI_ERRSYNCESC
  34. #define CSI2RX_REG_PPI_ERRCONTROL(base) (base)->PPI_ERRCONTROL
  35. #define CSI2RX_REG_CFG_DISABLE_PAYLOAD_0(base) (base)->CFG_DISABLE_PAYLOAD_0
  36. #define CSI2RX_REG_CFG_DISABLE_PAYLOAD_1(base) (base)->CFG_DISABLE_PAYLOAD_1
  37. #define CSI2RX_REG_CFG_IGNORE_VC(base) (base)->CFG_IGNORE_VC
  38. #define CSI2RX_REG_CFG_VID_VC(base) (base)->CFG_VID_VC
  39. #define CSI2RX_REG_CFG_VID_P_FIFO_SEND_LEVEL(base) (base)->CFG_VID_P_FIFO_SEND_LEVEL
  40. #define CSI2RX_REG_CFG_VID_VSYNC(base) (base)->CFG_VID_VSYNC
  41. #define CSI2RX_REG_CFG_VID_HSYNC_FP(base) (base)->CFG_VID_HSYNC_FP
  42. #define CSI2RX_REG_CFG_VID_HSYNC(base) (base)->CFG_VID_HSYNC
  43. #define CSI2RX_REG_CFG_VID_HSYNC_BP(base) (base)->CFG_VID_HSYNC_BP
  44. #else
  45. #define CSI2RX_REG_CFG_NUM_LANES(base) (base)->CSI2RX_CFG_NUM_LANES
  46. #define CSI2RX_REG_CFG_DISABLE_DATA_LANES(base) (base)->CSI2RX_CFG_DISABLE_DATA_LANES
  47. #define CSI2RX_REG_BIT_ERR(base) (base)->CSI2RX_BIT_ERR
  48. #define CSI2RX_REG_IRQ_STATUS(base) (base)->CSI2RX_IRQ_STATUS
  49. #define CSI2RX_REG_IRQ_MASK(base) (base)->CSI2RX_IRQ_MASK
  50. #define CSI2RX_REG_ULPS_STATUS(base) (base)->CSI2RX_ULPS_STATUS
  51. #define CSI2RX_REG_PPI_ERRSOT_HS(base) (base)->CSI2RX_PPI_ERRSOT_HS
  52. #define CSI2RX_REG_PPI_ERRSOTSYNC_HS(base) (base)->CSI2RX_PPI_ERRSOTSYNC_HS
  53. #define CSI2RX_REG_PPI_ERRESC(base) (base)->CSI2RX_PPI_ERRESC
  54. #define CSI2RX_REG_PPI_ERRSYNCESC(base) (base)->CSI2RX_PPI_ERRSYNCESC
  55. #define CSI2RX_REG_PPI_ERRCONTROL(base) (base)->CSI2RX_PPI_ERRCONTROL
  56. #define CSI2RX_REG_CFG_DISABLE_PAYLOAD_0(base) (base)->CSI2RX_CFG_DISABLE_PAYLOAD_0
  57. #define CSI2RX_REG_CFG_DISABLE_PAYLOAD_1(base) (base)->CSI2RX_CFG_DISABLE_PAYLOAD_1
  58. #define CSI2RX_REG_CFG_IGNORE_VC(base) (base)->CSI2RX_CFG_IGNORE_VC
  59. #define CSI2RX_REG_CFG_VID_VC(base) (base)->CSI2RX_CFG_VID_VC
  60. #define CSI2RX_REG_CFG_VID_P_FIFO_SEND_LEVEL(base) (base)->CSI2RX_CFG_VID_P_FIFO_SEND_LEVEL
  61. #define CSI2RX_REG_CFG_VID_VSYNC(base) (base)->CSI2RX_CFG_VID_VSYNC
  62. #define CSI2RX_REG_CFG_VID_HSYNC_FP(base) (base)->CSI2RX_CFG_VID_HSYNC_FP
  63. #define CSI2RX_REG_CFG_VID_HSYNC(base) (base)->CSI2RX_CFG_VID_HSYNC
  64. #define CSI2RX_REG_CFG_VID_HSYNC_BP(base) (base)->CSI2RX_CFG_VID_HSYNC_BP
  65. #endif
  66. #ifndef MIPI_CSI2RX_CSI2RX_CFG_NUM_LANES_csi2rx_cfg_num_lanes_MASK
  67. #define MIPI_CSI2RX_CSI2RX_CFG_NUM_LANES_csi2rx_cfg_num_lanes_MASK MIPI_CSI2RX_CFG_NUM_LANES_CFG_NUM_LANES_MASK
  68. #endif
  69. #ifndef MIPI_CSI2RX_CSI2RX_IRQ_MASK_csi2rx_irq_mask_MASK
  70. #define MIPI_CSI2RX_CSI2RX_IRQ_MASK_csi2rx_irq_mask_MASK MIPI_CSI2RX_IRQ_MASK_IRQ_MASK_MASK
  71. #endif
  72. /*! @brief CSI2RX data lanes. */
  73. enum _csi2rx_data_lane
  74. {
  75. kCSI2RX_DataLane0 = (1U << 0U), /*!< Data lane 0. */
  76. kCSI2RX_DataLane1 = (1U << 1U), /*!< Data lane 1. */
  77. kCSI2RX_DataLane2 = (1U << 2U), /*!< Data lane 2. */
  78. kCSI2RX_DataLane3 = (1U << 3U) /*!< Data lane 3. */
  79. };
  80. /*! @brief CSI2RX payload type. */
  81. enum _csi2rx_payload
  82. {
  83. kCSI2RX_PayloadGroup0Null = (1U << 0U), /*!< NULL. */
  84. kCSI2RX_PayloadGroup0Blank = (1U << 1U), /*!< Blank. */
  85. kCSI2RX_PayloadGroup0Embedded = (1U << 2U), /*!< Embedded. */
  86. kCSI2RX_PayloadGroup0YUV420_8Bit = (1U << 10U), /*!< Legacy YUV420 8 bit. */
  87. kCSI2RX_PayloadGroup0YUV422_8Bit = (1U << 14U), /*!< YUV422 8 bit. */
  88. kCSI2RX_PayloadGroup0YUV422_10Bit = (1U << 15U), /*!< YUV422 10 bit. */
  89. kCSI2RX_PayloadGroup0RGB444 = (1U << 16U), /*!< RGB444. */
  90. kCSI2RX_PayloadGroup0RGB555 = (1U << 17U), /*!< RGB555. */
  91. kCSI2RX_PayloadGroup0RGB565 = (1U << 18U), /*!< RGB565. */
  92. kCSI2RX_PayloadGroup0RGB666 = (1U << 19U), /*!< RGB666. */
  93. kCSI2RX_PayloadGroup0RGB888 = (1U << 20U), /*!< RGB888. */
  94. kCSI2RX_PayloadGroup0Raw6 = (1U << 24U), /*!< Raw 6. */
  95. kCSI2RX_PayloadGroup0Raw7 = (1U << 25U), /*!< Raw 7. */
  96. kCSI2RX_PayloadGroup0Raw8 = (1U << 26U), /*!< Raw 8. */
  97. kCSI2RX_PayloadGroup0Raw10 = (1U << 27U), /*!< Raw 10. */
  98. kCSI2RX_PayloadGroup0Raw12 = (1U << 28U), /*!< Raw 12. */
  99. kCSI2RX_PayloadGroup0Raw14 = (1U << 29U), /*!< Raw 14. */
  100. kCSI2RX_PayloadGroup1UserDefined1 = (1U << 0U), /*!< User defined 8-bit data type 1, 0x30. */
  101. kCSI2RX_PayloadGroup1UserDefined2 = (1U << 1U), /*!< User defined 8-bit data type 2, 0x31. */
  102. kCSI2RX_PayloadGroup1UserDefined3 = (1U << 2U), /*!< User defined 8-bit data type 3, 0x32. */
  103. kCSI2RX_PayloadGroup1UserDefined4 = (1U << 3U), /*!< User defined 8-bit data type 4, 0x33. */
  104. kCSI2RX_PayloadGroup1UserDefined5 = (1U << 4U), /*!< User defined 8-bit data type 5, 0x34. */
  105. kCSI2RX_PayloadGroup1UserDefined6 = (1U << 5U), /*!< User defined 8-bit data type 6, 0x35. */
  106. kCSI2RX_PayloadGroup1UserDefined7 = (1U << 6U), /*!< User defined 8-bit data type 7, 0x36. */
  107. kCSI2RX_PayloadGroup1UserDefined8 = (1U << 7U) /*!< User defined 8-bit data type 8, 0x37. */
  108. };
  109. /*! @brief CSI2RX configuration. */
  110. typedef struct _csi2rx_config
  111. {
  112. uint8_t laneNum; /*!< Number of active lanes used for receiving data. */
  113. uint8_t tHsSettle_EscClk; /*!< Number of rx_clk_esc clock periods for T_HS_SETTLE.
  114. The T_HS_SETTLE should be in the range of
  115. 85ns + 6UI to 145ns + 10UI. */
  116. } csi2rx_config_t;
  117. /*! @brief MIPI CSI2RX bit errors. */
  118. enum _csi2rx_bit_error
  119. {
  120. kCSI2RX_BitErrorEccTwoBit = (1U << 0U), /*!< ECC two bit error has occurred. */
  121. kCSI2RX_BitErrorEccOneBit = (1U << 1U) /*!< ECC one bit error has occurred. */
  122. };
  123. /*! @brief MIPI CSI2RX PPI error types. */
  124. typedef enum _csi2rx_ppi_error
  125. {
  126. kCSI2RX_PpiErrorSotHs, /*!< CSI2RX DPHY PPI error ErrSotHS. */
  127. kCSI2RX_PpiErrorSotSyncHs, /*!< CSI2RX DPHY PPI error ErrSotSync_HS. */
  128. kCSI2RX_PpiErrorEsc, /*!< CSI2RX DPHY PPI error ErrEsc. */
  129. kCSI2RX_PpiErrorSyncEsc, /*!< CSI2RX DPHY PPI error ErrSyncEsc. */
  130. kCSI2RX_PpiErrorControl, /*!< CSI2RX DPHY PPI error ErrControl. */
  131. } csi2rx_ppi_error_t;
  132. /*! @brief MIPI CSI2RX interrupt. */
  133. enum _csi2rx_interrupt
  134. {
  135. kCSI2RX_InterruptCrcError = (1U << 0U), /* CRC error. */
  136. kCSI2RX_InterruptEccOneBitError = (1U << 1U), /* One bit ECC error. */
  137. kCSI2RX_InterruptEccTwoBitError = (1U << 2U), /* One bit ECC error. */
  138. kCSI2RX_InterruptUlpsStatusChange = (1U << 3U), /* ULPS status changed. */
  139. kCSI2RX_InterruptErrorSotHs = (1U << 4U), /* D-PHY ErrSotHS occurred. */
  140. kCSI2RX_InterruptErrorSotSyncHs = (1U << 5U), /* D-PHY ErrSotSync_HS occurred. */
  141. kCSI2RX_InterruptErrorEsc = (1U << 6U), /* D-PHY ErrEsc occurred. */
  142. kCSI2RX_InterruptErrorSyncEsc = (1U << 7U), /* D-PHY ErrSyncEsc occurred. */
  143. kCSI2RX_InterruptErrorControl = (1U << 8U), /* D-PHY ErrControl occurred. */
  144. };
  145. /*! @brief MIPI CSI2RX D-PHY ULPS state. */
  146. enum _csi2rx_ulps_status
  147. {
  148. kCSI2RX_ClockLaneUlps = (1U << 0U), /*!< Clock lane is in ULPS state. */
  149. kCSI2RX_DataLane0Ulps = (1U << 1U), /*!< Data lane 0 is in ULPS state. */
  150. kCSI2RX_DataLane1Ulps = (1U << 2U), /*!< Data lane 1 is in ULPS state. */
  151. kCSI2RX_DataLane2Ulps = (1U << 3U), /*!< Data lane 2 is in ULPS state. */
  152. kCSI2RX_DataLane3Ulps = (1U << 4U), /*!< Data lane 3 is in ULPS state. */
  153. kCSI2RX_ClockLaneMark = (1U << 5U), /*!< Clock lane is in mark state. */
  154. kCSI2RX_DataLane0Mark = (1U << 6U), /*!< Data lane 0 is in mark state. */
  155. kCSI2RX_DataLane1Mark = (1U << 7U), /*!< Data lane 1 is in mark state. */
  156. kCSI2RX_DataLane2Mark = (1U << 8U), /*!< Data lane 2 is in mark state. */
  157. kCSI2RX_DataLane3Mark = (1U << 9U), /*!< Data lane 3 is in mark state. */
  158. };
  159. /*******************************************************************************
  160. * API
  161. ******************************************************************************/
  162. #if defined(__cplusplus)
  163. extern "C" {
  164. #endif
  165. /*!
  166. * @brief Enables and configures the CSI2RX peripheral module.
  167. *
  168. * @param base CSI2RX peripheral address.
  169. * @param config CSI2RX module configuration structure.
  170. */
  171. void CSI2RX_Init(MIPI_CSI2RX_Type *base, const csi2rx_config_t *config);
  172. /*!
  173. * @brief Disables the CSI2RX peripheral module.
  174. *
  175. * @param base CSI2RX peripheral address.
  176. */
  177. void CSI2RX_Deinit(MIPI_CSI2RX_Type *base);
  178. /*!
  179. * @brief Gets the MIPI CSI2RX bit error status.
  180. *
  181. * This function gets the RX bit error status, the return value could be compared
  182. * with @ref _csi2rx_bit_error. If one bit ECC error detected, the return value
  183. * could be passed to the function @ref CSI2RX_GetEccBitErrorPosition to get the
  184. * position of the ECC error bit.
  185. *
  186. * Example:
  187. * @code
  188. uint32_t bitError;
  189. uint32_t bitErrorPosition;
  190. bitError = CSI2RX_GetBitError(MIPI_CSI2RX);
  191. if (kCSI2RX_BitErrorEccTwoBit & bitError)
  192. {
  193. Two bits error;
  194. }
  195. else if (kCSI2RX_BitErrorEccOneBit & bitError)
  196. {
  197. One bits error;
  198. bitErrorPosition = CSI2RX_GetEccBitErrorPosition(bitError);
  199. }
  200. @endcode
  201. *
  202. * @param base CSI2RX peripheral address.
  203. * @return The RX bit error status.
  204. */
  205. static inline uint32_t CSI2RX_GetBitError(MIPI_CSI2RX_Type *base)
  206. {
  207. return CSI2RX_REG_BIT_ERR(base);
  208. }
  209. /*!
  210. * @brief Get ECC one bit error bit position.
  211. *
  212. * If @ref CSI2RX_GetBitError detects ECC one bit error, this function could
  213. * extract the error bit position from the return value of @ref CSI2RX_GetBitError.
  214. *
  215. * @param bitError The bit error returned by @ref CSI2RX_GetBitError.
  216. * @return The position of error bit.
  217. */
  218. static inline uint32_t CSI2RX_GetEccBitErrorPosition(uint32_t bitError)
  219. {
  220. return (bitError >> 2U) & 0x1FU;
  221. }
  222. /*!
  223. * @brief Gets the MIPI CSI2RX D-PHY ULPS status.
  224. *
  225. * Example to check whether data lane 0 is in ULPS status.
  226. * @code
  227. uint32_t status = CSI2RX_GetUlpsStatus(MIPI_CSI2RX);
  228. if (kCSI2RX_DataLane0Ulps & status)
  229. {
  230. Data lane 0 is in ULPS status.
  231. }
  232. @endcode
  233. *
  234. * @param base CSI2RX peripheral address.
  235. * @return The MIPI CSI2RX D-PHY ULPS status, it is OR'ed value or @ref _csi2rx_ulps_status.
  236. */
  237. static inline uint32_t CSI2RX_GetUlpsStatus(MIPI_CSI2RX_Type *base)
  238. {
  239. return CSI2RX_REG_ULPS_STATUS(base);
  240. }
  241. /*!
  242. * @brief Gets the MIPI CSI2RX D-PHY PPI error lanes.
  243. *
  244. * This function checks the PPI error occurred on which data lanes, the returned
  245. * value is OR'ed value of @ref csi2rx_ppi_error_t. For example, if the ErrSotHS
  246. * is detected, to check the ErrSotHS occurred on which data lanes, use like this:
  247. *
  248. * @code
  249. uint32_t errorDataLanes = CSI2RX_GetPpiErrorDataLanes(MIPI_CSI2RX, kCSI2RX_PpiErrorSotHs);
  250. if (kCSI2RX_DataLane0 & errorDataLanes)
  251. {
  252. ErrSotHS occurred on data lane 0.
  253. }
  254. if (kCSI2RX_DataLane1 & errorDataLanes)
  255. {
  256. ErrSotHS occurred on data lane 1.
  257. }
  258. @endcode
  259. *
  260. * @param base CSI2RX peripheral address.
  261. * @param errorType What kind of error to check.
  262. * @return The data lane mask that error @p errorType occurred.
  263. */
  264. static inline uint32_t CSI2RX_GetPpiErrorDataLanes(MIPI_CSI2RX_Type *base, csi2rx_ppi_error_t errorType)
  265. {
  266. uint32_t errorLanes;
  267. if (kCSI2RX_PpiErrorSotHs == errorType)
  268. {
  269. errorLanes = CSI2RX_REG_PPI_ERRSOT_HS(base);
  270. }
  271. else if (kCSI2RX_PpiErrorSotSyncHs == errorType)
  272. {
  273. errorLanes = CSI2RX_REG_PPI_ERRSOTSYNC_HS(base);
  274. }
  275. else if (kCSI2RX_PpiErrorEsc == errorType)
  276. {
  277. errorLanes = CSI2RX_REG_PPI_ERRESC(base);
  278. }
  279. else if (kCSI2RX_PpiErrorSyncEsc == errorType)
  280. {
  281. errorLanes = CSI2RX_REG_PPI_ERRSYNCESC(base);
  282. }
  283. else
  284. {
  285. errorLanes = CSI2RX_REG_PPI_ERRCONTROL(base);
  286. }
  287. return errorLanes;
  288. }
  289. /*!
  290. * @brief Enable the MIPI CSI2RX interrupts.
  291. *
  292. * This function enables the MIPI CSI2RX interrupts. The interrupts to enable
  293. * are passed in as an OR'ed value of @ref _csi2rx_interrupt. For example, to enable
  294. * one bit and two bit ECC error interrupts, use like this:
  295. *
  296. * @code
  297. CSI2RX_EnableInterrupts(MIPI_CSI2RX, kCSI2RX_InterruptEccOneBitError | kCSI2RX_InterruptEccTwoBitError);
  298. @endcode
  299. *
  300. * @param base CSI2RX peripheral address.
  301. * @param mask OR'ed value of @ref _csi2rx_interrupt.
  302. */
  303. static inline void CSI2RX_EnableInterrupts(MIPI_CSI2RX_Type *base, uint32_t mask)
  304. {
  305. CSI2RX_REG_IRQ_MASK(base) &= ~mask;
  306. }
  307. /*!
  308. * @brief Disable the MIPI CSI2RX interrupts.
  309. *
  310. * This function disables the MIPI CSI2RX interrupts. The interrupts to disable
  311. * are passed in as an OR'ed value of @ref _csi2rx_interrupt. For example, to disable
  312. * one bit and two bit ECC error interrupts, use like this:
  313. *
  314. * @code
  315. CSI2RX_DisableInterrupts(MIPI_CSI2RX, kCSI2RX_InterruptEccOneBitError | kCSI2RX_InterruptEccTwoBitError);
  316. @endcode
  317. *
  318. * @param base CSI2RX peripheral address.
  319. * @param mask OR'ed value of @ref _csi2rx_interrupt.
  320. */
  321. static inline void CSI2RX_DisableInterrupts(MIPI_CSI2RX_Type *base, uint32_t mask)
  322. {
  323. CSI2RX_REG_IRQ_MASK(base) |= mask;
  324. }
  325. /*!
  326. * @brief Get the MIPI CSI2RX interrupt status.
  327. *
  328. * This function returns the MIPI CSI2RX interrupts status as an OR'ed value
  329. * of @ref _csi2rx_interrupt.
  330. *
  331. * @param base CSI2RX peripheral address.
  332. * @return OR'ed value of @ref _csi2rx_interrupt.
  333. */
  334. static inline uint32_t CSI2RX_GetInterruptStatus(MIPI_CSI2RX_Type *base)
  335. {
  336. return CSI2RX_REG_IRQ_STATUS(base);
  337. }
  338. #if defined(__cplusplus)
  339. }
  340. #endif
  341. /*!
  342. *@}
  343. */
  344. #endif /* _FSL_MIPI_CSI2RX_H_ */