训练营PLSR题目
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。
 
 
 
 
 
 

2216 行
70 KiB

  1. /**
  2. ******************************************************************************
  3. * @file stm32f4xx_hal_ltdc.c
  4. * @author MCD Application Team
  5. * @brief LTDC HAL module driver.
  6. * This file provides firmware functions to manage the following
  7. * functionalities of the LTDC peripheral:
  8. * + Initialization and de-initialization functions
  9. * + IO operation functions
  10. * + Peripheral Control functions
  11. * + Peripheral State and Errors functions
  12. *
  13. ******************************************************************************
  14. * @attention
  15. *
  16. * Copyright (c) 2016 STMicroelectronics.
  17. * All rights reserved.
  18. *
  19. * This software is licensed under terms that can be found in the LICENSE file
  20. * in the root directory of this software component.
  21. * If no LICENSE file comes with this software, it is provided AS-IS.
  22. *
  23. ******************************************************************************
  24. @verbatim
  25. ==============================================================================
  26. ##### How to use this driver #####
  27. ==============================================================================
  28. [..]
  29. The LTDC HAL driver can be used as follows:
  30. (#) Declare a LTDC_HandleTypeDef handle structure, for example: LTDC_HandleTypeDef hltdc;
  31. (#) Initialize the LTDC low level resources by implementing the HAL_LTDC_MspInit() API:
  32. (##) Enable the LTDC interface clock
  33. (##) NVIC configuration if you need to use interrupt process
  34. (+++) Configure the LTDC interrupt priority
  35. (+++) Enable the NVIC LTDC IRQ Channel
  36. (#) Initialize the required configuration through the following parameters:
  37. the LTDC timing, the horizontal and vertical polarity, the pixel clock polarity,
  38. Data Enable polarity and the LTDC background color value using HAL_LTDC_Init() function
  39. *** Configuration ***
  40. =========================
  41. [..]
  42. (#) Program the required configuration through the following parameters:
  43. the pixel format, the blending factors, input alpha value, the window size
  44. and the image size using HAL_LTDC_ConfigLayer() function for foreground
  45. or/and background layer.
  46. (#) Optionally, configure and enable the CLUT using HAL_LTDC_ConfigCLUT() and
  47. HAL_LTDC_EnableCLUT functions.
  48. (#) Optionally, enable the Dither using HAL_LTDC_EnableDither().
  49. (#) Optionally, configure and enable the Color keying using HAL_LTDC_ConfigColorKeying()
  50. and HAL_LTDC_EnableColorKeying functions.
  51. (#) Optionally, configure LineInterrupt using HAL_LTDC_ProgramLineEvent()
  52. function
  53. (#) If needed, reconfigure and change the pixel format value, the alpha value
  54. value, the window size, the window position and the layer start address
  55. for foreground or/and background layer using respectively the following
  56. functions: HAL_LTDC_SetPixelFormat(), HAL_LTDC_SetAlpha(), HAL_LTDC_SetWindowSize(),
  57. HAL_LTDC_SetWindowPosition() and HAL_LTDC_SetAddress().
  58. (#) Variant functions with _NoReload suffix allows to set the LTDC configuration/settings without immediate reload.
  59. This is useful in case when the program requires to modify serval LTDC settings (on one or both layers)
  60. then applying(reload) these settings in one shot by calling the function HAL_LTDC_Reload().
  61. After calling the _NoReload functions to set different color/format/layer settings,
  62. the program shall call the function HAL_LTDC_Reload() to apply(reload) these settings.
  63. Function HAL_LTDC_Reload() can be called with the parameter ReloadType set to LTDC_RELOAD_IMMEDIATE if
  64. an immediate reload is required.
  65. Function HAL_LTDC_Reload() can be called with the parameter ReloadType set to LTDC_RELOAD_VERTICAL_BLANKING if
  66. the reload should be done in the next vertical blanking period,
  67. this option allows to avoid display flicker by applying the new settings during the vertical blanking period.
  68. (#) To control LTDC state you can use the following function: HAL_LTDC_GetState()
  69. *** LTDC HAL driver macros list ***
  70. =============================================
  71. [..]
  72. Below the list of most used macros in LTDC HAL driver.
  73. (+) __HAL_LTDC_ENABLE: Enable the LTDC.
  74. (+) __HAL_LTDC_DISABLE: Disable the LTDC.
  75. (+) __HAL_LTDC_LAYER_ENABLE: Enable an LTDC Layer.
  76. (+) __HAL_LTDC_LAYER_DISABLE: Disable an LTDC Layer.
  77. (+) __HAL_LTDC_RELOAD_IMMEDIATE_CONFIG: Reload Layer Configuration.
  78. (+) __HAL_LTDC_GET_FLAG: Get the LTDC pending flags.
  79. (+) __HAL_LTDC_CLEAR_FLAG: Clear the LTDC pending flags.
  80. (+) __HAL_LTDC_ENABLE_IT: Enable the specified LTDC interrupts.
  81. (+) __HAL_LTDC_DISABLE_IT: Disable the specified LTDC interrupts.
  82. (+) __HAL_LTDC_GET_IT_SOURCE: Check whether the specified LTDC interrupt has occurred or not.
  83. [..]
  84. (@) You can refer to the LTDC HAL driver header file for more useful macros
  85. *** Callback registration ***
  86. =============================================
  87. [..]
  88. The compilation define USE_HAL_LTDC_REGISTER_CALLBACKS when set to 1
  89. allows the user to configure dynamically the driver callbacks.
  90. Use function HAL_LTDC_RegisterCallback() to register a callback.
  91. [..]
  92. Function HAL_LTDC_RegisterCallback() allows to register following callbacks:
  93. (+) LineEventCallback : LTDC Line Event Callback.
  94. (+) ReloadEventCallback : LTDC Reload Event Callback.
  95. (+) ErrorCallback : LTDC Error Callback
  96. (+) MspInitCallback : LTDC MspInit.
  97. (+) MspDeInitCallback : LTDC MspDeInit.
  98. [..]
  99. This function takes as parameters the HAL peripheral handle, the callback ID
  100. and a pointer to the user callback function.
  101. [..]
  102. Use function HAL_LTDC_UnRegisterCallback() to reset a callback to the default
  103. weak function.
  104. HAL_LTDC_UnRegisterCallback() takes as parameters the HAL peripheral handle
  105. and the callback ID.
  106. [..]
  107. This function allows to reset following callbacks:
  108. (+) LineEventCallback : LTDC Line Event Callback
  109. (+) ReloadEventCallback : LTDC Reload Event Callback
  110. (+) ErrorCallback : LTDC Error Callback
  111. (+) MspInitCallback : LTDC MspInit
  112. (+) MspDeInitCallback : LTDC MspDeInit.
  113. [..]
  114. By default, after the HAL_LTDC_Init and when the state is HAL_LTDC_STATE_RESET
  115. all callbacks are set to the corresponding weak functions:
  116. examples HAL_LTDC_LineEventCallback(), HAL_LTDC_ErrorCallback().
  117. Exception done for MspInit and MspDeInit functions that are
  118. reset to the legacy weak (surcharged) functions in the HAL_LTDC_Init() and HAL_LTDC_DeInit()
  119. only when these callbacks are null (not registered beforehand).
  120. If not, MspInit or MspDeInit are not null, the HAL_LTDC_Init() and HAL_LTDC_DeInit()
  121. keep and use the user MspInit/MspDeInit callbacks (registered beforehand).
  122. [..]
  123. Callbacks can be registered/unregistered in HAL_LTDC_STATE_READY state only.
  124. Exception done MspInit/MspDeInit that can be registered/unregistered
  125. in HAL_LTDC_STATE_READY or HAL_LTDC_STATE_RESET state,
  126. thus registered (user) MspInit/DeInit callbacks can be used during the Init/DeInit.
  127. In that case first register the MspInit/MspDeInit user callbacks
  128. using HAL_LTDC_RegisterCallback() before calling HAL_LTDC_DeInit()
  129. or HAL_LTDC_Init() function.
  130. [..]
  131. When the compilation define USE_HAL_LTDC_REGISTER_CALLBACKS is set to 0 or
  132. not defined, the callback registration feature is not available and all callbacks
  133. are set to the corresponding weak functions.
  134. @endverbatim
  135. ******************************************************************************
  136. */
  137. /* Includes ------------------------------------------------------------------*/
  138. #include "stm32f4xx_hal.h"
  139. /** @addtogroup STM32F4xx_HAL_Driver
  140. * @{
  141. */
  142. #ifdef HAL_LTDC_MODULE_ENABLED
  143. #if defined (LTDC)
  144. /** @defgroup LTDC LTDC
  145. * @brief LTDC HAL module driver
  146. * @{
  147. */
  148. /* Private typedef -----------------------------------------------------------*/
  149. /* Private define ------------------------------------------------------------*/
  150. #define LTDC_TIMEOUT_VALUE ((uint32_t)100U) /* 100ms */
  151. /* Private macro -------------------------------------------------------------*/
  152. /* Private variables ---------------------------------------------------------*/
  153. /* Private function prototypes -----------------------------------------------*/
  154. static void LTDC_SetConfig(LTDC_HandleTypeDef *hltdc, LTDC_LayerCfgTypeDef *pLayerCfg, uint32_t LayerIdx);
  155. /* Private functions ---------------------------------------------------------*/
  156. /** @defgroup LTDC_Exported_Functions LTDC Exported Functions
  157. * @{
  158. */
  159. /** @defgroup LTDC_Exported_Functions_Group1 Initialization and Configuration functions
  160. * @brief Initialization and Configuration functions
  161. *
  162. @verbatim
  163. ===============================================================================
  164. ##### Initialization and Configuration functions #####
  165. ===============================================================================
  166. [..] This section provides functions allowing to:
  167. (+) Initialize and configure the LTDC
  168. (+) De-initialize the LTDC
  169. @endverbatim
  170. * @{
  171. */
  172. /**
  173. * @brief Initialize the LTDC according to the specified parameters in the LTDC_InitTypeDef.
  174. * @param hltdc pointer to a LTDC_HandleTypeDef structure that contains
  175. * the configuration information for the LTDC.
  176. * @retval HAL status
  177. */
  178. HAL_StatusTypeDef HAL_LTDC_Init(LTDC_HandleTypeDef *hltdc)
  179. {
  180. uint32_t tmp;
  181. uint32_t tmp1;
  182. /* Check the LTDC peripheral state */
  183. if (hltdc == NULL)
  184. {
  185. return HAL_ERROR;
  186. }
  187. /* Check function parameters */
  188. assert_param(IS_LTDC_ALL_INSTANCE(hltdc->Instance));
  189. assert_param(IS_LTDC_HSYNC(hltdc->Init.HorizontalSync));
  190. assert_param(IS_LTDC_VSYNC(hltdc->Init.VerticalSync));
  191. assert_param(IS_LTDC_AHBP(hltdc->Init.AccumulatedHBP));
  192. assert_param(IS_LTDC_AVBP(hltdc->Init.AccumulatedVBP));
  193. assert_param(IS_LTDC_AAH(hltdc->Init.AccumulatedActiveH));
  194. assert_param(IS_LTDC_AAW(hltdc->Init.AccumulatedActiveW));
  195. assert_param(IS_LTDC_TOTALH(hltdc->Init.TotalHeigh));
  196. assert_param(IS_LTDC_TOTALW(hltdc->Init.TotalWidth));
  197. assert_param(IS_LTDC_HSPOL(hltdc->Init.HSPolarity));
  198. assert_param(IS_LTDC_VSPOL(hltdc->Init.VSPolarity));
  199. assert_param(IS_LTDC_DEPOL(hltdc->Init.DEPolarity));
  200. assert_param(IS_LTDC_PCPOL(hltdc->Init.PCPolarity));
  201. #if (USE_HAL_LTDC_REGISTER_CALLBACKS == 1)
  202. if (hltdc->State == HAL_LTDC_STATE_RESET)
  203. {
  204. /* Allocate lock resource and initialize it */
  205. hltdc->Lock = HAL_UNLOCKED;
  206. /* Reset the LTDC callback to the legacy weak callbacks */
  207. hltdc->LineEventCallback = HAL_LTDC_LineEventCallback; /* Legacy weak LineEventCallback */
  208. hltdc->ReloadEventCallback = HAL_LTDC_ReloadEventCallback; /* Legacy weak ReloadEventCallback */
  209. hltdc->ErrorCallback = HAL_LTDC_ErrorCallback; /* Legacy weak ErrorCallback */
  210. if (hltdc->MspInitCallback == NULL)
  211. {
  212. hltdc->MspInitCallback = HAL_LTDC_MspInit;
  213. }
  214. /* Init the low level hardware */
  215. hltdc->MspInitCallback(hltdc);
  216. }
  217. #else
  218. if (hltdc->State == HAL_LTDC_STATE_RESET)
  219. {
  220. /* Allocate lock resource and initialize it */
  221. hltdc->Lock = HAL_UNLOCKED;
  222. /* Init the low level hardware */
  223. HAL_LTDC_MspInit(hltdc);
  224. }
  225. #endif /* USE_HAL_LTDC_REGISTER_CALLBACKS */
  226. /* Change LTDC peripheral state */
  227. hltdc->State = HAL_LTDC_STATE_BUSY;
  228. /* Configure the HS, VS, DE and PC polarity */
  229. hltdc->Instance->GCR &= ~(LTDC_GCR_HSPOL | LTDC_GCR_VSPOL | LTDC_GCR_DEPOL | LTDC_GCR_PCPOL);
  230. hltdc->Instance->GCR |= (uint32_t)(hltdc->Init.HSPolarity | hltdc->Init.VSPolarity | \
  231. hltdc->Init.DEPolarity | hltdc->Init.PCPolarity);
  232. /* Set Synchronization size */
  233. hltdc->Instance->SSCR &= ~(LTDC_SSCR_VSH | LTDC_SSCR_HSW);
  234. tmp = (hltdc->Init.HorizontalSync << 16U);
  235. hltdc->Instance->SSCR |= (tmp | hltdc->Init.VerticalSync);
  236. /* Set Accumulated Back porch */
  237. hltdc->Instance->BPCR &= ~(LTDC_BPCR_AVBP | LTDC_BPCR_AHBP);
  238. tmp = (hltdc->Init.AccumulatedHBP << 16U);
  239. hltdc->Instance->BPCR |= (tmp | hltdc->Init.AccumulatedVBP);
  240. /* Set Accumulated Active Width */
  241. hltdc->Instance->AWCR &= ~(LTDC_AWCR_AAH | LTDC_AWCR_AAW);
  242. tmp = (hltdc->Init.AccumulatedActiveW << 16U);
  243. hltdc->Instance->AWCR |= (tmp | hltdc->Init.AccumulatedActiveH);
  244. /* Set Total Width */
  245. hltdc->Instance->TWCR &= ~(LTDC_TWCR_TOTALH | LTDC_TWCR_TOTALW);
  246. tmp = (hltdc->Init.TotalWidth << 16U);
  247. hltdc->Instance->TWCR |= (tmp | hltdc->Init.TotalHeigh);
  248. /* Set the background color value */
  249. tmp = ((uint32_t)(hltdc->Init.Backcolor.Green) << 8U);
  250. tmp1 = ((uint32_t)(hltdc->Init.Backcolor.Red) << 16U);
  251. hltdc->Instance->BCCR &= ~(LTDC_BCCR_BCBLUE | LTDC_BCCR_BCGREEN | LTDC_BCCR_BCRED);
  252. hltdc->Instance->BCCR |= (tmp1 | tmp | hltdc->Init.Backcolor.Blue);
  253. /* Enable the Transfer Error and FIFO underrun interrupts */
  254. __HAL_LTDC_ENABLE_IT(hltdc, LTDC_IT_TE | LTDC_IT_FU);
  255. /* Enable LTDC by setting LTDCEN bit */
  256. __HAL_LTDC_ENABLE(hltdc);
  257. /* Initialize the error code */
  258. hltdc->ErrorCode = HAL_LTDC_ERROR_NONE;
  259. /* Initialize the LTDC state*/
  260. hltdc->State = HAL_LTDC_STATE_READY;
  261. return HAL_OK;
  262. }
  263. /**
  264. * @brief De-initialize the LTDC peripheral.
  265. * @param hltdc pointer to a LTDC_HandleTypeDef structure that contains
  266. * the configuration information for the LTDC.
  267. * @retval None
  268. */
  269. HAL_StatusTypeDef HAL_LTDC_DeInit(LTDC_HandleTypeDef *hltdc)
  270. {
  271. uint32_t tickstart;
  272. /* Check the LTDC peripheral state */
  273. if (hltdc == NULL)
  274. {
  275. return HAL_ERROR;
  276. }
  277. /* Check function parameters */
  278. assert_param(IS_LTDC_ALL_INSTANCE(hltdc->Instance));
  279. /* Disable LTDC Layer 1 */
  280. __HAL_LTDC_LAYER_DISABLE(hltdc, LTDC_LAYER_1);
  281. #if defined(LTDC_Layer2_BASE)
  282. /* Disable LTDC Layer 2 */
  283. __HAL_LTDC_LAYER_DISABLE(hltdc, LTDC_LAYER_2);
  284. #endif /* LTDC_Layer2_BASE */
  285. /* Reload during vertical blanking period */
  286. __HAL_LTDC_VERTICAL_BLANKING_RELOAD_CONFIG(hltdc);
  287. /* Get tick */
  288. tickstart = HAL_GetTick();
  289. /* Wait for VSYNC Interrupt */
  290. while (READ_BIT(hltdc->Instance->CDSR, LTDC_CDSR_VSYNCS) == 0U)
  291. {
  292. /* Check for the Timeout */
  293. if ((HAL_GetTick() - tickstart) > LTDC_TIMEOUT_VALUE)
  294. {
  295. break;
  296. }
  297. }
  298. /* Disable LTDC */
  299. __HAL_LTDC_DISABLE(hltdc);
  300. #if (USE_HAL_LTDC_REGISTER_CALLBACKS == 1)
  301. if (hltdc->MspDeInitCallback == NULL)
  302. {
  303. hltdc->MspDeInitCallback = HAL_LTDC_MspDeInit;
  304. }
  305. /* DeInit the low level hardware */
  306. hltdc->MspDeInitCallback(hltdc);
  307. #else
  308. /* DeInit the low level hardware */
  309. HAL_LTDC_MspDeInit(hltdc);
  310. #endif /* USE_HAL_LTDC_REGISTER_CALLBACKS */
  311. /* Initialize the error code */
  312. hltdc->ErrorCode = HAL_LTDC_ERROR_NONE;
  313. /* Initialize the LTDC state*/
  314. hltdc->State = HAL_LTDC_STATE_RESET;
  315. /* Release Lock */
  316. __HAL_UNLOCK(hltdc);
  317. return HAL_OK;
  318. }
  319. /**
  320. * @brief Initialize the LTDC MSP.
  321. * @param hltdc pointer to a LTDC_HandleTypeDef structure that contains
  322. * the configuration information for the LTDC.
  323. * @retval None
  324. */
  325. __weak void HAL_LTDC_MspInit(LTDC_HandleTypeDef *hltdc)
  326. {
  327. /* Prevent unused argument(s) compilation warning */
  328. UNUSED(hltdc);
  329. /* NOTE : This function should not be modified, when the callback is needed,
  330. the HAL_LTDC_MspInit could be implemented in the user file
  331. */
  332. }
  333. /**
  334. * @brief De-initialize the LTDC MSP.
  335. * @param hltdc pointer to a LTDC_HandleTypeDef structure that contains
  336. * the configuration information for the LTDC.
  337. * @retval None
  338. */
  339. __weak void HAL_LTDC_MspDeInit(LTDC_HandleTypeDef *hltdc)
  340. {
  341. /* Prevent unused argument(s) compilation warning */
  342. UNUSED(hltdc);
  343. /* NOTE : This function should not be modified, when the callback is needed,
  344. the HAL_LTDC_MspDeInit could be implemented in the user file
  345. */
  346. }
  347. #if (USE_HAL_LTDC_REGISTER_CALLBACKS == 1)
  348. /**
  349. * @brief Register a User LTDC Callback
  350. * To be used instead of the weak predefined callback
  351. * @param hltdc ltdc handle
  352. * @param CallbackID ID of the callback to be registered
  353. * This parameter can be one of the following values:
  354. * @arg @ref HAL_LTDC_LINE_EVENT_CB_ID Line Event Callback ID
  355. * @arg @ref HAL_LTDC_RELOAD_EVENT_CB_ID Reload Event Callback ID
  356. * @arg @ref HAL_LTDC_ERROR_CB_ID Error Callback ID
  357. * @arg @ref HAL_LTDC_MSPINIT_CB_ID MspInit callback ID
  358. * @arg @ref HAL_LTDC_MSPDEINIT_CB_ID MspDeInit callback ID
  359. * @param pCallback pointer to the Callback function
  360. * @retval status
  361. */
  362. HAL_StatusTypeDef HAL_LTDC_RegisterCallback(LTDC_HandleTypeDef *hltdc, HAL_LTDC_CallbackIDTypeDef CallbackID,
  363. pLTDC_CallbackTypeDef pCallback)
  364. {
  365. HAL_StatusTypeDef status = HAL_OK;
  366. if (pCallback == NULL)
  367. {
  368. /* Update the error code */
  369. hltdc->ErrorCode |= HAL_LTDC_ERROR_INVALID_CALLBACK;
  370. return HAL_ERROR;
  371. }
  372. /* Process locked */
  373. __HAL_LOCK(hltdc);
  374. if (hltdc->State == HAL_LTDC_STATE_READY)
  375. {
  376. switch (CallbackID)
  377. {
  378. case HAL_LTDC_LINE_EVENT_CB_ID :
  379. hltdc->LineEventCallback = pCallback;
  380. break;
  381. case HAL_LTDC_RELOAD_EVENT_CB_ID :
  382. hltdc->ReloadEventCallback = pCallback;
  383. break;
  384. case HAL_LTDC_ERROR_CB_ID :
  385. hltdc->ErrorCallback = pCallback;
  386. break;
  387. case HAL_LTDC_MSPINIT_CB_ID :
  388. hltdc->MspInitCallback = pCallback;
  389. break;
  390. case HAL_LTDC_MSPDEINIT_CB_ID :
  391. hltdc->MspDeInitCallback = pCallback;
  392. break;
  393. default :
  394. /* Update the error code */
  395. hltdc->ErrorCode |= HAL_LTDC_ERROR_INVALID_CALLBACK;
  396. /* Return error status */
  397. status = HAL_ERROR;
  398. break;
  399. }
  400. }
  401. else if (hltdc->State == HAL_LTDC_STATE_RESET)
  402. {
  403. switch (CallbackID)
  404. {
  405. case HAL_LTDC_MSPINIT_CB_ID :
  406. hltdc->MspInitCallback = pCallback;
  407. break;
  408. case HAL_LTDC_MSPDEINIT_CB_ID :
  409. hltdc->MspDeInitCallback = pCallback;
  410. break;
  411. default :
  412. /* Update the error code */
  413. hltdc->ErrorCode |= HAL_LTDC_ERROR_INVALID_CALLBACK;
  414. /* Return error status */
  415. status = HAL_ERROR;
  416. break;
  417. }
  418. }
  419. else
  420. {
  421. /* Update the error code */
  422. hltdc->ErrorCode |= HAL_LTDC_ERROR_INVALID_CALLBACK;
  423. /* Return error status */
  424. status = HAL_ERROR;
  425. }
  426. /* Release Lock */
  427. __HAL_UNLOCK(hltdc);
  428. return status;
  429. }
  430. /**
  431. * @brief Unregister an LTDC Callback
  432. * LTDC callback is redirected to the weak predefined callback
  433. * @param hltdc ltdc handle
  434. * @param CallbackID ID of the callback to be unregistered
  435. * This parameter can be one of the following values:
  436. * @arg @ref HAL_LTDC_LINE_EVENT_CB_ID Line Event Callback ID
  437. * @arg @ref HAL_LTDC_RELOAD_EVENT_CB_ID Reload Event Callback ID
  438. * @arg @ref HAL_LTDC_ERROR_CB_ID Error Callback ID
  439. * @arg @ref HAL_LTDC_MSPINIT_CB_ID MspInit callback ID
  440. * @arg @ref HAL_LTDC_MSPDEINIT_CB_ID MspDeInit callback ID
  441. * @retval status
  442. */
  443. HAL_StatusTypeDef HAL_LTDC_UnRegisterCallback(LTDC_HandleTypeDef *hltdc, HAL_LTDC_CallbackIDTypeDef CallbackID)
  444. {
  445. HAL_StatusTypeDef status = HAL_OK;
  446. /* Process locked */
  447. __HAL_LOCK(hltdc);
  448. if (hltdc->State == HAL_LTDC_STATE_READY)
  449. {
  450. switch (CallbackID)
  451. {
  452. case HAL_LTDC_LINE_EVENT_CB_ID :
  453. hltdc->LineEventCallback = HAL_LTDC_LineEventCallback; /* Legacy weak LineEventCallback */
  454. break;
  455. case HAL_LTDC_RELOAD_EVENT_CB_ID :
  456. hltdc->ReloadEventCallback = HAL_LTDC_ReloadEventCallback; /* Legacy weak ReloadEventCallback */
  457. break;
  458. case HAL_LTDC_ERROR_CB_ID :
  459. hltdc->ErrorCallback = HAL_LTDC_ErrorCallback; /* Legacy weak ErrorCallback */
  460. break;
  461. case HAL_LTDC_MSPINIT_CB_ID :
  462. hltdc->MspInitCallback = HAL_LTDC_MspInit; /* Legcay weak MspInit Callback */
  463. break;
  464. case HAL_LTDC_MSPDEINIT_CB_ID :
  465. hltdc->MspDeInitCallback = HAL_LTDC_MspDeInit; /* Legcay weak MspDeInit Callback */
  466. break;
  467. default :
  468. /* Update the error code */
  469. hltdc->ErrorCode |= HAL_LTDC_ERROR_INVALID_CALLBACK;
  470. /* Return error status */
  471. status = HAL_ERROR;
  472. break;
  473. }
  474. }
  475. else if (hltdc->State == HAL_LTDC_STATE_RESET)
  476. {
  477. switch (CallbackID)
  478. {
  479. case HAL_LTDC_MSPINIT_CB_ID :
  480. hltdc->MspInitCallback = HAL_LTDC_MspInit; /* Legcay weak MspInit Callback */
  481. break;
  482. case HAL_LTDC_MSPDEINIT_CB_ID :
  483. hltdc->MspDeInitCallback = HAL_LTDC_MspDeInit; /* Legcay weak MspDeInit Callback */
  484. break;
  485. default :
  486. /* Update the error code */
  487. hltdc->ErrorCode |= HAL_LTDC_ERROR_INVALID_CALLBACK;
  488. /* Return error status */
  489. status = HAL_ERROR;
  490. break;
  491. }
  492. }
  493. else
  494. {
  495. /* Update the error code */
  496. hltdc->ErrorCode |= HAL_LTDC_ERROR_INVALID_CALLBACK;
  497. /* Return error status */
  498. status = HAL_ERROR;
  499. }
  500. /* Release Lock */
  501. __HAL_UNLOCK(hltdc);
  502. return status;
  503. }
  504. #endif /* USE_HAL_LTDC_REGISTER_CALLBACKS */
  505. /**
  506. * @}
  507. */
  508. /** @defgroup LTDC_Exported_Functions_Group2 IO operation functions
  509. * @brief IO operation functions
  510. *
  511. @verbatim
  512. ===============================================================================
  513. ##### IO operation functions #####
  514. ===============================================================================
  515. [..] This section provides function allowing to:
  516. (+) Handle LTDC interrupt request
  517. @endverbatim
  518. * @{
  519. */
  520. /**
  521. * @brief Handle LTDC interrupt request.
  522. * @param hltdc pointer to a LTDC_HandleTypeDef structure that contains
  523. * the configuration information for the LTDC.
  524. * @retval HAL status
  525. */
  526. void HAL_LTDC_IRQHandler(LTDC_HandleTypeDef *hltdc)
  527. {
  528. uint32_t isrflags = READ_REG(hltdc->Instance->ISR);
  529. uint32_t itsources = READ_REG(hltdc->Instance->IER);
  530. /* Transfer Error Interrupt management ***************************************/
  531. if (((isrflags & LTDC_ISR_TERRIF) != 0U) && ((itsources & LTDC_IER_TERRIE) != 0U))
  532. {
  533. /* Disable the transfer Error interrupt */
  534. __HAL_LTDC_DISABLE_IT(hltdc, LTDC_IT_TE);
  535. /* Clear the transfer error flag */
  536. __HAL_LTDC_CLEAR_FLAG(hltdc, LTDC_FLAG_TE);
  537. /* Update error code */
  538. hltdc->ErrorCode |= HAL_LTDC_ERROR_TE;
  539. /* Change LTDC state */
  540. hltdc->State = HAL_LTDC_STATE_ERROR;
  541. /* Process unlocked */
  542. __HAL_UNLOCK(hltdc);
  543. /* Transfer error Callback */
  544. #if (USE_HAL_LTDC_REGISTER_CALLBACKS == 1)
  545. /*Call registered error callback*/
  546. hltdc->ErrorCallback(hltdc);
  547. #else
  548. /* Call legacy error callback*/
  549. HAL_LTDC_ErrorCallback(hltdc);
  550. #endif /* USE_HAL_LTDC_REGISTER_CALLBACKS */
  551. }
  552. /* FIFO underrun Interrupt management ***************************************/
  553. if (((isrflags & LTDC_ISR_FUIF) != 0U) && ((itsources & LTDC_IER_FUIE) != 0U))
  554. {
  555. /* Disable the FIFO underrun interrupt */
  556. __HAL_LTDC_DISABLE_IT(hltdc, LTDC_IT_FU);
  557. /* Clear the FIFO underrun flag */
  558. __HAL_LTDC_CLEAR_FLAG(hltdc, LTDC_FLAG_FU);
  559. /* Update error code */
  560. hltdc->ErrorCode |= HAL_LTDC_ERROR_FU;
  561. /* Change LTDC state */
  562. hltdc->State = HAL_LTDC_STATE_ERROR;
  563. /* Process unlocked */
  564. __HAL_UNLOCK(hltdc);
  565. /* Transfer error Callback */
  566. #if (USE_HAL_LTDC_REGISTER_CALLBACKS == 1)
  567. /*Call registered error callback*/
  568. hltdc->ErrorCallback(hltdc);
  569. #else
  570. /* Call legacy error callback*/
  571. HAL_LTDC_ErrorCallback(hltdc);
  572. #endif /* USE_HAL_LTDC_REGISTER_CALLBACKS */
  573. }
  574. /* Line Interrupt management ************************************************/
  575. if (((isrflags & LTDC_ISR_LIF) != 0U) && ((itsources & LTDC_IER_LIE) != 0U))
  576. {
  577. /* Disable the Line interrupt */
  578. __HAL_LTDC_DISABLE_IT(hltdc, LTDC_IT_LI);
  579. /* Clear the Line interrupt flag */
  580. __HAL_LTDC_CLEAR_FLAG(hltdc, LTDC_FLAG_LI);
  581. /* Change LTDC state */
  582. hltdc->State = HAL_LTDC_STATE_READY;
  583. /* Process unlocked */
  584. __HAL_UNLOCK(hltdc);
  585. /* Line interrupt Callback */
  586. #if (USE_HAL_LTDC_REGISTER_CALLBACKS == 1)
  587. /*Call registered Line Event callback */
  588. hltdc->LineEventCallback(hltdc);
  589. #else
  590. /*Call Legacy Line Event callback */
  591. HAL_LTDC_LineEventCallback(hltdc);
  592. #endif /* USE_HAL_LTDC_REGISTER_CALLBACKS */
  593. }
  594. /* Register reload Interrupt management ***************************************/
  595. if (((isrflags & LTDC_ISR_RRIF) != 0U) && ((itsources & LTDC_IER_RRIE) != 0U))
  596. {
  597. /* Disable the register reload interrupt */
  598. __HAL_LTDC_DISABLE_IT(hltdc, LTDC_IT_RR);
  599. /* Clear the register reload flag */
  600. __HAL_LTDC_CLEAR_FLAG(hltdc, LTDC_FLAG_RR);
  601. /* Change LTDC state */
  602. hltdc->State = HAL_LTDC_STATE_READY;
  603. /* Process unlocked */
  604. __HAL_UNLOCK(hltdc);
  605. /* Reload interrupt Callback */
  606. #if (USE_HAL_LTDC_REGISTER_CALLBACKS == 1)
  607. /*Call registered reload Event callback */
  608. hltdc->ReloadEventCallback(hltdc);
  609. #else
  610. /*Call Legacy Reload Event callback */
  611. HAL_LTDC_ReloadEventCallback(hltdc);
  612. #endif /* USE_HAL_LTDC_REGISTER_CALLBACKS */
  613. }
  614. }
  615. /**
  616. * @brief Error LTDC callback.
  617. * @param hltdc pointer to a LTDC_HandleTypeDef structure that contains
  618. * the configuration information for the LTDC.
  619. * @retval None
  620. */
  621. __weak void HAL_LTDC_ErrorCallback(LTDC_HandleTypeDef *hltdc)
  622. {
  623. /* Prevent unused argument(s) compilation warning */
  624. UNUSED(hltdc);
  625. /* NOTE : This function should not be modified, when the callback is needed,
  626. the HAL_LTDC_ErrorCallback could be implemented in the user file
  627. */
  628. }
  629. /**
  630. * @brief Line Event callback.
  631. * @param hltdc pointer to a LTDC_HandleTypeDef structure that contains
  632. * the configuration information for the LTDC.
  633. * @retval None
  634. */
  635. __weak void HAL_LTDC_LineEventCallback(LTDC_HandleTypeDef *hltdc)
  636. {
  637. /* Prevent unused argument(s) compilation warning */
  638. UNUSED(hltdc);
  639. /* NOTE : This function should not be modified, when the callback is needed,
  640. the HAL_LTDC_LineEventCallback could be implemented in the user file
  641. */
  642. }
  643. /**
  644. * @brief Reload Event callback.
  645. * @param hltdc pointer to a LTDC_HandleTypeDef structure that contains
  646. * the configuration information for the LTDC.
  647. * @retval None
  648. */
  649. __weak void HAL_LTDC_ReloadEventCallback(LTDC_HandleTypeDef *hltdc)
  650. {
  651. /* Prevent unused argument(s) compilation warning */
  652. UNUSED(hltdc);
  653. /* NOTE : This function should not be modified, when the callback is needed,
  654. the HAL_LTDC_ReloadEvenCallback could be implemented in the user file
  655. */
  656. }
  657. /**
  658. * @}
  659. */
  660. /** @defgroup LTDC_Exported_Functions_Group3 Peripheral Control functions
  661. * @brief Peripheral Control functions
  662. *
  663. @verbatim
  664. ===============================================================================
  665. ##### Peripheral Control functions #####
  666. ===============================================================================
  667. [..] This section provides functions allowing to:
  668. (+) Configure the LTDC foreground or/and background parameters.
  669. (+) Set the active layer.
  670. (+) Configure the color keying.
  671. (+) Configure the C-LUT.
  672. (+) Enable / Disable the color keying.
  673. (+) Enable / Disable the C-LUT.
  674. (+) Update the layer position.
  675. (+) Update the layer size.
  676. (+) Update pixel format on the fly.
  677. (+) Update transparency on the fly.
  678. (+) Update address on the fly.
  679. @endverbatim
  680. * @{
  681. */
  682. /**
  683. * @brief Configure the LTDC Layer according to the specified
  684. * parameters in the LTDC_InitTypeDef and create the associated handle.
  685. * @param hltdc pointer to a LTDC_HandleTypeDef structure that contains
  686. * the configuration information for the LTDC.
  687. * @param pLayerCfg pointer to a LTDC_LayerCfgTypeDef structure that contains
  688. * the configuration information for the Layer.
  689. * @param LayerIdx LTDC Layer index.
  690. * This parameter can be one of the following values:
  691. * LTDC_LAYER_1 (0) or LTDC_LAYER_2 (1)
  692. * @retval HAL status
  693. */
  694. HAL_StatusTypeDef HAL_LTDC_ConfigLayer(LTDC_HandleTypeDef *hltdc, LTDC_LayerCfgTypeDef *pLayerCfg, uint32_t LayerIdx)
  695. {
  696. /* Check the parameters */
  697. assert_param(IS_LTDC_LAYER(LayerIdx));
  698. assert_param(IS_LTDC_HCONFIGST(pLayerCfg->WindowX0));
  699. assert_param(IS_LTDC_HCONFIGSP(pLayerCfg->WindowX1));
  700. assert_param(IS_LTDC_VCONFIGST(pLayerCfg->WindowY0));
  701. assert_param(IS_LTDC_VCONFIGSP(pLayerCfg->WindowY1));
  702. assert_param(IS_LTDC_PIXEL_FORMAT(pLayerCfg->PixelFormat));
  703. assert_param(IS_LTDC_ALPHA(pLayerCfg->Alpha));
  704. assert_param(IS_LTDC_ALPHA(pLayerCfg->Alpha0));
  705. assert_param(IS_LTDC_BLENDING_FACTOR1(pLayerCfg->BlendingFactor1));
  706. assert_param(IS_LTDC_BLENDING_FACTOR2(pLayerCfg->BlendingFactor2));
  707. assert_param(IS_LTDC_CFBLL(pLayerCfg->ImageWidth));
  708. assert_param(IS_LTDC_CFBLNBR(pLayerCfg->ImageHeight));
  709. /* Process locked */
  710. __HAL_LOCK(hltdc);
  711. /* Change LTDC peripheral state */
  712. hltdc->State = HAL_LTDC_STATE_BUSY;
  713. /* Copy new layer configuration into handle structure */
  714. hltdc->LayerCfg[LayerIdx] = *pLayerCfg;
  715. /* Configure the LTDC Layer */
  716. LTDC_SetConfig(hltdc, pLayerCfg, LayerIdx);
  717. /* Set the Immediate Reload type */
  718. hltdc->Instance->SRCR = LTDC_SRCR_IMR;
  719. /* Initialize the LTDC state*/
  720. hltdc->State = HAL_LTDC_STATE_READY;
  721. /* Process unlocked */
  722. __HAL_UNLOCK(hltdc);
  723. return HAL_OK;
  724. }
  725. /**
  726. * @brief Configure the color keying.
  727. * @param hltdc pointer to a LTDC_HandleTypeDef structure that contains
  728. * the configuration information for the LTDC.
  729. * @param RGBValue the color key value
  730. * @param LayerIdx LTDC Layer index.
  731. * This parameter can be one of the following values:
  732. * LTDC_LAYER_1 (0) or LTDC_LAYER_2 (1)
  733. * @retval HAL status
  734. */
  735. HAL_StatusTypeDef HAL_LTDC_ConfigColorKeying(LTDC_HandleTypeDef *hltdc, uint32_t RGBValue, uint32_t LayerIdx)
  736. {
  737. /* Check the parameters */
  738. assert_param(IS_LTDC_LAYER(LayerIdx));
  739. /* Process locked */
  740. __HAL_LOCK(hltdc);
  741. /* Change LTDC peripheral state */
  742. hltdc->State = HAL_LTDC_STATE_BUSY;
  743. /* Configure the default color values */
  744. LTDC_LAYER(hltdc, LayerIdx)->CKCR &= ~(LTDC_LxCKCR_CKBLUE | LTDC_LxCKCR_CKGREEN | LTDC_LxCKCR_CKRED);
  745. LTDC_LAYER(hltdc, LayerIdx)->CKCR = RGBValue;
  746. /* Set the Immediate Reload type */
  747. hltdc->Instance->SRCR = LTDC_SRCR_IMR;
  748. /* Change the LTDC state*/
  749. hltdc->State = HAL_LTDC_STATE_READY;
  750. /* Process unlocked */
  751. __HAL_UNLOCK(hltdc);
  752. return HAL_OK;
  753. }
  754. /**
  755. * @brief Load the color lookup table.
  756. * @param hltdc pointer to a LTDC_HandleTypeDef structure that contains
  757. * the configuration information for the LTDC.
  758. * @param pCLUT pointer to the color lookup table address.
  759. * @param CLUTSize the color lookup table size.
  760. * @param LayerIdx LTDC Layer index.
  761. * This parameter can be one of the following values:
  762. * LTDC_LAYER_1 (0) or LTDC_LAYER_2 (1)
  763. * @retval HAL status
  764. */
  765. HAL_StatusTypeDef HAL_LTDC_ConfigCLUT(LTDC_HandleTypeDef *hltdc, uint32_t *pCLUT, uint32_t CLUTSize, uint32_t LayerIdx)
  766. {
  767. uint32_t tmp;
  768. uint32_t counter;
  769. uint32_t *pcolorlut = pCLUT;
  770. /* Check the parameters */
  771. assert_param(IS_LTDC_LAYER(LayerIdx));
  772. /* Process locked */
  773. __HAL_LOCK(hltdc);
  774. /* Change LTDC peripheral state */
  775. hltdc->State = HAL_LTDC_STATE_BUSY;
  776. for (counter = 0U; (counter < CLUTSize); counter++)
  777. {
  778. if (hltdc->LayerCfg[LayerIdx].PixelFormat == LTDC_PIXEL_FORMAT_AL44)
  779. {
  780. tmp = (((counter + (16U * counter)) << 24U) | ((uint32_t)(*pcolorlut) & 0xFFU) | \
  781. ((uint32_t)(*pcolorlut) & 0xFF00U) | ((uint32_t)(*pcolorlut) & 0xFF0000U));
  782. }
  783. else
  784. {
  785. tmp = ((counter << 24U) | ((uint32_t)(*pcolorlut) & 0xFFU) | \
  786. ((uint32_t)(*pcolorlut) & 0xFF00U) | ((uint32_t)(*pcolorlut) & 0xFF0000U));
  787. }
  788. pcolorlut++;
  789. /* Specifies the C-LUT address and RGB value */
  790. LTDC_LAYER(hltdc, LayerIdx)->CLUTWR = tmp;
  791. }
  792. /* Change the LTDC state*/
  793. hltdc->State = HAL_LTDC_STATE_READY;
  794. /* Process unlocked */
  795. __HAL_UNLOCK(hltdc);
  796. return HAL_OK;
  797. }
  798. /**
  799. * @brief Enable the color keying.
  800. * @param hltdc pointer to a LTDC_HandleTypeDef structure that contains
  801. * the configuration information for the LTDC.
  802. * @param LayerIdx LTDC Layer index.
  803. * This parameter can be one of the following values:
  804. * LTDC_LAYER_1 (0) or LTDC_LAYER_2 (1)
  805. * @retval HAL status
  806. */
  807. HAL_StatusTypeDef HAL_LTDC_EnableColorKeying(LTDC_HandleTypeDef *hltdc, uint32_t LayerIdx)
  808. {
  809. /* Check the parameters */
  810. assert_param(IS_LTDC_LAYER(LayerIdx));
  811. /* Process locked */
  812. __HAL_LOCK(hltdc);
  813. /* Change LTDC peripheral state */
  814. hltdc->State = HAL_LTDC_STATE_BUSY;
  815. /* Enable LTDC color keying by setting COLKEN bit */
  816. LTDC_LAYER(hltdc, LayerIdx)->CR |= (uint32_t)LTDC_LxCR_COLKEN;
  817. /* Set the Immediate Reload type */
  818. hltdc->Instance->SRCR = LTDC_SRCR_IMR;
  819. /* Change the LTDC state*/
  820. hltdc->State = HAL_LTDC_STATE_READY;
  821. /* Process unlocked */
  822. __HAL_UNLOCK(hltdc);
  823. return HAL_OK;
  824. }
  825. /**
  826. * @brief Disable the color keying.
  827. * @param hltdc pointer to a LTDC_HandleTypeDef structure that contains
  828. * the configuration information for the LTDC.
  829. * @param LayerIdx LTDC Layer index.
  830. * This parameter can be one of the following values:
  831. * LTDC_LAYER_1 (0) or LTDC_LAYER_2 (1)
  832. * @retval HAL status
  833. */
  834. HAL_StatusTypeDef HAL_LTDC_DisableColorKeying(LTDC_HandleTypeDef *hltdc, uint32_t LayerIdx)
  835. {
  836. /* Check the parameters */
  837. assert_param(IS_LTDC_LAYER(LayerIdx));
  838. /* Process locked */
  839. __HAL_LOCK(hltdc);
  840. /* Change LTDC peripheral state */
  841. hltdc->State = HAL_LTDC_STATE_BUSY;
  842. /* Disable LTDC color keying by setting COLKEN bit */
  843. LTDC_LAYER(hltdc, LayerIdx)->CR &= ~(uint32_t)LTDC_LxCR_COLKEN;
  844. /* Set the Immediate Reload type */
  845. hltdc->Instance->SRCR = LTDC_SRCR_IMR;
  846. /* Change the LTDC state*/
  847. hltdc->State = HAL_LTDC_STATE_READY;
  848. /* Process unlocked */
  849. __HAL_UNLOCK(hltdc);
  850. return HAL_OK;
  851. }
  852. /**
  853. * @brief Enable the color lookup table.
  854. * @param hltdc pointer to a LTDC_HandleTypeDef structure that contains
  855. * the configuration information for the LTDC.
  856. * @param LayerIdx LTDC Layer index.
  857. * This parameter can be one of the following values:
  858. * LTDC_LAYER_1 (0) or LTDC_LAYER_2 (1)
  859. * @retval HAL status
  860. */
  861. HAL_StatusTypeDef HAL_LTDC_EnableCLUT(LTDC_HandleTypeDef *hltdc, uint32_t LayerIdx)
  862. {
  863. /* Check the parameters */
  864. assert_param(IS_LTDC_LAYER(LayerIdx));
  865. /* Process locked */
  866. __HAL_LOCK(hltdc);
  867. /* Change LTDC peripheral state */
  868. hltdc->State = HAL_LTDC_STATE_BUSY;
  869. /* Enable LTDC color lookup table by setting CLUTEN bit */
  870. LTDC_LAYER(hltdc, LayerIdx)->CR |= (uint32_t)LTDC_LxCR_CLUTEN;
  871. /* Set the Immediate Reload type */
  872. hltdc->Instance->SRCR = LTDC_SRCR_IMR;
  873. /* Change the LTDC state*/
  874. hltdc->State = HAL_LTDC_STATE_READY;
  875. /* Process unlocked */
  876. __HAL_UNLOCK(hltdc);
  877. return HAL_OK;
  878. }
  879. /**
  880. * @brief Disable the color lookup table.
  881. * @param hltdc pointer to a LTDC_HandleTypeDef structure that contains
  882. * the configuration information for the LTDC.
  883. * @param LayerIdx LTDC Layer index.
  884. * This parameter can be one of the following values:
  885. * LTDC_LAYER_1 (0) or LTDC_LAYER_2 (1)
  886. * @retval HAL status
  887. */
  888. HAL_StatusTypeDef HAL_LTDC_DisableCLUT(LTDC_HandleTypeDef *hltdc, uint32_t LayerIdx)
  889. {
  890. /* Check the parameters */
  891. assert_param(IS_LTDC_LAYER(LayerIdx));
  892. /* Process locked */
  893. __HAL_LOCK(hltdc);
  894. /* Change LTDC peripheral state */
  895. hltdc->State = HAL_LTDC_STATE_BUSY;
  896. /* Disable LTDC color lookup table by setting CLUTEN bit */
  897. LTDC_LAYER(hltdc, LayerIdx)->CR &= ~(uint32_t)LTDC_LxCR_CLUTEN;
  898. /* Set the Immediate Reload type */
  899. hltdc->Instance->SRCR = LTDC_SRCR_IMR;
  900. /* Change the LTDC state*/
  901. hltdc->State = HAL_LTDC_STATE_READY;
  902. /* Process unlocked */
  903. __HAL_UNLOCK(hltdc);
  904. return HAL_OK;
  905. }
  906. /**
  907. * @brief Enable Dither.
  908. * @param hltdc pointer to a LTDC_HandleTypeDef structure that contains
  909. * the configuration information for the LTDC.
  910. * @retval HAL status
  911. */
  912. HAL_StatusTypeDef HAL_LTDC_EnableDither(LTDC_HandleTypeDef *hltdc)
  913. {
  914. /* Process locked */
  915. __HAL_LOCK(hltdc);
  916. /* Change LTDC peripheral state */
  917. hltdc->State = HAL_LTDC_STATE_BUSY;
  918. /* Enable Dither by setting DTEN bit */
  919. LTDC->GCR |= (uint32_t)LTDC_GCR_DEN;
  920. /* Change the LTDC state*/
  921. hltdc->State = HAL_LTDC_STATE_READY;
  922. /* Process unlocked */
  923. __HAL_UNLOCK(hltdc);
  924. return HAL_OK;
  925. }
  926. /**
  927. * @brief Disable Dither.
  928. * @param hltdc pointer to a LTDC_HandleTypeDef structure that contains
  929. * the configuration information for the LTDC.
  930. * @retval HAL status
  931. */
  932. HAL_StatusTypeDef HAL_LTDC_DisableDither(LTDC_HandleTypeDef *hltdc)
  933. {
  934. /* Process locked */
  935. __HAL_LOCK(hltdc);
  936. /* Change LTDC peripheral state */
  937. hltdc->State = HAL_LTDC_STATE_BUSY;
  938. /* Disable Dither by setting DTEN bit */
  939. LTDC->GCR &= ~(uint32_t)LTDC_GCR_DEN;
  940. /* Change the LTDC state*/
  941. hltdc->State = HAL_LTDC_STATE_READY;
  942. /* Process unlocked */
  943. __HAL_UNLOCK(hltdc);
  944. return HAL_OK;
  945. }
  946. /**
  947. * @brief Set the LTDC window size.
  948. * @param hltdc pointer to a LTDC_HandleTypeDef structure that contains
  949. * the configuration information for the LTDC.
  950. * @param XSize LTDC Pixel per line
  951. * @param YSize LTDC Line number
  952. * @param LayerIdx LTDC Layer index.
  953. * This parameter can be one of the following values:
  954. * LTDC_LAYER_1 (0) or LTDC_LAYER_2 (1)
  955. * @retval HAL status
  956. */
  957. HAL_StatusTypeDef HAL_LTDC_SetWindowSize(LTDC_HandleTypeDef *hltdc, uint32_t XSize, uint32_t YSize, uint32_t LayerIdx)
  958. {
  959. LTDC_LayerCfgTypeDef *pLayerCfg;
  960. /* Check the parameters (Layers parameters)*/
  961. assert_param(IS_LTDC_LAYER(LayerIdx));
  962. assert_param(IS_LTDC_CFBLL(XSize));
  963. assert_param(IS_LTDC_CFBLNBR(YSize));
  964. /* Process locked */
  965. __HAL_LOCK(hltdc);
  966. /* Change LTDC peripheral state */
  967. hltdc->State = HAL_LTDC_STATE_BUSY;
  968. /* Get layer configuration from handle structure */
  969. pLayerCfg = &hltdc->LayerCfg[LayerIdx];
  970. /* update horizontal stop */
  971. pLayerCfg->WindowX1 = XSize + pLayerCfg->WindowX0;
  972. /* update vertical stop */
  973. pLayerCfg->WindowY1 = YSize + pLayerCfg->WindowY0;
  974. /* Reconfigures the color frame buffer pitch in byte */
  975. pLayerCfg->ImageWidth = XSize;
  976. /* Reconfigures the frame buffer line number */
  977. pLayerCfg->ImageHeight = YSize;
  978. /* Set LTDC parameters */
  979. LTDC_SetConfig(hltdc, pLayerCfg, LayerIdx);
  980. /* Set the Immediate Reload type */
  981. hltdc->Instance->SRCR = LTDC_SRCR_IMR;
  982. /* Change the LTDC state*/
  983. hltdc->State = HAL_LTDC_STATE_READY;
  984. /* Process unlocked */
  985. __HAL_UNLOCK(hltdc);
  986. return HAL_OK;
  987. }
  988. /**
  989. * @brief Set the LTDC window position.
  990. * @param hltdc pointer to a LTDC_HandleTypeDef structure that contains
  991. * the configuration information for the LTDC.
  992. * @param X0 LTDC window X offset
  993. * @param Y0 LTDC window Y offset
  994. * @param LayerIdx LTDC Layer index.
  995. * This parameter can be one of the following values:
  996. * LTDC_LAYER_1 (0) or LTDC_LAYER_2 (1)
  997. * @retval HAL status
  998. */
  999. HAL_StatusTypeDef HAL_LTDC_SetWindowPosition(LTDC_HandleTypeDef *hltdc, uint32_t X0, uint32_t Y0, uint32_t LayerIdx)
  1000. {
  1001. LTDC_LayerCfgTypeDef *pLayerCfg;
  1002. /* Check the parameters */
  1003. assert_param(IS_LTDC_LAYER(LayerIdx));
  1004. assert_param(IS_LTDC_CFBLL(X0));
  1005. assert_param(IS_LTDC_CFBLNBR(Y0));
  1006. /* Process locked */
  1007. __HAL_LOCK(hltdc);
  1008. /* Change LTDC peripheral state */
  1009. hltdc->State = HAL_LTDC_STATE_BUSY;
  1010. /* Get layer configuration from handle structure */
  1011. pLayerCfg = &hltdc->LayerCfg[LayerIdx];
  1012. /* update horizontal start/stop */
  1013. pLayerCfg->WindowX0 = X0;
  1014. pLayerCfg->WindowX1 = X0 + pLayerCfg->ImageWidth;
  1015. /* update vertical start/stop */
  1016. pLayerCfg->WindowY0 = Y0;
  1017. pLayerCfg->WindowY1 = Y0 + pLayerCfg->ImageHeight;
  1018. /* Set LTDC parameters */
  1019. LTDC_SetConfig(hltdc, pLayerCfg, LayerIdx);
  1020. /* Set the Immediate Reload type */
  1021. hltdc->Instance->SRCR = LTDC_SRCR_IMR;
  1022. /* Change the LTDC state*/
  1023. hltdc->State = HAL_LTDC_STATE_READY;
  1024. /* Process unlocked */
  1025. __HAL_UNLOCK(hltdc);
  1026. return HAL_OK;
  1027. }
  1028. /**
  1029. * @brief Reconfigure the pixel format.
  1030. * @param hltdc pointer to a LTDC_HandleTypeDef structure that contains
  1031. * the configuration information for the LTDC.
  1032. * @param Pixelformat new pixel format value.
  1033. * @param LayerIdx LTDC Layer index.
  1034. * This parameter can be one of the following values:
  1035. * LTDC_LAYER_1 (0) or LTDC_LAYER_2 (1).
  1036. * @retval HAL status
  1037. */
  1038. HAL_StatusTypeDef HAL_LTDC_SetPixelFormat(LTDC_HandleTypeDef *hltdc, uint32_t Pixelformat, uint32_t LayerIdx)
  1039. {
  1040. LTDC_LayerCfgTypeDef *pLayerCfg;
  1041. /* Check the parameters */
  1042. assert_param(IS_LTDC_PIXEL_FORMAT(Pixelformat));
  1043. assert_param(IS_LTDC_LAYER(LayerIdx));
  1044. /* Process locked */
  1045. __HAL_LOCK(hltdc);
  1046. /* Change LTDC peripheral state */
  1047. hltdc->State = HAL_LTDC_STATE_BUSY;
  1048. /* Get layer configuration from handle structure */
  1049. pLayerCfg = &hltdc->LayerCfg[LayerIdx];
  1050. /* Reconfigure the pixel format */
  1051. pLayerCfg->PixelFormat = Pixelformat;
  1052. /* Set LTDC parameters */
  1053. LTDC_SetConfig(hltdc, pLayerCfg, LayerIdx);
  1054. /* Set the Immediate Reload type */
  1055. hltdc->Instance->SRCR = LTDC_SRCR_IMR;
  1056. /* Change the LTDC state*/
  1057. hltdc->State = HAL_LTDC_STATE_READY;
  1058. /* Process unlocked */
  1059. __HAL_UNLOCK(hltdc);
  1060. return HAL_OK;
  1061. }
  1062. /**
  1063. * @brief Reconfigure the layer alpha value.
  1064. * @param hltdc pointer to a LTDC_HandleTypeDef structure that contains
  1065. * the configuration information for the LTDC.
  1066. * @param Alpha new alpha value.
  1067. * @param LayerIdx LTDC Layer index.
  1068. * This parameter can be one of the following values:
  1069. * LTDC_LAYER_1 (0) or LTDC_LAYER_2 (1)
  1070. * @retval HAL status
  1071. */
  1072. HAL_StatusTypeDef HAL_LTDC_SetAlpha(LTDC_HandleTypeDef *hltdc, uint32_t Alpha, uint32_t LayerIdx)
  1073. {
  1074. LTDC_LayerCfgTypeDef *pLayerCfg;
  1075. /* Check the parameters */
  1076. assert_param(IS_LTDC_ALPHA(Alpha));
  1077. assert_param(IS_LTDC_LAYER(LayerIdx));
  1078. /* Process locked */
  1079. __HAL_LOCK(hltdc);
  1080. /* Change LTDC peripheral state */
  1081. hltdc->State = HAL_LTDC_STATE_BUSY;
  1082. /* Get layer configuration from handle structure */
  1083. pLayerCfg = &hltdc->LayerCfg[LayerIdx];
  1084. /* Reconfigure the Alpha value */
  1085. pLayerCfg->Alpha = Alpha;
  1086. /* Set LTDC parameters */
  1087. LTDC_SetConfig(hltdc, pLayerCfg, LayerIdx);
  1088. /* Set the Immediate Reload type */
  1089. hltdc->Instance->SRCR = LTDC_SRCR_IMR;
  1090. /* Change the LTDC state*/
  1091. hltdc->State = HAL_LTDC_STATE_READY;
  1092. /* Process unlocked */
  1093. __HAL_UNLOCK(hltdc);
  1094. return HAL_OK;
  1095. }
  1096. /**
  1097. * @brief Reconfigure the frame buffer Address.
  1098. * @param hltdc pointer to a LTDC_HandleTypeDef structure that contains
  1099. * the configuration information for the LTDC.
  1100. * @param Address new address value.
  1101. * @param LayerIdx LTDC Layer index.
  1102. * This parameter can be one of the following values:
  1103. * LTDC_LAYER_1 (0) or LTDC_LAYER_2 (1).
  1104. * @retval HAL status
  1105. */
  1106. HAL_StatusTypeDef HAL_LTDC_SetAddress(LTDC_HandleTypeDef *hltdc, uint32_t Address, uint32_t LayerIdx)
  1107. {
  1108. LTDC_LayerCfgTypeDef *pLayerCfg;
  1109. /* Check the parameters */
  1110. assert_param(IS_LTDC_LAYER(LayerIdx));
  1111. /* Process locked */
  1112. __HAL_LOCK(hltdc);
  1113. /* Change LTDC peripheral state */
  1114. hltdc->State = HAL_LTDC_STATE_BUSY;
  1115. /* Get layer configuration from handle structure */
  1116. pLayerCfg = &hltdc->LayerCfg[LayerIdx];
  1117. /* Reconfigure the Address */
  1118. pLayerCfg->FBStartAdress = Address;
  1119. /* Set LTDC parameters */
  1120. LTDC_SetConfig(hltdc, pLayerCfg, LayerIdx);
  1121. /* Set the Immediate Reload type */
  1122. hltdc->Instance->SRCR = LTDC_SRCR_IMR;
  1123. /* Change the LTDC state*/
  1124. hltdc->State = HAL_LTDC_STATE_READY;
  1125. /* Process unlocked */
  1126. __HAL_UNLOCK(hltdc);
  1127. return HAL_OK;
  1128. }
  1129. /**
  1130. * @brief Function used to reconfigure the pitch for specific cases where the attached LayerIdx buffer have a width
  1131. * that is larger than the one intended to be displayed on screen. Example of a buffer 800x480 attached to
  1132. * layer for which we want to read and display on screen only a portion 320x240 taken in the center
  1133. * of the buffer.
  1134. * The pitch in pixels will be in that case 800 pixels and not 320 pixels as initially configured by previous
  1135. * call to HAL_LTDC_ConfigLayer().
  1136. * @note This function should be called only after a previous call to HAL_LTDC_ConfigLayer() to modify the default
  1137. * pitch configured by HAL_LTDC_ConfigLayer() when required (refer to example described just above).
  1138. * @param hltdc pointer to a LTDC_HandleTypeDef structure that contains
  1139. * the configuration information for the LTDC.
  1140. * @param LinePitchInPixels New line pitch in pixels to configure for LTDC layer 'LayerIdx'.
  1141. * @param LayerIdx LTDC layer index concerned by the modification of line pitch.
  1142. * @retval HAL status
  1143. */
  1144. HAL_StatusTypeDef HAL_LTDC_SetPitch(LTDC_HandleTypeDef *hltdc, uint32_t LinePitchInPixels, uint32_t LayerIdx)
  1145. {
  1146. uint32_t tmp;
  1147. uint32_t pitchUpdate;
  1148. uint32_t pixelFormat;
  1149. /* Check the parameters */
  1150. assert_param(IS_LTDC_LAYER(LayerIdx));
  1151. /* Process locked */
  1152. __HAL_LOCK(hltdc);
  1153. /* Change LTDC peripheral state */
  1154. hltdc->State = HAL_LTDC_STATE_BUSY;
  1155. /* get LayerIdx used pixel format */
  1156. pixelFormat = hltdc->LayerCfg[LayerIdx].PixelFormat;
  1157. if (pixelFormat == LTDC_PIXEL_FORMAT_ARGB8888)
  1158. {
  1159. tmp = 4U;
  1160. }
  1161. else if (pixelFormat == LTDC_PIXEL_FORMAT_RGB888)
  1162. {
  1163. tmp = 3U;
  1164. }
  1165. else if ((pixelFormat == LTDC_PIXEL_FORMAT_ARGB4444) || \
  1166. (pixelFormat == LTDC_PIXEL_FORMAT_RGB565) || \
  1167. (pixelFormat == LTDC_PIXEL_FORMAT_ARGB1555) || \
  1168. (pixelFormat == LTDC_PIXEL_FORMAT_AL88))
  1169. {
  1170. tmp = 2U;
  1171. }
  1172. else
  1173. {
  1174. tmp = 1U;
  1175. }
  1176. pitchUpdate = ((LinePitchInPixels * tmp) << 16U);
  1177. /* Clear previously set standard pitch */
  1178. LTDC_LAYER(hltdc, LayerIdx)->CFBLR &= ~LTDC_LxCFBLR_CFBP;
  1179. /* Set the Reload type as immediate update of LTDC pitch configured above */
  1180. LTDC->SRCR |= LTDC_SRCR_IMR;
  1181. /* Set new line pitch value */
  1182. LTDC_LAYER(hltdc, LayerIdx)->CFBLR |= pitchUpdate;
  1183. /* Set the Reload type as immediate update of LTDC pitch configured above */
  1184. LTDC->SRCR |= LTDC_SRCR_IMR;
  1185. /* Change the LTDC state*/
  1186. hltdc->State = HAL_LTDC_STATE_READY;
  1187. /* Process unlocked */
  1188. __HAL_UNLOCK(hltdc);
  1189. return HAL_OK;
  1190. }
  1191. /**
  1192. * @brief Define the position of the line interrupt.
  1193. * @param hltdc pointer to a LTDC_HandleTypeDef structure that contains
  1194. * the configuration information for the LTDC.
  1195. * @param Line Line Interrupt Position.
  1196. * @note User application may resort to HAL_LTDC_LineEventCallback() at line interrupt generation.
  1197. * @retval HAL status
  1198. */
  1199. HAL_StatusTypeDef HAL_LTDC_ProgramLineEvent(LTDC_HandleTypeDef *hltdc, uint32_t Line)
  1200. {
  1201. /* Check the parameters */
  1202. assert_param(IS_LTDC_LIPOS(Line));
  1203. /* Process locked */
  1204. __HAL_LOCK(hltdc);
  1205. /* Change LTDC peripheral state */
  1206. hltdc->State = HAL_LTDC_STATE_BUSY;
  1207. /* Disable the Line interrupt */
  1208. __HAL_LTDC_DISABLE_IT(hltdc, LTDC_IT_LI);
  1209. /* Set the Line Interrupt position */
  1210. LTDC->LIPCR = (uint32_t)Line;
  1211. /* Enable the Line interrupt */
  1212. __HAL_LTDC_ENABLE_IT(hltdc, LTDC_IT_LI);
  1213. /* Change the LTDC state*/
  1214. hltdc->State = HAL_LTDC_STATE_READY;
  1215. /* Process unlocked */
  1216. __HAL_UNLOCK(hltdc);
  1217. return HAL_OK;
  1218. }
  1219. /**
  1220. * @brief Reload LTDC Layers configuration.
  1221. * @param hltdc pointer to a LTDC_HandleTypeDef structure that contains
  1222. * the configuration information for the LTDC.
  1223. * @param ReloadType This parameter can be one of the following values :
  1224. * LTDC_RELOAD_IMMEDIATE : Immediate Reload
  1225. * LTDC_RELOAD_VERTICAL_BLANKING : Reload in the next Vertical Blanking
  1226. * @note User application may resort to HAL_LTDC_ReloadEventCallback() at reload interrupt generation.
  1227. * @retval HAL status
  1228. */
  1229. HAL_StatusTypeDef HAL_LTDC_Reload(LTDC_HandleTypeDef *hltdc, uint32_t ReloadType)
  1230. {
  1231. /* Check the parameters */
  1232. assert_param(IS_LTDC_RELOAD(ReloadType));
  1233. /* Process locked */
  1234. __HAL_LOCK(hltdc);
  1235. /* Change LTDC peripheral state */
  1236. hltdc->State = HAL_LTDC_STATE_BUSY;
  1237. /* Enable the Reload interrupt */
  1238. __HAL_LTDC_ENABLE_IT(hltdc, LTDC_IT_RR);
  1239. /* Apply Reload type */
  1240. hltdc->Instance->SRCR = ReloadType;
  1241. /* Change the LTDC state*/
  1242. hltdc->State = HAL_LTDC_STATE_READY;
  1243. /* Process unlocked */
  1244. __HAL_UNLOCK(hltdc);
  1245. return HAL_OK;
  1246. }
  1247. /**
  1248. * @brief Configure the LTDC Layer according to the specified without reloading
  1249. * parameters in the LTDC_InitTypeDef and create the associated handle.
  1250. * Variant of the function HAL_LTDC_ConfigLayer without immediate reload.
  1251. * @param hltdc pointer to a LTDC_HandleTypeDef structure that contains
  1252. * the configuration information for the LTDC.
  1253. * @param pLayerCfg pointer to a LTDC_LayerCfgTypeDef structure that contains
  1254. * the configuration information for the Layer.
  1255. * @param LayerIdx LTDC Layer index.
  1256. * This parameter can be one of the following values:
  1257. * LTDC_LAYER_1 (0) or LTDC_LAYER_2 (1)
  1258. * @retval HAL status
  1259. */
  1260. HAL_StatusTypeDef HAL_LTDC_ConfigLayer_NoReload(LTDC_HandleTypeDef *hltdc, LTDC_LayerCfgTypeDef *pLayerCfg,
  1261. uint32_t LayerIdx)
  1262. {
  1263. /* Check the parameters */
  1264. assert_param(IS_LTDC_LAYER(LayerIdx));
  1265. assert_param(IS_LTDC_HCONFIGST(pLayerCfg->WindowX0));
  1266. assert_param(IS_LTDC_HCONFIGSP(pLayerCfg->WindowX1));
  1267. assert_param(IS_LTDC_VCONFIGST(pLayerCfg->WindowY0));
  1268. assert_param(IS_LTDC_VCONFIGSP(pLayerCfg->WindowY1));
  1269. assert_param(IS_LTDC_PIXEL_FORMAT(pLayerCfg->PixelFormat));
  1270. assert_param(IS_LTDC_ALPHA(pLayerCfg->Alpha));
  1271. assert_param(IS_LTDC_ALPHA(pLayerCfg->Alpha0));
  1272. assert_param(IS_LTDC_BLENDING_FACTOR1(pLayerCfg->BlendingFactor1));
  1273. assert_param(IS_LTDC_BLENDING_FACTOR2(pLayerCfg->BlendingFactor2));
  1274. assert_param(IS_LTDC_CFBLL(pLayerCfg->ImageWidth));
  1275. assert_param(IS_LTDC_CFBLNBR(pLayerCfg->ImageHeight));
  1276. /* Process locked */
  1277. __HAL_LOCK(hltdc);
  1278. /* Change LTDC peripheral state */
  1279. hltdc->State = HAL_LTDC_STATE_BUSY;
  1280. /* Copy new layer configuration into handle structure */
  1281. hltdc->LayerCfg[LayerIdx] = *pLayerCfg;
  1282. /* Configure the LTDC Layer */
  1283. LTDC_SetConfig(hltdc, pLayerCfg, LayerIdx);
  1284. /* Initialize the LTDC state*/
  1285. hltdc->State = HAL_LTDC_STATE_READY;
  1286. /* Process unlocked */
  1287. __HAL_UNLOCK(hltdc);
  1288. return HAL_OK;
  1289. }
  1290. /**
  1291. * @brief Set the LTDC window size without reloading.
  1292. * Variant of the function HAL_LTDC_SetWindowSize without immediate reload.
  1293. * @param hltdc pointer to a LTDC_HandleTypeDef structure that contains
  1294. * the configuration information for the LTDC.
  1295. * @param XSize LTDC Pixel per line
  1296. * @param YSize LTDC Line number
  1297. * @param LayerIdx LTDC Layer index.
  1298. * This parameter can be one of the following values:
  1299. * LTDC_LAYER_1 (0) or LTDC_LAYER_2 (1)
  1300. * @retval HAL status
  1301. */
  1302. HAL_StatusTypeDef HAL_LTDC_SetWindowSize_NoReload(LTDC_HandleTypeDef *hltdc, uint32_t XSize, uint32_t YSize,
  1303. uint32_t LayerIdx)
  1304. {
  1305. LTDC_LayerCfgTypeDef *pLayerCfg;
  1306. /* Check the parameters (Layers parameters)*/
  1307. assert_param(IS_LTDC_LAYER(LayerIdx));
  1308. assert_param(IS_LTDC_CFBLL(XSize));
  1309. assert_param(IS_LTDC_CFBLNBR(YSize));
  1310. /* Process locked */
  1311. __HAL_LOCK(hltdc);
  1312. /* Change LTDC peripheral state */
  1313. hltdc->State = HAL_LTDC_STATE_BUSY;
  1314. /* Get layer configuration from handle structure */
  1315. pLayerCfg = &hltdc->LayerCfg[LayerIdx];
  1316. /* update horizontal stop */
  1317. pLayerCfg->WindowX1 = XSize + pLayerCfg->WindowX0;
  1318. /* update vertical stop */
  1319. pLayerCfg->WindowY1 = YSize + pLayerCfg->WindowY0;
  1320. /* Reconfigures the color frame buffer pitch in byte */
  1321. pLayerCfg->ImageWidth = XSize;
  1322. /* Reconfigures the frame buffer line number */
  1323. pLayerCfg->ImageHeight = YSize;
  1324. /* Set LTDC parameters */
  1325. LTDC_SetConfig(hltdc, pLayerCfg, LayerIdx);
  1326. /* Change the LTDC state*/
  1327. hltdc->State = HAL_LTDC_STATE_READY;
  1328. /* Process unlocked */
  1329. __HAL_UNLOCK(hltdc);
  1330. return HAL_OK;
  1331. }
  1332. /**
  1333. * @brief Set the LTDC window position without reloading.
  1334. * Variant of the function HAL_LTDC_SetWindowPosition without immediate reload.
  1335. * @param hltdc pointer to a LTDC_HandleTypeDef structure that contains
  1336. * the configuration information for the LTDC.
  1337. * @param X0 LTDC window X offset
  1338. * @param Y0 LTDC window Y offset
  1339. * @param LayerIdx LTDC Layer index.
  1340. * This parameter can be one of the following values:
  1341. * LTDC_LAYER_1 (0) or LTDC_LAYER_2 (1)
  1342. * @retval HAL status
  1343. */
  1344. HAL_StatusTypeDef HAL_LTDC_SetWindowPosition_NoReload(LTDC_HandleTypeDef *hltdc, uint32_t X0, uint32_t Y0,
  1345. uint32_t LayerIdx)
  1346. {
  1347. LTDC_LayerCfgTypeDef *pLayerCfg;
  1348. /* Check the parameters */
  1349. assert_param(IS_LTDC_LAYER(LayerIdx));
  1350. assert_param(IS_LTDC_CFBLL(X0));
  1351. assert_param(IS_LTDC_CFBLNBR(Y0));
  1352. /* Process locked */
  1353. __HAL_LOCK(hltdc);
  1354. /* Change LTDC peripheral state */
  1355. hltdc->State = HAL_LTDC_STATE_BUSY;
  1356. /* Get layer configuration from handle structure */
  1357. pLayerCfg = &hltdc->LayerCfg[LayerIdx];
  1358. /* update horizontal start/stop */
  1359. pLayerCfg->WindowX0 = X0;
  1360. pLayerCfg->WindowX1 = X0 + pLayerCfg->ImageWidth;
  1361. /* update vertical start/stop */
  1362. pLayerCfg->WindowY0 = Y0;
  1363. pLayerCfg->WindowY1 = Y0 + pLayerCfg->ImageHeight;
  1364. /* Set LTDC parameters */
  1365. LTDC_SetConfig(hltdc, pLayerCfg, LayerIdx);
  1366. /* Change the LTDC state*/
  1367. hltdc->State = HAL_LTDC_STATE_READY;
  1368. /* Process unlocked */
  1369. __HAL_UNLOCK(hltdc);
  1370. return HAL_OK;
  1371. }
  1372. /**
  1373. * @brief Reconfigure the pixel format without reloading.
  1374. * Variant of the function HAL_LTDC_SetPixelFormat without immediate reload.
  1375. * @param hltdc pointer to a LTDC_HandleTypeDfef structure that contains
  1376. * the configuration information for the LTDC.
  1377. * @param Pixelformat new pixel format value.
  1378. * @param LayerIdx LTDC Layer index.
  1379. * This parameter can be one of the following values:
  1380. * LTDC_LAYER_1 (0) or LTDC_LAYER_2 (1).
  1381. * @retval HAL status
  1382. */
  1383. HAL_StatusTypeDef HAL_LTDC_SetPixelFormat_NoReload(LTDC_HandleTypeDef *hltdc, uint32_t Pixelformat, uint32_t LayerIdx)
  1384. {
  1385. LTDC_LayerCfgTypeDef *pLayerCfg;
  1386. /* Check the parameters */
  1387. assert_param(IS_LTDC_PIXEL_FORMAT(Pixelformat));
  1388. assert_param(IS_LTDC_LAYER(LayerIdx));
  1389. /* Process locked */
  1390. __HAL_LOCK(hltdc);
  1391. /* Change LTDC peripheral state */
  1392. hltdc->State = HAL_LTDC_STATE_BUSY;
  1393. /* Get layer configuration from handle structure */
  1394. pLayerCfg = &hltdc->LayerCfg[LayerIdx];
  1395. /* Reconfigure the pixel format */
  1396. pLayerCfg->PixelFormat = Pixelformat;
  1397. /* Set LTDC parameters */
  1398. LTDC_SetConfig(hltdc, pLayerCfg, LayerIdx);
  1399. /* Change the LTDC state*/
  1400. hltdc->State = HAL_LTDC_STATE_READY;
  1401. /* Process unlocked */
  1402. __HAL_UNLOCK(hltdc);
  1403. return HAL_OK;
  1404. }
  1405. /**
  1406. * @brief Reconfigure the layer alpha value without reloading.
  1407. * Variant of the function HAL_LTDC_SetAlpha without immediate reload.
  1408. * @param hltdc pointer to a LTDC_HandleTypeDef structure that contains
  1409. * the configuration information for the LTDC.
  1410. * @param Alpha new alpha value.
  1411. * @param LayerIdx LTDC Layer index.
  1412. * This parameter can be one of the following values:
  1413. * LTDC_LAYER_1 (0) or LTDC_LAYER_2 (1)
  1414. * @retval HAL status
  1415. */
  1416. HAL_StatusTypeDef HAL_LTDC_SetAlpha_NoReload(LTDC_HandleTypeDef *hltdc, uint32_t Alpha, uint32_t LayerIdx)
  1417. {
  1418. LTDC_LayerCfgTypeDef *pLayerCfg;
  1419. /* Check the parameters */
  1420. assert_param(IS_LTDC_ALPHA(Alpha));
  1421. assert_param(IS_LTDC_LAYER(LayerIdx));
  1422. /* Process locked */
  1423. __HAL_LOCK(hltdc);
  1424. /* Change LTDC peripheral state */
  1425. hltdc->State = HAL_LTDC_STATE_BUSY;
  1426. /* Get layer configuration from handle structure */
  1427. pLayerCfg = &hltdc->LayerCfg[LayerIdx];
  1428. /* Reconfigure the Alpha value */
  1429. pLayerCfg->Alpha = Alpha;
  1430. /* Set LTDC parameters */
  1431. LTDC_SetConfig(hltdc, pLayerCfg, LayerIdx);
  1432. /* Change the LTDC state*/
  1433. hltdc->State = HAL_LTDC_STATE_READY;
  1434. /* Process unlocked */
  1435. __HAL_UNLOCK(hltdc);
  1436. return HAL_OK;
  1437. }
  1438. /**
  1439. * @brief Reconfigure the frame buffer Address without reloading.
  1440. * Variant of the function HAL_LTDC_SetAddress without immediate reload.
  1441. * @param hltdc pointer to a LTDC_HandleTypeDef structure that contains
  1442. * the configuration information for the LTDC.
  1443. * @param Address new address value.
  1444. * @param LayerIdx LTDC Layer index.
  1445. * This parameter can be one of the following values:
  1446. * LTDC_LAYER_1 (0) or LTDC_LAYER_2 (1).
  1447. * @retval HAL status
  1448. */
  1449. HAL_StatusTypeDef HAL_LTDC_SetAddress_NoReload(LTDC_HandleTypeDef *hltdc, uint32_t Address, uint32_t LayerIdx)
  1450. {
  1451. LTDC_LayerCfgTypeDef *pLayerCfg;
  1452. /* Check the parameters */
  1453. assert_param(IS_LTDC_LAYER(LayerIdx));
  1454. /* Process locked */
  1455. __HAL_LOCK(hltdc);
  1456. /* Change LTDC peripheral state */
  1457. hltdc->State = HAL_LTDC_STATE_BUSY;
  1458. /* Get layer configuration from handle structure */
  1459. pLayerCfg = &hltdc->LayerCfg[LayerIdx];
  1460. /* Reconfigure the Address */
  1461. pLayerCfg->FBStartAdress = Address;
  1462. /* Set LTDC parameters */
  1463. LTDC_SetConfig(hltdc, pLayerCfg, LayerIdx);
  1464. /* Change the LTDC state*/
  1465. hltdc->State = HAL_LTDC_STATE_READY;
  1466. /* Process unlocked */
  1467. __HAL_UNLOCK(hltdc);
  1468. return HAL_OK;
  1469. }
  1470. /**
  1471. * @brief Function used to reconfigure the pitch for specific cases where the attached LayerIdx buffer have a width
  1472. * that is larger than the one intended to be displayed on screen. Example of a buffer 800x480 attached to
  1473. * layer for which we want to read and display on screen only a portion 320x240 taken in the center
  1474. * of the buffer.
  1475. * The pitch in pixels will be in that case 800 pixels and not 320 pixels as initially configured by
  1476. * previous call to HAL_LTDC_ConfigLayer().
  1477. * @note This function should be called only after a previous call to HAL_LTDC_ConfigLayer() to modify the default
  1478. * pitch configured by HAL_LTDC_ConfigLayer() when required (refer to example described just above).
  1479. * Variant of the function HAL_LTDC_SetPitch without immediate reload.
  1480. * @param hltdc pointer to a LTDC_HandleTypeDef structure that contains
  1481. * the configuration information for the LTDC.
  1482. * @param LinePitchInPixels New line pitch in pixels to configure for LTDC layer 'LayerIdx'.
  1483. * @param LayerIdx LTDC layer index concerned by the modification of line pitch.
  1484. * @retval HAL status
  1485. */
  1486. HAL_StatusTypeDef HAL_LTDC_SetPitch_NoReload(LTDC_HandleTypeDef *hltdc, uint32_t LinePitchInPixels, uint32_t LayerIdx)
  1487. {
  1488. uint32_t tmp;
  1489. uint32_t pitchUpdate;
  1490. uint32_t pixelFormat;
  1491. /* Check the parameters */
  1492. assert_param(IS_LTDC_LAYER(LayerIdx));
  1493. /* Process locked */
  1494. __HAL_LOCK(hltdc);
  1495. /* Change LTDC peripheral state */
  1496. hltdc->State = HAL_LTDC_STATE_BUSY;
  1497. /* get LayerIdx used pixel format */
  1498. pixelFormat = hltdc->LayerCfg[LayerIdx].PixelFormat;
  1499. if (pixelFormat == LTDC_PIXEL_FORMAT_ARGB8888)
  1500. {
  1501. tmp = 4U;
  1502. }
  1503. else if (pixelFormat == LTDC_PIXEL_FORMAT_RGB888)
  1504. {
  1505. tmp = 3U;
  1506. }
  1507. else if ((pixelFormat == LTDC_PIXEL_FORMAT_ARGB4444) || \
  1508. (pixelFormat == LTDC_PIXEL_FORMAT_RGB565) || \
  1509. (pixelFormat == LTDC_PIXEL_FORMAT_ARGB1555) || \
  1510. (pixelFormat == LTDC_PIXEL_FORMAT_AL88))
  1511. {
  1512. tmp = 2U;
  1513. }
  1514. else
  1515. {
  1516. tmp = 1U;
  1517. }
  1518. pitchUpdate = ((LinePitchInPixels * tmp) << 16U);
  1519. /* Clear previously set standard pitch */
  1520. LTDC_LAYER(hltdc, LayerIdx)->CFBLR &= ~LTDC_LxCFBLR_CFBP;
  1521. /* Set new line pitch value */
  1522. LTDC_LAYER(hltdc, LayerIdx)->CFBLR |= pitchUpdate;
  1523. /* Change the LTDC state*/
  1524. hltdc->State = HAL_LTDC_STATE_READY;
  1525. /* Process unlocked */
  1526. __HAL_UNLOCK(hltdc);
  1527. return HAL_OK;
  1528. }
  1529. /**
  1530. * @brief Configure the color keying without reloading.
  1531. * Variant of the function HAL_LTDC_ConfigColorKeying without immediate reload.
  1532. * @param hltdc pointer to a LTDC_HandleTypeDef structure that contains
  1533. * the configuration information for the LTDC.
  1534. * @param RGBValue the color key value
  1535. * @param LayerIdx LTDC Layer index.
  1536. * This parameter can be one of the following values:
  1537. * LTDC_LAYER_1 (0) or LTDC_LAYER_2 (1)
  1538. * @retval HAL status
  1539. */
  1540. HAL_StatusTypeDef HAL_LTDC_ConfigColorKeying_NoReload(LTDC_HandleTypeDef *hltdc, uint32_t RGBValue, uint32_t LayerIdx)
  1541. {
  1542. /* Check the parameters */
  1543. assert_param(IS_LTDC_LAYER(LayerIdx));
  1544. /* Process locked */
  1545. __HAL_LOCK(hltdc);
  1546. /* Change LTDC peripheral state */
  1547. hltdc->State = HAL_LTDC_STATE_BUSY;
  1548. /* Configure the default color values */
  1549. LTDC_LAYER(hltdc, LayerIdx)->CKCR &= ~(LTDC_LxCKCR_CKBLUE | LTDC_LxCKCR_CKGREEN | LTDC_LxCKCR_CKRED);
  1550. LTDC_LAYER(hltdc, LayerIdx)->CKCR = RGBValue;
  1551. /* Change the LTDC state*/
  1552. hltdc->State = HAL_LTDC_STATE_READY;
  1553. /* Process unlocked */
  1554. __HAL_UNLOCK(hltdc);
  1555. return HAL_OK;
  1556. }
  1557. /**
  1558. * @brief Enable the color keying without reloading.
  1559. * Variant of the function HAL_LTDC_EnableColorKeying without immediate reload.
  1560. * @param hltdc pointer to a LTDC_HandleTypeDef structure that contains
  1561. * the configuration information for the LTDC.
  1562. * @param LayerIdx LTDC Layer index.
  1563. * This parameter can be one of the following values:
  1564. * LTDC_LAYER_1 (0) or LTDC_LAYER_2 (1)
  1565. * @retval HAL status
  1566. */
  1567. HAL_StatusTypeDef HAL_LTDC_EnableColorKeying_NoReload(LTDC_HandleTypeDef *hltdc, uint32_t LayerIdx)
  1568. {
  1569. /* Check the parameters */
  1570. assert_param(IS_LTDC_LAYER(LayerIdx));
  1571. /* Process locked */
  1572. __HAL_LOCK(hltdc);
  1573. /* Change LTDC peripheral state */
  1574. hltdc->State = HAL_LTDC_STATE_BUSY;
  1575. /* Enable LTDC color keying by setting COLKEN bit */
  1576. LTDC_LAYER(hltdc, LayerIdx)->CR |= (uint32_t)LTDC_LxCR_COLKEN;
  1577. /* Change the LTDC state*/
  1578. hltdc->State = HAL_LTDC_STATE_READY;
  1579. /* Process unlocked */
  1580. __HAL_UNLOCK(hltdc);
  1581. return HAL_OK;
  1582. }
  1583. /**
  1584. * @brief Disable the color keying without reloading.
  1585. * Variant of the function HAL_LTDC_DisableColorKeying without immediate reload.
  1586. * @param hltdc pointer to a LTDC_HandleTypeDef structure that contains
  1587. * the configuration information for the LTDC.
  1588. * @param LayerIdx LTDC Layer index.
  1589. * This parameter can be one of the following values:
  1590. * LTDC_LAYER_1 (0) or LTDC_LAYER_2 (1)
  1591. * @retval HAL status
  1592. */
  1593. HAL_StatusTypeDef HAL_LTDC_DisableColorKeying_NoReload(LTDC_HandleTypeDef *hltdc, uint32_t LayerIdx)
  1594. {
  1595. /* Check the parameters */
  1596. assert_param(IS_LTDC_LAYER(LayerIdx));
  1597. /* Process locked */
  1598. __HAL_LOCK(hltdc);
  1599. /* Change LTDC peripheral state */
  1600. hltdc->State = HAL_LTDC_STATE_BUSY;
  1601. /* Disable LTDC color keying by setting COLKEN bit */
  1602. LTDC_LAYER(hltdc, LayerIdx)->CR &= ~(uint32_t)LTDC_LxCR_COLKEN;
  1603. /* Change the LTDC state*/
  1604. hltdc->State = HAL_LTDC_STATE_READY;
  1605. /* Process unlocked */
  1606. __HAL_UNLOCK(hltdc);
  1607. return HAL_OK;
  1608. }
  1609. /**
  1610. * @brief Enable the color lookup table without reloading.
  1611. * Variant of the function HAL_LTDC_EnableCLUT without immediate reload.
  1612. * @param hltdc pointer to a LTDC_HandleTypeDef structure that contains
  1613. * the configuration information for the LTDC.
  1614. * @param LayerIdx LTDC Layer index.
  1615. * This parameter can be one of the following values:
  1616. * LTDC_LAYER_1 (0) or LTDC_LAYER_2 (1)
  1617. * @retval HAL status
  1618. */
  1619. HAL_StatusTypeDef HAL_LTDC_EnableCLUT_NoReload(LTDC_HandleTypeDef *hltdc, uint32_t LayerIdx)
  1620. {
  1621. /* Check the parameters */
  1622. assert_param(IS_LTDC_LAYER(LayerIdx));
  1623. /* Process locked */
  1624. __HAL_LOCK(hltdc);
  1625. /* Change LTDC peripheral state */
  1626. hltdc->State = HAL_LTDC_STATE_BUSY;
  1627. /* Disable LTDC color lookup table by setting CLUTEN bit */
  1628. LTDC_LAYER(hltdc, LayerIdx)->CR |= (uint32_t)LTDC_LxCR_CLUTEN;
  1629. /* Change the LTDC state*/
  1630. hltdc->State = HAL_LTDC_STATE_READY;
  1631. /* Process unlocked */
  1632. __HAL_UNLOCK(hltdc);
  1633. return HAL_OK;
  1634. }
  1635. /**
  1636. * @brief Disable the color lookup table without reloading.
  1637. * Variant of the function HAL_LTDC_DisableCLUT without immediate reload.
  1638. * @param hltdc pointer to a LTDC_HandleTypeDef structure that contains
  1639. * the configuration information for the LTDC.
  1640. * @param LayerIdx LTDC Layer index.
  1641. * This parameter can be one of the following values:
  1642. * LTDC_LAYER_1 (0) or LTDC_LAYER_2 (1)
  1643. * @retval HAL status
  1644. */
  1645. HAL_StatusTypeDef HAL_LTDC_DisableCLUT_NoReload(LTDC_HandleTypeDef *hltdc, uint32_t LayerIdx)
  1646. {
  1647. /* Check the parameters */
  1648. assert_param(IS_LTDC_LAYER(LayerIdx));
  1649. /* Process locked */
  1650. __HAL_LOCK(hltdc);
  1651. /* Change LTDC peripheral state */
  1652. hltdc->State = HAL_LTDC_STATE_BUSY;
  1653. /* Disable LTDC color lookup table by setting CLUTEN bit */
  1654. LTDC_LAYER(hltdc, LayerIdx)->CR &= ~(uint32_t)LTDC_LxCR_CLUTEN;
  1655. /* Change the LTDC state*/
  1656. hltdc->State = HAL_LTDC_STATE_READY;
  1657. /* Process unlocked */
  1658. __HAL_UNLOCK(hltdc);
  1659. return HAL_OK;
  1660. }
  1661. /**
  1662. * @}
  1663. */
  1664. /** @defgroup LTDC_Exported_Functions_Group4 Peripheral State and Errors functions
  1665. * @brief Peripheral State and Errors functions
  1666. *
  1667. @verbatim
  1668. ===============================================================================
  1669. ##### Peripheral State and Errors functions #####
  1670. ===============================================================================
  1671. [..]
  1672. This subsection provides functions allowing to
  1673. (+) Check the LTDC handle state.
  1674. (+) Get the LTDC handle error code.
  1675. @endverbatim
  1676. * @{
  1677. */
  1678. /**
  1679. * @brief Return the LTDC handle state.
  1680. * @param hltdc pointer to a LTDC_HandleTypeDef structure that contains
  1681. * the configuration information for the LTDC.
  1682. * @retval HAL state
  1683. */
  1684. HAL_LTDC_StateTypeDef HAL_LTDC_GetState(LTDC_HandleTypeDef *hltdc)
  1685. {
  1686. return hltdc->State;
  1687. }
  1688. /**
  1689. * @brief Return the LTDC handle error code.
  1690. * @param hltdc pointer to a LTDC_HandleTypeDef structure that contains
  1691. * the configuration information for the LTDC.
  1692. * @retval LTDC Error Code
  1693. */
  1694. uint32_t HAL_LTDC_GetError(LTDC_HandleTypeDef *hltdc)
  1695. {
  1696. return hltdc->ErrorCode;
  1697. }
  1698. /**
  1699. * @}
  1700. */
  1701. /**
  1702. * @}
  1703. */
  1704. /** @defgroup LTDC_Private_Functions LTDC Private Functions
  1705. * @{
  1706. */
  1707. /**
  1708. * @brief Configure the LTDC peripheral
  1709. * @param hltdc Pointer to a LTDC_HandleTypeDef structure that contains
  1710. * the configuration information for the LTDC.
  1711. * @param pLayerCfg Pointer LTDC Layer Configuration structure
  1712. * @param LayerIdx LTDC Layer index.
  1713. * This parameter can be one of the following values: LTDC_LAYER_1 (0) or LTDC_LAYER_2 (1)
  1714. * @retval None
  1715. */
  1716. static void LTDC_SetConfig(LTDC_HandleTypeDef *hltdc, LTDC_LayerCfgTypeDef *pLayerCfg, uint32_t LayerIdx)
  1717. {
  1718. uint32_t tmp;
  1719. uint32_t tmp1;
  1720. uint32_t tmp2;
  1721. /* Configure the horizontal start and stop position */
  1722. tmp = ((pLayerCfg->WindowX1 + ((hltdc->Instance->BPCR & LTDC_BPCR_AHBP) >> 16U)) << 16U);
  1723. LTDC_LAYER(hltdc, LayerIdx)->WHPCR &= ~(LTDC_LxWHPCR_WHSTPOS | LTDC_LxWHPCR_WHSPPOS);
  1724. LTDC_LAYER(hltdc, LayerIdx)->WHPCR = ((pLayerCfg->WindowX0 + \
  1725. ((hltdc->Instance->BPCR & LTDC_BPCR_AHBP) >> 16U) + 1U) | tmp);
  1726. /* Configure the vertical start and stop position */
  1727. tmp = ((pLayerCfg->WindowY1 + (hltdc->Instance->BPCR & LTDC_BPCR_AVBP)) << 16U);
  1728. LTDC_LAYER(hltdc, LayerIdx)->WVPCR &= ~(LTDC_LxWVPCR_WVSTPOS | LTDC_LxWVPCR_WVSPPOS);
  1729. LTDC_LAYER(hltdc, LayerIdx)->WVPCR = ((pLayerCfg->WindowY0 + (hltdc->Instance->BPCR & LTDC_BPCR_AVBP) + 1U) | tmp);
  1730. /* Specifies the pixel format */
  1731. LTDC_LAYER(hltdc, LayerIdx)->PFCR &= ~(LTDC_LxPFCR_PF);
  1732. LTDC_LAYER(hltdc, LayerIdx)->PFCR = (pLayerCfg->PixelFormat);
  1733. /* Configure the default color values */
  1734. tmp = ((uint32_t)(pLayerCfg->Backcolor.Green) << 8U);
  1735. tmp1 = ((uint32_t)(pLayerCfg->Backcolor.Red) << 16U);
  1736. tmp2 = (pLayerCfg->Alpha0 << 24U);
  1737. LTDC_LAYER(hltdc, LayerIdx)->DCCR &= ~(LTDC_LxDCCR_DCBLUE | LTDC_LxDCCR_DCGREEN | LTDC_LxDCCR_DCRED |
  1738. LTDC_LxDCCR_DCALPHA);
  1739. LTDC_LAYER(hltdc, LayerIdx)->DCCR = (pLayerCfg->Backcolor.Blue | tmp | tmp1 | tmp2);
  1740. /* Specifies the constant alpha value */
  1741. LTDC_LAYER(hltdc, LayerIdx)->CACR &= ~(LTDC_LxCACR_CONSTA);
  1742. LTDC_LAYER(hltdc, LayerIdx)->CACR = (pLayerCfg->Alpha);
  1743. /* Specifies the blending factors */
  1744. LTDC_LAYER(hltdc, LayerIdx)->BFCR &= ~(LTDC_LxBFCR_BF2 | LTDC_LxBFCR_BF1);
  1745. LTDC_LAYER(hltdc, LayerIdx)->BFCR = (pLayerCfg->BlendingFactor1 | pLayerCfg->BlendingFactor2);
  1746. /* Configure the color frame buffer start address */
  1747. LTDC_LAYER(hltdc, LayerIdx)->CFBAR &= ~(LTDC_LxCFBAR_CFBADD);
  1748. LTDC_LAYER(hltdc, LayerIdx)->CFBAR = (pLayerCfg->FBStartAdress);
  1749. if (pLayerCfg->PixelFormat == LTDC_PIXEL_FORMAT_ARGB8888)
  1750. {
  1751. tmp = 4U;
  1752. }
  1753. else if (pLayerCfg->PixelFormat == LTDC_PIXEL_FORMAT_RGB888)
  1754. {
  1755. tmp = 3U;
  1756. }
  1757. else if ((pLayerCfg->PixelFormat == LTDC_PIXEL_FORMAT_ARGB4444) || \
  1758. (pLayerCfg->PixelFormat == LTDC_PIXEL_FORMAT_RGB565) || \
  1759. (pLayerCfg->PixelFormat == LTDC_PIXEL_FORMAT_ARGB1555) || \
  1760. (pLayerCfg->PixelFormat == LTDC_PIXEL_FORMAT_AL88))
  1761. {
  1762. tmp = 2U;
  1763. }
  1764. else
  1765. {
  1766. tmp = 1U;
  1767. }
  1768. /* Configure the color frame buffer pitch in byte */
  1769. LTDC_LAYER(hltdc, LayerIdx)->CFBLR &= ~(LTDC_LxCFBLR_CFBLL | LTDC_LxCFBLR_CFBP);
  1770. LTDC_LAYER(hltdc, LayerIdx)->CFBLR = (((pLayerCfg->ImageWidth * tmp) << 16U) | \
  1771. (((pLayerCfg->WindowX1 - pLayerCfg->WindowX0) * tmp) + 3U));
  1772. /* Configure the frame buffer line number */
  1773. LTDC_LAYER(hltdc, LayerIdx)->CFBLNR &= ~(LTDC_LxCFBLNR_CFBLNBR);
  1774. LTDC_LAYER(hltdc, LayerIdx)->CFBLNR = (pLayerCfg->ImageHeight);
  1775. /* Enable LTDC_Layer by setting LEN bit */
  1776. LTDC_LAYER(hltdc, LayerIdx)->CR |= (uint32_t)LTDC_LxCR_LEN;
  1777. }
  1778. /**
  1779. * @}
  1780. */
  1781. /**
  1782. * @}
  1783. */
  1784. #endif /* LTDC */
  1785. #endif /* HAL_LTDC_MODULE_ENABLED */
  1786. /**
  1787. * @}
  1788. */