stm32f7xx_hal_ltdc.c 38 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193
  1. /**
  2. ******************************************************************************
  3. * @file stm32f7xx_hal_ltdc.c
  4. * @author MCD Application Team
  5. * @version V1.0.1
  6. * @date 25-June-2015
  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. (#) To control LTDC state you can use the following function: HAL_LTDC_GetState()
  41. *** LTDC HAL driver macros list ***
  42. =============================================
  43. [..]
  44. Below the list of most used macros in LTDC HAL driver.
  45. (+) __HAL_LTDC_ENABLE: Enable the LTDC.
  46. (+) __HAL_LTDC_DISABLE: Disable the LTDC.
  47. (+) __HAL_LTDC_LAYER_ENABLE: Enable the LTDC Layer.
  48. (+) __HAL_LTDC_LAYER_DISABLE: Disable the LTDC Layer.
  49. (+) __HAL_LTDC_RELOAD_CONFIG: Reload Layer Configuration.
  50. (+) __HAL_LTDC_GET_FLAG: Get the LTDC pending flags.
  51. (+) __HAL_LTDC_CLEAR_FLAG: Clear the LTDC pending flags.
  52. (+) __HAL_LTDC_ENABLE_IT: Enable the specified LTDC interrupts.
  53. (+) __HAL_LTDC_DISABLE_IT: Disable the specified LTDC interrupts.
  54. (+) __HAL_LTDC_GET_IT_SOURCE: Check whether the specified LTDC interrupt has occurred or not.
  55. [..]
  56. (@) You can refer to the LTDC HAL driver header file for more useful macros
  57. @endverbatim
  58. ******************************************************************************
  59. * @attention
  60. *
  61. * <h2><center>&copy; COPYRIGHT(c) 2015 STMicroelectronics</center></h2>
  62. *
  63. * Redistribution and use in source and binary forms, with or without modification,
  64. * are permitted provided that the following conditions are met:
  65. * 1. Redistributions of source code must retain the above copyright notice,
  66. * this list of conditions and the following disclaimer.
  67. * 2. Redistributions in binary form must reproduce the above copyright notice,
  68. * this list of conditions and the following disclaimer in the documentation
  69. * and/or other materials provided with the distribution.
  70. * 3. Neither the name of STMicroelectronics nor the names of its contributors
  71. * may be used to endorse or promote products derived from this software
  72. * without specific prior written permission.
  73. *
  74. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  75. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  76. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  77. * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
  78. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  79. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  80. * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  81. * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  82. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  83. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  84. *
  85. ******************************************************************************
  86. */
  87. /* Includes ------------------------------------------------------------------*/
  88. #include "stm32f7xx_hal.h"
  89. /** @addtogroup STM32F7xx_HAL_Driver
  90. * @{
  91. */
  92. #if defined(STM32F756xx) || defined(STM32F746xx)
  93. /** @defgroup LTDC LTDC
  94. * @brief LTDC HAL module driver
  95. * @{
  96. */
  97. #ifdef HAL_LTDC_MODULE_ENABLED
  98. /* Private typedef -----------------------------------------------------------*/
  99. /* Private define ------------------------------------------------------------*/
  100. /* Private macro -------------------------------------------------------------*/
  101. /* Private variables ---------------------------------------------------------*/
  102. /* Private function prototypes -----------------------------------------------*/
  103. static void LTDC_SetConfig(LTDC_HandleTypeDef *hltdc, LTDC_LayerCfgTypeDef *pLayerCfg, uint32_t LayerIdx);
  104. /* Private functions ---------------------------------------------------------*/
  105. /** @defgroup LTDC_Exported_Functions LTDC Exported Functions
  106. * @{
  107. */
  108. /** @defgroup LTDC_Exported_Functions_Group1 Initialization and Configuration functions
  109. * @brief Initialization and Configuration functions
  110. *
  111. @verbatim
  112. ===============================================================================
  113. ##### Initialization and Configuration functions #####
  114. ===============================================================================
  115. [..] This section provides functions allowing to:
  116. (+) Initialize and configure the LTDC
  117. (+) De-initialize the LTDC
  118. @endverbatim
  119. * @{
  120. */
  121. /**
  122. * @brief Initializes the LTDC according to the specified
  123. * parameters in the LTDC_InitTypeDef and create the associated handle.
  124. * @param hltdc: pointer to a LTDC_HandleTypeDef structure that contains
  125. * the configuration information for the LTDC.
  126. * @retval HAL status
  127. */
  128. HAL_StatusTypeDef HAL_LTDC_Init(LTDC_HandleTypeDef *hltdc)
  129. {
  130. uint32_t tmp = 0, tmp1 = 0;
  131. /* Check the LTDC peripheral state */
  132. if(hltdc == NULL)
  133. {
  134. return HAL_ERROR;
  135. }
  136. /* Check function parameters */
  137. assert_param(IS_LTDC_ALL_INSTANCE(hltdc->Instance));
  138. assert_param(IS_LTDC_HSYNC(hltdc->Init.HorizontalSync));
  139. assert_param(IS_LTDC_VSYNC(hltdc->Init.VerticalSync));
  140. assert_param(IS_LTDC_AHBP(hltdc->Init.AccumulatedHBP));
  141. assert_param(IS_LTDC_AVBP(hltdc->Init.AccumulatedVBP));
  142. assert_param(IS_LTDC_AAH(hltdc->Init.AccumulatedActiveH));
  143. assert_param(IS_LTDC_AAW(hltdc->Init.AccumulatedActiveW));
  144. assert_param(IS_LTDC_TOTALH(hltdc->Init.TotalHeigh));
  145. assert_param(IS_LTDC_TOTALW(hltdc->Init.TotalWidth));
  146. assert_param(IS_LTDC_HSPOL(hltdc->Init.HSPolarity));
  147. assert_param(IS_LTDC_VSPOL(hltdc->Init.VSPolarity));
  148. assert_param(IS_LTDC_DEPOL(hltdc->Init.DEPolarity));
  149. assert_param(IS_LTDC_PCPOL(hltdc->Init.PCPolarity));
  150. if(hltdc->State == HAL_LTDC_STATE_RESET)
  151. {
  152. /* Allocate lock resource and initialize it */
  153. hltdc->Lock = HAL_UNLOCKED;
  154. /* Init the low level hardware */
  155. HAL_LTDC_MspInit(hltdc);
  156. }
  157. /* Change LTDC peripheral state */
  158. hltdc->State = HAL_LTDC_STATE_BUSY;
  159. /* Configures the HS, VS, DE and PC polarity */
  160. hltdc->Instance->GCR &= ~(LTDC_GCR_HSPOL | LTDC_GCR_VSPOL | LTDC_GCR_DEPOL | LTDC_GCR_PCPOL);
  161. hltdc->Instance->GCR |= (uint32_t)(hltdc->Init.HSPolarity | hltdc->Init.VSPolarity | \
  162. hltdc->Init.DEPolarity | hltdc->Init.PCPolarity);
  163. /* Sets Synchronization size */
  164. hltdc->Instance->SSCR &= ~(LTDC_SSCR_VSH | LTDC_SSCR_HSW);
  165. tmp = (hltdc->Init.HorizontalSync << 16);
  166. hltdc->Instance->SSCR |= (tmp | hltdc->Init.VerticalSync);
  167. /* Sets Accumulated Back porch */
  168. hltdc->Instance->BPCR &= ~(LTDC_BPCR_AVBP | LTDC_BPCR_AHBP);
  169. tmp = (hltdc->Init.AccumulatedHBP << 16);
  170. hltdc->Instance->BPCR |= (tmp | hltdc->Init.AccumulatedVBP);
  171. /* Sets Accumulated Active Width */
  172. hltdc->Instance->AWCR &= ~(LTDC_AWCR_AAH | LTDC_AWCR_AAW);
  173. tmp = (hltdc->Init.AccumulatedActiveW << 16);
  174. hltdc->Instance->AWCR |= (tmp | hltdc->Init.AccumulatedActiveH);
  175. /* Sets Total Width */
  176. hltdc->Instance->TWCR &= ~(LTDC_TWCR_TOTALH | LTDC_TWCR_TOTALW);
  177. tmp = (hltdc->Init.TotalWidth << 16);
  178. hltdc->Instance->TWCR |= (tmp | hltdc->Init.TotalHeigh);
  179. /* Sets the background color value */
  180. tmp = ((uint32_t)(hltdc->Init.Backcolor.Green) << 8);
  181. tmp1 = ((uint32_t)(hltdc->Init.Backcolor.Red) << 16);
  182. hltdc->Instance->BCCR &= ~(LTDC_BCCR_BCBLUE | LTDC_BCCR_BCGREEN | LTDC_BCCR_BCRED);
  183. hltdc->Instance->BCCR |= (tmp1 | tmp | hltdc->Init.Backcolor.Blue);
  184. /* Enable the transfer Error interrupt */
  185. __HAL_LTDC_ENABLE_IT(hltdc, LTDC_IT_TE);
  186. /* Enable the FIFO underrun interrupt */
  187. __HAL_LTDC_ENABLE_IT(hltdc, LTDC_IT_FU);
  188. /* Enable LTDC by setting LTDCEN bit */
  189. __HAL_LTDC_ENABLE(hltdc);
  190. /* Initialize the error code */
  191. hltdc->ErrorCode = HAL_LTDC_ERROR_NONE;
  192. /* Initialize the LTDC state*/
  193. hltdc->State = HAL_LTDC_STATE_READY;
  194. return HAL_OK;
  195. }
  196. /**
  197. * @brief Deinitializes the LTDC peripheral registers to their default reset
  198. * values.
  199. * @param hltdc: pointer to a LTDC_HandleTypeDef structure that contains
  200. * the configuration information for the LTDC.
  201. * @retval None
  202. */
  203. HAL_StatusTypeDef HAL_LTDC_DeInit(LTDC_HandleTypeDef *hltdc)
  204. {
  205. /* DeInit the low level hardware */
  206. HAL_LTDC_MspDeInit(hltdc);
  207. /* Initialize the error code */
  208. hltdc->ErrorCode = HAL_LTDC_ERROR_NONE;
  209. /* Initialize the LTDC state*/
  210. hltdc->State = HAL_LTDC_STATE_RESET;
  211. /* Release Lock */
  212. __HAL_UNLOCK(hltdc);
  213. return HAL_OK;
  214. }
  215. /**
  216. * @brief Initializes the LTDC MSP.
  217. * @param hltdc : pointer to a LTDC_HandleTypeDef structure that contains
  218. * the configuration information for the LTDC.
  219. * @retval None
  220. */
  221. __weak void HAL_LTDC_MspInit(LTDC_HandleTypeDef* hltdc)
  222. {
  223. /* NOTE : This function Should not be modified, when the callback is needed,
  224. the HAL_LTDC_MspInit could be implemented in the user file
  225. */
  226. }
  227. /**
  228. * @brief DeInitializes the LTDC MSP.
  229. * @param hltdc : pointer to a LTDC_HandleTypeDef structure that contains
  230. * the configuration information for the LTDC.
  231. * @retval None
  232. */
  233. __weak void HAL_LTDC_MspDeInit(LTDC_HandleTypeDef* hltdc)
  234. {
  235. /* NOTE : This function Should not be modified, when the callback is needed,
  236. the HAL_LTDC_MspDeInit could be implemented in the user file
  237. */
  238. }
  239. /**
  240. * @}
  241. */
  242. /** @defgroup LTDC_Exported_Functions_Group2 IO operation functions
  243. * @brief IO operation functions
  244. *
  245. @verbatim
  246. ===============================================================================
  247. ##### IO operation functions #####
  248. ===============================================================================
  249. [..] This section provides function allowing to:
  250. (+) Handle LTDC interrupt request
  251. @endverbatim
  252. * @{
  253. */
  254. /**
  255. * @brief Handles LTDC interrupt request.
  256. * @param hltdc: pointer to a LTDC_HandleTypeDef structure that contains
  257. * the configuration information for the LTDC.
  258. * @retval HAL status
  259. */
  260. void HAL_LTDC_IRQHandler(LTDC_HandleTypeDef *hltdc)
  261. {
  262. /* Transfer Error Interrupt management ***************************************/
  263. if(__HAL_LTDC_GET_FLAG(hltdc, LTDC_FLAG_TE) != RESET)
  264. {
  265. if(__HAL_LTDC_GET_IT_SOURCE(hltdc, LTDC_IT_TE) != RESET)
  266. {
  267. /* Disable the transfer Error interrupt */
  268. __HAL_LTDC_DISABLE_IT(hltdc, LTDC_IT_TE);
  269. /* Clear the transfer error flag */
  270. __HAL_LTDC_CLEAR_FLAG(hltdc, LTDC_FLAG_TE);
  271. /* Update error code */
  272. hltdc->ErrorCode |= HAL_LTDC_ERROR_TE;
  273. /* Change LTDC state */
  274. hltdc->State = HAL_LTDC_STATE_ERROR;
  275. /* Process unlocked */
  276. __HAL_UNLOCK(hltdc);
  277. /* Transfer error Callback */
  278. HAL_LTDC_ErrorCallback(hltdc);
  279. }
  280. }
  281. /* FIFO underrun Interrupt management ***************************************/
  282. if(__HAL_LTDC_GET_FLAG(hltdc, LTDC_FLAG_FU) != RESET)
  283. {
  284. if(__HAL_LTDC_GET_IT_SOURCE(hltdc, LTDC_IT_FU) != RESET)
  285. {
  286. /* Disable the FIFO underrun interrupt */
  287. __HAL_LTDC_DISABLE_IT(hltdc, LTDC_IT_FU);
  288. /* Clear the FIFO underrun flag */
  289. __HAL_LTDC_CLEAR_FLAG(hltdc, LTDC_FLAG_FU);
  290. /* Update error code */
  291. hltdc->ErrorCode |= HAL_LTDC_ERROR_FU;
  292. /* Change LTDC state */
  293. hltdc->State = HAL_LTDC_STATE_ERROR;
  294. /* Process unlocked */
  295. __HAL_UNLOCK(hltdc);
  296. /* Transfer error Callback */
  297. HAL_LTDC_ErrorCallback(hltdc);
  298. }
  299. }
  300. /* Line Interrupt management ************************************************/
  301. if(__HAL_LTDC_GET_FLAG(hltdc, LTDC_FLAG_LI) != RESET)
  302. {
  303. if(__HAL_LTDC_GET_IT_SOURCE(hltdc, LTDC_IT_LI) != RESET)
  304. {
  305. /* Disable the Line interrupt */
  306. __HAL_LTDC_DISABLE_IT(hltdc, LTDC_IT_LI);
  307. /* Clear the Line interrupt flag */
  308. __HAL_LTDC_CLEAR_FLAG(hltdc, LTDC_FLAG_LI);
  309. /* Change LTDC state */
  310. hltdc->State = HAL_LTDC_STATE_READY;
  311. /* Process unlocked */
  312. __HAL_UNLOCK(hltdc);
  313. /* Line interrupt Callback */
  314. HAL_LTDC_LineEvenCallback(hltdc);
  315. }
  316. }
  317. }
  318. /**
  319. * @brief Error LTDC callback.
  320. * @param hltdc: pointer to a LTDC_HandleTypeDef structure that contains
  321. * the configuration information for the LTDC.
  322. * @retval None
  323. */
  324. __weak void HAL_LTDC_ErrorCallback(LTDC_HandleTypeDef *hltdc)
  325. {
  326. /* NOTE : This function Should not be modified, when the callback is needed,
  327. the HAL_LTDC_ErrorCallback could be implemented in the user file
  328. */
  329. }
  330. /**
  331. * @brief Line Event callback.
  332. * @param hltdc: pointer to a LTDC_HandleTypeDef structure that contains
  333. * the configuration information for the LTDC.
  334. * @retval None
  335. */
  336. __weak void HAL_LTDC_LineEvenCallback(LTDC_HandleTypeDef *hltdc)
  337. {
  338. /* NOTE : This function Should not be modified, when the callback is needed,
  339. the HAL_LTDC_LineEvenCallback could be implemented in the user file
  340. */
  341. }
  342. /**
  343. * @}
  344. */
  345. /** @defgroup LTDC_Exported_Functions_Group3 Peripheral Control functions
  346. * @brief Peripheral Control functions
  347. *
  348. @verbatim
  349. ===============================================================================
  350. ##### Peripheral Control functions #####
  351. ===============================================================================
  352. [..] This section provides functions allowing to:
  353. (+) Configure the LTDC foreground or/and background parameters.
  354. (+) Set the active layer.
  355. (+) Configure the color keying.
  356. (+) Configure the C-LUT.
  357. (+) Enable / Disable the color keying.
  358. (+) Enable / Disable the C-LUT.
  359. (+) Update the layer position.
  360. (+) Update the layer size.
  361. (+) Update pixel format on the fly.
  362. (+) Update transparency on the fly.
  363. (+) Update address on the fly.
  364. @endverbatim
  365. * @{
  366. */
  367. /**
  368. * @brief Configure the LTDC Layer according to the specified
  369. * parameters in the LTDC_InitTypeDef and create the associated handle.
  370. * @param hltdc: pointer to a LTDC_HandleTypeDef structure that contains
  371. * the configuration information for the LTDC.
  372. * @param pLayerCfg: pointer to a LTDC_LayerCfgTypeDef structure that contains
  373. * the configuration information for the Layer.
  374. * @param LayerIdx: LTDC Layer index.
  375. * This parameter can be one of the following values:
  376. * 0 or 1
  377. * @retval HAL status
  378. */
  379. HAL_StatusTypeDef HAL_LTDC_ConfigLayer(LTDC_HandleTypeDef *hltdc, LTDC_LayerCfgTypeDef *pLayerCfg, uint32_t LayerIdx)
  380. {
  381. /* Process locked */
  382. __HAL_LOCK(hltdc);
  383. /* Change LTDC peripheral state */
  384. hltdc->State = HAL_LTDC_STATE_BUSY;
  385. /* Check the parameters */
  386. assert_param(IS_LTDC_LAYER(LayerIdx));
  387. assert_param(IS_LTDC_PIXEL_FORMAT(pLayerCfg->PixelFormat));
  388. assert_param(IS_LTDC_BLENDING_FACTOR1(pLayerCfg->BlendingFactor1));
  389. assert_param(IS_LTDC_BLENDING_FACTOR2(pLayerCfg->BlendingFactor2));
  390. assert_param(IS_LTDC_HCONFIGST(pLayerCfg->WindowX0));
  391. assert_param(IS_LTDC_HCONFIGSP(pLayerCfg->WindowX1));
  392. assert_param(IS_LTDC_VCONFIGST(pLayerCfg->WindowY0));
  393. assert_param(IS_LTDC_VCONFIGSP(pLayerCfg->WindowY1));
  394. assert_param(IS_LTDC_ALPHA(pLayerCfg->Alpha0));
  395. assert_param(IS_LTDC_CFBLL(pLayerCfg->ImageWidth));
  396. assert_param(IS_LTDC_CFBLNBR(pLayerCfg->ImageHeight));
  397. /* Copy new layer configuration into handle structure */
  398. hltdc->LayerCfg[LayerIdx] = *pLayerCfg;
  399. /* Configure the LTDC Layer */
  400. LTDC_SetConfig(hltdc, pLayerCfg, LayerIdx);
  401. /* Sets the Reload type */
  402. hltdc->Instance->SRCR = LTDC_SRCR_IMR;
  403. /* Initialize the LTDC state*/
  404. hltdc->State = HAL_LTDC_STATE_READY;
  405. /* Process unlocked */
  406. __HAL_UNLOCK(hltdc);
  407. return HAL_OK;
  408. }
  409. /**
  410. * @brief Configure the color keying.
  411. * @param hltdc: pointer to a LTDC_HandleTypeDef structure that contains
  412. * the configuration information for the LTDC.
  413. * @param RGBValue: the color key value
  414. * @param LayerIdx: LTDC Layer index.
  415. * This parameter can be one of the following values:
  416. * 0 or 1
  417. * @retval HAL status
  418. */
  419. HAL_StatusTypeDef HAL_LTDC_ConfigColorKeying(LTDC_HandleTypeDef *hltdc, uint32_t RGBValue, uint32_t LayerIdx)
  420. {
  421. /* Process locked */
  422. __HAL_LOCK(hltdc);
  423. /* Change LTDC peripheral state */
  424. hltdc->State = HAL_LTDC_STATE_BUSY;
  425. /* Check the parameters */
  426. assert_param(IS_LTDC_LAYER(LayerIdx));
  427. /* Configures the default color values */
  428. LTDC_LAYER(hltdc, LayerIdx)->CKCR &= ~(LTDC_LxCKCR_CKBLUE | LTDC_LxCKCR_CKGREEN | LTDC_LxCKCR_CKRED);
  429. LTDC_LAYER(hltdc, LayerIdx)->CKCR = RGBValue;
  430. /* Sets the Reload type */
  431. hltdc->Instance->SRCR = LTDC_SRCR_IMR;
  432. /* Change the LTDC state*/
  433. hltdc->State = HAL_LTDC_STATE_READY;
  434. /* Process unlocked */
  435. __HAL_UNLOCK(hltdc);
  436. return HAL_OK;
  437. }
  438. /**
  439. * @brief Load the color lookup table.
  440. * @param hltdc: pointer to a LTDC_HandleTypeDef structure that contains
  441. * the configuration information for the LTDC.
  442. * @param pCLUT: pointer to the color lookup table address.
  443. * @param CLUTSize: the color lookup table size.
  444. * @param LayerIdx: LTDC Layer index.
  445. * This parameter can be one of the following values:
  446. * 0 or 1
  447. * @retval HAL status
  448. */
  449. HAL_StatusTypeDef HAL_LTDC_ConfigCLUT(LTDC_HandleTypeDef *hltdc, uint32_t *pCLUT, uint32_t CLUTSize, uint32_t LayerIdx)
  450. {
  451. uint32_t tmp = 0;
  452. uint32_t counter = 0;
  453. uint32_t pcounter = 0;
  454. /* Process locked */
  455. __HAL_LOCK(hltdc);
  456. /* Change LTDC peripheral state */
  457. hltdc->State = HAL_LTDC_STATE_BUSY;
  458. /* Check the parameters */
  459. assert_param(IS_LTDC_LAYER(LayerIdx));
  460. for(counter = 0; (counter < CLUTSize); counter++)
  461. {
  462. if(hltdc->LayerCfg[LayerIdx].PixelFormat == LTDC_PIXEL_FORMAT_AL44)
  463. {
  464. tmp = (((counter + 16*counter) << 24) | ((uint32_t)(*pCLUT) & 0xFF) | ((uint32_t)(*pCLUT) & 0xFF00) | ((uint32_t)(*pCLUT) & 0xFF0000));
  465. }
  466. else
  467. {
  468. tmp = ((counter << 24) | ((uint32_t)(*pCLUT) & 0xFF) | ((uint32_t)(*pCLUT) & 0xFF00) | ((uint32_t)(*pCLUT) & 0xFF0000));
  469. }
  470. pcounter = (uint32_t)pCLUT + sizeof(*pCLUT);
  471. pCLUT = (uint32_t *)pcounter;
  472. /* Specifies the C-LUT address and RGB value */
  473. LTDC_LAYER(hltdc, LayerIdx)->CLUTWR = tmp;
  474. }
  475. /* Change the LTDC state*/
  476. hltdc->State = HAL_LTDC_STATE_READY;
  477. /* Process unlocked */
  478. __HAL_UNLOCK(hltdc);
  479. return HAL_OK;
  480. }
  481. /**
  482. * @brief Enable the color keying.
  483. * @param hltdc: pointer to a LTDC_HandleTypeDef structure that contains
  484. * the configuration information for the LTDC.
  485. * @param LayerIdx: LTDC Layer index.
  486. * This parameter can be one of the following values:
  487. * 0 or 1
  488. * @retval HAL status
  489. */
  490. HAL_StatusTypeDef HAL_LTDC_EnableColorKeying(LTDC_HandleTypeDef *hltdc, uint32_t LayerIdx)
  491. {
  492. /* Process locked */
  493. __HAL_LOCK(hltdc);
  494. /* Change LTDC peripheral state */
  495. hltdc->State = HAL_LTDC_STATE_BUSY;
  496. /* Check the parameters */
  497. assert_param(IS_LTDC_LAYER(LayerIdx));
  498. /* Enable LTDC color keying by setting COLKEN bit */
  499. LTDC_LAYER(hltdc, LayerIdx)->CR |= (uint32_t)LTDC_LxCR_COLKEN;
  500. /* Sets the Reload type */
  501. hltdc->Instance->SRCR = LTDC_SRCR_IMR;
  502. /* Change the LTDC state*/
  503. hltdc->State = HAL_LTDC_STATE_READY;
  504. /* Process unlocked */
  505. __HAL_UNLOCK(hltdc);
  506. return HAL_OK;
  507. }
  508. /**
  509. * @brief Disable the color keying.
  510. * @param hltdc: pointer to a LTDC_HandleTypeDef structure that contains
  511. * the configuration information for the LTDC.
  512. * @param LayerIdx: LTDC Layer index.
  513. * This parameter can be one of the following values:
  514. * 0 or 1
  515. * @retval HAL status
  516. */
  517. HAL_StatusTypeDef HAL_LTDC_DisableColorKeying(LTDC_HandleTypeDef *hltdc, uint32_t LayerIdx)
  518. {
  519. /* Process locked */
  520. __HAL_LOCK(hltdc);
  521. /* Change LTDC peripheral state */
  522. hltdc->State = HAL_LTDC_STATE_BUSY;
  523. /* Check the parameters */
  524. assert_param(IS_LTDC_LAYER(LayerIdx));
  525. /* Disable LTDC color keying by setting COLKEN bit */
  526. LTDC_LAYER(hltdc, LayerIdx)->CR &= ~(uint32_t)LTDC_LxCR_COLKEN;
  527. /* Sets the Reload type */
  528. hltdc->Instance->SRCR = LTDC_SRCR_IMR;
  529. /* Change the LTDC state*/
  530. hltdc->State = HAL_LTDC_STATE_READY;
  531. /* Process unlocked */
  532. __HAL_UNLOCK(hltdc);
  533. return HAL_OK;
  534. }
  535. /**
  536. * @brief Enable the color lookup table.
  537. * @param hltdc: pointer to a LTDC_HandleTypeDef structure that contains
  538. * the configuration information for the LTDC.
  539. * @param LayerIdx: LTDC Layer index.
  540. * This parameter can be one of the following values:
  541. * 0 or 1
  542. * @retval HAL status
  543. */
  544. HAL_StatusTypeDef HAL_LTDC_EnableCLUT(LTDC_HandleTypeDef *hltdc, uint32_t LayerIdx)
  545. {
  546. /* Process locked */
  547. __HAL_LOCK(hltdc);
  548. /* Change LTDC peripheral state */
  549. hltdc->State = HAL_LTDC_STATE_BUSY;
  550. /* Check the parameters */
  551. assert_param(IS_LTDC_LAYER(LayerIdx));
  552. /* Disable LTDC color lookup table by setting CLUTEN bit */
  553. LTDC_LAYER(hltdc, LayerIdx)->CR |= (uint32_t)LTDC_LxCR_CLUTEN;
  554. /* Sets the Reload type */
  555. hltdc->Instance->SRCR = LTDC_SRCR_IMR;
  556. /* Change the LTDC state*/
  557. hltdc->State = HAL_LTDC_STATE_READY;
  558. /* Process unlocked */
  559. __HAL_UNLOCK(hltdc);
  560. return HAL_OK;
  561. }
  562. /**
  563. * @brief Disable the color lookup table.
  564. * @param hltdc: pointer to a LTDC_HandleTypeDef structure that contains
  565. * the configuration information for the LTDC.
  566. * @param LayerIdx: LTDC Layer index.
  567. * This parameter can be one of the following values:
  568. * 0 or 1
  569. * @retval HAL status
  570. */
  571. HAL_StatusTypeDef HAL_LTDC_DisableCLUT(LTDC_HandleTypeDef *hltdc, uint32_t LayerIdx)
  572. {
  573. /* Process locked */
  574. __HAL_LOCK(hltdc);
  575. /* Change LTDC peripheral state */
  576. hltdc->State = HAL_LTDC_STATE_BUSY;
  577. /* Check the parameters */
  578. assert_param(IS_LTDC_LAYER(LayerIdx));
  579. /* Disable LTDC color lookup table by setting CLUTEN bit */
  580. LTDC_LAYER(hltdc, LayerIdx)->CR &= ~(uint32_t)LTDC_LxCR_CLUTEN;
  581. /* Sets the Reload type */
  582. hltdc->Instance->SRCR = LTDC_SRCR_IMR;
  583. /* Change the LTDC state*/
  584. hltdc->State = HAL_LTDC_STATE_READY;
  585. /* Process unlocked */
  586. __HAL_UNLOCK(hltdc);
  587. return HAL_OK;
  588. }
  589. /**
  590. * @brief Enables Dither.
  591. * @param hltdc: pointer to a LTDC_HandleTypeDef structure that contains
  592. * the configuration information for the LTDC.
  593. * @retval HAL status
  594. */
  595. HAL_StatusTypeDef HAL_LTDC_EnableDither(LTDC_HandleTypeDef *hltdc)
  596. {
  597. /* Process locked */
  598. __HAL_LOCK(hltdc);
  599. /* Change LTDC peripheral state */
  600. hltdc->State = HAL_LTDC_STATE_BUSY;
  601. /* Enable Dither by setting DTEN bit */
  602. LTDC->GCR |= (uint32_t)LTDC_GCR_DTEN;
  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 Disables Dither.
  611. * @param hltdc: pointer to a LTDC_HandleTypeDef structure that contains
  612. * the configuration information for the LTDC.
  613. * @retval HAL status
  614. */
  615. HAL_StatusTypeDef HAL_LTDC_DisableDither(LTDC_HandleTypeDef *hltdc)
  616. {
  617. /* Process locked */
  618. __HAL_LOCK(hltdc);
  619. /* Change LTDC peripheral state */
  620. hltdc->State = HAL_LTDC_STATE_BUSY;
  621. /* Disable Dither by setting DTEN bit */
  622. LTDC->GCR &= ~(uint32_t)LTDC_GCR_DTEN;
  623. /* Change the LTDC state*/
  624. hltdc->State = HAL_LTDC_STATE_READY;
  625. /* Process unlocked */
  626. __HAL_UNLOCK(hltdc);
  627. return HAL_OK;
  628. }
  629. /**
  630. * @brief Set the LTDC window size.
  631. * @param hltdc: pointer to a LTDC_HandleTypeDef structure that contains
  632. * the configuration information for the LTDC.
  633. * @param XSize: LTDC Pixel per line
  634. * @param YSize: LTDC Line number
  635. * @param LayerIdx: LTDC Layer index.
  636. * This parameter can be one of the following values:
  637. * 0 or 1
  638. * @retval HAL status
  639. */
  640. HAL_StatusTypeDef HAL_LTDC_SetWindowSize(LTDC_HandleTypeDef *hltdc, uint32_t XSize, uint32_t YSize, uint32_t LayerIdx)
  641. {
  642. LTDC_LayerCfgTypeDef *pLayerCfg;
  643. /* Process locked */
  644. __HAL_LOCK(hltdc);
  645. /* Change LTDC peripheral state */
  646. hltdc->State = HAL_LTDC_STATE_BUSY;
  647. /* Get layer configuration from handle structure */
  648. pLayerCfg = &hltdc->LayerCfg[LayerIdx];
  649. /* Check the parameters (Layers parameters)*/
  650. assert_param(IS_LTDC_LAYER(LayerIdx));
  651. assert_param(IS_LTDC_HCONFIGST(pLayerCfg->WindowX0));
  652. assert_param(IS_LTDC_HCONFIGSP(pLayerCfg->WindowX1));
  653. assert_param(IS_LTDC_VCONFIGST(pLayerCfg->WindowY0));
  654. assert_param(IS_LTDC_VCONFIGSP(pLayerCfg->WindowY1));
  655. assert_param(IS_LTDC_CFBLL(XSize));
  656. assert_param(IS_LTDC_CFBLNBR(YSize));
  657. /* update horizontal start/stop */
  658. pLayerCfg->WindowX0 = 0;
  659. pLayerCfg->WindowX1 = XSize + pLayerCfg->WindowX0;
  660. /* update vertical start/stop */
  661. pLayerCfg->WindowY0 = 0;
  662. pLayerCfg->WindowY1 = YSize + pLayerCfg->WindowY0;
  663. /* Reconfigures the color frame buffer pitch in byte */
  664. pLayerCfg->ImageWidth = XSize;
  665. /* Reconfigures the frame buffer line number */
  666. pLayerCfg->ImageHeight = YSize;
  667. /* Set LTDC parameters */
  668. LTDC_SetConfig(hltdc, pLayerCfg, LayerIdx);
  669. /* Sets the Reload type */
  670. hltdc->Instance->SRCR = LTDC_SRCR_IMR;
  671. /* Change the LTDC state*/
  672. hltdc->State = HAL_LTDC_STATE_READY;
  673. /* Process unlocked */
  674. __HAL_UNLOCK(hltdc);
  675. return HAL_OK;
  676. }
  677. /**
  678. * @brief Set the LTDC window position.
  679. * @param hltdc: pointer to a LTDC_HandleTypeDef structure that contains
  680. * the configuration information for the LTDC.
  681. * @param X0: LTDC window X offset
  682. * @param Y0: LTDC window Y offset
  683. * @param LayerIdx: LTDC Layer index.
  684. * This parameter can be one of the following values:
  685. * 0 or 1
  686. * @retval HAL status
  687. */
  688. HAL_StatusTypeDef HAL_LTDC_SetWindowPosition(LTDC_HandleTypeDef *hltdc, uint32_t X0, uint32_t Y0, uint32_t LayerIdx)
  689. {
  690. LTDC_LayerCfgTypeDef *pLayerCfg;
  691. /* Process locked */
  692. __HAL_LOCK(hltdc);
  693. /* Change LTDC peripheral state */
  694. hltdc->State = HAL_LTDC_STATE_BUSY;
  695. /* Get layer configuration from handle structure */
  696. pLayerCfg = &hltdc->LayerCfg[LayerIdx];
  697. /* Check the parameters */
  698. assert_param(IS_LTDC_LAYER(LayerIdx));
  699. assert_param(IS_LTDC_HCONFIGST(pLayerCfg->WindowX0));
  700. assert_param(IS_LTDC_HCONFIGSP(pLayerCfg->WindowX1));
  701. assert_param(IS_LTDC_VCONFIGST(pLayerCfg->WindowY0));
  702. assert_param(IS_LTDC_VCONFIGSP(pLayerCfg->WindowY1));
  703. /* update horizontal start/stop */
  704. pLayerCfg->WindowX0 = X0;
  705. pLayerCfg->WindowX1 = X0 + pLayerCfg->ImageWidth;
  706. /* update vertical start/stop */
  707. pLayerCfg->WindowY0 = Y0;
  708. pLayerCfg->WindowY1 = Y0 + pLayerCfg->ImageHeight;
  709. /* Set LTDC parameters */
  710. LTDC_SetConfig(hltdc, pLayerCfg, LayerIdx);
  711. /* Sets the Reload type */
  712. hltdc->Instance->SRCR = LTDC_SRCR_IMR;
  713. /* Change the LTDC state*/
  714. hltdc->State = HAL_LTDC_STATE_READY;
  715. /* Process unlocked */
  716. __HAL_UNLOCK(hltdc);
  717. return HAL_OK;
  718. }
  719. /**
  720. * @brief Reconfigure the pixel format.
  721. * @param hltdc: pointer to a LTDC_HandleTypeDef structure that contains
  722. * the configuration information for the LTDC.
  723. * @param Pixelformat: new pixel format value.
  724. * @param LayerIdx: LTDC Layer index.
  725. * This parameter can be one of the following values:
  726. * 0 or 1.
  727. * @retval HAL status
  728. */
  729. HAL_StatusTypeDef HAL_LTDC_SetPixelFormat(LTDC_HandleTypeDef *hltdc, uint32_t Pixelformat, uint32_t LayerIdx)
  730. {
  731. LTDC_LayerCfgTypeDef *pLayerCfg;
  732. /* Process locked */
  733. __HAL_LOCK(hltdc);
  734. /* Change LTDC peripheral state */
  735. hltdc->State = HAL_LTDC_STATE_BUSY;
  736. /* Check the parameters */
  737. assert_param(IS_LTDC_LAYER(LayerIdx));
  738. assert_param(IS_LTDC_PIXEL_FORMAT(Pixelformat));
  739. /* Get layer configuration from handle structure */
  740. pLayerCfg = &hltdc->LayerCfg[LayerIdx];
  741. /* Reconfigure the pixel format */
  742. pLayerCfg->PixelFormat = Pixelformat;
  743. /* Set LTDC parameters */
  744. LTDC_SetConfig(hltdc, pLayerCfg, LayerIdx);
  745. /* Sets the Reload type */
  746. hltdc->Instance->SRCR = LTDC_SRCR_IMR;
  747. /* Change the LTDC state*/
  748. hltdc->State = HAL_LTDC_STATE_READY;
  749. /* Process unlocked */
  750. __HAL_UNLOCK(hltdc);
  751. return HAL_OK;
  752. }
  753. /**
  754. * @brief Reconfigure the layer alpha value.
  755. * @param hltdc: pointer to a LTDC_HandleTypeDef structure that contains
  756. * the configuration information for the LTDC.
  757. * @param Alpha: new alpha value.
  758. * @param LayerIdx: LTDC Layer index.
  759. * This parameter can be one of the following values:
  760. * 0 or 1
  761. * @retval HAL status
  762. */
  763. HAL_StatusTypeDef HAL_LTDC_SetAlpha(LTDC_HandleTypeDef *hltdc, uint32_t Alpha, uint32_t LayerIdx)
  764. {
  765. LTDC_LayerCfgTypeDef *pLayerCfg;
  766. /* Process locked */
  767. __HAL_LOCK(hltdc);
  768. /* Change LTDC peripheral state */
  769. hltdc->State = HAL_LTDC_STATE_BUSY;
  770. /* Check the parameters */
  771. assert_param(IS_LTDC_ALPHA(Alpha));
  772. assert_param(IS_LTDC_LAYER(LayerIdx));
  773. /* Get layer configuration from handle structure */
  774. pLayerCfg = &hltdc->LayerCfg[LayerIdx];
  775. /* Reconfigure the Alpha value */
  776. pLayerCfg->Alpha = Alpha;
  777. /* Set LTDC parameters */
  778. LTDC_SetConfig(hltdc, pLayerCfg, LayerIdx);
  779. /* Sets the Reload type */
  780. hltdc->Instance->SRCR = LTDC_SRCR_IMR;
  781. /* Change the LTDC state*/
  782. hltdc->State = HAL_LTDC_STATE_READY;
  783. /* Process unlocked */
  784. __HAL_UNLOCK(hltdc);
  785. return HAL_OK;
  786. }
  787. /**
  788. * @brief Reconfigure the frame buffer Address.
  789. * @param hltdc: pointer to a LTDC_HandleTypeDef structure that contains
  790. * the configuration information for the LTDC.
  791. * @param Address: new address value.
  792. * @param LayerIdx: LTDC Layer index.
  793. * This parameter can be one of the following values:
  794. * 0 or 1.
  795. * @retval HAL status
  796. */
  797. HAL_StatusTypeDef HAL_LTDC_SetAddress(LTDC_HandleTypeDef *hltdc, uint32_t Address, uint32_t LayerIdx)
  798. {
  799. LTDC_LayerCfgTypeDef *pLayerCfg;
  800. /* Process locked */
  801. __HAL_LOCK(hltdc);
  802. /* Change LTDC peripheral state */
  803. hltdc->State = HAL_LTDC_STATE_BUSY;
  804. /* Check the parameters */
  805. assert_param(IS_LTDC_LAYER(LayerIdx));
  806. /* Get layer configuration from handle structure */
  807. pLayerCfg = &hltdc->LayerCfg[LayerIdx];
  808. /* Reconfigure the Address */
  809. pLayerCfg->FBStartAdress = Address;
  810. /* Set LTDC parameters */
  811. LTDC_SetConfig(hltdc, pLayerCfg, LayerIdx);
  812. /* Sets the Reload type */
  813. hltdc->Instance->SRCR = LTDC_SRCR_IMR;
  814. /* Change the LTDC state*/
  815. hltdc->State = HAL_LTDC_STATE_READY;
  816. /* Process unlocked */
  817. __HAL_UNLOCK(hltdc);
  818. return HAL_OK;
  819. }
  820. /**
  821. * @brief Define the position of the line interrupt .
  822. * @param hltdc: pointer to a LTDC_HandleTypeDef structure that contains
  823. * the configuration information for the LTDC.
  824. * @param Line: Line Interrupt Position.
  825. * @retval HAL status
  826. */
  827. HAL_StatusTypeDef HAL_LTDC_ProgramLineEvent(LTDC_HandleTypeDef *hltdc, uint32_t Line)
  828. {
  829. /* Process locked */
  830. __HAL_LOCK(hltdc);
  831. /* Change LTDC peripheral state */
  832. hltdc->State = HAL_LTDC_STATE_BUSY;
  833. /* Check the parameters */
  834. assert_param(IS_LTDC_LIPOS(Line));
  835. /* Enable the Line interrupt */
  836. __HAL_LTDC_ENABLE_IT(hltdc, LTDC_IT_LI);
  837. /* Sets the Line Interrupt position */
  838. LTDC->LIPCR = (uint32_t)Line;
  839. /* Change the LTDC state*/
  840. hltdc->State = HAL_LTDC_STATE_READY;
  841. /* Process unlocked */
  842. __HAL_UNLOCK(hltdc);
  843. return HAL_OK;
  844. }
  845. /**
  846. * @}
  847. */
  848. /** @defgroup LTDC_Exported_Functions_Group4 Peripheral State and Errors functions
  849. * @brief Peripheral State and Errors functions
  850. *
  851. @verbatim
  852. ===============================================================================
  853. ##### Peripheral State and Errors functions #####
  854. ===============================================================================
  855. [..]
  856. This subsection provides functions allowing to
  857. (+) Check the LTDC state.
  858. (+) Get error code.
  859. @endverbatim
  860. * @{
  861. */
  862. /**
  863. * @brief Return the LTDC state
  864. * @param hltdc: pointer to a LTDC_HandleTypeDef structure that contains
  865. * the configuration information for the LTDC.
  866. * @retval HAL state
  867. */
  868. HAL_LTDC_StateTypeDef HAL_LTDC_GetState(LTDC_HandleTypeDef *hltdc)
  869. {
  870. return hltdc->State;
  871. }
  872. /**
  873. * @brief Return the LTDC error code
  874. * @param hltdc : pointer to a LTDC_HandleTypeDef structure that contains
  875. * the configuration information for the LTDC.
  876. * @retval LTDC Error Code
  877. */
  878. uint32_t HAL_LTDC_GetError(LTDC_HandleTypeDef *hltdc)
  879. {
  880. return hltdc->ErrorCode;
  881. }
  882. /**
  883. * @}
  884. */
  885. /**
  886. * @brief Configures the LTDC peripheral
  887. * @param hltdc : Pointer to a LTDC_HandleTypeDef structure that contains
  888. * the configuration information for the LTDC.
  889. * @param pLayerCfg: Pointer LTDC Layer Configuration structure
  890. * @param LayerIdx: LTDC Layer index.
  891. * This parameter can be one of the following values: 0 or 1
  892. * @retval None
  893. */
  894. static void LTDC_SetConfig(LTDC_HandleTypeDef *hltdc, LTDC_LayerCfgTypeDef *pLayerCfg, uint32_t LayerIdx)
  895. {
  896. uint32_t tmp = 0;
  897. uint32_t tmp1 = 0;
  898. uint32_t tmp2 = 0;
  899. /* Configures the horizontal start and stop position */
  900. tmp = ((pLayerCfg->WindowX1 + ((hltdc->Instance->BPCR & LTDC_BPCR_AHBP) >> 16)) << 16);
  901. LTDC_LAYER(hltdc, LayerIdx)->WHPCR &= ~(LTDC_LxWHPCR_WHSTPOS | LTDC_LxWHPCR_WHSPPOS);
  902. LTDC_LAYER(hltdc, LayerIdx)->WHPCR = ((pLayerCfg->WindowX0 + ((hltdc->Instance->BPCR & LTDC_BPCR_AHBP) >> 16) + 1) | tmp);
  903. /* Configures the vertical start and stop position */
  904. tmp = ((pLayerCfg->WindowY1 + (hltdc->Instance->BPCR & LTDC_BPCR_AVBP)) << 16);
  905. LTDC_LAYER(hltdc, LayerIdx)->WVPCR &= ~(LTDC_LxWVPCR_WVSTPOS | LTDC_LxWVPCR_WVSPPOS);
  906. LTDC_LAYER(hltdc, LayerIdx)->WVPCR = ((pLayerCfg->WindowY0 + (hltdc->Instance->BPCR & LTDC_BPCR_AVBP) + 1) | tmp);
  907. /* Specifies the pixel format */
  908. LTDC_LAYER(hltdc, LayerIdx)->PFCR &= ~(LTDC_LxPFCR_PF);
  909. LTDC_LAYER(hltdc, LayerIdx)->PFCR = (pLayerCfg->PixelFormat);
  910. /* Configures the default color values */
  911. tmp = ((uint32_t)(pLayerCfg->Backcolor.Green) << 8);
  912. tmp1 = ((uint32_t)(pLayerCfg->Backcolor.Red) << 16);
  913. tmp2 = (pLayerCfg->Alpha0 << 24);
  914. LTDC_LAYER(hltdc, LayerIdx)->DCCR &= ~(LTDC_LxDCCR_DCBLUE | LTDC_LxDCCR_DCGREEN | LTDC_LxDCCR_DCRED | LTDC_LxDCCR_DCALPHA);
  915. LTDC_LAYER(hltdc, LayerIdx)->DCCR = (pLayerCfg->Backcolor.Blue | tmp | tmp1 | tmp2);
  916. /* Specifies the constant alpha value */
  917. LTDC_LAYER(hltdc, LayerIdx)->CACR &= ~(LTDC_LxCACR_CONSTA);
  918. LTDC_LAYER(hltdc, LayerIdx)->CACR = (pLayerCfg->Alpha);
  919. /* Specifies the blending factors */
  920. LTDC_LAYER(hltdc, LayerIdx)->BFCR &= ~(LTDC_LxBFCR_BF2 | LTDC_LxBFCR_BF1);
  921. LTDC_LAYER(hltdc, LayerIdx)->BFCR = (pLayerCfg->BlendingFactor1 | pLayerCfg->BlendingFactor2);
  922. /* Configures the color frame buffer start address */
  923. LTDC_LAYER(hltdc, LayerIdx)->CFBAR &= ~(LTDC_LxCFBAR_CFBADD);
  924. LTDC_LAYER(hltdc, LayerIdx)->CFBAR = (pLayerCfg->FBStartAdress);
  925. if(pLayerCfg->PixelFormat == LTDC_PIXEL_FORMAT_ARGB8888)
  926. {
  927. tmp = 4;
  928. }
  929. else if (pLayerCfg->PixelFormat == LTDC_PIXEL_FORMAT_RGB888)
  930. {
  931. tmp = 3;
  932. }
  933. else if((pLayerCfg->PixelFormat == LTDC_PIXEL_FORMAT_ARGB4444) || \
  934. (pLayerCfg->PixelFormat == LTDC_PIXEL_FORMAT_RGB565) || \
  935. (pLayerCfg->PixelFormat == LTDC_PIXEL_FORMAT_ARGB1555) || \
  936. (pLayerCfg->PixelFormat == LTDC_PIXEL_FORMAT_AL88))
  937. {
  938. tmp = 2;
  939. }
  940. else
  941. {
  942. tmp = 1;
  943. }
  944. /* Configures the color frame buffer pitch in byte */
  945. LTDC_LAYER(hltdc, LayerIdx)->CFBLR &= ~(LTDC_LxCFBLR_CFBLL | LTDC_LxCFBLR_CFBP);
  946. LTDC_LAYER(hltdc, LayerIdx)->CFBLR = (((pLayerCfg->ImageWidth * tmp) << 16) | (((pLayerCfg->WindowX1 - pLayerCfg->WindowX0) * tmp) + 3));
  947. /* Configures the frame buffer line number */
  948. LTDC_LAYER(hltdc, LayerIdx)->CFBLNR &= ~(LTDC_LxCFBLNR_CFBLNBR);
  949. LTDC_LAYER(hltdc, LayerIdx)->CFBLNR = (pLayerCfg->ImageHeight);
  950. /* Enable LTDC_Layer by setting LEN bit */
  951. LTDC_LAYER(hltdc, LayerIdx)->CR |= (uint32_t)LTDC_LxCR_LEN;
  952. }
  953. /**
  954. * @}
  955. */
  956. #endif /* HAL_LTDC_MODULE_ENABLED */
  957. /**
  958. * @}
  959. */
  960. #endif /* STM32F756xx || STM32F746xx */
  961. /**
  962. * @}
  963. */
  964. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/