Skip to content

Commit 59866c4

Browse files
committed
wait for push to finish before trying another push
1 parent 03c1faf commit 59866c4

19 files changed

+145
-140
lines changed

jni/fakehd/fakehd.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#pragma once
2+
13
void load_fakehd_config();
24
void fakehd_disable();
35
void fakehd_enable();

jni/hw/dji_display.c

Lines changed: 113 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
#include <stdlib.h>
22
#include "dji_display.h"
3+
#include "util/debug.h"
34

45
#define GOGGLES_V1_VOFFSET 575
56
#define GOGGLES_V2_VOFFSET 215
67

78
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;
811
return 0;
912
}
1013

@@ -15,6 +18,7 @@ dji_display_state_t *dji_display_state_alloc(uint8_t is_v2_goggles) {
1518
display_state->fb_1 = (duss_frame_buffer_t *)calloc(1,sizeof(duss_frame_buffer_t));
1619
display_state->pb_0 = (duss_disp_plane_blending_t *)calloc(1, sizeof(duss_disp_plane_blending_t));
1720
display_state->is_v2_goggles = is_v2_goggles;
21+
display_state->frame_waiting = 0;
1822
return display_state;
1923
}
2024

@@ -27,7 +31,6 @@ void dji_display_state_free(dji_display_state_t *display_state) {
2731
}
2832

2933
void dji_display_close_framebuffer(dji_display_state_t *display_state) {
30-
3134
duss_hal_display_port_enable(display_state->disp_instance_handle, 3, 0);
3235
duss_hal_display_release_plane(display_state->disp_instance_handle, display_state->plane_id);
3336
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_
9497
printf("failed to acquire plane");
9598
exit(0);
9699
}
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);
98101
if (res != 0) {
99102
printf("failed to register callback");
100103
exit(0);
@@ -171,10 +174,117 @@ void dji_display_open_framebuffer(dji_display_state_t *display_state, duss_disp_
171174
}
172175
}
173176

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+
174279
void dji_display_push_frame(dji_display_state_t *display_state, uint8_t which_fb) {
175280
duss_frame_buffer_t *fb = which_fb ? display_state->fb_1 : display_state->fb_0;
176281
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+
}
178288
}
179289

180290
void *dji_display_get_fb_address(dji_display_state_t *display_state, uint8_t which_fb) {

jni/hw/dji_display.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
#ifndef DJI_DISPLAY_H
2-
#define DJI_DISPLAY_H
1+
#pragma once
32
#include "duml_hal.h"
43

54
typedef struct dji_display_state_s {
@@ -18,12 +17,13 @@ typedef struct dji_display_state_s {
1817
duss_frame_buffer_t *fb_1;
1918
duss_disp_plane_blending_t *pb_0;
2019
uint8_t is_v2_goggles;
20+
uint8_t frame_waiting;
2121
} dji_display_state_t;
2222

2323
void dji_display_push_frame(dji_display_state_t *display_state, uint8_t which_fb);
2424
void dji_display_open_framebuffer(dji_display_state_t *display_state, duss_disp_plane_id_t plane_id);
25+
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);
2526
void dji_display_close_framebuffer(dji_display_state_t *display_state);
2627
dji_display_state_t *dji_display_state_alloc(uint8_t is_v2_goggles);
2728
void dji_display_state_free(dji_display_state_t *display_state);
2829
void *dji_display_get_fb_address(dji_display_state_t *display_state, uint8_t which_fb);
29-
#endif

jni/hw/dji_radio_shm.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
2+
#pragma once
13
#include <stdint.h>
24

35
#define RTOS_SHM_ADDRESS 0xfffc1000

jni/hw/dji_services.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#pragma once
2+
13
void dji_stop_goggles(int is_v2);
24
void dji_start_goggles(int is_v2);
35
int dji_goggles_are_v2();

jni/hw/duml_hal.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
#ifndef DUML_HAL_H
2-
#define DUML_HAL_H
1+
#pragma once
32
#include <stdint.h>
43

54
typedef int32_t duss_result_t;
@@ -259,4 +258,3 @@ duss_result_t duss_hal_attach_disp(char *param_1,duss_hal_obj **param_2);
259258
duss_result_t duss_hal_attach_ion_mem(char *param_1,duss_hal_obj **param_2);
260259
duss_result_t duss_hal_detach_ion_mem();
261260
duss_result_t duss_hal_detach_disp();
262-
#endif

jni/msp/msp.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#pragma once
12
#include <stdint.h>
23

34
#define MSP_CMD_API_VERSION 1

jni/msp/msp_displayport.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1+
#pragma once
12
#include <stdint.h>
3+
#include "msp.h"
24

35
typedef enum {
46
MSP_DISPLAYPORT_KEEPALIVE,

jni/msp_displayport_mux.c

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include "net/serial.h"
1414
#include "msp/msp.h"
1515
#include "msp/msp_displayport.h"
16+
#include "util/debug.h"
1617
#include "util/time_util.h"
1718
#include "util/fs_util.h"
1819

@@ -42,12 +43,6 @@ enum {
4243
// The Betaflight MSP minor version in which MSP DisplayPort sizing is supported.
4344
#define MSP_DISPLAY_SIZE_VERSION 45
4445

45-
#ifdef DEBUG
46-
#define DEBUG_PRINT(fmt, args...) fprintf(stderr, fmt, ## args)
47-
#else
48-
#define DEBUG_PRINT(fmt, args...)
49-
#endif
50-
5146
typedef struct msp_cache_entry_s {
5247
struct timespec time;
5348
msp_msg_t message;

jni/net/network.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
1+
#pragma once
2+
13
int connect_to_server(char *address, int port);
24
int bind_socket(int port);

0 commit comments

Comments
 (0)