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 "../hal/lv_hal.h"
17 #include "lv_obj.h"
18 #include "lv_theme.h"
19
20 /*********************
21 * DEFINES
22 *********************/
23
24 /**********************
25 * TYPEDEFS
26 **********************/
27
28 typedef enum {
29 LV_SCR_LOAD_ANIM_NONE,
30 LV_SCR_LOAD_ANIM_OVER_LEFT,
31 LV_SCR_LOAD_ANIM_OVER_RIGHT,
32 LV_SCR_LOAD_ANIM_OVER_TOP,
33 LV_SCR_LOAD_ANIM_OVER_BOTTOM,
34 LV_SCR_LOAD_ANIM_MOVE_LEFT,
35 LV_SCR_LOAD_ANIM_MOVE_RIGHT,
36 LV_SCR_LOAD_ANIM_MOVE_TOP,
37 LV_SCR_LOAD_ANIM_MOVE_BOTTOM,
38 LV_SCR_LOAD_ANIM_FADE_IN,
39 LV_SCR_LOAD_ANIM_FADE_ON = LV_SCR_LOAD_ANIM_FADE_IN, /*For backward compatibility*/
40 LV_SCR_LOAD_ANIM_FADE_OUT,
41 LV_SCR_LOAD_ANIM_OUT_LEFT,
42 LV_SCR_LOAD_ANIM_OUT_RIGHT,
43 LV_SCR_LOAD_ANIM_OUT_TOP,
44 LV_SCR_LOAD_ANIM_OUT_BOTTOM,
45 } lv_scr_load_anim_t;
46
47 /**********************
48 * GLOBAL PROTOTYPES
49 **********************/
50
51 /**
52 * Return with a pointer to the active screen
53 * @param disp pointer to display which active screen should be get. (NULL to use the default
54 * screen)
55 * @return pointer to the active screen object (loaded by 'lv_scr_load()')
56 */
57 lv_obj_t * lv_disp_get_scr_act(lv_disp_t * disp);
58
59 /**
60 * Return with a pointer to the previous screen. Only used during screen transitions.
61 * @param disp pointer to display which previous screen should be get. (NULL to use the default
62 * screen)
63 * @return pointer to the previous screen object or NULL if not used now
64 */
65 lv_obj_t * lv_disp_get_scr_prev(lv_disp_t * disp);
66
67 /**
68 * Make a screen active
69 * @param scr pointer to a screen
70 */
71 void lv_disp_load_scr(lv_obj_t * scr);
72
73 /**
74 * Return with the top layer. (Same on every screen and it is above the normal screen layer)
75 * @param disp pointer to display which top layer should be get. (NULL to use the default screen)
76 * @return pointer to the top layer object (transparent screen sized lv_obj)
77 */
78 lv_obj_t * lv_disp_get_layer_top(lv_disp_t * disp);
79
80 /**
81 * Return with the sys. layer. (Same on every screen and it is above the normal screen and the top
82 * layer)
83 * @param disp pointer to display which sys. layer should be retrieved. (NULL to use the default screen)
84 * @return pointer to the sys layer object (transparent screen sized lv_obj)
85 */
86 lv_obj_t * lv_disp_get_layer_sys(lv_disp_t * disp);
87
88 /**
89 * Set the theme of a display
90 * @param disp pointer to a display
91 */
92 void lv_disp_set_theme(lv_disp_t * disp, lv_theme_t * th);
93
94 /**
95 * Get the theme of a display
96 * @param disp pointer to a display
97 * @return the display's theme (can be NULL)
98 */
99 lv_theme_t * lv_disp_get_theme(lv_disp_t * disp);
100
101 /**
102 * Set the background color of a display
103 * @param disp pointer to a display
104 * @param color color of the background
105 */
106 void lv_disp_set_bg_color(lv_disp_t * disp, lv_color_t color);
107
108 /**
109 * Set the background image of a display
110 * @param disp pointer to a display
111 * @param img_src path to file or pointer to an `lv_img_dsc_t` variable
112 */
113 void lv_disp_set_bg_image(lv_disp_t * disp, const void * img_src);
114
115 /**
116 * Set opacity of the background
117 * @param disp pointer to a display
118 * @param opa opacity (0..255)
119 */
120 void lv_disp_set_bg_opa(lv_disp_t * disp, lv_opa_t opa);
121
122 /**
123 * Switch screen with animation
124 * @param scr pointer to the new screen to load
125 * @param anim_type type of the animation from `lv_scr_load_anim_t`, e.g. `LV_SCR_LOAD_ANIM_MOVE_LEFT`
126 * @param time time of the animation
127 * @param delay delay before the transition
128 * @param auto_del true: automatically delete the old screen
129 */
130 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);
131
132 /**
133 * Get elapsed time since last user activity on a display (e.g. click)
134 * @param disp pointer to a display (NULL to get the overall smallest inactivity)
135 * @return elapsed ticks (milliseconds) since the last activity
136 */
137 uint32_t lv_disp_get_inactive_time(const lv_disp_t * disp);
138
139 /**
140 * Manually trigger an activity on a display
141 * @param disp pointer to a display (NULL to use the default display)
142 */
143 void lv_disp_trig_activity(lv_disp_t * disp);
144
145 /**
146 * Clean any CPU cache that is related to the display.
147 * @param disp pointer to a display (NULL to use the default display)
148 */
149 void lv_disp_clean_dcache(lv_disp_t * disp);
150
151 /**
152 * Temporarily enable and disable the invalidation of the display.
153 * @param disp pointer to a display (NULL to use the default display)
154 * @param en true: enable invalidation; false: invalidation
155 */
156 void lv_disp_enable_invalidation(lv_disp_t * disp, bool en);
157
158 /**
159 * Get display invalidation is enabled.
160 * @param disp pointer to a display (NULL to use the default display)
161 * @return return true if invalidation is enabled
162 */
163 bool lv_disp_is_invalidation_enabled(lv_disp_t * disp);
164
165 /**
166 * Get a pointer to the screen refresher timer to
167 * modify its parameters with `lv_timer_...` functions.
168 * @param disp pointer to a display
169 * @return pointer to the display refresher timer. (NULL on error)
170 */
171 lv_timer_t * _lv_disp_get_refr_timer(lv_disp_t * disp);
172
173 /*------------------------------------------------
174 * To improve backward compatibility
175 * Recommended only if you have one display
176 *------------------------------------------------*/
177
178 /**
179 * Get the active screen of the default display
180 * @return pointer to the active screen
181 */
lv_scr_act(void)182 static inline lv_obj_t * lv_scr_act(void)
183 {
184 return lv_disp_get_scr_act(lv_disp_get_default());
185 }
186
187 /**
188 * Get the top layer of the default display
189 * @return pointer to the top layer
190 */
lv_layer_top(void)191 static inline lv_obj_t * lv_layer_top(void)
192 {
193 return lv_disp_get_layer_top(lv_disp_get_default());
194 }
195
196 /**
197 * Get the active screen of the default display
198 * @return pointer to the sys layer
199 */
lv_layer_sys(void)200 static inline lv_obj_t * lv_layer_sys(void)
201 {
202 return lv_disp_get_layer_sys(lv_disp_get_default());
203 }
204
lv_scr_load(lv_obj_t * scr)205 static inline void lv_scr_load(lv_obj_t * scr)
206 {
207 lv_disp_load_scr(scr);
208 }
209
210 /**********************
211 * MACROS
212 **********************/
213
214 /*------------------------------------------------
215 * To improve backward compatibility
216 * Recommended only if you have one display
217 *------------------------------------------------*/
218
219 #ifndef LV_HOR_RES
220 /**
221 * The horizontal resolution of the currently active display.
222 */
223 #define LV_HOR_RES lv_disp_get_hor_res(lv_disp_get_default())
224 #endif
225
226 #ifndef LV_VER_RES
227 /**
228 * The vertical resolution of the currently active display.
229 */
230 #define LV_VER_RES lv_disp_get_ver_res(lv_disp_get_default())
231 #endif
232
233 /**
234 * Scale the given number of pixels (a distance or size) relative to a 160 DPI display
235 * considering the DPI of the default display.
236 * It ensures that e.g. `lv_dpx(100)` will have the same physical size regardless to the
237 * DPI of the display.
238 * @param n the number of pixels to scale
239 * @return `n x current_dpi/160`
240 */
lv_dpx(lv_coord_t n)241 static inline lv_coord_t lv_dpx(lv_coord_t n)
242 {
243 return LV_DPX(n);
244 }
245
246 /**
247 * Scale the given number of pixels (a distance or size) relative to a 160 DPI display
248 * considering the DPI of the given display.
249 * It ensures that e.g. `lv_dpx(100)` will have the same physical size regardless to the
250 * DPI of the display.
251 * @param obj a display whose dpi should be considered
252 * @param n the number of pixels to scale
253 * @return `n x current_dpi/160`
254 */
lv_disp_dpx(const lv_disp_t * disp,lv_coord_t n)255 static inline lv_coord_t lv_disp_dpx(const lv_disp_t * disp, lv_coord_t n)
256 {
257 return _LV_DPX_CALC(lv_disp_get_dpi(disp), n);
258 }
259
260 #ifdef __cplusplus
261 } /*extern "C"*/
262 #endif
263
264 #endif /*LV_DISP_H*/
265