1 /**
2  * @file lv_gpu_nxp_pxp.h
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 #ifndef LV_GPU_NXP_PXP_H
31 #define LV_GPU_NXP_PXP_H
32 
33 #ifdef __cplusplus
34 extern "C" {
35 #endif
36 
37 /*********************
38  *      INCLUDES
39  *********************/
40 
41 #include "../../../lv_conf_internal.h"
42 
43 #if LV_USE_GPU_NXP_PXP
44 #include "fsl_cache.h"
45 #include "fsl_pxp.h"
46 
47 #include "../../../misc/lv_log.h"
48 
49 /*********************
50  *      DEFINES
51  *********************/
52 
53 /** PXP module instance to use*/
54 #define LV_GPU_NXP_PXP_ID PXP
55 
56 /** PXP interrupt line ID*/
57 #define LV_GPU_NXP_PXP_IRQ_ID PXP_IRQn
58 
59 #ifndef LV_GPU_NXP_PXP_LOG_ERRORS
60 /** Enable logging of PXP errors (\see LV_LOG_ERROR)*/
61 #define LV_GPU_NXP_PXP_LOG_ERRORS 1
62 #endif
63 
64 #ifndef LV_GPU_NXP_PXP_LOG_TRACES
65 /** Enable logging of PXP errors (\see LV_LOG_ERROR)*/
66 #define LV_GPU_NXP_PXP_LOG_TRACES 0
67 #endif
68 
69 /**********************
70  *      TYPEDEFS
71  **********************/
72 
73 /**
74  * NXP PXP device configuration - call-backs used for
75  * interrupt init/wait/deinit.
76  */
77 typedef struct {
78     /** Callback for PXP interrupt initialization*/
79     lv_res_t (*pxp_interrupt_init)(void);
80 
81     /** Callback for PXP interrupt de-initialization*/
82     void (*pxp_interrupt_deinit)(void);
83 
84     /** Callback for PXP start*/
85     void (*pxp_run)(void);
86 
87     /** Callback for waiting of PXP completion*/
88     void (*pxp_wait)(void);
89 } lv_nxp_pxp_cfg_t;
90 
91 /**********************
92  * GLOBAL PROTOTYPES
93  **********************/
94 
95 /**
96  * Reset and initialize PXP device. This function should be called as a part
97  * of display init sequence.
98  *
99  * @retval LV_RES_OK PXP init completed
100  * @retval LV_RES_INV Error occurred (\see LV_GPU_NXP_PXP_LOG_ERRORS)
101  */
102 lv_res_t lv_gpu_nxp_pxp_init(void);
103 
104 /**
105  * Disable PXP device. Should be called during display deinit sequence.
106  */
107 void lv_gpu_nxp_pxp_deinit(void);
108 
109 /**
110  * Reset PXP device.
111  */
112 void lv_gpu_nxp_pxp_reset(void);
113 
114 /**
115  * Clear cache and start PXP.
116  */
117 void lv_gpu_nxp_pxp_run(void);
118 
119 /**
120  * Wait for PXP completion.
121  */
122 void lv_gpu_nxp_pxp_wait(void);
123 
124 /**********************
125  *      MACROS
126  **********************/
127 
128 #define PXP_COND_STOP(cond, txt)              \
129     do {                                      \
130         if (cond) {                           \
131             LV_LOG_ERROR("%s. STOP!", txt);   \
132             for ( ; ; );                      \
133         }                                     \
134     } while(0)
135 
136 #if LV_GPU_NXP_PXP_LOG_ERRORS
137 #define PXP_RETURN_INV(fmt, ...)              \
138     do {                                      \
139         LV_LOG_ERROR(fmt, ##__VA_ARGS__);     \
140         return LV_RES_INV;                    \
141     } while (0)
142 #else
143 #define PXP_RETURN_INV(fmt, ...)              \
144     do {                                      \
145         return LV_RES_INV;                    \
146     }while(0)
147 #endif /*LV_GPU_NXP_PXP_LOG_ERRORS*/
148 
149 #if LV_GPU_NXP_PXP_LOG_TRACES
150 #define PXP_LOG_TRACE(fmt, ...)               \
151     do {                                      \
152         LV_LOG_ERROR(fmt, ##__VA_ARGS__);     \
153     } while (0)
154 #else
155 #define PXP_LOG_TRACE(fmt, ...)               \
156     do {                                      \
157     } while (0)
158 #endif /*LV_GPU_NXP_PXP_LOG_TRACES*/
159 
160 #endif /*LV_USE_GPU_NXP_PXP*/
161 
162 #ifdef __cplusplus
163 } /*extern "C"*/
164 #endif
165 
166 #endif /*LV_GPU_NXP_PXP_H*/
167