fsl_dcic.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366
  1. /*
  2. * Copyright 2020-2021 NXP
  3. * All rights reserved.
  4. *
  5. * SPDX-License-Identifier: BSD-3-Clause
  6. */
  7. #ifndef _FSL_DCIC_H_
  8. #define _FSL_DCIC_H_
  9. #include "fsl_common.h"
  10. /*!
  11. * @addtogroup DCIC
  12. * @{
  13. */
  14. /*******************************************************************************
  15. * Definitions
  16. ******************************************************************************/
  17. #ifndef DCIC_REGION_COUNT
  18. #define DCIC_REGION_COUNT DCIC_DCICRCS_COUNT
  19. #endif
  20. /*! @brief DCIC driver version. */
  21. #define FSL_DCIC_DRIVER_VERSION (MAKE_VERSION(2, 0, 1))
  22. /*! @brief CRC32 calculation polynomial. */
  23. #define DCIC_CRC32_POLYNOMIAL 0x04C11DB7UL
  24. /*! @brief CRC32 calculation initialize value. */
  25. #define DCIC_CRC32_INIT_VALUE 0UL
  26. /*! @brief ROI CRC32 value mismatch status. */
  27. #define DCIC_REGION_MISMATCH_STATUS(region) (1UL << (DCIC_DCICS_ROI_MATCH_STAT_SHIFT + (region)))
  28. /*!
  29. * @brief DCIC display signal polarity flags
  30. * @anchor _DCIC_polarity_flags
  31. */
  32. enum _DCIC_polarity_flags
  33. {
  34. kDCIC_VsyncActiveLow = DCIC_DCICC_VSYNC_POL_MASK, /*!< VSYNC active low. */
  35. kDCIC_VsyncActiveHigh = 0U, /*!< VSYNC active high. */
  36. kDCIC_HsyncActiveLow = DCIC_DCICC_HSYNC_POL_MASK, /*!< HSYNC active low. */
  37. kDCIC_HsyncActiveHigh = 0U, /*!< HSYNC active high. */
  38. kDCIC_DataEnableActiveLow = DCIC_DCICC_DE_POL_MASK, /*!< Data enable line active low. */
  39. kDCIC_DataEnableActiveHigh = 0U, /*!< Data enable line active high. */
  40. kDCIC_DriveDataOnRisingClkEdge = DCIC_DCICC_CLK_POL_MASK, /*!< Output data on falling clock edge, capture data
  41. on rising clock edge. */
  42. kDCIC_DriveDataOnFallingClkEdge = 0U, /*!< Output data on rising clock edge, capture data
  43. on falling clock edge. */
  44. };
  45. /*!
  46. * @brief Status flags.
  47. * @anchor _DCIC_status_flags
  48. */
  49. enum _DCIC_status_flags
  50. {
  51. kDCIC_FunctionalInterruptStatus = DCIC_DCICS_FI_STAT_MASK, /*!< Asserted when match results ready. */
  52. kDCIC_ErrorInterruptStatus = DCIC_DCICS_EI_STAT_MASK, /*!< Asserted when there is a signature mismatch. */
  53. kDCIC_Region0MismatchStatus = DCIC_REGION_MISMATCH_STATUS(0U), /*!< Region 0 CRC32 value mismatch. */
  54. kDCIC_Region1MismatchStatus = DCIC_REGION_MISMATCH_STATUS(1U), /*!< Region 1 CRC32 value mismatch. */
  55. kDCIC_Region2MismatchStatus = DCIC_REGION_MISMATCH_STATUS(2U), /*!< Region 2 CRC32 value mismatch. */
  56. kDCIC_Region3MismatchStatus = DCIC_REGION_MISMATCH_STATUS(3U), /*!< Region 3 CRC32 value mismatch. */
  57. kDCIC_Region4MismatchStatus = DCIC_REGION_MISMATCH_STATUS(4U), /*!< Region 4 CRC32 value mismatch. */
  58. kDCIC_Region5MismatchStatus = DCIC_REGION_MISMATCH_STATUS(5U), /*!< Region 5 CRC32 value mismatch. */
  59. kDCIC_Region6MismatchStatus = DCIC_REGION_MISMATCH_STATUS(6U), /*!< Region 6 CRC32 value mismatch. */
  60. kDCIC_Region7MismatchStatus = DCIC_REGION_MISMATCH_STATUS(7U), /*!< Region 7 CRC32 value mismatch. */
  61. kDCIC_Region8MismatchStatus = DCIC_REGION_MISMATCH_STATUS(8U), /*!< Region 8 CRC32 value mismatch. */
  62. kDCIC_Region9MismatchStatus = DCIC_REGION_MISMATCH_STATUS(9U), /*!< Region 9 CRC32 value mismatch. */
  63. kDCIC_Region10MismatchStatus = DCIC_REGION_MISMATCH_STATUS(10U), /*!< Region 10 CRC32 value mismatch. */
  64. kDCIC_Region11MismatchStatus = DCIC_REGION_MISMATCH_STATUS(11U), /*!< Region 11 CRC32 value mismatch. */
  65. kDCIC_Region12MismatchStatus = DCIC_REGION_MISMATCH_STATUS(12U), /*!< Region 12 CRC32 value mismatch. */
  66. kDCIC_Region13MismatchStatus = DCIC_REGION_MISMATCH_STATUS(13U), /*!< Region 13 CRC32 value mismatch. */
  67. kDCIC_Region14MismatchStatus = DCIC_REGION_MISMATCH_STATUS(14U), /*!< Region 14 CRC32 value mismatch. */
  68. kDCIC_Region15MismatchStatus = DCIC_REGION_MISMATCH_STATUS(15U), /*!< Region 15 CRC32 value mismatch. */
  69. };
  70. /*!
  71. * @brief Interrupts.
  72. * @anchor _dcic_interrupt_enable
  73. */
  74. enum _dcic_interrupt_enable
  75. {
  76. kDCIC_FunctionalInterruptEnable = DCIC_DCICIC_FI_MASK_MASK, /*!< Interrupt when match results ready. */
  77. kDCIC_ErrorInterruptEnable = DCIC_DCICIC_EI_MASK_MASK, /*!< Interrupt when there is a signature mismatch. */
  78. };
  79. /*!
  80. * @brief DCIC configuration.
  81. */
  82. typedef struct _dcic_config
  83. {
  84. bool enableExternalSignal; /*!< Enable the mismatch external signal. When enabled, the mismatch status could
  85. be monitored from the extern pin. */
  86. uint8_t polarityFlags; /*!< Display signal polarity, logical OR'ed of @ref _DCIC_polarity_flags. */
  87. uint32_t enableInterrupts; /*!< Interrupts to enable, should be OR'ed of @ref _dcic_interrupt_enable. */
  88. } dcic_config_t;
  89. /*!
  90. * @brief Region of interest (ROI) configuration.
  91. */
  92. typedef struct _dcic_region_config
  93. {
  94. bool lock; /*!< Lock the region configuration except reference CRC32 value setting. */
  95. uint16_t upperLeftX; /*!< X of upper left corner. Range: 0 to 2^13-1. */
  96. uint16_t upperLeftY; /*!< Y of upper left corner. Range: 0 to 2^12-1. */
  97. uint16_t lowerRightX; /*!< X of lower right corner. Range: 0 to 2^13-1. */
  98. uint16_t lowerRightY; /*!< Y of lower right corner. Range: 0 to 2^12-1. */
  99. uint32_t refCrc; /*!< Reference CRC32 value. */
  100. } dcic_region_config_t;
  101. #if defined(__cplusplus)
  102. extern "C" {
  103. #endif
  104. /*******************************************************************************
  105. * API
  106. ******************************************************************************/
  107. /*!
  108. * @name Initialization and deinitialization
  109. * @{
  110. */
  111. /*!
  112. * @brief Initializes the DCIC.
  113. *
  114. * This function resets DCIC registers to default value, then
  115. * set the configurations. This function does not start the
  116. * DCIC to work, application should call @ref DCIC_DisableRegion
  117. * to configure regions, then call @ref DCIC_Enable to start the
  118. * DCIC to work.
  119. *
  120. * @param base DCIC peripheral base address.
  121. * @param config Pointer to the configuration.
  122. */
  123. void DCIC_Init(DCIC_Type *base, const dcic_config_t *config);
  124. /*!
  125. * @brief Deinitialize the DCIC.
  126. *
  127. * Disable the DCIC functions.
  128. *
  129. * @param base DCIC peripheral base address.
  130. */
  131. void DCIC_Deinit(DCIC_Type *base);
  132. /*!
  133. * @brief Get the default configuration to initialize DCIC.
  134. *
  135. * The default configuration is:
  136. *
  137. * @code
  138. config->polarityFlags = kDCIC_VsyncActiveLow | kDCIC_HsyncActiveLow |
  139. kDCIC_DataEnableActiveLow | kDCIC_DriveDataOnFallingClkEdge;
  140. config->enableExternalSignal = false;
  141. config->enableInterrupts = 0;
  142. @endcode
  143. *
  144. * @param config Pointer to the configuration.
  145. */
  146. void DCIC_GetDefaultConfig(dcic_config_t *config);
  147. /*!
  148. * @brief Enable or disable the DCIC module.
  149. *
  150. * @param base DCIC peripheral base address.
  151. * @param enable Use true to enable, false to disable.
  152. */
  153. static inline void DCIC_Enable(DCIC_Type *base, bool enable)
  154. {
  155. if (enable)
  156. {
  157. base->DCICC |= DCIC_DCICC_IC_EN_MASK;
  158. }
  159. else
  160. {
  161. base->DCICC &= ~DCIC_DCICC_IC_EN_MASK;
  162. }
  163. }
  164. /* @} */
  165. /*!
  166. * @name Status
  167. * @{
  168. */
  169. /*!
  170. * @brief Get status flags.
  171. *
  172. * The flag @ref kDCIC_ErrorInterruptStatus is asserted if any region mismatch
  173. * flag asserted.
  174. *
  175. * @brief base DCIC peripheral base address.
  176. * @return Masks of asserted status flags, @ref _DCIC_status_flags.
  177. */
  178. static inline uint32_t DCIC_GetStatusFlags(DCIC_Type *base)
  179. {
  180. return base->DCICS;
  181. }
  182. /*!
  183. * @brief Clear status flags.
  184. *
  185. * The flag @ref kDCIC_ErrorInterruptStatus should be cleared by clearing all
  186. * asserted region mismatch flags.
  187. *
  188. * @brief base DCIC peripheral base address.
  189. * @brief mask Mask of status values that would be cleared, @ref _DCIC_status_flags.
  190. */
  191. static inline void DCIC_ClearStatusFlags(DCIC_Type *base, uint32_t mask)
  192. {
  193. base->DCICS = (mask & (DCIC_DCICS_FI_STAT_MASK | DCIC_DCICS_ROI_MATCH_STAT_MASK));
  194. }
  195. /* @} */
  196. /*!
  197. * @name Interrupts
  198. * @{
  199. */
  200. /*!
  201. * @brief Lock the interrupt enabled status.
  202. *
  203. * Once this function is called, the interrupt enabled status could not be changed
  204. * until reset.
  205. *
  206. * @param base DCIC peripheral base address.
  207. */
  208. static inline void DCIC_LockInterruptEnabledStatus(DCIC_Type *base)
  209. {
  210. base->DCICIC |= DCIC_DCICIC_FREEZE_MASK_MASK;
  211. }
  212. /*!
  213. * @brief Enable interrupts.
  214. *
  215. * @param base DCIC peripheral base address.
  216. * @param mask Mask of interrupt events that would be enabled. See to "_dcic_interrupt_enable_t".
  217. */
  218. static inline void DCIC_EnableInterrupts(DCIC_Type *base, uint32_t mask)
  219. {
  220. base->DCICIC &= ~mask;
  221. }
  222. /*!
  223. * @brief Disable interrupts.
  224. *
  225. * @param base DCIC peripheral base address.
  226. * @param mask Mask of interrupt events that would be disabled. See to "_dcic_interrupt_enable_t".
  227. */
  228. static inline void DCIC_DisableInterrupts(DCIC_Type *base, uint32_t mask)
  229. {
  230. base->DCICIC |= mask;
  231. }
  232. /* @} */
  233. /*!
  234. * @name Region
  235. * @{
  236. */
  237. /*!
  238. * @brief Enable the region of interest (ROI) with configuration.
  239. *
  240. * Enable the ROI with configuration. To change the configuration except reference
  241. * CRC value, the region should be disabled first by @ref DCIC_DisableRegion,
  242. * then call this function again. The reference CRC value could be changed by
  243. * @ref DCIC_SetRegionRefCrc without disabling the region.
  244. * If the configuration is locked, only the reference CRC value could be changed,
  245. * the region size and position, enable status could not be changed until reset.
  246. *
  247. * @param base DCIC peripheral base address.
  248. * @param regionIdx Region index, from 0 to (DCIC_REGION_COUNT - 1).
  249. * @param config Pointer to the configuration.
  250. */
  251. void DCIC_EnableRegion(DCIC_Type *base, uint8_t regionIdx, const dcic_region_config_t *config);
  252. /*!
  253. * @brief Disable the region of interest (ROI).
  254. *
  255. * @param base DCIC peripheral base address.
  256. * @param regionIdx Region index, from 0 to (DCIC_REGION_COUNT - 1).
  257. */
  258. static inline void DCIC_DisableRegion(DCIC_Type *base, uint8_t regionIdx)
  259. {
  260. assert(regionIdx < DCIC_REGION_COUNT);
  261. base->REGION[regionIdx].DCICRC &= ~DCIC_DCICRC_ROI_EN_MASK;
  262. }
  263. /*!
  264. * @brief Set the reference CRC of interest (ROI).
  265. *
  266. * @param base DCIC peripheral base address.
  267. * @param regionIdx Region index, from 0 to (DCIC_REGION_COUNT - 1).
  268. * @param crc The reference CRC value.
  269. */
  270. static inline void DCIC_SetRegionRefCrc(DCIC_Type *base, uint8_t regionIdx, uint32_t crc)
  271. {
  272. assert(regionIdx < DCIC_REGION_COUNT);
  273. base->REGION[regionIdx].DCICRRS = crc;
  274. }
  275. /*!
  276. * @brief Get the DCIC calculated CRC.
  277. *
  278. * @param base DCIC peripheral base address.
  279. * @param regionIdx Region index, from 0 to (DCIC_REGION_COUNT - 1).
  280. * @return The calculated CRC value.
  281. */
  282. static inline uint32_t DCIC_GetRegionCalculatedCrc(DCIC_Type *base, uint8_t regionIdx)
  283. {
  284. assert(regionIdx < DCIC_REGION_COUNT);
  285. return base->REGION[regionIdx].DCICRCS;
  286. }
  287. /* @} */
  288. /*!
  289. * @name Misc control.
  290. * @{
  291. */
  292. /*!
  293. * @brief Enable or disable output the mismatch external signal.
  294. *
  295. * The mismatch status can be output to external pins. If enabled:
  296. * - If @ref kDCIC_ErrorInterruptStatus asserted, the output signal
  297. * frequency is DCIC clock / 16.
  298. * - If @ref kDCIC_ErrorInterruptStatus not asserted, the output signal
  299. * frequency is DCIC clock / 4.
  300. * - If integrity check is disabled, the signal is idle.
  301. *
  302. * @param base DCIC peripheral base address.
  303. * @param enable. Use true to enable, false to disable.
  304. */
  305. static inline void DCIC_EnableMismatchExternalSignal(DCIC_Type *base, bool enable)
  306. {
  307. if (enable)
  308. {
  309. base->DCICIC |= DCIC_DCICIC_EXT_SIG_EN_MASK;
  310. }
  311. else
  312. {
  313. base->DCICIC &= ~DCIC_DCICIC_EXT_SIG_EN_MASK;
  314. }
  315. }
  316. /* @} */
  317. #if defined(__cplusplus)
  318. }
  319. #endif
  320. /*!
  321. * @}
  322. */
  323. #endif /* _FSL_DCIC_H_ */