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