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