From a03c01ca4db4f3dad95498cb6a1c423da7c8a6e8 Mon Sep 17 00:00:00 2001 From: marqs Date: Sun, 8 Jan 2017 12:02:32 +0200 Subject: [PATCH] Keep track of last used profile and (optionally) input --- software/sys_controller/ossc/av_controller.c | 28 +++++++++++------- software/sys_controller/ossc/av_controller.h | 5 ++-- software/sys_controller/ossc/controls.c | 2 +- software/sys_controller/ossc/menu.c | 2 +- software/sys_controller/ossc/userdata.c | 30 +++++++++++++------- software/sys_controller/ossc/userdata.h | 9 ++++-- software/sys_controller_bsp/settings.bsp | 4 +-- 7 files changed, 51 insertions(+), 29 deletions(-) diff --git a/software/sys_controller/ossc/av_controller.c b/software/sys_controller/ossc/av_controller.c index bfdcad8..50fdf11 100644 --- a/software/sys_controller/ossc/av_controller.c +++ b/software/sys_controller/ossc/av_controller.c @@ -460,6 +460,8 @@ void load_profile_disp(alt_u8 code) { retval = read_userdata(profile_sel); sniprintf(menu_row2, LCD_ROW_LEN+1, "%s", (retval==0) ? "Loaded" : "Load failed"); lcd_write_menu(); + if (retval == 0) + write_userdata(INIT_CONFIG_SLOT); usleep(500000); break; case NO_ACTION: @@ -483,6 +485,8 @@ void save_profile_disp(alt_u8 code) { retval = write_userdata(profile_sel); sniprintf(menu_row2, LCD_ROW_LEN+1, "%s", (retval==0) ? "Saved" : "Save failed"); lcd_write_menu(); + if (retval == 0) + write_userdata(INIT_CONFIG_SLOT); usleep(500000); break; case NO_ACTION: @@ -593,17 +597,17 @@ int init_hw() return -1; } + // Set defaults set_default_avconfig(); - - // Load default profile - read_userdata(0); - - // Load / setup remote keymap memcpy(rc_keymap, rc_keymap_default, sizeof(rc_keymap)); + + // Load initconfig and profile + read_userdata(INIT_CONFIG_SLOT); + read_userdata(profile_sel); + + // Setup remote keymap if (!(IORD_ALTERA_AVALON_PIO_DATA(PIO_1_BASE) & PB1_BIT)) setup_rc(); - else - read_userdata(RC_CONFIG_SLOT); // init always in HDMI mode (fixes yellow screen bug) TX_enable(TX_HDMI); @@ -643,11 +647,12 @@ int main() printf("### DIY VIDEO DIGITIZER / SCANCONVERTER INIT OK ###\n\n"); sniprintf(row1, LCD_ROW_LEN+1, "OSSC fw. %u.%.2u" FW_SUFFIX1 FW_SUFFIX2, FW_VER_MAJOR, FW_VER_MINOR); #ifndef DEBUG - strncpy(row2, "2014-2016 marqs", LCD_ROW_LEN+1); + strncpy(row2, "2014-2017 marqs", LCD_ROW_LEN+1); #else strncpy(row2, "** DEBUG BUILD *", LCD_ROW_LEN+1); #endif lcd_write_status(); + usleep(500000); } else { sniprintf(row1, LCD_ROW_LEN+1, "Init error %d", init_stat); strncpy(row2, "", LCD_ROW_LEN+1); @@ -655,7 +660,8 @@ int main() while (1) {} } - target_mode = tc.def_input; + if (tc.def_input < AV_LAST) + target_mode = tc.def_input; // Mainloop while(1) { @@ -737,7 +743,6 @@ int main() if (target_mode != AV_KEEP) { printf("### SWITCH MODE TO %s ###\n", avinput_str[target_mode]); - av_init = 1; 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); @@ -751,6 +756,9 @@ int main() strncpy(row2, " NO SYNC", LCD_ROW_LEN+1); if (!menu_active) lcd_write_status(); + if (av_init && (tc.def_input == AV_LAST)) + write_userdata(INIT_CONFIG_SLOT); + av_init = 1; } // Check here to enable regardless of av_init diff --git a/software/sys_controller/ossc/av_controller.h b/software/sys_controller/ossc/av_controller.h index af78ac2..671a606 100644 --- a/software/sys_controller/ossc/av_controller.h +++ b/software/sys_controller/ossc/av_controller.h @@ -33,7 +33,7 @@ #define VIDGEN_OFF (1<<1) #define AV_RESET_N (1<<0) -static const char *avinput_str[] = { "Test pattern", "AV1: RGBS", "AV1: RGsB", "AV1: YPbPr", "AV2: YPbPr", "AV2: RGsB", "AV3: RGBHV", "AV3: RGBS", "AV3: RGsB", "AV3: YPbPr" }; +static const char *avinput_str[] = { "Test pattern", "AV1: RGBS", "AV1: RGsB", "AV1: YPbPr", "AV2: YPbPr", "AV2: RGsB", "AV3: RGBHV", "AV3: RGBS", "AV3: RGsB", "AV3: YPbPr", "Last used" }; typedef enum { AV_KEEP = 0, @@ -45,7 +45,8 @@ typedef enum { AV3_RGBHV = 6, AV3_RGBs = 7, AV3_RGsB = 8, - AV3_YPBPR = 9 + AV3_YPBPR = 9, + AV_LAST = 10 } avinput_t; // In reverse order of importance diff --git a/software/sys_controller/ossc/controls.c b/software/sys_controller/ossc/controls.c index e0d01f5..aae9227 100644 --- a/software/sys_controller/ossc/controls.c +++ b/software/sys_controller/ossc/controls.c @@ -100,7 +100,7 @@ void setup_rc() usleep(WAITLOOP_SLEEP_US); } } - write_userdata(RC_CONFIG_SLOT); + write_userdata(INIT_CONFIG_SLOT); } void parse_control() diff --git a/software/sys_controller/ossc/menu.c b/software/sys_controller/ossc/menu.c index a515b88..6547c91 100644 --- a/software/sys_controller/ossc/menu.c +++ b/software/sys_controller/ossc/menu.c @@ -162,7 +162,7 @@ void display_menu(alt_u8 forcedisp) } } - if (!forcedisp && (code == NO_ACTION)) + if (!forcedisp && !remote_code) return; type = navi[navlvl].m->items[navi[navlvl].mp].type; diff --git a/software/sys_controller/ossc/userdata.c b/software/sys_controller/ossc/userdata.c index 434f344..0ea1807 100644 --- a/software/sys_controller/ossc/userdata.c +++ b/software/sys_controller/ossc/userdata.c @@ -25,9 +25,12 @@ #include "av_controller.h" extern alt_u16 rc_keymap[REMOTE_MAX_KEYS]; +extern avmode_t cm; extern avconfig_t tc; extern mode_data_t video_modes[]; +extern avinput_t target_mode; extern alt_u8 update_cur_vm; +extern alt_u8 profile_sel; int write_userdata(alt_u8 entry) { @@ -45,16 +48,19 @@ int write_userdata(alt_u8 entry) strncpy(((ude_hdr*)databuf)->userdata_key, "USRDATA", 8); ((ude_hdr*)databuf)->version_major = FW_VER_MAJOR; ((ude_hdr*)databuf)->version_minor = FW_VER_MINOR; - ((ude_hdr*)databuf)->type = (entry > MAX_PROFILE) ? UDE_REMOTE_MAP : UDE_PROFILE; + ((ude_hdr*)databuf)->type = (entry > MAX_PROFILE) ? UDE_INITCFG : UDE_PROFILE; switch (((ude_hdr*)databuf)->type) { - case UDE_REMOTE_MAP: - ((ude_remote_map*)databuf)->data_len = sizeof(rc_keymap); - memcpy(((ude_remote_map*)databuf)->keys, rc_keymap, sizeof(rc_keymap)); - retval = write_flash_page(databuf, sizeof(ude_remote_map), (USERDATA_OFFSET+entry*SECTORSIZE)/PAGESIZE); - if (retval != 0) { + case UDE_INITCFG: + ((ude_initcfg*)databuf)->data_len = sizeof(ude_initcfg) - offsetof(ude_initcfg, last_profile); + ((ude_initcfg*)databuf)->last_profile = profile_sel; + ((ude_initcfg*)databuf)->last_input = cm.avinput; + 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) return -1; - } + + printf("Initconfig data written (%u bytes)\n", sizeof(ude_initcfg) - offsetof(ude_initcfg, last_profile)); break; case UDE_PROFILE: vm_to_write = VIDEO_MODES_SIZE; @@ -125,9 +131,13 @@ int read_userdata(alt_u8 entry) } switch (((ude_hdr*)databuf)->type) { - case UDE_REMOTE_MAP: - if (((ude_remote_map*)databuf)->data_len == sizeof(rc_keymap)) { - memcpy(rc_keymap, ((ude_remote_map*)databuf)->keys, sizeof(rc_keymap)); + 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; + if (((ude_initcfg*)databuf)->last_input < AV_LAST) + target_mode = ((ude_initcfg*)databuf)->last_input; + memcpy(rc_keymap, ((ude_initcfg*)databuf)->keys, sizeof(rc_keymap)); printf("RC data read (%u bytes)\n", sizeof(rc_keymap)); } break; diff --git a/software/sys_controller/ossc/userdata.h b/software/sys_controller/ossc/userdata.h index b970002..114718a 100644 --- a/software/sys_controller/ossc/userdata.h +++ b/software/sys_controller/ossc/userdata.h @@ -23,15 +23,16 @@ #include "alt_types.h" #include "sysconfig.h" #include "controls.h" +#include "av_controller.h" #include "avconfig.h" #include "video_modes.h" #include "flash.h" #define MAX_PROFILE 9 -#define RC_CONFIG_SLOT MAX_USERDATA_ENTRY +#define INIT_CONFIG_SLOT MAX_USERDATA_ENTRY typedef enum { - UDE_REMOTE_MAP = 0, + UDE_INITCFG = 0, UDE_PROFILE, } ude_type; @@ -45,8 +46,10 @@ typedef struct { typedef struct { ude_hdr hdr; alt_u16 data_len; + alt_u8 last_profile; + avinput_t last_input; alt_u16 keys[REMOTE_MAX_KEYS]; -} __attribute__((packed, __may_alias__)) ude_remote_map; +} __attribute__((packed, __may_alias__)) ude_initcfg; typedef struct { ude_hdr hdr; diff --git a/software/sys_controller_bsp/settings.bsp b/software/sys_controller_bsp/settings.bsp index dbc7b42..4239b44 100644 --- a/software/sys_controller_bsp/settings.bsp +++ b/software/sys_controller_bsp/settings.bsp @@ -2,8 +2,8 @@ hal default - Dec 31, 2016 11:50:32 AM - 1483177832665 + Jan 7, 2017 11:01:41 PM + 1483822901087 ./ settings.bsp ../../sys.sopcinfo