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