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