Save the last profile used for each physical input

This commit is contained in:
Ari Sundholm 2017-10-23 15:48:42 +03:00
parent af4f7e17c7
commit 1979bdb333
4 changed files with 36 additions and 5 deletions

View File

@ -68,13 +68,14 @@ alt_u8 target_type;
alt_u8 stable_frames;
alt_u8 update_cur_vm;
alt_u8 vm_sel, vm_edit, profile_sel, lt_sel;
alt_u8 vm_sel, vm_edit, profile_sel, input_profiles[3], lt_sel;
alt_u16 tc_h_samplerate, tc_h_synclen, tc_h_bporch, tc_h_active, tc_v_synclen, tc_v_bporch, tc_v_active;
char row1[LCD_ROW_LEN+1], row2[LCD_ROW_LEN+1], menu_row1[LCD_ROW_LEN+1], menu_row2[LCD_ROW_LEN+1];
extern alt_u8 menu_active;
avinput_t target_mode;
phyinput_t phy_input_sel;
alt_u8 pcm1862_active;
@ -540,6 +541,7 @@ void program_mode()
int load_profile() {
int retval;
input_profiles[phy_input_sel] = profile_sel;
retval = read_userdata(profile_sel);
if (retval == 0)
write_userdata(INIT_CONFIG_SLOT);
@ -549,6 +551,7 @@ int load_profile() {
int save_profile() {
int retval;
input_profiles[phy_input_sel] = profile_sel;
retval = write_userdata(profile_sel);
if (retval == 0)
write_userdata(INIT_CONFIG_SLOT);
@ -806,6 +809,7 @@ int main()
switch (target_mode) {
case AV1_RGBs:
phy_input_sel = PHY_AV1;
target_input = TVP_INPUT1;
target_format = FORMAT_RGBS;
target_typemask = VIDEO_LDTV|VIDEO_SDTV|VIDEO_EDTV|VIDEO_HDTV;
@ -813,6 +817,7 @@ int main()
target_pcm = PCM_INPUT4;
break;
case AV1_RGsB:
phy_input_sel = PHY_AV1;
target_input = TVP_INPUT1;
target_format = FORMAT_RGsB;
target_typemask = VIDEO_LDTV|VIDEO_SDTV|VIDEO_EDTV|VIDEO_HDTV;
@ -820,6 +825,7 @@ int main()
target_pcm = PCM_INPUT4;
break;
case AV1_YPBPR:
phy_input_sel = PHY_AV1;
target_input = TVP_INPUT1;
target_format = FORMAT_YPbPr;
target_typemask = VIDEO_LDTV|VIDEO_SDTV|VIDEO_EDTV|VIDEO_HDTV;
@ -827,6 +833,7 @@ int main()
target_pcm = PCM_INPUT4;
break;
case AV2_YPBPR:
phy_input_sel = PHY_AV2;
target_input = TVP_INPUT1;
target_format = FORMAT_YPbPr;
target_typemask = VIDEO_LDTV|VIDEO_SDTV|VIDEO_EDTV|VIDEO_HDTV;
@ -834,6 +841,7 @@ int main()
target_pcm = PCM_INPUT3;
break;
case AV2_RGsB:
phy_input_sel = PHY_AV2;
target_input = TVP_INPUT1;
target_format = FORMAT_RGsB;
target_typemask = VIDEO_LDTV|VIDEO_SDTV|VIDEO_EDTV|VIDEO_HDTV;
@ -841,6 +849,7 @@ int main()
target_pcm = PCM_INPUT3;
break;
case AV3_RGBHV:
phy_input_sel = PHY_AV3;
target_input = TVP_INPUT3;
target_format = FORMAT_RGBHV;
target_typemask = VIDEO_PC;
@ -848,6 +857,7 @@ int main()
target_pcm = PCM_INPUT2;
break;
case AV3_RGBs:
phy_input_sel = PHY_AV3;
target_input = TVP_INPUT3;
target_format = FORMAT_RGBS;
target_typemask = VIDEO_LDTV|VIDEO_SDTV|VIDEO_EDTV|VIDEO_HDTV;
@ -855,6 +865,7 @@ int main()
target_pcm = PCM_INPUT2;
break;
case AV3_RGsB:
phy_input_sel = PHY_AV3;
target_input = TVP_INPUT3;
target_format = FORMAT_RGsB;
target_typemask = VIDEO_LDTV|VIDEO_SDTV|VIDEO_EDTV|VIDEO_HDTV;
@ -862,6 +873,7 @@ int main()
target_pcm = PCM_INPUT2;
break;
case AV3_YPBPR:
phy_input_sel = PHY_AV3;
target_input = TVP_INPUT3;
target_format = FORMAT_YPbPr;
target_typemask = VIDEO_LDTV|VIDEO_SDTV|VIDEO_EDTV|VIDEO_HDTV;
@ -874,6 +886,13 @@ int main()
if (target_mode != AV_KEEP) {
printf("### SWITCH MODE TO %s ###\n", avinput_str[target_mode]);
// The input changed, so load the appropriate profile
if (profile_sel != input_profiles[phy_input_sel]) {
profile_sel = input_profiles[phy_input_sel];
load_profile();
}
cm.avinput = target_mode;
cm.sync_active = 0;
ths_source_sel(target_ths, (cm.cc.video_lpf > 1) ? (VIDEO_LPF_MAX-cm.cc.video_lpf) : THS_LPF_BYPASS);

View File

@ -75,6 +75,12 @@ typedef enum {
AV_LAST = 10
} avinput_t;
typedef enum {
PHY_AV1 = 0,
PHY_AV2 = 1,
PHY_AV3 = 2
} phyinput_t;
// In reverse order of importance
typedef enum {
NO_CHANGE = 0,

View File

@ -29,7 +29,9 @@ extern avmode_t cm;
extern avconfig_t tc;
extern mode_data_t video_modes[];
extern avinput_t target_mode;
extern phyinput_t phy_input_sel;
extern alt_u8 update_cur_vm;
extern alt_u8 input_profiles[3];
extern alt_u8 profile_sel;
int write_userdata(alt_u8 entry)
@ -53,8 +55,9 @@ int write_userdata(alt_u8 entry)
switch (((ude_hdr*)databuf)->type) {
case UDE_INITCFG:
((ude_initcfg*)databuf)->data_len = sizeof(ude_initcfg) - offsetof(ude_initcfg, last_profile);
((ude_initcfg*)databuf)->last_profile = profile_sel;
memcpy(((ude_initcfg*)databuf)->last_profile, input_profiles, sizeof(input_profiles));
((ude_initcfg*)databuf)->last_input = cm.avinput;
((ude_initcfg*)databuf)->last_phy_input = phy_input_sel;
memcpy(((ude_initcfg*)databuf)->keys, rc_keymap, sizeof(rc_keymap));
retval = write_flash_page(databuf, sizeof(ude_initcfg), (USERDATA_OFFSET+entry*SECTORSIZE)/PAGESIZE);
if (retval != 0)
@ -133,10 +136,12 @@ int read_userdata(alt_u8 entry)
switch (((ude_hdr*)databuf)->type) {
case UDE_INITCFG:
if (((ude_initcfg*)databuf)->data_len == sizeof(ude_initcfg) - offsetof(ude_initcfg, last_profile)) {
if (((ude_initcfg*)databuf)->last_profile <= MAX_PROFILE)
profile_sel = ((ude_initcfg*)databuf)->last_profile;
for (alt_u8 i = 0; i < sizeof(input_profiles)/sizeof(*input_profiles); ++i)
if (((ude_initcfg*)databuf)->last_profile[i] <= MAX_PROFILE)
input_profiles[i] = ((ude_initcfg*)databuf)->last_profile[i];
if (((ude_initcfg*)databuf)->last_input < AV_LAST)
target_mode = ((ude_initcfg*)databuf)->last_input;
profile_sel = input_profiles[((ude_initcfg*)databuf)->last_phy_input];
memcpy(rc_keymap, ((ude_initcfg*)databuf)->keys, sizeof(rc_keymap));
printf("RC data read (%u bytes)\n", sizeof(rc_keymap));
}

View File

@ -46,8 +46,9 @@ typedef struct {
typedef struct {
ude_hdr hdr;
alt_u16 data_len;
alt_u8 last_profile;
alt_u8 last_profile[3];
avinput_t last_input;
phyinput_t last_phy_input;
alt_u16 keys[REMOTE_MAX_KEYS];
} __attribute__((packed, __may_alias__)) ude_initcfg;