Debian Codegraph @

lvgl/src/draw/nxp/pxp/lv_draw_buf_pxp.c

raw symbols SCIP
1 /**
2 * @file lv_draw_buf_pxp.c
3 *
4 */
5
6 /**
7 * Copyright 2023-2024 NXP
8 *
9 * SPDX-License-Identifier: MIT
10 */
11
12 /*********************
13 * INCLUDES
14 *********************/
15
16 #include "lv_draw_pxp.h"
17
18 #if LV_USE_PXP
19 #if LV_USE_DRAW_PXP
20 #include "../../lv_draw_buf_private.h"
21 #include "lv_pxp_cfg.h"
22 #include "lv_pxp_utils.h"
23
24 #include "lvgl_support.h"
25
26 /*********************
27 * DEFINES
28 *********************/
29
30 /**********************
31 * TYPEDEFS
32 **********************/
33
34 /**********************
35 * STATIC PROTOTYPES
36 **********************/
37
38 static void _invalidate_cache(const lv_draw_buf_t * draw_buf, const lv_area_t * area);
39
40 /**********************
41 * STATIC VARIABLES
42 **********************/
43
44 /**********************
45 * MACROS
46 **********************/
47
48 /**********************
49 * GLOBAL FUNCTIONS
50 **********************/
51
52 void lv_draw_buf_pxp_init_handlers(void)
53 {
54 lv_draw_buf_handlers_t * handlers = lv_draw_buf_get_handlers();
55 lv_draw_buf_handlers_t * font_handlers = lv_draw_buf_get_font_handlers();
56 lv_draw_buf_handlers_t * image_handlers = lv_draw_buf_get_image_handlers();
57
58 handlers->invalidate_cache_cb = _invalidate_cache;
59 font_handlers->invalidate_cache_cb = _invalidate_cache;
60 image_handlers->invalidate_cache_cb = _invalidate_cache;
61 }
62
63 /**********************
64 * STATIC FUNCTIONS
65 **********************/
66
67 static void _invalidate_cache(const lv_draw_buf_t * draw_buf, const lv_area_t * area)
68 {
69 const lv_image_header_t * header = &draw_buf->header;
70 uint32_t stride = header->stride;
71 lv_color_format_t cf = header->cf;
72
73 if(area->y1 == 0) {
74 uint32_t size = stride * lv_area_get_height(area);
75
76 /* Invalidate full buffer. */
77 DEMO_CleanInvalidateCacheByAddr((void *)draw_buf->data, size);
78 return;
79 }
80
81 const uint8_t * buf_u8 = draw_buf->data;
82 /*Cache management requires us to know the cache line size for proper alignment */
83 uint8_t align_bytes = __SCB_DCACHE_LINE_SIZE;
84 uint8_t bits_per_pixel = lv_color_format_get_bpp(cf);
85
86 uint16_t align_pixels = align_bytes * 8 / bits_per_pixel;
87 uint16_t offset_x = 0;
88
89 if(area->x1 >= (int32_t)(area->x1 % align_pixels)) {
90 uint16_t shift_x = area->x1 - (area->x1 % align_pixels);
91
92 offset_x = area->x1 - shift_x;
93 buf_u8 += (shift_x * bits_per_pixel) / 8;
94 }
95
96 if(area->y1) {
97 uint16_t shift_y = area->y1;
98
99 buf_u8 += shift_y * stride;
100 }
101
102 /* Area to clear can start from a different offset in buffer.
103 * Invalidate the area line by line.
104 */
105 uint16_t line_pixels = offset_x + lv_area_get_width(area);
106 uint16_t line_size = (line_pixels * bits_per_pixel) / 8;
107 uint16_t area_height = lv_area_get_height(area);
108
109 for(uint16_t y = 0; y < area_height; y++) {
110 const void * line_addr = buf_u8 + y * stride;
111
112 DEMO_CleanInvalidateCacheByAddr((void *)line_addr, line_size);
113 }
114 }
115
116 #endif /*LV_USE_DRAW_PXP*/
117 #endif /*LV_USE_PXP*/