1 /** 2 * @file lv_hal_disp.h 3 * 4 * @description Display Driver HAL interface header file 5 * 6 */ 7 8 #ifndef LV_HAL_DISP_H 9 #define LV_HAL_DISP_H 10 11 #ifdef __cplusplus 12 extern "C" { 13 #endif 14 15 /********************* 16 * INCLUDES 17 *********************/ 18 #include <stdint.h> 19 #include <stdbool.h> 20 #include "lv_hal.h" 21 #include "../draw/lv_draw.h" 22 #include "../misc/lv_color.h" 23 #include "../misc/lv_area.h" 24 #include "../misc/lv_ll.h" 25 #include "../misc/lv_timer.h" 26 27 /********************* 28 * DEFINES 29 *********************/ 30 #ifndef LV_INV_BUF_SIZE 31 #define LV_INV_BUF_SIZE 32 /*Buffer size for invalid areas*/ 32 #endif 33 34 #ifndef LV_ATTRIBUTE_FLUSH_READY 35 #define LV_ATTRIBUTE_FLUSH_READY 36 #endif 37 38 /********************** 39 * TYPEDEFS 40 **********************/ 41 42 struct _lv_obj_t; 43 struct _lv_disp_t; 44 struct _lv_disp_drv_t; 45 struct _lv_theme_t; 46 47 /** 48 * Structure for holding display buffer information. 49 */ 50 typedef struct _lv_disp_draw_buf_t { 51 void * buf1; /**< First display buffer.*/ 52 void * buf2; /**< Second display buffer.*/ 53 54 /*Internal, used by the library*/ 55 void * buf_act; 56 uint32_t size; /*In pixel count*/ 57 /*1: flushing is in progress. (It can't be a bit field because when it's cleared from IRQ Read-Modify-Write issue might occur)*/ 58 volatile int flushing; 59 /*1: It was the last chunk to flush. (It can't be a bit field because when it's cleared from IRQ Read-Modify-Write issue might occur)*/ 60 volatile int flushing_last; 61 volatile uint32_t last_area : 1; /*1: the last area is being rendered*/ 62 volatile uint32_t last_part : 1; /*1: the last part of the current area is being rendered*/ 63 } lv_disp_draw_buf_t; 64 65 typedef enum { 66 LV_DISP_ROT_NONE = 0, 67 LV_DISP_ROT_90, 68 LV_DISP_ROT_180, 69 LV_DISP_ROT_270 70 } lv_disp_rot_t; 71 72 /** 73 * Display Driver structure to be registered by HAL. 74 * Only its pointer will be saved in `lv_disp_t` so it should be declared as 75 * `static lv_disp_drv_t my_drv` or allocated dynamically. 76 */ 77 typedef struct _lv_disp_drv_t { 78 79 lv_coord_t hor_res; /**< Horizontal resolution.*/ 80 lv_coord_t ver_res; /**< Vertical resolution.*/ 81 82 lv_coord_t 83 physical_hor_res; /**< Horizontal resolution of the full / physical display. Set to -1 for fullscreen mode.*/ 84 lv_coord_t 85 physical_ver_res; /**< Vertical resolution of the full / physical display. Set to -1 for fullscreen mode.*/ 86 lv_coord_t 87 offset_x; /**< Horizontal offset from the full / physical display. Set to 0 for fullscreen mode.*/ 88 lv_coord_t offset_y; /**< Vertical offset from the full / physical display. Set to 0 for fullscreen mode.*/ 89 90 /** Pointer to a buffer initialized with `lv_disp_draw_buf_init()`. 91 * LVGL will use this buffer(s) to draw the screens contents*/ 92 lv_disp_draw_buf_t * draw_buf; 93 94 uint32_t direct_mode : 1; /**< 1: Use screen-sized buffers and draw to absolute coordinates*/ 95 uint32_t full_refresh : 1; /**< 1: Always make the whole screen redrawn*/ 96 uint32_t sw_rotate : 1; /**< 1: use software rotation (slower)*/ 97 uint32_t antialiasing : 1; /**< 1: anti-aliasing is enabled on this display.*/ 98 uint32_t rotated : 2; /**< 1: turn the display by 90 degree. @warning Does not update coordinates for you!*/ 99 uint32_t screen_transp : 1; /**Handle if the screen doesn't have a solid (opa == LV_OPA_COVER) background. 100 * Use only if required because it's slower.*/ 101 102 uint32_t dpi : 10; /** DPI (dot per inch) of the display. Default value is `LV_DPI_DEF`.*/ 103 104 /** MANDATORY: Write the internal buffer (draw_buf) to the display. 'lv_disp_flush_ready()' has to be 105 * called when finished*/ 106 void (*flush_cb)(struct _lv_disp_drv_t * disp_drv, const lv_area_t * area, lv_color_t * color_p); 107 108 /** OPTIONAL: Extend the invalidated areas to match with the display drivers requirements 109 * E.g. round `y` to, 8, 16 ..) on a monochrome display*/ 110 void (*rounder_cb)(struct _lv_disp_drv_t * disp_drv, lv_area_t * area); 111 112 /** OPTIONAL: Set a pixel in a buffer according to the special requirements of the display 113 * Can be used for color format not supported in LittelvGL. E.g. 2 bit -> 4 gray scales 114 * @note Much slower then drawing with supported color formats.*/ 115 void (*set_px_cb)(struct _lv_disp_drv_t * disp_drv, uint8_t * buf, lv_coord_t buf_w, lv_coord_t x, lv_coord_t y, 116 lv_color_t color, lv_opa_t opa); 117 118 void (*clear_cb)(struct _lv_disp_drv_t * disp_drv, uint8_t * buf, uint32_t size); 119 120 121 /** OPTIONAL: Called after every refresh cycle to tell the rendering and flushing time + the 122 * number of flushed pixels*/ 123 void (*monitor_cb)(struct _lv_disp_drv_t * disp_drv, uint32_t time, uint32_t px); 124 125 /** OPTIONAL: Called periodically while lvgl waits for operation to be completed. 126 * For example flushing or GPU 127 * User can execute very simple tasks here or yield the task*/ 128 void (*wait_cb)(struct _lv_disp_drv_t * disp_drv); 129 130 /** OPTIONAL: Called when lvgl needs any CPU cache that affects rendering to be cleaned*/ 131 void (*clean_dcache_cb)(struct _lv_disp_drv_t * disp_drv); 132 133 /** OPTIONAL: called when driver parameters are updated */ 134 void (*drv_update_cb)(struct _lv_disp_drv_t * disp_drv); 135 136 /** On CHROMA_KEYED images this color will be transparent. 137 * `LV_COLOR_CHROMA_KEY` by default. (lv_conf.h)*/ 138 lv_color_t color_chroma_key; 139 140 lv_draw_ctx_t * draw_ctx; 141 void (*draw_ctx_init)(struct _lv_disp_drv_t * disp_drv, lv_draw_ctx_t * draw_ctx); 142 void (*draw_ctx_deinit)(struct _lv_disp_drv_t * disp_drv, lv_draw_ctx_t * draw_ctx); 143 size_t draw_ctx_size; 144 145 #if LV_USE_USER_DATA 146 void * user_data; /**< Custom display driver user data*/ 147 #endif 148 149 } lv_disp_drv_t; 150 151 /** 152 * Display structure. 153 * @note `lv_disp_drv_t` should be the first member of the structure. 154 */ 155 typedef struct _lv_disp_t { 156 /**< Driver to the display*/ 157 struct _lv_disp_drv_t * driver; 158 159 /**< A timer which periodically checks the dirty areas and refreshes them*/ 160 lv_timer_t * refr_timer; 161 162 /**< The theme assigned to the screen*/ 163 struct _lv_theme_t * theme; 164 165 /** Screens of the display*/ 166 struct _lv_obj_t ** screens; /**< Array of screen objects.*/ 167 struct _lv_obj_t * act_scr; /**< Currently active screen on this display*/ 168 struct _lv_obj_t * prev_scr; /**< Previous screen. Used during screen animations*/ 169 struct _lv_obj_t * scr_to_load; /**< The screen prepared to load in lv_scr_load_anim*/ 170 struct _lv_obj_t * top_layer; /**< @see lv_disp_get_layer_top*/ 171 struct _lv_obj_t * sys_layer; /**< @see lv_disp_get_layer_sys*/ 172 uint32_t screen_cnt; 173 uint8_t del_prev : 174 1; /**< 1: Automatically delete the previous screen when the screen load animation is ready*/ 175 176 lv_opa_t bg_opa; /**<Opacity of the background color or wallpaper*/ 177 lv_color_t bg_color; /**< Default display color when screens are transparent*/ 178 const void * bg_img; /**< An image source to display as wallpaper*/ 179 180 /** Invalidated (marked to redraw) areas*/ 181 lv_area_t inv_areas[LV_INV_BUF_SIZE]; 182 uint8_t inv_area_joined[LV_INV_BUF_SIZE]; 183 uint16_t inv_p; 184 185 /*Miscellaneous data*/ 186 uint32_t last_activity_time; /**< Last time when there was activity on this display*/ 187 } lv_disp_t; 188 189 /********************** 190 * GLOBAL PROTOTYPES 191 **********************/ 192 193 /** 194 * Initialize a display driver with default values. 195 * It is used to have known values in the fields and not junk in memory. 196 * After it you can safely set only the fields you need. 197 * @param driver pointer to driver variable to initialize 198 */ 199 void lv_disp_drv_init(lv_disp_drv_t * driver); 200 201 /** 202 * Initialize a display buffer 203 * @param draw_buf pointer `lv_disp_draw_buf_t` variable to initialize 204 * @param buf1 A buffer to be used by LVGL to draw the image. 205 * Always has to specified and can't be NULL. 206 * Can be an array allocated by the user. E.g. `static lv_color_t disp_buf1[1024 * 10]` 207 * Or a memory address e.g. in external SRAM 208 * @param buf2 Optionally specify a second buffer to make image rendering and image flushing 209 * (sending to the display) parallel. 210 * In the `disp_drv->flush` you should use DMA or similar hardware to send 211 * the image to the display in the background. 212 * It lets LVGL to render next frame into the other buffer while previous is being 213 * sent. Set to `NULL` if unused. 214 * @param size_in_px_cnt size of the `buf1` and `buf2` in pixel count. 215 */ 216 void lv_disp_draw_buf_init(lv_disp_draw_buf_t * draw_buf, void * buf1, void * buf2, uint32_t size_in_px_cnt); 217 218 /** 219 * Register an initialized display driver. 220 * Automatically set the first display as active. 221 * @param driver pointer to an initialized 'lv_disp_drv_t' variable. Only its pointer is saved! 222 * @return pointer to the new display or NULL on error 223 */ 224 lv_disp_t * lv_disp_drv_register(lv_disp_drv_t * driver); 225 226 /** 227 * Update the driver in run time. 228 * @param disp pointer to a display. (return value of `lv_disp_drv_register`) 229 * @param new_drv pointer to the new driver 230 */ 231 void lv_disp_drv_update(lv_disp_t * disp, lv_disp_drv_t * new_drv); 232 233 /** 234 * Remove a display 235 * @param disp pointer to display 236 */ 237 void lv_disp_remove(lv_disp_t * disp); 238 239 /** 240 * Set a default display. The new screens will be created on it by default. 241 * @param disp pointer to a display 242 */ 243 void lv_disp_set_default(lv_disp_t * disp); 244 245 /** 246 * Get the default display 247 * @return pointer to the default display 248 */ 249 lv_disp_t * lv_disp_get_default(void); 250 251 /** 252 * Get the horizontal resolution of a display 253 * @param disp pointer to a display (NULL to use the default display) 254 * @return the horizontal resolution of the display 255 */ 256 lv_coord_t lv_disp_get_hor_res(lv_disp_t * disp); 257 258 /** 259 * Get the vertical resolution of a display 260 * @param disp pointer to a display (NULL to use the default display) 261 * @return the vertical resolution of the display 262 */ 263 lv_coord_t lv_disp_get_ver_res(lv_disp_t * disp); 264 265 /** 266 * Get the full / physical horizontal resolution of a display 267 * @param disp pointer to a display (NULL to use the default display) 268 * @return the full / physical horizontal resolution of the display 269 */ 270 lv_coord_t lv_disp_get_physical_hor_res(lv_disp_t * disp); 271 272 /** 273 * Get the full / physical vertical resolution of a display 274 * @param disp pointer to a display (NULL to use the default display) 275 * @return the full / physical vertical resolution of the display 276 */ 277 lv_coord_t lv_disp_get_physical_ver_res(lv_disp_t * disp); 278 279 /** 280 * Get the horizontal offset from the full / physical display 281 * @param disp pointer to a display (NULL to use the default display) 282 * @return the horizontal offset from the full / physical display 283 */ 284 lv_coord_t lv_disp_get_offset_x(lv_disp_t * disp); 285 286 /** 287 * Get the vertical offset from the full / physical display 288 * @param disp pointer to a display (NULL to use the default display) 289 * @return the horizontal offset from the full / physical display 290 */ 291 lv_coord_t lv_disp_get_offset_y(lv_disp_t * disp); 292 293 /** 294 * Get if anti-aliasing is enabled for a display or not 295 * @param disp pointer to a display (NULL to use the default display) 296 * @return true: anti-aliasing is enabled; false: disabled 297 */ 298 bool lv_disp_get_antialiasing(lv_disp_t * disp); 299 300 /** 301 * Get the DPI of the display 302 * @param disp pointer to a display (NULL to use the default display) 303 * @return dpi of the display 304 */ 305 lv_coord_t lv_disp_get_dpi(const lv_disp_t * disp); 306 307 308 /** 309 * Set the rotation of this display. 310 * @param disp pointer to a display (NULL to use the default display) 311 * @param rotation rotation angle 312 */ 313 void lv_disp_set_rotation(lv_disp_t * disp, lv_disp_rot_t rotation); 314 315 /** 316 * Get the current rotation of this display. 317 * @param disp pointer to a display (NULL to use the default display) 318 * @return rotation angle 319 */ 320 lv_disp_rot_t lv_disp_get_rotation(lv_disp_t * disp); 321 322 //! @cond Doxygen_Suppress 323 324 /** 325 * Call in the display driver's `flush_cb` function when the flushing is finished 326 * @param disp_drv pointer to display driver in `flush_cb` where this function is called 327 */ 328 LV_ATTRIBUTE_FLUSH_READY void lv_disp_flush_ready(lv_disp_drv_t * disp_drv); 329 330 /** 331 * Tell if it's the last area of the refreshing process. 332 * Can be called from `flush_cb` to execute some special display refreshing if needed when all areas area flushed. 333 * @param disp_drv pointer to display driver 334 * @return true: it's the last area to flush; false: there are other areas too which will be refreshed soon 335 */ 336 LV_ATTRIBUTE_FLUSH_READY bool lv_disp_flush_is_last(lv_disp_drv_t * disp_drv); 337 338 //! @endcond 339 340 /** 341 * Get the next display. 342 * @param disp pointer to the current display. NULL to initialize. 343 * @return the next display or NULL if no more. Give the first display when the parameter is NULL 344 */ 345 lv_disp_t * lv_disp_get_next(lv_disp_t * disp); 346 347 /** 348 * Get the internal buffer of a display 349 * @param disp pointer to a display 350 * @return pointer to the internal buffers 351 */ 352 lv_disp_draw_buf_t * lv_disp_get_draw_buf(lv_disp_t * disp); 353 354 void lv_disp_drv_use_generic_set_px_cb(lv_disp_drv_t * disp_drv, lv_img_cf_t cf); 355 356 /********************** 357 * MACROS 358 **********************/ 359 360 #ifdef __cplusplus 361 } /*extern "C"*/ 362 #endif 363 364 #endif 365