1
1
#include <stdlib.h>
2
2
#include "dji_display.h"
3
+ #include "util/debug.h"
3
4
4
5
#define GOGGLES_V1_VOFFSET 575
5
6
#define GOGGLES_V2_VOFFSET 215
6
7
7
- static duss_result_t pop_func (duss_disp_instance_handle_t * disp_handle ,duss_disp_plane_id_t plane_id , duss_frame_buffer_t * frame_buffer ,void * user_ctx ) {
8
- return 0 ;
9
- }
10
-
11
8
dji_display_state_t * dji_display_state_alloc (uint8_t is_v2_goggles ) {
12
9
dji_display_state_t * display_state = calloc (1 , sizeof (dji_display_state_t ));
13
10
display_state -> disp_instance_handle = (duss_disp_instance_handle_t * )calloc (1 , sizeof (duss_disp_instance_handle_t ));
14
11
display_state -> fb_0 = (duss_frame_buffer_t * )calloc (1 ,sizeof (duss_frame_buffer_t ));
15
12
display_state -> fb_1 = (duss_frame_buffer_t * )calloc (1 ,sizeof (duss_frame_buffer_t ));
16
13
display_state -> pb_0 = (duss_disp_plane_blending_t * )calloc (1 , sizeof (duss_disp_plane_blending_t ));
17
14
display_state -> is_v2_goggles = is_v2_goggles ;
15
+ display_state -> frame_drawn = 0 ;
18
16
return display_state ;
19
17
}
20
18
@@ -27,7 +25,6 @@ void dji_display_state_free(dji_display_state_t *display_state) {
27
25
}
28
26
29
27
void dji_display_close_framebuffer (dji_display_state_t * display_state ) {
30
-
31
28
duss_hal_display_port_enable (display_state -> disp_instance_handle , 3 , 0 );
32
29
duss_hal_display_release_plane (display_state -> disp_instance_handle , display_state -> plane_id );
33
30
duss_hal_display_close (display_state -> disp_handle , & display_state -> disp_instance_handle );
@@ -60,15 +57,15 @@ void dji_display_open_framebuffer(dji_display_state_t *display_state, duss_disp_
60
57
// Blending algorithm 1 seems to work.
61
58
62
59
display_state -> pb_0 -> blending_alg = 1 ;
63
-
60
+
64
61
duss_hal_device_desc_t device_descs [3 ] = {
65
62
{"/dev/dji_display" , & duss_hal_attach_disp , & duss_hal_detach_disp , 0x0 },
66
63
{"/dev/ion" , & duss_hal_attach_ion_mem , & duss_hal_detach_ion_mem , 0x0 },
67
64
{0 ,0 ,0 ,0 }
68
65
};
69
66
70
67
duss_hal_initialize (device_descs );
71
-
68
+
72
69
res = duss_hal_device_open ("/dev/dji_display" ,& hal_device_open_unk ,& display_state -> disp_handle );
73
70
if (res != 0 ) {
74
71
printf ("failed to open dji_display device" );
@@ -79,13 +76,13 @@ void dji_display_open_framebuffer(dji_display_state_t *display_state, duss_disp_
79
76
printf ("failed to open display hal" );
80
77
exit (0 );
81
78
}
82
-
79
+
83
80
res = duss_hal_display_reset (display_state -> disp_instance_handle );
84
81
if (res != 0 ) {
85
82
printf ("failed to reset display" );
86
83
exit (0 );
87
84
}
88
-
85
+
89
86
// No idea what this "plane mode" actually does but it's different on V2
90
87
uint8_t acquire_plane_mode = display_state -> is_v2_goggles ? 6 : 0 ;
91
88
@@ -94,19 +91,14 @@ void dji_display_open_framebuffer(dji_display_state_t *display_state, duss_disp_
94
91
printf ("failed to acquire plane" );
95
92
exit (0 );
96
93
}
97
- res = duss_hal_display_register_frame_cycle_callback (display_state -> disp_instance_handle , plane_id , & pop_func , 0 );
98
- if (res != 0 ) {
99
- printf ("failed to register callback" );
100
- exit (0 );
101
- }
102
94
res = duss_hal_display_port_enable (display_state -> disp_instance_handle , 3 , 1 );
103
95
if (res != 0 ) {
104
96
printf ("failed to enable display port" );
105
97
exit (0 );
106
98
}
107
99
108
100
res = duss_hal_display_plane_blending_set (display_state -> disp_instance_handle , plane_id , display_state -> pb_0 );
109
-
101
+
110
102
if (res != 0 ) {
111
103
printf ("failed to set blending" );
112
104
exit (0 );
@@ -155,7 +147,7 @@ void dji_display_open_framebuffer(dji_display_state_t *display_state, duss_disp_
155
147
exit (0 );
156
148
}
157
149
printf ("second buffer VRAM mapped virtual memory is at %p : %p\n" , display_state -> fb1_virtual_addr , display_state -> fb1_physical_addr );
158
-
150
+
159
151
for (int i = 0 ; i < 2 ; i ++ ) {
160
152
duss_frame_buffer_t * fb = i ? display_state -> fb_1 : display_state -> fb_0 ;
161
153
fb -> buffer = i ? display_state -> ion_buf_1 : display_state -> ion_buf_0 ;
@@ -171,13 +163,117 @@ void dji_display_open_framebuffer(dji_display_state_t *display_state, duss_disp_
171
163
}
172
164
}
173
165
174
- void dji_display_push_frame (dji_display_state_t * display_state , uint8_t which_fb ) {
175
- duss_frame_buffer_t * fb = which_fb ? display_state -> fb_1 : display_state -> fb_0 ;
176
- duss_hal_mem_sync (fb -> buffer , 1 );
177
- duss_hal_display_push_frame (display_state -> disp_instance_handle , display_state -> plane_id , fb );
166
+
167
+ void dji_display_open_framebuffer_injected (dji_display_state_t * display_state , duss_disp_instance_handle_t * disp , duss_hal_obj_handle_t ion_handle , duss_disp_plane_id_t plane_id ) {
168
+ uint32_t hal_device_open_unk = 0 ;
169
+ duss_result_t res = 0 ;
170
+ display_state -> disp_instance_handle = disp ;
171
+ display_state -> ion_handle = ion_handle ;
172
+ display_state -> plane_id = plane_id ;
173
+
174
+ // PLANE BLENDING
175
+
176
+ display_state -> pb_0 -> is_enable = 1 ;
177
+
178
+ // TODO just check hwid to figure this out. Not actually V1/V2 related but an HW version ID.
179
+
180
+ display_state -> pb_0 -> voffset = GOGGLES_V1_VOFFSET ;
181
+ display_state -> pb_0 -> hoffset = 0 ;
182
+
183
+ // On Goggles V1, the UI and video are in Z-Order 1. On Goggles V2, they're in Z-Order 4.
184
+ // Unfortunately, this means we cannot draw below the DJI UI on Goggles V1. But, on Goggles V2 we get what we want.
185
+
186
+ display_state -> pb_0 -> order = 2 ;
187
+
188
+ // Global alpha - disable as we want per pixel alpha.
189
+
190
+ display_state -> pb_0 -> glb_alpha_en = 0 ;
191
+ display_state -> pb_0 -> glb_alpha_val = 0 ;
192
+
193
+ // These aren't documented. Blending algorithm 0 is employed for menus and 1 for screensaver.
194
+
195
+ display_state -> pb_0 -> blending_alg = 1 ;
196
+
197
+ // No idea what this "plane mode" actually does but it's different on V2
198
+ uint8_t acquire_plane_mode = display_state -> is_v2_goggles ? 6 : 0 ;
199
+
200
+ DEBUG_PRINT ("acquire plane\n" );
201
+ res = duss_hal_display_aquire_plane (display_state -> disp_instance_handle ,acquire_plane_mode ,& plane_id );
202
+ if (res != 0 ) {
203
+ DEBUG_PRINT ("failed to acquire plane" );
204
+ exit (0 );
205
+ }
206
+
207
+ res = duss_hal_display_plane_blending_set (display_state -> disp_instance_handle , plane_id , display_state -> pb_0 );
208
+
209
+ if (res != 0 ) {
210
+ DEBUG_PRINT ("failed to set blending" );
211
+ exit (0 );
212
+ }
213
+ DEBUG_PRINT ("alloc ion buf\n" );
214
+ res = duss_hal_mem_alloc (display_state -> ion_handle ,& display_state -> ion_buf_0 ,0x473100 ,0x400 ,0 ,0x17 );
215
+ if (res != 0 ) {
216
+ DEBUG_PRINT ("failed to allocate VRAM" );
217
+ exit (0 );
218
+ }
219
+ res = duss_hal_mem_map (display_state -> ion_buf_0 , & display_state -> fb0_virtual_addr );
220
+ if (res != 0 ) {
221
+ DEBUG_PRINT ("failed to map VRAM" );
222
+ exit (0 );
223
+ }
224
+ res = duss_hal_mem_get_phys_addr (display_state -> ion_buf_0 , & display_state -> fb0_physical_addr );
225
+ if (res != 0 ) {
226
+ DEBUG_PRINT ("failed to get FB0 phys addr" );
227
+ exit (0 );
228
+ }
229
+ DEBUG_PRINT ("first buffer VRAM mapped virtual memory is at %p : %p\n" , display_state -> fb0_virtual_addr , display_state -> fb0_physical_addr );
230
+
231
+ res = duss_hal_mem_alloc (display_state -> ion_handle ,& display_state -> ion_buf_1 ,0x473100 ,0x400 ,0 ,0x17 );
232
+ if (res != 0 ) {
233
+ DEBUG_PRINT ("failed to allocate FB1 VRAM" );
234
+ exit (0 );
235
+ }
236
+ res = duss_hal_mem_map (display_state -> ion_buf_1 ,& display_state -> fb1_virtual_addr );
237
+ if (res != 0 ) {
238
+ DEBUG_PRINT ("failed to map FB1 VRAM" );
239
+ exit (0 );
240
+ }
241
+ res = duss_hal_mem_get_phys_addr (display_state -> ion_buf_1 , & display_state -> fb1_physical_addr );
242
+ if (res != 0 ) {
243
+ DEBUG_PRINT ("failed to get FB1 phys addr" );
244
+ exit (0 );
245
+ }
246
+ DEBUG_PRINT ("second buffer VRAM mapped virtual memory is at %p : %p\n" , display_state -> fb1_virtual_addr , display_state -> fb1_physical_addr );
247
+
248
+ for (int i = 0 ; i < 2 ; i ++ ) {
249
+ duss_frame_buffer_t * fb = i ? display_state -> fb_1 : display_state -> fb_0 ;
250
+ fb -> buffer = i ? display_state -> ion_buf_1 : display_state -> ion_buf_0 ;
251
+ fb -> pixel_format = display_state -> is_v2_goggles ? DUSS_PIXFMT_RGBA8888_GOGGLES_V2 : DUSS_PIXFMT_RGBA8888 ; // 20012 instead on V2
252
+ fb -> frame_id = i ;
253
+ fb -> planes [0 ].bytes_per_line = 0x1680 ;
254
+ fb -> planes [0 ].offset = 0 ;
255
+ fb -> planes [0 ].plane_height = 810 ;
256
+ fb -> planes [0 ].bytes_written = 0x473100 ;
257
+ fb -> width = 1440 ;
258
+ fb -> height = 810 ;
259
+ fb -> plane_count = 1 ;
260
+ }
261
+ }
262
+
263
+ void dji_display_push_frame (dji_display_state_t * display_state ) {
264
+ if (display_state -> frame_drawn == 0 ) {
265
+ duss_frame_buffer_t * fb = display_state -> fb_0 ;
266
+ duss_hal_mem_sync (fb -> buffer , 1 );
267
+ display_state -> frame_drawn = 1 ;
268
+ printf ("fbdebug pushing frame\n" );
269
+ duss_hal_display_push_frame (display_state -> disp_instance_handle , display_state -> plane_id , fb );
270
+ } else {
271
+ DEBUG_PRINT ("!!! Dropped frame due to pending frame push!\n" );
272
+ }
273
+ memcpy (display_state -> fb0_virtual_addr , display_state -> fb1_virtual_addr , sizeof (uint32_t ) * 1440 * 810 );
178
274
}
179
275
180
- void * dji_display_get_fb_address (dji_display_state_t * display_state , uint8_t which_fb ) {
181
- return which_fb ? display_state -> fb1_virtual_addr : display_state -> fb0_virtual_addr ;
276
+ void * dji_display_get_fb_address (dji_display_state_t * display_state ) {
277
+ return display_state -> fb1_virtual_addr ;
182
278
}
183
279
0 commit comments