acid-drop- Hacking the planet from a LilyGo T-Deck using custom firmware |
git clone git://git.acid.vegas/acid-drop.git |
Log | Files | Refs | Archive | README | LICENSE |
lv_hal_disp.h (13733B)
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 /** OPTIONAL: called when start rendering */ 137 void (*render_start_cb)(struct _lv_disp_drv_t * disp_drv); 138 139 /** On CHROMA_KEYED images this color will be transparent. 140 * `LV_COLOR_CHROMA_KEY` by default. (lv_conf.h)*/ 141 lv_color_t color_chroma_key; 142 143 lv_draw_ctx_t * draw_ctx; 144 void (*draw_ctx_init)(struct _lv_disp_drv_t * disp_drv, lv_draw_ctx_t * draw_ctx); 145 void (*draw_ctx_deinit)(struct _lv_disp_drv_t * disp_drv, lv_draw_ctx_t * draw_ctx); 146 size_t draw_ctx_size; 147 148 #if LV_USE_USER_DATA 149 void * user_data; /**< Custom display driver user data*/ 150 #endif 151 152 } lv_disp_drv_t; 153 154 /** 155 * Display structure. 156 * @note `lv_disp_drv_t` should be the first member of the structure. 157 */ 158 typedef struct _lv_disp_t { 159 /**< Driver to the display*/ 160 struct _lv_disp_drv_t * driver; 161 162 /**< A timer which periodically checks the dirty areas and refreshes them*/ 163 lv_timer_t * refr_timer; 164 165 /**< The theme assigned to the screen*/ 166 struct _lv_theme_t * theme; 167 168 /** Screens of the display*/ 169 struct _lv_obj_t ** screens; /**< Array of screen objects.*/ 170 struct _lv_obj_t * act_scr; /**< Currently active screen on this display*/ 171 struct _lv_obj_t * prev_scr; /**< Previous screen. Used during screen animations*/ 172 struct _lv_obj_t * scr_to_load; /**< The screen prepared to load in lv_scr_load_anim*/ 173 struct _lv_obj_t * top_layer; /**< @see lv_disp_get_layer_top*/ 174 struct _lv_obj_t * sys_layer; /**< @see lv_disp_get_layer_sys*/ 175 uint32_t screen_cnt; 176 uint8_t draw_prev_over_act : 177 1; /**< 1: Draw previous screen over active screen*/ 178 uint8_t del_prev : 179 1; /**< 1: Automatically delete the previous screen when the screen load animation is ready*/ 180 uint8_t rendering_in_progress : 1; /**< 1: The current screen rendering is in progress*/ 181 182 lv_opa_t bg_opa; /**<Opacity of the background color or wallpaper*/ 183 lv_color_t bg_color; /**< Default display color when screens are transparent*/ 184 const void * bg_img; /**< An image source to display as wallpaper*/ 185 186 /** Invalidated (marked to redraw) areas*/ 187 lv_area_t inv_areas[LV_INV_BUF_SIZE]; 188 uint8_t inv_area_joined[LV_INV_BUF_SIZE]; 189 uint16_t inv_p; 190 191 /*Miscellaneous data*/ 192 uint32_t last_activity_time; /**< Last time when there was activity on this display*/ 193 } lv_disp_t; 194 195 /********************** 196 * GLOBAL PROTOTYPES 197 **********************/ 198 199 /** 200 * Initialize a display driver with default values. 201 * It is used to have known values in the fields and not junk in memory. 202 * After it you can safely set only the fields you need. 203 * @param driver pointer to driver variable to initialize 204 */ 205 void lv_disp_drv_init(lv_disp_drv_t * driver); 206 207 /** 208 * Initialize a display buffer 209 * @param draw_buf pointer `lv_disp_draw_buf_t` variable to initialize 210 * @param buf1 A buffer to be used by LVGL to draw the image. 211 * Always has to specified and can't be NULL. 212 * Can be an array allocated by the user. E.g. `static lv_color_t disp_buf1[1024 * 10]` 213 * Or a memory address e.g. in external SRAM 214 * @param buf2 Optionally specify a second buffer to make image rendering and image flushing 215 * (sending to the display) parallel. 216 * In the `disp_drv->flush` you should use DMA or similar hardware to send 217 * the image to the display in the background. 218 * It lets LVGL to render next frame into the other buffer while previous is being 219 * sent. Set to `NULL` if unused. 220 * @param size_in_px_cnt size of the `buf1` and `buf2` in pixel count. 221 */ 222 void lv_disp_draw_buf_init(lv_disp_draw_buf_t * draw_buf, void * buf1, void * buf2, uint32_t size_in_px_cnt); 223 224 /** 225 * Register an initialized display driver. 226 * Automatically set the first display as active. 227 * @param driver pointer to an initialized 'lv_disp_drv_t' variable. Only its pointer is saved! 228 * @return pointer to the new display or NULL on error 229 */ 230 lv_disp_t * lv_disp_drv_register(lv_disp_drv_t * driver); 231 232 /** 233 * Update the driver in run time. 234 * @param disp pointer to a display. (return value of `lv_disp_drv_register`) 235 * @param new_drv pointer to the new driver 236 */ 237 void lv_disp_drv_update(lv_disp_t * disp, lv_disp_drv_t * new_drv); 238 239 /** 240 * Remove a display 241 * @param disp pointer to display 242 */ 243 void lv_disp_remove(lv_disp_t * disp); 244 245 /** 246 * Set a default display. The new screens will be created on it by default. 247 * @param disp pointer to a display 248 */ 249 void lv_disp_set_default(lv_disp_t * disp); 250 251 /** 252 * Get the default display 253 * @return pointer to the default display 254 */ 255 lv_disp_t * lv_disp_get_default(void); 256 257 /** 258 * Get the horizontal resolution of a display 259 * @param disp pointer to a display (NULL to use the default display) 260 * @return the horizontal resolution of the display 261 */ 262 lv_coord_t lv_disp_get_hor_res(lv_disp_t * disp); 263 264 /** 265 * Get the vertical resolution of a display 266 * @param disp pointer to a display (NULL to use the default display) 267 * @return the vertical resolution of the display 268 */ 269 lv_coord_t lv_disp_get_ver_res(lv_disp_t * disp); 270 271 /** 272 * Get the full / physical horizontal resolution of a display 273 * @param disp pointer to a display (NULL to use the default display) 274 * @return the full / physical horizontal resolution of the display 275 */ 276 lv_coord_t lv_disp_get_physical_hor_res(lv_disp_t * disp); 277 278 /** 279 * Get the full / physical vertical resolution of a display 280 * @param disp pointer to a display (NULL to use the default display) 281 * @return the full / physical vertical resolution of the display 282 */ 283 lv_coord_t lv_disp_get_physical_ver_res(lv_disp_t * disp); 284 285 /** 286 * Get the horizontal offset from the full / physical display 287 * @param disp pointer to a display (NULL to use the default display) 288 * @return the horizontal offset from the full / physical display 289 */ 290 lv_coord_t lv_disp_get_offset_x(lv_disp_t * disp); 291 292 /** 293 * Get the vertical offset from the full / physical display 294 * @param disp pointer to a display (NULL to use the default display) 295 * @return the horizontal offset from the full / physical display 296 */ 297 lv_coord_t lv_disp_get_offset_y(lv_disp_t * disp); 298 299 /** 300 * Get if anti-aliasing is enabled for a display or not 301 * @param disp pointer to a display (NULL to use the default display) 302 * @return true: anti-aliasing is enabled; false: disabled 303 */ 304 bool lv_disp_get_antialiasing(lv_disp_t * disp); 305 306 /** 307 * Get the DPI of the display 308 * @param disp pointer to a display (NULL to use the default display) 309 * @return dpi of the display 310 */ 311 lv_coord_t lv_disp_get_dpi(const lv_disp_t * disp); 312 313 314 /** 315 * Set the rotation of this display. 316 * @param disp pointer to a display (NULL to use the default display) 317 * @param rotation rotation angle 318 */ 319 void lv_disp_set_rotation(lv_disp_t * disp, lv_disp_rot_t rotation); 320 321 /** 322 * Get the current rotation of this display. 323 * @param disp pointer to a display (NULL to use the default display) 324 * @return rotation angle 325 */ 326 lv_disp_rot_t lv_disp_get_rotation(lv_disp_t * disp); 327 328 //! @cond Doxygen_Suppress 329 330 /** 331 * Call in the display driver's `flush_cb` function when the flushing is finished 332 * @param disp_drv pointer to display driver in `flush_cb` where this function is called 333 */ 334 LV_ATTRIBUTE_FLUSH_READY void lv_disp_flush_ready(lv_disp_drv_t * disp_drv); 335 336 /** 337 * Tell if it's the last area of the refreshing process. 338 * Can be called from `flush_cb` to execute some special display refreshing if needed when all areas area flushed. 339 * @param disp_drv pointer to display driver 340 * @return true: it's the last area to flush; false: there are other areas too which will be refreshed soon 341 */ 342 LV_ATTRIBUTE_FLUSH_READY bool lv_disp_flush_is_last(lv_disp_drv_t * disp_drv); 343 344 //! @endcond 345 346 /** 347 * Get the next display. 348 * @param disp pointer to the current display. NULL to initialize. 349 * @return the next display or NULL if no more. Give the first display when the parameter is NULL 350 */ 351 lv_disp_t * lv_disp_get_next(lv_disp_t * disp); 352 353 /** 354 * Get the internal buffer of a display 355 * @param disp pointer to a display 356 * @return pointer to the internal buffers 357 */ 358 lv_disp_draw_buf_t * lv_disp_get_draw_buf(lv_disp_t * disp); 359 360 void lv_disp_drv_use_generic_set_px_cb(lv_disp_drv_t * disp_drv, lv_img_cf_t cf); 361 362 /********************** 363 * MACROS 364 **********************/ 365 366 #ifdef __cplusplus 367 } /*extern "C"*/ 368 #endif 369 370 #endif