1 /**
2  * @file lv_gpu_nxp_pxp.c
3  *
4  */
5 
6 /**
7  * MIT License
8  *
9  * Copyright 2020-2023 NXP
10  *
11  * Permission is hereby granted, free of charge, to any person obtaining a copy
12  * of this software and associated documentation files (the "Software"), to deal
13  * in the Software without restriction, including without limitation the rights to
14  * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
15  * the Software, and to permit persons to whom the Software is furnished to do so,
16  * subject to the following conditions:
17  *
18  * The above copyright notice and this permission notice (including the next paragraph)
19  * shall be included in all copies or substantial portions of the Software.
20  *
21  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
22  * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
23  * PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
24  * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
25  * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
26  * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27  *
28  */
29 
30 /*********************
31  *      INCLUDES
32  *********************/
33 
34 #include "lv_gpu_nxp_pxp.h"
35 
36 #if LV_USE_GPU_NXP_PXP
37 #include "lv_gpu_nxp_pxp_osa.h"
38 #include "../../../core/lv_refr.h"
39 
40 /*********************
41  *      DEFINES
42  *********************/
43 
44 /**********************
45  *      TYPEDEFS
46  **********************/
47 
48 /**********************
49  *  STATIC PROTOTYPES
50  **********************/
51 
52 /**
53  * Clean and invalidate cache.
54  */
55 static inline void invalidate_cache(void);
56 
57 /**********************
58  *  STATIC VARIABLES
59  **********************/
60 
61 static lv_nxp_pxp_cfg_t * pxp_cfg;
62 
63 /**********************
64  *      MACROS
65  **********************/
66 
67 /**********************
68  *   GLOBAL FUNCTIONS
69  **********************/
70 
lv_gpu_nxp_pxp_init(void)71 lv_res_t lv_gpu_nxp_pxp_init(void)
72 {
73 #if LV_USE_GPU_NXP_PXP_AUTO_INIT
74     pxp_cfg = lv_gpu_nxp_pxp_get_cfg();
75 #endif
76 
77     if(!pxp_cfg || !pxp_cfg->pxp_interrupt_deinit || !pxp_cfg->pxp_interrupt_init ||
78        !pxp_cfg->pxp_run || !pxp_cfg->pxp_wait)
79         PXP_RETURN_INV("PXP configuration error.");
80 
81     PXP_Init(LV_GPU_NXP_PXP_ID);
82 
83     PXP_EnableCsc1(LV_GPU_NXP_PXP_ID, false); /*Disable CSC1, it is enabled by default.*/
84     PXP_SetProcessBlockSize(LV_GPU_NXP_PXP_ID, kPXP_BlockSize16); /*Block size 16x16 for higher performance*/
85 
86     PXP_EnableInterrupts(LV_GPU_NXP_PXP_ID, kPXP_CompleteInterruptEnable);
87 
88     if(pxp_cfg->pxp_interrupt_init() != LV_RES_OK) {
89         PXP_DisableInterrupts(LV_GPU_NXP_PXP_ID, kPXP_CompleteInterruptEnable);
90         PXP_Deinit(LV_GPU_NXP_PXP_ID);
91         PXP_RETURN_INV("PXP interrupt init failed.");
92     }
93 
94     return LV_RES_OK;
95 }
96 
lv_gpu_nxp_pxp_deinit(void)97 void lv_gpu_nxp_pxp_deinit(void)
98 {
99     pxp_cfg->pxp_interrupt_deinit();
100     PXP_DisableInterrupts(LV_GPU_NXP_PXP_ID, kPXP_CompleteInterruptEnable);
101     PXP_Deinit(LV_GPU_NXP_PXP_ID);
102 }
103 
lv_gpu_nxp_pxp_reset(void)104 void lv_gpu_nxp_pxp_reset(void)
105 {
106     /* Wait for previous command to complete before resetting the registers. */
107     lv_gpu_nxp_pxp_wait();
108 
109     PXP_ResetControl(LV_GPU_NXP_PXP_ID);
110 
111     PXP_EnableCsc1(LV_GPU_NXP_PXP_ID, false); /*Disable CSC1, it is enabled by default.*/
112     PXP_SetProcessBlockSize(LV_GPU_NXP_PXP_ID, kPXP_BlockSize16); /*Block size 16x16 for higher performance*/
113 }
114 
lv_gpu_nxp_pxp_run(void)115 void lv_gpu_nxp_pxp_run(void)
116 {
117     invalidate_cache();
118 
119     pxp_cfg->pxp_run();
120 }
121 
lv_gpu_nxp_pxp_wait(void)122 void lv_gpu_nxp_pxp_wait(void)
123 {
124     pxp_cfg->pxp_wait();
125 }
126 
127 /**********************
128  *   STATIC FUNCTIONS
129  **********************/
130 
invalidate_cache(void)131 static inline void invalidate_cache(void)
132 {
133     lv_disp_t * disp = _lv_refr_get_disp_refreshing();
134     if(disp->driver->clean_dcache_cb)
135         disp->driver->clean_dcache_cb(disp->driver);
136 }
137 
138 #endif /*LV_USE_GPU_NXP_PXP*/
139