2 ******************************************************************************
3 * @file stm32f4xx_hal_ltdc.c
4 * @author MCD Application Team
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
16 ==============================================================================
17 ##### How to use this driver #####
18 ==============================================================================
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
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.
30 (#) Optionally, configure and enable the CLUT using HAL_LTDC_ConfigCLUT() and
31 HAL_LTDC_EnableCLUT functions.
33 (#) Optionally, enable the Dither using HAL_LTDC_EnableDither().
35 (#) Optionally, configure and enable the Color keying using HAL_LTDC_ConfigColorKeying()
36 and HAL_LTDC_EnableColorKeying functions.
38 (#) Optionally, configure LineInterrupt using HAL_LTDC_ProgramLineInterrupt()
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.
47 (#) To control LTDC state you can use the following function: HAL_LTDC_GetState()
49 *** LTDC HAL driver macros list ***
50 =============================================
52 Below the list of most used macros in LTDC HAL driver.
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.
66 (@) You can refer to the LTDC HAL driver header file for more useful macros
69 ******************************************************************************
72 * <h2><center>© COPYRIGHT(c) 2014 STMicroelectronics</center></h2>
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.
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.
96 ******************************************************************************
99 /* Includes ------------------------------------------------------------------*/
100 #include "stm32f4xx_hal.h"
102 /** @addtogroup STM32F4xx_HAL_Driver
106 * @brief LTDC HAL module driver
110 #ifdef HAL_LTDC_MODULE_ENABLED
112 #if defined(STM32F429xx) || defined(STM32F439xx)
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 ---------------------------------------------------------*/
122 /** @defgroup LTDC_Private_Functions
126 /** @defgroup LTDC_Group1 Initialization and Configuration functions
127 * @brief Initialization and Configuration functions
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
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.
148 HAL_StatusTypeDef
HAL_LTDC_Init(LTDC_HandleTypeDef
*hltdc
)
150 uint32_t tmp
= 0, tmp1
= 0;
152 /* Check the LTDC peripheral state */
153 if(hltdc
== HAL_NULL
)
158 /* Check function parameters */
159 assert_param(IS_LTDC_ALL_INSTANCE(hltdc
->Instance
));
160 assert_param(IS_LTDC_HSYNC(hltdc
->Init
.HorizontalSync
));
161 assert_param(IS_LTDC_VSYNC(hltdc
->Init
.VerticalSync
));
162 assert_param(IS_LTDC_AHBP(hltdc
->Init
.AccumulatedHBP
));
163 assert_param(IS_LTDC_AVBP(hltdc
->Init
.AccumulatedVBP
));
164 assert_param(IS_LTDC_AAH(hltdc
->Init
.AccumulatedActiveH
));
165 assert_param(IS_LTDC_AAW(hltdc
->Init
.AccumulatedActiveW
));
166 assert_param(IS_LTDC_TOTALH(hltdc
->Init
.TotalHeigh
));
167 assert_param(IS_LTDC_TOTALW(hltdc
->Init
.TotalWidth
));
168 assert_param(IS_LTDC_HSPOL(hltdc
->Init
.HSPolarity
));
169 assert_param(IS_LTDC_VSPOL(hltdc
->Init
.VSPolarity
));
170 assert_param(IS_LTDC_DEPOL(hltdc
->Init
.DEPolarity
));
171 assert_param(IS_LTDC_PCPOL(hltdc
->Init
.PCPolarity
));
173 if(hltdc
->State
== HAL_LTDC_STATE_RESET
)
175 /* Init the low level hardware */
176 HAL_LTDC_MspInit(hltdc
);
179 /* Change LTDC peripheral state */
180 hltdc
->State
= HAL_LTDC_STATE_BUSY
;
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
);
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
);
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
);
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
);
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
);
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
);
213 /* Enable the transfer Error interrupt */
214 __HAL_LTDC_ENABLE_IT(hltdc
, LTDC_IT_TE
);
216 /* Enable the FIFO underrun interrupt */
217 __HAL_LTDC_ENABLE_IT(hltdc
, LTDC_IT_FU
);
219 /* Enable LTDC by setting LTDCEN bit */
220 __HAL_LTDC_ENABLE(hltdc
);
222 /* Initialise the error code */
223 hltdc
->ErrorCode
= HAL_LTDC_ERROR_NONE
;
225 /* Initialize the LTDC state*/
226 hltdc
->State
= HAL_LTDC_STATE_READY
;
232 * @brief Deinitializes the LTDC peripheral registers to their default reset
234 * @param hltdc: pointer to a LTDC_HandleTypeDef structure that contains
235 * the configuration information for the LTDC.
239 HAL_StatusTypeDef
HAL_LTDC_DeInit(LTDC_HandleTypeDef
*hltdc
)
241 /* DeInit the low level hardware */
242 HAL_LTDC_MspDeInit(hltdc
);
244 /* Initialise the error code */
245 hltdc
->ErrorCode
= HAL_LTDC_ERROR_NONE
;
247 /* Initialize the LTDC state*/
248 hltdc
->State
= HAL_LTDC_STATE_RESET
;
257 * @brief Initializes the LTDC MSP.
258 * @param hltdc : pointer to a LTDC_HandleTypeDef structure that contains
259 * the configuration information for the LTDC.
262 __weak
void HAL_LTDC_MspInit(LTDC_HandleTypeDef
* hltdc
)
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
270 * @brief DeInitializes the LTDC MSP.
271 * @param hltdc : pointer to a LTDC_HandleTypeDef structure that contains
272 * the configuration information for the LTDC.
275 __weak
void HAL_LTDC_MspDeInit(LTDC_HandleTypeDef
* hltdc
)
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
286 /** @defgroup LTDC_Group2 IO operation functions
287 * @brief IO operation functions
290 ===============================================================================
291 ##### IO operation functions #####
292 ===============================================================================
293 [..] This section provides function allowing to:
294 (+) Handle LTDC interrupt request
300 * @brief Handles LTDC interrupt request.
301 * @param hltdc: pointer to a LTDC_HandleTypeDef structure that contains
302 * the configuration information for the LTDC.
305 void HAL_LTDC_IRQHandler(LTDC_HandleTypeDef
*hltdc
)
307 /* Transfer Error Interrupt management ***************************************/
308 if(__HAL_LTDC_GET_FLAG(hltdc
, LTDC_FLAG_TE
) != RESET
)
310 if(__HAL_LTDC_GET_IT_SOURCE(hltdc
, LTDC_IT_TE
) != RESET
)
312 /* Disable the transfer Error interrupt */
313 __HAL_LTDC_DISABLE_IT(hltdc
, LTDC_IT_TE
);
315 /* Clear the transfer error flag */
316 __HAL_LTDC_CLEAR_FLAG(hltdc
, LTDC_FLAG_TE
);
318 /* Update error code */
319 hltdc
->ErrorCode
|= HAL_LTDC_ERROR_TE
;
321 /* Change LTDC state */
322 hltdc
->State
= HAL_LTDC_STATE_ERROR
;
324 /* Process unlocked */
327 /* Transfer error Callback */
328 HAL_LTDC_ErrorCallback(hltdc
);
331 /* FIFO underrun Interrupt management ***************************************/
332 if(__HAL_LTDC_GET_FLAG(hltdc
, LTDC_FLAG_FU
) != RESET
)
334 if(__HAL_LTDC_GET_IT_SOURCE(hltdc
, LTDC_IT_FU
) != RESET
)
336 /* Disable the FIFO underrun interrupt */
337 __HAL_LTDC_DISABLE_IT(hltdc
, LTDC_IT_FU
);
339 /* Clear the FIFO underrun flag */
340 __HAL_LTDC_CLEAR_FLAG(hltdc
, LTDC_FLAG_FU
);
342 /* Update error code */
343 hltdc
->ErrorCode
|= HAL_LTDC_ERROR_FU
;
345 /* Change LTDC state */
346 hltdc
->State
= HAL_LTDC_STATE_ERROR
;
348 /* Process unlocked */
351 /* Transfer error Callback */
352 HAL_LTDC_ErrorCallback(hltdc
);
355 /* Line Interrupt management ************************************************/
356 if(__HAL_LTDC_GET_FLAG(hltdc
, LTDC_FLAG_LI
) != RESET
)
358 if(__HAL_LTDC_GET_IT_SOURCE(hltdc
, LTDC_IT_LI
) != RESET
)
360 /* Disable the Line interrupt */
361 __HAL_LTDC_DISABLE_IT(hltdc
, LTDC_IT_LI
);
363 /* Clear the Line interrupt flag */
364 __HAL_LTDC_CLEAR_FLAG(hltdc
, LTDC_FLAG_LI
);
366 /* Change LTDC state */
367 hltdc
->State
= HAL_LTDC_STATE_READY
;
369 /* Process unlocked */
372 /* Line interrupt Callback */
373 HAL_LTDC_LineEvenCallback(hltdc
);
379 * @brief Error LTDC callback.
380 * @param hltdc: pointer to a LTDC_HandleTypeDef structure that contains
381 * the configuration information for the LTDC.
384 __weak
void HAL_LTDC_ErrorCallback(LTDC_HandleTypeDef
*hltdc
)
386 /* NOTE : This function Should not be modified, when the callback is needed,
387 the HAL_LTDC_ErrorCallback could be implemented in the user file
392 * @brief Line Event callback.
393 * @param hltdc: pointer to a LTDC_HandleTypeDef structure that contains
394 * the configuration information for the LTDC.
397 __weak
void HAL_LTDC_LineEvenCallback(LTDC_HandleTypeDef
*hltdc
)
399 /* NOTE : This function Should not be modified, when the callback is needed,
400 the HAL_LTDC_LineEvenCallback could be implemented in the user file
408 /** @defgroup LTDC_Group3 Peripheral Control functions
409 * @brief Peripheral Control functions
412 ===============================================================================
413 ##### Peripheral Control functions #####
414 ===============================================================================
415 [..] This section provides functions allowing to:
416 (+) Configure the LTDC foreground or/and background parameters.
417 (+) Set the active layer.
418 (+) Configure the color keying.
419 (+) Configure the C-LUT.
420 (+) Enable / Disable the color keying.
421 (+) Enable / Disable the C-LUT.
422 (+) Update the layer position.
423 (+) Update the layer size.
424 (+) Update pixel format on the fly.
425 (+) Update transparency on the fly.
426 (+) Update address on the fly.
433 * @brief Configure the LTDC Layer according to the specified
434 * parameters in the LTDC_InitTypeDef and create the associated handle.
435 * @param hltdc: pointer to a LTDC_HandleTypeDef structure that contains
436 * the configuration information for the LTDC.
437 * @param pLayerCfg: pointer to a LTDC_LayerCfgTypeDef structure that contains
438 * the configuration information for the Layer.
439 * @param LayerIdx: LTDC Layer index.
440 * This parameter can be one of the following values:
444 HAL_StatusTypeDef
HAL_LTDC_ConfigLayer(LTDC_HandleTypeDef
*hltdc
, LTDC_LayerCfgTypeDef
*pLayerCfg
, uint32_t LayerIdx
)
449 /* Change LTDC peripheral state */
450 hltdc
->State
= HAL_LTDC_STATE_BUSY
;
452 /* Check the parameters */
453 assert_param(IS_LTDC_LAYER(LayerIdx
));
454 assert_param(IS_LTDC_PIXEL_FORMAT(pLayerCfg
->PixelFormat
));
455 assert_param(IS_LTDC_BLENDING_FACTOR1(pLayerCfg
->BlendingFactor1
));
456 assert_param(IS_LTDC_BLENDING_FACTOR2(pLayerCfg
->BlendingFactor2
));
457 assert_param(IS_LTDC_HCONFIGST(pLayerCfg
->WindowX0
));
458 assert_param(IS_LTDC_HCONFIGSP(pLayerCfg
->WindowX1
));
459 assert_param(IS_LTDC_VCONFIGST(pLayerCfg
->WindowY0
));
460 assert_param(IS_LTDC_VCONFIGSP(pLayerCfg
->WindowY1
));
461 assert_param(IS_LTDC_ALPHA(pLayerCfg
->Alpha0
));
462 assert_param(IS_LTDC_CFBLL(pLayerCfg
->ImageWidth
));
463 assert_param(IS_LTDC_CFBLNBR(pLayerCfg
->ImageHeight
));
465 /* Copy new layer configuration into handle structure */
466 hltdc
->LayerCfg
[LayerIdx
] = *pLayerCfg
;
468 /* Configure the LTDC Layer */
469 LTDC_SetConfig(hltdc
, pLayerCfg
, LayerIdx
);
471 /* Sets the Reload type */
472 hltdc
->Instance
->SRCR
= LTDC_SRCR_IMR
;
474 /* Initialize the LTDC state*/
475 hltdc
->State
= HAL_LTDC_STATE_READY
;
477 /* Process unlocked */
484 * @brief Configure the color keying.
485 * @param hltdc: pointer to a LTDC_HandleTypeDef structure that contains
486 * the configuration information for the LTDC.
487 * @param RGBValue: the color key value
488 * @param LayerIdx: LTDC Layer index.
489 * This parameter can be one of the following values:
493 HAL_StatusTypeDef
HAL_LTDC_ConfigColorKeying(LTDC_HandleTypeDef
*hltdc
, uint32_t RGBValue
, uint32_t LayerIdx
)
498 /* Change LTDC peripheral state */
499 hltdc
->State
= HAL_LTDC_STATE_BUSY
;
501 /* Check the parameters */
502 assert_param(IS_LTDC_LAYER(LayerIdx
));
504 /* Configures the default color values */
505 __HAL_LTDC_LAYER(hltdc
, LayerIdx
)->CKCR
&= ~(LTDC_LxCKCR_CKBLUE
| LTDC_LxCKCR_CKGREEN
| LTDC_LxCKCR_CKRED
);
506 __HAL_LTDC_LAYER(hltdc
, LayerIdx
)->CKCR
= RGBValue
;
508 /* Sets the Reload type */
509 hltdc
->Instance
->SRCR
= LTDC_SRCR_IMR
;
511 /* Change the LTDC state*/
512 hltdc
->State
= HAL_LTDC_STATE_READY
;
514 /* Process unlocked */
521 * @brief Load the color lookup table.
522 * @param hltdc: pointer to a LTDC_HandleTypeDef structure that contains
523 * the configuration information for the LTDC.
524 * @param pCLUT: pointer to the color lookup table address.
525 * @param CLUTSize: the color lookup table size.
526 * @param LayerIdx: LTDC Layer index.
527 * This parameter can be one of the following values:
531 HAL_StatusTypeDef
HAL_LTDC_ConfigCLUT(LTDC_HandleTypeDef
*hltdc
, uint32_t *pCLUT
, uint32_t CLUTSize
, uint32_t LayerIdx
)
534 uint32_t counter
= 0;
535 uint32_t pcounter
= 0;
540 /* Change LTDC peripheral state */
541 hltdc
->State
= HAL_LTDC_STATE_BUSY
;
543 /* Check the parameters */
544 assert_param(IS_LTDC_LAYER(LayerIdx
));
546 for(counter
= 0; (counter
< CLUTSize
); counter
++)
548 tmp
= ((counter
<< 24) | ((uint32_t)(*pCLUT
) & 0xFF) | ((uint32_t)(*pCLUT
) & 0xFF00) | ((uint32_t)(*pCLUT
) & 0xFF0000));
549 pcounter
= (uint32_t)pCLUT
+ sizeof(*pCLUT
);
550 pCLUT
= (uint32_t *)pcounter
;
552 /* Specifies the C-LUT address and RGB value */
553 __HAL_LTDC_LAYER(hltdc
, LayerIdx
)->CLUTWR
= tmp
;
556 /* Change the LTDC state*/
557 hltdc
->State
= HAL_LTDC_STATE_READY
;
559 /* Process unlocked */
566 * @brief Enable the color keying.
567 * @param hltdc: pointer to a LTDC_HandleTypeDef structure that contains
568 * the configuration information for the LTDC.
569 * @param LayerIdx: LTDC Layer index.
570 * This parameter can be one of the following values:
574 HAL_StatusTypeDef
HAL_LTDC_EnableColorKeying(LTDC_HandleTypeDef
*hltdc
, uint32_t LayerIdx
)
579 /* Change LTDC peripheral state */
580 hltdc
->State
= HAL_LTDC_STATE_BUSY
;
582 /* Check the parameters */
583 assert_param(IS_LTDC_LAYER(LayerIdx
));
585 /* Enable LTDC color keying by setting COLKEN bit */
586 __HAL_LTDC_LAYER(hltdc
, LayerIdx
)->CR
|= (uint32_t)LTDC_LxCR_COLKEN
;
588 /* Sets the Reload type */
589 hltdc
->Instance
->SRCR
= LTDC_SRCR_IMR
;
591 /* Change the LTDC state*/
592 hltdc
->State
= HAL_LTDC_STATE_READY
;
594 /* Process unlocked */
601 * @brief Disable the color keying.
602 * @param hltdc: pointer to a LTDC_HandleTypeDef structure that contains
603 * the configuration information for the LTDC.
604 * @param LayerIdx: LTDC Layer index.
605 * This parameter can be one of the following values:
609 HAL_StatusTypeDef
HAL_LTDC_DisableColorKeying(LTDC_HandleTypeDef
*hltdc
, uint32_t LayerIdx
)
614 /* Change LTDC peripheral state */
615 hltdc
->State
= HAL_LTDC_STATE_BUSY
;
617 /* Check the parameters */
618 assert_param(IS_LTDC_LAYER(LayerIdx
));
620 /* Disable LTDC color keying by setting COLKEN bit */
621 __HAL_LTDC_LAYER(hltdc
, LayerIdx
)->CR
&= ~(uint32_t)LTDC_LxCR_COLKEN
;
623 /* Sets the Reload type */
624 hltdc
->Instance
->SRCR
= LTDC_SRCR_IMR
;
626 /* Change the LTDC state*/
627 hltdc
->State
= HAL_LTDC_STATE_READY
;
629 /* Process unlocked */
636 * @brief Enable the color lookup table.
637 * @param hltdc: pointer to a LTDC_HandleTypeDef structure that contains
638 * the configuration information for the LTDC.
639 * @param LayerIdx: LTDC Layer index.
640 * This parameter can be one of the following values:
644 HAL_StatusTypeDef
HAL_LTDC_EnableCLUT(LTDC_HandleTypeDef
*hltdc
, uint32_t LayerIdx
)
650 /* Change LTDC peripheral state */
651 hltdc
->State
= HAL_LTDC_STATE_BUSY
;
653 /* Check the parameters */
654 assert_param(IS_LTDC_LAYER(LayerIdx
));
656 /* Disable LTDC color lookup table by setting CLUTEN bit */
657 __HAL_LTDC_LAYER(hltdc
, LayerIdx
)->CR
|= (uint32_t)LTDC_LxCR_CLUTEN
;
659 /* Sets the Reload type */
660 hltdc
->Instance
->SRCR
= LTDC_SRCR_IMR
;
662 /* Change the LTDC state*/
663 hltdc
->State
= HAL_LTDC_STATE_READY
;
665 /* Process unlocked */
672 * @brief Disable the color lookup table.
673 * @param hltdc: pointer to a LTDC_HandleTypeDef structure that contains
674 * the configuration information for the LTDC.
675 * @param LayerIdx: LTDC Layer index.
676 * This parameter can be one of the following values:
680 HAL_StatusTypeDef
HAL_LTDC_DisableCLUT(LTDC_HandleTypeDef
*hltdc
, uint32_t LayerIdx
)
686 /* Change LTDC peripheral state */
687 hltdc
->State
= HAL_LTDC_STATE_BUSY
;
689 /* Check the parameters */
690 assert_param(IS_LTDC_LAYER(LayerIdx
));
692 /* Disable LTDC color lookup table by setting CLUTEN bit */
693 __HAL_LTDC_LAYER(hltdc
, LayerIdx
)->CR
&= ~(uint32_t)LTDC_LxCR_CLUTEN
;
695 /* Sets the Reload type */
696 hltdc
->Instance
->SRCR
= LTDC_SRCR_IMR
;
698 /* Change the LTDC state*/
699 hltdc
->State
= HAL_LTDC_STATE_READY
;
701 /* Process unlocked */
708 * @brief Enables Dither.
709 * @param hltdc: pointer to a LTDC_HandleTypeDef structure that contains
710 * the configuration information for the LTDC.
714 HAL_StatusTypeDef
HAL_LTDC_EnableDither(LTDC_HandleTypeDef
*hltdc
)
719 /* Change LTDC peripheral state */
720 hltdc
->State
= HAL_LTDC_STATE_BUSY
;
722 /* Enable Dither by setting DTEN bit */
723 LTDC
->GCR
|= (uint32_t)LTDC_GCR_DTEN
;
725 /* Change the LTDC state*/
726 hltdc
->State
= HAL_LTDC_STATE_READY
;
728 /* Process unlocked */
735 * @brief Disables Dither.
736 * @param hltdc: pointer to a LTDC_HandleTypeDef structure that contains
737 * the configuration information for the LTDC.
741 HAL_StatusTypeDef
HAL_LTDC_DisableDither(LTDC_HandleTypeDef
*hltdc
)
746 /* Change LTDC peripheral state */
747 hltdc
->State
= HAL_LTDC_STATE_BUSY
;
749 /* Disable Dither by setting DTEN bit */
750 LTDC
->GCR
&= ~(uint32_t)LTDC_GCR_DTEN
;
752 /* Change the LTDC state*/
753 hltdc
->State
= HAL_LTDC_STATE_READY
;
755 /* Process unlocked */
762 * @brief Set the LTDC window size.
763 * @param hltdc: pointer to a LTDC_HandleTypeDef structure that contains
764 * the configuration information for the LTDC.
765 * @param XSize: LTDC Pixel per line
766 * @param YSize: LTDC Line number
767 * @param LayerIdx: LTDC Layer index.
768 * This parameter can be one of the following values:
772 HAL_StatusTypeDef
HAL_LTDC_SetWindowSize(LTDC_HandleTypeDef
*hltdc
, uint32_t XSize
, uint32_t YSize
, uint32_t LayerIdx
)
774 LTDC_LayerCfgTypeDef
*pLayerCfg
;
779 /* Change LTDC peripheral state */
780 hltdc
->State
= HAL_LTDC_STATE_BUSY
;
782 /* Get layer configuration from handle structure */
783 pLayerCfg
= &hltdc
->LayerCfg
[LayerIdx
];
785 /* Check the parameters (Layers parameters)*/
786 assert_param(IS_LTDC_LAYER(LayerIdx
));
787 assert_param(IS_LTDC_HCONFIGST(pLayerCfg
->WindowX0
));
788 assert_param(IS_LTDC_HCONFIGSP(pLayerCfg
->WindowX1
));
789 assert_param(IS_LTDC_VCONFIGST(pLayerCfg
->WindowY0
));
790 assert_param(IS_LTDC_VCONFIGSP(pLayerCfg
->WindowY1
));
791 assert_param(IS_LTDC_CFBLL(XSize
));
792 assert_param(IS_LTDC_CFBLNBR(YSize
));
794 /* update horizontal start/stop */
795 pLayerCfg
->WindowX0
= 0;
796 pLayerCfg
->WindowX1
= XSize
+ pLayerCfg
->WindowX0
;
798 /* update vertical start/stop */
799 pLayerCfg
->WindowY0
= 0;
800 pLayerCfg
->WindowY1
= YSize
+ pLayerCfg
->WindowY0
;
802 /* Reconfigures the color frame buffer pitch in byte */
803 pLayerCfg
->ImageWidth
= XSize
;
805 /* Reconfigures the frame buffer line number */
806 pLayerCfg
->ImageHeight
= YSize
;
808 /* Set LTDC parameters */
809 LTDC_SetConfig(hltdc
, pLayerCfg
, LayerIdx
);
811 /* Sets the Reload type */
812 hltdc
->Instance
->SRCR
= LTDC_SRCR_IMR
;
814 /* Change the LTDC state*/
815 hltdc
->State
= HAL_LTDC_STATE_READY
;
817 /* Process unlocked */
824 * @brief Set the LTDC window position.
825 * @param hltdc: pointer to a LTDC_HandleTypeDef structure that contains
826 * the configuration information for the LTDC.
827 * @param X0: LTDC window X offset
828 * @param Y0: LTDC window Y offset
829 * @param LayerIdx: LTDC Layer index.
830 * This parameter can be one of the following values:
834 HAL_StatusTypeDef
HAL_LTDC_SetWindowPosition(LTDC_HandleTypeDef
*hltdc
, uint32_t X0
, uint32_t Y0
, uint32_t LayerIdx
)
836 LTDC_LayerCfgTypeDef
*pLayerCfg
;
841 /* Change LTDC peripheral state */
842 hltdc
->State
= HAL_LTDC_STATE_BUSY
;
844 /* Get layer configuration from handle structure */
845 pLayerCfg
= &hltdc
->LayerCfg
[LayerIdx
];
847 /* Check the parameters */
848 assert_param(IS_LTDC_LAYER(LayerIdx
));
849 assert_param(IS_LTDC_HCONFIGST(pLayerCfg
->WindowX0
));
850 assert_param(IS_LTDC_HCONFIGSP(pLayerCfg
->WindowX1
));
851 assert_param(IS_LTDC_VCONFIGST(pLayerCfg
->WindowY0
));
852 assert_param(IS_LTDC_VCONFIGSP(pLayerCfg
->WindowY1
));
854 /* update horizontal start/stop */
855 pLayerCfg
->WindowX0
= X0
;
856 pLayerCfg
->WindowX1
= X0
+ pLayerCfg
->ImageWidth
;
858 /* update vertical start/stop */
859 pLayerCfg
->WindowY0
= Y0
;
860 pLayerCfg
->WindowY1
= Y0
+ pLayerCfg
->ImageHeight
;
862 /* Set LTDC parameters */
863 LTDC_SetConfig(hltdc
, pLayerCfg
, LayerIdx
);
865 /* Sets the Reload type */
866 hltdc
->Instance
->SRCR
= LTDC_SRCR_IMR
;
868 /* Change the LTDC state*/
869 hltdc
->State
= HAL_LTDC_STATE_READY
;
871 /* Process unlocked */
878 * @brief Reconfigure the pixel format.
879 * @param hltdc: pointer to a LTDC_HandleTypeDef structure that contains
880 * the configuration information for the LTDC.
881 * @param Pixelformat: new pixel format value.
882 * @param LayerIdx: LTDC Layer index.
883 * This parameter can be one of the following values:
887 HAL_StatusTypeDef
HAL_LTDC_SetPixelFormat(LTDC_HandleTypeDef
*hltdc
, uint32_t Pixelformat
, uint32_t LayerIdx
)
889 LTDC_LayerCfgTypeDef
*pLayerCfg
;
894 /* Change LTDC peripheral state */
895 hltdc
->State
= HAL_LTDC_STATE_BUSY
;
897 /* Check the parameters */
898 assert_param(IS_LTDC_LAYER(LayerIdx
));
899 assert_param(IS_LTDC_PIXEL_FORMAT(Pixelformat
));
901 /* Get layer configuration from handle structure */
902 pLayerCfg
= &hltdc
->LayerCfg
[LayerIdx
];
904 /* Reconfigure the pixel format */
905 pLayerCfg
->PixelFormat
= Pixelformat
;
907 /* Set LTDC parameters */
908 LTDC_SetConfig(hltdc
, pLayerCfg
, LayerIdx
);
910 /* Sets the Reload type */
911 hltdc
->Instance
->SRCR
= LTDC_SRCR_IMR
;
913 /* Change the LTDC state*/
914 hltdc
->State
= HAL_LTDC_STATE_READY
;
916 /* Process unlocked */
923 * @brief Reconfigure the layer alpha value.
924 * @param hltdc: pointer to a LTDC_HandleTypeDef structure that contains
925 * the configuration information for the LTDC.
926 * @param Alpha: new alpha value.
927 * @param LayerIdx: LTDC Layer index.
928 * This parameter can be one of the following values:
932 HAL_StatusTypeDef
HAL_LTDC_SetAlpha(LTDC_HandleTypeDef
*hltdc
, uint32_t Alpha
, uint32_t LayerIdx
)
934 LTDC_LayerCfgTypeDef
*pLayerCfg
;
939 /* Change LTDC peripheral state */
940 hltdc
->State
= HAL_LTDC_STATE_BUSY
;
942 /* Check the parameters */
943 assert_param(IS_LTDC_ALPHA(Alpha
));
944 assert_param(IS_LTDC_LAYER(LayerIdx
));
946 /* Get layer configuration from handle structure */
947 pLayerCfg
= &hltdc
->LayerCfg
[LayerIdx
];
949 /* Reconfigure the Alpha value */
950 pLayerCfg
->Alpha
= Alpha
;
952 /* Set LTDC parameters */
953 LTDC_SetConfig(hltdc
, pLayerCfg
, LayerIdx
);
955 /* Sets the Reload type */
956 hltdc
->Instance
->SRCR
= LTDC_SRCR_IMR
;
958 /* Change the LTDC state*/
959 hltdc
->State
= HAL_LTDC_STATE_READY
;
961 /* Process unlocked */
967 * @brief Reconfigure the frame buffer Address.
968 * @param hltdc: pointer to a LTDC_HandleTypeDef structure that contains
969 * the configuration information for the LTDC.
970 * @param Address: new address value.
971 * @param LayerIdx: LTDC Layer index.
972 * This parameter can be one of the following values:
976 HAL_StatusTypeDef
HAL_LTDC_SetAddress(LTDC_HandleTypeDef
*hltdc
, uint32_t Address
, uint32_t LayerIdx
)
978 LTDC_LayerCfgTypeDef
*pLayerCfg
;
983 /* Change LTDC peripheral state */
984 hltdc
->State
= HAL_LTDC_STATE_BUSY
;
986 /* Check the parameters */
987 assert_param(IS_LTDC_LAYER(LayerIdx
));
989 /* Get layer configuration from handle structure */
990 pLayerCfg
= &hltdc
->LayerCfg
[LayerIdx
];
992 /* Reconfigure the Address */
993 pLayerCfg
->FBStartAdress
= Address
;
995 /* Set LTDC parameters */
996 LTDC_SetConfig(hltdc
, pLayerCfg
, LayerIdx
);
998 /* Sets the Reload type */
999 hltdc
->Instance
->SRCR
= LTDC_SRCR_IMR
;
1001 /* Change the LTDC state*/
1002 hltdc
->State
= HAL_LTDC_STATE_READY
;
1004 /* Process unlocked */
1005 __HAL_UNLOCK(hltdc
);
1011 * @brief Define the position of the line interrupt .
1012 * @param hltdc: pointer to a LTDC_HandleTypeDef structure that contains
1013 * the configuration information for the LTDC.
1014 * @param Line: Line Interrupt Position.
1015 * @retval HAL status
1017 HAL_StatusTypeDef
HAL_LTDC_ProgramLineEvent(LTDC_HandleTypeDef
*hltdc
, uint32_t Line
)
1019 /* Process locked */
1022 /* Change LTDC peripheral state */
1023 hltdc
->State
= HAL_LTDC_STATE_BUSY
;
1025 /* Check the parameters */
1026 assert_param(IS_LTDC_LIPOS(Line
));
1028 /* Enable the Line interrupt */
1029 __HAL_LTDC_ENABLE_IT(hltdc
, LTDC_IT_LI
);
1031 /* Sets the Line Interrupt position */
1032 LTDC
->LIPCR
= (uint32_t)Line
;
1034 /* Change the LTDC state*/
1035 hltdc
->State
= HAL_LTDC_STATE_READY
;
1037 /* Process unlocked */
1038 __HAL_UNLOCK(hltdc
);
1047 /** @defgroup LTDC_Group4 Peripheral State and Errors functions
1048 * @brief Peripheral State and Errors functions
1051 ===============================================================================
1052 ##### Peripheral State and Errors functions #####
1053 ===============================================================================
1055 This subsection provides functions allowing to
1056 (+) Check the LTDC state.
1064 * @brief Return the LTDC state
1065 * @param hltdc: pointer to a LTDC_HandleTypeDef structure that contains
1066 * the configuration information for the LTDC.
1069 HAL_LTDC_StateTypeDef
HAL_LTDC_GetState(LTDC_HandleTypeDef
*hltdc
)
1071 return hltdc
->State
;
1075 * @brief Return the LTDC error code
1076 * @param hltdc : pointer to a LTDC_HandleTypeDef structure that contains
1077 * the configuration information for the LTDC.
1078 * @retval LTDC Error Code
1080 uint32_t HAL_LTDC_GetError(LTDC_HandleTypeDef
*hltdc
)
1082 return hltdc
->ErrorCode
;
1090 * @brief Configures the LTDC peripheral
1091 * @param hltdc : Pointer to a LTDC_HandleTypeDef structure that contains
1092 * the configuration information for the LTDC.
1093 * @param pLayerCfg: Pointer LTDC Layer Configuration strusture
1094 * @param LayerIdx: LTDC Layer index.
1095 * This parameter can be one of the following values: 0 or 1
1098 static void LTDC_SetConfig(LTDC_HandleTypeDef
*hltdc
, LTDC_LayerCfgTypeDef
*pLayerCfg
, uint32_t LayerIdx
)
1104 /* Configures the horizontal start and stop position */
1105 tmp
= ((pLayerCfg
->WindowX1
+ ((hltdc
->Instance
->BPCR
& LTDC_BPCR_AHBP
) >> 16)) << 16);
1106 __HAL_LTDC_LAYER(hltdc
, LayerIdx
)->WHPCR
&= ~(LTDC_LxWHPCR_WHSTPOS
| LTDC_LxWHPCR_WHSPPOS
);
1107 __HAL_LTDC_LAYER(hltdc
, LayerIdx
)->WHPCR
= ((pLayerCfg
->WindowX0
+ ((hltdc
->Instance
->BPCR
& LTDC_BPCR_AHBP
) >> 16) + 1) | tmp
);
1109 /* Configures the vertical start and stop position */
1110 tmp
= ((pLayerCfg
->WindowY1
+ (hltdc
->Instance
->BPCR
& LTDC_BPCR_AVBP
)) << 16);
1111 __HAL_LTDC_LAYER(hltdc
, LayerIdx
)->WVPCR
&= ~(LTDC_LxWVPCR_WVSTPOS
| LTDC_LxWVPCR_WVSPPOS
);
1112 __HAL_LTDC_LAYER(hltdc
, LayerIdx
)->WVPCR
= ((pLayerCfg
->WindowY0
+ (hltdc
->Instance
->BPCR
& LTDC_BPCR_AVBP
) + 1) | tmp
);
1114 /* Specifies the pixel format */
1115 __HAL_LTDC_LAYER(hltdc
, LayerIdx
)->PFCR
&= ~(LTDC_LxPFCR_PF
);
1116 __HAL_LTDC_LAYER(hltdc
, LayerIdx
)->PFCR
= (pLayerCfg
->PixelFormat
);
1118 /* Configures the default color values */
1119 tmp
= ((uint32_t)(pLayerCfg
->Backcolor
.Green
) << 8);
1120 tmp1
= ((uint32_t)(pLayerCfg
->Backcolor
.Red
) << 16);
1121 tmp2
= (pLayerCfg
->Alpha0
<< 24);
1122 __HAL_LTDC_LAYER(hltdc
, LayerIdx
)->DCCR
&= ~(LTDC_LxDCCR_DCBLUE
| LTDC_LxDCCR_DCGREEN
| LTDC_LxDCCR_DCRED
| LTDC_LxDCCR_DCALPHA
);
1123 __HAL_LTDC_LAYER(hltdc
, LayerIdx
)->DCCR
= (pLayerCfg
->Backcolor
.Blue
| tmp
| tmp1
| tmp2
);
1125 /* Specifies the constant alpha value */
1126 __HAL_LTDC_LAYER(hltdc
, LayerIdx
)->CACR
&= ~(LTDC_LxCACR_CONSTA
);
1127 __HAL_LTDC_LAYER(hltdc
, LayerIdx
)->CACR
= (pLayerCfg
->Alpha
);
1129 /* Specifies the blending factors */
1130 __HAL_LTDC_LAYER(hltdc
, LayerIdx
)->BFCR
&= ~(LTDC_LxBFCR_BF2
| LTDC_LxBFCR_BF1
);
1131 __HAL_LTDC_LAYER(hltdc
, LayerIdx
)->BFCR
= (pLayerCfg
->BlendingFactor1
| pLayerCfg
->BlendingFactor2
);
1133 /* Configures the color frame buffer start address */
1134 __HAL_LTDC_LAYER(hltdc
, LayerIdx
)->CFBAR
&= ~(LTDC_LxCFBAR_CFBADD
);
1135 __HAL_LTDC_LAYER(hltdc
, LayerIdx
)->CFBAR
= (pLayerCfg
->FBStartAdress
);
1137 if(pLayerCfg
->PixelFormat
== LTDC_PIXEL_FORMAT_ARGB8888
)
1141 else if (pLayerCfg
->PixelFormat
== LTDC_PIXEL_FORMAT_RGB888
)
1145 else if((pLayerCfg
->PixelFormat
== LTDC_PIXEL_FORMAT_ARGB4444
) || \
1146 (pLayerCfg
->PixelFormat
== LTDC_PIXEL_FORMAT_RGB565
) || \
1147 (pLayerCfg
->PixelFormat
== LTDC_PIXEL_FORMAT_ARGB1555
) || \
1148 (pLayerCfg
->PixelFormat
== LTDC_PIXEL_FORMAT_AL88
))
1157 /* Configures the color frame buffer pitch in byte */
1158 __HAL_LTDC_LAYER(hltdc
, LayerIdx
)->CFBLR
&= ~(LTDC_LxCFBLR_CFBLL
| LTDC_LxCFBLR_CFBP
);
1159 __HAL_LTDC_LAYER(hltdc
, LayerIdx
)->CFBLR
= (((pLayerCfg
->ImageWidth
* tmp
) << 16) | ((pLayerCfg
->ImageWidth
* tmp
) + 3));
1161 /* Configures the frame buffer line number */
1162 __HAL_LTDC_LAYER(hltdc
, LayerIdx
)->CFBLNR
&= ~(LTDC_LxCFBLNR_CFBLNBR
);
1163 __HAL_LTDC_LAYER(hltdc
, LayerIdx
)->CFBLNR
= (pLayerCfg
->ImageHeight
);
1165 /* Enable LTDC_Layer by setting LEN bit */
1166 __HAL_LTDC_LAYER(hltdc
, LayerIdx
)->CR
|= (uint32_t)LTDC_LxCR_LEN
;
1172 #endif /* STM32F429xx || STM32F439xx */
1173 #endif /* HAL_LTDC_MODULE_ENABLED */
1182 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/