1
0
mirror of https://github.com/marqs85/ossc.git synced 2024-06-01 17:41:37 +00:00

Merge branch 'save_last_profile_per_input' of git://github.com/megari/ossc into megari-save_last_profile_per_input

This commit is contained in:
marqs 2017-12-07 23:29:36 +02:00
commit 09c735bd5f
6 changed files with 66 additions and 28 deletions

View File

@ -68,13 +68,14 @@ alt_u8 target_type;
alt_u8 stable_frames; alt_u8 stable_frames;
alt_u8 update_cur_vm; 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, def_input;
alt_u16 tc_h_samplerate, tc_h_synclen, tc_h_bporch, tc_h_active, tc_v_synclen, tc_v_bporch, tc_v_active; 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]; 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; extern alt_u8 menu_active;
avinput_t target_mode; avinput_t target_mode;
phyinput_t phy_input_sel;
alt_u8 pcm1862_active; alt_u8 pcm1862_active;
@ -540,6 +541,7 @@ void program_mode()
int load_profile() { int load_profile() {
int retval; int retval;
input_profiles[phy_input_sel] = profile_sel;
retval = read_userdata(profile_sel); retval = read_userdata(profile_sel);
if (retval == 0) if (retval == 0)
write_userdata(INIT_CONFIG_SLOT); write_userdata(INIT_CONFIG_SLOT);
@ -549,6 +551,7 @@ int load_profile() {
int save_profile() { int save_profile() {
int retval; int retval;
input_profiles[phy_input_sel] = profile_sel;
retval = write_userdata(profile_sel); retval = write_userdata(profile_sel);
if (retval == 0) if (retval == 0)
write_userdata(INIT_CONFIG_SLOT); write_userdata(INIT_CONFIG_SLOT);
@ -782,8 +785,8 @@ int main()
while (1) {} while (1) {}
} }
if (tc.def_input < AV_LAST) if (def_input < AV_LAST)
target_mode = tc.def_input; target_mode = def_input;
// Mainloop // Mainloop
while(1) { while(1) {
@ -874,6 +877,15 @@ int main()
if (target_mode != AV_KEEP) { if (target_mode != AV_KEEP) {
printf("### SWITCH MODE TO %s ###\n", avinput_str[target_mode]); printf("### SWITCH MODE TO %s ###\n", avinput_str[target_mode]);
phy_input_sel = avinput_to_phyinput[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];
read_userdata(profile_sel);
}
cm.avinput = target_mode; cm.avinput = target_mode;
cm.sync_active = 0; cm.sync_active = 0;
ths_source_sel(target_ths, (cm.cc.video_lpf > 1) ? (VIDEO_LPF_MAX-cm.cc.video_lpf) : THS_LPF_BYPASS); ths_source_sel(target_ths, (cm.cc.video_lpf > 1) ? (VIDEO_LPF_MAX-cm.cc.video_lpf) : THS_LPF_BYPASS);
@ -889,7 +901,7 @@ int main()
strncpy(row2, " NO SYNC", LCD_ROW_LEN+1); strncpy(row2, " NO SYNC", LCD_ROW_LEN+1);
if (!menu_active) if (!menu_active)
lcd_write_status(); lcd_write_status();
if (av_init && (tc.def_input == AV_LAST)) if (av_init && (def_input == AV_LAST))
write_userdata(INIT_CONFIG_SLOT); write_userdata(INIT_CONFIG_SLOT);
av_init = 1; av_init = 1;
} }

View File

@ -75,6 +75,27 @@ typedef enum {
AV_LAST = 10 AV_LAST = 10
} avinput_t; } avinput_t;
typedef enum {
PHY_AV1 = 0,
PHY_AV2 = 1,
PHY_AV3 = 2,
PHY_INVALID = 3
} phyinput_t;
static phyinput_t avinput_to_phyinput[] = {
[AV_KEEP] = PHY_INVALID,
[AV1_RGBs] = PHY_AV1,
[AV1_RGsB] = PHY_AV1,
[AV1_YPBPR] = PHY_AV1,
[AV2_YPBPR] = PHY_AV2,
[AV2_RGsB] = PHY_AV2,
[AV3_RGBHV] = PHY_AV3,
[AV3_RGBs] = PHY_AV3,
[AV3_RGsB] = PHY_AV3,
[AV3_YPBPR] = PHY_AV3,
[AV_LAST] = PHY_INVALID
};
// In reverse order of importance // In reverse order of importance
typedef enum { typedef enum {
NO_CHANGE = 0, NO_CHANGE = 0,

View File

@ -83,7 +83,6 @@ typedef struct {
alt_u8 audio_dw_sampl; alt_u8 audio_dw_sampl;
alt_u8 audio_swap_lr; alt_u8 audio_swap_lr;
#endif #endif
alt_u8 def_input;
color_setup_t col; color_setup_t col;
} __attribute__((packed)) avconfig_t; } __attribute__((packed)) avconfig_t;

View File

@ -41,7 +41,7 @@ extern mode_data_t video_modes[];
extern alt_u16 tc_h_samplerate, tc_h_synclen, tc_h_bporch, tc_h_active, tc_v_synclen, tc_v_bporch, tc_v_active; extern alt_u16 tc_h_samplerate, tc_h_synclen, tc_h_bporch, tc_h_active, tc_v_synclen, tc_v_bporch, tc_v_active;
extern alt_u32 remote_code; extern alt_u32 remote_code;
extern alt_u16 rc_keymap[REMOTE_MAX_KEYS]; extern alt_u16 rc_keymap[REMOTE_MAX_KEYS];
extern alt_u8 vm_sel, profile_sel, lt_sel; extern alt_u8 vm_sel, profile_sel, lt_sel, def_input;
alt_u8 menu_active; alt_u8 menu_active;
@ -134,7 +134,7 @@ MENU(menu_output, P99_PROTECT({ \
{ LNG("256x240 aspect","256x240アスペクト"), OPT_AVCONFIG_SELECTION, { .sel = { &tc.ar_256col, OPT_WRAP, SETTING_ITEM(ar_256col_desc) } } }, { LNG("256x240 aspect","256x240アスペクト"), OPT_AVCONFIG_SELECTION, { .sel = { &tc.ar_256col, OPT_WRAP, SETTING_ITEM(ar_256col_desc) } } },
{ LNG("TX mode","TXモード"), OPT_AVCONFIG_SELECTION, { .sel = { &tc.tx_mode, OPT_WRAP, SETTING_ITEM(tx_mode_desc) } } }, { LNG("TX mode","TXモード"), OPT_AVCONFIG_SELECTION, { .sel = { &tc.tx_mode, OPT_WRAP, SETTING_ITEM(tx_mode_desc) } } },
{ "HDMI ITC", OPT_AVCONFIG_SELECTION, { .sel = { &tc.hdmi_itc, OPT_WRAP, SETTING_ITEM(off_on_desc) } } }, { "HDMI ITC", OPT_AVCONFIG_SELECTION, { .sel = { &tc.hdmi_itc, OPT_WRAP, SETTING_ITEM(off_on_desc) } } },
{ LNG("Initial input","ショキニュウリョク"), OPT_AVCONFIG_SELECTION, { .sel = { &tc.def_input, OPT_WRAP, SETTING_ITEM(avinput_str) } } }, { LNG("Initial input","ショキニュウリョク"), OPT_AVCONFIG_SELECTION, { .sel = { &def_input, OPT_WRAP, SETTING_ITEM(avinput_str) } } },
})) }))
MENU(menu_postproc, P99_PROTECT({ \ MENU(menu_postproc, P99_PROTECT({ \

View File

@ -30,7 +30,9 @@ extern avconfig_t tc;
extern mode_data_t video_modes[]; extern mode_data_t video_modes[];
extern avinput_t target_mode; extern avinput_t target_mode;
extern alt_u8 update_cur_vm; extern alt_u8 update_cur_vm;
extern alt_u8 input_profiles[3];
extern alt_u8 profile_sel; extern alt_u8 profile_sel;
extern alt_u8 def_input;
int write_userdata(alt_u8 entry) int write_userdata(alt_u8 entry)
{ {
@ -38,6 +40,7 @@ int write_userdata(alt_u8 entry)
alt_u16 vm_to_write; alt_u16 vm_to_write;
alt_u16 pageoffset, srcoffset; alt_u16 pageoffset, srcoffset;
alt_u8 pageno; alt_u8 pageno;
alt_u32 bytes_to_w;
int retval; int retval;
if (entry > MAX_USERDATA_ENTRY) { if (entry > MAX_USERDATA_ENTRY) {
@ -53,8 +56,9 @@ int write_userdata(alt_u8 entry)
switch (((ude_hdr*)databuf)->type) { switch (((ude_hdr*)databuf)->type) {
case UDE_INITCFG: case UDE_INITCFG:
((ude_initcfg*)databuf)->data_len = sizeof(ude_initcfg) - offsetof(ude_initcfg, last_profile); ((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_input = cm.avinput;
((ude_initcfg*)databuf)->def_input = def_input;
memcpy(((ude_initcfg*)databuf)->keys, rc_keymap, sizeof(rc_keymap)); memcpy(((ude_initcfg*)databuf)->keys, rc_keymap, sizeof(rc_keymap));
retval = write_flash_page(databuf, sizeof(ude_initcfg), (USERDATA_OFFSET+entry*SECTORSIZE)/PAGESIZE); retval = write_flash_page(databuf, sizeof(ude_initcfg), (USERDATA_OFFSET+entry*SECTORSIZE)/PAGESIZE);
if (retval != 0) if (retval != 0)
@ -67,31 +71,29 @@ int write_userdata(alt_u8 entry)
((ude_profile*)databuf)->avc_data_len = sizeof(avconfig_t); ((ude_profile*)databuf)->avc_data_len = sizeof(avconfig_t);
((ude_profile*)databuf)->vm_data_len = vm_to_write; ((ude_profile*)databuf)->vm_data_len = vm_to_write;
pageno = 0;
pageoffset = offsetof(ude_profile, avc); pageoffset = offsetof(ude_profile, avc);
// assume that sizeof(avconfig_t) << PAGESIZE // assume that sizeof(avconfig_t) << PAGESIZE
memcpy(databuf+pageoffset, &tc, sizeof(avconfig_t)); memcpy(databuf+pageoffset, &tc, sizeof(avconfig_t));
pageoffset += sizeof(avconfig_t); pageoffset += sizeof(avconfig_t);
srcoffset = 0; // write a full page first
memcpy(databuf+pageoffset, (char*)video_modes, PAGESIZE-pageoffset);
srcoffset = PAGESIZE-pageoffset;
vm_to_write -= PAGESIZE-pageoffset;
write_flash_page(databuf, PAGESIZE, ((USERDATA_OFFSET+entry*SECTORSIZE)/PAGESIZE));
// then write the rest
pageno = 1;
while (vm_to_write > 0) { while (vm_to_write > 0) {
if (vm_to_write >= PAGESIZE-pageoffset) { bytes_to_w = (vm_to_write > PAGESIZE) ? PAGESIZE : vm_to_write;
memcpy(databuf+pageoffset, (char*)video_modes+srcoffset, PAGESIZE-pageoffset); memcpy(databuf, (char*)video_modes+srcoffset, bytes_to_w);
srcoffset += PAGESIZE-pageoffset; write_flash_page(databuf, bytes_to_w, ((USERDATA_OFFSET+entry*SECTORSIZE)/PAGESIZE) + pageno);
pageoffset = 0; srcoffset += bytes_to_w;
vm_to_write -= PAGESIZE-pageoffset; vm_to_write -= bytes_to_w;
// check ++pageno;
write_flash_page(databuf, PAGESIZE, ((USERDATA_OFFSET+entry*SECTORSIZE)/PAGESIZE) + pageno);
pageno++;
} else {
memcpy(databuf+pageoffset, (char*)video_modes+srcoffset, vm_to_write);
pageoffset += vm_to_write;
vm_to_write = 0;
// check
write_flash_page(databuf, PAGESIZE, ((USERDATA_OFFSET+entry*SECTORSIZE)/PAGESIZE) + pageno);
}
} }
printf("Profile %u data written (%u bytes)\n", entry, sizeof(avconfig_t)+VIDEO_MODES_SIZE); printf("Profile %u data written (%u bytes)\n", entry, sizeof(avconfig_t)+VIDEO_MODES_SIZE);
break; break;
default: default:
@ -133,10 +135,13 @@ int read_userdata(alt_u8 entry)
switch (((ude_hdr*)databuf)->type) { switch (((ude_hdr*)databuf)->type) {
case UDE_INITCFG: case UDE_INITCFG:
if (((ude_initcfg*)databuf)->data_len == sizeof(ude_initcfg) - offsetof(ude_initcfg, last_profile)) { if (((ude_initcfg*)databuf)->data_len == sizeof(ude_initcfg) - offsetof(ude_initcfg, last_profile)) {
if (((ude_initcfg*)databuf)->last_profile <= MAX_PROFILE) for (alt_u8 i = 0; i < sizeof(input_profiles)/sizeof(*input_profiles); ++i)
profile_sel = ((ude_initcfg*)databuf)->last_profile; 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) if (((ude_initcfg*)databuf)->last_input < AV_LAST)
target_mode = ((ude_initcfg*)databuf)->last_input; target_mode = ((ude_initcfg*)databuf)->last_input;
def_input = ((ude_initcfg*)databuf)->def_input;
profile_sel = input_profiles[0]; // Arbitrary default
memcpy(rc_keymap, ((ude_initcfg*)databuf)->keys, sizeof(rc_keymap)); memcpy(rc_keymap, ((ude_initcfg*)databuf)->keys, sizeof(rc_keymap));
printf("RC data read (%u bytes)\n", sizeof(rc_keymap)); printf("RC data read (%u bytes)\n", sizeof(rc_keymap));
} }

View File

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