Back to home page

LXR

 
 

    


File indexing completed on 2025-05-11 08:23:07

0001 /**
0002   ******************************************************************************
0003   * @file    stm32h7xx_hal_gfxmmu.c
0004   * @author  MCD Application Team
0005   * @brief   This file provides firmware functions to manage the following 
0006   *          functionalities of the Graphic MMU (GFXMMU) peripheral:
0007   *           + Initialization and De-initialization.
0008   *           + LUT configuration.
0009   *           + Force flush and/or invalidate of cache.
0010   *           + Modify physical buffer addresses.
0011   *           + Modify cache and pre-fetch parameters.
0012   *           + Error management.
0013   *
0014   ******************************************************************************
0015   * @attention
0016   *
0017   * Copyright (c) 2017 STMicroelectronics.
0018   * All rights reserved.
0019   *
0020   * This software is licensed under terms that can be found in the LICENSE file
0021   * in the root directory of this software component.
0022   * If no LICENSE file comes with this software, it is provided AS-IS.
0023   *
0024   ******************************************************************************
0025   @verbatim
0026   ==============================================================================
0027                      ##### How to use this driver #####
0028   ==============================================================================
0029   [..]
0030     *** Initialization ***
0031     ======================
0032     [..]
0033       (#) As prerequisite, fill in the HAL_GFXMMU_MspInit() :
0034         (++) Enable GFXMMU clock interface with __HAL_RCC_GFXMMU_CLK_ENABLE().
0035         (++) If interrupts are used, enable and configure GFXMMU global
0036             interrupt with HAL_NVIC_SetPriority() and HAL_NVIC_EnableIRQ().
0037       (#) Configure the number of blocks per line, default value, physical 
0038           buffer addresses, cache and pre-fetch parameters and interrupts
0039           using the HAL_GFXMMU_Init() function.
0040 
0041     *** LUT configuration ***
0042     =========================
0043     [..]
0044       (#) Use HAL_GFXMMU_DisableLutLines() to deactivate all LUT lines (or a
0045           range of lines).
0046       (#) Use HAL_GFXMMU_ConfigLut() to copy LUT from flash to look up RAM.
0047       (#) Use HAL_GFXMMU_ConfigLutLine() to configure one line of LUT.
0048 
0049     *** Force flush and/or invalidate of cache ***
0050     ==============================================
0051     [..]    
0052       (#) Use HAL_GFXMMU_ConfigForceCache() to flush and/or invalidate cache.
0053 
0054     *** Modify physical buffer addresses ***
0055     =======================================
0056     [..]    
0057       (#) Use HAL_GFXMMU_ModifyBuffers() to modify physical buffer addresses.
0058 
0059     *** Modify cache and pre-fetch parameters ***
0060     =============================================
0061     [..]    
0062       (#) Use HAL_GFXMMU_ModifyCachePrefetch() to modify cache and pre-fetch
0063           parameters.
0064 
0065     *** Error management ***
0066     ========================
0067     [..]
0068       (#) If interrupts are used, HAL_GFXMMU_IRQHandler() will be called when
0069           an error occurs. This function will call HAL_GFXMMU_ErrorCallback().
0070           Use HAL_GFXMMU_GetError() to get the error code.
0071 
0072     *** De-initialization ***
0073     =========================
0074     [..]    
0075       (#) As prerequisite, fill in the HAL_GFXMMU_MspDeInit() :
0076         (++) Disable GFXMMU clock interface with __HAL_RCC_GFXMMU_CLK_ENABLE().
0077         (++) If interrupts has been used, disable GFXMMU global interrupt with
0078              HAL_NVIC_DisableIRQ().
0079       (#) De-initialize GFXMMU using the HAL_GFXMMU_DeInit() function.
0080 
0081     *** Callback registration ***
0082     =============================
0083 
0084     [..]
0085     The compilation define USE_HAL_GFXMMU_REGISTER_CALLBACKS when set to 1
0086     allows the user to configure dynamically the driver callbacks.
0087     Use functions HAL_GFXMMU_RegisterCallback() to register a user callback.
0088 
0089     [..]
0090     Function HAL_GFXMMU_RegisterCallback() allows to register following callbacks:
0091       (+) ErrorCallback      : GFXMMU error.
0092       (+) MspInitCallback    : GFXMMU MspInit.
0093       (+) MspDeInitCallback  : GFXMMU MspDeInit.
0094     [..]
0095     This function takes as parameters the HAL peripheral handle, the callback ID
0096     and a pointer to the user callback function.
0097 
0098     [..]
0099     Use function HAL_GFXMMU_UnRegisterCallback() to reset a callback to the default
0100     weak (surcharged) function.
0101     HAL_GFXMMU_UnRegisterCallback() takes as parameters the HAL peripheral handle,
0102     and the callback ID.
0103     [..]
0104     This function allows to reset following callbacks:
0105       (+) ErrorCallback      : GFXMMU error.
0106       (+) MspInitCallback    : GFXMMU MspInit.
0107       (+) MspDeInitCallback  : GFXMMU MspDeInit.
0108 
0109     [..]
0110     By default, after the HAL_GFXMMU_Init and if the state is HAL_GFXMMU_STATE_RESET
0111     all callbacks are reset to the corresponding legacy weak (surcharged) functions:
0112     examples HAL_GFXMMU_ErrorCallback().
0113     Exception done for MspInit and MspDeInit callbacks that are respectively
0114     reset to the legacy weak (surcharged) functions in the HAL_GFXMMU_Init
0115     and HAL_GFXMMU_DeInit only when these callbacks are null (not registered beforehand).
0116     If not, MspInit or MspDeInit are not null, the HAL_GFXMMU_Init and HAL_GFXMMU_DeInit
0117     keep and use the user MspInit/MspDeInit callbacks (registered beforehand).
0118 
0119     [..]
0120     Callbacks can be registered/unregistered in READY state only.
0121     Exception done for MspInit/MspDeInit callbacks that can be registered/unregistered
0122     in READY or RESET state, thus registered (user) MspInit/DeInit callbacks can be used
0123     during the Init/DeInit.
0124     In that case first register the MspInit/MspDeInit user callbacks
0125     using HAL_GFXMMU_RegisterCallback before calling HAL_GFXMMU_DeInit
0126     or HAL_GFXMMU_Init function.
0127 
0128     [..]
0129     When the compilation define USE_HAL_GFXMMU_REGISTER_CALLBACKS is set to 0 or
0130     not defined, the callback registering feature is not available
0131     and weak (surcharged) callbacks are used.
0132 
0133   @endverbatim
0134   ******************************************************************************
0135   */
0136 
0137 /* Includes ------------------------------------------------------------------*/
0138 #include "stm32h7xx_hal.h"
0139 
0140 /** @addtogroup STM32H7xx_HAL_Driver
0141   * @{
0142   */
0143 #ifdef HAL_GFXMMU_MODULE_ENABLED
0144 #if defined(GFXMMU)
0145 /** @defgroup GFXMMU GFXMMU
0146   * @ingroup RTEMSBSPsARMSTM32H7
0147   * @brief GFXMMU HAL driver module
0148   * @{
0149   */
0150 
0151 /* Private typedef -----------------------------------------------------------*/
0152 /* Private define ------------------------------------------------------------*/
0153 #define GFXMMU_LUTXL_FVB_OFFSET     8U
0154 #define GFXMMU_LUTXL_LVB_OFFSET     16U
0155 #define GFXMMU_CR_ITS_MASK          0x1FU
0156 /* Private macro -------------------------------------------------------------*/
0157 /* Private variables ---------------------------------------------------------*/
0158 /* Private function prototypes -----------------------------------------------*/
0159 /* Exported functions --------------------------------------------------------*/
0160 /** @defgroup GFXMMU_Exported_Functions GFXMMU Exported Functions
0161   * @ingroup RTEMSBSPsARMSTM32H7
0162   * @{
0163   */
0164 
0165 /** @defgroup GFXMMU_Exported_Functions_Group1 Initialization and de-initialization functions
0166   * @ingroup RTEMSBSPsARMSTM32H7
0167  *  @brief    Initialization and de-initialization functions 
0168  *
0169 @verbatim
0170   ==============================================================================
0171           ##### Initialization and de-initialization functions #####
0172   ==============================================================================
0173     [..]  This section provides functions allowing to:
0174       (+) Initialize the GFXMMU.
0175       (+) De-initialize the GFXMMU.
0176 @endverbatim
0177   * @{
0178   */
0179 
0180 /**
0181   * @brief  Initialize the GFXMMU according to the specified parameters in the
0182   *         GFXMMU_InitTypeDef structure and initialize the associated handle.
0183   * @param  hgfxmmu GFXMMU handle.
0184   * @retval HAL status.
0185   */
0186 HAL_StatusTypeDef HAL_GFXMMU_Init(GFXMMU_HandleTypeDef *hgfxmmu)
0187 {
0188   HAL_StatusTypeDef status = HAL_OK;
0189   
0190   /* Check GFXMMU handle */
0191   if(hgfxmmu == NULL)
0192   {
0193     status = HAL_ERROR;
0194   }
0195   else
0196   {
0197     /* Check parameters */
0198     assert_param(IS_GFXMMU_ALL_INSTANCE(hgfxmmu->Instance));
0199     assert_param(IS_GFXMMU_BLOCKS_PER_LINE(hgfxmmu->Init.BlocksPerLine));
0200     assert_param(IS_GFXMMU_BUFFER_ADDRESS(hgfxmmu->Init.Buffers.Buf0Address));
0201     assert_param(IS_GFXMMU_BUFFER_ADDRESS(hgfxmmu->Init.Buffers.Buf1Address));
0202     assert_param(IS_GFXMMU_BUFFER_ADDRESS(hgfxmmu->Init.Buffers.Buf2Address));
0203     assert_param(IS_GFXMMU_BUFFER_ADDRESS(hgfxmmu->Init.Buffers.Buf3Address));
0204     assert_param(IS_FUNCTIONAL_STATE(hgfxmmu->Init.CachePrefetch.Activation));
0205     assert_param(IS_FUNCTIONAL_STATE(hgfxmmu->Init.Interrupts.Activation));
0206     
0207 #if (USE_HAL_GFXMMU_REGISTER_CALLBACKS == 1)
0208     /* Reset callback pointers to the weak predefined callbacks */
0209     hgfxmmu->ErrorCallback = HAL_GFXMMU_ErrorCallback;
0210 
0211     /* Call GFXMMU MSP init function */
0212     if(hgfxmmu->MspInitCallback == NULL)
0213     {
0214       hgfxmmu->MspInitCallback = HAL_GFXMMU_MspInit;
0215     }
0216     hgfxmmu->MspInitCallback(hgfxmmu);
0217 #else
0218     /* Call GFXMMU MSP init function */
0219     HAL_GFXMMU_MspInit(hgfxmmu);
0220 #endif
0221     
0222     /* Configure blocks per line, cache and interrupts parameters on GFXMMU_CR register */
0223     hgfxmmu->Instance->CR &= ~(GFXMMU_CR_B0OIE | GFXMMU_CR_B1OIE | GFXMMU_CR_B2OIE | GFXMMU_CR_B3OIE |
0224                                GFXMMU_CR_AMEIE | GFXMMU_CR_192BM | GFXMMU_CR_CE    | GFXMMU_CR_CL    |
0225                                GFXMMU_CR_CLB   | GFXMMU_CR_FC    | GFXMMU_CR_PD    | GFXMMU_CR_OC    |
0226                                GFXMMU_CR_OB);
0227     hgfxmmu->Instance->CR |= (hgfxmmu->Init.BlocksPerLine);
0228     if(hgfxmmu->Init.CachePrefetch.Activation == ENABLE)
0229     {
0230       assert_param(IS_GFXMMU_CACHE_LOCK(hgfxmmu->Init.CachePrefetch.CacheLock));
0231       assert_param(IS_GFXMMU_PREFETCH(hgfxmmu->Init.CachePrefetch.Prefetch));
0232       assert_param(IS_GFXMMU_OUTTER_BUFFERABILITY(hgfxmmu->Init.CachePrefetch.OutterBufferability));
0233       assert_param(IS_GFXMMU_OUTTER_CACHABILITY(hgfxmmu->Init.CachePrefetch.OutterCachability));
0234       hgfxmmu->Instance->CR |= (GFXMMU_CR_CE |
0235                                 hgfxmmu->Init.CachePrefetch.CacheLock |
0236                                 hgfxmmu->Init.CachePrefetch.Prefetch |
0237                                 hgfxmmu->Init.CachePrefetch.OutterBufferability |
0238                                 hgfxmmu->Init.CachePrefetch.OutterCachability);
0239       if(hgfxmmu->Init.CachePrefetch.CacheLock == GFXMMU_CACHE_LOCK_ENABLE)
0240       {
0241         assert_param(IS_GFXMMU_CACHE_LOCK_BUFFER(hgfxmmu->Init.CachePrefetch.CacheLockBuffer));
0242         assert_param(IS_GFXMMU_CACHE_FORCE(hgfxmmu->Init.CachePrefetch.CacheForce));
0243         hgfxmmu->Instance->CR |= (hgfxmmu->Init.CachePrefetch.CacheLockBuffer | 
0244                                   hgfxmmu->Init.CachePrefetch.CacheForce);
0245       }
0246     }
0247     if(hgfxmmu->Init.Interrupts.Activation == ENABLE)
0248     {
0249       assert_param(IS_GFXMMU_INTERRUPTS(hgfxmmu->Init.Interrupts.UsedInterrupts));
0250       hgfxmmu->Instance->CR |= hgfxmmu->Init.Interrupts.UsedInterrupts;
0251     }
0252     
0253     /* Configure default value on GFXMMU_DVR register */
0254     hgfxmmu->Instance->DVR = hgfxmmu->Init.DefaultValue;
0255     
0256     /* Configure physical buffer addresses on GFXMMU_BxCR registers */
0257     hgfxmmu->Instance->B0CR = hgfxmmu->Init.Buffers.Buf0Address;
0258     hgfxmmu->Instance->B1CR = hgfxmmu->Init.Buffers.Buf1Address;
0259     hgfxmmu->Instance->B2CR = hgfxmmu->Init.Buffers.Buf2Address;
0260     hgfxmmu->Instance->B3CR = hgfxmmu->Init.Buffers.Buf3Address;
0261     
0262     /* Force invalidate cache if cache is enabled */
0263     if(hgfxmmu->Init.CachePrefetch.Activation == ENABLE)
0264     {
0265       hgfxmmu->Instance->CCR |= GFXMMU_CACHE_FORCE_INVALIDATE;
0266     }
0267     
0268     /* Reset GFXMMU error code */
0269     hgfxmmu->ErrorCode = GFXMMU_ERROR_NONE;
0270     
0271     /* Set GFXMMU to ready state */
0272     hgfxmmu->State = HAL_GFXMMU_STATE_READY;
0273   }
0274   /* Return function status */
0275   return status;
0276 }
0277 
0278 /**
0279   * @brief  De-initialize the GFXMMU.
0280   * @param  hgfxmmu GFXMMU handle.
0281   * @retval HAL status.
0282   */
0283 HAL_StatusTypeDef HAL_GFXMMU_DeInit(GFXMMU_HandleTypeDef *hgfxmmu)
0284 {
0285   HAL_StatusTypeDef status = HAL_OK;
0286   
0287   /* Check GFXMMU handle */
0288   if(hgfxmmu == NULL)
0289   {
0290     status = HAL_ERROR;
0291   }
0292   else
0293   {
0294     /* Check parameters */
0295     assert_param(IS_GFXMMU_ALL_INSTANCE(hgfxmmu->Instance));
0296     
0297     /* Disable all interrupts on GFXMMU_CR register */
0298     hgfxmmu->Instance->CR &= ~(GFXMMU_CR_B0OIE | GFXMMU_CR_B1OIE | GFXMMU_CR_B2OIE | GFXMMU_CR_B3OIE |
0299                                GFXMMU_CR_AMEIE);
0300     
0301     /* Call GFXMMU MSP de-init function */
0302 #if (USE_HAL_GFXMMU_REGISTER_CALLBACKS == 1)
0303     if(hgfxmmu->MspDeInitCallback == NULL)
0304     {
0305       hgfxmmu->MspDeInitCallback = HAL_GFXMMU_MspDeInit;
0306     }
0307     hgfxmmu->MspDeInitCallback(hgfxmmu);
0308 #else
0309     HAL_GFXMMU_MspDeInit(hgfxmmu);
0310 #endif
0311     
0312     /* Set GFXMMU to reset state */
0313     hgfxmmu->State = HAL_GFXMMU_STATE_RESET;
0314   }
0315   /* Return function status */
0316   return status;
0317 }
0318 
0319 /**
0320   * @brief  Initialize the GFXMMU MSP.
0321   * @param  hgfxmmu GFXMMU handle.
0322   * @retval None.
0323   */
0324 __weak void HAL_GFXMMU_MspInit(GFXMMU_HandleTypeDef *hgfxmmu)
0325 {
0326   /* Prevent unused argument(s) compilation warning */
0327   UNUSED(hgfxmmu);
0328   
0329   /* NOTE : This function should not be modified, when the function is needed,
0330             the HAL_GFXMMU_MspInit could be implemented in the user file.
0331    */
0332 }
0333 
0334 /**
0335   * @brief  De-initialize the GFXMMU MSP.
0336   * @param  hgfxmmu GFXMMU handle.
0337   * @retval None.
0338   */
0339 __weak void HAL_GFXMMU_MspDeInit(GFXMMU_HandleTypeDef *hgfxmmu)
0340 {
0341   /* Prevent unused argument(s) compilation warning */
0342   UNUSED(hgfxmmu);
0343   
0344   /* NOTE : This function should not be modified, when the function is needed,
0345             the HAL_GFXMMU_MspDeInit could be implemented in the user file.
0346    */
0347 }
0348 
0349 #if (USE_HAL_GFXMMU_REGISTER_CALLBACKS == 1)
0350 /**
0351   * @brief  Register a user GFXMMU callback
0352   *         to be used instead of the weak predefined callback.
0353   * @param  hgfxmmu GFXMMU handle.
0354   * @param  CallbackID ID of the callback to be registered.
0355   *         This parameter can be one of the following values:
0356   *           @arg @ref HAL_GFXMMU_ERROR_CB_ID error callback ID.
0357   *           @arg @ref HAL_GFXMMU_MSPINIT_CB_ID MSP init callback ID.
0358   *           @arg @ref HAL_GFXMMU_MSPDEINIT_CB_ID MSP de-init callback ID.
0359   * @param  pCallback pointer to the callback function.
0360   * @retval HAL status.
0361   */
0362 HAL_StatusTypeDef HAL_GFXMMU_RegisterCallback(GFXMMU_HandleTypeDef        *hgfxmmu,
0363                                               HAL_GFXMMU_CallbackIDTypeDef CallbackID,
0364                                               pGFXMMU_CallbackTypeDef      pCallback)
0365 {
0366   HAL_StatusTypeDef status = HAL_OK;
0367 
0368   if(pCallback == NULL)
0369   {
0370     /* update the error code */
0371     hgfxmmu->ErrorCode |= GFXMMU_ERROR_INVALID_CALLBACK;
0372     /* update return status */
0373     status = HAL_ERROR;
0374   }
0375   else
0376   {
0377     if(HAL_GFXMMU_STATE_READY == hgfxmmu->State)
0378     {
0379       switch (CallbackID)
0380       {
0381       case HAL_GFXMMU_ERROR_CB_ID :
0382         hgfxmmu->ErrorCallback = pCallback;
0383         break;
0384       case HAL_GFXMMU_MSPINIT_CB_ID :
0385         hgfxmmu->MspInitCallback = pCallback;
0386         break;
0387       case HAL_GFXMMU_MSPDEINIT_CB_ID :
0388         hgfxmmu->MspDeInitCallback = pCallback;
0389         break;
0390       default :
0391         /* update the error code */
0392         hgfxmmu->ErrorCode |= GFXMMU_ERROR_INVALID_CALLBACK;
0393         /* update return status */
0394         status = HAL_ERROR;
0395         break;
0396       }
0397     }
0398     else if(HAL_GFXMMU_STATE_RESET == hgfxmmu->State)
0399     {
0400       switch (CallbackID)
0401       {
0402       case HAL_GFXMMU_MSPINIT_CB_ID :
0403         hgfxmmu->MspInitCallback = pCallback;
0404         break;
0405       case HAL_GFXMMU_MSPDEINIT_CB_ID :
0406         hgfxmmu->MspDeInitCallback = pCallback;
0407         break;
0408       default :
0409         /* update the error code */
0410         hgfxmmu->ErrorCode |= GFXMMU_ERROR_INVALID_CALLBACK;
0411         /* update return status */
0412         status = HAL_ERROR;
0413         break;
0414       }
0415     }
0416     else
0417     {
0418       /* update the error code */
0419       hgfxmmu->ErrorCode |= GFXMMU_ERROR_INVALID_CALLBACK;
0420       /* update return status */
0421       status = HAL_ERROR;
0422     }
0423   }
0424   return status;
0425 }
0426 
0427 /**
0428   * @brief  Unregister a user GFXMMU callback.
0429   *         GFXMMU callback is redirected to the weak predefined callback.
0430   * @param  hgfxmmu GFXMMU handle.
0431   * @param  CallbackID ID of the callback to be unregistered.
0432   *         This parameter can be one of the following values:
0433   *           @arg @ref HAL_GFXMMU_ERROR_CB_ID error callback ID.
0434   *           @arg @ref HAL_GFXMMU_MSPINIT_CB_ID MSP init callback ID.
0435   *           @arg @ref HAL_GFXMMU_MSPDEINIT_CB_ID MSP de-init callback ID.
0436   * @retval HAL status.
0437   */
0438 HAL_StatusTypeDef HAL_GFXMMU_UnRegisterCallback(GFXMMU_HandleTypeDef        *hgfxmmu,
0439                                                 HAL_GFXMMU_CallbackIDTypeDef CallbackID)
0440 {
0441   HAL_StatusTypeDef status = HAL_OK;
0442 
0443   if(HAL_GFXMMU_STATE_READY == hgfxmmu->State)
0444   {
0445     switch (CallbackID)
0446     {
0447     case HAL_GFXMMU_ERROR_CB_ID :
0448       hgfxmmu->ErrorCallback = HAL_GFXMMU_ErrorCallback;
0449       break;
0450     case HAL_GFXMMU_MSPINIT_CB_ID :
0451       hgfxmmu->MspInitCallback = HAL_GFXMMU_MspInit;
0452       break;
0453     case HAL_GFXMMU_MSPDEINIT_CB_ID :
0454       hgfxmmu->MspDeInitCallback = HAL_GFXMMU_MspDeInit;
0455       break;
0456     default :
0457       /* update the error code */
0458       hgfxmmu->ErrorCode |= GFXMMU_ERROR_INVALID_CALLBACK;
0459       /* update return status */
0460       status = HAL_ERROR;
0461       break;
0462     }
0463   }
0464   else if(HAL_GFXMMU_STATE_RESET == hgfxmmu->State)
0465   {
0466     switch (CallbackID)
0467     {
0468     case HAL_GFXMMU_MSPINIT_CB_ID :
0469       hgfxmmu->MspInitCallback = HAL_GFXMMU_MspInit;
0470       break;
0471     case HAL_GFXMMU_MSPDEINIT_CB_ID :
0472       hgfxmmu->MspDeInitCallback = HAL_GFXMMU_MspDeInit;
0473       break;
0474     default :
0475       /* update the error code */
0476       hgfxmmu->ErrorCode |= GFXMMU_ERROR_INVALID_CALLBACK;
0477       /* update return status */
0478       status = HAL_ERROR;
0479       break;
0480     }
0481   }
0482   else
0483   {
0484     /* update the error code */
0485     hgfxmmu->ErrorCode |= GFXMMU_ERROR_INVALID_CALLBACK;
0486     /* update return status */
0487     status = HAL_ERROR;
0488   }
0489   return status;
0490 }
0491 #endif /* USE_HAL_GFXMMU_REGISTER_CALLBACKS */
0492 
0493 /**
0494   * @}
0495   */
0496 
0497 /** @defgroup GFXMMU_Exported_Functions_Group2 Operations functions
0498   * @ingroup RTEMSBSPsARMSTM32H7
0499  *  @brief    GFXMMU operation functions
0500  *
0501 @verbatim
0502   ==============================================================================
0503                       ##### Operation functions #####
0504   ==============================================================================
0505     [..]  This section provides functions allowing to:
0506       (+) Configure LUT.
0507       (+) Force flush and/or invalidate of cache.
0508       (+) Modify physical buffer addresses.
0509       (+) Modify cache and pre-fetch parameters.
0510       (+) Manage error.
0511 @endverbatim
0512   * @{
0513   */
0514 
0515 /**
0516   * @brief  This function allows to copy LUT from flash to look up RAM.
0517   * @param  hgfxmmu GFXMMU handle.
0518   * @param  FirstLine First line enabled on LUT.
0519   *         This parameter must be a number between Min_Data = 0 and Max_Data = 1023.
0520   * @param  LinesNumber Number of lines enabled on LUT.
0521   *         This parameter must be a number between Min_Data = 1 and Max_Data = 1024.
0522   * @param  Address Start address of LUT in flash.
0523   * @retval HAL status.
0524   */
0525 HAL_StatusTypeDef HAL_GFXMMU_ConfigLut(GFXMMU_HandleTypeDef *hgfxmmu,
0526                                        uint32_t FirstLine,
0527                                        uint32_t LinesNumber,
0528                                        uint32_t Address)
0529 {
0530   HAL_StatusTypeDef status = HAL_OK;
0531   
0532   /* Check parameters */
0533   assert_param(IS_GFXMMU_ALL_INSTANCE(hgfxmmu->Instance));
0534   assert_param(IS_GFXMMU_LUT_LINE(FirstLine));
0535   assert_param(IS_GFXMMU_LUT_LINES_NUMBER(LinesNumber));
0536   
0537   /* Check GFXMMU state and coherent parameters */
0538   if((hgfxmmu->State != HAL_GFXMMU_STATE_READY) || ((FirstLine + LinesNumber) > 1024U))
0539   {
0540     status = HAL_ERROR;
0541   }
0542   else
0543   {
0544     uint32_t current_address, current_line, lutxl_address, lutxh_address;
0545     
0546     /* Initialize local variables */
0547     current_address = Address;
0548     current_line    = 0U;
0549     lutxl_address   = (uint32_t) &(hgfxmmu->Instance->LUT[2U * FirstLine]);
0550     lutxh_address   = (uint32_t) &(hgfxmmu->Instance->LUT[(2U * FirstLine) + 1U]);
0551     
0552     /* Copy LUT from flash to look up RAM */
0553     while(current_line < LinesNumber)
0554     {
0555       *((uint32_t *)lutxl_address) = *((uint32_t *)current_address);
0556       current_address += 4U;
0557       *((uint32_t *)lutxh_address) = *((uint32_t *)current_address);
0558       current_address += 4U;
0559       lutxl_address += 8U;
0560       lutxh_address += 8U;
0561       current_line++;
0562     }
0563   }
0564   /* Return function status */
0565   return status;
0566 }
0567 
0568 /**
0569   * @brief  This function allows to disable a range of LUT lines.
0570   * @param  hgfxmmu GFXMMU handle.
0571   * @param  FirstLine First line to disable on LUT.
0572   *         This parameter must be a number between Min_Data = 0 and Max_Data = 1023.
0573   * @param  LinesNumber Number of lines to disable on LUT.
0574   *         This parameter must be a number between Min_Data = 1 and Max_Data = 1024.
0575   * @retval HAL status.
0576   */
0577 HAL_StatusTypeDef HAL_GFXMMU_DisableLutLines(GFXMMU_HandleTypeDef *hgfxmmu,
0578                                              uint32_t FirstLine,
0579                                              uint32_t LinesNumber)
0580 {
0581   HAL_StatusTypeDef status = HAL_OK;
0582   
0583   /* Check parameters */
0584   assert_param(IS_GFXMMU_ALL_INSTANCE(hgfxmmu->Instance));
0585   assert_param(IS_GFXMMU_LUT_LINE(FirstLine));
0586   assert_param(IS_GFXMMU_LUT_LINES_NUMBER(LinesNumber));
0587   
0588   /* Check GFXMMU state and coherent parameters */
0589   if((hgfxmmu->State != HAL_GFXMMU_STATE_READY) || ((FirstLine + LinesNumber) > 1024U))
0590   {
0591     status = HAL_ERROR;
0592   }
0593   else
0594   {
0595     uint32_t current_line, lutxl_address, lutxh_address;
0596     
0597     /* Initialize local variables */
0598     current_line    = 0U;
0599     lutxl_address   = (uint32_t) &(hgfxmmu->Instance->LUT[2U * FirstLine]);
0600     lutxh_address   = (uint32_t) &(hgfxmmu->Instance->LUT[(2U * FirstLine) + 1U]);
0601     
0602     /* Disable LUT lines */
0603     while(current_line < LinesNumber)
0604     {
0605       *((uint32_t *)lutxl_address) = 0U;
0606       *((uint32_t *)lutxh_address) = 0U;
0607       lutxl_address += 8U;
0608       lutxh_address += 8U;
0609       current_line++;
0610     }
0611   }
0612   /* Return function status */
0613   return status;
0614 }
0615 
0616 /**
0617   * @brief  This function allows to configure one line of LUT.
0618   * @param  hgfxmmu GFXMMU handle.
0619   * @param  lutLine LUT line parameters.
0620   * @retval HAL status.
0621   */
0622 HAL_StatusTypeDef HAL_GFXMMU_ConfigLutLine(GFXMMU_HandleTypeDef *hgfxmmu, GFXMMU_LutLineTypeDef *lutLine)
0623 {
0624   HAL_StatusTypeDef status = HAL_OK;
0625   
0626   /* Check parameters */
0627   assert_param(IS_GFXMMU_ALL_INSTANCE(hgfxmmu->Instance));
0628   assert_param(IS_GFXMMU_LUT_LINE(lutLine->LineNumber));
0629   assert_param(IS_GFXMMU_LUT_LINE_STATUS(lutLine->LineStatus));
0630   assert_param(IS_GFXMMU_LUT_BLOCK(lutLine->FirstVisibleBlock));
0631   assert_param(IS_GFXMMU_LUT_BLOCK(lutLine->LastVisibleBlock));
0632   assert_param(IS_GFXMMU_LUT_LINE_OFFSET(lutLine->LineOffset));
0633   
0634   /* Check GFXMMU state */
0635   if(hgfxmmu->State != HAL_GFXMMU_STATE_READY)
0636   {
0637     status = HAL_ERROR;
0638   }
0639   else
0640   {
0641     uint32_t lutxl_address, lutxh_address;
0642     
0643     /* Initialize local variables */
0644     lutxl_address   = (uint32_t) &(hgfxmmu->Instance->LUT[2U * lutLine->LineNumber]);
0645     lutxh_address   = (uint32_t) &(hgfxmmu->Instance->LUT[(2U * lutLine->LineNumber) + 1U]);
0646     
0647     /* Configure LUT line */
0648     if(lutLine->LineStatus == GFXMMU_LUT_LINE_ENABLE)
0649     {
0650       /* Enable and configure LUT line */
0651       *((uint32_t *)lutxl_address) = (lutLine->LineStatus | 
0652                                      (lutLine->FirstVisibleBlock << GFXMMU_LUTXL_FVB_OFFSET) | 
0653                                      (lutLine->LastVisibleBlock << GFXMMU_LUTXL_LVB_OFFSET));
0654       *((uint32_t *)lutxh_address) = (uint32_t) lutLine->LineOffset;
0655     }
0656     else
0657     {
0658       /* Disable LUT line */
0659       *((uint32_t *)lutxl_address) = 0U;
0660       *((uint32_t *)lutxh_address) = 0U;
0661     }
0662   }
0663   /* Return function status */
0664   return status;
0665 }
0666 
0667 /**
0668   * @brief  This function allows to force flush and/or invalidate of cache.
0669   * @param  hgfxmmu GFXMMU handle.
0670   * @param  ForceParam Force cache parameter.
0671   *         This parameter can be a values combination of @ref GFXMMU_CacheForceParam.
0672   * @retval HAL status.
0673   */
0674 HAL_StatusTypeDef HAL_GFXMMU_ConfigForceCache(GFXMMU_HandleTypeDef *hgfxmmu, uint32_t ForceParam)
0675 {
0676   HAL_StatusTypeDef status = HAL_OK;
0677   
0678   /* Check parameters */
0679   assert_param(IS_GFXMMU_ALL_INSTANCE(hgfxmmu->Instance));
0680   assert_param(IS_GFXMMU_CACHE_FORCE_ACTION(ForceParam));
0681   
0682   /* Check GFXMMU state and cache status */
0683   if(((hgfxmmu->Instance->CR & GFXMMU_CR_CE) != GFXMMU_CR_CE) || (hgfxmmu->State != HAL_GFXMMU_STATE_READY))
0684   {
0685     status = HAL_ERROR;
0686   }
0687   else
0688   {
0689     /* Force flush and/or invalidate cache on GFXMMU_CCR register */
0690     hgfxmmu->Instance->CCR |= ForceParam;
0691   }
0692   /* Return function status */
0693   return status;
0694 }
0695 
0696 /**
0697   * @brief  This function allows to modify physical buffer addresses.
0698   * @param  hgfxmmu GFXMMU handle.
0699   * @param  Buffers Buffers parameters.
0700   * @retval HAL status.
0701   */
0702 HAL_StatusTypeDef HAL_GFXMMU_ModifyBuffers(GFXMMU_HandleTypeDef *hgfxmmu, GFXMMU_BuffersTypeDef *Buffers)
0703 {
0704   HAL_StatusTypeDef status = HAL_OK;
0705   
0706   /* Check parameters */
0707   assert_param(IS_GFXMMU_ALL_INSTANCE(hgfxmmu->Instance));
0708   assert_param(IS_GFXMMU_BUFFER_ADDRESS(Buffers->Buf0Address));
0709   assert_param(IS_GFXMMU_BUFFER_ADDRESS(Buffers->Buf1Address));
0710   assert_param(IS_GFXMMU_BUFFER_ADDRESS(Buffers->Buf2Address));
0711   assert_param(IS_GFXMMU_BUFFER_ADDRESS(Buffers->Buf3Address));
0712   
0713   /* Check GFXMMU state */
0714   if(hgfxmmu->State != HAL_GFXMMU_STATE_READY)
0715   {
0716     status = HAL_ERROR;
0717   }
0718   else
0719   {
0720     /* Modify physical buffer addresses on GFXMMU_BxCR registers */
0721     hgfxmmu->Instance->B0CR = Buffers->Buf0Address;
0722     hgfxmmu->Instance->B1CR = Buffers->Buf1Address;
0723     hgfxmmu->Instance->B2CR = Buffers->Buf2Address;
0724     hgfxmmu->Instance->B3CR = Buffers->Buf3Address;
0725   }
0726   /* Return function status */
0727   return status;
0728 }
0729 
0730 /**
0731   * @brief  This function allows to modify cache and pre-fetch parameters.
0732   * @param  hgfxmmu GFXMMU handle.
0733   * @param  CachePrefetch Cache and pre-fetch parameters.
0734   * @retval HAL status.
0735   */
0736 HAL_StatusTypeDef HAL_GFXMMU_ModifyCachePrefetch(GFXMMU_HandleTypeDef *hgfxmmu,
0737                                                  GFXMMU_CachePrefetchTypeDef *CachePrefetch)
0738 {
0739   HAL_StatusTypeDef status = HAL_OK;
0740   assert_param(IS_FUNCTIONAL_STATE(CachePrefetch->Activation));
0741   
0742   /* Check parameters */
0743   assert_param(IS_GFXMMU_ALL_INSTANCE(hgfxmmu->Instance));
0744   
0745   /* Check GFXMMU state */
0746   if(hgfxmmu->State != HAL_GFXMMU_STATE_READY)
0747   {
0748     status = HAL_ERROR;
0749   }
0750   else
0751   {
0752     /* Modify cache and pre-fetch parameters on GFXMMU_CR register */
0753     hgfxmmu->Instance->CR &= ~(GFXMMU_CR_CE | GFXMMU_CR_CL | GFXMMU_CR_CLB | GFXMMU_CR_FC |
0754                                GFXMMU_CR_PD | GFXMMU_CR_OC | GFXMMU_CR_OB);
0755     if(CachePrefetch->Activation == ENABLE)
0756     {
0757       assert_param(IS_GFXMMU_CACHE_LOCK(CachePrefetch->CacheLock));
0758       assert_param(IS_GFXMMU_PREFETCH(CachePrefetch->Prefetch));
0759       assert_param(IS_GFXMMU_OUTTER_BUFFERABILITY(CachePrefetch->OutterBufferability));
0760       assert_param(IS_GFXMMU_OUTTER_CACHABILITY(CachePrefetch->OutterCachability));
0761       hgfxmmu->Instance->CR |= (GFXMMU_CR_CE |
0762                                 CachePrefetch->CacheLock |
0763                                 CachePrefetch->Prefetch |
0764                                 CachePrefetch->OutterBufferability |
0765                                 CachePrefetch->OutterCachability);
0766       if(CachePrefetch->CacheLock == GFXMMU_CACHE_LOCK_ENABLE)
0767       {
0768         assert_param(IS_GFXMMU_CACHE_LOCK_BUFFER(CachePrefetch->CacheLockBuffer));
0769         assert_param(IS_GFXMMU_CACHE_FORCE(CachePrefetch->CacheForce));
0770         hgfxmmu->Instance->CR |= (CachePrefetch->CacheLockBuffer |
0771                                   CachePrefetch->CacheForce);
0772       }
0773     }
0774   }
0775   /* Return function status */
0776   return status;
0777 }
0778 
0779 /**
0780   * @brief  This function handles the GFXMMU interrupts.
0781   * @param  hgfxmmu GFXMMU handle.
0782   * @retval None.
0783   */
0784 void HAL_GFXMMU_IRQHandler(GFXMMU_HandleTypeDef *hgfxmmu)
0785 {
0786   uint32_t flags, interrupts, error;
0787   
0788   /* Read current flags and interrupts and determine which error occurs */
0789   flags = hgfxmmu->Instance->SR;
0790   interrupts = (hgfxmmu->Instance->CR & GFXMMU_CR_ITS_MASK);
0791   error = (flags & interrupts);
0792   
0793   if(error != 0U)
0794   {
0795     /* Clear flags on GFXMMU_FCR register */
0796     hgfxmmu->Instance->FCR = error;
0797     
0798     /* Update GFXMMU error code */
0799     hgfxmmu->ErrorCode |= error;
0800     
0801     /* Call GFXMMU error callback */
0802 #if (USE_HAL_GFXMMU_REGISTER_CALLBACKS == 1)
0803     hgfxmmu->ErrorCallback(hgfxmmu);
0804 #else
0805     HAL_GFXMMU_ErrorCallback(hgfxmmu);
0806 #endif
0807   }
0808 }
0809 
0810 /**
0811   * @brief  Error callback. 
0812   * @param  hgfxmmu GFXMMU handle.
0813   * @retval None.
0814   */
0815 __weak void HAL_GFXMMU_ErrorCallback(GFXMMU_HandleTypeDef *hgfxmmu)
0816 {
0817   /* Prevent unused argument(s) compilation warning */
0818   UNUSED(hgfxmmu);
0819   
0820   /* NOTE : This function should not be modified, when the callback is needed,
0821             the HAL_GFXMMU_ErrorCallback could be implemented in the user file.
0822    */
0823 }
0824 
0825 /**
0826   * @}
0827   */
0828 
0829 /** @defgroup GFXMMU_Exported_Functions_Group3 State functions
0830   * @ingroup RTEMSBSPsARMSTM32H7
0831  *  @brief    GFXMMU state functions
0832  *
0833 @verbatim
0834   ==============================================================================
0835                          ##### State functions #####
0836   ==============================================================================
0837     [..]  This section provides functions allowing to:
0838       (+) Get GFXMMU handle state.
0839       (+) Get GFXMMU error code.
0840 @endverbatim
0841   * @{
0842   */
0843 
0844 /**
0845   * @brief  This function allows to get the current GFXMMU handle state.
0846   * @param  hgfxmmu GFXMMU handle.
0847   * @retval GFXMMU state.
0848   */
0849 HAL_GFXMMU_StateTypeDef HAL_GFXMMU_GetState(GFXMMU_HandleTypeDef *hgfxmmu)
0850 {
0851   /* Return GFXMMU handle state */
0852   return hgfxmmu->State;
0853 }
0854 
0855 /**
0856   * @brief  This function allows to get the current GFXMMU error code.
0857   * @param  hgfxmmu GFXMMU handle.
0858   * @retval GFXMMU error code.
0859   */
0860 uint32_t HAL_GFXMMU_GetError(GFXMMU_HandleTypeDef *hgfxmmu)
0861 {
0862   uint32_t error_code;
0863   
0864   /* Enter in critical section */
0865   __disable_irq();  
0866   
0867   /* Store and reset GFXMMU error code */
0868   error_code = hgfxmmu->ErrorCode;
0869   hgfxmmu->ErrorCode = GFXMMU_ERROR_NONE;
0870   
0871   /* Exit from critical section */
0872   __enable_irq();
0873   
0874   /* Return GFXMMU error code */
0875   return error_code;
0876 }
0877 
0878 /**
0879   * @}
0880   */
0881 
0882 /**
0883   * @}
0884   */
0885 /* End of exported functions -------------------------------------------------*/
0886 /* Private functions ---------------------------------------------------------*/
0887 /* End of private functions --------------------------------------------------*/
0888 
0889 /**
0890   * @}
0891   */
0892 #endif /* GFXMMU */
0893 #endif /* HAL_GFXMMU_MODULE_ENABLED */
0894 /**
0895   * @}
0896   */
0897