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