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