1 /**
2   ******************************************************************************
3   * @file    stm32h7xx_hal_gfxmmu.c
4   * @author  MCD Application Team
5   * @brief   This file provides firmware functions to manage the following
6   *          functionalities of the Graphic MMU (GFXMMU) peripheral:
7   *           + Initialization and De-initialization.
8   *           + LUT configuration.
9   *           + Force flush and/or invalidate of cache.
10   *           + Modify physical buffer addresses.
11   *           + Modify cache and pre-fetch parameters.
12   *           + Error management.
13   *
14   ******************************************************************************
15   * @attention
16   *
17   * Copyright (c) 2017 STMicroelectronics.
18   * All rights reserved.
19   *
20   * This software is licensed under terms that can be found in the LICENSE file
21   * in the root directory of this software component.
22   * If no LICENSE file comes with this software, it is provided AS-IS.
23   *
24   ******************************************************************************
25   @verbatim
26   ==============================================================================
27                      ##### How to use this driver #####
28   ==============================================================================
29   [..]
30     *** Initialization ***
31     ======================
32     [..]
33       (#) As prerequisite, fill in the HAL_GFXMMU_MspInit() :
34         (++) Enable GFXMMU clock interface with __HAL_RCC_GFXMMU_CLK_ENABLE().
35         (++) If interrupts are used, enable and configure GFXMMU global
36             interrupt with HAL_NVIC_SetPriority() and HAL_NVIC_EnableIRQ().
37       (#) Configure the number of blocks per line, default value, physical
38           buffer addresses, cache and pre-fetch parameters and interrupts
39           using the HAL_GFXMMU_Init() function.
40 
41     *** LUT configuration ***
42     =========================
43     [..]
44       (#) Use HAL_GFXMMU_DisableLutLines() to deactivate all LUT lines (or a
45           range of lines).
46       (#) Use HAL_GFXMMU_ConfigLut() to copy LUT from flash to look up RAM.
47       (#) Use HAL_GFXMMU_ConfigLutLine() to configure one line of LUT.
48 
49     *** Force flush and/or invalidate of cache ***
50     ==============================================
51     [..]
52       (#) Use HAL_GFXMMU_ConfigForceCache() to flush and/or invalidate cache.
53 
54     *** Modify physical buffer addresses ***
55     =======================================
56     [..]
57       (#) Use HAL_GFXMMU_ModifyBuffers() to modify physical buffer addresses.
58 
59     *** Modify cache and pre-fetch parameters ***
60     =============================================
61     [..]
62       (#) Use HAL_GFXMMU_ModifyCachePrefetch() to modify cache and pre-fetch
63           parameters.
64 
65     *** Error management ***
66     ========================
67     [..]
68       (#) If interrupts are used, HAL_GFXMMU_IRQHandler() will be called when
69           an error occurs. This function will call HAL_GFXMMU_ErrorCallback().
70           Use HAL_GFXMMU_GetError() to get the error code.
71 
72     *** De-initialization ***
73     =========================
74     [..]
75       (#) As prerequisite, fill in the HAL_GFXMMU_MspDeInit() :
76         (++) Disable GFXMMU clock interface with __HAL_RCC_GFXMMU_CLK_ENABLE().
77         (++) If interrupts has been used, disable GFXMMU global interrupt with
78              HAL_NVIC_DisableIRQ().
79       (#) De-initialize GFXMMU using the HAL_GFXMMU_DeInit() function.
80 
81     *** Callback registration ***
82     =============================
83 
84     [..]
85     The compilation define USE_HAL_GFXMMU_REGISTER_CALLBACKS when set to 1
86     allows the user to configure dynamically the driver callbacks.
87     Use functions HAL_GFXMMU_RegisterCallback() to register a user callback.
88 
89     [..]
90     Function HAL_GFXMMU_RegisterCallback() allows to register following callbacks:
91       (+) ErrorCallback      : GFXMMU error.
92       (+) MspInitCallback    : GFXMMU MspInit.
93       (+) MspDeInitCallback  : GFXMMU MspDeInit.
94     [..]
95     This function takes as parameters the HAL peripheral handle, the callback ID
96     and a pointer to the user callback function.
97 
98     [..]
99     Use function HAL_GFXMMU_UnRegisterCallback() to reset a callback to the default
100     weak (surcharged) function.
101     HAL_GFXMMU_UnRegisterCallback() takes as parameters the HAL peripheral handle,
102     and the callback ID.
103     [..]
104     This function allows to reset following callbacks:
105       (+) ErrorCallback      : GFXMMU error.
106       (+) MspInitCallback    : GFXMMU MspInit.
107       (+) MspDeInitCallback  : GFXMMU MspDeInit.
108 
109     [..]
110     By default, after the HAL_GFXMMU_Init and if the state is HAL_GFXMMU_STATE_RESET
111     all callbacks are reset to the corresponding legacy weak (surcharged) functions:
112     examples HAL_GFXMMU_ErrorCallback().
113     Exception done for MspInit and MspDeInit callbacks that are respectively
114     reset to the legacy weak (surcharged) functions in the HAL_GFXMMU_Init
115     and HAL_GFXMMU_DeInit only when these callbacks are null (not registered beforehand).
116     If not, MspInit or MspDeInit are not null, the HAL_GFXMMU_Init and HAL_GFXMMU_DeInit
117     keep and use the user MspInit/MspDeInit callbacks (registered beforehand).
118 
119     [..]
120     Callbacks can be registered/unregistered in READY state only.
121     Exception done for MspInit/MspDeInit callbacks that can be registered/unregistered
122     in READY or RESET state, thus registered (user) MspInit/DeInit callbacks can be used
123     during the Init/DeInit.
124     In that case first register the MspInit/MspDeInit user callbacks
125     using HAL_GFXMMU_RegisterCallback before calling HAL_GFXMMU_DeInit
126     or HAL_GFXMMU_Init function.
127 
128     [..]
129     When the compilation define USE_HAL_GFXMMU_REGISTER_CALLBACKS is set to 0 or
130     not defined, the callback registering feature is not available
131     and weak (surcharged) callbacks are used.
132 
133   @endverbatim
134   ******************************************************************************
135   */
136 
137 /* Includes ------------------------------------------------------------------*/
138 #include "stm32h7xx_hal.h"
139 
140 /** @addtogroup STM32H7xx_HAL_Driver
141   * @{
142   */
143 #ifdef HAL_GFXMMU_MODULE_ENABLED
144 #if defined(GFXMMU)
145 /** @defgroup GFXMMU GFXMMU
146   * @brief GFXMMU HAL driver module
147   * @{
148   */
149 
150 /* Private typedef -----------------------------------------------------------*/
151 /* Private define ------------------------------------------------------------*/
152 #define GFXMMU_LUTXL_FVB_OFFSET     8U
153 #define GFXMMU_LUTXL_LVB_OFFSET     16U
154 #define GFXMMU_CR_ITS_MASK          0x1FU
155 /* Private macro -------------------------------------------------------------*/
156 /* Private variables ---------------------------------------------------------*/
157 /* Private function prototypes -----------------------------------------------*/
158 /* Exported functions --------------------------------------------------------*/
159 /** @defgroup GFXMMU_Exported_Functions GFXMMU Exported Functions
160   * @{
161   */
162 
163 /** @defgroup GFXMMU_Exported_Functions_Group1 Initialization and de-initialization functions
164  *  @brief    Initialization and de-initialization functions
165  *
166 @verbatim
167   ==============================================================================
168           ##### Initialization and de-initialization functions #####
169   ==============================================================================
170     [..]  This section provides functions allowing to:
171       (+) Initialize the GFXMMU.
172       (+) De-initialize the GFXMMU.
173 @endverbatim
174   * @{
175   */
176 
177 /**
178   * @brief  Initialize the GFXMMU according to the specified parameters in the
179   *         GFXMMU_InitTypeDef structure and initialize the associated handle.
180   * @param  hgfxmmu GFXMMU handle.
181   * @retval HAL status.
182   */
HAL_GFXMMU_Init(GFXMMU_HandleTypeDef * hgfxmmu)183 HAL_StatusTypeDef HAL_GFXMMU_Init(GFXMMU_HandleTypeDef *hgfxmmu)
184 {
185   HAL_StatusTypeDef status = HAL_OK;
186 
187   /* Check GFXMMU handle */
188   if(hgfxmmu == NULL)
189   {
190     status = HAL_ERROR;
191   }
192   else
193   {
194     /* Check parameters */
195     assert_param(IS_GFXMMU_ALL_INSTANCE(hgfxmmu->Instance));
196     assert_param(IS_GFXMMU_BLOCKS_PER_LINE(hgfxmmu->Init.BlocksPerLine));
197     assert_param(IS_GFXMMU_BUFFER_ADDRESS(hgfxmmu->Init.Buffers.Buf0Address));
198     assert_param(IS_GFXMMU_BUFFER_ADDRESS(hgfxmmu->Init.Buffers.Buf1Address));
199     assert_param(IS_GFXMMU_BUFFER_ADDRESS(hgfxmmu->Init.Buffers.Buf2Address));
200     assert_param(IS_GFXMMU_BUFFER_ADDRESS(hgfxmmu->Init.Buffers.Buf3Address));
201     assert_param(IS_FUNCTIONAL_STATE(hgfxmmu->Init.CachePrefetch.Activation));
202     assert_param(IS_FUNCTIONAL_STATE(hgfxmmu->Init.Interrupts.Activation));
203 
204 #if (USE_HAL_GFXMMU_REGISTER_CALLBACKS == 1)
205     /* Reset callback pointers to the weak predefined callbacks */
206     hgfxmmu->ErrorCallback = HAL_GFXMMU_ErrorCallback;
207 
208     /* Call GFXMMU MSP init function */
209     if(hgfxmmu->MspInitCallback == NULL)
210     {
211       hgfxmmu->MspInitCallback = HAL_GFXMMU_MspInit;
212     }
213     hgfxmmu->MspInitCallback(hgfxmmu);
214 #else
215     /* Call GFXMMU MSP init function */
216     HAL_GFXMMU_MspInit(hgfxmmu);
217 #endif
218 
219     /* Configure blocks per line, cache and interrupts parameters on GFXMMU_CR register */
220     hgfxmmu->Instance->CR &= ~(GFXMMU_CR_B0OIE | GFXMMU_CR_B1OIE | GFXMMU_CR_B2OIE | GFXMMU_CR_B3OIE |
221                                GFXMMU_CR_AMEIE | GFXMMU_CR_192BM | GFXMMU_CR_CE    | GFXMMU_CR_CL    |
222                                GFXMMU_CR_CLB   | GFXMMU_CR_FC    | GFXMMU_CR_PD    | GFXMMU_CR_OC    |
223                                GFXMMU_CR_OB);
224     hgfxmmu->Instance->CR |= (hgfxmmu->Init.BlocksPerLine);
225     if(hgfxmmu->Init.CachePrefetch.Activation == ENABLE)
226     {
227       assert_param(IS_GFXMMU_CACHE_LOCK(hgfxmmu->Init.CachePrefetch.CacheLock));
228       assert_param(IS_GFXMMU_PREFETCH(hgfxmmu->Init.CachePrefetch.Prefetch));
229       assert_param(IS_GFXMMU_OUTTER_BUFFERABILITY(hgfxmmu->Init.CachePrefetch.OutterBufferability));
230       assert_param(IS_GFXMMU_OUTTER_CACHABILITY(hgfxmmu->Init.CachePrefetch.OutterCachability));
231       hgfxmmu->Instance->CR |= (GFXMMU_CR_CE |
232                                 hgfxmmu->Init.CachePrefetch.CacheLock |
233                                 hgfxmmu->Init.CachePrefetch.Prefetch |
234                                 hgfxmmu->Init.CachePrefetch.OutterBufferability |
235                                 hgfxmmu->Init.CachePrefetch.OutterCachability);
236       if(hgfxmmu->Init.CachePrefetch.CacheLock == GFXMMU_CACHE_LOCK_ENABLE)
237       {
238         assert_param(IS_GFXMMU_CACHE_LOCK_BUFFER(hgfxmmu->Init.CachePrefetch.CacheLockBuffer));
239         assert_param(IS_GFXMMU_CACHE_FORCE(hgfxmmu->Init.CachePrefetch.CacheForce));
240         hgfxmmu->Instance->CR |= (hgfxmmu->Init.CachePrefetch.CacheLockBuffer |
241                                   hgfxmmu->Init.CachePrefetch.CacheForce);
242       }
243     }
244     if(hgfxmmu->Init.Interrupts.Activation == ENABLE)
245     {
246       assert_param(IS_GFXMMU_INTERRUPTS(hgfxmmu->Init.Interrupts.UsedInterrupts));
247       hgfxmmu->Instance->CR |= hgfxmmu->Init.Interrupts.UsedInterrupts;
248     }
249 
250     /* Configure default value on GFXMMU_DVR register */
251     hgfxmmu->Instance->DVR = hgfxmmu->Init.DefaultValue;
252 
253     /* Configure physical buffer addresses on GFXMMU_BxCR registers */
254     hgfxmmu->Instance->B0CR = hgfxmmu->Init.Buffers.Buf0Address;
255     hgfxmmu->Instance->B1CR = hgfxmmu->Init.Buffers.Buf1Address;
256     hgfxmmu->Instance->B2CR = hgfxmmu->Init.Buffers.Buf2Address;
257     hgfxmmu->Instance->B3CR = hgfxmmu->Init.Buffers.Buf3Address;
258 
259     /* Force invalidate cache if cache is enabled */
260     if(hgfxmmu->Init.CachePrefetch.Activation == ENABLE)
261     {
262       hgfxmmu->Instance->CCR |= GFXMMU_CACHE_FORCE_INVALIDATE;
263     }
264 
265     /* Reset GFXMMU error code */
266     hgfxmmu->ErrorCode = GFXMMU_ERROR_NONE;
267 
268     /* Set GFXMMU to ready state */
269     hgfxmmu->State = HAL_GFXMMU_STATE_READY;
270   }
271   /* Return function status */
272   return status;
273 }
274 
275 /**
276   * @brief  De-initialize the GFXMMU.
277   * @param  hgfxmmu GFXMMU handle.
278   * @retval HAL status.
279   */
HAL_GFXMMU_DeInit(GFXMMU_HandleTypeDef * hgfxmmu)280 HAL_StatusTypeDef HAL_GFXMMU_DeInit(GFXMMU_HandleTypeDef *hgfxmmu)
281 {
282   HAL_StatusTypeDef status = HAL_OK;
283 
284   /* Check GFXMMU handle */
285   if(hgfxmmu == NULL)
286   {
287     status = HAL_ERROR;
288   }
289   else
290   {
291     /* Check parameters */
292     assert_param(IS_GFXMMU_ALL_INSTANCE(hgfxmmu->Instance));
293 
294     /* Disable all interrupts on GFXMMU_CR register */
295     hgfxmmu->Instance->CR &= ~(GFXMMU_CR_B0OIE | GFXMMU_CR_B1OIE | GFXMMU_CR_B2OIE | GFXMMU_CR_B3OIE |
296                                GFXMMU_CR_AMEIE);
297 
298     /* Call GFXMMU MSP de-init function */
299 #if (USE_HAL_GFXMMU_REGISTER_CALLBACKS == 1)
300     if(hgfxmmu->MspDeInitCallback == NULL)
301     {
302       hgfxmmu->MspDeInitCallback = HAL_GFXMMU_MspDeInit;
303     }
304     hgfxmmu->MspDeInitCallback(hgfxmmu);
305 #else
306     HAL_GFXMMU_MspDeInit(hgfxmmu);
307 #endif
308 
309     /* Set GFXMMU to reset state */
310     hgfxmmu->State = HAL_GFXMMU_STATE_RESET;
311   }
312   /* Return function status */
313   return status;
314 }
315 
316 /**
317   * @brief  Initialize the GFXMMU MSP.
318   * @param  hgfxmmu GFXMMU handle.
319   * @retval None.
320   */
HAL_GFXMMU_MspInit(GFXMMU_HandleTypeDef * hgfxmmu)321 __weak void HAL_GFXMMU_MspInit(GFXMMU_HandleTypeDef *hgfxmmu)
322 {
323   /* Prevent unused argument(s) compilation warning */
324   UNUSED(hgfxmmu);
325 
326   /* NOTE : This function should not be modified, when the function is needed,
327             the HAL_GFXMMU_MspInit could be implemented in the user file.
328    */
329 }
330 
331 /**
332   * @brief  De-initialize the GFXMMU MSP.
333   * @param  hgfxmmu GFXMMU handle.
334   * @retval None.
335   */
HAL_GFXMMU_MspDeInit(GFXMMU_HandleTypeDef * hgfxmmu)336 __weak void HAL_GFXMMU_MspDeInit(GFXMMU_HandleTypeDef *hgfxmmu)
337 {
338   /* Prevent unused argument(s) compilation warning */
339   UNUSED(hgfxmmu);
340 
341   /* NOTE : This function should not be modified, when the function is needed,
342             the HAL_GFXMMU_MspDeInit could be implemented in the user file.
343    */
344 }
345 
346 #if (USE_HAL_GFXMMU_REGISTER_CALLBACKS == 1)
347 /**
348   * @brief  Register a user GFXMMU callback
349   *         to be used instead of the weak predefined callback.
350   * @param  hgfxmmu GFXMMU handle.
351   * @param  CallbackID ID of the callback to be registered.
352   *         This parameter can be one of the following values:
353   *           @arg @ref HAL_GFXMMU_ERROR_CB_ID error callback ID.
354   *           @arg @ref HAL_GFXMMU_MSPINIT_CB_ID MSP init callback ID.
355   *           @arg @ref HAL_GFXMMU_MSPDEINIT_CB_ID MSP de-init callback ID.
356   * @param  pCallback pointer to the callback function.
357   * @retval HAL status.
358   */
HAL_GFXMMU_RegisterCallback(GFXMMU_HandleTypeDef * hgfxmmu,HAL_GFXMMU_CallbackIDTypeDef CallbackID,pGFXMMU_CallbackTypeDef pCallback)359 HAL_StatusTypeDef HAL_GFXMMU_RegisterCallback(GFXMMU_HandleTypeDef        *hgfxmmu,
360                                               HAL_GFXMMU_CallbackIDTypeDef CallbackID,
361                                               pGFXMMU_CallbackTypeDef      pCallback)
362 {
363   HAL_StatusTypeDef status = HAL_OK;
364 
365   if(pCallback == NULL)
366   {
367     /* update the error code */
368     hgfxmmu->ErrorCode |= GFXMMU_ERROR_INVALID_CALLBACK;
369     /* update return status */
370     status = HAL_ERROR;
371   }
372   else
373   {
374     if(HAL_GFXMMU_STATE_READY == hgfxmmu->State)
375     {
376       switch (CallbackID)
377       {
378       case HAL_GFXMMU_ERROR_CB_ID :
379         hgfxmmu->ErrorCallback = pCallback;
380         break;
381       case HAL_GFXMMU_MSPINIT_CB_ID :
382         hgfxmmu->MspInitCallback = pCallback;
383         break;
384       case HAL_GFXMMU_MSPDEINIT_CB_ID :
385         hgfxmmu->MspDeInitCallback = pCallback;
386         break;
387       default :
388         /* update the error code */
389         hgfxmmu->ErrorCode |= GFXMMU_ERROR_INVALID_CALLBACK;
390         /* update return status */
391         status = HAL_ERROR;
392         break;
393       }
394     }
395     else if(HAL_GFXMMU_STATE_RESET == hgfxmmu->State)
396     {
397       switch (CallbackID)
398       {
399       case HAL_GFXMMU_MSPINIT_CB_ID :
400         hgfxmmu->MspInitCallback = pCallback;
401         break;
402       case HAL_GFXMMU_MSPDEINIT_CB_ID :
403         hgfxmmu->MspDeInitCallback = pCallback;
404         break;
405       default :
406         /* update the error code */
407         hgfxmmu->ErrorCode |= GFXMMU_ERROR_INVALID_CALLBACK;
408         /* update return status */
409         status = HAL_ERROR;
410         break;
411       }
412     }
413     else
414     {
415       /* update the error code */
416       hgfxmmu->ErrorCode |= GFXMMU_ERROR_INVALID_CALLBACK;
417       /* update return status */
418       status = HAL_ERROR;
419     }
420   }
421   return status;
422 }
423 
424 /**
425   * @brief  Unregister a user GFXMMU callback.
426   *         GFXMMU callback is redirected to the weak predefined callback.
427   * @param  hgfxmmu GFXMMU handle.
428   * @param  CallbackID ID of the callback to be unregistered.
429   *         This parameter can be one of the following values:
430   *           @arg @ref HAL_GFXMMU_ERROR_CB_ID error callback ID.
431   *           @arg @ref HAL_GFXMMU_MSPINIT_CB_ID MSP init callback ID.
432   *           @arg @ref HAL_GFXMMU_MSPDEINIT_CB_ID MSP de-init callback ID.
433   * @retval HAL status.
434   */
HAL_GFXMMU_UnRegisterCallback(GFXMMU_HandleTypeDef * hgfxmmu,HAL_GFXMMU_CallbackIDTypeDef CallbackID)435 HAL_StatusTypeDef HAL_GFXMMU_UnRegisterCallback(GFXMMU_HandleTypeDef        *hgfxmmu,
436                                                 HAL_GFXMMU_CallbackIDTypeDef CallbackID)
437 {
438   HAL_StatusTypeDef status = HAL_OK;
439 
440   if(HAL_GFXMMU_STATE_READY == hgfxmmu->State)
441   {
442     switch (CallbackID)
443     {
444     case HAL_GFXMMU_ERROR_CB_ID :
445       hgfxmmu->ErrorCallback = HAL_GFXMMU_ErrorCallback;
446       break;
447     case HAL_GFXMMU_MSPINIT_CB_ID :
448       hgfxmmu->MspInitCallback = HAL_GFXMMU_MspInit;
449       break;
450     case HAL_GFXMMU_MSPDEINIT_CB_ID :
451       hgfxmmu->MspDeInitCallback = HAL_GFXMMU_MspDeInit;
452       break;
453     default :
454       /* update the error code */
455       hgfxmmu->ErrorCode |= GFXMMU_ERROR_INVALID_CALLBACK;
456       /* update return status */
457       status = HAL_ERROR;
458       break;
459     }
460   }
461   else if(HAL_GFXMMU_STATE_RESET == hgfxmmu->State)
462   {
463     switch (CallbackID)
464     {
465     case HAL_GFXMMU_MSPINIT_CB_ID :
466       hgfxmmu->MspInitCallback = HAL_GFXMMU_MspInit;
467       break;
468     case HAL_GFXMMU_MSPDEINIT_CB_ID :
469       hgfxmmu->MspDeInitCallback = HAL_GFXMMU_MspDeInit;
470       break;
471     default :
472       /* update the error code */
473       hgfxmmu->ErrorCode |= GFXMMU_ERROR_INVALID_CALLBACK;
474       /* update return status */
475       status = HAL_ERROR;
476       break;
477     }
478   }
479   else
480   {
481     /* update the error code */
482     hgfxmmu->ErrorCode |= GFXMMU_ERROR_INVALID_CALLBACK;
483     /* update return status */
484     status = HAL_ERROR;
485   }
486   return status;
487 }
488 #endif /* USE_HAL_GFXMMU_REGISTER_CALLBACKS */
489 
490 /**
491   * @}
492   */
493 
494 /** @defgroup GFXMMU_Exported_Functions_Group2 Operations functions
495  *  @brief    GFXMMU operation functions
496  *
497 @verbatim
498   ==============================================================================
499                       ##### Operation functions #####
500   ==============================================================================
501     [..]  This section provides functions allowing to:
502       (+) Configure LUT.
503       (+) Force flush and/or invalidate of cache.
504       (+) Modify physical buffer addresses.
505       (+) Modify cache and pre-fetch parameters.
506       (+) Manage error.
507 @endverbatim
508   * @{
509   */
510 
511 /**
512   * @brief  This function allows to copy LUT from flash to look up RAM.
513   * @param  hgfxmmu GFXMMU handle.
514   * @param  FirstLine First line enabled on LUT.
515   *         This parameter must be a number between Min_Data = 0 and Max_Data = 1023.
516   * @param  LinesNumber Number of lines enabled on LUT.
517   *         This parameter must be a number between Min_Data = 1 and Max_Data = 1024.
518   * @param  Address Start address of LUT in flash.
519   * @retval HAL status.
520   */
HAL_GFXMMU_ConfigLut(GFXMMU_HandleTypeDef * hgfxmmu,uint32_t FirstLine,uint32_t LinesNumber,uint32_t Address)521 HAL_StatusTypeDef HAL_GFXMMU_ConfigLut(GFXMMU_HandleTypeDef *hgfxmmu,
522                                        uint32_t FirstLine,
523                                        uint32_t LinesNumber,
524                                        uint32_t Address)
525 {
526   HAL_StatusTypeDef status = HAL_OK;
527 
528   /* Check parameters */
529   assert_param(IS_GFXMMU_ALL_INSTANCE(hgfxmmu->Instance));
530   assert_param(IS_GFXMMU_LUT_LINE(FirstLine));
531   assert_param(IS_GFXMMU_LUT_LINES_NUMBER(LinesNumber));
532 
533   /* Check GFXMMU state and coherent parameters */
534   if((hgfxmmu->State != HAL_GFXMMU_STATE_READY) || ((FirstLine + LinesNumber) > 1024U))
535   {
536     status = HAL_ERROR;
537   }
538   else
539   {
540     uint32_t current_address, current_line, lutxl_address, lutxh_address;
541 
542     /* Initialize local variables */
543     current_address = Address;
544     current_line    = 0U;
545     lutxl_address   = (uint32_t) &(hgfxmmu->Instance->LUT[2U * FirstLine]);
546     lutxh_address   = (uint32_t) &(hgfxmmu->Instance->LUT[(2U * FirstLine) + 1U]);
547 
548     /* Copy LUT from flash to look up RAM */
549     while(current_line < LinesNumber)
550     {
551       *((uint32_t *)lutxl_address) = *((uint32_t *)current_address);
552       current_address += 4U;
553       *((uint32_t *)lutxh_address) = *((uint32_t *)current_address);
554       current_address += 4U;
555       lutxl_address += 8U;
556       lutxh_address += 8U;
557       current_line++;
558     }
559   }
560   /* Return function status */
561   return status;
562 }
563 
564 /**
565   * @brief  This function allows to disable a range of LUT lines.
566   * @param  hgfxmmu GFXMMU handle.
567   * @param  FirstLine First line to disable on LUT.
568   *         This parameter must be a number between Min_Data = 0 and Max_Data = 1023.
569   * @param  LinesNumber Number of lines to disable on LUT.
570   *         This parameter must be a number between Min_Data = 1 and Max_Data = 1024.
571   * @retval HAL status.
572   */
HAL_GFXMMU_DisableLutLines(GFXMMU_HandleTypeDef * hgfxmmu,uint32_t FirstLine,uint32_t LinesNumber)573 HAL_StatusTypeDef HAL_GFXMMU_DisableLutLines(GFXMMU_HandleTypeDef *hgfxmmu,
574                                              uint32_t FirstLine,
575                                              uint32_t LinesNumber)
576 {
577   HAL_StatusTypeDef status = HAL_OK;
578 
579   /* Check parameters */
580   assert_param(IS_GFXMMU_ALL_INSTANCE(hgfxmmu->Instance));
581   assert_param(IS_GFXMMU_LUT_LINE(FirstLine));
582   assert_param(IS_GFXMMU_LUT_LINES_NUMBER(LinesNumber));
583 
584   /* Check GFXMMU state and coherent parameters */
585   if((hgfxmmu->State != HAL_GFXMMU_STATE_READY) || ((FirstLine + LinesNumber) > 1024U))
586   {
587     status = HAL_ERROR;
588   }
589   else
590   {
591     uint32_t current_line, lutxl_address, lutxh_address;
592 
593     /* Initialize local variables */
594     current_line    = 0U;
595     lutxl_address   = (uint32_t) &(hgfxmmu->Instance->LUT[2U * FirstLine]);
596     lutxh_address   = (uint32_t) &(hgfxmmu->Instance->LUT[(2U * FirstLine) + 1U]);
597 
598     /* Disable LUT lines */
599     while(current_line < LinesNumber)
600     {
601       *((uint32_t *)lutxl_address) = 0U;
602       *((uint32_t *)lutxh_address) = 0U;
603       lutxl_address += 8U;
604       lutxh_address += 8U;
605       current_line++;
606     }
607   }
608   /* Return function status */
609   return status;
610 }
611 
612 /**
613   * @brief  This function allows to configure one line of LUT.
614   * @param  hgfxmmu GFXMMU handle.
615   * @param  lutLine LUT line parameters.
616   * @retval HAL status.
617   */
HAL_GFXMMU_ConfigLutLine(GFXMMU_HandleTypeDef * hgfxmmu,GFXMMU_LutLineTypeDef * lutLine)618 HAL_StatusTypeDef HAL_GFXMMU_ConfigLutLine(GFXMMU_HandleTypeDef *hgfxmmu, GFXMMU_LutLineTypeDef *lutLine)
619 {
620   HAL_StatusTypeDef status = HAL_OK;
621 
622   /* Check parameters */
623   assert_param(IS_GFXMMU_ALL_INSTANCE(hgfxmmu->Instance));
624   assert_param(IS_GFXMMU_LUT_LINE(lutLine->LineNumber));
625   assert_param(IS_GFXMMU_LUT_LINE_STATUS(lutLine->LineStatus));
626   assert_param(IS_GFXMMU_LUT_BLOCK(lutLine->FirstVisibleBlock));
627   assert_param(IS_GFXMMU_LUT_BLOCK(lutLine->LastVisibleBlock));
628   assert_param(IS_GFXMMU_LUT_LINE_OFFSET(lutLine->LineOffset));
629 
630   /* Check GFXMMU state */
631   if(hgfxmmu->State != HAL_GFXMMU_STATE_READY)
632   {
633     status = HAL_ERROR;
634   }
635   else
636   {
637     uint32_t lutxl_address, lutxh_address;
638 
639     /* Initialize local variables */
640     lutxl_address   = (uint32_t) &(hgfxmmu->Instance->LUT[2U * lutLine->LineNumber]);
641     lutxh_address   = (uint32_t) &(hgfxmmu->Instance->LUT[(2U * lutLine->LineNumber) + 1U]);
642 
643     /* Configure LUT line */
644     if(lutLine->LineStatus == GFXMMU_LUT_LINE_ENABLE)
645     {
646       /* Enable and configure LUT line */
647       *((uint32_t *)lutxl_address) = (lutLine->LineStatus |
648                                      (lutLine->FirstVisibleBlock << GFXMMU_LUTXL_FVB_OFFSET) |
649                                      (lutLine->LastVisibleBlock << GFXMMU_LUTXL_LVB_OFFSET));
650       *((uint32_t *)lutxh_address) = (uint32_t) lutLine->LineOffset;
651     }
652     else
653     {
654       /* Disable LUT line */
655       *((uint32_t *)lutxl_address) = 0U;
656       *((uint32_t *)lutxh_address) = 0U;
657     }
658   }
659   /* Return function status */
660   return status;
661 }
662 
663 /**
664   * @brief  This function allows to force flush and/or invalidate of cache.
665   * @param  hgfxmmu GFXMMU handle.
666   * @param  ForceParam Force cache parameter.
667   *         This parameter can be a values combination of @ref GFXMMU_CacheForceParam.
668   * @retval HAL status.
669   */
HAL_GFXMMU_ConfigForceCache(GFXMMU_HandleTypeDef * hgfxmmu,uint32_t ForceParam)670 HAL_StatusTypeDef HAL_GFXMMU_ConfigForceCache(GFXMMU_HandleTypeDef *hgfxmmu, uint32_t ForceParam)
671 {
672   HAL_StatusTypeDef status = HAL_OK;
673 
674   /* Check parameters */
675   assert_param(IS_GFXMMU_ALL_INSTANCE(hgfxmmu->Instance));
676   assert_param(IS_GFXMMU_CACHE_FORCE_ACTION(ForceParam));
677 
678   /* Check GFXMMU state and cache status */
679   if(((hgfxmmu->Instance->CR & GFXMMU_CR_CE) != GFXMMU_CR_CE) || (hgfxmmu->State != HAL_GFXMMU_STATE_READY))
680   {
681     status = HAL_ERROR;
682   }
683   else
684   {
685     /* Force flush and/or invalidate cache on GFXMMU_CCR register */
686     hgfxmmu->Instance->CCR |= ForceParam;
687   }
688   /* Return function status */
689   return status;
690 }
691 
692 /**
693   * @brief  This function allows to modify physical buffer addresses.
694   * @param  hgfxmmu GFXMMU handle.
695   * @param  Buffers Buffers parameters.
696   * @retval HAL status.
697   */
HAL_GFXMMU_ModifyBuffers(GFXMMU_HandleTypeDef * hgfxmmu,GFXMMU_BuffersTypeDef * Buffers)698 HAL_StatusTypeDef HAL_GFXMMU_ModifyBuffers(GFXMMU_HandleTypeDef *hgfxmmu, GFXMMU_BuffersTypeDef *Buffers)
699 {
700   HAL_StatusTypeDef status = HAL_OK;
701 
702   /* Check parameters */
703   assert_param(IS_GFXMMU_ALL_INSTANCE(hgfxmmu->Instance));
704   assert_param(IS_GFXMMU_BUFFER_ADDRESS(Buffers->Buf0Address));
705   assert_param(IS_GFXMMU_BUFFER_ADDRESS(Buffers->Buf1Address));
706   assert_param(IS_GFXMMU_BUFFER_ADDRESS(Buffers->Buf2Address));
707   assert_param(IS_GFXMMU_BUFFER_ADDRESS(Buffers->Buf3Address));
708 
709   /* Check GFXMMU state */
710   if(hgfxmmu->State != HAL_GFXMMU_STATE_READY)
711   {
712     status = HAL_ERROR;
713   }
714   else
715   {
716     /* Modify physical buffer addresses on GFXMMU_BxCR registers */
717     hgfxmmu->Instance->B0CR = Buffers->Buf0Address;
718     hgfxmmu->Instance->B1CR = Buffers->Buf1Address;
719     hgfxmmu->Instance->B2CR = Buffers->Buf2Address;
720     hgfxmmu->Instance->B3CR = Buffers->Buf3Address;
721   }
722   /* Return function status */
723   return status;
724 }
725 
726 /**
727   * @brief  This function allows to modify cache and pre-fetch parameters.
728   * @param  hgfxmmu GFXMMU handle.
729   * @param  CachePrefetch Cache and pre-fetch parameters.
730   * @retval HAL status.
731   */
HAL_GFXMMU_ModifyCachePrefetch(GFXMMU_HandleTypeDef * hgfxmmu,GFXMMU_CachePrefetchTypeDef * CachePrefetch)732 HAL_StatusTypeDef HAL_GFXMMU_ModifyCachePrefetch(GFXMMU_HandleTypeDef *hgfxmmu,
733                                                  GFXMMU_CachePrefetchTypeDef *CachePrefetch)
734 {
735   HAL_StatusTypeDef status = HAL_OK;
736   assert_param(IS_FUNCTIONAL_STATE(CachePrefetch->Activation));
737 
738   /* Check parameters */
739   assert_param(IS_GFXMMU_ALL_INSTANCE(hgfxmmu->Instance));
740 
741   /* Check GFXMMU state */
742   if(hgfxmmu->State != HAL_GFXMMU_STATE_READY)
743   {
744     status = HAL_ERROR;
745   }
746   else
747   {
748     /* Modify cache and pre-fetch parameters on GFXMMU_CR register */
749     hgfxmmu->Instance->CR &= ~(GFXMMU_CR_CE | GFXMMU_CR_CL | GFXMMU_CR_CLB | GFXMMU_CR_FC |
750                                GFXMMU_CR_PD | GFXMMU_CR_OC | GFXMMU_CR_OB);
751     if(CachePrefetch->Activation == ENABLE)
752     {
753       assert_param(IS_GFXMMU_CACHE_LOCK(CachePrefetch->CacheLock));
754       assert_param(IS_GFXMMU_PREFETCH(CachePrefetch->Prefetch));
755       assert_param(IS_GFXMMU_OUTTER_BUFFERABILITY(CachePrefetch->OutterBufferability));
756       assert_param(IS_GFXMMU_OUTTER_CACHABILITY(CachePrefetch->OutterCachability));
757       hgfxmmu->Instance->CR |= (GFXMMU_CR_CE |
758                                 CachePrefetch->CacheLock |
759                                 CachePrefetch->Prefetch |
760                                 CachePrefetch->OutterBufferability |
761                                 CachePrefetch->OutterCachability);
762       if(CachePrefetch->CacheLock == GFXMMU_CACHE_LOCK_ENABLE)
763       {
764         assert_param(IS_GFXMMU_CACHE_LOCK_BUFFER(CachePrefetch->CacheLockBuffer));
765         assert_param(IS_GFXMMU_CACHE_FORCE(CachePrefetch->CacheForce));
766         hgfxmmu->Instance->CR |= (CachePrefetch->CacheLockBuffer |
767                                   CachePrefetch->CacheForce);
768       }
769     }
770   }
771   /* Return function status */
772   return status;
773 }
774 
775 /**
776   * @brief  This function handles the GFXMMU interrupts.
777   * @param  hgfxmmu GFXMMU handle.
778   * @retval None.
779   */
HAL_GFXMMU_IRQHandler(GFXMMU_HandleTypeDef * hgfxmmu)780 void HAL_GFXMMU_IRQHandler(GFXMMU_HandleTypeDef *hgfxmmu)
781 {
782   uint32_t flags, interrupts, error;
783 
784   /* Read current flags and interrupts and determine which error occurs */
785   flags = hgfxmmu->Instance->SR;
786   interrupts = (hgfxmmu->Instance->CR & GFXMMU_CR_ITS_MASK);
787   error = (flags & interrupts);
788 
789   if(error != 0U)
790   {
791     /* Clear flags on GFXMMU_FCR register */
792     hgfxmmu->Instance->FCR = error;
793 
794     /* Update GFXMMU error code */
795     hgfxmmu->ErrorCode |= error;
796 
797     /* Call GFXMMU error callback */
798 #if (USE_HAL_GFXMMU_REGISTER_CALLBACKS == 1)
799     hgfxmmu->ErrorCallback(hgfxmmu);
800 #else
801     HAL_GFXMMU_ErrorCallback(hgfxmmu);
802 #endif
803   }
804 }
805 
806 /**
807   * @brief  Error callback.
808   * @param  hgfxmmu GFXMMU handle.
809   * @retval None.
810   */
HAL_GFXMMU_ErrorCallback(GFXMMU_HandleTypeDef * hgfxmmu)811 __weak void HAL_GFXMMU_ErrorCallback(GFXMMU_HandleTypeDef *hgfxmmu)
812 {
813   /* Prevent unused argument(s) compilation warning */
814   UNUSED(hgfxmmu);
815 
816   /* NOTE : This function should not be modified, when the callback is needed,
817             the HAL_GFXMMU_ErrorCallback could be implemented in the user file.
818    */
819 }
820 
821 /**
822   * @}
823   */
824 
825 /** @defgroup GFXMMU_Exported_Functions_Group3 State functions
826  *  @brief    GFXMMU state functions
827  *
828 @verbatim
829   ==============================================================================
830                          ##### State functions #####
831   ==============================================================================
832     [..]  This section provides functions allowing to:
833       (+) Get GFXMMU handle state.
834       (+) Get GFXMMU error code.
835 @endverbatim
836   * @{
837   */
838 
839 /**
840   * @brief  This function allows to get the current GFXMMU handle state.
841   * @param  hgfxmmu GFXMMU handle.
842   * @retval GFXMMU state.
843   */
HAL_GFXMMU_GetState(GFXMMU_HandleTypeDef * hgfxmmu)844 HAL_GFXMMU_StateTypeDef HAL_GFXMMU_GetState(GFXMMU_HandleTypeDef *hgfxmmu)
845 {
846   /* Return GFXMMU handle state */
847   return hgfxmmu->State;
848 }
849 
850 /**
851   * @brief  This function allows to get the current GFXMMU error code.
852   * @param  hgfxmmu GFXMMU handle.
853   * @retval GFXMMU error code.
854   */
HAL_GFXMMU_GetError(GFXMMU_HandleTypeDef * hgfxmmu)855 uint32_t HAL_GFXMMU_GetError(GFXMMU_HandleTypeDef *hgfxmmu)
856 {
857   uint32_t error_code;
858 
859   /* Enter in critical section */
860   __disable_irq();
861 
862   /* Store and reset GFXMMU error code */
863   error_code = hgfxmmu->ErrorCode;
864   hgfxmmu->ErrorCode = GFXMMU_ERROR_NONE;
865 
866   /* Exit from critical section */
867   __enable_irq();
868 
869   /* Return GFXMMU error code */
870   return error_code;
871 }
872 
873 /**
874   * @}
875   */
876 
877 /**
878   * @}
879   */
880 /* End of exported functions -------------------------------------------------*/
881 /* Private functions ---------------------------------------------------------*/
882 /* End of private functions --------------------------------------------------*/
883 
884 /**
885   * @}
886   */
887 #endif /* GFXMMU */
888 #endif /* HAL_GFXMMU_MODULE_ENABLED */
889 /**
890   * @}
891   */
892 
893