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
8
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 ) {
9
+ dji_display_state_t * display_state = (dji_display_state_t * )user_ctx ;
10
+ display_state -> frame_waiting = 0 ;
8
11
return 0 ;
9
12
}
10
13
@@ -15,6 +18,7 @@ dji_display_state_t *dji_display_state_alloc(uint8_t is_v2_goggles) {
15
18
display_state -> fb_1 = (duss_frame_buffer_t * )calloc (1 ,sizeof (duss_frame_buffer_t ));
16
19
display_state -> pb_0 = (duss_disp_plane_blending_t * )calloc (1 , sizeof (duss_disp_plane_blending_t ));
17
20
display_state -> is_v2_goggles = is_v2_goggles ;
21
+ display_state -> frame_waiting = 0 ;
18
22
return display_state ;
19
23
}
20
24
@@ -27,7 +31,6 @@ void dji_display_state_free(dji_display_state_t *display_state) {
27
31
}
28
32
29
33
void dji_display_close_framebuffer (dji_display_state_t * display_state ) {
30
-
31
34
duss_hal_display_port_enable (display_state -> disp_instance_handle , 3 , 0 );
32
35
duss_hal_display_release_plane (display_state -> disp_instance_handle , display_state -> plane_id );
33
36
duss_hal_display_close (display_state -> disp_handle , & display_state -> disp_instance_handle );
@@ -94,7 +97,7 @@ void dji_display_open_framebuffer(dji_display_state_t *display_state, duss_disp_
94
97
printf ("failed to acquire plane" );
95
98
exit (0 );
96
99
}
97
- res = duss_hal_display_register_frame_cycle_callback (display_state -> disp_instance_handle , plane_id , & pop_func , 0 );
100
+ res = duss_hal_display_register_frame_cycle_callback (display_state -> disp_instance_handle , plane_id , & pop_func , display_state );
98
101
if (res != 0 ) {
99
102
printf ("failed to register callback" );
100
103
exit (0 );
@@ -171,10 +174,117 @@ void dji_display_open_framebuffer(dji_display_state_t *display_state, duss_disp_
171
174
}
172
175
}
173
176
177
+
178
+ 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 ) {
179
+ uint32_t hal_device_open_unk = 0 ;
180
+ duss_result_t res = 0 ;
181
+ display_state -> disp_instance_handle = disp ;
182
+ display_state -> ion_handle = ion_handle ;
183
+ display_state -> plane_id = plane_id ;
184
+
185
+ // PLANE BLENDING
186
+
187
+ display_state -> pb_0 -> is_enable = 1 ;
188
+
189
+ // TODO just check hwid to figure this out. Not actually V1/V2 related but an HW version ID.
190
+
191
+ display_state -> pb_0 -> voffset = GOGGLES_V1_VOFFSET ;
192
+ display_state -> pb_0 -> hoffset = 0 ;
193
+
194
+ // On Goggles V1, the UI and video are in Z-Order 1. On Goggles V2, they're in Z-Order 4.
195
+ // Unfortunately, this means we cannot draw below the DJI UI on Goggles V1. But, on Goggles V2 we get what we want.
196
+
197
+ display_state -> pb_0 -> order = 2 ;
198
+
199
+ // Global alpha - disable as we want per pixel alpha.
200
+
201
+ display_state -> pb_0 -> glb_alpha_en = 0 ;
202
+ display_state -> pb_0 -> glb_alpha_val = 0 ;
203
+
204
+ // These aren't documented. Blending algorithm 0 is employed for menus and 1 for screensaver.
205
+
206
+ display_state -> pb_0 -> blending_alg = 1 ;
207
+
208
+ // No idea what this "plane mode" actually does but it's different on V2
209
+ uint8_t acquire_plane_mode = display_state -> is_v2_goggles ? 6 : 0 ;
210
+
211
+ DEBUG_PRINT ("acquire plane\n" );
212
+ res = duss_hal_display_aquire_plane (display_state -> disp_instance_handle ,acquire_plane_mode ,& plane_id );
213
+ if (res != 0 ) {
214
+ DEBUG_PRINT ("failed to acquire plane" );
215
+ exit (0 );
216
+ }
217
+ res = duss_hal_display_register_frame_cycle_callback (display_state -> disp_instance_handle , plane_id , & pop_func , 0 );
218
+ if (res != 0 ) {
219
+ DEBUG_PRINT ("failed to register callback" );
220
+ exit (0 );
221
+ }
222
+
223
+ res = duss_hal_display_plane_blending_set (display_state -> disp_instance_handle , plane_id , display_state -> pb_0 );
224
+
225
+ if (res != 0 ) {
226
+ DEBUG_PRINT ("failed to set blending" );
227
+ exit (0 );
228
+ }
229
+ DEBUG_PRINT ("alloc ion buf\n" );
230
+ res = duss_hal_mem_alloc (display_state -> ion_handle ,& display_state -> ion_buf_0 ,0x473100 ,0x400 ,0 ,0x17 );
231
+ if (res != 0 ) {
232
+ DEBUG_PRINT ("failed to allocate VRAM" );
233
+ exit (0 );
234
+ }
235
+ res = duss_hal_mem_map (display_state -> ion_buf_0 , & display_state -> fb0_virtual_addr );
236
+ if (res != 0 ) {
237
+ DEBUG_PRINT ("failed to map VRAM" );
238
+ exit (0 );
239
+ }
240
+ res = duss_hal_mem_get_phys_addr (display_state -> ion_buf_0 , & display_state -> fb0_physical_addr );
241
+ if (res != 0 ) {
242
+ DEBUG_PRINT ("failed to get FB0 phys addr" );
243
+ exit (0 );
244
+ }
245
+ DEBUG_PRINT ("first buffer VRAM mapped virtual memory is at %p : %p\n" , display_state -> fb0_virtual_addr , display_state -> fb0_physical_addr );
246
+
247
+ res = duss_hal_mem_alloc (display_state -> ion_handle ,& display_state -> ion_buf_1 ,0x473100 ,0x400 ,0 ,0x17 );
248
+ if (res != 0 ) {
249
+ DEBUG_PRINT ("failed to allocate FB1 VRAM" );
250
+ exit (0 );
251
+ }
252
+ res = duss_hal_mem_map (display_state -> ion_buf_1 ,& display_state -> fb1_virtual_addr );
253
+ if (res != 0 ) {
254
+ DEBUG_PRINT ("failed to map FB1 VRAM" );
255
+ exit (0 );
256
+ }
257
+ res = duss_hal_mem_get_phys_addr (display_state -> ion_buf_1 , & display_state -> fb1_physical_addr );
258
+ if (res != 0 ) {
259
+ DEBUG_PRINT ("failed to get FB1 phys addr" );
260
+ exit (0 );
261
+ }
262
+ DEBUG_PRINT ("second buffer VRAM mapped virtual memory is at %p : %p\n" , display_state -> fb1_virtual_addr , display_state -> fb1_physical_addr );
263
+
264
+ for (int i = 0 ; i < 2 ; i ++ ) {
265
+ duss_frame_buffer_t * fb = i ? display_state -> fb_1 : display_state -> fb_0 ;
266
+ fb -> buffer = i ? display_state -> ion_buf_1 : display_state -> ion_buf_0 ;
267
+ fb -> pixel_format = display_state -> is_v2_goggles ? DUSS_PIXFMT_RGBA8888_GOGGLES_V2 : DUSS_PIXFMT_RGBA8888 ; // 20012 instead on V2
268
+ fb -> frame_id = i ;
269
+ fb -> planes [0 ].bytes_per_line = 0x1680 ;
270
+ fb -> planes [0 ].offset = 0 ;
271
+ fb -> planes [0 ].plane_height = 810 ;
272
+ fb -> planes [0 ].bytes_written = 0x473100 ;
273
+ fb -> width = 1440 ;
274
+ fb -> height = 810 ;
275
+ fb -> plane_count = 1 ;
276
+ }
277
+ }
278
+
174
279
void dji_display_push_frame (dji_display_state_t * display_state , uint8_t which_fb ) {
175
280
duss_frame_buffer_t * fb = which_fb ? display_state -> fb_1 : display_state -> fb_0 ;
176
281
duss_hal_mem_sync (fb -> buffer , 1 );
177
- duss_hal_display_push_frame (display_state -> disp_instance_handle , display_state -> plane_id , fb );
282
+ if (display_state -> frame_waiting == 0 ) {
283
+ display_state -> frame_waiting = 1 ;
284
+ duss_hal_display_push_frame (display_state -> disp_instance_handle , display_state -> plane_id , fb );
285
+ } else {
286
+ DEBUG_PRINT ("!!! Dropped frame due to pending frame push!\n" );
287
+ }
178
288
}
179
289
180
290
void * dji_display_get_fb_address (dji_display_state_t * display_state , uint8_t which_fb ) {
0 commit comments