stm32f4xx_hal_ltdc.c 61 KB

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