stm32l4xx_hal_ltdc.c 70 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215
  1. /**
  2. ******************************************************************************
  3. * @file stm32l4xx_hal_ltdc.c
  4. * @author MCD Application Team
  5. * @brief LTDC HAL module driver.
  6. * This file provides firmware functions to manage the following
  7. * functionalities of the LTDC peripheral:
  8. * + Initialization and de-initialization functions
  9. * + IO operation functions
  10. * + Peripheral Control functions
  11. * + Peripheral State and Errors functions
  12. *
  13. ******************************************************************************
  14. * @attention
  15. *
  16. * Copyright (c) 2017 STMicroelectronics.
  17. * All rights reserved.
  18. *
  19. * This software is licensed under terms that can be found in the LICENSE file
  20. * in the root directory of this software component.
  21. * If no LICENSE file comes with this software, it is provided AS-IS.
  22. *
  23. ******************************************************************************
  24. @verbatim
  25. ==============================================================================
  26. ##### How to use this driver #####
  27. ==============================================================================
  28. [..]
  29. The LTDC HAL driver can be used as follows:
  30. (#) Declare a LTDC_HandleTypeDef handle structure, for example: LTDC_HandleTypeDef hltdc;
  31. (#) Initialize the LTDC low level resources by implementing the HAL_LTDC_MspInit() API:
  32. (##) Enable the LTDC interface clock
  33. (##) NVIC configuration if you need to use interrupt process
  34. (+++) Configure the LTDC interrupt priority
  35. (+++) Enable the NVIC LTDC IRQ Channel
  36. (#) Initialize the required configuration through the following parameters:
  37. the LTDC timing, the horizontal and vertical polarity, the pixel clock polarity,
  38. Data Enable polarity and the LTDC background color value using HAL_LTDC_Init() function
  39. *** Configuration ***
  40. =========================
  41. [..]
  42. (#) Program the required configuration through the following parameters:
  43. the pixel format, the blending factors, input alpha value, the window size
  44. and the image size using HAL_LTDC_ConfigLayer() function for foreground
  45. or/and background layer.
  46. (#) Optionally, configure and enable the CLUT using HAL_LTDC_ConfigCLUT() and
  47. HAL_LTDC_EnableCLUT functions.
  48. (#) Optionally, enable the Dither using HAL_LTDC_EnableDither().
  49. (#) Optionally, configure and enable the Color keying using HAL_LTDC_ConfigColorKeying()
  50. and HAL_LTDC_EnableColorKeying functions.
  51. (#) Optionally, configure LineInterrupt using HAL_LTDC_ProgramLineEvent()
  52. function
  53. (#) If needed, reconfigure and change the pixel format value, the alpha value
  54. value, the window size, the window position and the layer start address
  55. for foreground or/and background layer using respectively the following
  56. functions: HAL_LTDC_SetPixelFormat(), HAL_LTDC_SetAlpha(), HAL_LTDC_SetWindowSize(),
  57. HAL_LTDC_SetWindowPosition() and HAL_LTDC_SetAddress().
  58. (#) Variant functions with _NoReload suffix allows to set the LTDC configuration/settings without immediate reload.
  59. This is useful in case when the program requires to modify serval LTDC settings (on one or both layers)
  60. then applying(reload) these settings in one shot by calling the function HAL_LTDC_Reload().
  61. After calling the _NoReload functions to set different color/format/layer settings,
  62. the program shall call the function HAL_LTDC_Reload() to apply(reload) these settings.
  63. Function HAL_LTDC_Reload() can be called with the parameter ReloadType set to LTDC_RELOAD_IMMEDIATE if
  64. an immediate reload is required.
  65. Function HAL_LTDC_Reload() can be called with the parameter ReloadType set to LTDC_RELOAD_VERTICAL_BLANKING if
  66. the reload should be done in the next vertical blanking period,
  67. this option allows to avoid display flicker by applying the new settings during the vertical blanking period.
  68. (#) To control LTDC state you can use the following function: HAL_LTDC_GetState()
  69. *** LTDC HAL driver macros list ***
  70. =============================================
  71. [..]
  72. Below the list of most used macros in LTDC HAL driver.
  73. (+) __HAL_LTDC_ENABLE: Enable the LTDC.
  74. (+) __HAL_LTDC_DISABLE: Disable the LTDC.
  75. (+) __HAL_LTDC_LAYER_ENABLE: Enable an LTDC Layer.
  76. (+) __HAL_LTDC_LAYER_DISABLE: Disable an LTDC Layer.
  77. (+) __HAL_LTDC_RELOAD_IMMEDIATE_CONFIG: Reload Layer Configuration.
  78. (+) __HAL_LTDC_GET_FLAG: Get the LTDC pending flags.
  79. (+) __HAL_LTDC_CLEAR_FLAG: Clear the LTDC pending flags.
  80. (+) __HAL_LTDC_ENABLE_IT: Enable the specified LTDC interrupts.
  81. (+) __HAL_LTDC_DISABLE_IT: Disable the specified LTDC interrupts.
  82. (+) __HAL_LTDC_GET_IT_SOURCE: Check whether the specified LTDC interrupt has occurred or not.
  83. [..]
  84. (@) You can refer to the LTDC HAL driver header file for more useful macros
  85. *** Callback registration ***
  86. =============================================
  87. [..]
  88. The compilation define USE_HAL_LTDC_REGISTER_CALLBACKS when set to 1
  89. allows the user to configure dynamically the driver callbacks.
  90. Use function HAL_LTDC_RegisterCallback() to register a callback.
  91. [..]
  92. Function HAL_LTDC_RegisterCallback() allows to register following callbacks:
  93. (+) LineEventCallback : LTDC Line Event Callback.
  94. (+) ReloadEventCallback : LTDC Reload Event Callback.
  95. (+) ErrorCallback : LTDC Error Callback
  96. (+) MspInitCallback : LTDC MspInit.
  97. (+) MspDeInitCallback : LTDC MspDeInit.
  98. [..]
  99. This function takes as parameters the HAL peripheral handle, the callback ID
  100. and a pointer to the user callback function.
  101. [..]
  102. Use function HAL_LTDC_UnRegisterCallback() to reset a callback to the default
  103. weak function.
  104. HAL_LTDC_UnRegisterCallback() takes as parameters the HAL peripheral handle
  105. and the callback ID.
  106. [..]
  107. This function allows to reset following callbacks:
  108. (+) LineEventCallback : LTDC Line Event Callback
  109. (+) ReloadEventCallback : LTDC Reload Event Callback
  110. (+) ErrorCallback : LTDC Error Callback
  111. (+) MspInitCallback : LTDC MspInit
  112. (+) MspDeInitCallback : LTDC MspDeInit.
  113. [..]
  114. By default, after the HAL_LTDC_Init and when the state is HAL_LTDC_STATE_RESET
  115. all callbacks are set to the corresponding weak functions:
  116. examples HAL_LTDC_LineEventCallback(), HAL_LTDC_ErrorCallback().
  117. Exception done for MspInit and MspDeInit functions that are
  118. reset to the legacy weak (surcharged) functions in the HAL_LTDC_Init() and HAL_LTDC_DeInit()
  119. only when these callbacks are null (not registered beforehand).
  120. If not, MspInit or MspDeInit are not null, the HAL_LTDC_Init() and HAL_LTDC_DeInit()
  121. keep and use the user MspInit/MspDeInit callbacks (registered beforehand).
  122. [..]
  123. Callbacks can be registered/unregistered in HAL_LTDC_STATE_READY state only.
  124. Exception done MspInit/MspDeInit that can be registered/unregistered
  125. in HAL_LTDC_STATE_READY or HAL_LTDC_STATE_RESET state,
  126. thus registered (user) MspInit/DeInit callbacks can be used during the Init/DeInit.
  127. In that case first register the MspInit/MspDeInit user callbacks
  128. using HAL_LTDC_RegisterCallback() before calling HAL_LTDC_DeInit()
  129. or HAL_LTDC_Init() function.
  130. [..]
  131. When the compilation define USE_HAL_LTDC_REGISTER_CALLBACKS is set to 0 or
  132. not defined, the callback registration feature is not available and all callbacks
  133. are set to the corresponding weak functions.
  134. @endverbatim
  135. ******************************************************************************
  136. */
  137. /* Includes ------------------------------------------------------------------*/
  138. #include "stm32l4xx_hal.h"
  139. /** @addtogroup STM32L4xx_HAL_Driver
  140. * @{
  141. */
  142. #ifdef HAL_LTDC_MODULE_ENABLED
  143. #if defined (LTDC)
  144. /** @defgroup LTDC LTDC
  145. * @brief LTDC HAL module driver
  146. * @{
  147. */
  148. /* Private typedef -----------------------------------------------------------*/
  149. /* Private define ------------------------------------------------------------*/
  150. /** @defgroup LTDC_Private_Define LTDC Private Define
  151. * @{
  152. */
  153. #define LTDC_TIMEOUT_VALUE ((uint32_t)100U) /* 100ms */
  154. /**
  155. * @}
  156. */
  157. /* Private macro -------------------------------------------------------------*/
  158. /* Private variables ---------------------------------------------------------*/
  159. /* Private function prototypes -----------------------------------------------*/
  160. static void LTDC_SetConfig(LTDC_HandleTypeDef *hltdc, LTDC_LayerCfgTypeDef *pLayerCfg, uint32_t LayerIdx);
  161. /* Private functions ---------------------------------------------------------*/
  162. /** @defgroup LTDC_Exported_Functions LTDC Exported Functions
  163. * @{
  164. */
  165. /** @defgroup LTDC_Exported_Functions_Group1 Initialization and Configuration functions
  166. * @brief Initialization and Configuration functions
  167. *
  168. @verbatim
  169. ===============================================================================
  170. ##### Initialization and Configuration functions #####
  171. ===============================================================================
  172. [..] This section provides functions allowing to:
  173. (+) Initialize and configure the LTDC
  174. (+) De-initialize the LTDC
  175. @endverbatim
  176. * @{
  177. */
  178. /**
  179. * @brief Initialize the LTDC according to the specified parameters in the LTDC_InitTypeDef.
  180. * @param hltdc pointer to a LTDC_HandleTypeDef structure that contains
  181. * the configuration information for the LTDC.
  182. * @retval HAL status
  183. */
  184. HAL_StatusTypeDef HAL_LTDC_Init(LTDC_HandleTypeDef *hltdc)
  185. {
  186. uint32_t tmp;
  187. uint32_t tmp1;
  188. /* Check the LTDC peripheral state */
  189. if (hltdc == NULL)
  190. {
  191. return HAL_ERROR;
  192. }
  193. /* Check function parameters */
  194. assert_param(IS_LTDC_ALL_INSTANCE(hltdc->Instance));
  195. assert_param(IS_LTDC_HSYNC(hltdc->Init.HorizontalSync));
  196. assert_param(IS_LTDC_VSYNC(hltdc->Init.VerticalSync));
  197. assert_param(IS_LTDC_AHBP(hltdc->Init.AccumulatedHBP));
  198. assert_param(IS_LTDC_AVBP(hltdc->Init.AccumulatedVBP));
  199. assert_param(IS_LTDC_AAH(hltdc->Init.AccumulatedActiveH));
  200. assert_param(IS_LTDC_AAW(hltdc->Init.AccumulatedActiveW));
  201. assert_param(IS_LTDC_TOTALH(hltdc->Init.TotalHeigh));
  202. assert_param(IS_LTDC_TOTALW(hltdc->Init.TotalWidth));
  203. assert_param(IS_LTDC_HSPOL(hltdc->Init.HSPolarity));
  204. assert_param(IS_LTDC_VSPOL(hltdc->Init.VSPolarity));
  205. assert_param(IS_LTDC_DEPOL(hltdc->Init.DEPolarity));
  206. assert_param(IS_LTDC_PCPOL(hltdc->Init.PCPolarity));
  207. #if (USE_HAL_LTDC_REGISTER_CALLBACKS == 1)
  208. if (hltdc->State == HAL_LTDC_STATE_RESET)
  209. {
  210. /* Allocate lock resource and initialize it */
  211. hltdc->Lock = HAL_UNLOCKED;
  212. /* Reset the LTDC callback to the legacy weak callbacks */
  213. hltdc->LineEventCallback = HAL_LTDC_LineEventCallback; /* Legacy weak LineEventCallback */
  214. hltdc->ReloadEventCallback = HAL_LTDC_ReloadEventCallback; /* Legacy weak ReloadEventCallback */
  215. hltdc->ErrorCallback = HAL_LTDC_ErrorCallback; /* Legacy weak ErrorCallback */
  216. if (hltdc->MspInitCallback == NULL)
  217. {
  218. hltdc->MspInitCallback = HAL_LTDC_MspInit;
  219. }
  220. /* Init the low level hardware */
  221. hltdc->MspInitCallback(hltdc);
  222. }
  223. #else
  224. if (hltdc->State == HAL_LTDC_STATE_RESET)
  225. {
  226. /* Allocate lock resource and initialize it */
  227. hltdc->Lock = HAL_UNLOCKED;
  228. /* Init the low level hardware */
  229. HAL_LTDC_MspInit(hltdc);
  230. }
  231. #endif /* USE_HAL_LTDC_REGISTER_CALLBACKS */
  232. /* Change LTDC peripheral state */
  233. hltdc->State = HAL_LTDC_STATE_BUSY;
  234. /* Configure the HS, VS, DE and PC polarity */
  235. hltdc->Instance->GCR &= ~(LTDC_GCR_HSPOL | LTDC_GCR_VSPOL | LTDC_GCR_DEPOL | LTDC_GCR_PCPOL);
  236. hltdc->Instance->GCR |= (uint32_t)(hltdc->Init.HSPolarity | hltdc->Init.VSPolarity | \
  237. hltdc->Init.DEPolarity | hltdc->Init.PCPolarity);
  238. /* Set Synchronization size */
  239. tmp = (hltdc->Init.HorizontalSync << 16U);
  240. WRITE_REG(hltdc->Instance->SSCR, (tmp | hltdc->Init.VerticalSync));
  241. /* Set Accumulated Back porch */
  242. tmp = (hltdc->Init.AccumulatedHBP << 16U);
  243. WRITE_REG(hltdc->Instance->BPCR, (tmp | hltdc->Init.AccumulatedVBP));
  244. /* Set Accumulated Active Width */
  245. tmp = (hltdc->Init.AccumulatedActiveW << 16U);
  246. WRITE_REG(hltdc->Instance->AWCR, (tmp | hltdc->Init.AccumulatedActiveH));
  247. /* Set Total Width */
  248. tmp = (hltdc->Init.TotalWidth << 16U);
  249. WRITE_REG(hltdc->Instance->TWCR, (tmp | hltdc->Init.TotalHeigh));
  250. /* Set the background color value */
  251. tmp = ((uint32_t)(hltdc->Init.Backcolor.Green) << 8U);
  252. tmp1 = ((uint32_t)(hltdc->Init.Backcolor.Red) << 16U);
  253. hltdc->Instance->BCCR &= ~(LTDC_BCCR_BCBLUE | LTDC_BCCR_BCGREEN | LTDC_BCCR_BCRED);
  254. hltdc->Instance->BCCR |= (tmp1 | tmp | hltdc->Init.Backcolor.Blue);
  255. /* Enable the Transfer Error and FIFO underrun interrupts */
  256. __HAL_LTDC_ENABLE_IT(hltdc, LTDC_IT_TE | LTDC_IT_FU);
  257. /* Enable LTDC by setting LTDCEN bit */
  258. __HAL_LTDC_ENABLE(hltdc);
  259. /* Initialize the error code */
  260. hltdc->ErrorCode = HAL_LTDC_ERROR_NONE;
  261. /* Initialize the LTDC state*/
  262. hltdc->State = HAL_LTDC_STATE_READY;
  263. return HAL_OK;
  264. }
  265. /**
  266. * @brief De-initialize the LTDC peripheral.
  267. * @param hltdc pointer to a LTDC_HandleTypeDef structure that contains
  268. * the configuration information for the LTDC.
  269. * @retval None
  270. */
  271. HAL_StatusTypeDef HAL_LTDC_DeInit(LTDC_HandleTypeDef *hltdc)
  272. {
  273. uint32_t tickstart;
  274. /* Check the LTDC peripheral state */
  275. if (hltdc == NULL)
  276. {
  277. return HAL_ERROR;
  278. }
  279. /* Check function parameters */
  280. assert_param(IS_LTDC_ALL_INSTANCE(hltdc->Instance));
  281. /* Disable LTDC Layer 1 */
  282. __HAL_LTDC_LAYER_DISABLE(hltdc, LTDC_LAYER_1);
  283. #if defined(LTDC_Layer2_BASE)
  284. /* Disable LTDC Layer 2 */
  285. __HAL_LTDC_LAYER_DISABLE(hltdc, LTDC_LAYER_2);
  286. #endif /* LTDC_Layer2_BASE */
  287. /* Reload during vertical blanking period */
  288. __HAL_LTDC_VERTICAL_BLANKING_RELOAD_CONFIG(hltdc);
  289. /* Get tick */
  290. tickstart = HAL_GetTick();
  291. /* Wait for VSYNC Interrupt */
  292. while (READ_BIT(hltdc->Instance->CDSR, LTDC_CDSR_VSYNCS) == 0U)
  293. {
  294. /* Check for the Timeout */
  295. if ((HAL_GetTick() - tickstart) > LTDC_TIMEOUT_VALUE)
  296. {
  297. break;
  298. }
  299. }
  300. /* Disable LTDC */
  301. __HAL_LTDC_DISABLE(hltdc);
  302. #if (USE_HAL_LTDC_REGISTER_CALLBACKS == 1)
  303. if (hltdc->MspDeInitCallback == NULL)
  304. {
  305. hltdc->MspDeInitCallback = HAL_LTDC_MspDeInit;
  306. }
  307. /* DeInit the low level hardware */
  308. hltdc->MspDeInitCallback(hltdc);
  309. #else
  310. /* DeInit the low level hardware */
  311. HAL_LTDC_MspDeInit(hltdc);
  312. #endif /* USE_HAL_LTDC_REGISTER_CALLBACKS */
  313. /* Initialize the error code */
  314. hltdc->ErrorCode = HAL_LTDC_ERROR_NONE;
  315. /* Initialize the LTDC state*/
  316. hltdc->State = HAL_LTDC_STATE_RESET;
  317. /* Release Lock */
  318. __HAL_UNLOCK(hltdc);
  319. return HAL_OK;
  320. }
  321. /**
  322. * @brief Initialize the LTDC MSP.
  323. * @param hltdc pointer to a LTDC_HandleTypeDef structure that contains
  324. * the configuration information for the LTDC.
  325. * @retval None
  326. */
  327. __weak void HAL_LTDC_MspInit(LTDC_HandleTypeDef *hltdc)
  328. {
  329. /* Prevent unused argument(s) compilation warning */
  330. UNUSED(hltdc);
  331. /* NOTE : This function should not be modified, when the callback is needed,
  332. the HAL_LTDC_MspInit could be implemented in the user file
  333. */
  334. }
  335. /**
  336. * @brief De-initialize the LTDC MSP.
  337. * @param hltdc pointer to a LTDC_HandleTypeDef structure that contains
  338. * the configuration information for the LTDC.
  339. * @retval None
  340. */
  341. __weak void HAL_LTDC_MspDeInit(LTDC_HandleTypeDef *hltdc)
  342. {
  343. /* Prevent unused argument(s) compilation warning */
  344. UNUSED(hltdc);
  345. /* NOTE : This function should not be modified, when the callback is needed,
  346. the HAL_LTDC_MspDeInit could be implemented in the user file
  347. */
  348. }
  349. #if (USE_HAL_LTDC_REGISTER_CALLBACKS == 1)
  350. /**
  351. * @brief Register a User LTDC Callback
  352. * To be used instead of the weak predefined callback
  353. * @param hltdc ltdc handle
  354. * @param CallbackID ID of the callback to be registered
  355. * This parameter can be one of the following values:
  356. * @arg @ref HAL_LTDC_LINE_EVENT_CB_ID Line Event Callback ID
  357. * @arg @ref HAL_LTDC_RELOAD_EVENT_CB_ID Reload Event Callback ID
  358. * @arg @ref HAL_LTDC_ERROR_CB_ID Error Callback ID
  359. * @arg @ref HAL_LTDC_MSPINIT_CB_ID MspInit callback ID
  360. * @arg @ref HAL_LTDC_MSPDEINIT_CB_ID MspDeInit callback ID
  361. * @param pCallback pointer to the Callback function
  362. * @retval status
  363. */
  364. HAL_StatusTypeDef HAL_LTDC_RegisterCallback(LTDC_HandleTypeDef *hltdc, HAL_LTDC_CallbackIDTypeDef CallbackID,
  365. pLTDC_CallbackTypeDef pCallback)
  366. {
  367. HAL_StatusTypeDef status = HAL_OK;
  368. if (pCallback == NULL)
  369. {
  370. /* Update the error code */
  371. hltdc->ErrorCode |= HAL_LTDC_ERROR_INVALID_CALLBACK;
  372. return HAL_ERROR;
  373. }
  374. /* Process locked */
  375. __HAL_LOCK(hltdc);
  376. if (hltdc->State == HAL_LTDC_STATE_READY)
  377. {
  378. switch (CallbackID)
  379. {
  380. case HAL_LTDC_LINE_EVENT_CB_ID :
  381. hltdc->LineEventCallback = pCallback;
  382. break;
  383. case HAL_LTDC_RELOAD_EVENT_CB_ID :
  384. hltdc->ReloadEventCallback = pCallback;
  385. break;
  386. case HAL_LTDC_ERROR_CB_ID :
  387. hltdc->ErrorCallback = pCallback;
  388. break;
  389. case HAL_LTDC_MSPINIT_CB_ID :
  390. hltdc->MspInitCallback = pCallback;
  391. break;
  392. case HAL_LTDC_MSPDEINIT_CB_ID :
  393. hltdc->MspDeInitCallback = pCallback;
  394. break;
  395. default :
  396. /* Update the error code */
  397. hltdc->ErrorCode |= HAL_LTDC_ERROR_INVALID_CALLBACK;
  398. /* Return error status */
  399. status = HAL_ERROR;
  400. break;
  401. }
  402. }
  403. else if (hltdc->State == HAL_LTDC_STATE_RESET)
  404. {
  405. switch (CallbackID)
  406. {
  407. case HAL_LTDC_MSPINIT_CB_ID :
  408. hltdc->MspInitCallback = pCallback;
  409. break;
  410. case HAL_LTDC_MSPDEINIT_CB_ID :
  411. hltdc->MspDeInitCallback = pCallback;
  412. break;
  413. default :
  414. /* Update the error code */
  415. hltdc->ErrorCode |= HAL_LTDC_ERROR_INVALID_CALLBACK;
  416. /* Return error status */
  417. status = HAL_ERROR;
  418. break;
  419. }
  420. }
  421. else
  422. {
  423. /* Update the error code */
  424. hltdc->ErrorCode |= HAL_LTDC_ERROR_INVALID_CALLBACK;
  425. /* Return error status */
  426. status = HAL_ERROR;
  427. }
  428. /* Release Lock */
  429. __HAL_UNLOCK(hltdc);
  430. return status;
  431. }
  432. /**
  433. * @brief Unregister an LTDC Callback
  434. * LTDC callback is redirected to the weak predefined callback
  435. * @param hltdc ltdc handle
  436. * @param CallbackID ID of the callback to be unregistered
  437. * This parameter can be one of the following values:
  438. * @arg @ref HAL_LTDC_LINE_EVENT_CB_ID Line Event Callback ID
  439. * @arg @ref HAL_LTDC_RELOAD_EVENT_CB_ID Reload Event Callback ID
  440. * @arg @ref HAL_LTDC_ERROR_CB_ID Error Callback ID
  441. * @arg @ref HAL_LTDC_MSPINIT_CB_ID MspInit callback ID
  442. * @arg @ref HAL_LTDC_MSPDEINIT_CB_ID MspDeInit callback ID
  443. * @retval status
  444. */
  445. HAL_StatusTypeDef HAL_LTDC_UnRegisterCallback(LTDC_HandleTypeDef *hltdc, HAL_LTDC_CallbackIDTypeDef CallbackID)
  446. {
  447. HAL_StatusTypeDef status = HAL_OK;
  448. /* Process locked */
  449. __HAL_LOCK(hltdc);
  450. if (hltdc->State == HAL_LTDC_STATE_READY)
  451. {
  452. switch (CallbackID)
  453. {
  454. case HAL_LTDC_LINE_EVENT_CB_ID :
  455. hltdc->LineEventCallback = HAL_LTDC_LineEventCallback; /* Legacy weak LineEventCallback */
  456. break;
  457. case HAL_LTDC_RELOAD_EVENT_CB_ID :
  458. hltdc->ReloadEventCallback = HAL_LTDC_ReloadEventCallback; /* Legacy weak ReloadEventCallback */
  459. break;
  460. case HAL_LTDC_ERROR_CB_ID :
  461. hltdc->ErrorCallback = HAL_LTDC_ErrorCallback; /* Legacy weak ErrorCallback */
  462. break;
  463. case HAL_LTDC_MSPINIT_CB_ID :
  464. hltdc->MspInitCallback = HAL_LTDC_MspInit; /* Legcay weak MspInit Callback */
  465. break;
  466. case HAL_LTDC_MSPDEINIT_CB_ID :
  467. hltdc->MspDeInitCallback = HAL_LTDC_MspDeInit; /* Legcay weak MspDeInit Callback */
  468. break;
  469. default :
  470. /* Update the error code */
  471. hltdc->ErrorCode |= HAL_LTDC_ERROR_INVALID_CALLBACK;
  472. /* Return error status */
  473. status = HAL_ERROR;
  474. break;
  475. }
  476. }
  477. else if (hltdc->State == HAL_LTDC_STATE_RESET)
  478. {
  479. switch (CallbackID)
  480. {
  481. case HAL_LTDC_MSPINIT_CB_ID :
  482. hltdc->MspInitCallback = HAL_LTDC_MspInit; /* Legcay weak MspInit Callback */
  483. break;
  484. case HAL_LTDC_MSPDEINIT_CB_ID :
  485. hltdc->MspDeInitCallback = HAL_LTDC_MspDeInit; /* Legcay weak MspDeInit Callback */
  486. break;
  487. default :
  488. /* Update the error code */
  489. hltdc->ErrorCode |= HAL_LTDC_ERROR_INVALID_CALLBACK;
  490. /* Return error status */
  491. status = HAL_ERROR;
  492. break;
  493. }
  494. }
  495. else
  496. {
  497. /* Update the error code */
  498. hltdc->ErrorCode |= HAL_LTDC_ERROR_INVALID_CALLBACK;
  499. /* Return error status */
  500. status = HAL_ERROR;
  501. }
  502. /* Release Lock */
  503. __HAL_UNLOCK(hltdc);
  504. return status;
  505. }
  506. #endif /* USE_HAL_LTDC_REGISTER_CALLBACKS */
  507. /**
  508. * @}
  509. */
  510. /** @defgroup LTDC_Exported_Functions_Group2 IO operation functions
  511. * @brief IO operation functions
  512. *
  513. @verbatim
  514. ===============================================================================
  515. ##### IO operation functions #####
  516. ===============================================================================
  517. [..] This section provides function allowing to:
  518. (+) Handle LTDC interrupt request
  519. @endverbatim
  520. * @{
  521. */
  522. /**
  523. * @brief Handle LTDC interrupt request.
  524. * @param hltdc pointer to a LTDC_HandleTypeDef structure that contains
  525. * the configuration information for the LTDC.
  526. * @retval HAL status
  527. */
  528. void HAL_LTDC_IRQHandler(LTDC_HandleTypeDef *hltdc)
  529. {
  530. uint32_t isrflags = READ_REG(hltdc->Instance->ISR);
  531. uint32_t itsources = READ_REG(hltdc->Instance->IER);
  532. /* Transfer Error Interrupt management ***************************************/
  533. if (((isrflags & LTDC_ISR_TERRIF) != 0U) && ((itsources & LTDC_IER_TERRIE) != 0U))
  534. {
  535. /* Disable the transfer Error interrupt */
  536. __HAL_LTDC_DISABLE_IT(hltdc, LTDC_IT_TE);
  537. /* Clear the transfer error flag */
  538. __HAL_LTDC_CLEAR_FLAG(hltdc, LTDC_FLAG_TE);
  539. /* Update error code */
  540. hltdc->ErrorCode |= HAL_LTDC_ERROR_TE;
  541. /* Change LTDC state */
  542. hltdc->State = HAL_LTDC_STATE_ERROR;
  543. /* Process unlocked */
  544. __HAL_UNLOCK(hltdc);
  545. /* Transfer error Callback */
  546. #if (USE_HAL_LTDC_REGISTER_CALLBACKS == 1)
  547. /*Call registered error callback*/
  548. hltdc->ErrorCallback(hltdc);
  549. #else
  550. /* Call legacy error callback*/
  551. HAL_LTDC_ErrorCallback(hltdc);
  552. #endif /* USE_HAL_LTDC_REGISTER_CALLBACKS */
  553. }
  554. /* FIFO underrun Interrupt management ***************************************/
  555. if (((isrflags & LTDC_ISR_FUIF) != 0U) && ((itsources & LTDC_IER_FUIE) != 0U))
  556. {
  557. /* Disable the FIFO underrun interrupt */
  558. __HAL_LTDC_DISABLE_IT(hltdc, LTDC_IT_FU);
  559. /* Clear the FIFO underrun flag */
  560. __HAL_LTDC_CLEAR_FLAG(hltdc, LTDC_FLAG_FU);
  561. /* Update error code */
  562. hltdc->ErrorCode |= HAL_LTDC_ERROR_FU;
  563. /* Change LTDC state */
  564. hltdc->State = HAL_LTDC_STATE_ERROR;
  565. /* Process unlocked */
  566. __HAL_UNLOCK(hltdc);
  567. /* Transfer error Callback */
  568. #if (USE_HAL_LTDC_REGISTER_CALLBACKS == 1)
  569. /*Call registered error callback*/
  570. hltdc->ErrorCallback(hltdc);
  571. #else
  572. /* Call legacy error callback*/
  573. HAL_LTDC_ErrorCallback(hltdc);
  574. #endif /* USE_HAL_LTDC_REGISTER_CALLBACKS */
  575. }
  576. /* Line Interrupt management ************************************************/
  577. if (((isrflags & LTDC_ISR_LIF) != 0U) && ((itsources & LTDC_IER_LIE) != 0U))
  578. {
  579. /* Disable the Line interrupt */
  580. __HAL_LTDC_DISABLE_IT(hltdc, LTDC_IT_LI);
  581. /* Clear the Line interrupt flag */
  582. __HAL_LTDC_CLEAR_FLAG(hltdc, LTDC_FLAG_LI);
  583. /* Change LTDC state */
  584. hltdc->State = HAL_LTDC_STATE_READY;
  585. /* Process unlocked */
  586. __HAL_UNLOCK(hltdc);
  587. /* Line interrupt Callback */
  588. #if (USE_HAL_LTDC_REGISTER_CALLBACKS == 1)
  589. /*Call registered Line Event callback */
  590. hltdc->LineEventCallback(hltdc);
  591. #else
  592. /*Call Legacy Line Event callback */
  593. HAL_LTDC_LineEventCallback(hltdc);
  594. #endif /* USE_HAL_LTDC_REGISTER_CALLBACKS */
  595. }
  596. /* Register reload Interrupt management ***************************************/
  597. if (((isrflags & LTDC_ISR_RRIF) != 0U) && ((itsources & LTDC_IER_RRIE) != 0U))
  598. {
  599. /* Disable the register reload interrupt */
  600. __HAL_LTDC_DISABLE_IT(hltdc, LTDC_IT_RR);
  601. /* Clear the register reload flag */
  602. __HAL_LTDC_CLEAR_FLAG(hltdc, LTDC_FLAG_RR);
  603. /* Change LTDC state */
  604. hltdc->State = HAL_LTDC_STATE_READY;
  605. /* Process unlocked */
  606. __HAL_UNLOCK(hltdc);
  607. /* Reload interrupt Callback */
  608. #if (USE_HAL_LTDC_REGISTER_CALLBACKS == 1)
  609. /*Call registered reload Event callback */
  610. hltdc->ReloadEventCallback(hltdc);
  611. #else
  612. /*Call Legacy Reload Event callback */
  613. HAL_LTDC_ReloadEventCallback(hltdc);
  614. #endif /* USE_HAL_LTDC_REGISTER_CALLBACKS */
  615. }
  616. }
  617. /**
  618. * @brief Error LTDC callback.
  619. * @param hltdc pointer to a LTDC_HandleTypeDef structure that contains
  620. * the configuration information for the LTDC.
  621. * @retval None
  622. */
  623. __weak void HAL_LTDC_ErrorCallback(LTDC_HandleTypeDef *hltdc)
  624. {
  625. /* Prevent unused argument(s) compilation warning */
  626. UNUSED(hltdc);
  627. /* NOTE : This function should not be modified, when the callback is needed,
  628. the HAL_LTDC_ErrorCallback could be implemented in the user file
  629. */
  630. }
  631. /**
  632. * @brief Line Event callback.
  633. * @param hltdc pointer to a LTDC_HandleTypeDef structure that contains
  634. * the configuration information for the LTDC.
  635. * @retval None
  636. */
  637. __weak void HAL_LTDC_LineEventCallback(LTDC_HandleTypeDef *hltdc)
  638. {
  639. /* Prevent unused argument(s) compilation warning */
  640. UNUSED(hltdc);
  641. /* NOTE : This function should not be modified, when the callback is needed,
  642. the HAL_LTDC_LineEventCallback could be implemented in the user file
  643. */
  644. }
  645. /**
  646. * @brief Reload Event callback.
  647. * @param hltdc pointer to a LTDC_HandleTypeDef structure that contains
  648. * the configuration information for the LTDC.
  649. * @retval None
  650. */
  651. __weak void HAL_LTDC_ReloadEventCallback(LTDC_HandleTypeDef *hltdc)
  652. {
  653. /* Prevent unused argument(s) compilation warning */
  654. UNUSED(hltdc);
  655. /* NOTE : This function should not be modified, when the callback is needed,
  656. the HAL_LTDC_ReloadEvenCallback could be implemented in the user file
  657. */
  658. }
  659. /**
  660. * @}
  661. */
  662. /** @defgroup LTDC_Exported_Functions_Group3 Peripheral Control functions
  663. * @brief Peripheral Control functions
  664. *
  665. @verbatim
  666. ===============================================================================
  667. ##### Peripheral Control functions #####
  668. ===============================================================================
  669. [..] This section provides functions allowing to:
  670. (+) Configure the LTDC foreground or/and background parameters.
  671. (+) Set the active layer.
  672. (+) Configure the color keying.
  673. (+) Configure the C-LUT.
  674. (+) Enable / Disable the color keying.
  675. (+) Enable / Disable the C-LUT.
  676. (+) Update the layer position.
  677. (+) Update the layer size.
  678. (+) Update pixel format on the fly.
  679. (+) Update transparency on the fly.
  680. (+) Update address on the fly.
  681. @endverbatim
  682. * @{
  683. */
  684. /**
  685. * @brief Configure the LTDC Layer according to the specified
  686. * parameters in the LTDC_InitTypeDef and create the associated handle.
  687. * @param hltdc pointer to a LTDC_HandleTypeDef structure that contains
  688. * the configuration information for the LTDC.
  689. * @param pLayerCfg pointer to a LTDC_LayerCfgTypeDef structure that contains
  690. * the configuration information for the Layer.
  691. * @param LayerIdx LTDC Layer index.
  692. * This parameter can be one of the following values:
  693. * LTDC_LAYER_1 (0) or LTDC_LAYER_2 (1)
  694. * @retval HAL status
  695. */
  696. HAL_StatusTypeDef HAL_LTDC_ConfigLayer(LTDC_HandleTypeDef *hltdc, LTDC_LayerCfgTypeDef *pLayerCfg, uint32_t LayerIdx)
  697. {
  698. /* Check the parameters */
  699. assert_param(IS_LTDC_LAYER(LayerIdx));
  700. assert_param(IS_LTDC_HCONFIGST(pLayerCfg->WindowX0));
  701. assert_param(IS_LTDC_HCONFIGSP(pLayerCfg->WindowX1));
  702. assert_param(IS_LTDC_VCONFIGST(pLayerCfg->WindowY0));
  703. assert_param(IS_LTDC_VCONFIGSP(pLayerCfg->WindowY1));
  704. assert_param(IS_LTDC_PIXEL_FORMAT(pLayerCfg->PixelFormat));
  705. assert_param(IS_LTDC_ALPHA(pLayerCfg->Alpha));
  706. assert_param(IS_LTDC_ALPHA(pLayerCfg->Alpha0));
  707. assert_param(IS_LTDC_BLENDING_FACTOR1(pLayerCfg->BlendingFactor1));
  708. assert_param(IS_LTDC_BLENDING_FACTOR2(pLayerCfg->BlendingFactor2));
  709. assert_param(IS_LTDC_CFBLL(pLayerCfg->ImageWidth));
  710. assert_param(IS_LTDC_CFBLNBR(pLayerCfg->ImageHeight));
  711. /* Process locked */
  712. __HAL_LOCK(hltdc);
  713. /* Change LTDC peripheral state */
  714. hltdc->State = HAL_LTDC_STATE_BUSY;
  715. /* Copy new layer configuration into handle structure */
  716. hltdc->LayerCfg[LayerIdx] = *pLayerCfg;
  717. /* Configure the LTDC Layer */
  718. LTDC_SetConfig(hltdc, pLayerCfg, LayerIdx);
  719. /* Set the Immediate Reload type */
  720. hltdc->Instance->SRCR = LTDC_SRCR_IMR;
  721. /* Initialize the LTDC state*/
  722. hltdc->State = HAL_LTDC_STATE_READY;
  723. /* Process unlocked */
  724. __HAL_UNLOCK(hltdc);
  725. return HAL_OK;
  726. }
  727. /**
  728. * @brief Configure the color keying.
  729. * @param hltdc pointer to a LTDC_HandleTypeDef structure that contains
  730. * the configuration information for the LTDC.
  731. * @param RGBValue the color key value
  732. * @param LayerIdx LTDC Layer index.
  733. * This parameter can be one of the following values:
  734. * LTDC_LAYER_1 (0) or LTDC_LAYER_2 (1)
  735. * @retval HAL status
  736. */
  737. HAL_StatusTypeDef HAL_LTDC_ConfigColorKeying(LTDC_HandleTypeDef *hltdc, uint32_t RGBValue, uint32_t LayerIdx)
  738. {
  739. /* Check the parameters */
  740. assert_param(IS_LTDC_LAYER(LayerIdx));
  741. /* Process locked */
  742. __HAL_LOCK(hltdc);
  743. /* Change LTDC peripheral state */
  744. hltdc->State = HAL_LTDC_STATE_BUSY;
  745. /* Configure the default color values */
  746. LTDC_LAYER(hltdc, LayerIdx)->CKCR &= ~(LTDC_LxCKCR_CKBLUE | LTDC_LxCKCR_CKGREEN | LTDC_LxCKCR_CKRED);
  747. LTDC_LAYER(hltdc, LayerIdx)->CKCR = RGBValue;
  748. /* Set the Immediate Reload type */
  749. hltdc->Instance->SRCR = LTDC_SRCR_IMR;
  750. /* Change the LTDC state*/
  751. hltdc->State = HAL_LTDC_STATE_READY;
  752. /* Process unlocked */
  753. __HAL_UNLOCK(hltdc);
  754. return HAL_OK;
  755. }
  756. /**
  757. * @brief Load the color lookup table.
  758. * @param hltdc pointer to a LTDC_HandleTypeDef structure that contains
  759. * the configuration information for the LTDC.
  760. * @param pCLUT pointer to the color lookup table address.
  761. * @param CLUTSize the color lookup table size.
  762. * @param LayerIdx LTDC Layer index.
  763. * This parameter can be one of the following values:
  764. * LTDC_LAYER_1 (0) or LTDC_LAYER_2 (1)
  765. * @retval HAL status
  766. */
  767. HAL_StatusTypeDef HAL_LTDC_ConfigCLUT(LTDC_HandleTypeDef *hltdc, const uint32_t *pCLUT, uint32_t CLUTSize,
  768. uint32_t LayerIdx)
  769. {
  770. uint32_t tmp;
  771. uint32_t counter;
  772. const uint32_t *pcolorlut = pCLUT;
  773. /* Check the parameters */
  774. assert_param(IS_LTDC_LAYER(LayerIdx));
  775. /* Process locked */
  776. __HAL_LOCK(hltdc);
  777. /* Change LTDC peripheral state */
  778. hltdc->State = HAL_LTDC_STATE_BUSY;
  779. for (counter = 0U; (counter < CLUTSize); counter++)
  780. {
  781. if (hltdc->LayerCfg[LayerIdx].PixelFormat == LTDC_PIXEL_FORMAT_AL44)
  782. {
  783. tmp = (((counter + (16U * counter)) << 24U) | ((uint32_t)(*pcolorlut) & 0xFFU) | \
  784. ((uint32_t)(*pcolorlut) & 0xFF00U) | ((uint32_t)(*pcolorlut) & 0xFF0000U));
  785. }
  786. else
  787. {
  788. tmp = ((counter << 24U) | ((uint32_t)(*pcolorlut) & 0xFFU) | \
  789. ((uint32_t)(*pcolorlut) & 0xFF00U) | ((uint32_t)(*pcolorlut) & 0xFF0000U));
  790. }
  791. pcolorlut++;
  792. /* Specifies the C-LUT address and RGB value */
  793. LTDC_LAYER(hltdc, LayerIdx)->CLUTWR = tmp;
  794. }
  795. /* Change the LTDC state*/
  796. hltdc->State = HAL_LTDC_STATE_READY;
  797. /* Process unlocked */
  798. __HAL_UNLOCK(hltdc);
  799. return HAL_OK;
  800. }
  801. /**
  802. * @brief Enable the color keying.
  803. * @param hltdc pointer to a LTDC_HandleTypeDef structure that contains
  804. * the configuration information for the LTDC.
  805. * @param LayerIdx LTDC Layer index.
  806. * This parameter can be one of the following values:
  807. * LTDC_LAYER_1 (0) or LTDC_LAYER_2 (1)
  808. * @retval HAL status
  809. */
  810. HAL_StatusTypeDef HAL_LTDC_EnableColorKeying(LTDC_HandleTypeDef *hltdc, uint32_t LayerIdx)
  811. {
  812. /* Check the parameters */
  813. assert_param(IS_LTDC_LAYER(LayerIdx));
  814. /* Process locked */
  815. __HAL_LOCK(hltdc);
  816. /* Change LTDC peripheral state */
  817. hltdc->State = HAL_LTDC_STATE_BUSY;
  818. /* Enable LTDC color keying by setting COLKEN bit */
  819. LTDC_LAYER(hltdc, LayerIdx)->CR |= (uint32_t)LTDC_LxCR_COLKEN;
  820. /* Set the Immediate Reload type */
  821. hltdc->Instance->SRCR = LTDC_SRCR_IMR;
  822. /* Change the LTDC state*/
  823. hltdc->State = HAL_LTDC_STATE_READY;
  824. /* Process unlocked */
  825. __HAL_UNLOCK(hltdc);
  826. return HAL_OK;
  827. }
  828. /**
  829. * @brief Disable the color keying.
  830. * @param hltdc pointer to a LTDC_HandleTypeDef structure that contains
  831. * the configuration information for the LTDC.
  832. * @param LayerIdx LTDC Layer index.
  833. * This parameter can be one of the following values:
  834. * LTDC_LAYER_1 (0) or LTDC_LAYER_2 (1)
  835. * @retval HAL status
  836. */
  837. HAL_StatusTypeDef HAL_LTDC_DisableColorKeying(LTDC_HandleTypeDef *hltdc, uint32_t LayerIdx)
  838. {
  839. /* Check the parameters */
  840. assert_param(IS_LTDC_LAYER(LayerIdx));
  841. /* Process locked */
  842. __HAL_LOCK(hltdc);
  843. /* Change LTDC peripheral state */
  844. hltdc->State = HAL_LTDC_STATE_BUSY;
  845. /* Disable LTDC color keying by setting COLKEN bit */
  846. LTDC_LAYER(hltdc, LayerIdx)->CR &= ~(uint32_t)LTDC_LxCR_COLKEN;
  847. /* Set the Immediate Reload type */
  848. hltdc->Instance->SRCR = LTDC_SRCR_IMR;
  849. /* Change the LTDC state*/
  850. hltdc->State = HAL_LTDC_STATE_READY;
  851. /* Process unlocked */
  852. __HAL_UNLOCK(hltdc);
  853. return HAL_OK;
  854. }
  855. /**
  856. * @brief Enable the color lookup table.
  857. * @param hltdc pointer to a LTDC_HandleTypeDef structure that contains
  858. * the configuration information for the LTDC.
  859. * @param LayerIdx LTDC Layer index.
  860. * This parameter can be one of the following values:
  861. * LTDC_LAYER_1 (0) or LTDC_LAYER_2 (1)
  862. * @retval HAL status
  863. */
  864. HAL_StatusTypeDef HAL_LTDC_EnableCLUT(LTDC_HandleTypeDef *hltdc, uint32_t LayerIdx)
  865. {
  866. /* Check the parameters */
  867. assert_param(IS_LTDC_LAYER(LayerIdx));
  868. /* Process locked */
  869. __HAL_LOCK(hltdc);
  870. /* Change LTDC peripheral state */
  871. hltdc->State = HAL_LTDC_STATE_BUSY;
  872. /* Enable LTDC color lookup table by setting CLUTEN bit */
  873. LTDC_LAYER(hltdc, LayerIdx)->CR |= (uint32_t)LTDC_LxCR_CLUTEN;
  874. /* Set the Immediate Reload type */
  875. hltdc->Instance->SRCR = LTDC_SRCR_IMR;
  876. /* Change the LTDC state*/
  877. hltdc->State = HAL_LTDC_STATE_READY;
  878. /* Process unlocked */
  879. __HAL_UNLOCK(hltdc);
  880. return HAL_OK;
  881. }
  882. /**
  883. * @brief Disable the color lookup table.
  884. * @param hltdc pointer to a LTDC_HandleTypeDef structure that contains
  885. * the configuration information for the LTDC.
  886. * @param LayerIdx LTDC Layer index.
  887. * This parameter can be one of the following values:
  888. * LTDC_LAYER_1 (0) or LTDC_LAYER_2 (1)
  889. * @retval HAL status
  890. */
  891. HAL_StatusTypeDef HAL_LTDC_DisableCLUT(LTDC_HandleTypeDef *hltdc, uint32_t LayerIdx)
  892. {
  893. /* Check the parameters */
  894. assert_param(IS_LTDC_LAYER(LayerIdx));
  895. /* Process locked */
  896. __HAL_LOCK(hltdc);
  897. /* Change LTDC peripheral state */
  898. hltdc->State = HAL_LTDC_STATE_BUSY;
  899. /* Disable LTDC color lookup table by setting CLUTEN bit */
  900. LTDC_LAYER(hltdc, LayerIdx)->CR &= ~(uint32_t)LTDC_LxCR_CLUTEN;
  901. /* Set the Immediate Reload type */
  902. hltdc->Instance->SRCR = LTDC_SRCR_IMR;
  903. /* Change the LTDC state*/
  904. hltdc->State = HAL_LTDC_STATE_READY;
  905. /* Process unlocked */
  906. __HAL_UNLOCK(hltdc);
  907. return HAL_OK;
  908. }
  909. /**
  910. * @brief Enable Dither.
  911. * @param hltdc pointer to a LTDC_HandleTypeDef structure that contains
  912. * the configuration information for the LTDC.
  913. * @retval HAL status
  914. */
  915. HAL_StatusTypeDef HAL_LTDC_EnableDither(LTDC_HandleTypeDef *hltdc)
  916. {
  917. /* Process locked */
  918. __HAL_LOCK(hltdc);
  919. /* Change LTDC peripheral state */
  920. hltdc->State = HAL_LTDC_STATE_BUSY;
  921. /* Enable Dither by setting DTEN bit */
  922. LTDC->GCR |= (uint32_t)LTDC_GCR_DEN;
  923. /* Change the LTDC state*/
  924. hltdc->State = HAL_LTDC_STATE_READY;
  925. /* Process unlocked */
  926. __HAL_UNLOCK(hltdc);
  927. return HAL_OK;
  928. }
  929. /**
  930. * @brief Disable Dither.
  931. * @param hltdc pointer to a LTDC_HandleTypeDef structure that contains
  932. * the configuration information for the LTDC.
  933. * @retval HAL status
  934. */
  935. HAL_StatusTypeDef HAL_LTDC_DisableDither(LTDC_HandleTypeDef *hltdc)
  936. {
  937. /* Process locked */
  938. __HAL_LOCK(hltdc);
  939. /* Change LTDC peripheral state */
  940. hltdc->State = HAL_LTDC_STATE_BUSY;
  941. /* Disable Dither by setting DTEN bit */
  942. LTDC->GCR &= ~(uint32_t)LTDC_GCR_DEN;
  943. /* Change the LTDC state*/
  944. hltdc->State = HAL_LTDC_STATE_READY;
  945. /* Process unlocked */
  946. __HAL_UNLOCK(hltdc);
  947. return HAL_OK;
  948. }
  949. /**
  950. * @brief Set the LTDC window size.
  951. * @param hltdc pointer to a LTDC_HandleTypeDef structure that contains
  952. * the configuration information for the LTDC.
  953. * @param XSize LTDC Pixel per line
  954. * @param YSize LTDC Line number
  955. * @param LayerIdx LTDC Layer index.
  956. * This parameter can be one of the following values:
  957. * LTDC_LAYER_1 (0) or LTDC_LAYER_2 (1)
  958. * @retval HAL status
  959. */
  960. HAL_StatusTypeDef HAL_LTDC_SetWindowSize(LTDC_HandleTypeDef *hltdc, uint32_t XSize, uint32_t YSize, uint32_t LayerIdx)
  961. {
  962. LTDC_LayerCfgTypeDef *pLayerCfg;
  963. /* Check the parameters (Layers parameters)*/
  964. assert_param(IS_LTDC_LAYER(LayerIdx));
  965. assert_param(IS_LTDC_CFBLL(XSize));
  966. assert_param(IS_LTDC_CFBLNBR(YSize));
  967. /* Process locked */
  968. __HAL_LOCK(hltdc);
  969. /* Change LTDC peripheral state */
  970. hltdc->State = HAL_LTDC_STATE_BUSY;
  971. /* Get layer configuration from handle structure */
  972. pLayerCfg = &hltdc->LayerCfg[LayerIdx];
  973. /* update horizontal stop */
  974. pLayerCfg->WindowX1 = XSize + pLayerCfg->WindowX0;
  975. /* update vertical stop */
  976. pLayerCfg->WindowY1 = YSize + pLayerCfg->WindowY0;
  977. /* Reconfigures the color frame buffer pitch in byte */
  978. pLayerCfg->ImageWidth = XSize;
  979. /* Reconfigures the frame buffer line number */
  980. pLayerCfg->ImageHeight = YSize;
  981. /* Set LTDC parameters */
  982. LTDC_SetConfig(hltdc, pLayerCfg, LayerIdx);
  983. /* Set the Immediate Reload type */
  984. hltdc->Instance->SRCR = LTDC_SRCR_IMR;
  985. /* Change the LTDC state*/
  986. hltdc->State = HAL_LTDC_STATE_READY;
  987. /* Process unlocked */
  988. __HAL_UNLOCK(hltdc);
  989. return HAL_OK;
  990. }
  991. /**
  992. * @brief Set the LTDC window position.
  993. * @param hltdc pointer to a LTDC_HandleTypeDef structure that contains
  994. * the configuration information for the LTDC.
  995. * @param X0 LTDC window X offset
  996. * @param Y0 LTDC window Y offset
  997. * @param LayerIdx LTDC Layer index.
  998. * This parameter can be one of the following values:
  999. * LTDC_LAYER_1 (0) or LTDC_LAYER_2 (1)
  1000. * @retval HAL status
  1001. */
  1002. HAL_StatusTypeDef HAL_LTDC_SetWindowPosition(LTDC_HandleTypeDef *hltdc, uint32_t X0, uint32_t Y0, uint32_t LayerIdx)
  1003. {
  1004. LTDC_LayerCfgTypeDef *pLayerCfg;
  1005. /* Check the parameters */
  1006. assert_param(IS_LTDC_LAYER(LayerIdx));
  1007. assert_param(IS_LTDC_CFBLL(X0));
  1008. assert_param(IS_LTDC_CFBLNBR(Y0));
  1009. /* Process locked */
  1010. __HAL_LOCK(hltdc);
  1011. /* Change LTDC peripheral state */
  1012. hltdc->State = HAL_LTDC_STATE_BUSY;
  1013. /* Get layer configuration from handle structure */
  1014. pLayerCfg = &hltdc->LayerCfg[LayerIdx];
  1015. /* update horizontal start/stop */
  1016. pLayerCfg->WindowX0 = X0;
  1017. pLayerCfg->WindowX1 = X0 + pLayerCfg->ImageWidth;
  1018. /* update vertical start/stop */
  1019. pLayerCfg->WindowY0 = Y0;
  1020. pLayerCfg->WindowY1 = Y0 + pLayerCfg->ImageHeight;
  1021. /* Set LTDC parameters */
  1022. LTDC_SetConfig(hltdc, pLayerCfg, LayerIdx);
  1023. /* Set the Immediate Reload type */
  1024. hltdc->Instance->SRCR = LTDC_SRCR_IMR;
  1025. /* Change the LTDC state*/
  1026. hltdc->State = HAL_LTDC_STATE_READY;
  1027. /* Process unlocked */
  1028. __HAL_UNLOCK(hltdc);
  1029. return HAL_OK;
  1030. }
  1031. /**
  1032. * @brief Reconfigure the pixel format.
  1033. * @param hltdc pointer to a LTDC_HandleTypeDef structure that contains
  1034. * the configuration information for the LTDC.
  1035. * @param Pixelformat new pixel format value.
  1036. * @param LayerIdx LTDC Layer index.
  1037. * This parameter can be one of the following values:
  1038. * LTDC_LAYER_1 (0) or LTDC_LAYER_2 (1).
  1039. * @retval HAL status
  1040. */
  1041. HAL_StatusTypeDef HAL_LTDC_SetPixelFormat(LTDC_HandleTypeDef *hltdc, uint32_t Pixelformat, uint32_t LayerIdx)
  1042. {
  1043. LTDC_LayerCfgTypeDef *pLayerCfg;
  1044. /* Check the parameters */
  1045. assert_param(IS_LTDC_PIXEL_FORMAT(Pixelformat));
  1046. assert_param(IS_LTDC_LAYER(LayerIdx));
  1047. /* Process locked */
  1048. __HAL_LOCK(hltdc);
  1049. /* Change LTDC peripheral state */
  1050. hltdc->State = HAL_LTDC_STATE_BUSY;
  1051. /* Get layer configuration from handle structure */
  1052. pLayerCfg = &hltdc->LayerCfg[LayerIdx];
  1053. /* Reconfigure the pixel format */
  1054. pLayerCfg->PixelFormat = Pixelformat;
  1055. /* Set LTDC parameters */
  1056. LTDC_SetConfig(hltdc, pLayerCfg, LayerIdx);
  1057. /* Set the Immediate Reload type */
  1058. hltdc->Instance->SRCR = LTDC_SRCR_IMR;
  1059. /* Change the LTDC state*/
  1060. hltdc->State = HAL_LTDC_STATE_READY;
  1061. /* Process unlocked */
  1062. __HAL_UNLOCK(hltdc);
  1063. return HAL_OK;
  1064. }
  1065. /**
  1066. * @brief Reconfigure the layer alpha value.
  1067. * @param hltdc pointer to a LTDC_HandleTypeDef structure that contains
  1068. * the configuration information for the LTDC.
  1069. * @param Alpha new alpha value.
  1070. * @param LayerIdx LTDC Layer index.
  1071. * This parameter can be one of the following values:
  1072. * LTDC_LAYER_1 (0) or LTDC_LAYER_2 (1)
  1073. * @retval HAL status
  1074. */
  1075. HAL_StatusTypeDef HAL_LTDC_SetAlpha(LTDC_HandleTypeDef *hltdc, uint32_t Alpha, uint32_t LayerIdx)
  1076. {
  1077. LTDC_LayerCfgTypeDef *pLayerCfg;
  1078. /* Check the parameters */
  1079. assert_param(IS_LTDC_ALPHA(Alpha));
  1080. assert_param(IS_LTDC_LAYER(LayerIdx));
  1081. /* Process locked */
  1082. __HAL_LOCK(hltdc);
  1083. /* Change LTDC peripheral state */
  1084. hltdc->State = HAL_LTDC_STATE_BUSY;
  1085. /* Get layer configuration from handle structure */
  1086. pLayerCfg = &hltdc->LayerCfg[LayerIdx];
  1087. /* Reconfigure the Alpha value */
  1088. pLayerCfg->Alpha = Alpha;
  1089. /* Set LTDC parameters */
  1090. LTDC_SetConfig(hltdc, pLayerCfg, LayerIdx);
  1091. /* Set the Immediate Reload type */
  1092. hltdc->Instance->SRCR = LTDC_SRCR_IMR;
  1093. /* Change the LTDC state*/
  1094. hltdc->State = HAL_LTDC_STATE_READY;
  1095. /* Process unlocked */
  1096. __HAL_UNLOCK(hltdc);
  1097. return HAL_OK;
  1098. }
  1099. /**
  1100. * @brief Reconfigure the frame buffer Address.
  1101. * @param hltdc pointer to a LTDC_HandleTypeDef structure that contains
  1102. * the configuration information for the LTDC.
  1103. * @param Address new address value.
  1104. * @param LayerIdx LTDC Layer index.
  1105. * This parameter can be one of the following values:
  1106. * LTDC_LAYER_1 (0) or LTDC_LAYER_2 (1).
  1107. * @retval HAL status
  1108. */
  1109. HAL_StatusTypeDef HAL_LTDC_SetAddress(LTDC_HandleTypeDef *hltdc, uint32_t Address, uint32_t LayerIdx)
  1110. {
  1111. LTDC_LayerCfgTypeDef *pLayerCfg;
  1112. /* Check the parameters */
  1113. assert_param(IS_LTDC_LAYER(LayerIdx));
  1114. /* Process locked */
  1115. __HAL_LOCK(hltdc);
  1116. /* Change LTDC peripheral state */
  1117. hltdc->State = HAL_LTDC_STATE_BUSY;
  1118. /* Get layer configuration from handle structure */
  1119. pLayerCfg = &hltdc->LayerCfg[LayerIdx];
  1120. /* Reconfigure the Address */
  1121. pLayerCfg->FBStartAdress = Address;
  1122. /* Set LTDC parameters */
  1123. LTDC_SetConfig(hltdc, pLayerCfg, LayerIdx);
  1124. /* Set the Immediate Reload type */
  1125. hltdc->Instance->SRCR = LTDC_SRCR_IMR;
  1126. /* Change the LTDC state*/
  1127. hltdc->State = HAL_LTDC_STATE_READY;
  1128. /* Process unlocked */
  1129. __HAL_UNLOCK(hltdc);
  1130. return HAL_OK;
  1131. }
  1132. /**
  1133. * @brief Function used to reconfigure the pitch for specific cases where the attached LayerIdx buffer have a width
  1134. * that is larger than the one intended to be displayed on screen. Example of a buffer 800x480 attached to
  1135. * layer for which we want to read and display on screen only a portion 320x240 taken in the center
  1136. * of the buffer.
  1137. * The pitch in pixels will be in that case 800 pixels and not 320 pixels as initially configured by previous
  1138. * call to HAL_LTDC_ConfigLayer().
  1139. * @note This function should be called only after a previous call to HAL_LTDC_ConfigLayer() to modify the default
  1140. * pitch configured by HAL_LTDC_ConfigLayer() when required (refer to example described just above).
  1141. * @param hltdc pointer to a LTDC_HandleTypeDef structure that contains
  1142. * the configuration information for the LTDC.
  1143. * @param LinePitchInPixels New line pitch in pixels to configure for LTDC layer 'LayerIdx'.
  1144. * @param LayerIdx LTDC layer index concerned by the modification of line pitch.
  1145. * @retval HAL status
  1146. */
  1147. HAL_StatusTypeDef HAL_LTDC_SetPitch(LTDC_HandleTypeDef *hltdc, uint32_t LinePitchInPixels, uint32_t LayerIdx)
  1148. {
  1149. uint32_t tmp;
  1150. uint32_t pitchUpdate;
  1151. uint32_t pixelFormat;
  1152. /* Check the parameters */
  1153. assert_param(IS_LTDC_LAYER(LayerIdx));
  1154. /* Process locked */
  1155. __HAL_LOCK(hltdc);
  1156. /* Change LTDC peripheral state */
  1157. hltdc->State = HAL_LTDC_STATE_BUSY;
  1158. /* get LayerIdx used pixel format */
  1159. pixelFormat = hltdc->LayerCfg[LayerIdx].PixelFormat;
  1160. if (pixelFormat == LTDC_PIXEL_FORMAT_ARGB8888)
  1161. {
  1162. tmp = 4U;
  1163. }
  1164. else if (pixelFormat == LTDC_PIXEL_FORMAT_RGB888)
  1165. {
  1166. tmp = 3U;
  1167. }
  1168. else if ((pixelFormat == LTDC_PIXEL_FORMAT_ARGB4444) || \
  1169. (pixelFormat == LTDC_PIXEL_FORMAT_RGB565) || \
  1170. (pixelFormat == LTDC_PIXEL_FORMAT_ARGB1555) || \
  1171. (pixelFormat == LTDC_PIXEL_FORMAT_AL88))
  1172. {
  1173. tmp = 2U;
  1174. }
  1175. else
  1176. {
  1177. tmp = 1U;
  1178. }
  1179. pitchUpdate = ((LinePitchInPixels * tmp) << 16U);
  1180. /* Clear previously set standard pitch */
  1181. LTDC_LAYER(hltdc, LayerIdx)->CFBLR &= ~LTDC_LxCFBLR_CFBP;
  1182. /* Set the Reload type as immediate update of LTDC pitch configured above */
  1183. LTDC->SRCR |= LTDC_SRCR_IMR;
  1184. /* Set new line pitch value */
  1185. LTDC_LAYER(hltdc, LayerIdx)->CFBLR |= pitchUpdate;
  1186. /* Set the Reload type as immediate update of LTDC pitch configured above */
  1187. LTDC->SRCR |= LTDC_SRCR_IMR;
  1188. /* Change the LTDC state*/
  1189. hltdc->State = HAL_LTDC_STATE_READY;
  1190. /* Process unlocked */
  1191. __HAL_UNLOCK(hltdc);
  1192. return HAL_OK;
  1193. }
  1194. /**
  1195. * @brief Define the position of the line interrupt.
  1196. * @param hltdc pointer to a LTDC_HandleTypeDef structure that contains
  1197. * the configuration information for the LTDC.
  1198. * @param Line Line Interrupt Position.
  1199. * @note User application may resort to HAL_LTDC_LineEventCallback() at line interrupt generation.
  1200. * @retval HAL status
  1201. */
  1202. HAL_StatusTypeDef HAL_LTDC_ProgramLineEvent(LTDC_HandleTypeDef *hltdc, uint32_t Line)
  1203. {
  1204. /* Check the parameters */
  1205. assert_param(IS_LTDC_LIPOS(Line));
  1206. /* Process locked */
  1207. __HAL_LOCK(hltdc);
  1208. /* Change LTDC peripheral state */
  1209. hltdc->State = HAL_LTDC_STATE_BUSY;
  1210. /* Disable the Line interrupt */
  1211. __HAL_LTDC_DISABLE_IT(hltdc, LTDC_IT_LI);
  1212. /* Set the Line Interrupt position */
  1213. LTDC->LIPCR = (uint32_t)Line;
  1214. /* Enable the Line interrupt */
  1215. __HAL_LTDC_ENABLE_IT(hltdc, LTDC_IT_LI);
  1216. /* Change the LTDC state*/
  1217. hltdc->State = HAL_LTDC_STATE_READY;
  1218. /* Process unlocked */
  1219. __HAL_UNLOCK(hltdc);
  1220. return HAL_OK;
  1221. }
  1222. /**
  1223. * @brief Reload LTDC Layers configuration.
  1224. * @param hltdc pointer to a LTDC_HandleTypeDef structure that contains
  1225. * the configuration information for the LTDC.
  1226. * @param ReloadType This parameter can be one of the following values :
  1227. * LTDC_RELOAD_IMMEDIATE : Immediate Reload
  1228. * LTDC_RELOAD_VERTICAL_BLANKING : Reload in the next Vertical Blanking
  1229. * @note User application may resort to HAL_LTDC_ReloadEventCallback() at reload interrupt generation.
  1230. * @retval HAL status
  1231. */
  1232. HAL_StatusTypeDef HAL_LTDC_Reload(LTDC_HandleTypeDef *hltdc, uint32_t ReloadType)
  1233. {
  1234. /* Check the parameters */
  1235. assert_param(IS_LTDC_RELOAD(ReloadType));
  1236. /* Process locked */
  1237. __HAL_LOCK(hltdc);
  1238. /* Change LTDC peripheral state */
  1239. hltdc->State = HAL_LTDC_STATE_BUSY;
  1240. /* Enable the Reload interrupt */
  1241. __HAL_LTDC_ENABLE_IT(hltdc, LTDC_IT_RR);
  1242. /* Apply Reload type */
  1243. hltdc->Instance->SRCR = ReloadType;
  1244. /* Change the LTDC state*/
  1245. hltdc->State = HAL_LTDC_STATE_READY;
  1246. /* Process unlocked */
  1247. __HAL_UNLOCK(hltdc);
  1248. return HAL_OK;
  1249. }
  1250. /**
  1251. * @brief Configure the LTDC Layer according to the specified without reloading
  1252. * parameters in the LTDC_InitTypeDef and create the associated handle.
  1253. * Variant of the function HAL_LTDC_ConfigLayer without immediate reload.
  1254. * @param hltdc pointer to a LTDC_HandleTypeDef structure that contains
  1255. * the configuration information for the LTDC.
  1256. * @param pLayerCfg pointer to a LTDC_LayerCfgTypeDef structure that contains
  1257. * the configuration information for the Layer.
  1258. * @param LayerIdx LTDC Layer index.
  1259. * This parameter can be one of the following values:
  1260. * LTDC_LAYER_1 (0) or LTDC_LAYER_2 (1)
  1261. * @retval HAL status
  1262. */
  1263. HAL_StatusTypeDef HAL_LTDC_ConfigLayer_NoReload(LTDC_HandleTypeDef *hltdc, LTDC_LayerCfgTypeDef *pLayerCfg,
  1264. uint32_t LayerIdx)
  1265. {
  1266. /* Check the parameters */
  1267. assert_param(IS_LTDC_LAYER(LayerIdx));
  1268. assert_param(IS_LTDC_HCONFIGST(pLayerCfg->WindowX0));
  1269. assert_param(IS_LTDC_HCONFIGSP(pLayerCfg->WindowX1));
  1270. assert_param(IS_LTDC_VCONFIGST(pLayerCfg->WindowY0));
  1271. assert_param(IS_LTDC_VCONFIGSP(pLayerCfg->WindowY1));
  1272. assert_param(IS_LTDC_PIXEL_FORMAT(pLayerCfg->PixelFormat));
  1273. assert_param(IS_LTDC_ALPHA(pLayerCfg->Alpha));
  1274. assert_param(IS_LTDC_ALPHA(pLayerCfg->Alpha0));
  1275. assert_param(IS_LTDC_BLENDING_FACTOR1(pLayerCfg->BlendingFactor1));
  1276. assert_param(IS_LTDC_BLENDING_FACTOR2(pLayerCfg->BlendingFactor2));
  1277. assert_param(IS_LTDC_CFBLL(pLayerCfg->ImageWidth));
  1278. assert_param(IS_LTDC_CFBLNBR(pLayerCfg->ImageHeight));
  1279. /* Process locked */
  1280. __HAL_LOCK(hltdc);
  1281. /* Change LTDC peripheral state */
  1282. hltdc->State = HAL_LTDC_STATE_BUSY;
  1283. /* Copy new layer configuration into handle structure */
  1284. hltdc->LayerCfg[LayerIdx] = *pLayerCfg;
  1285. /* Configure the LTDC Layer */
  1286. LTDC_SetConfig(hltdc, pLayerCfg, LayerIdx);
  1287. /* Initialize the LTDC state*/
  1288. hltdc->State = HAL_LTDC_STATE_READY;
  1289. /* Process unlocked */
  1290. __HAL_UNLOCK(hltdc);
  1291. return HAL_OK;
  1292. }
  1293. /**
  1294. * @brief Set the LTDC window size without reloading.
  1295. * Variant of the function HAL_LTDC_SetWindowSize without immediate reload.
  1296. * @param hltdc pointer to a LTDC_HandleTypeDef structure that contains
  1297. * the configuration information for the LTDC.
  1298. * @param XSize LTDC Pixel per line
  1299. * @param YSize LTDC Line number
  1300. * @param LayerIdx LTDC Layer index.
  1301. * This parameter can be one of the following values:
  1302. * LTDC_LAYER_1 (0) or LTDC_LAYER_2 (1)
  1303. * @retval HAL status
  1304. */
  1305. HAL_StatusTypeDef HAL_LTDC_SetWindowSize_NoReload(LTDC_HandleTypeDef *hltdc, uint32_t XSize, uint32_t YSize,
  1306. uint32_t LayerIdx)
  1307. {
  1308. LTDC_LayerCfgTypeDef *pLayerCfg;
  1309. /* Check the parameters (Layers parameters)*/
  1310. assert_param(IS_LTDC_LAYER(LayerIdx));
  1311. assert_param(IS_LTDC_CFBLL(XSize));
  1312. assert_param(IS_LTDC_CFBLNBR(YSize));
  1313. /* Process locked */
  1314. __HAL_LOCK(hltdc);
  1315. /* Change LTDC peripheral state */
  1316. hltdc->State = HAL_LTDC_STATE_BUSY;
  1317. /* Get layer configuration from handle structure */
  1318. pLayerCfg = &hltdc->LayerCfg[LayerIdx];
  1319. /* update horizontal stop */
  1320. pLayerCfg->WindowX1 = XSize + pLayerCfg->WindowX0;
  1321. /* update vertical stop */
  1322. pLayerCfg->WindowY1 = YSize + pLayerCfg->WindowY0;
  1323. /* Reconfigures the color frame buffer pitch in byte */
  1324. pLayerCfg->ImageWidth = XSize;
  1325. /* Reconfigures the frame buffer line number */
  1326. pLayerCfg->ImageHeight = YSize;
  1327. /* Set LTDC parameters */
  1328. LTDC_SetConfig(hltdc, pLayerCfg, LayerIdx);
  1329. /* Change the LTDC state*/
  1330. hltdc->State = HAL_LTDC_STATE_READY;
  1331. /* Process unlocked */
  1332. __HAL_UNLOCK(hltdc);
  1333. return HAL_OK;
  1334. }
  1335. /**
  1336. * @brief Set the LTDC window position without reloading.
  1337. * Variant of the function HAL_LTDC_SetWindowPosition without immediate reload.
  1338. * @param hltdc pointer to a LTDC_HandleTypeDef structure that contains
  1339. * the configuration information for the LTDC.
  1340. * @param X0 LTDC window X offset
  1341. * @param Y0 LTDC window Y offset
  1342. * @param LayerIdx LTDC Layer index.
  1343. * This parameter can be one of the following values:
  1344. * LTDC_LAYER_1 (0) or LTDC_LAYER_2 (1)
  1345. * @retval HAL status
  1346. */
  1347. HAL_StatusTypeDef HAL_LTDC_SetWindowPosition_NoReload(LTDC_HandleTypeDef *hltdc, uint32_t X0, uint32_t Y0,
  1348. uint32_t LayerIdx)
  1349. {
  1350. LTDC_LayerCfgTypeDef *pLayerCfg;
  1351. /* Check the parameters */
  1352. assert_param(IS_LTDC_LAYER(LayerIdx));
  1353. assert_param(IS_LTDC_CFBLL(X0));
  1354. assert_param(IS_LTDC_CFBLNBR(Y0));
  1355. /* Process locked */
  1356. __HAL_LOCK(hltdc);
  1357. /* Change LTDC peripheral state */
  1358. hltdc->State = HAL_LTDC_STATE_BUSY;
  1359. /* Get layer configuration from handle structure */
  1360. pLayerCfg = &hltdc->LayerCfg[LayerIdx];
  1361. /* update horizontal start/stop */
  1362. pLayerCfg->WindowX0 = X0;
  1363. pLayerCfg->WindowX1 = X0 + pLayerCfg->ImageWidth;
  1364. /* update vertical start/stop */
  1365. pLayerCfg->WindowY0 = Y0;
  1366. pLayerCfg->WindowY1 = Y0 + pLayerCfg->ImageHeight;
  1367. /* Set LTDC parameters */
  1368. LTDC_SetConfig(hltdc, pLayerCfg, LayerIdx);
  1369. /* Change the LTDC state*/
  1370. hltdc->State = HAL_LTDC_STATE_READY;
  1371. /* Process unlocked */
  1372. __HAL_UNLOCK(hltdc);
  1373. return HAL_OK;
  1374. }
  1375. /**
  1376. * @brief Reconfigure the pixel format without reloading.
  1377. * Variant of the function HAL_LTDC_SetPixelFormat without immediate reload.
  1378. * @param hltdc pointer to a LTDC_HandleTypeDfef structure that contains
  1379. * the configuration information for the LTDC.
  1380. * @param Pixelformat new pixel format value.
  1381. * @param LayerIdx LTDC Layer index.
  1382. * This parameter can be one of the following values:
  1383. * LTDC_LAYER_1 (0) or LTDC_LAYER_2 (1).
  1384. * @retval HAL status
  1385. */
  1386. HAL_StatusTypeDef HAL_LTDC_SetPixelFormat_NoReload(LTDC_HandleTypeDef *hltdc, uint32_t Pixelformat, uint32_t LayerIdx)
  1387. {
  1388. LTDC_LayerCfgTypeDef *pLayerCfg;
  1389. /* Check the parameters */
  1390. assert_param(IS_LTDC_PIXEL_FORMAT(Pixelformat));
  1391. assert_param(IS_LTDC_LAYER(LayerIdx));
  1392. /* Process locked */
  1393. __HAL_LOCK(hltdc);
  1394. /* Change LTDC peripheral state */
  1395. hltdc->State = HAL_LTDC_STATE_BUSY;
  1396. /* Get layer configuration from handle structure */
  1397. pLayerCfg = &hltdc->LayerCfg[LayerIdx];
  1398. /* Reconfigure the pixel format */
  1399. pLayerCfg->PixelFormat = Pixelformat;
  1400. /* Set LTDC parameters */
  1401. LTDC_SetConfig(hltdc, pLayerCfg, LayerIdx);
  1402. /* Change the LTDC state*/
  1403. hltdc->State = HAL_LTDC_STATE_READY;
  1404. /* Process unlocked */
  1405. __HAL_UNLOCK(hltdc);
  1406. return HAL_OK;
  1407. }
  1408. /**
  1409. * @brief Reconfigure the layer alpha value without reloading.
  1410. * Variant of the function HAL_LTDC_SetAlpha without immediate reload.
  1411. * @param hltdc pointer to a LTDC_HandleTypeDef structure that contains
  1412. * the configuration information for the LTDC.
  1413. * @param Alpha new alpha value.
  1414. * @param LayerIdx LTDC Layer index.
  1415. * This parameter can be one of the following values:
  1416. * LTDC_LAYER_1 (0) or LTDC_LAYER_2 (1)
  1417. * @retval HAL status
  1418. */
  1419. HAL_StatusTypeDef HAL_LTDC_SetAlpha_NoReload(LTDC_HandleTypeDef *hltdc, uint32_t Alpha, uint32_t LayerIdx)
  1420. {
  1421. LTDC_LayerCfgTypeDef *pLayerCfg;
  1422. /* Check the parameters */
  1423. assert_param(IS_LTDC_ALPHA(Alpha));
  1424. assert_param(IS_LTDC_LAYER(LayerIdx));
  1425. /* Process locked */
  1426. __HAL_LOCK(hltdc);
  1427. /* Change LTDC peripheral state */
  1428. hltdc->State = HAL_LTDC_STATE_BUSY;
  1429. /* Get layer configuration from handle structure */
  1430. pLayerCfg = &hltdc->LayerCfg[LayerIdx];
  1431. /* Reconfigure the Alpha value */
  1432. pLayerCfg->Alpha = Alpha;
  1433. /* Set LTDC parameters */
  1434. LTDC_SetConfig(hltdc, pLayerCfg, LayerIdx);
  1435. /* Change the LTDC state*/
  1436. hltdc->State = HAL_LTDC_STATE_READY;
  1437. /* Process unlocked */
  1438. __HAL_UNLOCK(hltdc);
  1439. return HAL_OK;
  1440. }
  1441. /**
  1442. * @brief Reconfigure the frame buffer Address without reloading.
  1443. * Variant of the function HAL_LTDC_SetAddress without immediate reload.
  1444. * @param hltdc pointer to a LTDC_HandleTypeDef structure that contains
  1445. * the configuration information for the LTDC.
  1446. * @param Address new address value.
  1447. * @param LayerIdx LTDC Layer index.
  1448. * This parameter can be one of the following values:
  1449. * LTDC_LAYER_1 (0) or LTDC_LAYER_2 (1).
  1450. * @retval HAL status
  1451. */
  1452. HAL_StatusTypeDef HAL_LTDC_SetAddress_NoReload(LTDC_HandleTypeDef *hltdc, uint32_t Address, uint32_t LayerIdx)
  1453. {
  1454. LTDC_LayerCfgTypeDef *pLayerCfg;
  1455. /* Check the parameters */
  1456. assert_param(IS_LTDC_LAYER(LayerIdx));
  1457. /* Process locked */
  1458. __HAL_LOCK(hltdc);
  1459. /* Change LTDC peripheral state */
  1460. hltdc->State = HAL_LTDC_STATE_BUSY;
  1461. /* Get layer configuration from handle structure */
  1462. pLayerCfg = &hltdc->LayerCfg[LayerIdx];
  1463. /* Reconfigure the Address */
  1464. pLayerCfg->FBStartAdress = Address;
  1465. /* Set LTDC parameters */
  1466. LTDC_SetConfig(hltdc, pLayerCfg, LayerIdx);
  1467. /* Change the LTDC state*/
  1468. hltdc->State = HAL_LTDC_STATE_READY;
  1469. /* Process unlocked */
  1470. __HAL_UNLOCK(hltdc);
  1471. return HAL_OK;
  1472. }
  1473. /**
  1474. * @brief Function used to reconfigure the pitch for specific cases where the attached LayerIdx buffer have a width
  1475. * that is larger than the one intended to be displayed on screen. Example of a buffer 800x480 attached to
  1476. * layer for which we want to read and display on screen only a portion 320x240 taken in the center
  1477. * of the buffer.
  1478. * The pitch in pixels will be in that case 800 pixels and not 320 pixels as initially configured by
  1479. * previous call to HAL_LTDC_ConfigLayer().
  1480. * @note This function should be called only after a previous call to HAL_LTDC_ConfigLayer() to modify the default
  1481. * pitch configured by HAL_LTDC_ConfigLayer() when required (refer to example described just above).
  1482. * Variant of the function HAL_LTDC_SetPitch without immediate reload.
  1483. * @param hltdc pointer to a LTDC_HandleTypeDef structure that contains
  1484. * the configuration information for the LTDC.
  1485. * @param LinePitchInPixels New line pitch in pixels to configure for LTDC layer 'LayerIdx'.
  1486. * @param LayerIdx LTDC layer index concerned by the modification of line pitch.
  1487. * @retval HAL status
  1488. */
  1489. HAL_StatusTypeDef HAL_LTDC_SetPitch_NoReload(LTDC_HandleTypeDef *hltdc, uint32_t LinePitchInPixels, uint32_t LayerIdx)
  1490. {
  1491. uint32_t tmp;
  1492. uint32_t pitchUpdate;
  1493. uint32_t pixelFormat;
  1494. /* Check the parameters */
  1495. assert_param(IS_LTDC_LAYER(LayerIdx));
  1496. /* Process locked */
  1497. __HAL_LOCK(hltdc);
  1498. /* Change LTDC peripheral state */
  1499. hltdc->State = HAL_LTDC_STATE_BUSY;
  1500. /* get LayerIdx used pixel format */
  1501. pixelFormat = hltdc->LayerCfg[LayerIdx].PixelFormat;
  1502. if (pixelFormat == LTDC_PIXEL_FORMAT_ARGB8888)
  1503. {
  1504. tmp = 4U;
  1505. }
  1506. else if (pixelFormat == LTDC_PIXEL_FORMAT_RGB888)
  1507. {
  1508. tmp = 3U;
  1509. }
  1510. else if ((pixelFormat == LTDC_PIXEL_FORMAT_ARGB4444) || \
  1511. (pixelFormat == LTDC_PIXEL_FORMAT_RGB565) || \
  1512. (pixelFormat == LTDC_PIXEL_FORMAT_ARGB1555) || \
  1513. (pixelFormat == LTDC_PIXEL_FORMAT_AL88))
  1514. {
  1515. tmp = 2U;
  1516. }
  1517. else
  1518. {
  1519. tmp = 1U;
  1520. }
  1521. pitchUpdate = ((LinePitchInPixels * tmp) << 16U);
  1522. /* Clear previously set standard pitch */
  1523. LTDC_LAYER(hltdc, LayerIdx)->CFBLR &= ~LTDC_LxCFBLR_CFBP;
  1524. /* Set new line pitch value */
  1525. LTDC_LAYER(hltdc, LayerIdx)->CFBLR |= pitchUpdate;
  1526. /* Change the LTDC state*/
  1527. hltdc->State = HAL_LTDC_STATE_READY;
  1528. /* Process unlocked */
  1529. __HAL_UNLOCK(hltdc);
  1530. return HAL_OK;
  1531. }
  1532. /**
  1533. * @brief Configure the color keying without reloading.
  1534. * Variant of the function HAL_LTDC_ConfigColorKeying without immediate reload.
  1535. * @param hltdc pointer to a LTDC_HandleTypeDef structure that contains
  1536. * the configuration information for the LTDC.
  1537. * @param RGBValue the color key value
  1538. * @param LayerIdx LTDC Layer index.
  1539. * This parameter can be one of the following values:
  1540. * LTDC_LAYER_1 (0) or LTDC_LAYER_2 (1)
  1541. * @retval HAL status
  1542. */
  1543. HAL_StatusTypeDef HAL_LTDC_ConfigColorKeying_NoReload(LTDC_HandleTypeDef *hltdc, uint32_t RGBValue, uint32_t LayerIdx)
  1544. {
  1545. /* Check the parameters */
  1546. assert_param(IS_LTDC_LAYER(LayerIdx));
  1547. /* Process locked */
  1548. __HAL_LOCK(hltdc);
  1549. /* Change LTDC peripheral state */
  1550. hltdc->State = HAL_LTDC_STATE_BUSY;
  1551. /* Configure the default color values */
  1552. LTDC_LAYER(hltdc, LayerIdx)->CKCR &= ~(LTDC_LxCKCR_CKBLUE | LTDC_LxCKCR_CKGREEN | LTDC_LxCKCR_CKRED);
  1553. LTDC_LAYER(hltdc, LayerIdx)->CKCR = RGBValue;
  1554. /* Change the LTDC state*/
  1555. hltdc->State = HAL_LTDC_STATE_READY;
  1556. /* Process unlocked */
  1557. __HAL_UNLOCK(hltdc);
  1558. return HAL_OK;
  1559. }
  1560. /**
  1561. * @brief Enable the color keying without reloading.
  1562. * Variant of the function HAL_LTDC_EnableColorKeying without immediate reload.
  1563. * @param hltdc pointer to a LTDC_HandleTypeDef structure that contains
  1564. * the configuration information for the LTDC.
  1565. * @param LayerIdx LTDC Layer index.
  1566. * This parameter can be one of the following values:
  1567. * LTDC_LAYER_1 (0) or LTDC_LAYER_2 (1)
  1568. * @retval HAL status
  1569. */
  1570. HAL_StatusTypeDef HAL_LTDC_EnableColorKeying_NoReload(LTDC_HandleTypeDef *hltdc, uint32_t LayerIdx)
  1571. {
  1572. /* Check the parameters */
  1573. assert_param(IS_LTDC_LAYER(LayerIdx));
  1574. /* Process locked */
  1575. __HAL_LOCK(hltdc);
  1576. /* Change LTDC peripheral state */
  1577. hltdc->State = HAL_LTDC_STATE_BUSY;
  1578. /* Enable LTDC color keying by setting COLKEN bit */
  1579. LTDC_LAYER(hltdc, LayerIdx)->CR |= (uint32_t)LTDC_LxCR_COLKEN;
  1580. /* Change the LTDC state*/
  1581. hltdc->State = HAL_LTDC_STATE_READY;
  1582. /* Process unlocked */
  1583. __HAL_UNLOCK(hltdc);
  1584. return HAL_OK;
  1585. }
  1586. /**
  1587. * @brief Disable the color keying without reloading.
  1588. * Variant of the function HAL_LTDC_DisableColorKeying without immediate reload.
  1589. * @param hltdc pointer to a LTDC_HandleTypeDef structure that contains
  1590. * the configuration information for the LTDC.
  1591. * @param LayerIdx LTDC Layer index.
  1592. * This parameter can be one of the following values:
  1593. * LTDC_LAYER_1 (0) or LTDC_LAYER_2 (1)
  1594. * @retval HAL status
  1595. */
  1596. HAL_StatusTypeDef HAL_LTDC_DisableColorKeying_NoReload(LTDC_HandleTypeDef *hltdc, uint32_t LayerIdx)
  1597. {
  1598. /* Check the parameters */
  1599. assert_param(IS_LTDC_LAYER(LayerIdx));
  1600. /* Process locked */
  1601. __HAL_LOCK(hltdc);
  1602. /* Change LTDC peripheral state */
  1603. hltdc->State = HAL_LTDC_STATE_BUSY;
  1604. /* Disable LTDC color keying by setting COLKEN bit */
  1605. LTDC_LAYER(hltdc, LayerIdx)->CR &= ~(uint32_t)LTDC_LxCR_COLKEN;
  1606. /* Change the LTDC state*/
  1607. hltdc->State = HAL_LTDC_STATE_READY;
  1608. /* Process unlocked */
  1609. __HAL_UNLOCK(hltdc);
  1610. return HAL_OK;
  1611. }
  1612. /**
  1613. * @brief Enable the color lookup table without reloading.
  1614. * Variant of the function HAL_LTDC_EnableCLUT without immediate reload.
  1615. * @param hltdc pointer to a LTDC_HandleTypeDef structure that contains
  1616. * the configuration information for the LTDC.
  1617. * @param LayerIdx LTDC Layer index.
  1618. * This parameter can be one of the following values:
  1619. * LTDC_LAYER_1 (0) or LTDC_LAYER_2 (1)
  1620. * @retval HAL status
  1621. */
  1622. HAL_StatusTypeDef HAL_LTDC_EnableCLUT_NoReload(LTDC_HandleTypeDef *hltdc, uint32_t LayerIdx)
  1623. {
  1624. /* Check the parameters */
  1625. assert_param(IS_LTDC_LAYER(LayerIdx));
  1626. /* Process locked */
  1627. __HAL_LOCK(hltdc);
  1628. /* Change LTDC peripheral state */
  1629. hltdc->State = HAL_LTDC_STATE_BUSY;
  1630. /* Disable LTDC color lookup table by setting CLUTEN bit */
  1631. LTDC_LAYER(hltdc, LayerIdx)->CR |= (uint32_t)LTDC_LxCR_CLUTEN;
  1632. /* Change the LTDC state*/
  1633. hltdc->State = HAL_LTDC_STATE_READY;
  1634. /* Process unlocked */
  1635. __HAL_UNLOCK(hltdc);
  1636. return HAL_OK;
  1637. }
  1638. /**
  1639. * @brief Disable the color lookup table without reloading.
  1640. * Variant of the function HAL_LTDC_DisableCLUT without immediate reload.
  1641. * @param hltdc pointer to a LTDC_HandleTypeDef structure that contains
  1642. * the configuration information for the LTDC.
  1643. * @param LayerIdx LTDC Layer index.
  1644. * This parameter can be one of the following values:
  1645. * LTDC_LAYER_1 (0) or LTDC_LAYER_2 (1)
  1646. * @retval HAL status
  1647. */
  1648. HAL_StatusTypeDef HAL_LTDC_DisableCLUT_NoReload(LTDC_HandleTypeDef *hltdc, uint32_t LayerIdx)
  1649. {
  1650. /* Check the parameters */
  1651. assert_param(IS_LTDC_LAYER(LayerIdx));
  1652. /* Process locked */
  1653. __HAL_LOCK(hltdc);
  1654. /* Change LTDC peripheral state */
  1655. hltdc->State = HAL_LTDC_STATE_BUSY;
  1656. /* Disable LTDC color lookup table by setting CLUTEN bit */
  1657. LTDC_LAYER(hltdc, LayerIdx)->CR &= ~(uint32_t)LTDC_LxCR_CLUTEN;
  1658. /* Change the LTDC state*/
  1659. hltdc->State = HAL_LTDC_STATE_READY;
  1660. /* Process unlocked */
  1661. __HAL_UNLOCK(hltdc);
  1662. return HAL_OK;
  1663. }
  1664. /**
  1665. * @}
  1666. */
  1667. /** @defgroup LTDC_Exported_Functions_Group4 Peripheral State and Errors functions
  1668. * @brief Peripheral State and Errors functions
  1669. *
  1670. @verbatim
  1671. ===============================================================================
  1672. ##### Peripheral State and Errors functions #####
  1673. ===============================================================================
  1674. [..]
  1675. This subsection provides functions allowing to
  1676. (+) Check the LTDC handle state.
  1677. (+) Get the LTDC handle error code.
  1678. @endverbatim
  1679. * @{
  1680. */
  1681. /**
  1682. * @brief Return the LTDC handle state.
  1683. * @param hltdc pointer to a LTDC_HandleTypeDef structure that contains
  1684. * the configuration information for the LTDC.
  1685. * @retval HAL state
  1686. */
  1687. HAL_LTDC_StateTypeDef HAL_LTDC_GetState(const LTDC_HandleTypeDef *hltdc)
  1688. {
  1689. return hltdc->State;
  1690. }
  1691. /**
  1692. * @brief Return the LTDC handle error code.
  1693. * @param hltdc pointer to a LTDC_HandleTypeDef structure that contains
  1694. * the configuration information for the LTDC.
  1695. * @retval LTDC Error Code
  1696. */
  1697. uint32_t HAL_LTDC_GetError(const LTDC_HandleTypeDef *hltdc)
  1698. {
  1699. return hltdc->ErrorCode;
  1700. }
  1701. /**
  1702. * @}
  1703. */
  1704. /**
  1705. * @}
  1706. */
  1707. /** @defgroup LTDC_Private_Functions LTDC Private Functions
  1708. * @{
  1709. */
  1710. /**
  1711. * @brief Configure the LTDC peripheral
  1712. * @param hltdc Pointer to a LTDC_HandleTypeDef structure that contains
  1713. * the configuration information for the LTDC.
  1714. * @param pLayerCfg Pointer LTDC Layer Configuration structure
  1715. * @param LayerIdx LTDC Layer index.
  1716. * This parameter can be one of the following values: LTDC_LAYER_1 (0) or LTDC_LAYER_2 (1)
  1717. * @retval None
  1718. */
  1719. static void LTDC_SetConfig(LTDC_HandleTypeDef *hltdc, LTDC_LayerCfgTypeDef *pLayerCfg, uint32_t LayerIdx)
  1720. {
  1721. uint32_t tmp;
  1722. uint32_t tmp1;
  1723. uint32_t tmp2;
  1724. /* Configure the horizontal start and stop position */
  1725. tmp = ((pLayerCfg->WindowX1 + ((hltdc->Instance->BPCR & LTDC_BPCR_AHBP) >> 16U)) << 16U);
  1726. LTDC_LAYER(hltdc, LayerIdx)->WHPCR &= ~(LTDC_LxWHPCR_WHSTPOS | LTDC_LxWHPCR_WHSPPOS);
  1727. LTDC_LAYER(hltdc, LayerIdx)->WHPCR = ((pLayerCfg->WindowX0 + \
  1728. ((hltdc->Instance->BPCR & LTDC_BPCR_AHBP) >> 16U) + 1U) | tmp);
  1729. /* Configure the vertical start and stop position */
  1730. tmp = ((pLayerCfg->WindowY1 + (hltdc->Instance->BPCR & LTDC_BPCR_AVBP)) << 16U);
  1731. LTDC_LAYER(hltdc, LayerIdx)->WVPCR &= ~(LTDC_LxWVPCR_WVSTPOS | LTDC_LxWVPCR_WVSPPOS);
  1732. LTDC_LAYER(hltdc, LayerIdx)->WVPCR = ((pLayerCfg->WindowY0 + (hltdc->Instance->BPCR & LTDC_BPCR_AVBP) + 1U) | tmp);
  1733. /* Specifies the pixel format */
  1734. LTDC_LAYER(hltdc, LayerIdx)->PFCR &= ~(LTDC_LxPFCR_PF);
  1735. LTDC_LAYER(hltdc, LayerIdx)->PFCR = (pLayerCfg->PixelFormat);
  1736. /* Configure the default color values */
  1737. tmp = ((uint32_t)(pLayerCfg->Backcolor.Green) << 8U);
  1738. tmp1 = ((uint32_t)(pLayerCfg->Backcolor.Red) << 16U);
  1739. tmp2 = (pLayerCfg->Alpha0 << 24U);
  1740. WRITE_REG(LTDC_LAYER(hltdc, LayerIdx)->DCCR, (pLayerCfg->Backcolor.Blue | tmp | tmp1 | tmp2));
  1741. /* Specifies the constant alpha value */
  1742. LTDC_LAYER(hltdc, LayerIdx)->CACR &= ~(LTDC_LxCACR_CONSTA);
  1743. LTDC_LAYER(hltdc, LayerIdx)->CACR = (pLayerCfg->Alpha);
  1744. /* Specifies the blending factors */
  1745. LTDC_LAYER(hltdc, LayerIdx)->BFCR &= ~(LTDC_LxBFCR_BF2 | LTDC_LxBFCR_BF1);
  1746. LTDC_LAYER(hltdc, LayerIdx)->BFCR = (pLayerCfg->BlendingFactor1 | pLayerCfg->BlendingFactor2);
  1747. /* Configure the color frame buffer start address */
  1748. WRITE_REG(LTDC_LAYER(hltdc, LayerIdx)->CFBAR, pLayerCfg->FBStartAdress);
  1749. if (pLayerCfg->PixelFormat == LTDC_PIXEL_FORMAT_ARGB8888)
  1750. {
  1751. tmp = 4U;
  1752. }
  1753. else if (pLayerCfg->PixelFormat == LTDC_PIXEL_FORMAT_RGB888)
  1754. {
  1755. tmp = 3U;
  1756. }
  1757. else if ((pLayerCfg->PixelFormat == LTDC_PIXEL_FORMAT_ARGB4444) || \
  1758. (pLayerCfg->PixelFormat == LTDC_PIXEL_FORMAT_RGB565) || \
  1759. (pLayerCfg->PixelFormat == LTDC_PIXEL_FORMAT_ARGB1555) || \
  1760. (pLayerCfg->PixelFormat == LTDC_PIXEL_FORMAT_AL88))
  1761. {
  1762. tmp = 2U;
  1763. }
  1764. else
  1765. {
  1766. tmp = 1U;
  1767. }
  1768. /* Configure the color frame buffer pitch in byte */
  1769. LTDC_LAYER(hltdc, LayerIdx)->CFBLR &= ~(LTDC_LxCFBLR_CFBLL | LTDC_LxCFBLR_CFBP);
  1770. LTDC_LAYER(hltdc, LayerIdx)->CFBLR = (((pLayerCfg->ImageWidth * tmp) << 16U) | \
  1771. (((pLayerCfg->WindowX1 - pLayerCfg->WindowX0) * tmp) + 3U));
  1772. /* Configure the frame buffer line number */
  1773. LTDC_LAYER(hltdc, LayerIdx)->CFBLNR &= ~(LTDC_LxCFBLNR_CFBLNBR);
  1774. LTDC_LAYER(hltdc, LayerIdx)->CFBLNR = (pLayerCfg->ImageHeight);
  1775. /* Enable LTDC_Layer by setting LEN bit */
  1776. LTDC_LAYER(hltdc, LayerIdx)->CR |= (uint32_t)LTDC_LxCR_LEN;
  1777. }
  1778. /**
  1779. * @}
  1780. */
  1781. /**
  1782. * @}
  1783. */
  1784. #endif /* LTDC */
  1785. #endif /* HAL_LTDC_MODULE_ENABLED */
  1786. /**
  1787. * @}
  1788. */