stm32f4xx_hal_ltdc.c 69 KB

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