From 5d39e2b752e1c255b32403cfad683124fc3b5f20 Mon Sep 17 00:00:00 2001 From: marqs Date: Tue, 25 Jun 2019 23:22:41 +0300 Subject: [PATCH] add compatibility option for AV3 to use AV1 RGB (and audio) --- software/sys_controller/ossc/av_controller.c | 39 ++++++++++++++++---- software/sys_controller/ossc/avconfig.h | 1 + software/sys_controller/ossc/menu.c | 1 + software/sys_controller/tvp7002/tvp7002.c | 24 ++++-------- software/sys_controller/tvp7002/tvp7002.h | 14 ++++++- 5 files changed, 54 insertions(+), 25 deletions(-) diff --git a/software/sys_controller/ossc/av_controller.c b/software/sys_controller/ossc/av_controller.c index f85abe9..e3b4d76 100644 --- a/software/sys_controller/ossc/av_controller.c +++ b/software/sys_controller/ossc/av_controller.c @@ -195,7 +195,7 @@ inline int check_linecnt(alt_u8 progressive, alt_u32 totlines) { } // Check if input video status / target configuration has changed -status_t get_status(tvp_input_t input, video_format format) +status_t get_status(tvp_sync_input_t syncinput) { alt_u32 data1, data2; alt_u32 totlines, clkcnt; @@ -221,7 +221,7 @@ status_t get_status(tvp_input_t input, video_format format) } } - sync_active = tvp_check_sync(input, format); + sync_active = tvp_check_sync(syncinput); vsyncmode = cm.sync_active ? sc->sc_status.fpga_vsyncgen : 0; // Read sync information from TVP7002 status registers @@ -827,6 +827,7 @@ void enable_outputs() int main() { tvp_input_t target_tvp = 0; + tvp_sync_input_t target_tvp_sync = 0; ths_input_t target_ths = 0; pcm_input_t target_pcm = 0; video_format target_format = 0; @@ -947,12 +948,13 @@ int main() auto_input_changed = 0; } - if (target_input != cm.avinput) { + if ((target_input != cm.avinput) || ((target_tvp_sync >= TVP_HV_A) && ((tc.av3_alt_rgb != cm.cc.av3_alt_rgb)))) { target_tvp = TVP_INPUT1; + target_tvp_sync = TVP_SOG1; target_typemask = VIDEO_LDTV|VIDEO_SDTV|VIDEO_EDTV|VIDEO_HDTV; - if (target_input <= AV1_YPBPR) { + if ((target_input <= AV1_YPBPR) || (tc.av3_alt_rgb && ((target_input == AV3_RGBHV) || (target_input == AV3_RGBs)))) { target_ths = THS_INPUT_B; target_pcm = PCM_INPUT4; } else if (target_input <= AV2_RGsB) { @@ -981,7 +983,26 @@ int main() break; case AV3_RGBHV: target_format = FORMAT_RGBHV; - target_typemask = VIDEO_PC; + if (!tc.av3_alt_rgb) + target_typemask = VIDEO_PC; + break; + default: + break; + } + + switch (target_input) { + case AV1_RGBs: + target_tvp_sync = TVP_SOG2; + break; + case AV3_RGBHV: + target_tvp_sync = TVP_HV_A; + break; + case AV3_RGBs: + target_tvp_sync = TVP_CS_A; + break; + case AV3_RGsB: + case AV3_YPBPR: + target_tvp_sync = TVP_SOG3; break; default: break; @@ -998,7 +1019,7 @@ int main() if (pcm1862_active) pcm_source_sel(target_pcm); #endif - tvp_source_sel(target_tvp, target_format); + tvp_source_sel(target_tvp, target_tvp_sync, target_format); cm.clkcnt = 0; //TODO: proper invalidate strncpy(row1, avinput_str[cm.avinput], LCD_ROW_LEN+1); strncpy(row2, " NO SYNC", LCD_ROW_LEN+1); @@ -1027,9 +1048,13 @@ int main() HDMITX_SetAVIInfoFrame(HDMI_Unkown, (tc.tx_mode == TX_HDMI_RGB) ? F_MODE_RGB444 : F_MODE_YUV444, 0, 0, tc.hdmi_itc, cm.hdmitx_pixr_ifr); cm.cc.hdmi_itc = tc.hdmi_itc; } + if (tc.av3_alt_rgb != cm.cc.av3_alt_rgb) { + printf("Changing AV3 RGB source\n"); + cm.cc.av3_alt_rgb = tc.av3_alt_rgb; + } if (cm.avinput != AV_TESTPAT) { - status = get_status(target_tvp, target_format); + status = get_status(target_tvp_sync); switch (status) { case ACTIVITY_CHANGE: diff --git a/software/sys_controller/ossc/avconfig.h b/software/sys_controller/ossc/avconfig.h index 53e3c5b..7f5e6c3 100644 --- a/software/sys_controller/ossc/avconfig.h +++ b/software/sys_controller/ossc/avconfig.h @@ -107,6 +107,7 @@ typedef struct { alt_u8 post_coast; alt_u8 full_tx_setup; alt_u8 vga_ilace_fix; + alt_u8 av3_alt_rgb; alt_u8 reverse_lpf; alt_u8 audio_dw_sampl; alt_u8 audio_swap_lr; diff --git a/software/sys_controller/ossc/menu.c b/software/sys_controller/ossc/menu.c index 6e72d1f..577ac36 100644 --- a/software/sys_controller/ossc/menu.c +++ b/software/sys_controller/ossc/menu.c @@ -190,6 +190,7 @@ MENU(menu_postproc, P99_PROTECT({ \ MENU(menu_compatibility, P99_PROTECT({ \ { LNG("Full TX setup","フルTXセットアップ"), OPT_AVCONFIG_SELECTION, { .sel = { &tc.full_tx_setup, OPT_WRAP, SETTING_ITEM(off_on_desc) } } }, { LNG("AV3 interlacefix","AV3インターレースシュウセイ"), OPT_AVCONFIG_SELECTION, { .sel = { &tc.vga_ilace_fix, OPT_WRAP, SETTING_ITEM(off_on_desc) } } }, + { "AV3 use AV1 RGB", OPT_AVCONFIG_SELECTION, { .sel = { &tc.av3_alt_rgb, OPT_WRAP, SETTING_ITEM(off_on_desc) } } }, })) #ifdef ENABLE_AUDIO diff --git a/software/sys_controller/tvp7002/tvp7002.c b/software/sys_controller/tvp7002/tvp7002.c index c8682d3..8251a23 100644 --- a/software/sys_controller/tvp7002/tvp7002.c +++ b/software/sys_controller/tvp7002/tvp7002.c @@ -385,27 +385,19 @@ void tvp_source_setup(video_type type, alt_u16 h_samplerate, alt_u16 refclks_per tvp_setup_hpll(h_samplerate, refclks_per_line, plldivby2); } -void tvp_source_sel(tvp_input_t input, video_format fmt) +void tvp_source_sel(tvp_input_t input, tvp_sync_input_t syncinput, video_format fmt) { alt_u8 sync_status; - alt_u8 sog_ch; - - if ((fmt == FORMAT_RGsB) || (fmt == FORMAT_YPbPr)) - sog_ch = (input == TVP_INPUT3) ? 2 : 0; - else if ((input == TVP_INPUT1) && (fmt == FORMAT_RGBS)) - sog_ch = 1; - else - sog_ch = 2; // RGB+SOG input select - tvp_writereg(TVP_INPMUX1, (sog_ch<<6) | (input<<4) | (input<<2) | input); + tvp_writereg(TVP_INPMUX1, (((syncinput <= TVP_SOG3) ? syncinput : 0)<<6) | (input<<4) | (input<<2) | input); // Clamp setup tvp_set_clamp(fmt); // HV/SOG sync select - if ((input == TVP_INPUT3) && ((fmt == FORMAT_RGBHV) || (fmt == FORMAT_RGBS))) { - if (fmt == FORMAT_RGBHV) + if (syncinput > TVP_SOG3) { + if (syncinput < TVP_CS_A) tvp_writereg(TVP_SYNCCTRL1, 0x52); else // RGBS tvp_writereg(TVP_SYNCCTRL1, 0x53); @@ -444,16 +436,16 @@ void tvp_source_sel(tvp_input_t input, video_format fmt) printf("\n"); } -alt_u8 tvp_check_sync(tvp_input_t input, video_format fmt) +alt_u8 tvp_check_sync(tvp_sync_input_t syncinput) { alt_u8 sync_status; sync_status = tvp_readreg(TVP_SYNCSTAT); - if ((input == TVP_INPUT3) && (fmt == FORMAT_RGBHV)) - return ((sync_status & 0x90) == 0x90); - else if ((input == TVP_INPUT3) && (fmt == FORMAT_RGBS)) + if (syncinput >= TVP_CS_A) return ((sync_status & 0x88) == 0x88); + else if (syncinput >= TVP_HV_A) + return ((sync_status & 0x90) == 0x90); else return !!(sync_status & (1<<1)); } diff --git a/software/sys_controller/tvp7002/tvp7002.h b/software/sys_controller/tvp7002/tvp7002.h index 5ffcf2e..e6662e3 100644 --- a/software/sys_controller/tvp7002/tvp7002.h +++ b/software/sys_controller/tvp7002/tvp7002.h @@ -44,6 +44,16 @@ typedef enum { TVP_INPUT3 = 2 } tvp_input_t; +typedef enum { + TVP_SOG1 = 0, + TVP_SOG2 = 1, + TVP_SOG3 = 2, + TVP_HV_A = 3, + TVP_HV_B = 4, + TVP_CS_A = 5, + TVP_CS_B = 6 +} tvp_sync_input_t; + typedef enum { REFCLK_EXT27 = 0, REFCLK_INTCLK = 1 @@ -111,8 +121,8 @@ void tvp_set_alc(alt_u8 en_alc, video_type type, alt_u8 h_syncinlen); void tvp_source_setup(video_type type, alt_u16 h_samplerate, alt_u16 refclks_per_line, alt_u8 plldivby2, alt_u8 h_syncinlen); -void tvp_source_sel(tvp_input_t input, video_format fmt); +void tvp_source_sel(tvp_input_t input, tvp_sync_input_t syncinput, video_format fmt); -alt_u8 tvp_check_sync(tvp_input_t input, video_format fmt); +alt_u8 tvp_check_sync(tvp_sync_input_t syncinput); #endif /* TVP7002_H_ */