stm32f4xx_hal_ltdc.c 41 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273
  1. /**
  2. ******************************************************************************
  3. * @file stm32f4xx_hal_ltdc.c
  4. * @author MCD Application Team
  5. * @version V1.4.3
  6. * @date 11-December-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 "stm32f4xx_hal.h"
  89. /** @addtogroup STM32F4xx_HAL_Driver
  90. * @{
  91. */
  92. /** @defgroup LTDC LTDC
  93. * @brief LTDC HAL module driver
  94. * @{
  95. */
  96. #ifdef HAL_LTDC_MODULE_ENABLED
  97. #if defined(STM32F429xx) || defined(STM32F439xx) || defined(STM32F469xx) || defined(STM32F479xx)
  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. /* Prevent unused argument(s) compilation warning */
  224. UNUSED(hltdc);
  225. /* NOTE : This function Should not be modified, when the callback is needed,
  226. the HAL_LTDC_MspInit could be implemented in the user file
  227. */
  228. }
  229. /**
  230. * @brief DeInitializes the LTDC MSP.
  231. * @param hltdc : pointer to a LTDC_HandleTypeDef structure that contains
  232. * the configuration information for the LTDC.
  233. * @retval None
  234. */
  235. __weak void HAL_LTDC_MspDeInit(LTDC_HandleTypeDef* hltdc)
  236. {
  237. /* Prevent unused argument(s) compilation warning */
  238. UNUSED(hltdc);
  239. /* NOTE : This function Should not be modified, when the callback is needed,
  240. the HAL_LTDC_MspDeInit could be implemented in the user file
  241. */
  242. }
  243. /**
  244. * @}
  245. */
  246. /** @defgroup LTDC_Exported_Functions_Group2 IO operation functions
  247. * @brief IO operation functions
  248. *
  249. @verbatim
  250. ===============================================================================
  251. ##### IO operation functions #####
  252. ===============================================================================
  253. [..] This section provides function allowing to:
  254. (+) Handle LTDC interrupt request
  255. @endverbatim
  256. * @{
  257. */
  258. /**
  259. * @brief Handles LTDC interrupt request.
  260. * @param hltdc: pointer to a LTDC_HandleTypeDef structure that contains
  261. * the configuration information for the LTDC.
  262. * @retval HAL status
  263. */
  264. void HAL_LTDC_IRQHandler(LTDC_HandleTypeDef *hltdc)
  265. {
  266. /* Transfer Error Interrupt management ***************************************/
  267. if(__HAL_LTDC_GET_FLAG(hltdc, LTDC_FLAG_TE) != RESET)
  268. {
  269. if(__HAL_LTDC_GET_IT_SOURCE(hltdc, LTDC_IT_TE) != RESET)
  270. {
  271. /* Disable the transfer Error interrupt */
  272. __HAL_LTDC_DISABLE_IT(hltdc, LTDC_IT_TE);
  273. /* Clear the transfer error flag */
  274. __HAL_LTDC_CLEAR_FLAG(hltdc, LTDC_FLAG_TE);
  275. /* Update error code */
  276. hltdc->ErrorCode |= HAL_LTDC_ERROR_TE;
  277. /* Change LTDC state */
  278. hltdc->State = HAL_LTDC_STATE_ERROR;
  279. /* Process unlocked */
  280. __HAL_UNLOCK(hltdc);
  281. /* Transfer error Callback */
  282. HAL_LTDC_ErrorCallback(hltdc);
  283. }
  284. }
  285. /* FIFO underrun Interrupt management ***************************************/
  286. if(__HAL_LTDC_GET_FLAG(hltdc, LTDC_FLAG_FU) != RESET)
  287. {
  288. if(__HAL_LTDC_GET_IT_SOURCE(hltdc, LTDC_IT_FU) != RESET)
  289. {
  290. /* Disable the FIFO underrun interrupt */
  291. __HAL_LTDC_DISABLE_IT(hltdc, LTDC_IT_FU);
  292. /* Clear the FIFO underrun flag */
  293. __HAL_LTDC_CLEAR_FLAG(hltdc, LTDC_FLAG_FU);
  294. /* Update error code */
  295. hltdc->ErrorCode |= HAL_LTDC_ERROR_FU;
  296. /* Change LTDC state */
  297. hltdc->State = HAL_LTDC_STATE_ERROR;
  298. /* Process unlocked */
  299. __HAL_UNLOCK(hltdc);
  300. /* Transfer error Callback */
  301. HAL_LTDC_ErrorCallback(hltdc);
  302. }
  303. }
  304. /* Line Interrupt management ************************************************/
  305. if(__HAL_LTDC_GET_FLAG(hltdc, LTDC_FLAG_LI) != RESET)
  306. {
  307. if(__HAL_LTDC_GET_IT_SOURCE(hltdc, LTDC_IT_LI) != RESET)
  308. {
  309. /* Disable the Line interrupt */
  310. __HAL_LTDC_DISABLE_IT(hltdc, LTDC_IT_LI);
  311. /* Clear the Line interrupt flag */
  312. __HAL_LTDC_CLEAR_FLAG(hltdc, LTDC_FLAG_LI);
  313. /* Change LTDC state */
  314. hltdc->State = HAL_LTDC_STATE_READY;
  315. /* Process unlocked */
  316. __HAL_UNLOCK(hltdc);
  317. /* Line interrupt Callback */
  318. HAL_LTDC_LineEventCallback(hltdc);
  319. }
  320. }
  321. }
  322. /**
  323. * @brief Error LTDC callback.
  324. * @param hltdc: pointer to a LTDC_HandleTypeDef structure that contains
  325. * the configuration information for the LTDC.
  326. * @retval None
  327. */
  328. __weak void HAL_LTDC_ErrorCallback(LTDC_HandleTypeDef *hltdc)
  329. {
  330. /* Prevent unused argument(s) compilation warning */
  331. UNUSED(hltdc);
  332. /* NOTE : This function Should not be modified, when the callback is needed,
  333. the HAL_LTDC_ErrorCallback could be implemented in the user file
  334. */
  335. }
  336. /**
  337. * @brief Line Event callback.
  338. * @param hltdc: pointer to a LTDC_HandleTypeDef structure that contains
  339. * the configuration information for the LTDC.
  340. * @retval None
  341. */
  342. __weak void HAL_LTDC_LineEventCallback(LTDC_HandleTypeDef *hltdc)
  343. {
  344. /* Prevent unused argument(s) compilation warning */
  345. UNUSED(hltdc);
  346. /* NOTE : This function Should not be modified, when the callback is needed,
  347. the HAL_LTDC_LineEventCallback could be implemented in the user file
  348. */
  349. }
  350. /**
  351. * @}
  352. */
  353. /** @defgroup LTDC_Exported_Functions_Group3 Peripheral Control functions
  354. * @brief Peripheral Control functions
  355. *
  356. @verbatim
  357. ===============================================================================
  358. ##### Peripheral Control functions #####
  359. ===============================================================================
  360. [..] This section provides functions allowing to:
  361. (+) Configure the LTDC foreground or/and background parameters.
  362. (+) Set the active layer.
  363. (+) Configure the color keying.
  364. (+) Configure the C-LUT.
  365. (+) Enable / Disable the color keying.
  366. (+) Enable / Disable the C-LUT.
  367. (+) Update the layer position.
  368. (+) Update the layer size.
  369. (+) Update pixel format on the fly.
  370. (+) Update transparency on the fly.
  371. (+) Update address on the fly.
  372. @endverbatim
  373. * @{
  374. */
  375. /**
  376. * @brief Configure the LTDC Layer according to the specified
  377. * parameters in the LTDC_InitTypeDef and create the associated handle.
  378. * @param hltdc: pointer to a LTDC_HandleTypeDef structure that contains
  379. * the configuration information for the LTDC.
  380. * @param pLayerCfg: pointer to a LTDC_LayerCfgTypeDef structure that contains
  381. * the configuration information for the Layer.
  382. * @param LayerIdx: LTDC Layer index.
  383. * This parameter can be one of the following values:
  384. * 0 or 1
  385. * @retval HAL status
  386. */
  387. HAL_StatusTypeDef HAL_LTDC_ConfigLayer(LTDC_HandleTypeDef *hltdc, LTDC_LayerCfgTypeDef *pLayerCfg, uint32_t LayerIdx)
  388. {
  389. /* Process locked */
  390. __HAL_LOCK(hltdc);
  391. /* Change LTDC peripheral state */
  392. hltdc->State = HAL_LTDC_STATE_BUSY;
  393. /* Check the parameters */
  394. assert_param(IS_LTDC_LAYER(LayerIdx));
  395. assert_param(IS_LTDC_PIXEL_FORMAT(pLayerCfg->PixelFormat));
  396. assert_param(IS_LTDC_BLENDING_FACTOR1(pLayerCfg->BlendingFactor1));
  397. assert_param(IS_LTDC_BLENDING_FACTOR2(pLayerCfg->BlendingFactor2));
  398. assert_param(IS_LTDC_HCONFIGST(pLayerCfg->WindowX0));
  399. assert_param(IS_LTDC_HCONFIGSP(pLayerCfg->WindowX1));
  400. assert_param(IS_LTDC_VCONFIGST(pLayerCfg->WindowY0));
  401. assert_param(IS_LTDC_VCONFIGSP(pLayerCfg->WindowY1));
  402. assert_param(IS_LTDC_ALPHA(pLayerCfg->Alpha0));
  403. assert_param(IS_LTDC_CFBLL(pLayerCfg->ImageWidth));
  404. assert_param(IS_LTDC_CFBLNBR(pLayerCfg->ImageHeight));
  405. /* Copy new layer configuration into handle structure */
  406. hltdc->LayerCfg[LayerIdx] = *pLayerCfg;
  407. /* Configure the LTDC Layer */
  408. LTDC_SetConfig(hltdc, pLayerCfg, LayerIdx);
  409. /* Sets the Reload type */
  410. hltdc->Instance->SRCR = LTDC_SRCR_IMR;
  411. /* Initialize the LTDC state*/
  412. hltdc->State = HAL_LTDC_STATE_READY;
  413. /* Process unlocked */
  414. __HAL_UNLOCK(hltdc);
  415. return HAL_OK;
  416. }
  417. /**
  418. * @brief Configure the color keying.
  419. * @param hltdc: pointer to a LTDC_HandleTypeDef structure that contains
  420. * the configuration information for the LTDC.
  421. * @param RGBValue: the color key value
  422. * @param LayerIdx: LTDC Layer index.
  423. * This parameter can be one of the following values:
  424. * 0 or 1
  425. * @retval HAL status
  426. */
  427. HAL_StatusTypeDef HAL_LTDC_ConfigColorKeying(LTDC_HandleTypeDef *hltdc, uint32_t RGBValue, uint32_t LayerIdx)
  428. {
  429. /* Process locked */
  430. __HAL_LOCK(hltdc);
  431. /* Change LTDC peripheral state */
  432. hltdc->State = HAL_LTDC_STATE_BUSY;
  433. /* Check the parameters */
  434. assert_param(IS_LTDC_LAYER(LayerIdx));
  435. /* Configures the default color values */
  436. LTDC_LAYER(hltdc, LayerIdx)->CKCR &= ~(LTDC_LxCKCR_CKBLUE | LTDC_LxCKCR_CKGREEN | LTDC_LxCKCR_CKRED);
  437. LTDC_LAYER(hltdc, LayerIdx)->CKCR = RGBValue;
  438. /* Sets the Reload type */
  439. hltdc->Instance->SRCR = LTDC_SRCR_IMR;
  440. /* Change the LTDC state*/
  441. hltdc->State = HAL_LTDC_STATE_READY;
  442. /* Process unlocked */
  443. __HAL_UNLOCK(hltdc);
  444. return HAL_OK;
  445. }
  446. /**
  447. * @brief Load the color lookup table.
  448. * @param hltdc: pointer to a LTDC_HandleTypeDef structure that contains
  449. * the configuration information for the LTDC.
  450. * @param pCLUT: pointer to the color lookup table address.
  451. * @param CLUTSize: the color lookup table size.
  452. * @param LayerIdx: LTDC Layer index.
  453. * This parameter can be one of the following values:
  454. * 0 or 1
  455. * @retval HAL status
  456. */
  457. HAL_StatusTypeDef HAL_LTDC_ConfigCLUT(LTDC_HandleTypeDef *hltdc, uint32_t *pCLUT, uint32_t CLUTSize, uint32_t LayerIdx)
  458. {
  459. uint32_t tmp = 0;
  460. uint32_t counter = 0;
  461. uint32_t pcounter = 0;
  462. /* Process locked */
  463. __HAL_LOCK(hltdc);
  464. /* Change LTDC peripheral state */
  465. hltdc->State = HAL_LTDC_STATE_BUSY;
  466. /* Check the parameters */
  467. assert_param(IS_LTDC_LAYER(LayerIdx));
  468. for(counter = 0; (counter < CLUTSize); counter++)
  469. {
  470. if(hltdc->LayerCfg[LayerIdx].PixelFormat == LTDC_PIXEL_FORMAT_AL44)
  471. {
  472. tmp = (((counter + 16*counter) << 24) | ((uint32_t)(*pCLUT) & 0xFF) | ((uint32_t)(*pCLUT) & 0xFF00) | ((uint32_t)(*pCLUT) & 0xFF0000));
  473. }
  474. else
  475. {
  476. tmp = ((counter << 24) | ((uint32_t)(*pCLUT) & 0xFF) | ((uint32_t)(*pCLUT) & 0xFF00) | ((uint32_t)(*pCLUT) & 0xFF0000));
  477. }
  478. pcounter = (uint32_t)pCLUT + sizeof(*pCLUT);
  479. pCLUT = (uint32_t *)pcounter;
  480. /* Specifies the C-LUT address and RGB value */
  481. LTDC_LAYER(hltdc, LayerIdx)->CLUTWR = tmp;
  482. }
  483. /* Change the LTDC state*/
  484. hltdc->State = HAL_LTDC_STATE_READY;
  485. /* Process unlocked */
  486. __HAL_UNLOCK(hltdc);
  487. return HAL_OK;
  488. }
  489. /**
  490. * @brief Enable the color keying.
  491. * @param hltdc: pointer to a LTDC_HandleTypeDef structure that contains
  492. * the configuration information for the LTDC.
  493. * @param LayerIdx: LTDC Layer index.
  494. * This parameter can be one of the following values:
  495. * 0 or 1
  496. * @retval HAL status
  497. */
  498. HAL_StatusTypeDef HAL_LTDC_EnableColorKeying(LTDC_HandleTypeDef *hltdc, uint32_t LayerIdx)
  499. {
  500. /* Process locked */
  501. __HAL_LOCK(hltdc);
  502. /* Change LTDC peripheral state */
  503. hltdc->State = HAL_LTDC_STATE_BUSY;
  504. /* Check the parameters */
  505. assert_param(IS_LTDC_LAYER(LayerIdx));
  506. /* Enable LTDC color keying by setting COLKEN bit */
  507. LTDC_LAYER(hltdc, LayerIdx)->CR |= (uint32_t)LTDC_LxCR_COLKEN;
  508. /* Sets the Reload type */
  509. hltdc->Instance->SRCR = LTDC_SRCR_IMR;
  510. /* Change the LTDC state*/
  511. hltdc->State = HAL_LTDC_STATE_READY;
  512. /* Process unlocked */
  513. __HAL_UNLOCK(hltdc);
  514. return HAL_OK;
  515. }
  516. /**
  517. * @brief Disable the color keying.
  518. * @param hltdc: pointer to a LTDC_HandleTypeDef structure that contains
  519. * the configuration information for the LTDC.
  520. * @param LayerIdx: LTDC Layer index.
  521. * This parameter can be one of the following values:
  522. * 0 or 1
  523. * @retval HAL status
  524. */
  525. HAL_StatusTypeDef HAL_LTDC_DisableColorKeying(LTDC_HandleTypeDef *hltdc, uint32_t LayerIdx)
  526. {
  527. /* Process locked */
  528. __HAL_LOCK(hltdc);
  529. /* Change LTDC peripheral state */
  530. hltdc->State = HAL_LTDC_STATE_BUSY;
  531. /* Check the parameters */
  532. assert_param(IS_LTDC_LAYER(LayerIdx));
  533. /* Disable LTDC color keying by setting COLKEN bit */
  534. LTDC_LAYER(hltdc, LayerIdx)->CR &= ~(uint32_t)LTDC_LxCR_COLKEN;
  535. /* Sets the Reload type */
  536. hltdc->Instance->SRCR = LTDC_SRCR_IMR;
  537. /* Change the LTDC state*/
  538. hltdc->State = HAL_LTDC_STATE_READY;
  539. /* Process unlocked */
  540. __HAL_UNLOCK(hltdc);
  541. return HAL_OK;
  542. }
  543. /**
  544. * @brief Enable the color lookup table.
  545. * @param hltdc: pointer to a LTDC_HandleTypeDef structure that contains
  546. * the configuration information for the LTDC.
  547. * @param LayerIdx: LTDC Layer index.
  548. * This parameter can be one of the following values:
  549. * 0 or 1
  550. * @retval HAL status
  551. */
  552. HAL_StatusTypeDef HAL_LTDC_EnableCLUT(LTDC_HandleTypeDef *hltdc, uint32_t LayerIdx)
  553. {
  554. /* Process locked */
  555. __HAL_LOCK(hltdc);
  556. /* Change LTDC peripheral state */
  557. hltdc->State = HAL_LTDC_STATE_BUSY;
  558. /* Check the parameters */
  559. assert_param(IS_LTDC_LAYER(LayerIdx));
  560. /* Disable LTDC color lookup table by setting CLUTEN bit */
  561. LTDC_LAYER(hltdc, LayerIdx)->CR |= (uint32_t)LTDC_LxCR_CLUTEN;
  562. /* Sets the Reload type */
  563. hltdc->Instance->SRCR = LTDC_SRCR_IMR;
  564. /* Change the LTDC state*/
  565. hltdc->State = HAL_LTDC_STATE_READY;
  566. /* Process unlocked */
  567. __HAL_UNLOCK(hltdc);
  568. return HAL_OK;
  569. }
  570. /**
  571. * @brief Disable the color lookup table.
  572. * @param hltdc: pointer to a LTDC_HandleTypeDef structure that contains
  573. * the configuration information for the LTDC.
  574. * @param LayerIdx: LTDC Layer index.
  575. * This parameter can be one of the following values:
  576. * 0 or 1
  577. * @retval HAL status
  578. */
  579. HAL_StatusTypeDef HAL_LTDC_DisableCLUT(LTDC_HandleTypeDef *hltdc, uint32_t LayerIdx)
  580. {
  581. /* Process locked */
  582. __HAL_LOCK(hltdc);
  583. /* Change LTDC peripheral state */
  584. hltdc->State = HAL_LTDC_STATE_BUSY;
  585. /* Check the parameters */
  586. assert_param(IS_LTDC_LAYER(LayerIdx));
  587. /* Disable LTDC color lookup table by setting CLUTEN bit */
  588. LTDC_LAYER(hltdc, LayerIdx)->CR &= ~(uint32_t)LTDC_LxCR_CLUTEN;
  589. /* Sets the Reload type */
  590. hltdc->Instance->SRCR = LTDC_SRCR_IMR;
  591. /* Change the LTDC state*/
  592. hltdc->State = HAL_LTDC_STATE_READY;
  593. /* Process unlocked */
  594. __HAL_UNLOCK(hltdc);
  595. return HAL_OK;
  596. }
  597. /**
  598. * @brief Enables Dither.
  599. * @param hltdc: pointer to a LTDC_HandleTypeDef structure that contains
  600. * the configuration information for the LTDC.
  601. * @retval HAL status
  602. */
  603. HAL_StatusTypeDef HAL_LTDC_EnableDither(LTDC_HandleTypeDef *hltdc)
  604. {
  605. /* Process locked */
  606. __HAL_LOCK(hltdc);
  607. /* Change LTDC peripheral state */
  608. hltdc->State = HAL_LTDC_STATE_BUSY;
  609. /* Enable Dither by setting DTEN bit */
  610. LTDC->GCR |= (uint32_t)LTDC_GCR_DTEN;
  611. /* Change the LTDC state*/
  612. hltdc->State = HAL_LTDC_STATE_READY;
  613. /* Process unlocked */
  614. __HAL_UNLOCK(hltdc);
  615. return HAL_OK;
  616. }
  617. /**
  618. * @brief Disables Dither.
  619. * @param hltdc: pointer to a LTDC_HandleTypeDef structure that contains
  620. * the configuration information for the LTDC.
  621. * @retval HAL status
  622. */
  623. HAL_StatusTypeDef HAL_LTDC_DisableDither(LTDC_HandleTypeDef *hltdc)
  624. {
  625. /* Process locked */
  626. __HAL_LOCK(hltdc);
  627. /* Change LTDC peripheral state */
  628. hltdc->State = HAL_LTDC_STATE_BUSY;
  629. /* Disable Dither by setting DTEN bit */
  630. LTDC->GCR &= ~(uint32_t)LTDC_GCR_DTEN;
  631. /* Change the LTDC state*/
  632. hltdc->State = HAL_LTDC_STATE_READY;
  633. /* Process unlocked */
  634. __HAL_UNLOCK(hltdc);
  635. return HAL_OK;
  636. }
  637. /**
  638. * @brief Set the LTDC window size.
  639. * @param hltdc: pointer to a LTDC_HandleTypeDef structure that contains
  640. * the configuration information for the LTDC.
  641. * @param XSize: LTDC Pixel per line
  642. * @param YSize: LTDC Line number
  643. * @param LayerIdx: LTDC Layer index.
  644. * This parameter can be one of the following values:
  645. * 0 or 1
  646. * @retval HAL status
  647. */
  648. HAL_StatusTypeDef HAL_LTDC_SetWindowSize(LTDC_HandleTypeDef *hltdc, uint32_t XSize, uint32_t YSize, uint32_t LayerIdx)
  649. {
  650. LTDC_LayerCfgTypeDef *pLayerCfg;
  651. /* Process locked */
  652. __HAL_LOCK(hltdc);
  653. /* Change LTDC peripheral state */
  654. hltdc->State = HAL_LTDC_STATE_BUSY;
  655. /* Get layer configuration from handle structure */
  656. pLayerCfg = &hltdc->LayerCfg[LayerIdx];
  657. /* Check the parameters (Layers parameters)*/
  658. assert_param(IS_LTDC_LAYER(LayerIdx));
  659. assert_param(IS_LTDC_HCONFIGST(pLayerCfg->WindowX0));
  660. assert_param(IS_LTDC_HCONFIGSP(pLayerCfg->WindowX1));
  661. assert_param(IS_LTDC_VCONFIGST(pLayerCfg->WindowY0));
  662. assert_param(IS_LTDC_VCONFIGSP(pLayerCfg->WindowY1));
  663. assert_param(IS_LTDC_CFBLL(XSize));
  664. assert_param(IS_LTDC_CFBLNBR(YSize));
  665. /* update horizontal start/stop */
  666. pLayerCfg->WindowX0 = 0;
  667. pLayerCfg->WindowX1 = XSize + pLayerCfg->WindowX0;
  668. /* update vertical start/stop */
  669. pLayerCfg->WindowY0 = 0;
  670. pLayerCfg->WindowY1 = YSize + pLayerCfg->WindowY0;
  671. /* Reconfigures the color frame buffer pitch in byte */
  672. pLayerCfg->ImageWidth = XSize;
  673. /* Reconfigures the frame buffer line number */
  674. pLayerCfg->ImageHeight = YSize;
  675. /* Set LTDC parameters */
  676. LTDC_SetConfig(hltdc, pLayerCfg, LayerIdx);
  677. /* Sets the Reload type */
  678. hltdc->Instance->SRCR = LTDC_SRCR_IMR;
  679. /* Change the LTDC state*/
  680. hltdc->State = HAL_LTDC_STATE_READY;
  681. /* Process unlocked */
  682. __HAL_UNLOCK(hltdc);
  683. return HAL_OK;
  684. }
  685. /**
  686. * @brief Set the LTDC window position.
  687. * @param hltdc: pointer to a LTDC_HandleTypeDef structure that contains
  688. * the configuration information for the LTDC.
  689. * @param X0: LTDC window X offset
  690. * @param Y0: LTDC window Y offset
  691. * @param LayerIdx: LTDC Layer index.
  692. * This parameter can be one of the following values:
  693. * 0 or 1
  694. * @retval HAL status
  695. */
  696. HAL_StatusTypeDef HAL_LTDC_SetWindowPosition(LTDC_HandleTypeDef *hltdc, uint32_t X0, uint32_t Y0, uint32_t LayerIdx)
  697. {
  698. LTDC_LayerCfgTypeDef *pLayerCfg;
  699. /* Process locked */
  700. __HAL_LOCK(hltdc);
  701. /* Change LTDC peripheral state */
  702. hltdc->State = HAL_LTDC_STATE_BUSY;
  703. /* Get layer configuration from handle structure */
  704. pLayerCfg = &hltdc->LayerCfg[LayerIdx];
  705. /* Check the parameters */
  706. assert_param(IS_LTDC_LAYER(LayerIdx));
  707. assert_param(IS_LTDC_HCONFIGST(pLayerCfg->WindowX0));
  708. assert_param(IS_LTDC_HCONFIGSP(pLayerCfg->WindowX1));
  709. assert_param(IS_LTDC_VCONFIGST(pLayerCfg->WindowY0));
  710. assert_param(IS_LTDC_VCONFIGSP(pLayerCfg->WindowY1));
  711. /* update horizontal start/stop */
  712. pLayerCfg->WindowX0 = X0;
  713. pLayerCfg->WindowX1 = X0 + pLayerCfg->ImageWidth;
  714. /* update vertical start/stop */
  715. pLayerCfg->WindowY0 = Y0;
  716. pLayerCfg->WindowY1 = Y0 + pLayerCfg->ImageHeight;
  717. /* Set LTDC parameters */
  718. LTDC_SetConfig(hltdc, pLayerCfg, LayerIdx);
  719. /* Sets the Reload type */
  720. hltdc->Instance->SRCR = LTDC_SRCR_IMR;
  721. /* Change the LTDC state*/
  722. hltdc->State = HAL_LTDC_STATE_READY;
  723. /* Process unlocked */
  724. __HAL_UNLOCK(hltdc);
  725. return HAL_OK;
  726. }
  727. /**
  728. * @brief Reconfigure the pixel format.
  729. * @param hltdc: pointer to a LTDC_HandleTypeDef structure that contains
  730. * the configuration information for the LTDC.
  731. * @param Pixelformat: new pixel format value.
  732. * @param LayerIdx: LTDC Layer index.
  733. * This parameter can be one of the following values:
  734. * 0 or 1.
  735. * @retval HAL status
  736. */
  737. HAL_StatusTypeDef HAL_LTDC_SetPixelFormat(LTDC_HandleTypeDef *hltdc, uint32_t Pixelformat, uint32_t LayerIdx)
  738. {
  739. LTDC_LayerCfgTypeDef *pLayerCfg;
  740. /* Process locked */
  741. __HAL_LOCK(hltdc);
  742. /* Change LTDC peripheral state */
  743. hltdc->State = HAL_LTDC_STATE_BUSY;
  744. /* Check the parameters */
  745. assert_param(IS_LTDC_LAYER(LayerIdx));
  746. assert_param(IS_LTDC_PIXEL_FORMAT(Pixelformat));
  747. /* Get layer configuration from handle structure */
  748. pLayerCfg = &hltdc->LayerCfg[LayerIdx];
  749. /* Reconfigure the pixel format */
  750. pLayerCfg->PixelFormat = Pixelformat;
  751. /* Set LTDC parameters */
  752. LTDC_SetConfig(hltdc, pLayerCfg, LayerIdx);
  753. /* Sets the Reload type */
  754. hltdc->Instance->SRCR = LTDC_SRCR_IMR;
  755. /* Change the LTDC state*/
  756. hltdc->State = HAL_LTDC_STATE_READY;
  757. /* Process unlocked */
  758. __HAL_UNLOCK(hltdc);
  759. return HAL_OK;
  760. }
  761. /**
  762. * @brief Reconfigure the layer alpha value.
  763. * @param hltdc: pointer to a LTDC_HandleTypeDef structure that contains
  764. * the configuration information for the LTDC.
  765. * @param Alpha: new alpha value.
  766. * @param LayerIdx: LTDC Layer index.
  767. * This parameter can be one of the following values:
  768. * 0 or 1
  769. * @retval HAL status
  770. */
  771. HAL_StatusTypeDef HAL_LTDC_SetAlpha(LTDC_HandleTypeDef *hltdc, uint32_t Alpha, uint32_t LayerIdx)
  772. {
  773. LTDC_LayerCfgTypeDef *pLayerCfg;
  774. /* Process locked */
  775. __HAL_LOCK(hltdc);
  776. /* Change LTDC peripheral state */
  777. hltdc->State = HAL_LTDC_STATE_BUSY;
  778. /* Check the parameters */
  779. assert_param(IS_LTDC_ALPHA(Alpha));
  780. assert_param(IS_LTDC_LAYER(LayerIdx));
  781. /* Get layer configuration from handle structure */
  782. pLayerCfg = &hltdc->LayerCfg[LayerIdx];
  783. /* Reconfigure the Alpha value */
  784. pLayerCfg->Alpha = Alpha;
  785. /* Set LTDC parameters */
  786. LTDC_SetConfig(hltdc, pLayerCfg, LayerIdx);
  787. /* Sets the Reload type */
  788. hltdc->Instance->SRCR = LTDC_SRCR_IMR;
  789. /* Change the LTDC state*/
  790. hltdc->State = HAL_LTDC_STATE_READY;
  791. /* Process unlocked */
  792. __HAL_UNLOCK(hltdc);
  793. return HAL_OK;
  794. }
  795. /**
  796. * @brief Reconfigure the frame buffer Address.
  797. * @param hltdc: pointer to a LTDC_HandleTypeDef structure that contains
  798. * the configuration information for the LTDC.
  799. * @param Address: new address value.
  800. * @param LayerIdx: LTDC Layer index.
  801. * This parameter can be one of the following values:
  802. * 0 or 1.
  803. * @retval HAL status
  804. */
  805. HAL_StatusTypeDef HAL_LTDC_SetAddress(LTDC_HandleTypeDef *hltdc, uint32_t Address, uint32_t LayerIdx)
  806. {
  807. LTDC_LayerCfgTypeDef *pLayerCfg;
  808. /* Process locked */
  809. __HAL_LOCK(hltdc);
  810. /* Change LTDC peripheral state */
  811. hltdc->State = HAL_LTDC_STATE_BUSY;
  812. /* Check the parameters */
  813. assert_param(IS_LTDC_LAYER(LayerIdx));
  814. /* Get layer configuration from handle structure */
  815. pLayerCfg = &hltdc->LayerCfg[LayerIdx];
  816. /* Reconfigure the Address */
  817. pLayerCfg->FBStartAdress = Address;
  818. /* Set LTDC parameters */
  819. LTDC_SetConfig(hltdc, pLayerCfg, LayerIdx);
  820. /* Sets the Reload type */
  821. hltdc->Instance->SRCR = LTDC_SRCR_IMR;
  822. /* Change the LTDC state*/
  823. hltdc->State = HAL_LTDC_STATE_READY;
  824. /* Process unlocked */
  825. __HAL_UNLOCK(hltdc);
  826. return HAL_OK;
  827. }
  828. /**
  829. * @brief Function used to reconfigure the pitch for specific cases where the attached LayerIdx buffer have a width that is
  830. * larger than the one intended to be displayed on screen. Example of a buffer 800x480 attached to layer for which we
  831. * want to read and display on screen only a portion 320x240 taken in the center of the buffer. The pitch in pixels
  832. * will be in that case 800 pixels and not 320 pixels as initially configured by previous call to HAL_LTDC_ConfigLayer().
  833. * Note : this function should be called only after a previous call to HAL_LTDC_ConfigLayer() to modify the default pitch
  834. * configured by HAL_LTDC_ConfigLayer() when required (refer to example described just above).
  835. * @param hltdc: pointer to a LTDC_HandleTypeDef structure that contains
  836. * the configuration information for the LTDC.
  837. * @param LinePitchInPixels: New line pitch in pixels to configure for LTDC layer 'LayerIdx'.
  838. * @param LayerIdx: LTDC layer index concerned by the modification of line pitch.
  839. * @retval HAL status
  840. */
  841. HAL_StatusTypeDef HAL_LTDC_SetPitch(LTDC_HandleTypeDef *hltdc, uint32_t LinePitchInPixels, uint32_t LayerIdx)
  842. {
  843. uint32_t tmp = 0;
  844. uint32_t pitchUpdate = 0;
  845. uint32_t pixelFormat = 0;
  846. /* Process locked */
  847. __HAL_LOCK(hltdc);
  848. /* Change LTDC peripheral state */
  849. hltdc->State = HAL_LTDC_STATE_BUSY;
  850. /* Check the parameters */
  851. assert_param(IS_LTDC_LAYER(LayerIdx));
  852. /* get LayerIdx used pixel format */
  853. pixelFormat = hltdc->LayerCfg[LayerIdx].PixelFormat;
  854. if(pixelFormat == LTDC_PIXEL_FORMAT_ARGB8888)
  855. {
  856. tmp = 4;
  857. }
  858. else if (pixelFormat == LTDC_PIXEL_FORMAT_RGB888)
  859. {
  860. tmp = 3;
  861. }
  862. else if((pixelFormat == LTDC_PIXEL_FORMAT_ARGB4444) || \
  863. (pixelFormat == LTDC_PIXEL_FORMAT_RGB565) || \
  864. (pixelFormat == LTDC_PIXEL_FORMAT_ARGB1555) || \
  865. (pixelFormat == LTDC_PIXEL_FORMAT_AL88))
  866. {
  867. tmp = 2;
  868. }
  869. else
  870. {
  871. tmp = 1;
  872. }
  873. pitchUpdate = ((LinePitchInPixels * tmp) << 16);
  874. /* Clear previously set standard pitch */
  875. LTDC_LAYER(hltdc, LayerIdx)->CFBLR &= ~LTDC_LxCFBLR_CFBP;
  876. /* Sets the Reload type as immediate update of LTDC pitch configured above */
  877. LTDC->SRCR |= LTDC_SRCR_IMR;
  878. /* Set new line pitch value */
  879. LTDC_LAYER(hltdc, LayerIdx)->CFBLR |= pitchUpdate;
  880. /* Sets the Reload type as immediate update of LTDC pitch configured above */
  881. LTDC->SRCR |= LTDC_SRCR_IMR;
  882. /* Change the LTDC state*/
  883. hltdc->State = HAL_LTDC_STATE_READY;
  884. /* Process unlocked */
  885. __HAL_UNLOCK(hltdc);
  886. return HAL_OK;
  887. }
  888. /**
  889. * @brief Define the position of the line interrupt .
  890. * @param hltdc: pointer to a LTDC_HandleTypeDef structure that contains
  891. * the configuration information for the LTDC.
  892. * @param Line: Line Interrupt Position.
  893. * @retval HAL status
  894. */
  895. HAL_StatusTypeDef HAL_LTDC_ProgramLineEvent(LTDC_HandleTypeDef *hltdc, uint32_t Line)
  896. {
  897. /* Process locked */
  898. __HAL_LOCK(hltdc);
  899. /* Change LTDC peripheral state */
  900. hltdc->State = HAL_LTDC_STATE_BUSY;
  901. /* Check the parameters */
  902. assert_param(IS_LTDC_LIPOS(Line));
  903. /* Enable the Line interrupt */
  904. __HAL_LTDC_ENABLE_IT(hltdc, LTDC_IT_LI);
  905. /* Sets the Line Interrupt position */
  906. LTDC->LIPCR = (uint32_t)Line;
  907. /* Change the LTDC state*/
  908. hltdc->State = HAL_LTDC_STATE_READY;
  909. /* Process unlocked */
  910. __HAL_UNLOCK(hltdc);
  911. return HAL_OK;
  912. }
  913. /**
  914. * @}
  915. */
  916. /** @defgroup LTDC_Exported_Functions_Group4 Peripheral State and Errors functions
  917. * @brief Peripheral State and Errors functions
  918. *
  919. @verbatim
  920. ===============================================================================
  921. ##### Peripheral State and Errors functions #####
  922. ===============================================================================
  923. [..]
  924. This subsection provides functions allowing to
  925. (+) Check the LTDC state.
  926. (+) Get error code.
  927. @endverbatim
  928. * @{
  929. */
  930. /**
  931. * @brief Return the LTDC state
  932. * @param hltdc: pointer to a LTDC_HandleTypeDef structure that contains
  933. * the configuration information for the LTDC.
  934. * @retval HAL state
  935. */
  936. HAL_LTDC_StateTypeDef HAL_LTDC_GetState(LTDC_HandleTypeDef *hltdc)
  937. {
  938. return hltdc->State;
  939. }
  940. /**
  941. * @brief Return the LTDC error code
  942. * @param hltdc : pointer to a LTDC_HandleTypeDef structure that contains
  943. * the configuration information for the LTDC.
  944. * @retval LTDC Error Code
  945. */
  946. uint32_t HAL_LTDC_GetError(LTDC_HandleTypeDef *hltdc)
  947. {
  948. return hltdc->ErrorCode;
  949. }
  950. /**
  951. * @}
  952. */
  953. /**
  954. * @brief Configures the LTDC peripheral
  955. * @param hltdc : Pointer to a LTDC_HandleTypeDef structure that contains
  956. * the configuration information for the LTDC.
  957. * @param pLayerCfg: Pointer LTDC Layer Configuration structure
  958. * @param LayerIdx: LTDC Layer index.
  959. * This parameter can be one of the following values: 0 or 1
  960. * @retval None
  961. */
  962. static void LTDC_SetConfig(LTDC_HandleTypeDef *hltdc, LTDC_LayerCfgTypeDef *pLayerCfg, uint32_t LayerIdx)
  963. {
  964. uint32_t tmp = 0;
  965. uint32_t tmp1 = 0;
  966. uint32_t tmp2 = 0;
  967. /* Configures the horizontal start and stop position */
  968. tmp = ((pLayerCfg->WindowX1 + ((hltdc->Instance->BPCR & LTDC_BPCR_AHBP) >> 16)) << 16);
  969. LTDC_LAYER(hltdc, LayerIdx)->WHPCR &= ~(LTDC_LxWHPCR_WHSTPOS | LTDC_LxWHPCR_WHSPPOS);
  970. LTDC_LAYER(hltdc, LayerIdx)->WHPCR = ((pLayerCfg->WindowX0 + ((hltdc->Instance->BPCR & LTDC_BPCR_AHBP) >> 16) + 1) | tmp);
  971. /* Configures the vertical start and stop position */
  972. tmp = ((pLayerCfg->WindowY1 + (hltdc->Instance->BPCR & LTDC_BPCR_AVBP)) << 16);
  973. LTDC_LAYER(hltdc, LayerIdx)->WVPCR &= ~(LTDC_LxWVPCR_WVSTPOS | LTDC_LxWVPCR_WVSPPOS);
  974. LTDC_LAYER(hltdc, LayerIdx)->WVPCR = ((pLayerCfg->WindowY0 + (hltdc->Instance->BPCR & LTDC_BPCR_AVBP) + 1) | tmp);
  975. /* Specifies the pixel format */
  976. LTDC_LAYER(hltdc, LayerIdx)->PFCR &= ~(LTDC_LxPFCR_PF);
  977. LTDC_LAYER(hltdc, LayerIdx)->PFCR = (pLayerCfg->PixelFormat);
  978. /* Configures the default color values */
  979. tmp = ((uint32_t)(pLayerCfg->Backcolor.Green) << 8);
  980. tmp1 = ((uint32_t)(pLayerCfg->Backcolor.Red) << 16);
  981. tmp2 = (pLayerCfg->Alpha0 << 24);
  982. LTDC_LAYER(hltdc, LayerIdx)->DCCR &= ~(LTDC_LxDCCR_DCBLUE | LTDC_LxDCCR_DCGREEN | LTDC_LxDCCR_DCRED | LTDC_LxDCCR_DCALPHA);
  983. LTDC_LAYER(hltdc, LayerIdx)->DCCR = (pLayerCfg->Backcolor.Blue | tmp | tmp1 | tmp2);
  984. /* Specifies the constant alpha value */
  985. LTDC_LAYER(hltdc, LayerIdx)->CACR &= ~(LTDC_LxCACR_CONSTA);
  986. LTDC_LAYER(hltdc, LayerIdx)->CACR = (pLayerCfg->Alpha);
  987. /* Specifies the blending factors */
  988. LTDC_LAYER(hltdc, LayerIdx)->BFCR &= ~(LTDC_LxBFCR_BF2 | LTDC_LxBFCR_BF1);
  989. LTDC_LAYER(hltdc, LayerIdx)->BFCR = (pLayerCfg->BlendingFactor1 | pLayerCfg->BlendingFactor2);
  990. /* Configures the color frame buffer start address */
  991. LTDC_LAYER(hltdc, LayerIdx)->CFBAR &= ~(LTDC_LxCFBAR_CFBADD);
  992. LTDC_LAYER(hltdc, LayerIdx)->CFBAR = (pLayerCfg->FBStartAdress);
  993. if(pLayerCfg->PixelFormat == LTDC_PIXEL_FORMAT_ARGB8888)
  994. {
  995. tmp = 4;
  996. }
  997. else if (pLayerCfg->PixelFormat == LTDC_PIXEL_FORMAT_RGB888)
  998. {
  999. tmp = 3;
  1000. }
  1001. else if((pLayerCfg->PixelFormat == LTDC_PIXEL_FORMAT_ARGB4444) || \
  1002. (pLayerCfg->PixelFormat == LTDC_PIXEL_FORMAT_RGB565) || \
  1003. (pLayerCfg->PixelFormat == LTDC_PIXEL_FORMAT_ARGB1555) || \
  1004. (pLayerCfg->PixelFormat == LTDC_PIXEL_FORMAT_AL88))
  1005. {
  1006. tmp = 2;
  1007. }
  1008. else
  1009. {
  1010. tmp = 1;
  1011. }
  1012. /* Configures the color frame buffer pitch in byte */
  1013. LTDC_LAYER(hltdc, LayerIdx)->CFBLR &= ~(LTDC_LxCFBLR_CFBLL | LTDC_LxCFBLR_CFBP);
  1014. LTDC_LAYER(hltdc, LayerIdx)->CFBLR = (((pLayerCfg->ImageWidth * tmp) << 16) | (((pLayerCfg->WindowX1 - pLayerCfg->WindowX0) * tmp) + 3));
  1015. /* Configures the frame buffer line number */
  1016. LTDC_LAYER(hltdc, LayerIdx)->CFBLNR &= ~(LTDC_LxCFBLNR_CFBLNBR);
  1017. LTDC_LAYER(hltdc, LayerIdx)->CFBLNR = (pLayerCfg->ImageHeight);
  1018. /* Enable LTDC_Layer by setting LEN bit */
  1019. LTDC_LAYER(hltdc, LayerIdx)->CR |= (uint32_t)LTDC_LxCR_LEN;
  1020. }
  1021. /**
  1022. * @}
  1023. */
  1024. #endif /* STM32F429xx || STM32F439xx || STM32F469xx || STM32F479xx */
  1025. #endif /* HAL_LTDC_MODULE_ENABLED */
  1026. /**
  1027. * @}
  1028. */
  1029. /**
  1030. * @}
  1031. */
  1032. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/