stm32f7xx_hal_ltdc.c 61 KB

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