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