stm32l4xx_hal_gfxmmu.c 25 KB

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