1 /**
2 * @file lv_nuttx_cache.c
3 *
4 */
5
6 /*********************
7 * INCLUDES
8 *********************/
9
10 #include "lv_nuttx_cache.h"
11 #include "../../../lvgl.h"
12
13 #if LV_USE_NUTTX
14
15 #include "../../draw/lv_draw_buf_private.h"
16 #include <nuttx/cache.h>
17
18 /*********************
19 * DEFINES
20 *********************/
21
22 /**********************
23 * TYPEDEFS
24 **********************/
25
26 /**********************
27 * STATIC PROTOTYPES
28 **********************/
29
30 static void invalidate_cache(const lv_draw_buf_t * draw_buf, const lv_area_t * area);
31 static void flush_cache(const lv_draw_buf_t * draw_buf, const lv_area_t * area);
32
33 /**********************
34 * STATIC VARIABLES
35 **********************/
36
37 /**********************
38 * MACROS
39 **********************/
40
41 /**********************
42 * GLOBAL FUNCTIONS
43 **********************/
44
lv_nuttx_cache_init(void)45 void lv_nuttx_cache_init(void)
46 {
47 lv_draw_buf_handlers_t * handlers = lv_draw_buf_get_handlers();
48 handlers->invalidate_cache_cb = invalidate_cache;
49 handlers->flush_cache_cb = flush_cache;
50 }
51
lv_nuttx_cache_deinit(void)52 void lv_nuttx_cache_deinit(void)
53 {
54 lv_draw_buf_handlers_t * handlers = lv_draw_buf_get_handlers();
55 handlers->invalidate_cache_cb = NULL;
56 handlers->flush_cache_cb = NULL;
57 }
58
59 /**********************
60 * STATIC FUNCTIONS
61 **********************/
62
draw_buf_to_region(const lv_draw_buf_t * draw_buf,const lv_area_t * area,lv_uintptr_t * start,lv_uintptr_t * end)63 static void draw_buf_to_region(
64 const lv_draw_buf_t * draw_buf, const lv_area_t * area,
65 lv_uintptr_t * start, lv_uintptr_t * end)
66 {
67 LV_ASSERT_NULL(draw_buf);
68 LV_ASSERT_NULL(area);
69 LV_ASSERT_NULL(start);
70 LV_ASSERT_NULL(end);
71
72 void * buf = draw_buf->data;
73 uint32_t stride = draw_buf->header.stride;
74
75 int32_t h = lv_area_get_height(area);
76 *start = (lv_uintptr_t)buf + area->y1 * stride;
77 *end = *start + h * stride;
78 }
79
invalidate_cache(const lv_draw_buf_t * draw_buf,const lv_area_t * area)80 static void invalidate_cache(const lv_draw_buf_t * draw_buf, const lv_area_t * area)
81 {
82 lv_uintptr_t start;
83 lv_uintptr_t end;
84 draw_buf_to_region(draw_buf, area, &start, &end);
85 up_invalidate_dcache(start, end);
86 }
87
flush_cache(const lv_draw_buf_t * draw_buf,const lv_area_t * area)88 static void flush_cache(const lv_draw_buf_t * draw_buf, const lv_area_t * area)
89 {
90 lv_uintptr_t start;
91 lv_uintptr_t end;
92 draw_buf_to_region(draw_buf, area, &start, &end);
93 up_flush_dcache(start, end);
94 }
95
96 #endif /* LV_USE_NUTTX */
97