STM32H735xx HAL User Manual
stm32h7xx_hal_gfxmmu.c
Go to the documentation of this file.
00001 /**
00002   ******************************************************************************
00003   * @file    stm32h7xx_hal_gfxmmu.c
00004   * @author  MCD Application Team
00005   * @brief   This file provides firmware functions to manage the following 
00006   *          functionalities of the Graphic MMU (GFXMMU) peripheral:
00007   *           + Initialization and De-initialization.
00008   *           + LUT configuration.
00009   *           + Force flush and/or invalidate of cache.
00010   *           + Modify physical buffer addresses.
00011   *           + Modify cache and pre-fetch parameters.
00012   *           + Error management.
00013   *
00014   ******************************************************************************
00015   * @attention
00016   *
00017   * Copyright (c) 2017 STMicroelectronics.
00018   * All rights reserved.
00019   *
00020   * This software is licensed under terms that can be found in the LICENSE file
00021   * in the root directory of this software component.
00022   * If no LICENSE file comes with this software, it is provided AS-IS.
00023   *
00024   ******************************************************************************
00025   @verbatim
00026   ==============================================================================
00027                      ##### How to use this driver #####
00028   ==============================================================================
00029   [..]
00030     *** Initialization ***
00031     ======================
00032     [..]
00033       (#) As prerequisite, fill in the HAL_GFXMMU_MspInit() :
00034         (++) Enable GFXMMU clock interface with __HAL_RCC_GFXMMU_CLK_ENABLE().
00035         (++) If interrupts are used, enable and configure GFXMMU global
00036             interrupt with HAL_NVIC_SetPriority() and HAL_NVIC_EnableIRQ().
00037       (#) Configure the number of blocks per line, default value, physical 
00038           buffer addresses, cache and pre-fetch parameters and interrupts
00039           using the HAL_GFXMMU_Init() function.
00040 
00041     *** LUT configuration ***
00042     =========================
00043     [..]
00044       (#) Use HAL_GFXMMU_DisableLutLines() to deactivate all LUT lines (or a
00045           range of lines).
00046       (#) Use HAL_GFXMMU_ConfigLut() to copy LUT from flash to look up RAM.
00047       (#) Use HAL_GFXMMU_ConfigLutLine() to configure one line of LUT.
00048 
00049     *** Force flush and/or invalidate of cache ***
00050     ==============================================
00051     [..]    
00052       (#) Use HAL_GFXMMU_ConfigForceCache() to flush and/or invalidate cache.
00053 
00054     *** Modify physical buffer addresses ***
00055     =======================================
00056     [..]    
00057       (#) Use HAL_GFXMMU_ModifyBuffers() to modify physical buffer addresses.
00058 
00059     *** Modify cache and pre-fetch parameters ***
00060     =============================================
00061     [..]    
00062       (#) Use HAL_GFXMMU_ModifyCachePrefetch() to modify cache and pre-fetch
00063           parameters.
00064 
00065     *** Error management ***
00066     ========================
00067     [..]
00068       (#) If interrupts are used, HAL_GFXMMU_IRQHandler() will be called when
00069           an error occurs. This function will call HAL_GFXMMU_ErrorCallback().
00070           Use HAL_GFXMMU_GetError() to get the error code.
00071 
00072     *** De-initialization ***
00073     =========================
00074     [..]    
00075       (#) As prerequisite, fill in the HAL_GFXMMU_MspDeInit() :
00076         (++) Disable GFXMMU clock interface with __HAL_RCC_GFXMMU_CLK_ENABLE().
00077         (++) If interrupts has been used, disable GFXMMU global interrupt with
00078              HAL_NVIC_DisableIRQ().
00079       (#) De-initialize GFXMMU using the HAL_GFXMMU_DeInit() function.
00080 
00081     *** Callback registration ***
00082     =============================
00083 
00084     [..]
00085     The compilation define USE_HAL_GFXMMU_REGISTER_CALLBACKS when set to 1
00086     allows the user to configure dynamically the driver callbacks.
00087     Use functions HAL_GFXMMU_RegisterCallback() to register a user callback.
00088 
00089     [..]
00090     Function HAL_GFXMMU_RegisterCallback() allows to register following callbacks:
00091       (+) ErrorCallback      : GFXMMU error.
00092       (+) MspInitCallback    : GFXMMU MspInit.
00093       (+) MspDeInitCallback  : GFXMMU MspDeInit.
00094     [..]
00095     This function takes as parameters the HAL peripheral handle, the callback ID
00096     and a pointer to the user callback function.
00097 
00098     [..]
00099     Use function HAL_GFXMMU_UnRegisterCallback() to reset a callback to the default
00100     weak (surcharged) function.
00101     HAL_GFXMMU_UnRegisterCallback() takes as parameters the HAL peripheral handle,
00102     and the callback ID.
00103     [..]
00104     This function allows to reset following callbacks:
00105       (+) ErrorCallback      : GFXMMU error.
00106       (+) MspInitCallback    : GFXMMU MspInit.
00107       (+) MspDeInitCallback  : GFXMMU MspDeInit.
00108 
00109     [..]
00110     By default, after the HAL_GFXMMU_Init and if the state is HAL_GFXMMU_STATE_RESET
00111     all callbacks are reset to the corresponding legacy weak (surcharged) functions:
00112     examples HAL_GFXMMU_ErrorCallback().
00113     Exception done for MspInit and MspDeInit callbacks that are respectively
00114     reset to the legacy weak (surcharged) functions in the HAL_GFXMMU_Init
00115     and HAL_GFXMMU_DeInit only when these callbacks are null (not registered beforehand).
00116     If not, MspInit or MspDeInit are not null, the HAL_GFXMMU_Init and HAL_GFXMMU_DeInit
00117     keep and use the user MspInit/MspDeInit callbacks (registered beforehand).
00118 
00119     [..]
00120     Callbacks can be registered/unregistered in READY state only.
00121     Exception done for MspInit/MspDeInit callbacks that can be registered/unregistered
00122     in READY or RESET state, thus registered (user) MspInit/DeInit callbacks can be used
00123     during the Init/DeInit.
00124     In that case first register the MspInit/MspDeInit user callbacks
00125     using HAL_GFXMMU_RegisterCallback before calling HAL_GFXMMU_DeInit
00126     or HAL_GFXMMU_Init function.
00127 
00128     [..]
00129     When the compilation define USE_HAL_GFXMMU_REGISTER_CALLBACKS is set to 0 or
00130     not defined, the callback registering feature is not available
00131     and weak (surcharged) callbacks are used.
00132 
00133   @endverbatim
00134   ******************************************************************************
00135   */
00136 
00137 /* Includes ------------------------------------------------------------------*/
00138 #include "stm32h7xx_hal.h"
00139 
00140 /** @addtogroup STM32H7xx_HAL_Driver
00141   * @{
00142   */
00143 #ifdef HAL_GFXMMU_MODULE_ENABLED
00144 #if defined(GFXMMU)
00145 /** @defgroup GFXMMU GFXMMU
00146   * @brief GFXMMU HAL driver module
00147   * @{
00148   */
00149 
00150 /* Private typedef -----------------------------------------------------------*/
00151 /* Private define ------------------------------------------------------------*/
00152 #define GFXMMU_LUTXL_FVB_OFFSET     8U
00153 #define GFXMMU_LUTXL_LVB_OFFSET     16U
00154 #define GFXMMU_CR_ITS_MASK          0x1FU
00155 /* Private macro -------------------------------------------------------------*/
00156 /* Private variables ---------------------------------------------------------*/
00157 /* Private function prototypes -----------------------------------------------*/
00158 /* Exported functions --------------------------------------------------------*/
00159 /** @defgroup GFXMMU_Exported_Functions GFXMMU Exported Functions
00160   * @{
00161   */
00162 
00163 /** @defgroup GFXMMU_Exported_Functions_Group1 Initialization and de-initialization functions
00164  *  @brief    Initialization and de-initialization functions 
00165  *
00166 @verbatim
00167   ==============================================================================
00168           ##### Initialization and de-initialization functions #####
00169   ==============================================================================
00170     [..]  This section provides functions allowing to:
00171       (+) Initialize the GFXMMU.
00172       (+) De-initialize the GFXMMU.
00173 @endverbatim
00174   * @{
00175   */
00176 
00177 /**
00178   * @brief  Initialize the GFXMMU according to the specified parameters in the
00179   *         GFXMMU_InitTypeDef structure and initialize the associated handle.
00180   * @param  hgfxmmu GFXMMU handle.
00181   * @retval HAL status.
00182   */
00183 HAL_StatusTypeDef HAL_GFXMMU_Init(GFXMMU_HandleTypeDef *hgfxmmu)
00184 {
00185   HAL_StatusTypeDef status = HAL_OK;
00186   
00187   /* Check GFXMMU handle */
00188   if(hgfxmmu == NULL)
00189   {
00190     status = HAL_ERROR;
00191   }
00192   else
00193   {
00194     /* Check parameters */
00195     assert_param(IS_GFXMMU_ALL_INSTANCE(hgfxmmu->Instance));
00196     assert_param(IS_GFXMMU_BLOCKS_PER_LINE(hgfxmmu->Init.BlocksPerLine));
00197     assert_param(IS_GFXMMU_BUFFER_ADDRESS(hgfxmmu->Init.Buffers.Buf0Address));
00198     assert_param(IS_GFXMMU_BUFFER_ADDRESS(hgfxmmu->Init.Buffers.Buf1Address));
00199     assert_param(IS_GFXMMU_BUFFER_ADDRESS(hgfxmmu->Init.Buffers.Buf2Address));
00200     assert_param(IS_GFXMMU_BUFFER_ADDRESS(hgfxmmu->Init.Buffers.Buf3Address));
00201     assert_param(IS_FUNCTIONAL_STATE(hgfxmmu->Init.CachePrefetch.Activation));
00202     assert_param(IS_FUNCTIONAL_STATE(hgfxmmu->Init.Interrupts.Activation));
00203     
00204 #if (USE_HAL_GFXMMU_REGISTER_CALLBACKS == 1)
00205     /* Reset callback pointers to the weak predefined callbacks */
00206     hgfxmmu->ErrorCallback = HAL_GFXMMU_ErrorCallback;
00207 
00208     /* Call GFXMMU MSP init function */
00209     if(hgfxmmu->MspInitCallback == NULL)
00210     {
00211       hgfxmmu->MspInitCallback = HAL_GFXMMU_MspInit;
00212     }
00213     hgfxmmu->MspInitCallback(hgfxmmu);
00214 #else
00215     /* Call GFXMMU MSP init function */
00216     HAL_GFXMMU_MspInit(hgfxmmu);
00217 #endif
00218     
00219     /* Configure blocks per line, cache and interrupts parameters on GFXMMU_CR register */
00220     hgfxmmu->Instance->CR &= ~(GFXMMU_CR_B0OIE | GFXMMU_CR_B1OIE | GFXMMU_CR_B2OIE | GFXMMU_CR_B3OIE |
00221                                GFXMMU_CR_AMEIE | GFXMMU_CR_192BM | GFXMMU_CR_CE    | GFXMMU_CR_CL    |
00222                                GFXMMU_CR_CLB   | GFXMMU_CR_FC    | GFXMMU_CR_PD    | GFXMMU_CR_OC    |
00223                                GFXMMU_CR_OB);
00224     hgfxmmu->Instance->CR |= (hgfxmmu->Init.BlocksPerLine);
00225     if(hgfxmmu->Init.CachePrefetch.Activation == ENABLE)
00226     {
00227       assert_param(IS_GFXMMU_CACHE_LOCK(hgfxmmu->Init.CachePrefetch.CacheLock));
00228       assert_param(IS_GFXMMU_PREFETCH(hgfxmmu->Init.CachePrefetch.Prefetch));
00229       assert_param(IS_GFXMMU_OUTTER_BUFFERABILITY(hgfxmmu->Init.CachePrefetch.OutterBufferability));
00230       assert_param(IS_GFXMMU_OUTTER_CACHABILITY(hgfxmmu->Init.CachePrefetch.OutterCachability));
00231       hgfxmmu->Instance->CR |= (GFXMMU_CR_CE |
00232                                 hgfxmmu->Init.CachePrefetch.CacheLock |
00233                                 hgfxmmu->Init.CachePrefetch.Prefetch |
00234                                 hgfxmmu->Init.CachePrefetch.OutterBufferability |
00235                                 hgfxmmu->Init.CachePrefetch.OutterCachability);
00236       if(hgfxmmu->Init.CachePrefetch.CacheLock == GFXMMU_CACHE_LOCK_ENABLE)
00237       {
00238         assert_param(IS_GFXMMU_CACHE_LOCK_BUFFER(hgfxmmu->Init.CachePrefetch.CacheLockBuffer));
00239         assert_param(IS_GFXMMU_CACHE_FORCE(hgfxmmu->Init.CachePrefetch.CacheForce));
00240         hgfxmmu->Instance->CR |= (hgfxmmu->Init.CachePrefetch.CacheLockBuffer | 
00241                                   hgfxmmu->Init.CachePrefetch.CacheForce);
00242       }
00243     }
00244     if(hgfxmmu->Init.Interrupts.Activation == ENABLE)
00245     {
00246       assert_param(IS_GFXMMU_INTERRUPTS(hgfxmmu->Init.Interrupts.UsedInterrupts));
00247       hgfxmmu->Instance->CR |= hgfxmmu->Init.Interrupts.UsedInterrupts;
00248     }
00249     
00250     /* Configure default value on GFXMMU_DVR register */
00251     hgfxmmu->Instance->DVR = hgfxmmu->Init.DefaultValue;
00252     
00253     /* Configure physical buffer addresses on GFXMMU_BxCR registers */
00254     hgfxmmu->Instance->B0CR = hgfxmmu->Init.Buffers.Buf0Address;
00255     hgfxmmu->Instance->B1CR = hgfxmmu->Init.Buffers.Buf1Address;
00256     hgfxmmu->Instance->B2CR = hgfxmmu->Init.Buffers.Buf2Address;
00257     hgfxmmu->Instance->B3CR = hgfxmmu->Init.Buffers.Buf3Address;
00258     
00259     /* Force invalidate cache if cache is enabled */
00260     if(hgfxmmu->Init.CachePrefetch.Activation == ENABLE)
00261     {
00262       hgfxmmu->Instance->CCR |= GFXMMU_CACHE_FORCE_INVALIDATE;
00263     }
00264     
00265     /* Reset GFXMMU error code */
00266     hgfxmmu->ErrorCode = GFXMMU_ERROR_NONE;
00267     
00268     /* Set GFXMMU to ready state */
00269     hgfxmmu->State = HAL_GFXMMU_STATE_READY;
00270   }
00271   /* Return function status */
00272   return status;
00273 }
00274 
00275 /**
00276   * @brief  De-initialize the GFXMMU.
00277   * @param  hgfxmmu GFXMMU handle.
00278   * @retval HAL status.
00279   */
00280 HAL_StatusTypeDef HAL_GFXMMU_DeInit(GFXMMU_HandleTypeDef *hgfxmmu)
00281 {
00282   HAL_StatusTypeDef status = HAL_OK;
00283   
00284   /* Check GFXMMU handle */
00285   if(hgfxmmu == NULL)
00286   {
00287     status = HAL_ERROR;
00288   }
00289   else
00290   {
00291     /* Check parameters */
00292     assert_param(IS_GFXMMU_ALL_INSTANCE(hgfxmmu->Instance));
00293     
00294     /* Disable all interrupts on GFXMMU_CR register */
00295     hgfxmmu->Instance->CR &= ~(GFXMMU_CR_B0OIE | GFXMMU_CR_B1OIE | GFXMMU_CR_B2OIE | GFXMMU_CR_B3OIE |
00296                                GFXMMU_CR_AMEIE);
00297     
00298     /* Call GFXMMU MSP de-init function */
00299 #if (USE_HAL_GFXMMU_REGISTER_CALLBACKS == 1)
00300     if(hgfxmmu->MspDeInitCallback == NULL)
00301     {
00302       hgfxmmu->MspDeInitCallback = HAL_GFXMMU_MspDeInit;
00303     }
00304     hgfxmmu->MspDeInitCallback(hgfxmmu);
00305 #else
00306     HAL_GFXMMU_MspDeInit(hgfxmmu);
00307 #endif
00308     
00309     /* Set GFXMMU to reset state */
00310     hgfxmmu->State = HAL_GFXMMU_STATE_RESET;
00311   }
00312   /* Return function status */
00313   return status;
00314 }
00315 
00316 /**
00317   * @brief  Initialize the GFXMMU MSP.
00318   * @param  hgfxmmu GFXMMU handle.
00319   * @retval None.
00320   */
00321 __weak void HAL_GFXMMU_MspInit(GFXMMU_HandleTypeDef *hgfxmmu)
00322 {
00323   /* Prevent unused argument(s) compilation warning */
00324   UNUSED(hgfxmmu);
00325   
00326   /* NOTE : This function should not be modified, when the function is needed,
00327             the HAL_GFXMMU_MspInit could be implemented in the user file.
00328    */
00329 }
00330 
00331 /**
00332   * @brief  De-initialize the GFXMMU MSP.
00333   * @param  hgfxmmu GFXMMU handle.
00334   * @retval None.
00335   */
00336 __weak void HAL_GFXMMU_MspDeInit(GFXMMU_HandleTypeDef *hgfxmmu)
00337 {
00338   /* Prevent unused argument(s) compilation warning */
00339   UNUSED(hgfxmmu);
00340   
00341   /* NOTE : This function should not be modified, when the function is needed,
00342             the HAL_GFXMMU_MspDeInit could be implemented in the user file.
00343    */
00344 }
00345 
00346 #if (USE_HAL_GFXMMU_REGISTER_CALLBACKS == 1)
00347 /**
00348   * @brief  Register a user GFXMMU callback
00349   *         to be used instead of the weak predefined callback.
00350   * @param  hgfxmmu GFXMMU handle.
00351   * @param  CallbackID ID of the callback to be registered.
00352   *         This parameter can be one of the following values:
00353   *           @arg @ref HAL_GFXMMU_ERROR_CB_ID error callback ID.
00354   *           @arg @ref HAL_GFXMMU_MSPINIT_CB_ID MSP init callback ID.
00355   *           @arg @ref HAL_GFXMMU_MSPDEINIT_CB_ID MSP de-init callback ID.
00356   * @param  pCallback pointer to the callback function.
00357   * @retval HAL status.
00358   */
00359 HAL_StatusTypeDef HAL_GFXMMU_RegisterCallback(GFXMMU_HandleTypeDef        *hgfxmmu,
00360                                               HAL_GFXMMU_CallbackIDTypeDef CallbackID,
00361                                               pGFXMMU_CallbackTypeDef      pCallback)
00362 {
00363   HAL_StatusTypeDef status = HAL_OK;
00364 
00365   if(pCallback == NULL)
00366   {
00367     /* update the error code */
00368     hgfxmmu->ErrorCode |= GFXMMU_ERROR_INVALID_CALLBACK;
00369     /* update return status */
00370     status = HAL_ERROR;
00371   }
00372   else
00373   {
00374     if(HAL_GFXMMU_STATE_READY == hgfxmmu->State)
00375     {
00376       switch (CallbackID)
00377       {
00378       case HAL_GFXMMU_ERROR_CB_ID :
00379         hgfxmmu->ErrorCallback = pCallback;
00380         break;
00381       case HAL_GFXMMU_MSPINIT_CB_ID :
00382         hgfxmmu->MspInitCallback = pCallback;
00383         break;
00384       case HAL_GFXMMU_MSPDEINIT_CB_ID :
00385         hgfxmmu->MspDeInitCallback = pCallback;
00386         break;
00387       default :
00388         /* update the error code */
00389         hgfxmmu->ErrorCode |= GFXMMU_ERROR_INVALID_CALLBACK;
00390         /* update return status */
00391         status = HAL_ERROR;
00392         break;
00393       }
00394     }
00395     else if(HAL_GFXMMU_STATE_RESET == hgfxmmu->State)
00396     {
00397       switch (CallbackID)
00398       {
00399       case HAL_GFXMMU_MSPINIT_CB_ID :
00400         hgfxmmu->MspInitCallback = pCallback;
00401         break;
00402       case HAL_GFXMMU_MSPDEINIT_CB_ID :
00403         hgfxmmu->MspDeInitCallback = pCallback;
00404         break;
00405       default :
00406         /* update the error code */
00407         hgfxmmu->ErrorCode |= GFXMMU_ERROR_INVALID_CALLBACK;
00408         /* update return status */
00409         status = HAL_ERROR;
00410         break;
00411       }
00412     }
00413     else
00414     {
00415       /* update the error code */
00416       hgfxmmu->ErrorCode |= GFXMMU_ERROR_INVALID_CALLBACK;
00417       /* update return status */
00418       status = HAL_ERROR;
00419     }
00420   }
00421   return status;
00422 }
00423 
00424 /**
00425   * @brief  Unregister a user GFXMMU callback.
00426   *         GFXMMU callback is redirected to the weak predefined callback.
00427   * @param  hgfxmmu GFXMMU handle.
00428   * @param  CallbackID ID of the callback to be unregistered.
00429   *         This parameter can be one of the following values:
00430   *           @arg @ref HAL_GFXMMU_ERROR_CB_ID error callback ID.
00431   *           @arg @ref HAL_GFXMMU_MSPINIT_CB_ID MSP init callback ID.
00432   *           @arg @ref HAL_GFXMMU_MSPDEINIT_CB_ID MSP de-init callback ID.
00433   * @retval HAL status.
00434   */
00435 HAL_StatusTypeDef HAL_GFXMMU_UnRegisterCallback(GFXMMU_HandleTypeDef        *hgfxmmu,
00436                                                 HAL_GFXMMU_CallbackIDTypeDef CallbackID)
00437 {
00438   HAL_StatusTypeDef status = HAL_OK;
00439 
00440   if(HAL_GFXMMU_STATE_READY == hgfxmmu->State)
00441   {
00442     switch (CallbackID)
00443     {
00444     case HAL_GFXMMU_ERROR_CB_ID :
00445       hgfxmmu->ErrorCallback = HAL_GFXMMU_ErrorCallback;
00446       break;
00447     case HAL_GFXMMU_MSPINIT_CB_ID :
00448       hgfxmmu->MspInitCallback = HAL_GFXMMU_MspInit;
00449       break;
00450     case HAL_GFXMMU_MSPDEINIT_CB_ID :
00451       hgfxmmu->MspDeInitCallback = HAL_GFXMMU_MspDeInit;
00452       break;
00453     default :
00454       /* update the error code */
00455       hgfxmmu->ErrorCode |= GFXMMU_ERROR_INVALID_CALLBACK;
00456       /* update return status */
00457       status = HAL_ERROR;
00458       break;
00459     }
00460   }
00461   else if(HAL_GFXMMU_STATE_RESET == hgfxmmu->State)
00462   {
00463     switch (CallbackID)
00464     {
00465     case HAL_GFXMMU_MSPINIT_CB_ID :
00466       hgfxmmu->MspInitCallback = HAL_GFXMMU_MspInit;
00467       break;
00468     case HAL_GFXMMU_MSPDEINIT_CB_ID :
00469       hgfxmmu->MspDeInitCallback = HAL_GFXMMU_MspDeInit;
00470       break;
00471     default :
00472       /* update the error code */
00473       hgfxmmu->ErrorCode |= GFXMMU_ERROR_INVALID_CALLBACK;
00474       /* update return status */
00475       status = HAL_ERROR;
00476       break;
00477     }
00478   }
00479   else
00480   {
00481     /* update the error code */
00482     hgfxmmu->ErrorCode |= GFXMMU_ERROR_INVALID_CALLBACK;
00483     /* update return status */
00484     status = HAL_ERROR;
00485   }
00486   return status;
00487 }
00488 #endif /* USE_HAL_GFXMMU_REGISTER_CALLBACKS */
00489 
00490 /**
00491   * @}
00492   */
00493 
00494 /** @defgroup GFXMMU_Exported_Functions_Group2 Operations functions
00495  *  @brief    GFXMMU operation functions
00496  *
00497 @verbatim
00498   ==============================================================================
00499                       ##### Operation functions #####
00500   ==============================================================================
00501     [..]  This section provides functions allowing to:
00502       (+) Configure LUT.
00503       (+) Force flush and/or invalidate of cache.
00504       (+) Modify physical buffer addresses.
00505       (+) Modify cache and pre-fetch parameters.
00506       (+) Manage error.
00507 @endverbatim
00508   * @{
00509   */
00510 
00511 /**
00512   * @brief  This function allows to copy LUT from flash to look up RAM.
00513   * @param  hgfxmmu GFXMMU handle.
00514   * @param  FirstLine First line enabled on LUT.
00515   *         This parameter must be a number between Min_Data = 0 and Max_Data = 1023.
00516   * @param  LinesNumber Number of lines enabled on LUT.
00517   *         This parameter must be a number between Min_Data = 1 and Max_Data = 1024.
00518   * @param  Address Start address of LUT in flash.
00519   * @retval HAL status.
00520   */
00521 HAL_StatusTypeDef HAL_GFXMMU_ConfigLut(GFXMMU_HandleTypeDef *hgfxmmu,
00522                                        uint32_t FirstLine,
00523                                        uint32_t LinesNumber,
00524                                        uint32_t Address)
00525 {
00526   HAL_StatusTypeDef status = HAL_OK;
00527   
00528   /* Check parameters */
00529   assert_param(IS_GFXMMU_ALL_INSTANCE(hgfxmmu->Instance));
00530   assert_param(IS_GFXMMU_LUT_LINE(FirstLine));
00531   assert_param(IS_GFXMMU_LUT_LINES_NUMBER(LinesNumber));
00532   
00533   /* Check GFXMMU state and coherent parameters */
00534   if((hgfxmmu->State != HAL_GFXMMU_STATE_READY) || ((FirstLine + LinesNumber) > 1024U))
00535   {
00536     status = HAL_ERROR;
00537   }
00538   else
00539   {
00540     uint32_t current_address, current_line, lutxl_address, lutxh_address;
00541     
00542     /* Initialize local variables */
00543     current_address = Address;
00544     current_line    = 0U;
00545     lutxl_address   = (uint32_t) &(hgfxmmu->Instance->LUT[2U * FirstLine]);
00546     lutxh_address   = (uint32_t) &(hgfxmmu->Instance->LUT[(2U * FirstLine) + 1U]);
00547     
00548     /* Copy LUT from flash to look up RAM */
00549     while(current_line < LinesNumber)
00550     {
00551       *((uint32_t *)lutxl_address) = *((uint32_t *)current_address);
00552       current_address += 4U;
00553       *((uint32_t *)lutxh_address) = *((uint32_t *)current_address);
00554       current_address += 4U;
00555       lutxl_address += 8U;
00556       lutxh_address += 8U;
00557       current_line++;
00558     }
00559   }
00560   /* Return function status */
00561   return status;
00562 }
00563 
00564 /**
00565   * @brief  This function allows to disable a range of LUT lines.
00566   * @param  hgfxmmu GFXMMU handle.
00567   * @param  FirstLine First line to disable on LUT.
00568   *         This parameter must be a number between Min_Data = 0 and Max_Data = 1023.
00569   * @param  LinesNumber Number of lines to disable on LUT.
00570   *         This parameter must be a number between Min_Data = 1 and Max_Data = 1024.
00571   * @retval HAL status.
00572   */
00573 HAL_StatusTypeDef HAL_GFXMMU_DisableLutLines(GFXMMU_HandleTypeDef *hgfxmmu,
00574                                              uint32_t FirstLine,
00575                                              uint32_t LinesNumber)
00576 {
00577   HAL_StatusTypeDef status = HAL_OK;
00578   
00579   /* Check parameters */
00580   assert_param(IS_GFXMMU_ALL_INSTANCE(hgfxmmu->Instance));
00581   assert_param(IS_GFXMMU_LUT_LINE(FirstLine));
00582   assert_param(IS_GFXMMU_LUT_LINES_NUMBER(LinesNumber));
00583   
00584   /* Check GFXMMU state and coherent parameters */
00585   if((hgfxmmu->State != HAL_GFXMMU_STATE_READY) || ((FirstLine + LinesNumber) > 1024U))
00586   {
00587     status = HAL_ERROR;
00588   }
00589   else
00590   {
00591     uint32_t current_line, lutxl_address, lutxh_address;
00592     
00593     /* Initialize local variables */
00594     current_line    = 0U;
00595     lutxl_address   = (uint32_t) &(hgfxmmu->Instance->LUT[2U * FirstLine]);
00596     lutxh_address   = (uint32_t) &(hgfxmmu->Instance->LUT[(2U * FirstLine) + 1U]);
00597     
00598     /* Disable LUT lines */
00599     while(current_line < LinesNumber)
00600     {
00601       *((uint32_t *)lutxl_address) = 0U;
00602       *((uint32_t *)lutxh_address) = 0U;
00603       lutxl_address += 8U;
00604       lutxh_address += 8U;
00605       current_line++;
00606     }
00607   }
00608   /* Return function status */
00609   return status;
00610 }
00611 
00612 /**
00613   * @brief  This function allows to configure one line of LUT.
00614   * @param  hgfxmmu GFXMMU handle.
00615   * @param  lutLine LUT line parameters.
00616   * @retval HAL status.
00617   */
00618 HAL_StatusTypeDef HAL_GFXMMU_ConfigLutLine(GFXMMU_HandleTypeDef *hgfxmmu, GFXMMU_LutLineTypeDef *lutLine)
00619 {
00620   HAL_StatusTypeDef status = HAL_OK;
00621   
00622   /* Check parameters */
00623   assert_param(IS_GFXMMU_ALL_INSTANCE(hgfxmmu->Instance));
00624   assert_param(IS_GFXMMU_LUT_LINE(lutLine->LineNumber));
00625   assert_param(IS_GFXMMU_LUT_LINE_STATUS(lutLine->LineStatus));
00626   assert_param(IS_GFXMMU_LUT_BLOCK(lutLine->FirstVisibleBlock));
00627   assert_param(IS_GFXMMU_LUT_BLOCK(lutLine->LastVisibleBlock));
00628   assert_param(IS_GFXMMU_LUT_LINE_OFFSET(lutLine->LineOffset));
00629   
00630   /* Check GFXMMU state */
00631   if(hgfxmmu->State != HAL_GFXMMU_STATE_READY)
00632   {
00633     status = HAL_ERROR;
00634   }
00635   else
00636   {
00637     uint32_t lutxl_address, lutxh_address;
00638     
00639     /* Initialize local variables */
00640     lutxl_address   = (uint32_t) &(hgfxmmu->Instance->LUT[2U * lutLine->LineNumber]);
00641     lutxh_address   = (uint32_t) &(hgfxmmu->Instance->LUT[(2U * lutLine->LineNumber) + 1U]);
00642     
00643     /* Configure LUT line */
00644     if(lutLine->LineStatus == GFXMMU_LUT_LINE_ENABLE)
00645     {
00646       /* Enable and configure LUT line */
00647       *((uint32_t *)lutxl_address) = (lutLine->LineStatus | 
00648                                      (lutLine->FirstVisibleBlock << GFXMMU_LUTXL_FVB_OFFSET) | 
00649                                      (lutLine->LastVisibleBlock << GFXMMU_LUTXL_LVB_OFFSET));
00650       *((uint32_t *)lutxh_address) = (uint32_t) lutLine->LineOffset;
00651     }
00652     else
00653     {
00654       /* Disable LUT line */
00655       *((uint32_t *)lutxl_address) = 0U;
00656       *((uint32_t *)lutxh_address) = 0U;
00657     }
00658   }
00659   /* Return function status */
00660   return status;
00661 }
00662 
00663 /**
00664   * @brief  This function allows to force flush and/or invalidate of cache.
00665   * @param  hgfxmmu GFXMMU handle.
00666   * @param  ForceParam Force cache parameter.
00667   *         This parameter can be a values combination of @ref GFXMMU_CacheForceParam.
00668   * @retval HAL status.
00669   */
00670 HAL_StatusTypeDef HAL_GFXMMU_ConfigForceCache(GFXMMU_HandleTypeDef *hgfxmmu, uint32_t ForceParam)
00671 {
00672   HAL_StatusTypeDef status = HAL_OK;
00673   
00674   /* Check parameters */
00675   assert_param(IS_GFXMMU_ALL_INSTANCE(hgfxmmu->Instance));
00676   assert_param(IS_GFXMMU_CACHE_FORCE_ACTION(ForceParam));
00677   
00678   /* Check GFXMMU state and cache status */
00679   if(((hgfxmmu->Instance->CR & GFXMMU_CR_CE) != GFXMMU_CR_CE) || (hgfxmmu->State != HAL_GFXMMU_STATE_READY))
00680   {
00681     status = HAL_ERROR;
00682   }
00683   else
00684   {
00685     /* Force flush and/or invalidate cache on GFXMMU_CCR register */
00686     hgfxmmu->Instance->CCR |= ForceParam;
00687   }
00688   /* Return function status */
00689   return status;
00690 }
00691 
00692 /**
00693   * @brief  This function allows to modify physical buffer addresses.
00694   * @param  hgfxmmu GFXMMU handle.
00695   * @param  Buffers Buffers parameters.
00696   * @retval HAL status.
00697   */
00698 HAL_StatusTypeDef HAL_GFXMMU_ModifyBuffers(GFXMMU_HandleTypeDef *hgfxmmu, GFXMMU_BuffersTypeDef *Buffers)
00699 {
00700   HAL_StatusTypeDef status = HAL_OK;
00701   
00702   /* Check parameters */
00703   assert_param(IS_GFXMMU_ALL_INSTANCE(hgfxmmu->Instance));
00704   assert_param(IS_GFXMMU_BUFFER_ADDRESS(Buffers->Buf0Address));
00705   assert_param(IS_GFXMMU_BUFFER_ADDRESS(Buffers->Buf1Address));
00706   assert_param(IS_GFXMMU_BUFFER_ADDRESS(Buffers->Buf2Address));
00707   assert_param(IS_GFXMMU_BUFFER_ADDRESS(Buffers->Buf3Address));
00708   
00709   /* Check GFXMMU state */
00710   if(hgfxmmu->State != HAL_GFXMMU_STATE_READY)
00711   {
00712     status = HAL_ERROR;
00713   }
00714   else
00715   {
00716     /* Modify physical buffer addresses on GFXMMU_BxCR registers */
00717     hgfxmmu->Instance->B0CR = Buffers->Buf0Address;
00718     hgfxmmu->Instance->B1CR = Buffers->Buf1Address;
00719     hgfxmmu->Instance->B2CR = Buffers->Buf2Address;
00720     hgfxmmu->Instance->B3CR = Buffers->Buf3Address;
00721   }
00722   /* Return function status */
00723   return status;
00724 }
00725 
00726 /**
00727   * @brief  This function allows to modify cache and pre-fetch parameters.
00728   * @param  hgfxmmu GFXMMU handle.
00729   * @param  CachePrefetch Cache and pre-fetch parameters.
00730   * @retval HAL status.
00731   */
00732 HAL_StatusTypeDef HAL_GFXMMU_ModifyCachePrefetch(GFXMMU_HandleTypeDef *hgfxmmu,
00733                                                  GFXMMU_CachePrefetchTypeDef *CachePrefetch)
00734 {
00735   HAL_StatusTypeDef status = HAL_OK;
00736   assert_param(IS_FUNCTIONAL_STATE(CachePrefetch->Activation));
00737   
00738   /* Check parameters */
00739   assert_param(IS_GFXMMU_ALL_INSTANCE(hgfxmmu->Instance));
00740   
00741   /* Check GFXMMU state */
00742   if(hgfxmmu->State != HAL_GFXMMU_STATE_READY)
00743   {
00744     status = HAL_ERROR;
00745   }
00746   else
00747   {
00748     /* Modify cache and pre-fetch parameters on GFXMMU_CR register */
00749     hgfxmmu->Instance->CR &= ~(GFXMMU_CR_CE | GFXMMU_CR_CL | GFXMMU_CR_CLB | GFXMMU_CR_FC |
00750                                GFXMMU_CR_PD | GFXMMU_CR_OC | GFXMMU_CR_OB);
00751     if(CachePrefetch->Activation == ENABLE)
00752     {
00753       assert_param(IS_GFXMMU_CACHE_LOCK(CachePrefetch->CacheLock));
00754       assert_param(IS_GFXMMU_PREFETCH(CachePrefetch->Prefetch));
00755       assert_param(IS_GFXMMU_OUTTER_BUFFERABILITY(CachePrefetch->OutterBufferability));
00756       assert_param(IS_GFXMMU_OUTTER_CACHABILITY(CachePrefetch->OutterCachability));
00757       hgfxmmu->Instance->CR |= (GFXMMU_CR_CE |
00758                                 CachePrefetch->CacheLock |
00759                                 CachePrefetch->Prefetch |
00760                                 CachePrefetch->OutterBufferability |
00761                                 CachePrefetch->OutterCachability);
00762       if(CachePrefetch->CacheLock == GFXMMU_CACHE_LOCK_ENABLE)
00763       {
00764         assert_param(IS_GFXMMU_CACHE_LOCK_BUFFER(CachePrefetch->CacheLockBuffer));
00765         assert_param(IS_GFXMMU_CACHE_FORCE(CachePrefetch->CacheForce));
00766         hgfxmmu->Instance->CR |= (CachePrefetch->CacheLockBuffer |
00767                                   CachePrefetch->CacheForce);
00768       }
00769     }
00770   }
00771   /* Return function status */
00772   return status;
00773 }
00774 
00775 /**
00776   * @brief  This function handles the GFXMMU interrupts.
00777   * @param  hgfxmmu GFXMMU handle.
00778   * @retval None.
00779   */
00780 void HAL_GFXMMU_IRQHandler(GFXMMU_HandleTypeDef *hgfxmmu)
00781 {
00782   uint32_t flags, interrupts, error;
00783   
00784   /* Read current flags and interrupts and determine which error occurs */
00785   flags = hgfxmmu->Instance->SR;
00786   interrupts = (hgfxmmu->Instance->CR & GFXMMU_CR_ITS_MASK);
00787   error = (flags & interrupts);
00788   
00789   if(error != 0U)
00790   {
00791     /* Clear flags on GFXMMU_FCR register */
00792     hgfxmmu->Instance->FCR = error;
00793     
00794     /* Update GFXMMU error code */
00795     hgfxmmu->ErrorCode |= error;
00796     
00797     /* Call GFXMMU error callback */
00798 #if (USE_HAL_GFXMMU_REGISTER_CALLBACKS == 1)
00799     hgfxmmu->ErrorCallback(hgfxmmu);
00800 #else
00801     HAL_GFXMMU_ErrorCallback(hgfxmmu);
00802 #endif
00803   }
00804 }
00805 
00806 /**
00807   * @brief  Error callback. 
00808   * @param  hgfxmmu GFXMMU handle.
00809   * @retval None.
00810   */
00811 __weak void HAL_GFXMMU_ErrorCallback(GFXMMU_HandleTypeDef *hgfxmmu)
00812 {
00813   /* Prevent unused argument(s) compilation warning */
00814   UNUSED(hgfxmmu);
00815   
00816   /* NOTE : This function should not be modified, when the callback is needed,
00817             the HAL_GFXMMU_ErrorCallback could be implemented in the user file.
00818    */
00819 }
00820 
00821 /**
00822   * @}
00823   */
00824 
00825 /** @defgroup GFXMMU_Exported_Functions_Group3 State functions
00826  *  @brief    GFXMMU state functions
00827  *
00828 @verbatim
00829   ==============================================================================
00830                          ##### State functions #####
00831   ==============================================================================
00832     [..]  This section provides functions allowing to:
00833       (+) Get GFXMMU handle state.
00834       (+) Get GFXMMU error code.
00835 @endverbatim
00836   * @{
00837   */
00838 
00839 /**
00840   * @brief  This function allows to get the current GFXMMU handle state.
00841   * @param  hgfxmmu GFXMMU handle.
00842   * @retval GFXMMU state.
00843   */
00844 HAL_GFXMMU_StateTypeDef HAL_GFXMMU_GetState(GFXMMU_HandleTypeDef *hgfxmmu)
00845 {
00846   /* Return GFXMMU handle state */
00847   return hgfxmmu->State;
00848 }
00849 
00850 /**
00851   * @brief  This function allows to get the current GFXMMU error code.
00852   * @param  hgfxmmu GFXMMU handle.
00853   * @retval GFXMMU error code.
00854   */
00855 uint32_t HAL_GFXMMU_GetError(GFXMMU_HandleTypeDef *hgfxmmu)
00856 {
00857   uint32_t error_code;
00858   
00859   /* Enter in critical section */
00860   __disable_irq();  
00861   
00862   /* Store and reset GFXMMU error code */
00863   error_code = hgfxmmu->ErrorCode;
00864   hgfxmmu->ErrorCode = GFXMMU_ERROR_NONE;
00865   
00866   /* Exit from critical section */
00867   __enable_irq();
00868   
00869   /* Return GFXMMU error code */
00870   return error_code;
00871 }
00872 
00873 /**
00874   * @}
00875   */
00876 
00877 /**
00878   * @}
00879   */
00880 /* End of exported functions -------------------------------------------------*/
00881 /* Private functions ---------------------------------------------------------*/
00882 /* End of private functions --------------------------------------------------*/
00883 
00884 /**
00885   * @}
00886   */
00887 #endif /* GFXMMU */
00888 #endif /* HAL_GFXMMU_MODULE_ENABLED */
00889 /**
00890   * @}
00891   */
00892