stm32l4xx_hal_ltdc.c 63 KB

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