Create release.yml
[betaflight.git] / lib / main / STM32H7 / Drivers / STM32H7xx_HAL_Driver / Src / stm32h7xx_hal_gfxmmu.c
blobd1bdcbd62ff26d77fd7d337f169e2a2c1e7dee83
1 /**
2 ******************************************************************************
3 * @file stm32h7xx_hal_gfxmmu.c
4 * @author MCD Application Team
5 * @brief This file provides firmware functions to manage the following
6 * functionalities of the Graphic MMU (GFXMMU) peripheral:
7 * + Initialization and De-initialization.
8 * + LUT configuration.
9 * + Force flush and/or invalidate of cache.
10 * + Modify physical buffer adresses.
11 * + Modify cache and pre-fetch parameters.
12 * + Error management.
14 @verbatim
15 ==============================================================================
16 ##### How to use this driver #####
17 ==============================================================================
18 [..]
19 *** Initialization ***
20 ======================
21 [..]
22 (#) As prerequisite, fill in the HAL_GFXMMU_MspInit() :
23 (++) Enable GFXMMU clock interface with __HAL_RCC_GFXMMU_CLK_ENABLE().
24 (++) If interrupts are used, enable and configure GFXMMU global
25 interrupt with HAL_NVIC_SetPriority() and HAL_NVIC_EnableIRQ().
26 (#) Configure the number of blocks per line, default value, physical
27 buffer addresses, cache and pre-fetch parameters and interrupts
28 using the HAL_GFXMMU_Init() function.
30 *** LUT configuration ***
31 =========================
32 [..]
33 (#) Use HAL_GFXMMU_DisableLutLines() to deactivate all LUT lines (or a
34 range of lines).
35 (#) Use HAL_GFXMMU_ConfigLut() to copy LUT from flash to look up RAM.
36 (#) Use HAL_GFXMMU_ConfigLutLine() to configure one line of LUT.
38 *** Force flush and/or invalidate of cache ***
39 ==============================================
40 [..]
41 (#) Use HAL_GFXMMU_ConfigForceCache() to flush and/or invalidate cache.
43 *** Modify physical buffer adresses ***
44 =======================================
45 [..]
46 (#) Use HAL_GFXMMU_ModifyBuffers() to modify physical buffer addresses.
48 *** Modify cache and pre-fetch parameters ***
49 =============================================
50 [..]
51 (#) Use HAL_GFXMMU_ModifyCachePrefetch() to modify cache and pre-fetch
52 parameters.
54 *** Error management ***
55 ========================
56 [..]
57 (#) If interrupts are used, HAL_GFXMMU_IRQHandler() will be called when
58 an error occurs. This function will call HAL_GFXMMU_ErrorCallback().
59 Use HAL_GFXMMU_GetError() to get the error code.
61 *** De-initialization ***
62 =========================
63 [..]
64 (#) As prerequisite, fill in the HAL_GFXMMU_MspDeInit() :
65 (++) Disable GFXMMU clock interface with __HAL_RCC_GFXMMU_CLK_ENABLE().
66 (++) If interrupts has been used, disable GFXMMU global interrupt with
67 HAL_NVIC_DisableIRQ().
68 (#) De-initialize GFXMMU using the HAL_GFXMMU_DeInit() function.
70 *** Callback registration ***
71 =============================
73 [..]
74 The compilation define USE_HAL_GFXMMU_REGISTER_CALLBACKS when set to 1
75 allows the user to configure dynamically the driver callbacks.
76 Use functions HAL_GFXMMU_RegisterCallback() to register a user callback.
78 [..]
79 Function HAL_GFXMMU_RegisterCallback() allows to register following callbacks:
80 (+) ErrorCallback : GFXMMU error.
81 (+) MspInitCallback : GFXMMU MspInit.
82 (+) MspDeInitCallback : GFXMMU MspDeInit.
83 [..]
84 This function takes as parameters the HAL peripheral handle, the callback ID
85 and a pointer to the user callback function.
87 [..]
88 Use function HAL_GFXMMU_UnRegisterCallback() to reset a callback to the default
89 weak (surcharged) function.
90 HAL_GFXMMU_UnRegisterCallback() takes as parameters the HAL peripheral handle,
91 and the callback ID.
92 [..]
93 This function allows to reset following callbacks:
94 (+) ErrorCallback : GFXMMU error.
95 (+) MspInitCallback : GFXMMU MspInit.
96 (+) MspDeInitCallback : GFXMMU MspDeInit.
98 [..]
99 By default, after the HAL_GFXMMU_Init and if the state is HAL_GFXMMU_STATE_RESET
100 all callbacks are reset to the corresponding legacy weak (surcharged) functions:
101 examples HAL_GFXMMU_ErrorCallback().
102 Exception done for MspInit and MspDeInit callbacks that are respectively
103 reset to the legacy weak (surcharged) functions in the HAL_GFXMMU_Init
104 and HAL_GFXMMU_DeInit only when these callbacks are null (not registered beforehand).
105 If not, MspInit or MspDeInit are not null, the HAL_GFXMMU_Init and HAL_GFXMMU_DeInit
106 keep and use the user MspInit/MspDeInit callbacks (registered beforehand).
108 [..]
109 Callbacks can be registered/unregistered in READY state only.
110 Exception done for MspInit/MspDeInit callbacks that can be registered/unregistered
111 in READY or RESET state, thus registered (user) MspInit/DeInit callbacks can be used
112 during the Init/DeInit.
113 In that case first register the MspInit/MspDeInit user callbacks
114 using HAL_GFXMMU_RegisterCallback before calling HAL_GFXMMU_DeInit
115 or HAL_GFXMMU_Init function.
117 [..]
118 When the compilation define USE_HAL_GFXMMU_REGISTER_CALLBACKS is set to 0 or
119 not defined, the callback registering feature is not available
120 and weak (surcharged) callbacks are used.
122 @endverbatim
123 ******************************************************************************
124 * @attention
126 * <h2><center>&copy; Copyright (c) 2017 STMicroelectronics.
127 * All rights reserved.</center></h2>
129 * This software component is licensed by ST under BSD 3-Clause license,
130 * the "License"; You may not use this file except in compliance with the
131 * License. You may obtain a copy of the License at:
132 * opensource.org/licenses/BSD-3-Clause
134 ******************************************************************************
137 /* Includes ------------------------------------------------------------------*/
138 #include "stm32h7xx_hal.h"
140 /** @addtogroup STM32H7xx_HAL_Driver
141 * @{
143 #ifdef HAL_GFXMMU_MODULE_ENABLED
144 #if defined(GFXMMU)
145 /** @defgroup GFXMMU GFXMMU
146 * @brief GFXMMU HAL driver module
147 * @{
150 /* Private typedef -----------------------------------------------------------*/
151 /* Private define ------------------------------------------------------------*/
152 #define GFXMMU_LUTXL_FVB_OFFSET 8U
153 #define GFXMMU_LUTXL_LVB_OFFSET 16U
154 #define GFXMMU_CR_ITS_MASK 0x1FU
155 /* Private macro -------------------------------------------------------------*/
156 /* Private variables ---------------------------------------------------------*/
157 /* Private function prototypes -----------------------------------------------*/
158 /* Exported functions --------------------------------------------------------*/
159 /** @defgroup GFXMMU_Exported_Functions GFXMMU Exported Functions
160 * @{
163 /** @defgroup GFXMMU_Exported_Functions_Group1 Initialization and de-initialization functions
164 * @brief Initialization and de-initialization functions
166 @verbatim
167 ==============================================================================
168 ##### Initialization and de-initialization functions #####
169 ==============================================================================
170 [..] This section provides functions allowing to:
171 (+) Initialize the GFXMMU.
172 (+) De-initialize the GFXMMU.
173 @endverbatim
174 * @{
178 * @brief Initialize the GFXMMU according to the specified parameters in the
179 * GFXMMU_InitTypeDef structure and initialize the associated handle.
180 * @param hgfxmmu GFXMMU handle.
181 * @retval HAL status.
183 HAL_StatusTypeDef HAL_GFXMMU_Init(GFXMMU_HandleTypeDef *hgfxmmu)
185 HAL_StatusTypeDef status = HAL_OK;
187 /* Check GFXMMU handle */
188 if(hgfxmmu == NULL)
190 status = HAL_ERROR;
192 else
194 /* Check parameters */
195 assert_param(IS_GFXMMU_ALL_INSTANCE(hgfxmmu->Instance));
196 assert_param(IS_GFXMMU_BLOCKS_PER_LINE(hgfxmmu->Init.BlocksPerLine));
197 assert_param(IS_GFXMMU_BUFFER_ADDRESS(hgfxmmu->Init.Buffers.Buf0Address));
198 assert_param(IS_GFXMMU_BUFFER_ADDRESS(hgfxmmu->Init.Buffers.Buf1Address));
199 assert_param(IS_GFXMMU_BUFFER_ADDRESS(hgfxmmu->Init.Buffers.Buf2Address));
200 assert_param(IS_GFXMMU_BUFFER_ADDRESS(hgfxmmu->Init.Buffers.Buf3Address));
201 assert_param(IS_FUNCTIONAL_STATE(hgfxmmu->Init.CachePrefetch.Activation));
202 assert_param(IS_FUNCTIONAL_STATE(hgfxmmu->Init.Interrupts.Activation));
204 #if (USE_HAL_GFXMMU_REGISTER_CALLBACKS == 1)
205 /* Reset callback pointers to the weak predefined callbacks */
206 hgfxmmu->ErrorCallback = HAL_GFXMMU_ErrorCallback;
208 /* Call GFXMMU MSP init function */
209 if(hgfxmmu->MspInitCallback == NULL)
211 hgfxmmu->MspInitCallback = HAL_GFXMMU_MspInit;
213 hgfxmmu->MspInitCallback(hgfxmmu);
214 #else
215 /* Call GFXMMU MSP init function */
216 HAL_GFXMMU_MspInit(hgfxmmu);
217 #endif
219 /* Configure blocks per line, cache and interrupts parameters on GFXMMU_CR register */
220 hgfxmmu->Instance->CR &= ~(GFXMMU_CR_B0OIE | GFXMMU_CR_B1OIE | GFXMMU_CR_B2OIE | GFXMMU_CR_B3OIE |
221 GFXMMU_CR_AMEIE | GFXMMU_CR_192BM | GFXMMU_CR_CE | GFXMMU_CR_CL |
222 GFXMMU_CR_CLB | GFXMMU_CR_FC | GFXMMU_CR_PD | GFXMMU_CR_OC |
223 GFXMMU_CR_OB);
224 hgfxmmu->Instance->CR |= (hgfxmmu->Init.BlocksPerLine);
225 if(hgfxmmu->Init.CachePrefetch.Activation == ENABLE)
227 assert_param(IS_GFXMMU_CACHE_LOCK(hgfxmmu->Init.CachePrefetch.CacheLock));
228 assert_param(IS_GFXMMU_PREFETCH(hgfxmmu->Init.CachePrefetch.Prefetch));
229 assert_param(IS_GFXMMU_OUTTER_BUFFERABILITY(hgfxmmu->Init.CachePrefetch.OutterBufferability));
230 assert_param(IS_GFXMMU_OUTTER_CACHABILITY(hgfxmmu->Init.CachePrefetch.OutterCachability));
231 hgfxmmu->Instance->CR |= (GFXMMU_CR_CE |
232 hgfxmmu->Init.CachePrefetch.CacheLock |
233 hgfxmmu->Init.CachePrefetch.Prefetch |
234 hgfxmmu->Init.CachePrefetch.OutterBufferability |
235 hgfxmmu->Init.CachePrefetch.OutterCachability);
236 if(hgfxmmu->Init.CachePrefetch.CacheLock == GFXMMU_CACHE_LOCK_ENABLE)
238 assert_param(IS_GFXMMU_CACHE_LOCK_BUFFER(hgfxmmu->Init.CachePrefetch.CacheLockBuffer));
239 assert_param(IS_GFXMMU_CACHE_FORCE(hgfxmmu->Init.CachePrefetch.CacheForce));
240 hgfxmmu->Instance->CR |= (hgfxmmu->Init.CachePrefetch.CacheLockBuffer |
241 hgfxmmu->Init.CachePrefetch.CacheForce);
244 if(hgfxmmu->Init.Interrupts.Activation == ENABLE)
246 assert_param(IS_GFXMMU_INTERRUPTS(hgfxmmu->Init.Interrupts.UsedInterrupts));
247 hgfxmmu->Instance->CR |= hgfxmmu->Init.Interrupts.UsedInterrupts;
250 /* Configure default value on GFXMMU_DVR register */
251 hgfxmmu->Instance->DVR = hgfxmmu->Init.DefaultValue;
253 /* Configure physical buffer adresses on GFXMMU_BxCR registers */
254 hgfxmmu->Instance->B0CR = hgfxmmu->Init.Buffers.Buf0Address;
255 hgfxmmu->Instance->B1CR = hgfxmmu->Init.Buffers.Buf1Address;
256 hgfxmmu->Instance->B2CR = hgfxmmu->Init.Buffers.Buf2Address;
257 hgfxmmu->Instance->B3CR = hgfxmmu->Init.Buffers.Buf3Address;
259 /* Force invalidate cache if cache is enabled */
260 if(hgfxmmu->Init.CachePrefetch.Activation == ENABLE)
262 hgfxmmu->Instance->CCR |= GFXMMU_CACHE_FORCE_INVALIDATE;
265 /* Reset GFXMMU error code */
266 hgfxmmu->ErrorCode = GFXMMU_ERROR_NONE;
268 /* Set GFXMMU to ready state */
269 hgfxmmu->State = HAL_GFXMMU_STATE_READY;
271 /* Return function status */
272 return status;
276 * @brief De-initialize the GFXMMU.
277 * @param hgfxmmu GFXMMU handle.
278 * @retval HAL status.
280 HAL_StatusTypeDef HAL_GFXMMU_DeInit(GFXMMU_HandleTypeDef *hgfxmmu)
282 HAL_StatusTypeDef status = HAL_OK;
284 /* Check GFXMMU handle */
285 if(hgfxmmu == NULL)
287 status = HAL_ERROR;
289 else
291 /* Check parameters */
292 assert_param(IS_GFXMMU_ALL_INSTANCE(hgfxmmu->Instance));
294 /* Disable all interrupts on GFXMMU_CR register */
295 hgfxmmu->Instance->CR &= ~(GFXMMU_CR_B0OIE | GFXMMU_CR_B1OIE | GFXMMU_CR_B2OIE | GFXMMU_CR_B3OIE |
296 GFXMMU_CR_AMEIE);
298 /* Call GFXMMU MSP de-init function */
299 #if (USE_HAL_GFXMMU_REGISTER_CALLBACKS == 1)
300 if(hgfxmmu->MspDeInitCallback == NULL)
302 hgfxmmu->MspDeInitCallback = HAL_GFXMMU_MspDeInit;
304 hgfxmmu->MspDeInitCallback(hgfxmmu);
305 #else
306 HAL_GFXMMU_MspDeInit(hgfxmmu);
307 #endif
309 /* Set GFXMMU to reset state */
310 hgfxmmu->State = HAL_GFXMMU_STATE_RESET;
312 /* Return function status */
313 return status;
317 * @brief Initialize the GFXMMU MSP.
318 * @param hgfxmmu GFXMMU handle.
319 * @retval None.
321 __weak void HAL_GFXMMU_MspInit(GFXMMU_HandleTypeDef *hgfxmmu)
323 /* Prevent unused argument(s) compilation warning */
324 UNUSED(hgfxmmu);
326 /* NOTE : This function should not be modified, when the function is needed,
327 the HAL_GFXMMU_MspInit could be implemented in the user file.
332 * @brief De-initialize the GFXMMU MSP.
333 * @param hgfxmmu GFXMMU handle.
334 * @retval None.
336 __weak void HAL_GFXMMU_MspDeInit(GFXMMU_HandleTypeDef *hgfxmmu)
338 /* Prevent unused argument(s) compilation warning */
339 UNUSED(hgfxmmu);
341 /* NOTE : This function should not be modified, when the function is needed,
342 the HAL_GFXMMU_MspDeInit could be implemented in the user file.
346 #if (USE_HAL_GFXMMU_REGISTER_CALLBACKS == 1)
348 * @brief Register a user GFXMMU callback
349 * to be used instead of the weak predefined callback.
350 * @param hgfxmmu GFXMMU handle.
351 * @param CallbackID ID of the callback to be registered.
352 * This parameter can be one of the following values:
353 * @arg @ref HAL_GFXMMU_ERROR_CB_ID error callback ID.
354 * @arg @ref HAL_GFXMMU_MSPINIT_CB_ID MSP init callback ID.
355 * @arg @ref HAL_GFXMMU_MSPDEINIT_CB_ID MSP de-init callback ID.
356 * @param pCallback pointer to the callback function.
357 * @retval HAL status.
359 HAL_StatusTypeDef HAL_GFXMMU_RegisterCallback(GFXMMU_HandleTypeDef *hgfxmmu,
360 HAL_GFXMMU_CallbackIDTypeDef CallbackID,
361 pGFXMMU_CallbackTypeDef pCallback)
363 HAL_StatusTypeDef status = HAL_OK;
365 if(pCallback == NULL)
367 /* update the error code */
368 hgfxmmu->ErrorCode |= GFXMMU_ERROR_INVALID_CALLBACK;
369 /* update return status */
370 status = HAL_ERROR;
372 else
374 if(HAL_GFXMMU_STATE_READY == hgfxmmu->State)
376 switch (CallbackID)
378 case HAL_GFXMMU_ERROR_CB_ID :
379 hgfxmmu->ErrorCallback = pCallback;
380 break;
381 case HAL_GFXMMU_MSPINIT_CB_ID :
382 hgfxmmu->MspInitCallback = pCallback;
383 break;
384 case HAL_GFXMMU_MSPDEINIT_CB_ID :
385 hgfxmmu->MspDeInitCallback = pCallback;
386 break;
387 default :
388 /* update the error code */
389 hgfxmmu->ErrorCode |= GFXMMU_ERROR_INVALID_CALLBACK;
390 /* update return status */
391 status = HAL_ERROR;
392 break;
395 else if(HAL_GFXMMU_STATE_RESET == hgfxmmu->State)
397 switch (CallbackID)
399 case HAL_GFXMMU_MSPINIT_CB_ID :
400 hgfxmmu->MspInitCallback = pCallback;
401 break;
402 case HAL_GFXMMU_MSPDEINIT_CB_ID :
403 hgfxmmu->MspDeInitCallback = pCallback;
404 break;
405 default :
406 /* update the error code */
407 hgfxmmu->ErrorCode |= GFXMMU_ERROR_INVALID_CALLBACK;
408 /* update return status */
409 status = HAL_ERROR;
410 break;
413 else
415 /* update the error code */
416 hgfxmmu->ErrorCode |= GFXMMU_ERROR_INVALID_CALLBACK;
417 /* update return status */
418 status = HAL_ERROR;
421 return status;
425 * @brief Unregister a user GFXMMU callback.
426 * GFXMMU callback is redirected to the weak predefined callback.
427 * @param hgfxmmu GFXMMU handle.
428 * @param CallbackID ID of the callback to be unregistered.
429 * This parameter can be one of the following values:
430 * @arg @ref HAL_GFXMMU_ERROR_CB_ID error callback ID.
431 * @arg @ref HAL_GFXMMU_MSPINIT_CB_ID MSP init callback ID.
432 * @arg @ref HAL_GFXMMU_MSPDEINIT_CB_ID MSP de-init callback ID.
433 * @retval HAL status.
435 HAL_StatusTypeDef HAL_GFXMMU_UnRegisterCallback(GFXMMU_HandleTypeDef *hgfxmmu,
436 HAL_GFXMMU_CallbackIDTypeDef CallbackID)
438 HAL_StatusTypeDef status = HAL_OK;
440 if(HAL_GFXMMU_STATE_READY == hgfxmmu->State)
442 switch (CallbackID)
444 case HAL_GFXMMU_ERROR_CB_ID :
445 hgfxmmu->ErrorCallback = HAL_GFXMMU_ErrorCallback;
446 break;
447 case HAL_GFXMMU_MSPINIT_CB_ID :
448 hgfxmmu->MspInitCallback = HAL_GFXMMU_MspInit;
449 break;
450 case HAL_GFXMMU_MSPDEINIT_CB_ID :
451 hgfxmmu->MspDeInitCallback = HAL_GFXMMU_MspDeInit;
452 break;
453 default :
454 /* update the error code */
455 hgfxmmu->ErrorCode |= GFXMMU_ERROR_INVALID_CALLBACK;
456 /* update return status */
457 status = HAL_ERROR;
458 break;
461 else if(HAL_GFXMMU_STATE_RESET == hgfxmmu->State)
463 switch (CallbackID)
465 case HAL_GFXMMU_MSPINIT_CB_ID :
466 hgfxmmu->MspInitCallback = HAL_GFXMMU_MspInit;
467 break;
468 case HAL_GFXMMU_MSPDEINIT_CB_ID :
469 hgfxmmu->MspDeInitCallback = HAL_GFXMMU_MspDeInit;
470 break;
471 default :
472 /* update the error code */
473 hgfxmmu->ErrorCode |= GFXMMU_ERROR_INVALID_CALLBACK;
474 /* update return status */
475 status = HAL_ERROR;
476 break;
479 else
481 /* update the error code */
482 hgfxmmu->ErrorCode |= GFXMMU_ERROR_INVALID_CALLBACK;
483 /* update return status */
484 status = HAL_ERROR;
486 return status;
488 #endif /* USE_HAL_GFXMMU_REGISTER_CALLBACKS */
491 * @}
494 /** @defgroup GFXMMU_Exported_Functions_Group2 Operations functions
495 * @brief GFXMMU operation functions
497 @verbatim
498 ==============================================================================
499 ##### Operation functions #####
500 ==============================================================================
501 [..] This section provides functions allowing to:
502 (+) Configure LUT.
503 (+) Force flush and/or invalidate of cache.
504 (+) Modify physical buffer adresses.
505 (+) Modify cache and pre-fetch parameters.
506 (+) Manage error.
507 @endverbatim
508 * @{
512 * @brief This function allows to copy LUT from flash to look up RAM.
513 * @param hgfxmmu GFXMMU handle.
514 * @param FirstLine First line enabled on LUT.
515 * This parameter must be a number between Min_Data = 0 and Max_Data = 1023.
516 * @param LinesNumber Number of lines enabled on LUT.
517 * This parameter must be a number between Min_Data = 1 and Max_Data = 1024.
518 * @param Address Start address of LUT in flash.
519 * @retval HAL status.
521 HAL_StatusTypeDef HAL_GFXMMU_ConfigLut(GFXMMU_HandleTypeDef *hgfxmmu,
522 uint32_t FirstLine,
523 uint32_t LinesNumber,
524 uint32_t Address)
526 HAL_StatusTypeDef status = HAL_OK;
528 /* Check parameters */
529 assert_param(IS_GFXMMU_ALL_INSTANCE(hgfxmmu->Instance));
530 assert_param(IS_GFXMMU_LUT_LINE(FirstLine));
531 assert_param(IS_GFXMMU_LUT_LINES_NUMBER(LinesNumber));
533 /* Check GFXMMU state and coherent parameters */
534 if((hgfxmmu->State != HAL_GFXMMU_STATE_READY) || ((FirstLine + LinesNumber) > 1024U))
536 status = HAL_ERROR;
538 else
540 uint32_t current_address, current_line, lutxl_address, lutxh_address;
542 /* Initialize local variables */
543 current_address = Address;
544 current_line = 0U;
545 lutxl_address = (uint32_t) &(hgfxmmu->Instance->LUT[2U * FirstLine]);
546 lutxh_address = (uint32_t) &(hgfxmmu->Instance->LUT[(2U * FirstLine) + 1U]);
548 /* Copy LUT from flash to look up RAM */
549 while(current_line < LinesNumber)
551 *((uint32_t *)lutxl_address) = *((uint32_t *)current_address);
552 current_address += 4U;
553 *((uint32_t *)lutxh_address) = *((uint32_t *)current_address);
554 current_address += 4U;
555 lutxl_address += 8U;
556 lutxh_address += 8U;
557 current_line++;
560 /* Return function status */
561 return status;
565 * @brief This function allows to disable a range of LUT lines.
566 * @param hgfxmmu GFXMMU handle.
567 * @param FirstLine First line to disable on LUT.
568 * This parameter must be a number between Min_Data = 0 and Max_Data = 1023.
569 * @param LinesNumber Number of lines to disable on LUT.
570 * This parameter must be a number between Min_Data = 1 and Max_Data = 1024.
571 * @retval HAL status.
573 HAL_StatusTypeDef HAL_GFXMMU_DisableLutLines(GFXMMU_HandleTypeDef *hgfxmmu,
574 uint32_t FirstLine,
575 uint32_t LinesNumber)
577 HAL_StatusTypeDef status = HAL_OK;
579 /* Check parameters */
580 assert_param(IS_GFXMMU_ALL_INSTANCE(hgfxmmu->Instance));
581 assert_param(IS_GFXMMU_LUT_LINE(FirstLine));
582 assert_param(IS_GFXMMU_LUT_LINES_NUMBER(LinesNumber));
584 /* Check GFXMMU state and coherent parameters */
585 if((hgfxmmu->State != HAL_GFXMMU_STATE_READY) || ((FirstLine + LinesNumber) > 1024U))
587 status = HAL_ERROR;
589 else
591 uint32_t current_line, lutxl_address, lutxh_address;
593 /* Initialize local variables */
594 current_line = 0U;
595 lutxl_address = (uint32_t) &(hgfxmmu->Instance->LUT[2U * FirstLine]);
596 lutxh_address = (uint32_t) &(hgfxmmu->Instance->LUT[(2U * FirstLine) + 1U]);
598 /* Disable LUT lines */
599 while(current_line < LinesNumber)
601 *((uint32_t *)lutxl_address) = 0U;
602 *((uint32_t *)lutxh_address) = 0U;
603 lutxl_address += 8U;
604 lutxh_address += 8U;
605 current_line++;
608 /* Return function status */
609 return status;
613 * @brief This function allows to configure one line of LUT.
614 * @param hgfxmmu GFXMMU handle.
615 * @param lutLine LUT line parameters.
616 * @retval HAL status.
618 HAL_StatusTypeDef HAL_GFXMMU_ConfigLutLine(GFXMMU_HandleTypeDef *hgfxmmu, GFXMMU_LutLineTypeDef *lutLine)
620 HAL_StatusTypeDef status = HAL_OK;
622 /* Check parameters */
623 assert_param(IS_GFXMMU_ALL_INSTANCE(hgfxmmu->Instance));
624 assert_param(IS_GFXMMU_LUT_LINE(lutLine->LineNumber));
625 assert_param(IS_GFXMMU_LUT_LINE_STATUS(lutLine->LineStatus));
626 assert_param(IS_GFXMMU_LUT_BLOCK(lutLine->FirstVisibleBlock));
627 assert_param(IS_GFXMMU_LUT_BLOCK(lutLine->LastVisibleBlock));
628 assert_param(IS_GFXMMU_LUT_LINE_OFFSET(lutLine->LineOffset));
630 /* Check GFXMMU state */
631 if(hgfxmmu->State != HAL_GFXMMU_STATE_READY)
633 status = HAL_ERROR;
635 else
637 uint32_t lutxl_address, lutxh_address;
639 /* Initialize local variables */
640 lutxl_address = (uint32_t) &(hgfxmmu->Instance->LUT[2U * lutLine->LineNumber]);
641 lutxh_address = (uint32_t) &(hgfxmmu->Instance->LUT[(2U * lutLine->LineNumber) + 1U]);
643 /* Configure LUT line */
644 if(lutLine->LineStatus == GFXMMU_LUT_LINE_ENABLE)
646 /* Enable and configure LUT line */
647 *((uint32_t *)lutxl_address) = (lutLine->LineStatus |
648 (lutLine->FirstVisibleBlock << GFXMMU_LUTXL_FVB_OFFSET) |
649 (lutLine->LastVisibleBlock << GFXMMU_LUTXL_LVB_OFFSET));
650 *((uint32_t *)lutxh_address) = (uint32_t) lutLine->LineOffset;
652 else
654 /* Disable LUT line */
655 *((uint32_t *)lutxl_address) = 0U;
656 *((uint32_t *)lutxh_address) = 0U;
659 /* Return function status */
660 return status;
664 * @brief This function allows to force flush and/or invalidate of cache.
665 * @param hgfxmmu GFXMMU handle.
666 * @param ForceParam Force cache parameter.
667 * This parameter can be a values combination of @ref GFXMMU_CacheForceParam.
668 * @retval HAL status.
670 HAL_StatusTypeDef HAL_GFXMMU_ConfigForceCache(GFXMMU_HandleTypeDef *hgfxmmu, uint32_t ForceParam)
672 HAL_StatusTypeDef status = HAL_OK;
674 /* Check parameters */
675 assert_param(IS_GFXMMU_ALL_INSTANCE(hgfxmmu->Instance));
676 assert_param(IS_GFXMMU_CACHE_FORCE_ACTION(ForceParam));
678 /* Check GFXMMU state and cache status */
679 if(((hgfxmmu->Instance->CR & GFXMMU_CR_CE) != GFXMMU_CR_CE) || (hgfxmmu->State != HAL_GFXMMU_STATE_READY))
681 status = HAL_ERROR;
683 else
685 /* Force flush and/or invalidate cache on GFXMMU_CCR register */
686 hgfxmmu->Instance->CCR |= ForceParam;
688 /* Return function status */
689 return status;
693 * @brief This function allows to modify physical buffer addresses.
694 * @param hgfxmmu GFXMMU handle.
695 * @param Buffers Buffers parameters.
696 * @retval HAL status.
698 HAL_StatusTypeDef HAL_GFXMMU_ModifyBuffers(GFXMMU_HandleTypeDef *hgfxmmu, GFXMMU_BuffersTypeDef *Buffers)
700 HAL_StatusTypeDef status = HAL_OK;
702 /* Check parameters */
703 assert_param(IS_GFXMMU_ALL_INSTANCE(hgfxmmu->Instance));
704 assert_param(IS_GFXMMU_BUFFER_ADDRESS(Buffers->Buf0Address));
705 assert_param(IS_GFXMMU_BUFFER_ADDRESS(Buffers->Buf1Address));
706 assert_param(IS_GFXMMU_BUFFER_ADDRESS(Buffers->Buf2Address));
707 assert_param(IS_GFXMMU_BUFFER_ADDRESS(Buffers->Buf3Address));
709 /* Check GFXMMU state */
710 if(hgfxmmu->State != HAL_GFXMMU_STATE_READY)
712 status = HAL_ERROR;
714 else
716 /* Modify physical buffer adresses on GFXMMU_BxCR registers */
717 hgfxmmu->Instance->B0CR = Buffers->Buf0Address;
718 hgfxmmu->Instance->B1CR = Buffers->Buf1Address;
719 hgfxmmu->Instance->B2CR = Buffers->Buf2Address;
720 hgfxmmu->Instance->B3CR = Buffers->Buf3Address;
722 /* Return function status */
723 return status;
727 * @brief This function allows to modify cache and pre-fetch parameters.
728 * @param hgfxmmu GFXMMU handle.
729 * @param CachePrefetch Cache and pre-fetch parameters.
730 * @retval HAL status.
732 HAL_StatusTypeDef HAL_GFXMMU_ModifyCachePrefetch(GFXMMU_HandleTypeDef *hgfxmmu,
733 GFXMMU_CachePrefetchTypeDef *CachePrefetch)
735 HAL_StatusTypeDef status = HAL_OK;
736 assert_param(IS_FUNCTIONAL_STATE(CachePrefetch->Activation));
738 /* Check parameters */
739 assert_param(IS_GFXMMU_ALL_INSTANCE(hgfxmmu->Instance));
741 /* Check GFXMMU state */
742 if(hgfxmmu->State != HAL_GFXMMU_STATE_READY)
744 status = HAL_ERROR;
746 else
748 /* Modify cache and pre-fetch parameters on GFXMMU_CR register */
749 hgfxmmu->Instance->CR &= ~(GFXMMU_CR_CE | GFXMMU_CR_CL | GFXMMU_CR_CLB | GFXMMU_CR_FC |
750 GFXMMU_CR_PD | GFXMMU_CR_OC | GFXMMU_CR_OB);
751 if(CachePrefetch->Activation == ENABLE)
753 assert_param(IS_GFXMMU_CACHE_LOCK(CachePrefetch->CacheLock));
754 assert_param(IS_GFXMMU_PREFETCH(CachePrefetch->Prefetch));
755 assert_param(IS_GFXMMU_OUTTER_BUFFERABILITY(CachePrefetch->OutterBufferability));
756 assert_param(IS_GFXMMU_OUTTER_CACHABILITY(CachePrefetch->OutterCachability));
757 hgfxmmu->Instance->CR |= (GFXMMU_CR_CE |
758 CachePrefetch->CacheLock |
759 CachePrefetch->Prefetch |
760 CachePrefetch->OutterBufferability |
761 CachePrefetch->OutterCachability);
762 if(CachePrefetch->CacheLock == GFXMMU_CACHE_LOCK_ENABLE)
764 assert_param(IS_GFXMMU_CACHE_LOCK_BUFFER(CachePrefetch->CacheLockBuffer));
765 assert_param(IS_GFXMMU_CACHE_FORCE(CachePrefetch->CacheForce));
766 hgfxmmu->Instance->CR |= (CachePrefetch->CacheLockBuffer |
767 CachePrefetch->CacheForce);
771 /* Return function status */
772 return status;
776 * @brief This function handles the GFXMMU interrupts.
777 * @param hgfxmmu GFXMMU handle.
778 * @retval None.
780 void HAL_GFXMMU_IRQHandler(GFXMMU_HandleTypeDef *hgfxmmu)
782 uint32_t flags, interrupts, error;
784 /* Read current flags and interrupts and determine which error occurs */
785 flags = hgfxmmu->Instance->SR;
786 interrupts = (hgfxmmu->Instance->CR & GFXMMU_CR_ITS_MASK);
787 error = (flags & interrupts);
789 if(error != 0U)
791 /* Clear flags on GFXMMU_FCR register */
792 hgfxmmu->Instance->FCR = error;
794 /* Update GFXMMU error code */
795 hgfxmmu->ErrorCode |= error;
797 /* Call GFXMMU error callback */
798 #if (USE_HAL_GFXMMU_REGISTER_CALLBACKS == 1)
799 hgfxmmu->ErrorCallback(hgfxmmu);
800 #else
801 HAL_GFXMMU_ErrorCallback(hgfxmmu);
802 #endif
807 * @brief Error callback.
808 * @param hgfxmmu GFXMMU handle.
809 * @retval None.
811 __weak void HAL_GFXMMU_ErrorCallback(GFXMMU_HandleTypeDef *hgfxmmu)
813 /* Prevent unused argument(s) compilation warning */
814 UNUSED(hgfxmmu);
816 /* NOTE : This function should not be modified, when the callback is needed,
817 the HAL_GFXMMU_ErrorCallback could be implemented in the user file.
822 * @}
825 /** @defgroup GFXMMU_Exported_Functions_Group3 State functions
826 * @brief GFXMMU state functions
828 @verbatim
829 ==============================================================================
830 ##### State functions #####
831 ==============================================================================
832 [..] This section provides functions allowing to:
833 (+) Get GFXMMU handle state.
834 (+) Get GFXMMU error code.
835 @endverbatim
836 * @{
840 * @brief This function allows to get the current GFXMMU handle state.
841 * @param hgfxmmu GFXMMU handle.
842 * @retval GFXMMU state.
844 HAL_GFXMMU_StateTypeDef HAL_GFXMMU_GetState(GFXMMU_HandleTypeDef *hgfxmmu)
846 /* Return GFXMMU handle state */
847 return hgfxmmu->State;
851 * @brief This function allows to get the current GFXMMU error code.
852 * @param hgfxmmu GFXMMU handle.
853 * @retval GFXMMU error code.
855 uint32_t HAL_GFXMMU_GetError(GFXMMU_HandleTypeDef *hgfxmmu)
857 uint32_t error_code;
859 /* Enter in critical section */
860 __disable_irq();
862 /* Store and reset GFXMMU error code */
863 error_code = hgfxmmu->ErrorCode;
864 hgfxmmu->ErrorCode = GFXMMU_ERROR_NONE;
866 /* Exit from critical section */
867 __enable_irq();
869 /* Return GFXMMU error code */
870 return error_code;
874 * @}
878 * @}
880 /* End of exported functions -------------------------------------------------*/
881 /* Private functions ---------------------------------------------------------*/
882 /* End of private functions --------------------------------------------------*/
885 * @}
887 #endif /* GFXMMU */
888 #endif /* HAL_GFXMMU_MODULE_ENABLED */
890 * @}
893 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/