1 /**
2  * @file lv_disp.h
3  *
4  */
5 
6 #ifndef LV_DISP_H
7 #define LV_DISP_H
8 
9 #ifdef __cplusplus
10 extern "C" {
11 #endif
12 
13 /*********************
14  *      INCLUDES
15  *********************/
16 #include "../lv_hal/lv_hal.h"
17 #include "lv_obj.h"
18 
19 /*********************
20  *      DEFINES
21  *********************/
22 
23 /**********************
24  *      TYPEDEFS
25  **********************/
26 
27 typedef enum {
28     LV_SCR_LOAD_ANIM_NONE,
29     LV_SCR_LOAD_ANIM_OVER_LEFT,
30     LV_SCR_LOAD_ANIM_OVER_RIGHT,
31     LV_SCR_LOAD_ANIM_OVER_TOP,
32     LV_SCR_LOAD_ANIM_OVER_BOTTOM,
33     LV_SCR_LOAD_ANIM_MOVE_LEFT,
34     LV_SCR_LOAD_ANIM_MOVE_RIGHT,
35     LV_SCR_LOAD_ANIM_MOVE_TOP,
36     LV_SCR_LOAD_ANIM_MOVE_BOTTOM,
37     LV_SCR_LOAD_ANIM_FADE_ON,
38 } lv_scr_load_anim_t;
39 
40 /**********************
41  * GLOBAL PROTOTYPES
42  **********************/
43 
44 /**
45  * Return with a pointer to the active screen
46  * @param disp pointer to display which active screen should be get. (NULL to use the default
47  * screen)
48  * @return pointer to the active screen object (loaded by 'lv_scr_load()')
49  */
50 lv_obj_t * lv_disp_get_scr_act(lv_disp_t * disp);
51 
52 /**
53  * Return with a pointer to the previous screen. Only used during screen transitions.
54  * @param disp pointer to display which previous screen should be get. (NULL to use the default
55  * screen)
56  * @return pointer to the previous screen object or NULL if not used now
57  */
58 lv_obj_t * lv_disp_get_scr_prev(lv_disp_t * disp);
59 
60 /**
61  * Make a screen active
62  * @param scr pointer to a screen
63  */
64 void lv_disp_load_scr(lv_obj_t * scr);
65 
66 /**
67  * Return with the top layer. (Same on every screen and it is above the normal screen layer)
68  * @param disp pointer to display which top layer should be get. (NULL to use the default screen)
69  * @return pointer to the top layer object  (transparent screen sized lv_obj)
70  */
71 lv_obj_t * lv_disp_get_layer_top(lv_disp_t * disp);
72 
73 /**
74  * Return with the sys. layer. (Same on every screen and it is above the normal screen and the top
75  * layer)
76  * @param disp pointer to display which sys. layer  should be get. (NULL to use the default screen)
77  * @return pointer to the sys layer object  (transparent screen sized lv_obj)
78  */
79 lv_obj_t * lv_disp_get_layer_sys(lv_disp_t * disp);
80 
81 /**
82  * Assign a screen to a display.
83  * @param disp pointer to a display where to assign the screen
84  * @param scr pointer to a screen object to assign
85  */
86 void lv_disp_assign_screen(lv_disp_t * disp, lv_obj_t * scr);
87 
88 
89 /**
90  * Set the background color of a display
91  * @param disp pointer to a display
92  * @param color color of the background
93  */
94 void lv_disp_set_bg_color(lv_disp_t * disp, lv_color_t color);
95 
96 /**
97  * Set the background image of a display
98  * @param disp pointer to a display
99  * @param img_src path to file or pointer to an `lv_img_dsc_t` variable
100  */
101 void lv_disp_set_bg_image(lv_disp_t * disp, const void  * img_src);
102 
103 /**
104  * Opacity of the background
105  * @param disp pointer to a display
106  * @param opa opacity (0..255)
107  */
108 void lv_disp_set_bg_opa(lv_disp_t * disp, lv_opa_t opa);
109 
110 #if LV_USE_ANIMATION
111 
112 /**
113  * Switch screen with animation
114  * @param scr pointer to the new screen to load
115  * @param anim_type type of the animation from `lv_scr_load_anim_t`. E.g.  `LV_SCR_LOAD_ANIM_MOVE_LEFT`
116  * @param time time of the animation
117  * @param delay delay before the transition
118  * @param auto_del true: automatically delete the old screen
119  */
120 void lv_scr_load_anim(lv_obj_t * scr, lv_scr_load_anim_t anim_type, uint32_t time, uint32_t delay, bool auto_del);
121 
122 #endif
123 /**
124  * Get elapsed time since last user activity on a display (e.g. click)
125  * @param disp pointer to an display (NULL to get the overall smallest inactivity)
126  * @return elapsed ticks (milliseconds) since the last activity
127  */
128 uint32_t lv_disp_get_inactive_time(const lv_disp_t * disp);
129 
130 /**
131  * Manually trigger an activity on a display
132  * @param disp pointer to an display (NULL to use the default display)
133  */
134 void lv_disp_trig_activity(lv_disp_t * disp);
135 
136 /**
137  * Clean any CPU cache that is related to the display.
138  * @param disp pointer to an display (NULL to use the default display)
139  */
140 void lv_disp_clean_dcache(lv_disp_t * disp);
141 
142 /**
143  * Get a pointer to the screen refresher task to
144  * modify its parameters with `lv_task_...` functions.
145  * @param disp pointer to a display
146  * @return pointer to the display refresher task. (NULL on error)
147  */
148 lv_task_t * _lv_disp_get_refr_task(lv_disp_t * disp);
149 
150 /*------------------------------------------------
151  * To improve backward compatibility
152  * Recommended only if you have one display
153  *------------------------------------------------*/
154 
155 /**
156  * Get the active screen of the default display
157  * @return pointer to the active screen
158  */
lv_scr_act(void)159 static inline lv_obj_t * lv_scr_act(void)
160 {
161     return lv_disp_get_scr_act(lv_disp_get_default());
162 }
163 
164 /**
165  * Get the top layer  of the default display
166  * @return pointer to the top layer
167  */
lv_layer_top(void)168 static inline lv_obj_t * lv_layer_top(void)
169 {
170     return lv_disp_get_layer_top(lv_disp_get_default());
171 }
172 
173 /**
174  * Get the active screen of the default display
175  * @return  pointer to the sys layer
176  */
lv_layer_sys(void)177 static inline lv_obj_t * lv_layer_sys(void)
178 {
179     return lv_disp_get_layer_sys(lv_disp_get_default());
180 }
181 
lv_scr_load(lv_obj_t * scr)182 static inline void lv_scr_load(lv_obj_t * scr)
183 {
184     lv_disp_load_scr(scr);
185 }
186 
187 /**********************
188  *      MACROS
189  **********************/
190 
191 /*------------------------------------------------
192  * To improve backward compatibility
193  * Recommended only if you have one display
194  *------------------------------------------------*/
195 
196 #ifndef LV_HOR_RES
197 /**
198  * The horizontal resolution of the currently active display.
199  */
200 #define LV_HOR_RES lv_disp_get_hor_res(lv_disp_get_default())
201 #endif
202 
203 #ifndef LV_VER_RES
204 /**
205  * The vertical resolution of the currently active display.
206  */
207 #define LV_VER_RES lv_disp_get_ver_res(lv_disp_get_default())
208 #endif
209 
210 
211 /**
212  * Same as Android's DIP. (Different name is chosen to avoid mistype between LV_DPI and LV_DIP)
213  * 1 dip is 1 px on a 160 DPI screen
214  * 1 dip is 2 px on a 320 DPI screen
215  * https://stackoverflow.com/questions/2025282/what-is-the-difference-between-px-dip-dp-and-sp
216  */
217 #define LV_DPX(n)   (n == 0 ? 0 :LV_MATH_MAX((( lv_disp_get_dpi(NULL) * (n) + 80) / 160), 1)) /*+80 for rounding*/
218 
lv_dpx(lv_coord_t n)219 static inline lv_coord_t lv_dpx(lv_coord_t n)
220 {
221     return LV_DPX(n);
222 }
223 
224 #ifdef __cplusplus
225 } /* extern "C" */
226 #endif
227 
228 #endif /*LV_TEMPL_H*/
229