You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

894 lines
30 KiB

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