stm32f4xx_ltdc.c 37 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102
  1. /**
  2. ******************************************************************************
  3. * @file stm32f4xx_ltdc.c
  4. * @author MCD Application Team
  5. * @version V1.8.1
  6. * @date 27-January-2022
  7. * @brief This file provides firmware functions to manage the following
  8. * functionalities of the LTDC controller (LTDC) peripheral:
  9. * + Initialization and configuration
  10. * + Interrupts and flags management
  11. *
  12. * @verbatim
  13. ===============================================================================
  14. ##### How to use this driver #####
  15. ===============================================================================
  16. [..]
  17. (#) Enable LTDC clock using
  18. RCC_APB2PeriphResetCmd(RCC_APB2Periph_LTDC, ENABLE) function.
  19. (#) Configures LTDC
  20. (++) Configure the required Pixel clock following the panel datasheet
  21. (++) Configure the Synchronous timings: VSYNC, HSYNC, Vertical and
  22. Horizontal back proch, active data area and the front proch
  23. timings
  24. (++) Configure the synchronous signals and clock polarity in the
  25. LTDC_GCR register
  26. (#) Configures Layer1/2 parameters
  27. (++) The Layer window horizontal and vertical position in the LTDC_LxWHPCR and
  28. LTDC_WVPCR registers. The layer window must be in the active data area.
  29. (++) The pixel input format in the LTDC_LxPFCR register
  30. (++) The color frame buffer start address in the LTDC_LxCFBAR register
  31. (++) The line length and pitch of the color frame buffer in the
  32. LTDC_LxCFBLR register
  33. (++) The number of lines of the color frame buffer in
  34. the LTDC_LxCFBLNR register
  35. (++) if needed, load the CLUT with the RGB values and the address
  36. in the LTDC_LxCLUTWR register
  37. (++) If needed, configure the default color and the blending factors
  38. respectively in the LTDC_LxDCCR and LTDC_LxBFCR registers
  39. (++) If needed, Dithering and color keying can be enabled respectively
  40. in the LTDC_GCR and LTDC_LxCKCR registers. It can be also enabled
  41. on the fly.
  42. (#) Enable Layer1/2 and if needed the CLUT in the LTDC_LxCR register
  43. (#) Reload the shadow registers to active register through
  44. the LTDC_SRCR register.
  45. -@- All layer parameters can be modified on the fly except the CLUT.
  46. The new configuration has to be either reloaded immediately
  47. or during vertical blanking period by configuring the LTDC_SRCR register.
  48. (#) Call the LTDC_Cmd() to enable the LTDC controller.
  49. @endverbatim
  50. ******************************************************************************
  51. * @attention
  52. *
  53. * Copyright (c) 2016 STMicroelectronics.
  54. * All rights reserved.
  55. *
  56. * This software is licensed under terms that can be found in the LICENSE file
  57. * in the root directory of this software component.
  58. * If no LICENSE file comes with this software, it is provided AS-IS.
  59. *
  60. ******************************************************************************
  61. */
  62. /* Includes ------------------------------------------------------------------*/
  63. #include "stm32f4xx_ltdc.h"
  64. #include "stm32f4xx_rcc.h"
  65. /** @addtogroup STM32F4xx_StdPeriph_Driver
  66. * @{
  67. */
  68. /** @defgroup LTDC
  69. * @brief LTDC driver modules
  70. * @{
  71. */
  72. /* Private typedef -----------------------------------------------------------*/
  73. /* Private define ------------------------------------------------------------*/
  74. /* Private macro -------------------------------------------------------------*/
  75. /* Private variables ---------------------------------------------------------*/
  76. /* Private function prototypes -----------------------------------------------*/
  77. /* Private functions ---------------------------------------------------------*/
  78. #define GCR_MASK ((uint32_t)0x0FFE888F) /* LTDC GCR Mask */
  79. /** @defgroup LTDC_Private_Functions
  80. * @{
  81. */
  82. /** @defgroup LTDC_Group1 Initialization and Configuration functions
  83. * @brief Initialization and Configuration functions
  84. *
  85. @verbatim
  86. ===============================================================================
  87. ##### Initialization and Configuration functions #####
  88. ===============================================================================
  89. [..] This section provides functions allowing to:
  90. (+) Initialize and configure the LTDC
  91. (+) Enable or Disable Dither
  92. (+) Define the position of the line interrupt
  93. (+) reload layers registers with new parameters
  94. (+) Initialize and configure layer1 and layer2
  95. (+) Set and configure the color keying functionality
  96. (+) Configure and Enables or disables CLUT
  97. @endverbatim
  98. * @{
  99. */
  100. /**
  101. * @brief Deinitializes the LTDC peripheral registers to their default reset
  102. * values.
  103. * @param None
  104. * @retval None
  105. */
  106. void LTDC_DeInit(void)
  107. {
  108. /* Enable LTDC reset state */
  109. RCC_APB2PeriphResetCmd(RCC_APB2Periph_LTDC, ENABLE);
  110. /* Release LTDC from reset state */
  111. RCC_APB2PeriphResetCmd(RCC_APB2Periph_LTDC, DISABLE);
  112. }
  113. /**
  114. * @brief Initializes the LTDC peripheral according to the specified parameters
  115. * in the LTDC_InitStruct.
  116. * @note This function can be used only when the LTDC is disabled.
  117. * @param LTDC_InitStruct: pointer to a LTDC_InitTypeDef structure that contains
  118. * the configuration information for the specified LTDC peripheral.
  119. * @retval None
  120. */
  121. void LTDC_Init(LTDC_InitTypeDef* LTDC_InitStruct)
  122. {
  123. uint32_t horizontalsync = 0;
  124. uint32_t accumulatedHBP = 0;
  125. uint32_t accumulatedactiveW = 0;
  126. uint32_t totalwidth = 0;
  127. uint32_t backgreen = 0;
  128. uint32_t backred = 0;
  129. /* Check function parameters */
  130. assert_param(IS_LTDC_HSYNC(LTDC_InitStruct->LTDC_HorizontalSync));
  131. assert_param(IS_LTDC_VSYNC(LTDC_InitStruct->LTDC_VerticalSync));
  132. assert_param(IS_LTDC_AHBP(LTDC_InitStruct->LTDC_AccumulatedHBP));
  133. assert_param(IS_LTDC_AVBP(LTDC_InitStruct->LTDC_AccumulatedVBP));
  134. assert_param(IS_LTDC_AAH(LTDC_InitStruct->LTDC_AccumulatedActiveH));
  135. assert_param(IS_LTDC_AAW(LTDC_InitStruct->LTDC_AccumulatedActiveW));
  136. assert_param(IS_LTDC_TOTALH(LTDC_InitStruct->LTDC_TotalHeigh));
  137. assert_param(IS_LTDC_TOTALW(LTDC_InitStruct->LTDC_TotalWidth));
  138. assert_param(IS_LTDC_HSPOL(LTDC_InitStruct->LTDC_HSPolarity));
  139. assert_param(IS_LTDC_VSPOL(LTDC_InitStruct->LTDC_VSPolarity));
  140. assert_param(IS_LTDC_DEPOL(LTDC_InitStruct->LTDC_DEPolarity));
  141. assert_param(IS_LTDC_PCPOL(LTDC_InitStruct->LTDC_PCPolarity));
  142. assert_param(IS_LTDC_BackBlueValue(LTDC_InitStruct->LTDC_BackgroundBlueValue));
  143. assert_param(IS_LTDC_BackGreenValue(LTDC_InitStruct->LTDC_BackgroundGreenValue));
  144. assert_param(IS_LTDC_BackRedValue(LTDC_InitStruct->LTDC_BackgroundRedValue));
  145. /* Sets Synchronization size */
  146. LTDC->SSCR &= ~(LTDC_SSCR_VSH | LTDC_SSCR_HSW);
  147. horizontalsync = (LTDC_InitStruct->LTDC_HorizontalSync << 16);
  148. LTDC->SSCR |= (horizontalsync | LTDC_InitStruct->LTDC_VerticalSync);
  149. /* Sets Accumulated Back porch */
  150. LTDC->BPCR &= ~(LTDC_BPCR_AVBP | LTDC_BPCR_AHBP);
  151. accumulatedHBP = (LTDC_InitStruct->LTDC_AccumulatedHBP << 16);
  152. LTDC->BPCR |= (accumulatedHBP | LTDC_InitStruct->LTDC_AccumulatedVBP);
  153. /* Sets Accumulated Active Width */
  154. LTDC->AWCR &= ~(LTDC_AWCR_AAH | LTDC_AWCR_AAW);
  155. accumulatedactiveW = (LTDC_InitStruct->LTDC_AccumulatedActiveW << 16);
  156. LTDC->AWCR |= (accumulatedactiveW | LTDC_InitStruct->LTDC_AccumulatedActiveH);
  157. /* Sets Total Width */
  158. LTDC->TWCR &= ~(LTDC_TWCR_TOTALH | LTDC_TWCR_TOTALW);
  159. totalwidth = (LTDC_InitStruct->LTDC_TotalWidth << 16);
  160. LTDC->TWCR |= (totalwidth | LTDC_InitStruct->LTDC_TotalHeigh);
  161. LTDC->GCR &= (uint32_t)GCR_MASK;
  162. LTDC->GCR |= (uint32_t)(LTDC_InitStruct->LTDC_HSPolarity | LTDC_InitStruct->LTDC_VSPolarity | \
  163. LTDC_InitStruct->LTDC_DEPolarity | LTDC_InitStruct->LTDC_PCPolarity);
  164. /* sets the background color value */
  165. backgreen = (LTDC_InitStruct->LTDC_BackgroundGreenValue << 8);
  166. backred = (LTDC_InitStruct->LTDC_BackgroundRedValue << 16);
  167. LTDC->BCCR &= ~(LTDC_BCCR_BCBLUE | LTDC_BCCR_BCGREEN | LTDC_BCCR_BCRED);
  168. LTDC->BCCR |= (backred | backgreen | LTDC_InitStruct->LTDC_BackgroundBlueValue);
  169. }
  170. /**
  171. * @brief Fills each LTDC_InitStruct member with its default value.
  172. * @param LTDC_InitStruct: pointer to a LTDC_InitTypeDef structure which will
  173. * be initialized.
  174. * @retval None
  175. */
  176. void LTDC_StructInit(LTDC_InitTypeDef* LTDC_InitStruct)
  177. {
  178. /*--------------- Reset LTDC init structure parameters values ----------------*/
  179. LTDC_InitStruct->LTDC_HSPolarity = LTDC_HSPolarity_AL; /*!< Initialize the LTDC_HSPolarity member */
  180. LTDC_InitStruct->LTDC_VSPolarity = LTDC_VSPolarity_AL; /*!< Initialize the LTDC_VSPolarity member */
  181. LTDC_InitStruct->LTDC_DEPolarity = LTDC_DEPolarity_AL; /*!< Initialize the LTDC_DEPolarity member */
  182. LTDC_InitStruct->LTDC_PCPolarity = LTDC_PCPolarity_IPC; /*!< Initialize the LTDC_PCPolarity member */
  183. LTDC_InitStruct->LTDC_HorizontalSync = 0x00; /*!< Initialize the LTDC_HorizontalSync member */
  184. LTDC_InitStruct->LTDC_VerticalSync = 0x00; /*!< Initialize the LTDC_VerticalSync member */
  185. LTDC_InitStruct->LTDC_AccumulatedHBP = 0x00; /*!< Initialize the LTDC_AccumulatedHBP member */
  186. LTDC_InitStruct->LTDC_AccumulatedVBP = 0x00; /*!< Initialize the LTDC_AccumulatedVBP member */
  187. LTDC_InitStruct->LTDC_AccumulatedActiveW = 0x00; /*!< Initialize the LTDC_AccumulatedActiveW member */
  188. LTDC_InitStruct->LTDC_AccumulatedActiveH = 0x00; /*!< Initialize the LTDC_AccumulatedActiveH member */
  189. LTDC_InitStruct->LTDC_TotalWidth = 0x00; /*!< Initialize the LTDC_TotalWidth member */
  190. LTDC_InitStruct->LTDC_TotalHeigh = 0x00; /*!< Initialize the LTDC_TotalHeigh member */
  191. LTDC_InitStruct->LTDC_BackgroundRedValue = 0x00; /*!< Initialize the LTDC_BackgroundRedValue member */
  192. LTDC_InitStruct->LTDC_BackgroundGreenValue = 0x00; /*!< Initialize the LTDC_BackgroundGreenValue member */
  193. LTDC_InitStruct->LTDC_BackgroundBlueValue = 0x00; /*!< Initialize the LTDC_BackgroundBlueValue member */
  194. }
  195. /**
  196. * @brief Enables or disables the LTDC Controller.
  197. * @param NewState: new state of the LTDC peripheral.
  198. * This parameter can be: ENABLE or DISABLE.
  199. * @retval None
  200. */
  201. void LTDC_Cmd(FunctionalState NewState)
  202. {
  203. /* Check the parameters */
  204. assert_param(IS_FUNCTIONAL_STATE(NewState));
  205. if (NewState != DISABLE)
  206. {
  207. /* Enable LTDC by setting LTDCEN bit */
  208. LTDC->GCR |= (uint32_t)LTDC_GCR_LTDCEN;
  209. }
  210. else
  211. {
  212. /* Disable LTDC by clearing LTDCEN bit */
  213. LTDC->GCR &= ~(uint32_t)LTDC_GCR_LTDCEN;
  214. }
  215. }
  216. /**
  217. * @brief Enables or disables Dither.
  218. * @param NewState: new state of the Dither.
  219. * This parameter can be: ENABLE or DISABLE.
  220. * @retval None
  221. */
  222. void LTDC_DitherCmd(FunctionalState NewState)
  223. {
  224. /* Check the parameters */
  225. assert_param(IS_FUNCTIONAL_STATE(NewState));
  226. if (NewState != DISABLE)
  227. {
  228. /* Enable Dither by setting DTEN bit */
  229. LTDC->GCR |= (uint32_t)LTDC_GCR_DTEN;
  230. }
  231. else
  232. {
  233. /* Disable Dither by clearing DTEN bit */
  234. LTDC->GCR &= ~(uint32_t)LTDC_GCR_DTEN;
  235. }
  236. }
  237. /**
  238. * @brief Get the dither RGB width.
  239. * @param LTDC_RGB_InitStruct: pointer to a LTDC_RGBTypeDef structure that contains
  240. * the Dither RGB width.
  241. * @retval None
  242. */
  243. LTDC_RGBTypeDef LTDC_GetRGBWidth(void)
  244. {
  245. LTDC_RGBTypeDef LTDC_RGB_InitStruct;
  246. LTDC->GCR &= (uint32_t)GCR_MASK;
  247. LTDC_RGB_InitStruct.LTDC_BlueWidth = (uint32_t)((LTDC->GCR >> 4) & 0x7);
  248. LTDC_RGB_InitStruct.LTDC_GreenWidth = (uint32_t)((LTDC->GCR >> 8) & 0x7);
  249. LTDC_RGB_InitStruct.LTDC_RedWidth = (uint32_t)((LTDC->GCR >> 12) & 0x7);
  250. return LTDC_RGB_InitStruct;
  251. }
  252. /**
  253. * @brief Fills each LTDC_RGBStruct member with its default value.
  254. * @param LTDC_RGB_InitStruct: pointer to a LTDC_RGBTypeDef structure which will
  255. * be initialized.
  256. * @retval None
  257. */
  258. void LTDC_RGBStructInit(LTDC_RGBTypeDef* LTDC_RGB_InitStruct)
  259. {
  260. LTDC_RGB_InitStruct->LTDC_BlueWidth = 0x02;
  261. LTDC_RGB_InitStruct->LTDC_GreenWidth = 0x02;
  262. LTDC_RGB_InitStruct->LTDC_RedWidth = 0x02;
  263. }
  264. /**
  265. * @brief Define the position of the line interrupt .
  266. * @param LTDC_LIPositionConfig: Line Interrupt Position.
  267. * @retval None
  268. */
  269. void LTDC_LIPConfig(uint32_t LTDC_LIPositionConfig)
  270. {
  271. /* Check the parameters */
  272. assert_param(IS_LTDC_LIPOS(LTDC_LIPositionConfig));
  273. /* Sets the Line Interrupt position */
  274. LTDC->LIPCR = (uint32_t)LTDC_LIPositionConfig;
  275. }
  276. /**
  277. * @brief reload layers registers with new parameters
  278. * @param LTDC_Reload: specifies the type of reload.
  279. * This parameter can be one of the following values:
  280. * @arg LTDC_IMReload: Vertical blanking reload.
  281. * @arg LTDC_VBReload: Immediate reload.
  282. * @retval None
  283. */
  284. void LTDC_ReloadConfig(uint32_t LTDC_Reload)
  285. {
  286. /* Check the parameters */
  287. assert_param(IS_LTDC_RELOAD(LTDC_Reload));
  288. /* Sets the Reload type */
  289. LTDC->SRCR = (uint32_t)LTDC_Reload;
  290. }
  291. /**
  292. * @brief Initializes the LTDC Layer according to the specified parameters
  293. * in the LTDC_LayerStruct.
  294. * @note This function can be used only when the LTDC is disabled.
  295. * @param LTDC_layerx: Select the layer to be configured, this parameter can be
  296. * one of the following values: LTDC_Layer1, LTDC_Layer2
  297. * @param LTDC_LayerStruct: pointer to a LTDC_LayerTypeDef structure that contains
  298. * the configuration information for the specified LTDC peripheral.
  299. * @retval None
  300. */
  301. void LTDC_LayerInit(LTDC_Layer_TypeDef* LTDC_Layerx, LTDC_Layer_InitTypeDef* LTDC_Layer_InitStruct)
  302. {
  303. uint32_t whsppos = 0;
  304. uint32_t wvsppos = 0;
  305. uint32_t dcgreen = 0;
  306. uint32_t dcred = 0;
  307. uint32_t dcalpha = 0;
  308. uint32_t cfbp = 0;
  309. /* Check the parameters */
  310. assert_param(IS_LTDC_Pixelformat(LTDC_Layer_InitStruct->LTDC_PixelFormat));
  311. assert_param(IS_LTDC_BlendingFactor1(LTDC_Layer_InitStruct->LTDC_BlendingFactor_1));
  312. assert_param(IS_LTDC_BlendingFactor2(LTDC_Layer_InitStruct->LTDC_BlendingFactor_2));
  313. assert_param(IS_LTDC_HCONFIGST(LTDC_Layer_InitStruct->LTDC_HorizontalStart));
  314. assert_param(IS_LTDC_HCONFIGSP(LTDC_Layer_InitStruct->LTDC_HorizontalStop));
  315. assert_param(IS_LTDC_VCONFIGST(LTDC_Layer_InitStruct->LTDC_VerticalStart));
  316. assert_param(IS_LTDC_VCONFIGSP(LTDC_Layer_InitStruct->LTDC_VerticalStop));
  317. assert_param(IS_LTDC_DEFAULTCOLOR(LTDC_Layer_InitStruct->LTDC_DefaultColorBlue));
  318. assert_param(IS_LTDC_DEFAULTCOLOR(LTDC_Layer_InitStruct->LTDC_DefaultColorGreen));
  319. assert_param(IS_LTDC_DEFAULTCOLOR(LTDC_Layer_InitStruct->LTDC_DefaultColorRed));
  320. assert_param(IS_LTDC_DEFAULTCOLOR(LTDC_Layer_InitStruct->LTDC_DefaultColorAlpha));
  321. assert_param(IS_LTDC_CFBP(LTDC_Layer_InitStruct->LTDC_CFBPitch));
  322. assert_param(IS_LTDC_CFBLL(LTDC_Layer_InitStruct->LTDC_CFBLineLength));
  323. assert_param(IS_LTDC_CFBLNBR(LTDC_Layer_InitStruct->LTDC_CFBLineNumber));
  324. /* Configures the horizontal start and stop position */
  325. whsppos = LTDC_Layer_InitStruct->LTDC_HorizontalStop << 16;
  326. LTDC_Layerx->WHPCR &= ~(LTDC_LxWHPCR_WHSTPOS | LTDC_LxWHPCR_WHSPPOS);
  327. LTDC_Layerx->WHPCR = (LTDC_Layer_InitStruct->LTDC_HorizontalStart | whsppos);
  328. /* Configures the vertical start and stop position */
  329. wvsppos = LTDC_Layer_InitStruct->LTDC_VerticalStop << 16;
  330. LTDC_Layerx->WVPCR &= ~(LTDC_LxWVPCR_WVSTPOS | LTDC_LxWVPCR_WVSPPOS);
  331. LTDC_Layerx->WVPCR = (LTDC_Layer_InitStruct->LTDC_VerticalStart | wvsppos);
  332. /* Specifies the pixel format */
  333. LTDC_Layerx->PFCR &= ~(LTDC_LxPFCR_PF);
  334. LTDC_Layerx->PFCR = (LTDC_Layer_InitStruct->LTDC_PixelFormat);
  335. /* Configures the default color values */
  336. dcgreen = (LTDC_Layer_InitStruct->LTDC_DefaultColorGreen << 8);
  337. dcred = (LTDC_Layer_InitStruct->LTDC_DefaultColorRed << 16);
  338. dcalpha = (LTDC_Layer_InitStruct->LTDC_DefaultColorAlpha << 24);
  339. LTDC_Layerx->DCCR &= ~(LTDC_LxDCCR_DCBLUE | LTDC_LxDCCR_DCGREEN | LTDC_LxDCCR_DCRED | LTDC_LxDCCR_DCALPHA);
  340. LTDC_Layerx->DCCR = (LTDC_Layer_InitStruct->LTDC_DefaultColorBlue | dcgreen | \
  341. dcred | dcalpha);
  342. /* Specifies the constant alpha value */
  343. LTDC_Layerx->CACR &= ~(LTDC_LxCACR_CONSTA);
  344. LTDC_Layerx->CACR = (LTDC_Layer_InitStruct->LTDC_ConstantAlpha);
  345. /* Specifies the blending factors */
  346. LTDC_Layerx->BFCR &= ~(LTDC_LxBFCR_BF2 | LTDC_LxBFCR_BF1);
  347. LTDC_Layerx->BFCR = (LTDC_Layer_InitStruct->LTDC_BlendingFactor_1 | LTDC_Layer_InitStruct->LTDC_BlendingFactor_2);
  348. /* Configures the color frame buffer start address */
  349. LTDC_Layerx->CFBAR &= ~(LTDC_LxCFBAR_CFBADD);
  350. LTDC_Layerx->CFBAR = (LTDC_Layer_InitStruct->LTDC_CFBStartAdress);
  351. /* Configures the color frame buffer pitch in byte */
  352. cfbp = (LTDC_Layer_InitStruct->LTDC_CFBPitch << 16);
  353. LTDC_Layerx->CFBLR &= ~(LTDC_LxCFBLR_CFBLL | LTDC_LxCFBLR_CFBP);
  354. LTDC_Layerx->CFBLR = (LTDC_Layer_InitStruct->LTDC_CFBLineLength | cfbp);
  355. /* Configures the frame buffer line number */
  356. LTDC_Layerx->CFBLNR &= ~(LTDC_LxCFBLNR_CFBLNBR);
  357. LTDC_Layerx->CFBLNR = (LTDC_Layer_InitStruct->LTDC_CFBLineNumber);
  358. }
  359. /**
  360. * @brief Fills each LTDC_Layer_InitStruct member with its default value.
  361. * @param LTDC_Layer_InitStruct: pointer to a LTDC_LayerTypeDef structure which will
  362. * be initialized.
  363. * @retval None
  364. */
  365. void LTDC_LayerStructInit(LTDC_Layer_InitTypeDef * LTDC_Layer_InitStruct)
  366. {
  367. /*--------------- Reset Layer structure parameters values -------------------*/
  368. /*!< Initialize the horizontal limit member */
  369. LTDC_Layer_InitStruct->LTDC_HorizontalStart = 0x00;
  370. LTDC_Layer_InitStruct->LTDC_HorizontalStop = 0x00;
  371. /*!< Initialize the vertical limit member */
  372. LTDC_Layer_InitStruct->LTDC_VerticalStart = 0x00;
  373. LTDC_Layer_InitStruct->LTDC_VerticalStop = 0x00;
  374. /*!< Initialize the pixel format member */
  375. LTDC_Layer_InitStruct->LTDC_PixelFormat = LTDC_Pixelformat_ARGB8888;
  376. /*!< Initialize the constant alpha value */
  377. LTDC_Layer_InitStruct->LTDC_ConstantAlpha = 0xFF;
  378. /*!< Initialize the default color values */
  379. LTDC_Layer_InitStruct->LTDC_DefaultColorBlue = 0x00;
  380. LTDC_Layer_InitStruct->LTDC_DefaultColorGreen = 0x00;
  381. LTDC_Layer_InitStruct->LTDC_DefaultColorRed = 0x00;
  382. LTDC_Layer_InitStruct->LTDC_DefaultColorAlpha = 0x00;
  383. /*!< Initialize the blending factors */
  384. LTDC_Layer_InitStruct->LTDC_BlendingFactor_1 = LTDC_BlendingFactor1_PAxCA;
  385. LTDC_Layer_InitStruct->LTDC_BlendingFactor_2 = LTDC_BlendingFactor2_PAxCA;
  386. /*!< Initialize the frame buffer start address */
  387. LTDC_Layer_InitStruct->LTDC_CFBStartAdress = 0x00;
  388. /*!< Initialize the frame buffer pitch and line length */
  389. LTDC_Layer_InitStruct->LTDC_CFBLineLength = 0x00;
  390. LTDC_Layer_InitStruct->LTDC_CFBPitch = 0x00;
  391. /*!< Initialize the frame buffer line number */
  392. LTDC_Layer_InitStruct->LTDC_CFBLineNumber = 0x00;
  393. }
  394. /**
  395. * @brief Enables or disables the LTDC_Layer Controller.
  396. * @param LTDC_layerx: Select the layer to be configured, this parameter can be
  397. * one of the following values: LTDC_Layer1, LTDC_Layer2
  398. * @param NewState: new state of the LTDC_Layer peripheral.
  399. * This parameter can be: ENABLE or DISABLE.
  400. * @retval None
  401. */
  402. void LTDC_LayerCmd(LTDC_Layer_TypeDef* LTDC_Layerx, FunctionalState NewState)
  403. {
  404. /* Check the parameters */
  405. assert_param(IS_FUNCTIONAL_STATE(NewState));
  406. if (NewState != DISABLE)
  407. {
  408. /* Enable LTDC_Layer by setting LEN bit */
  409. LTDC_Layerx->CR |= (uint32_t)LTDC_LxCR_LEN;
  410. }
  411. else
  412. {
  413. /* Disable LTDC_Layer by clearing LEN bit */
  414. LTDC_Layerx->CR &= ~(uint32_t)LTDC_LxCR_LEN;
  415. }
  416. }
  417. /**
  418. * @brief Get the current position.
  419. * @param LTDC_Pos_InitStruct: pointer to a LTDC_PosTypeDef structure that contains
  420. * the current position.
  421. * @retval None
  422. */
  423. LTDC_PosTypeDef LTDC_GetPosStatus(void)
  424. {
  425. LTDC_PosTypeDef LTDC_Pos_InitStruct;
  426. LTDC->CPSR &= ~(LTDC_CPSR_CYPOS | LTDC_CPSR_CXPOS);
  427. LTDC_Pos_InitStruct.LTDC_POSX = (uint32_t)(LTDC->CPSR >> 16);
  428. LTDC_Pos_InitStruct.LTDC_POSY = (uint32_t)(LTDC->CPSR & 0xFFFF);
  429. return LTDC_Pos_InitStruct;
  430. }
  431. /**
  432. * @brief Fills each LTDC_Pos_InitStruct member with its default value.
  433. * @param LTDC_Pos_InitStruct: pointer to a LTDC_PosTypeDef structure which will
  434. * be initialized.
  435. * @retval None
  436. */
  437. void LTDC_PosStructInit(LTDC_PosTypeDef* LTDC_Pos_InitStruct)
  438. {
  439. LTDC_Pos_InitStruct->LTDC_POSX = 0x00;
  440. LTDC_Pos_InitStruct->LTDC_POSY = 0x00;
  441. }
  442. /**
  443. * @brief Checks whether the specified LTDC's flag is set or not.
  444. * @param LTDC_CD: specifies the flag to check.
  445. * This parameter can be one of the following values:
  446. * @arg LTDC_CD_VDES: vertical data enable current status.
  447. * @arg LTDC_CD_HDES: horizontal data enable current status.
  448. * @arg LTDC_CD_VSYNC: Vertical Synchronization current status.
  449. * @arg LTDC_CD_HSYNC: Horizontal Synchronization current status.
  450. * @retval The new state of LTDC_CD (SET or RESET).
  451. */
  452. FlagStatus LTDC_GetCDStatus(uint32_t LTDC_CD)
  453. {
  454. FlagStatus bitstatus;
  455. /* Check the parameters */
  456. assert_param(IS_LTDC_GET_CD(LTDC_CD));
  457. if ((LTDC->CDSR & LTDC_CD) != (uint32_t)RESET)
  458. {
  459. bitstatus = SET;
  460. }
  461. else
  462. {
  463. bitstatus = RESET;
  464. }
  465. return bitstatus;
  466. }
  467. /**
  468. * @brief Set and configure the color keying.
  469. * @param LTDC_colorkeying_InitStruct: pointer to a LTDC_ColorKeying_InitTypeDef
  470. * structure that contains the color keying configuration.
  471. * @param LTDC_layerx: Select the layer to be configured, this parameter can be
  472. * one of the following values: LTDC_Layer1, LTDC_Layer2
  473. * @retval None
  474. */
  475. void LTDC_ColorKeyingConfig(LTDC_Layer_TypeDef* LTDC_Layerx, LTDC_ColorKeying_InitTypeDef* LTDC_colorkeying_InitStruct, FunctionalState NewState)
  476. {
  477. uint32_t ckgreen = 0;
  478. uint32_t ckred = 0;
  479. /* Check the parameters */
  480. assert_param(IS_FUNCTIONAL_STATE(NewState));
  481. assert_param(IS_LTDC_CKEYING(LTDC_colorkeying_InitStruct->LTDC_ColorKeyBlue));
  482. assert_param(IS_LTDC_CKEYING(LTDC_colorkeying_InitStruct->LTDC_ColorKeyGreen));
  483. assert_param(IS_LTDC_CKEYING(LTDC_colorkeying_InitStruct->LTDC_ColorKeyRed));
  484. if (NewState != DISABLE)
  485. {
  486. /* Enable LTDC color keying by setting COLKEN bit */
  487. LTDC_Layerx->CR |= (uint32_t)LTDC_LxCR_COLKEN;
  488. /* Sets the color keying values */
  489. ckgreen = (LTDC_colorkeying_InitStruct->LTDC_ColorKeyGreen << 8);
  490. ckred = (LTDC_colorkeying_InitStruct->LTDC_ColorKeyRed << 16);
  491. LTDC_Layerx->CKCR &= ~(LTDC_LxCKCR_CKBLUE | LTDC_LxCKCR_CKGREEN | LTDC_LxCKCR_CKRED);
  492. LTDC_Layerx->CKCR |= (LTDC_colorkeying_InitStruct->LTDC_ColorKeyBlue | ckgreen | ckred);
  493. }
  494. else
  495. {
  496. /* Disable LTDC color keying by clearing COLKEN bit */
  497. LTDC_Layerx->CR &= ~(uint32_t)LTDC_LxCR_COLKEN;
  498. }
  499. /* Reload shadow register */
  500. LTDC->SRCR = LTDC_IMReload;
  501. }
  502. /**
  503. * @brief Fills each LTDC_colorkeying_InitStruct member with its default value.
  504. * @param LTDC_colorkeying_InitStruct: pointer to a LTDC_ColorKeying_InitTypeDef structure which will
  505. * be initialized.
  506. * @retval None
  507. */
  508. void LTDC_ColorKeyingStructInit(LTDC_ColorKeying_InitTypeDef* LTDC_colorkeying_InitStruct)
  509. {
  510. /*!< Initialize the color keying values */
  511. LTDC_colorkeying_InitStruct->LTDC_ColorKeyBlue = 0x00;
  512. LTDC_colorkeying_InitStruct->LTDC_ColorKeyGreen = 0x00;
  513. LTDC_colorkeying_InitStruct->LTDC_ColorKeyRed = 0x00;
  514. }
  515. /**
  516. * @brief Enables or disables CLUT.
  517. * @param NewState: new state of CLUT.
  518. * @param LTDC_layerx: Select the layer to be configured, this parameter can be
  519. * one of the following values: LTDC_Layer1, LTDC_Layer2
  520. * This parameter can be: ENABLE or DISABLE.
  521. * @retval None
  522. */
  523. void LTDC_CLUTCmd(LTDC_Layer_TypeDef* LTDC_Layerx, FunctionalState NewState)
  524. {
  525. /* Check the parameters */
  526. assert_param(IS_FUNCTIONAL_STATE(NewState));
  527. if (NewState != DISABLE)
  528. {
  529. /* Enable CLUT by setting CLUTEN bit */
  530. LTDC_Layerx->CR |= (uint32_t)LTDC_LxCR_CLUTEN;
  531. }
  532. else
  533. {
  534. /* Disable CLUT by clearing CLUTEN bit */
  535. LTDC_Layerx->CR &= ~(uint32_t)LTDC_LxCR_CLUTEN;
  536. }
  537. /* Reload shadow register */
  538. LTDC->SRCR = LTDC_IMReload;
  539. }
  540. /**
  541. * @brief configure the CLUT.
  542. * @param LTDC_CLUT_InitStruct: pointer to a LTDC_CLUT_InitTypeDef structure that contains
  543. * the CLUT configuration.
  544. * @param LTDC_layerx: Select the layer to be configured, this parameter can be
  545. * one of the following values: LTDC_Layer1, LTDC_Layer2
  546. * @retval None
  547. */
  548. void LTDC_CLUTInit(LTDC_Layer_TypeDef* LTDC_Layerx, LTDC_CLUT_InitTypeDef* LTDC_CLUT_InitStruct)
  549. {
  550. uint32_t green = 0;
  551. uint32_t red = 0;
  552. uint32_t clutadd = 0;
  553. /* Check the parameters */
  554. assert_param(IS_LTDC_CLUTWR(LTDC_CLUT_InitStruct->LTDC_CLUTAdress));
  555. assert_param(IS_LTDC_CLUTWR(LTDC_CLUT_InitStruct->LTDC_RedValue));
  556. assert_param(IS_LTDC_CLUTWR(LTDC_CLUT_InitStruct->LTDC_GreenValue));
  557. assert_param(IS_LTDC_CLUTWR(LTDC_CLUT_InitStruct->LTDC_BlueValue));
  558. /* Specifies the CLUT address and RGB value */
  559. green = (LTDC_CLUT_InitStruct->LTDC_GreenValue << 8);
  560. red = (LTDC_CLUT_InitStruct->LTDC_RedValue << 16);
  561. clutadd = (LTDC_CLUT_InitStruct->LTDC_CLUTAdress << 24);
  562. LTDC_Layerx->CLUTWR = (clutadd | LTDC_CLUT_InitStruct->LTDC_BlueValue | \
  563. green | red);
  564. }
  565. /**
  566. * @brief Fills each LTDC_CLUT_InitStruct member with its default value.
  567. * @param LTDC_CLUT_InitStruct: pointer to a LTDC_CLUT_InitTypeDef structure which will
  568. * be initialized.
  569. * @retval None
  570. */
  571. void LTDC_CLUTStructInit(LTDC_CLUT_InitTypeDef* LTDC_CLUT_InitStruct)
  572. {
  573. /*!< Initialize the CLUT address and RGB values */
  574. LTDC_CLUT_InitStruct->LTDC_CLUTAdress = 0x00;
  575. LTDC_CLUT_InitStruct->LTDC_BlueValue = 0x00;
  576. LTDC_CLUT_InitStruct->LTDC_GreenValue = 0x00;
  577. LTDC_CLUT_InitStruct->LTDC_RedValue = 0x00;
  578. }
  579. /**
  580. * @brief reconfigure the layer position.
  581. * @param OffsetX: horizontal offset from start active width .
  582. * @param OffsetY: vertical offset from start active height.
  583. * @param LTDC_layerx: Select the layer to be configured, this parameter can be
  584. * one of the following values: LTDC_Layer1, LTDC_Layer2
  585. * @retval Reload of the shadow registers values must be applied after layer
  586. * position reconfiguration.
  587. */
  588. void LTDC_LayerPosition(LTDC_Layer_TypeDef* LTDC_Layerx, uint16_t OffsetX, uint16_t OffsetY)
  589. {
  590. uint32_t tempreg, temp;
  591. uint32_t horizontal_start;
  592. uint32_t horizontal_stop;
  593. uint32_t vertical_start;
  594. uint32_t vertical_stop;
  595. LTDC_Layerx->WHPCR &= ~(LTDC_LxWHPCR_WHSTPOS | LTDC_LxWHPCR_WHSPPOS);
  596. LTDC_Layerx->WVPCR &= ~(LTDC_LxWVPCR_WVSTPOS | LTDC_LxWVPCR_WVSPPOS);
  597. /* Reconfigures the horizontal and vertical start position */
  598. tempreg = LTDC->BPCR;
  599. horizontal_start = (tempreg >> 16) + 1 + OffsetX;
  600. vertical_start = (tempreg & 0xFFFF) + 1 + OffsetY;
  601. /* Reconfigures the horizontal and vertical stop position */
  602. /* Get the number of byte per pixel */
  603. tempreg = LTDC_Layerx->PFCR;
  604. if (tempreg == LTDC_Pixelformat_ARGB8888)
  605. {
  606. temp = 4;
  607. }
  608. else if (tempreg == LTDC_Pixelformat_RGB888)
  609. {
  610. temp = 3;
  611. }
  612. else if ((tempreg == LTDC_Pixelformat_ARGB4444) ||
  613. (tempreg == LTDC_Pixelformat_RGB565) ||
  614. (tempreg == LTDC_Pixelformat_ARGB1555) ||
  615. (tempreg == LTDC_Pixelformat_AL88))
  616. {
  617. temp = 2;
  618. }
  619. else
  620. {
  621. temp = 1;
  622. }
  623. tempreg = LTDC_Layerx->CFBLR;
  624. horizontal_stop = (((tempreg & 0x1FFF) - 3)/temp) + horizontal_start - 1;
  625. tempreg = LTDC_Layerx->CFBLNR;
  626. vertical_stop = (tempreg & 0x7FF) + vertical_start - 1;
  627. LTDC_Layerx->WHPCR = horizontal_start | (horizontal_stop << 16);
  628. LTDC_Layerx->WVPCR = vertical_start | (vertical_stop << 16);
  629. }
  630. /**
  631. * @brief reconfigure constant alpha.
  632. * @param ConstantAlpha: constant alpha value.
  633. * @param LTDC_layerx: Select the layer to be configured, this parameter can be
  634. * one of the following values: LTDC_Layer1, LTDC_Layer2
  635. * @retval Reload of the shadow registers values must be applied after constant
  636. * alpha reconfiguration.
  637. */
  638. void LTDC_LayerAlpha(LTDC_Layer_TypeDef* LTDC_Layerx, uint8_t ConstantAlpha)
  639. {
  640. /* reconfigure the constant alpha value */
  641. LTDC_Layerx->CACR = ConstantAlpha;
  642. }
  643. /**
  644. * @brief reconfigure layer address.
  645. * @param Address: The color frame buffer start address.
  646. * @param LTDC_layerx: Select the layer to be configured, this parameter can be
  647. * one of the following values: LTDC_Layer1, LTDC_Layer2
  648. * @retval Reload of the shadow registers values must be applied after layer
  649. * address reconfiguration.
  650. */
  651. void LTDC_LayerAddress(LTDC_Layer_TypeDef* LTDC_Layerx, uint32_t Address)
  652. {
  653. /* Reconfigures the color frame buffer start address */
  654. LTDC_Layerx->CFBAR = Address;
  655. }
  656. /**
  657. * @brief reconfigure layer size.
  658. * @param Width: layer window width.
  659. * @param Height: layer window height.
  660. * @param LTDC_layerx: Select the layer to be configured, this parameter can be
  661. * one of the following values: LTDC_Layer1, LTDC_Layer2
  662. * @retval Reload of the shadow registers values must be applied after layer
  663. * size reconfiguration.
  664. */
  665. void LTDC_LayerSize(LTDC_Layer_TypeDef* LTDC_Layerx, uint32_t Width, uint32_t Height)
  666. {
  667. uint8_t temp;
  668. uint32_t tempreg;
  669. uint32_t horizontal_start;
  670. uint32_t horizontal_stop;
  671. uint32_t vertical_start;
  672. uint32_t vertical_stop;
  673. tempreg = LTDC_Layerx->PFCR;
  674. if (tempreg == LTDC_Pixelformat_ARGB8888)
  675. {
  676. temp = 4;
  677. }
  678. else if (tempreg == LTDC_Pixelformat_RGB888)
  679. {
  680. temp = 3;
  681. }
  682. else if ((tempreg == LTDC_Pixelformat_ARGB4444) || \
  683. (tempreg == LTDC_Pixelformat_RGB565) || \
  684. (tempreg == LTDC_Pixelformat_ARGB1555) || \
  685. (tempreg == LTDC_Pixelformat_AL88))
  686. {
  687. temp = 2;
  688. }
  689. else
  690. {
  691. temp = 1;
  692. }
  693. /* update horizontal and vertical stop */
  694. tempreg = LTDC_Layerx->WHPCR;
  695. horizontal_start = (tempreg & 0x1FFF);
  696. horizontal_stop = Width + horizontal_start - 1;
  697. tempreg = LTDC_Layerx->WVPCR;
  698. vertical_start = (tempreg & 0x1FFF);
  699. vertical_stop = Height + vertical_start - 1;
  700. LTDC_Layerx->WHPCR = horizontal_start | (horizontal_stop << 16);
  701. LTDC_Layerx->WVPCR = vertical_start | (vertical_stop << 16);
  702. /* Reconfigures the color frame buffer pitch in byte */
  703. LTDC_Layerx->CFBLR = ((Width * temp) << 16) | ((Width * temp) + 3);
  704. /* Reconfigures the frame buffer line number */
  705. LTDC_Layerx->CFBLNR = Height;
  706. }
  707. /**
  708. * @brief reconfigure layer pixel format.
  709. * @param PixelFormat: reconfigure the pixel format, this parameter can be
  710. * one of the following values:@ref LTDC_Pixelformat.
  711. * @param LTDC_layerx: Select the layer to be configured, this parameter can be
  712. * one of the following values: LTDC_Layer1, LTDC_Layer2
  713. * @retval Reload of the shadow registers values must be applied after layer
  714. * pixel format reconfiguration.
  715. */
  716. void LTDC_LayerPixelFormat(LTDC_Layer_TypeDef* LTDC_Layerx, uint32_t PixelFormat)
  717. {
  718. uint8_t temp;
  719. uint32_t tempreg;
  720. tempreg = LTDC_Layerx->PFCR;
  721. if (tempreg == LTDC_Pixelformat_ARGB8888)
  722. {
  723. temp = 4;
  724. }
  725. else if (tempreg == LTDC_Pixelformat_RGB888)
  726. {
  727. temp = 3;
  728. }
  729. else if ((tempreg == LTDC_Pixelformat_ARGB4444) || \
  730. (tempreg == LTDC_Pixelformat_RGB565) || \
  731. (tempreg == LTDC_Pixelformat_ARGB1555) || \
  732. (tempreg == LTDC_Pixelformat_AL88))
  733. {
  734. temp = 2;
  735. }
  736. else
  737. {
  738. temp = 1;
  739. }
  740. tempreg = (LTDC_Layerx->CFBLR >> 16);
  741. tempreg = (tempreg / temp);
  742. if (PixelFormat == LTDC_Pixelformat_ARGB8888)
  743. {
  744. temp = 4;
  745. }
  746. else if (PixelFormat == LTDC_Pixelformat_RGB888)
  747. {
  748. temp = 3;
  749. }
  750. else if ((PixelFormat == LTDC_Pixelformat_ARGB4444) || \
  751. (PixelFormat == LTDC_Pixelformat_RGB565) || \
  752. (PixelFormat == LTDC_Pixelformat_ARGB1555) || \
  753. (PixelFormat == LTDC_Pixelformat_AL88))
  754. {
  755. temp = 2;
  756. }
  757. else
  758. {
  759. temp = 1;
  760. }
  761. /* Reconfigures the color frame buffer pitch in byte */
  762. LTDC_Layerx->CFBLR = ((tempreg * temp) << 16) | ((tempreg * temp) + 3);
  763. /* Reconfigures the color frame buffer start address */
  764. LTDC_Layerx->PFCR = PixelFormat;
  765. }
  766. /**
  767. * @}
  768. */
  769. /** @defgroup LTDC_Group2 Interrupts and flags management functions
  770. * @brief Interrupts and flags management functions
  771. *
  772. @verbatim
  773. ===============================================================================
  774. ##### Interrupts and flags management functions #####
  775. ===============================================================================
  776. [..] This section provides functions allowing to configure the LTDC Interrupts
  777. and to get the status and clear flags and Interrupts pending bits.
  778. [..] The LTDC provides 4 Interrupts sources and 4 Flags
  779. *** Flags ***
  780. =============
  781. [..]
  782. (+) LTDC_FLAG_LI: Line Interrupt flag.
  783. (+) LTDC_FLAG_FU: FIFO Underrun Interrupt flag.
  784. (+) LTDC_FLAG_TERR: Transfer Error Interrupt flag.
  785. (+) LTDC_FLAG_RR: Register Reload interrupt flag.
  786. *** Interrupts ***
  787. ==================
  788. [..]
  789. (+) LTDC_IT_LI: Line Interrupt is generated when a programmed line
  790. is reached. The line interrupt position is programmed in
  791. the LTDC_LIPR register.
  792. (+) LTDC_IT_FU: FIFO Underrun interrupt is generated when a pixel is requested
  793. from an empty layer FIFO
  794. (+) LTDC_IT_TERR: Transfer Error interrupt is generated when an AHB bus
  795. error occurs during data transfer.
  796. (+) LTDC_IT_RR: Register Reload interrupt is generated when the shadow
  797. registers reload was performed during the vertical blanking
  798. period.
  799. @endverbatim
  800. * @{
  801. */
  802. /**
  803. * @brief Enables or disables the specified LTDC's interrupts.
  804. * @param LTDC_IT: specifies the LTDC interrupts sources to be enabled or disabled.
  805. * This parameter can be any combination of the following values:
  806. * @arg LTDC_IT_LI: Line Interrupt Enable.
  807. * @arg LTDC_IT_FU: FIFO Underrun Interrupt Enable.
  808. * @arg LTDC_IT_TERR: Transfer Error Interrupt Enable.
  809. * @arg LTDC_IT_RR: Register Reload interrupt enable.
  810. * @param NewState: new state of the specified LTDC interrupts.
  811. * This parameter can be: ENABLE or DISABLE.
  812. * @retval None
  813. */
  814. void LTDC_ITConfig(uint32_t LTDC_IT, FunctionalState NewState)
  815. {
  816. /* Check the parameters */
  817. assert_param(IS_LTDC_IT(LTDC_IT));
  818. assert_param(IS_FUNCTIONAL_STATE(NewState));
  819. if (NewState != DISABLE)
  820. {
  821. LTDC->IER |= LTDC_IT;
  822. }
  823. else
  824. {
  825. LTDC->IER &= (uint32_t)~LTDC_IT;
  826. }
  827. }
  828. /**
  829. * @brief Checks whether the specified LTDC's flag is set or not.
  830. * @param LTDC_FLAG: specifies the flag to check.
  831. * This parameter can be one of the following values:
  832. * @arg LTDC_FLAG_LI: Line Interrupt flag.
  833. * @arg LTDC_FLAG_FU: FIFO Underrun Interrupt flag.
  834. * @arg LTDC_FLAG_TERR: Transfer Error Interrupt flag.
  835. * @arg LTDC_FLAG_RR: Register Reload interrupt flag.
  836. * @retval The new state of LTDC_FLAG (SET or RESET).
  837. */
  838. FlagStatus LTDC_GetFlagStatus(uint32_t LTDC_FLAG)
  839. {
  840. FlagStatus bitstatus = RESET;
  841. /* Check the parameters */
  842. assert_param(IS_LTDC_FLAG(LTDC_FLAG));
  843. if ((LTDC->ISR & LTDC_FLAG) != (uint32_t)RESET)
  844. {
  845. bitstatus = SET;
  846. }
  847. else
  848. {
  849. bitstatus = RESET;
  850. }
  851. return bitstatus;
  852. }
  853. /**
  854. * @brief Clears the LTDC's pending flags.
  855. * @param LTDC_FLAG: specifies the flag to clear.
  856. * This parameter can be any combination of the following values:
  857. * @arg LTDC_FLAG_LI: Line Interrupt flag.
  858. * @arg LTDC_FLAG_FU: FIFO Underrun Interrupt flag.
  859. * @arg LTDC_FLAG_TERR: Transfer Error Interrupt flag.
  860. * @arg LTDC_FLAG_RR: Register Reload interrupt flag.
  861. * @retval None
  862. */
  863. void LTDC_ClearFlag(uint32_t LTDC_FLAG)
  864. {
  865. /* Check the parameters */
  866. assert_param(IS_LTDC_FLAG(LTDC_FLAG));
  867. /* Clear the corresponding LTDC flag */
  868. LTDC->ICR = (uint32_t)LTDC_FLAG;
  869. }
  870. /**
  871. * @brief Checks whether the specified LTDC's interrupt has occurred or not.
  872. * @param LTDC_IT: specifies the LTDC interrupts sources to check.
  873. * This parameter can be one of the following values:
  874. * @arg LTDC_IT_LI: Line Interrupt Enable.
  875. * @arg LTDC_IT_FU: FIFO Underrun Interrupt Enable.
  876. * @arg LTDC_IT_TERR: Transfer Error Interrupt Enable.
  877. * @arg LTDC_IT_RR: Register Reload interrupt Enable.
  878. * @retval The new state of the LTDC_IT (SET or RESET).
  879. */
  880. ITStatus LTDC_GetITStatus(uint32_t LTDC_IT)
  881. {
  882. ITStatus bitstatus = RESET;
  883. /* Check the parameters */
  884. assert_param(IS_LTDC_IT(LTDC_IT));
  885. if ((LTDC->ISR & LTDC_IT) != (uint32_t)RESET)
  886. {
  887. bitstatus = SET;
  888. }
  889. else
  890. {
  891. bitstatus = RESET;
  892. }
  893. if (((LTDC->IER & LTDC_IT) != (uint32_t)RESET) && (bitstatus != (uint32_t)RESET))
  894. {
  895. bitstatus = SET;
  896. }
  897. else
  898. {
  899. bitstatus = RESET;
  900. }
  901. return bitstatus;
  902. }
  903. /**
  904. * @brief Clears the LTDC's interrupt pending bits.
  905. * @param LTDC_IT: specifies the interrupt pending bit to clear.
  906. * This parameter can be any combination of the following values:
  907. * @arg LTDC_IT_LIE: Line Interrupt.
  908. * @arg LTDC_IT_FUIE: FIFO Underrun Interrupt.
  909. * @arg LTDC_IT_TERRIE: Transfer Error Interrupt.
  910. * @arg LTDC_IT_RRIE: Register Reload interrupt.
  911. * @retval None
  912. */
  913. void LTDC_ClearITPendingBit(uint32_t LTDC_IT)
  914. {
  915. /* Check the parameters */
  916. assert_param(IS_LTDC_IT(LTDC_IT));
  917. /* Clear the corresponding LTDC Interrupt */
  918. LTDC->ICR = (uint32_t)LTDC_IT;
  919. }
  920. /**
  921. * @}
  922. */
  923. /**
  924. * @}
  925. */
  926. /**
  927. * @}
  928. */
  929. /**
  930. * @}
  931. */