Skip to content

Commit

Permalink
Merge pull request #63 from ligenxxxx/remove-camera-repower-page-for-…
Browse files Browse the repository at this point in the history
…runcam

reset runcam camera isp if video format is changed
  • Loading branch information
ligenxxxx committed Dec 10, 2022
2 parents ee26a8f + a59f1c0 commit 2730e57
Show file tree
Hide file tree
Showing 8 changed files with 93 additions and 40 deletions.
75 changes: 46 additions & 29 deletions src/camera.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ uint8_t camera_profile_menu;
uint8_t video_format = VDO_FMT_720P60;
uint8_t camRatio = 0;
uint8_t camMenuStatus = CAM_STATUS_IDLE;
uint8_t reset_isp_need = 0;

void camera_type_detect(void) {
camera_type = CAMERA_TYPE_UNKNOW;
Expand All @@ -36,6 +37,20 @@ void camera_type_detect(void) {
}
}

void camera_ratio_detect(void) {
if (camera_type == CAMERA_TYPE_RUNCAM_MICRO_V1) {
camRatio = 0;
} else if (camera_type == CAMERA_TYPE_RUNCAM_MICRO_V2) {
if (camera_setting_reg_set[11] == 0)
camRatio = 1;
else
camRatio = 0;
} else if (camera_type == CAMERA_TYPE_RUNCAM_NANO_90) {
camRatio = 1;
} else
camRatio = 0;
}

void camera_mode_detect() {
uint8_t cycles = 4;
uint8_t loss = 0;
Expand All @@ -47,17 +62,17 @@ void camera_mode_detect() {

if (camera_type) {
if (camera_type == CAMERA_TYPE_RUNCAM_NANO_90) {
if (camera_setting_reg_set[11] == 0 || camera_setting_reg_set[11] == 1) {
video_format = VDO_FMT_540P90;
Init_TC3587(1);
Init_TC3587(1);
if (camera_setting_reg_set[11] == 0) {
Set_540P90(0);
video_format = VDO_FMT_540P90;
} else if (camera_setting_reg_set[11] == 1) {
Set_540P90_crop(0);
video_format = VDO_FMT_540P90_CROP;
} else if (camera_setting_reg_set[11] == 2) {
video_format = VDO_FMT_540P60;
Init_TC3587(1);
Set_540P90(0);
; // Set_540P90(0);
; // video_format = VDO_FMT_540P60;
} else if (camera_setting_reg_set[11] == 3) {
Set_720P60(IS_RX);
Init_TC3587(0);
Set_960x720P60(0);
video_format = VDO_FMT_960x720P60;
}
Expand Down Expand Up @@ -104,7 +119,7 @@ void camera_mode_detect() {
cycles--;
}
}

camera_ratio_detect();
#ifdef _DEBUG_MODE
debugf("\r\ncameraID: %x", (uint16_t)camera_type);
#endif
Expand Down Expand Up @@ -246,6 +261,10 @@ void camera_init(void) {
camera_setting_read();
camera_setting_reg_menu_update();
camera_set(camera_setting_reg_menu, 1);

if (camera_mfr == CAMERA_MFR_RUNCAM)
runcam_reset_isp();

camera_mode_detect();

camera_button_init();
Expand Down Expand Up @@ -369,8 +388,8 @@ void camera_menu_draw_value(void) {
strcpy(&osd_buf[i][osd_menu_offset + 19], resolution_runcam_micro_v2[camera_setting_reg_menu[i - 1]]);
} else if (camera_type == CAMERA_TYPE_RUNCAM_NANO_90) {
strcpy(&osd_buf[i][osd_menu_offset + 19], resolution_runcam_nano_90[camera_setting_reg_menu[i - 1]]);
osd_buf[i][osd_menu_offset + 29] = '>';
}
osd_buf[i][osd_menu_offset + 29] = '>';
break;
default:
break;
Expand Down Expand Up @@ -446,13 +465,13 @@ void camera_profile_menu_toggle(uint8_t op) {
if (camera_profile_menu == CAMERA_PROFILE_NUM)
camera_profile_menu = 0;
camera_setting_reg_menu_update();
camera_set(camera_setting_reg_menu, 0);
reset_isp_need |= camera_set(camera_setting_reg_menu, 0);
} else if (op == BTN_LEFT) {
camera_profile_menu--;
if (camera_profile_menu > CAMERA_PROFILE_NUM)
camera_profile_menu = CAMERA_PROFILE_NUM - 1;
camera_setting_reg_menu_update();
camera_set(camera_setting_reg_menu, 0);
reset_isp_need |= camera_set(camera_setting_reg_menu, 0);
}
}

Expand Down Expand Up @@ -559,7 +578,6 @@ uint8_t camera_status_update(uint8_t op) {

uint8_t ret = 0;
static uint8_t step = 1;
static uint8_t repower = 0;
// static uint8_t cnt;
static uint8_t last_op = BTN_RIGHT;

Expand All @@ -578,7 +596,7 @@ uint8_t camera_status_update(uint8_t op) {
camera_setting_reg_menu_update();

camera_menu_long_press(op, last_op, 1);
repower = 0;
reset_isp_need = 0;

camMenuStatus = CAM_STATUS_PROFILE;
camera_menu_cursor_update(0);
Expand Down Expand Up @@ -635,15 +653,10 @@ uint8_t camera_status_update(uint8_t op) {

if (op == BTN_RIGHT) {
camera_setting_reg_menu_update();
repower = camera_set(camera_setting_reg_menu, 0);
camera_set(camera_setting_reg_menu, 0);

if (repower) {
camera_menu_show_repower();
camMenuStatus = CAM_STATUS_REPOWER;
} else {
camMenuStatus = CAM_STATUS_IDLE;
ret = 1;
}
camMenuStatus = CAM_STATUS_IDLE;
ret = 1;
}
break;
case CAM_STATUS_SAVE_EXIT:
Expand All @@ -653,19 +666,23 @@ uint8_t camera_status_update(uint8_t op) {
camera_menu_item_toggle(op);

if (op == BTN_RIGHT) {
// 540@60 do not work for now
if (camera_mfr == CAMERA_MFR_RUNCAM && camera_type == CAMERA_TYPE_RUNCAM_NANO_90 && camera_setting_reg_menu[11] == 2)
break;
camera_profile_eep = camera_profile_menu;
camera_profile_write();
repower = camera_set(camera_setting_reg_menu, 1);
reset_isp_need |= camera_set(camera_setting_reg_menu, 1);
camera_setting_reg_eep_update();
camera_setting_profile_write(0xff);

if (repower) {
camera_menu_show_repower();
camMenuStatus = CAM_STATUS_REPOWER;
} else {
camMenuStatus = CAM_STATUS_IDLE;
ret = 1;
if (reset_isp_need) {
if (camera_mfr == CAMERA_MFR_RUNCAM) {
runcam_reset_isp();
camera_mode_detect();
}
}
camMenuStatus = CAM_STATUS_IDLE;
ret = 1;
}
break;
// case CAM_STATUS_REPOWER:
Expand Down
1 change: 1 addition & 0 deletions src/camera.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ typedef enum {
VDO_FMT_720P60_NEW,
VDO_FMT_720P30,
VDO_FMT_540P90,
VDO_FMT_540P90_CROP,
VDO_FMT_540P60,
VDO_FMT_960x720P60
} video_format_e;
Expand Down
31 changes: 25 additions & 6 deletions src/hardware.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#include "hardware.h"

#include "camera.h"
#include "common.h"
#include "dm6300.h"
Expand Down Expand Up @@ -141,7 +140,7 @@ void Set_720P60(uint8_t page) {
}

void Set_960x720P60(uint8_t page) {
WriteReg(page, 0x21, 0x1F);
WriteReg(page, 0x21, 0x1C);

WriteReg(page, 0x40, 0xC0);
WriteReg(page, 0x41, 0x23);
Expand Down Expand Up @@ -182,11 +181,31 @@ void Set_720P30(uint8_t page, uint8_t is_43) {
}

void Set_540P90(uint8_t page) {
#ifdef CAM90_DEMO
WriteReg(page, 0x21, 0x24);
#else
WriteReg(page, 0x21, 0x21);
#endif

WriteReg(page, 0x40, 0xD0);
WriteReg(page, 0x41, 0x22);
WriteReg(page, 0x42, 0x18);

// WriteReg(page, 0x43, 0xD4); //pat
// WriteReg(page, 0x44, 0x45);

WriteReg(page, 0x43, 0x1F); // cam
WriteReg(page, 0x44, 0x44);

WriteReg(page, 0x45, 0x29);
WriteReg(page, 0x49, 0x04);
WriteReg(page, 0x4c, 0x08);
WriteReg(page, 0x4f, 0x00);
WriteReg(page, 0x52, 0x04);
WriteReg(page, 0x53, 0x02);
WriteReg(page, 0x54, 0x3C);

WriteReg(page, 0x06, 0x01);
}

void Set_540P90_crop(uint8_t page) {
WriteReg(page, 0x21, 0x1f);

WriteReg(page, 0x40, 0xD0);
WriteReg(page, 0x41, 0x22);
Expand Down
1 change: 1 addition & 0 deletions src/hardware.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ void CFG_Back();
void Set_720P50(uint8_t page);
void Set_720P60(uint8_t page);
void Set_540P90(uint8_t page);
void Set_540P90_crop(uint8_t page);
void Set_960x720P60(uint8_t page);
void Set_720P30(uint8_t page, uint8_t is_43);

Expand Down
5 changes: 5 additions & 0 deletions src/i2c_device.c
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ void Init_TC3587(uint8_t fmt) {
#ifdef _DEBUG_TC3587
debugf("\r\nDetecte TC3587...");
#endif
#if (0) // some vtx cannot pass tc3587 detect, I don't know the reason.
while (1) {
val = I2C_Read16(ADDR_TC3587, 0x0000);
if (val == 0x4401) {
Expand All @@ -105,6 +106,10 @@ void Init_TC3587(uint8_t fmt) {
}
}
}
#else
LED_BLUE_ON;
led_status = ON;
#endif
I2C_Write16(ADDR_TC3587, 0x0002, 0x0001);
I2C_Write16(ADDR_TC3587, 0x0002, 0x0000); // srst

Expand Down
4 changes: 3 additions & 1 deletion src/msp_displayport.c
Original file line number Diff line number Diff line change
Expand Up @@ -440,6 +440,8 @@ uint8_t get_tx_data_5680() // prepare data to VRX
tx_buf[4] = 0xCC;
else if (video_format == VDO_FMT_540P90)
tx_buf[4] = 0xEE;
else if (video_format == VDO_FMT_540P90_CROP)
tx_buf[4] = 0x44;
else if (video_format == VDO_FMT_540P60)
tx_buf[4] = 0x33;
else if (video_format == VDO_FMT_960x720P60)
Expand Down Expand Up @@ -474,7 +476,7 @@ uint8_t get_tx_data_5680() // prepare data to VRX

tx_buf[14] = fc_lock & 0x03;

tx_buf[15] = (camRatio == 0) ? 0xaa : 0x55;
tx_buf[15] = (camRatio == 0) ? 0x55 : 0xaa;

tx_buf[16] = VTX_VERSION_MAJOR;
tx_buf[17] = VTX_VERSION_MINOR;
Expand Down
15 changes: 11 additions & 4 deletions src/runcam.c
Original file line number Diff line number Diff line change
Expand Up @@ -344,10 +344,10 @@ void runcam_video_format(uint8_t val) {
2: 1280x720@60 16:9 full
RUNCAM_NANO_90:
0: 720x540@90
1: 720x540@90 crop //NANO 90 DEMO CAMERA DOESN"T SUPPORT
2: 720x540@60
3: 960x720@60
0: 720x540@90 4:3
1: 720x540@90 4:3 crop // NANO 90 DEMO CAMERA DOESN"T SUPPORT
2: 720x540@60 4:3
3: 960x720@60 4:3
*/
camera_setting_reg_set[11] = val;

Expand Down Expand Up @@ -412,6 +412,13 @@ void runcam_save(void) {
#endif
}

void runcam_reset_isp(void) {
RUNCAM_Write(camera_device, 0x000694, 0x00000130);
#ifdef _DEBUG_RUNCAM
debugf("\r\nRUNCAM reset isp");
#endif
}

uint8_t runcam_set(uint8_t *setting_profile) {
static uint8_t init_done = 0;
uint8_t ret = 0;
Expand Down
1 change: 1 addition & 0 deletions src/runcam.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@ void runcam_type_detect(void);
void runcam_setting_profile_reset(uint8_t *setting_profile);
uint8_t runcam_setting_profile_check(uint8_t *setting_profile);
uint8_t runcam_set(uint8_t *setting_profile);
void runcam_reset_isp(void);
void runcam_save(void);
#endif

0 comments on commit 2730e57

Please sign in to comment.