Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
CTCaer
GitHub Repository: CTCaer/hekate
Path: blob/master/bdk/libs/lvgl/lv_hal/lv_hal_disp.c
1476 views
1
2
/**
3
* @file hal_disp.c
4
*
5
* @description HAL layer for display driver
6
*
7
*/
8
9
/*********************
10
* INCLUDES
11
*********************/
12
#include <stdint.h>
13
#include <stddef.h>
14
#include "../lv_hal/lv_hal_disp.h"
15
#include "../lv_misc/lv_mem.h"
16
#include "../lv_core/lv_obj.h"
17
#include "../lv_misc/lv_gc.h"
18
19
#if defined(LV_GC_INCLUDE)
20
# include LV_GC_INCLUDE
21
#endif /* LV_ENABLE_GC */
22
23
24
/*********************
25
* DEFINES
26
*********************/
27
28
/**********************
29
* TYPEDEFS
30
**********************/
31
32
/**********************
33
* STATIC PROTOTYPES
34
**********************/
35
36
/**********************
37
* STATIC VARIABLES
38
**********************/
39
static lv_disp_t * active;
40
41
/**********************
42
* MACROS
43
**********************/
44
45
/**********************
46
* GLOBAL FUNCTIONS
47
**********************/
48
49
/**
50
* Initialize a display driver with default values.
51
* It is used to surly have known values in the fields ant not memory junk.
52
* After it you can set the fields.
53
* @param driver pointer to driver variable to initialize
54
*/
55
void lv_disp_drv_init(lv_disp_drv_t * driver)
56
{
57
driver->disp_fill = NULL;
58
driver->disp_map = NULL;
59
driver->disp_flush = NULL;
60
61
#if USE_LV_GPU
62
driver->mem_blend = NULL;
63
driver->mem_fill = NULL;
64
#endif
65
66
#if LV_VDB_SIZE
67
driver->vdb_wr = NULL;
68
#endif
69
}
70
71
/**
72
* Register an initialized display driver.
73
* Automatically set the first display as active.
74
* @param driver pointer to an initialized 'lv_disp_drv_t' variable (can be local variable)
75
* @return pointer to the new display or NULL on error
76
*/
77
lv_disp_t * lv_disp_drv_register(lv_disp_drv_t * driver)
78
{
79
lv_disp_t * node;
80
81
node = lv_mem_alloc(sizeof(lv_disp_t));
82
lv_mem_assert(node);
83
if(node == NULL) return NULL;
84
85
memcpy(&node->driver, driver, sizeof(lv_disp_drv_t));
86
node->next = NULL;
87
88
/* Set first display as active by default */
89
if(LV_GC_ROOT(_lv_disp_list) == NULL) {
90
LV_GC_ROOT(_lv_disp_list) = node;
91
active = node;
92
lv_obj_invalidate(lv_scr_act());
93
} else {
94
((lv_disp_t*)LV_GC_ROOT(_lv_disp_list))->next = node;
95
}
96
97
return node;
98
}
99
100
101
/**
102
* Set the active display
103
* @param disp pointer to a display (return value of 'lv_disp_register')
104
*/
105
void lv_disp_set_active(lv_disp_t * disp)
106
{
107
active = disp;
108
lv_obj_invalidate(lv_scr_act());
109
}
110
111
/**
112
* Get a pointer to the active display
113
* @return pointer to the active display
114
*/
115
lv_disp_t * lv_disp_get_active(void)
116
{
117
return active;
118
}
119
120
/**
121
* Get the next display.
122
* @param disp pointer to the current display. NULL to initialize.
123
* @return the next display or NULL if no more. Give the first display when the parameter is NULL
124
*/
125
lv_disp_t * lv_disp_next(lv_disp_t * disp)
126
{
127
if(disp == NULL) {
128
return LV_GC_ROOT(_lv_disp_list);
129
} else {
130
if(((lv_disp_t*)LV_GC_ROOT(_lv_disp_list))->next == NULL) return NULL;
131
else return ((lv_disp_t*)LV_GC_ROOT(_lv_disp_list))->next;
132
}
133
}
134
135
/**
136
* Write the content of the internal buffer (VDB) to the display
137
* @param x1 left coordinate of the rectangle
138
* @param x2 right coordinate of the rectangle
139
* @param y1 top coordinate of the rectangle
140
* @param y2 bottom coordinate of the rectangle
141
* @param color_p fill color
142
*/
143
void lv_disp_fill(int32_t x1, int32_t y1, int32_t x2, int32_t y2, lv_color_t color)
144
{
145
if(active == NULL) return;
146
if(active->driver.disp_fill != NULL) active->driver.disp_fill(x1, y1, x2, y2, color);
147
}
148
149
/**
150
* Fill a rectangular area with a color on the active display
151
* @param x1 left coordinate of the rectangle
152
* @param x2 right coordinate of the rectangle
153
* @param y1 top coordinate of the rectangle
154
* @param y2 bottom coordinate of the rectangle
155
* @param color_p pointer to an array of colors
156
*/
157
void lv_disp_flush(int32_t x1, int32_t y1, int32_t x2, int32_t y2, lv_color_t * color_p)
158
{
159
if(active == NULL) return;
160
if(active->driver.disp_flush != NULL) {
161
162
LV_LOG_TRACE("disp flush started");
163
active->driver.disp_flush(x1, y1, x2, y2, color_p);
164
LV_LOG_TRACE("disp flush ready");
165
166
} else {
167
LV_LOG_WARN("disp flush function registered");
168
}
169
}
170
171
/**
172
* Put a color map to a rectangular area on the active display
173
* @param x1 left coordinate of the rectangle
174
* @param x2 right coordinate of the rectangle
175
* @param y1 top coordinate of the rectangle
176
* @param y2 bottom coordinate of the rectangle
177
* @param color_map pointer to an array of colors
178
*/
179
void lv_disp_map(int32_t x1, int32_t y1, int32_t x2, int32_t y2, const lv_color_t * color_map)
180
{
181
if(active == NULL) return;
182
if(active->driver.disp_map != NULL) active->driver.disp_map(x1, y1, x2, y2, color_map);
183
}
184
185
#if USE_LV_GPU
186
187
/**
188
* Blend pixels to a destination memory from a source memory
189
* In 'lv_disp_drv_t' 'mem_blend' is optional. (NULL if not available)
190
* @param dest a memory address. Blend 'src' here.
191
* @param src pointer to pixel map. Blend it to 'dest'.
192
* @param length number of pixels in 'src'
193
* @param opa opacity (0, LV_OPA_TRANSP: transparent ... 255, LV_OPA_COVER, fully cover)
194
*/
195
void lv_disp_mem_blend(lv_color_t * dest, const lv_color_t * src, uint32_t length, lv_opa_t opa)
196
{
197
if(active == NULL) return;
198
if(active->driver.mem_blend != NULL) active->driver.mem_blend(dest, src, length, opa);
199
}
200
201
/**
202
* Fill a memory with a color (GPUs may support it)
203
* In 'lv_disp_drv_t' 'mem_fill' is optional. (NULL if not available)
204
* @param dest a memory address. Copy 'src' here.
205
* @param src pointer to pixel map. Copy it to 'dest'.
206
* @param length number of pixels in 'src'
207
* @param opa opacity (0, LV_OPA_TRANSP: transparent ... 255, LV_OPA_COVER, fully cover)
208
*/
209
void lv_disp_mem_fill(lv_color_t * dest, uint32_t length, lv_color_t color)
210
{
211
if(active == NULL) return;
212
if(active->driver.mem_fill != NULL) active->driver.mem_fill(dest, length, color);
213
}
214
215
/**
216
* Shows if memory blending (by GPU) is supported or not
217
* @return false: 'mem_blend' is not supported in the driver; true: 'mem_blend' is supported in the driver
218
*/
219
bool lv_disp_is_mem_blend_supported(void)
220
{
221
if(active == NULL) return false;
222
if(active->driver.mem_blend) return true;
223
else return false;
224
}
225
226
/**
227
* Shows if memory fill (by GPU) is supported or not
228
* @return false: 'mem_fill' is not supported in the drover; true: 'mem_fill' is supported in the driver
229
*/
230
bool lv_disp_is_mem_fill_supported(void)
231
{
232
if(active == NULL) return false;
233
if(active->driver.mem_fill) return true;
234
else return false;
235
}
236
237
#endif
238
239
/**********************
240
* STATIC FUNCTIONS
241
**********************/
242
243
244