mirror of
https://github.com/marqs85/ossc
synced 2025-10-26 05:26:02 +03:00
integrate userdata structure from Ossc Pro
This commit is contained in:
parent
05a9e351d4
commit
3194ec6ed3
2
ossc.cof
2
ossc.cof
@ -16,7 +16,7 @@
|
||||
<hex_block>
|
||||
<hex_filename>software/sys_controller/mem_init/flash.hex</hex_filename>
|
||||
<hex_addressing>relative</hex_addressing>
|
||||
<hex_offset>524288</hex_offset>
|
||||
<hex_offset>327680</hex_offset>
|
||||
<hex_little_endian>0</hex_little_endian>
|
||||
</hex_block>
|
||||
<version>10</version>
|
||||
|
||||
@ -377,7 +377,7 @@ sys sys_inst(
|
||||
.reset_po_reset_n (po_reset_n),
|
||||
.ibex_0_ndm_ndmreset_o (ndmreset_req),
|
||||
.ibex_0_ndm_ndmreset_ack_i (ndmreset_ack),
|
||||
.ibex_0_config_boot_addr_i (32'h02080000),
|
||||
.ibex_0_config_boot_addr_i (32'h02050000),
|
||||
.ibex_0_config_core_sleep_o (),
|
||||
.master_0_master_reset_reset (jtagm_reset_req),
|
||||
.i2c_opencores_0_export_scl_pad_io (scl),
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
# flash details
|
||||
set flash_base 0x02000000
|
||||
set flash_imem_offset 0x00080000
|
||||
set flash_imem_offset 0x00050000
|
||||
set flash_imem_base [format 0x%.8x [expr $flash_base + $flash_imem_offset]]
|
||||
set flash_secsize 65536
|
||||
|
||||
|
||||
@ -1150,8 +1150,8 @@ src/userdata_sjis.c: src/userdata.c
|
||||
iconv -f UTF-8 -t SHIFT-JIS src/userdata.c > src/userdata_sjis.c
|
||||
|
||||
mem_init/flash.hex: sys_controller.elf
|
||||
$(RV_OBJCOPY) --change-addresses -0x02080000 -O binary --gap-fill 0 $< mem_init/flash.bin
|
||||
$(RV_OBJCOPY) --change-addresses -0x02080000 -O ihex --gap-fill 0 $< mem_init/flash.hex
|
||||
$(RV_OBJCOPY) --change-addresses -0x02050000 -O binary --gap-fill 0 $< mem_init/flash.bin
|
||||
$(RV_OBJCOPY) --change-addresses -0x02050000 -O ihex --gap-fill 0 $< mem_init/flash.hex
|
||||
mkdir -p mem_init/chunks
|
||||
rm -f mem_init/chunks/*
|
||||
split -d -b 1024 -a 4 mem_init/flash.bin mem_init/chunks/flash.
|
||||
|
||||
@ -65,18 +65,24 @@ extern alt_u16 rc_keymap_default[REMOTE_MAX_KEYS];
|
||||
extern alt_u32 remote_code;
|
||||
extern alt_u32 btn_code, btn_code_prev;
|
||||
extern alt_u8 remote_rpt, remote_rpt_prev;
|
||||
extern avconfig_t tc, tc_default;
|
||||
extern avconfig_t tc;
|
||||
extern alt_u8 vm_sel;
|
||||
extern char target_profile_name[PROFILE_NAME_LEN+1];
|
||||
extern char target_profile_name[USERDATA_NAME_LEN+1];
|
||||
|
||||
tvp_input_t target_tvp;
|
||||
tvp_sync_input_t target_tvp_sync;
|
||||
alt_u8 target_type;
|
||||
alt_u8 update_cur_vm;
|
||||
|
||||
alt_u8 profile_sel, profile_sel_menu, input_profiles[AV_LAST], lt_sel, def_input, profile_link, lcd_bl_timeout;
|
||||
alt_u8 osd_enable=1, osd_status_timeout=1, osd_highlight_color=4;
|
||||
alt_u8 auto_input, auto_av1_ypbpr, auto_av2_ypbpr = 1, auto_av3_ypbpr;
|
||||
// Default settings
|
||||
const settings_t ts_default = {
|
||||
.osd_enable = 1,
|
||||
.osd_status_timeout = 1,
|
||||
.osd_highlight_color = 4,
|
||||
.auto_av2_ypbpr = 1,
|
||||
};
|
||||
|
||||
alt_u8 profile_sel, profile_sel_menu, sd_profile_sel_menu, input_profiles[AV_LAST], lt_sel;
|
||||
|
||||
char row1[LCD_ROW_LEN+1], row2[LCD_ROW_LEN+1], menu_row1[LCD_ROW_LEN+1], menu_row2[LCD_ROW_LEN+1];
|
||||
|
||||
@ -97,6 +103,8 @@ alt_u32 read_it2(alt_u32 regaddr);
|
||||
mode_data_t vmode_in, vmode_out;
|
||||
vm_proc_config_t vm_conf;
|
||||
|
||||
settings_t cs, ts;
|
||||
|
||||
// Manually (see cyiv-51005.pdf) or automatically (MIF/HEX from PLL megafunction) generated config may not
|
||||
// provide fully correct scan chain data (e.g. mismatches in C3) and lead to incorrect PLL configuration.
|
||||
// To get correct scan chain data, do the following:
|
||||
@ -140,9 +148,9 @@ int loaded_lc_palette = -1;
|
||||
|
||||
void ui_disp_menu(alt_u8 osd_mode)
|
||||
{
|
||||
alt_u8 menu_page;
|
||||
uint8_t menu_page;
|
||||
|
||||
if ((osd_mode == 1) || (osd_enable == 2)) {
|
||||
if ((osd_mode == 1) || (ts.osd_enable == 2)) {
|
||||
strncpy((char*)osd->osd_array.data[0][0], menu_row1, OSD_CHAR_COLS);
|
||||
strncpy((char*)osd->osd_array.data[1][0], menu_row2, OSD_CHAR_COLS);
|
||||
osd->osd_row_color.mask = 0;
|
||||
@ -763,7 +771,7 @@ int load_profile() {
|
||||
target_input = tc.link_av;
|
||||
|
||||
// Update profile link (also prevents the change of input from inducing a profile load).
|
||||
input_profiles[profile_link ? target_input : AV_TESTPAT] = profile_sel;
|
||||
input_profiles[ts.profile_link ? target_input : AV_TESTPAT] = profile_sel;
|
||||
write_userdata(INIT_CONFIG_SLOT);
|
||||
}
|
||||
|
||||
@ -777,13 +785,18 @@ int save_profile() {
|
||||
if (retval == 0) {
|
||||
profile_sel = profile_sel_menu;
|
||||
|
||||
input_profiles[profile_link ? cm.avinput : AV_TESTPAT] = profile_sel;
|
||||
input_profiles[ts.profile_link ? cm.avinput : AV_TESTPAT] = profile_sel;
|
||||
write_userdata(INIT_CONFIG_SLOT);
|
||||
}
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
||||
void set_default_settings() {
|
||||
memcpy(&ts, &ts_default, sizeof(settings_t));
|
||||
set_default_keymap();
|
||||
}
|
||||
|
||||
void set_default_c_shmask() {
|
||||
memset(&c_shmask, 0, sizeof(c_shmask));
|
||||
strncpy(c_shmask.name, "Custom: <none>", 20);
|
||||
@ -857,17 +870,19 @@ int init_hw()
|
||||
}*/
|
||||
|
||||
// Set defaults
|
||||
set_default_avconfig();
|
||||
memcpy(&cm.cc, &tc_default, sizeof(avconfig_t));
|
||||
set_default_profile(1);
|
||||
set_default_c_shmask();
|
||||
memcpy(rc_keymap, rc_keymap_default, sizeof(rc_keymap));
|
||||
set_default_settings();
|
||||
|
||||
// Init menu
|
||||
init_menu();
|
||||
|
||||
// Load initconfig and profile
|
||||
//read_userdata(INIT_CONFIG_SLOT, 0);
|
||||
//read_userdata(profile_sel, 0);
|
||||
read_userdata(INIT_CONFIG_SLOT, 0);
|
||||
profile_sel = input_profiles[AV_TESTPAT]; // Global profile
|
||||
read_userdata(profile_sel, 0);
|
||||
|
||||
update_settings(1);
|
||||
|
||||
// Setup test pattern
|
||||
get_vmode(VMODE_480p, &vmode_in, &vmode_out, &vm_conf);
|
||||
@ -977,6 +992,19 @@ int latency_test() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
void update_settings(int init_setup) {
|
||||
if (init_setup || (ts.osd_enable != cs.osd_enable) || (ts.osd_status_timeout != cs.osd_status_timeout) || (ts.osd_highlight_color != cs.osd_highlight_color)) {
|
||||
osd->osd_config.enable = !!ts.osd_enable;
|
||||
osd->osd_config.status_timeout = ts.osd_status_timeout;
|
||||
osd->osd_config.highlight_color = 2+ts.osd_highlight_color;
|
||||
refresh_osd();
|
||||
}
|
||||
if (init_setup)
|
||||
target_input = ts.def_input;
|
||||
|
||||
memcpy(&cs, &ts, sizeof(settings_t));
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
ths_input_t target_ths = 0;
|
||||
@ -1044,19 +1072,19 @@ int main()
|
||||
}
|
||||
|
||||
// Auto input switching
|
||||
if ((auto_input != AUTO_OFF) && (cm.avinput != AV_TESTPAT) && !cm.sync_active && !menu_active
|
||||
if ((cs.auto_input != AUTO_OFF) && (cm.avinput != AV_TESTPAT) && !cm.sync_active && !menu_active
|
||||
&& (alt_timestamp() >= auto_input_timestamp + 300 * (alt_timestamp_freq() >> 10)) && (auto_input_ctr < AUTO_MAX_COUNT)) {
|
||||
|
||||
// Keep switching on the same physical input when set to Current input or a short time after losing sync.
|
||||
auto_input_keep_current = (auto_input == AUTO_CURRENT_INPUT || auto_input_current_ctr < AUTO_CURRENT_MAX_COUNT);
|
||||
auto_input_keep_current = (cs.auto_input == AUTO_CURRENT_INPUT || auto_input_current_ctr < AUTO_CURRENT_MAX_COUNT);
|
||||
|
||||
switch(cm.avinput) {
|
||||
case AV1_RGBs:
|
||||
target_input = auto_av1_ypbpr ? AV1_YPBPR : AV1_RGsB;
|
||||
target_input = cs.auto_av1_ypbpr ? AV1_YPBPR : AV1_RGsB;
|
||||
break;
|
||||
case AV1_RGsB:
|
||||
case AV1_YPBPR:
|
||||
target_input = auto_input_keep_current ? AV1_RGBs : (auto_av2_ypbpr ? AV2_YPBPR : AV2_RGsB);
|
||||
target_input = auto_input_keep_current ? AV1_RGBs : (cs.auto_av2_ypbpr ? AV2_YPBPR : AV2_RGsB);
|
||||
break;
|
||||
case AV2_YPBPR:
|
||||
case AV2_RGsB:
|
||||
@ -1066,7 +1094,7 @@ int main()
|
||||
target_input = AV3_RGBs;
|
||||
break;
|
||||
case AV3_RGBs:
|
||||
target_input = auto_av3_ypbpr ? AV3_YPBPR : AV3_RGsB;
|
||||
target_input = cs.auto_av3_ypbpr ? AV3_YPBPR : AV3_RGsB;
|
||||
break;
|
||||
case AV3_RGsB:
|
||||
case AV3_YPBPR:
|
||||
@ -1097,7 +1125,7 @@ int main()
|
||||
if ((target_input != cm.avinput && man_input_change) || (auto_input_changed && cm.sync_active)) {
|
||||
// The input changed, so load the appropriate profile if
|
||||
// input->profile link is enabled
|
||||
if (profile_link && (profile_sel != input_profiles[target_input])) {
|
||||
if (cs.profile_link && (profile_sel != input_profiles[target_input])) {
|
||||
profile_sel = input_profiles[target_input];
|
||||
read_userdata(profile_sel, 0);
|
||||
}
|
||||
@ -1182,7 +1210,7 @@ int main()
|
||||
ui_disp_status(1);
|
||||
if (man_input_change) {
|
||||
// record last input if it was selected manually
|
||||
if (def_input == AV_LAST)
|
||||
if (cs.def_input == AV_LAST)
|
||||
write_userdata(INIT_CONFIG_SLOT);
|
||||
// Set auto_input_timestamp when input is manually changed
|
||||
auto_input_ctr = 0;
|
||||
@ -1222,16 +1250,8 @@ int main()
|
||||
printf("Changing AV3 RGB source\n");
|
||||
cm.cc.av3_alt_rgb = tc.av3_alt_rgb;
|
||||
}
|
||||
if ((!!osd_enable != osd->osd_config.enable) || (osd_status_timeout != osd->osd_config.status_timeout) || (osd_highlight_color != osd->osd_config.highlight_color)) {
|
||||
osd->osd_config.enable = !!osd_enable;
|
||||
osd->osd_config.status_timeout = osd_status_timeout;
|
||||
osd->osd_config.highlight_color = 2+osd_highlight_color;
|
||||
if (menu_active) {
|
||||
remote_code = 0;
|
||||
render_osd_page();
|
||||
display_menu(1);
|
||||
}
|
||||
}
|
||||
|
||||
update_settings(0);
|
||||
|
||||
if (cm.avinput != AV_TESTPAT) {
|
||||
status = get_status(target_tvp_sync);
|
||||
|
||||
@ -89,6 +89,20 @@ typedef struct {
|
||||
avconfig_t cc;
|
||||
} avmode_t;
|
||||
|
||||
typedef struct {
|
||||
uint8_t profile_link;
|
||||
avinput_t def_input;
|
||||
uint8_t auto_input;
|
||||
uint8_t auto_av1_ypbpr;
|
||||
uint8_t auto_av2_ypbpr;
|
||||
uint8_t auto_av3_ypbpr;
|
||||
uint8_t lcd_bl_timeout;
|
||||
uint8_t osd_enable;
|
||||
uint8_t osd_status_timeout;
|
||||
uint8_t osd_highlight_color;
|
||||
uint8_t phase_hotkey_enable;
|
||||
} settings_t;
|
||||
|
||||
typedef struct {
|
||||
uint8_t iv_x;
|
||||
uint8_t iv_y;
|
||||
@ -117,10 +131,9 @@ void ui_disp_status(alt_u8 refresh_osd_timer);
|
||||
|
||||
void set_sampler_phase(uint8_t sampler_phase, uint8_t update_sc);
|
||||
|
||||
int load_profile();
|
||||
int save_profile();
|
||||
|
||||
void print_vm_stats();
|
||||
int latency_test();
|
||||
|
||||
void update_settings(int init_setup);
|
||||
|
||||
#endif
|
||||
|
||||
@ -157,6 +157,11 @@ typedef struct {
|
||||
avinput_t link_av;
|
||||
} __attribute__((packed)) avconfig_t;
|
||||
|
||||
int set_default_avconfig();
|
||||
int set_default_profile(int update_cc);
|
||||
int reset_profile();
|
||||
int load_profile();
|
||||
int save_profile();
|
||||
int load_profile_sd();
|
||||
int save_profile_sd();
|
||||
|
||||
#endif
|
||||
|
||||
@ -60,6 +60,7 @@ typedef enum {
|
||||
#define REMOTE_MAX_KEYS (RC_PROF_HOTKEY-RC_BTN1+1)
|
||||
|
||||
void setup_rc();
|
||||
void set_default_keymap();
|
||||
int parse_control();
|
||||
|
||||
#endif
|
||||
|
||||
@ -21,26 +21,17 @@
|
||||
#define FIRMWARE_H_
|
||||
|
||||
#include <stdint.h>
|
||||
#include "alt_types.h"
|
||||
#include "sysconfig.h"
|
||||
|
||||
#define FW_VER_MAJOR 1
|
||||
#define FW_VER_MINOR 20
|
||||
|
||||
#define PROFILE_VER_MAJOR 1
|
||||
#define PROFILE_VER_MINOR 12
|
||||
|
||||
#define INITCFG_VER_MAJOR 1
|
||||
#define INITCFG_VER_MINOR 20
|
||||
|
||||
#ifdef OSDLANG_JP
|
||||
#define FW_SUFFIX "j"
|
||||
#else
|
||||
#define FW_SUFFIX ""
|
||||
#endif
|
||||
|
||||
#define FW_UPDATE_RETRIES 3
|
||||
|
||||
typedef struct {
|
||||
char fw_key[4];
|
||||
uint8_t version_major;
|
||||
|
||||
@ -128,6 +128,7 @@ void render_osd_page();
|
||||
void display_menu(alt_u8 forcedisp);
|
||||
void sampler_phase_disp(alt_u8 v);
|
||||
void update_osd_size(mode_data_t *vm_out);
|
||||
void refresh_osd();
|
||||
static void vm_select();
|
||||
static void vm_tweak(alt_u16 *v);
|
||||
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
//
|
||||
// Copyright (C) 2015-2023 Markus Hiienkari <mhiienka@niksula.hut.fi>
|
||||
// Copyright (C) 2015-2025 Markus Hiienkari <mhiienka@niksula.hut.fi>
|
||||
//
|
||||
// This file is part of Open Source Scan Converter project.
|
||||
//
|
||||
@ -20,29 +20,17 @@
|
||||
#ifndef USERDATA_H_
|
||||
#define USERDATA_H_
|
||||
|
||||
#include "alt_types.h"
|
||||
#include <stdint.h>
|
||||
#include "sysconfig.h"
|
||||
#include "controls.h"
|
||||
#include "av_controller.h"
|
||||
#include "avconfig.h"
|
||||
#include "video_modes.h"
|
||||
#include "flash.h"
|
||||
|
||||
#define PROFILE_NAME_LEN 12
|
||||
|
||||
// EPCS16 pagesize is 256 bytes
|
||||
// Flash is split 50-50 to FW and userdata, 1MB each
|
||||
#define PAGESIZE 256
|
||||
#define PAGES_PER_SECTOR 256 //EPCS "sector" corresponds to "block" on Spansion flash
|
||||
#define SECTORSIZE (PAGESIZE*PAGES_PER_SECTOR)
|
||||
#define USERDATA_OFFSET 0x100000
|
||||
#define MAX_USERDATA_ENTRY 15 // 16 sectors for userdata
|
||||
#define USERDATA_NAME_LEN 13
|
||||
#define MAX_USERDATA_ENTRY 15
|
||||
#define MAX_SD_USERDATA_ENTRY 100
|
||||
|
||||
#define MAX_PROFILE (MAX_USERDATA_ENTRY-1)
|
||||
#define MAX_SD_PROFILE (MAX_SD_USERDATA_ENTRY-1)
|
||||
#define INIT_CONFIG_SLOT MAX_USERDATA_ENTRY
|
||||
|
||||
#define UDATA_IMPT_CANCELLED 104
|
||||
#define UDATA_EXPT_CANCELLED 105
|
||||
#define SD_INIT_CONFIG_SLOT MAX_SD_USERDATA_ENTRY
|
||||
|
||||
typedef enum {
|
||||
UDE_INITCFG = 0,
|
||||
@ -51,41 +39,26 @@ typedef enum {
|
||||
|
||||
typedef struct {
|
||||
char userdata_key[8];
|
||||
alt_u8 version_major;
|
||||
alt_u8 version_minor;
|
||||
char name[USERDATA_NAME_LEN+1];
|
||||
ude_type type;
|
||||
uint8_t num_items;
|
||||
} __attribute__((packed, __may_alias__)) ude_hdr;
|
||||
|
||||
typedef struct {
|
||||
ude_hdr hdr;
|
||||
alt_u16 data_len;
|
||||
alt_u8 last_profile[AV_LAST];
|
||||
alt_u8 profile_link;
|
||||
avinput_t last_input;
|
||||
avinput_t def_input;
|
||||
alt_u8 lcd_bl_timeout;
|
||||
alt_u8 auto_input;
|
||||
alt_u8 auto_av1_ypbpr;
|
||||
alt_u8 auto_av2_ypbpr;
|
||||
alt_u8 auto_av3_ypbpr;
|
||||
alt_u8 osd_enable;
|
||||
alt_u8 osd_status_timeout;
|
||||
alt_u8 osd_highlight_color;
|
||||
alt_u8 phase_hotkey_enable;
|
||||
alt_u16 keys[REMOTE_MAX_KEYS];
|
||||
} __attribute__((packed, __may_alias__)) ude_initcfg;
|
||||
uint16_t id;
|
||||
uint16_t version;
|
||||
uint16_t data_size;
|
||||
} __attribute__((packed, __may_alias__)) ude_item_hdr;
|
||||
|
||||
typedef struct {
|
||||
ude_hdr hdr;
|
||||
char name[PROFILE_NAME_LEN+1];
|
||||
alt_u16 avc_data_len;
|
||||
alt_u16 vm_data_len;
|
||||
avconfig_t avc;
|
||||
//mode_data_t vm[VIDEO_MODES_CNT];
|
||||
} __attribute__((packed, __may_alias__)) ude_profile;
|
||||
ude_item_hdr hdr;
|
||||
void *data;
|
||||
} ude_item_map;
|
||||
|
||||
int write_userdata(alt_u8 entry);
|
||||
int read_userdata(alt_u8 entry, int dry_run);
|
||||
int write_userdata(uint8_t entry);
|
||||
int read_userdata(uint8_t entry, int dry_run);
|
||||
int write_userdata_sd(uint8_t entry);
|
||||
int read_userdata_sd(uint8_t entry, int dry_run);
|
||||
int import_userdata();
|
||||
int export_userdata();
|
||||
|
||||
|
||||
@ -1,14 +1,14 @@
|
||||
SEARCH_DIR(.)
|
||||
__DYNAMIC = 0;
|
||||
|
||||
/* First 16 flash sectors reserved for firmware image (1MB).
|
||||
/* First 16 flash sectors reserved for 2 firmware images (2x 0.5MB).
|
||||
In typical configuration a firmware image consists of
|
||||
* compressed bitstream (8 sectors / 0.5MB)
|
||||
* flash_imem (8 sectors / 0.5MB)
|
||||
* compressed bitstream (5 sectors / 0.3MB)
|
||||
* flash_imem (3 sectors / 0.2MB)
|
||||
Last 16 flash sectors reserved for userdata (16x 64KB). */
|
||||
MEMORY
|
||||
{
|
||||
flash_imem : ORIGIN = 0x02080000, LENGTH = 524288
|
||||
flash_imem : ORIGIN = 0x02050000, LENGTH = 196608
|
||||
dataram : ORIGIN = 0x00010000, LENGTH = 16384
|
||||
}
|
||||
|
||||
|
||||
@ -21,12 +21,15 @@
|
||||
#include "system.h"
|
||||
#include "avconfig.h"
|
||||
#include "av_controller.h"
|
||||
#include "userdata.h"
|
||||
#include "altera_avalon_pio_regs.h"
|
||||
#include "tvp7002.h"
|
||||
|
||||
#define DEFAULT_ON 1
|
||||
|
||||
extern avmode_t cm;
|
||||
extern alt_u8 update_cur_vm;
|
||||
extern uint8_t sd_profile_sel_menu;
|
||||
|
||||
// Target configuration
|
||||
avconfig_t tc;
|
||||
@ -65,14 +68,37 @@ const avconfig_t tc_default = {
|
||||
.link_av = AV_LAST,
|
||||
};
|
||||
|
||||
int set_default_avconfig()
|
||||
int set_default_profile(int update_cc)
|
||||
{
|
||||
memcpy(&tc, &tc_default, sizeof(avconfig_t));
|
||||
|
||||
tc.tx_mode = (IORD_ALTERA_AVALON_PIO_DATA(PIO_1_BASE) & HDMITX_MODE_MASK) ? TX_DVI : TX_HDMI_RGB;
|
||||
|
||||
if (update_cc)
|
||||
memcpy(&cm.cc, &tc, sizeof(avconfig_t));
|
||||
|
||||
set_default_vm_table();
|
||||
update_cur_vm = 1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int reset_profile() {
|
||||
set_default_profile(0);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int load_profile_sd() {
|
||||
return read_userdata_sd(sd_profile_sel_menu, 0);
|
||||
}
|
||||
|
||||
int save_profile_sd() {
|
||||
int retval;
|
||||
|
||||
retval = write_userdata_sd(sd_profile_sel_menu);
|
||||
if (retval == 0)
|
||||
write_userdata_sd(SD_INIT_CONFIG_SLOT);
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
||||
@ -43,12 +43,12 @@ extern char menu_row1[LCD_ROW_LEN+1], menu_row2[LCD_ROW_LEN+1];
|
||||
extern mode_data_t video_modes_plm[];
|
||||
extern avmode_t cm;
|
||||
extern avconfig_t tc;
|
||||
extern settings_t ts;
|
||||
extern avinput_t target_input;
|
||||
extern alt_u8 menu_active;
|
||||
extern alt_u32 sys_ctrl;
|
||||
extern alt_u16 tc_sampler_phase;
|
||||
extern alt_u8 profile_sel, profile_sel_menu;
|
||||
extern alt_u8 lcd_bl_timeout;
|
||||
extern alt_u8 vm_edit;
|
||||
extern volatile osd_regs *osd;
|
||||
|
||||
@ -94,7 +94,7 @@ void setup_rc()
|
||||
|
||||
if ((btn_code_prev == 0) && (btn_code == PB0_BIT)) {
|
||||
if (i == 0) {
|
||||
memcpy(rc_keymap, rc_keymap_default, sizeof(rc_keymap));
|
||||
set_default_keymap();
|
||||
i=REMOTE_MAX_KEYS;
|
||||
} else {
|
||||
i-=2;
|
||||
@ -116,6 +116,10 @@ void setup_rc()
|
||||
osd->osd_config.menu_active = 0;
|
||||
}
|
||||
|
||||
void set_default_keymap() {
|
||||
memcpy(rc_keymap, rc_keymap_default, sizeof(rc_keymap));
|
||||
}
|
||||
|
||||
int parse_control()
|
||||
{
|
||||
int i, prof_x10=0, ret=0, retval;
|
||||
@ -341,7 +345,7 @@ Button_Check:
|
||||
|
||||
sys_ctrl &= ~(3<<LCD_BL_TIMEOUT_OFFS);
|
||||
if (!menu_active)
|
||||
sys_ctrl |= (lcd_bl_timeout << LCD_BL_TIMEOUT_OFFS);
|
||||
sys_ctrl |= (ts.lcd_bl_timeout << LCD_BL_TIMEOUT_OFFS);
|
||||
|
||||
IOWR_ALTERA_AVALON_PIO_DATA(PIO_0_BASE, sys_ctrl);
|
||||
|
||||
|
||||
@ -54,10 +54,12 @@ int fw_update() {
|
||||
uint8_t databuf[SD_BLK_SIZE]; // temp buffer for data
|
||||
uint16_t fs_csize, fs_startsec, cl_iter, cl_soffs;
|
||||
|
||||
retval = file_mount();
|
||||
if (retval != 0) {
|
||||
printf("SD card not detected %d\n", retval);
|
||||
return -1;
|
||||
if (!sdcard_dev.mount) {
|
||||
retval = file_mount();
|
||||
if (retval != 0) {
|
||||
printf("SD card not detected %d\n", retval);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
//sniprintf(dirname_root, sizeof(dirname_root), "/%s", dirname);
|
||||
|
||||
@ -33,15 +33,14 @@
|
||||
extern char row1[LCD_ROW_LEN+1], row2[LCD_ROW_LEN+1], menu_row1[LCD_ROW_LEN+1], menu_row2[LCD_ROW_LEN+1];
|
||||
extern avmode_t cm;
|
||||
extern avconfig_t tc;
|
||||
extern settings_t ts;
|
||||
extern mode_data_t video_modes_plm[];
|
||||
extern alt_u32 remote_code;
|
||||
extern alt_u16 rc_keymap[REMOTE_MAX_KEYS];
|
||||
extern alt_u8 vm_sel, profile_sel_menu, lt_sel, def_input, profile_link, lcd_bl_timeout;
|
||||
extern alt_u8 auto_input, auto_av1_ypbpr, auto_av2_ypbpr, auto_av3_ypbpr;
|
||||
extern alt_u8 vm_sel, profile_sel_menu, sd_profile_sel_menu, lt_sel;
|
||||
extern alt_u8 update_cur_vm;
|
||||
extern alt_u8 osd_enable, osd_status_timeout, osd_highlight_color, phase_hotkey_enable;
|
||||
extern uint8_t sl_def_iv_x, sl_def_iv_y;
|
||||
extern char target_profile_name[PROFILE_NAME_LEN+1];
|
||||
extern char target_profile_name[USERDATA_NAME_LEN+1];
|
||||
extern volatile osd_regs *osd;
|
||||
extern const int num_video_modes_plm;
|
||||
extern c_shmask_t c_shmask;
|
||||
@ -104,7 +103,8 @@ static void lt_disp(alt_u8 v) { strncpy(menu_row2, lt_desc[v], LCD_ROW_LEN+1); }
|
||||
static void aud_db_disp(alt_u8 v) { sniprintf(menu_row2, LCD_ROW_LEN+1, "%d dB", ((alt_8)v-AUDIO_GAIN_0DB)); }
|
||||
static void vm_display_name (alt_u8 v) { strncpy(menu_row2, video_modes_plm[v].name, LCD_ROW_LEN+1); }
|
||||
static void link_av_desc (avinput_t v) { strncpy(menu_row2, v == AV_LAST ? "No link" : avinput_str[v], LCD_ROW_LEN+1); }
|
||||
static void profile_disp(alt_u8 v) { read_userdata(v, 1); sniprintf(menu_row2, LCD_ROW_LEN+1, "%u: %s", v, (target_profile_name[0] == 0) ? "<empty>" : target_profile_name); }
|
||||
static void profile_disp(uint8_t v) { sniprintf(menu_row2, LCD_ROW_LEN+1, "%u: %s", v, (read_userdata(v, 1) != 0) ? "<empty>" : target_profile_name); }
|
||||
static void sd_profile_disp(uint8_t v) { sniprintf(menu_row2, LCD_ROW_LEN+1, "%u: %s", v, (read_userdata_sd(v, 1) != 0) ? "<empty>" : target_profile_name); }
|
||||
static void alc_v_filter_disp(alt_u8 v) { sniprintf(menu_row2, LCD_ROW_LEN+1, LNG("%u lines","%u ライン"), (1<<v)); }
|
||||
static void alc_h_filter_disp(alt_u8 v) { sniprintf(menu_row2, LCD_ROW_LEN+1, LNG("%u pixels","%u ドット"), (1<<(v+1))); }
|
||||
void sampler_phase_disp(alt_u8 v) { sniprintf(menu_row2, LCD_ROW_LEN+1, "%d deg", (v*11250)/1000); }
|
||||
@ -112,6 +112,7 @@ void sampler_phase_disp(alt_u8 v) { sniprintf(menu_row2, LCD_ROW_LEN+1, "%d deg"
|
||||
|
||||
static arg_info_t vm_arg_info = {&vm_sel, 0, vm_display_name};
|
||||
static const arg_info_t profile_arg_info = {&profile_sel_menu, MAX_PROFILE, profile_disp};
|
||||
static const arg_info_t sd_profile_arg_info = {&sd_profile_sel_menu, MAX_SD_PROFILE, sd_profile_disp};
|
||||
static const arg_info_t lt_arg_info = {<_sel, (sizeof(lt_desc)/sizeof(char*))-1, lt_disp};
|
||||
|
||||
|
||||
@ -242,22 +243,24 @@ MENU(menu_audio, P99_PROTECT({ \
|
||||
|
||||
MENU(menu_settings, P99_PROTECT({ \
|
||||
{ LNG("Link prof->input","Link prof->input"), OPT_AVCONFIG_NUMVALUE, { .num = { &tc.link_av, OPT_WRAP, AV1_RGBs, AV_LAST, link_av_desc } } },
|
||||
{ LNG("Link input->prof","Link input->prof"), OPT_AVCONFIG_SELECTION, { .sel = { &profile_link, OPT_WRAP, SETTING_ITEM(off_on_desc) } } },
|
||||
{ LNG("Initial input","ショキニュウリョク"), OPT_AVCONFIG_SELECTION, { .sel = { &def_input, OPT_WRAP, SETTING_ITEM(avinput_str) } } },
|
||||
{ "Autodetect input", OPT_AVCONFIG_SELECTION, { .sel = { &auto_input, OPT_WRAP, SETTING_ITEM(auto_input_desc) } } },
|
||||
{ "Auto AV1 Y/Gs", OPT_AVCONFIG_SELECTION, { .sel = { &auto_av1_ypbpr, OPT_WRAP, SETTING_ITEM(rgsb_ypbpr_desc) } } },
|
||||
{ "Auto AV2 Y/Gs", OPT_AVCONFIG_SELECTION, { .sel = { &auto_av2_ypbpr, OPT_WRAP, SETTING_ITEM(rgsb_ypbpr_desc) } } },
|
||||
{ "Auto AV3 Y/Gs", OPT_AVCONFIG_SELECTION, { .sel = { &auto_av3_ypbpr, OPT_WRAP, SETTING_ITEM(rgsb_ypbpr_desc) } } },
|
||||
{ "LCD BL timeout", OPT_AVCONFIG_SELECTION, { .sel = { &lcd_bl_timeout, OPT_WRAP, SETTING_ITEM(lcd_bl_timeout_desc) } } },
|
||||
{ "OSD", OPT_AVCONFIG_SELECTION, { .sel = { &osd_enable, OPT_WRAP, SETTING_ITEM(osd_enable_desc) } } },
|
||||
{ "OSD status disp.", OPT_AVCONFIG_SELECTION, { .sel = { &osd_status_timeout, OPT_WRAP, SETTING_ITEM(osd_status_desc) } } },
|
||||
{ "OSD cursor color", OPT_AVCONFIG_SELECTION, { .sel = { &osd_highlight_color, OPT_WRAP, SETTING_ITEM(osd_color_desc) } } },
|
||||
{ "Phase hotkey", OPT_AVCONFIG_SELECTION, { .sel = { &phase_hotkey_enable, OPT_WRAP, SETTING_ITEM(off_on_desc) } } },
|
||||
{ LNG("Link input->prof","Link input->prof"), OPT_AVCONFIG_SELECTION, { .sel = { &ts.profile_link, OPT_WRAP, SETTING_ITEM(off_on_desc) } } },
|
||||
{ LNG("Initial input","ショキニュウリョク"), OPT_AVCONFIG_SELECTION, { .sel = { &ts.def_input, OPT_WRAP, SETTING_ITEM(avinput_str) } } },
|
||||
{ "Autodetect input", OPT_AVCONFIG_SELECTION, { .sel = { &ts.auto_input, OPT_WRAP, SETTING_ITEM(auto_input_desc) } } },
|
||||
{ "Auto AV1 Y/Gs", OPT_AVCONFIG_SELECTION, { .sel = { &ts.auto_av1_ypbpr, OPT_WRAP, SETTING_ITEM(rgsb_ypbpr_desc) } } },
|
||||
{ "Auto AV2 Y/Gs", OPT_AVCONFIG_SELECTION, { .sel = { &ts.auto_av2_ypbpr, OPT_WRAP, SETTING_ITEM(rgsb_ypbpr_desc) } } },
|
||||
{ "Auto AV3 Y/Gs", OPT_AVCONFIG_SELECTION, { .sel = { &ts.auto_av3_ypbpr, OPT_WRAP, SETTING_ITEM(rgsb_ypbpr_desc) } } },
|
||||
{ "LCD BL timeout", OPT_AVCONFIG_SELECTION, { .sel = { &ts.lcd_bl_timeout, OPT_WRAP, SETTING_ITEM(lcd_bl_timeout_desc) } } },
|
||||
{ "OSD", OPT_AVCONFIG_SELECTION, { .sel = { &ts.osd_enable, OPT_WRAP, SETTING_ITEM(osd_enable_desc) } } },
|
||||
{ "OSD status disp.", OPT_AVCONFIG_SELECTION, { .sel = { &ts.osd_status_timeout, OPT_WRAP, SETTING_ITEM(osd_status_desc) } } },
|
||||
{ "OSD cursor color", OPT_AVCONFIG_SELECTION, { .sel = { &ts.osd_highlight_color, OPT_WRAP, SETTING_ITEM(osd_color_desc) } } },
|
||||
{ "Phase hotkey", OPT_AVCONFIG_SELECTION, { .sel = { &ts.phase_hotkey_enable, OPT_WRAP, SETTING_ITEM(off_on_desc) } } },
|
||||
{ LNG("<Load profile >","<プロファイルロード >"), OPT_FUNC_CALL, { .fun = { load_profile, &profile_arg_info } } },
|
||||
{ LNG("<Save profile >","<プロファイルセーブ >"), OPT_FUNC_CALL, { .fun = { save_profile, &profile_arg_info } } },
|
||||
{ LNG("<Reset settings>","<セッテイヲショキカ >"), OPT_FUNC_CALL, { .fun = { set_default_avconfig, NULL } } },
|
||||
{ LNG("<Import sett. >","<セッテイヨミコミ >"), OPT_FUNC_CALL, { .fun = { import_userdata, NULL } } },
|
||||
{ LNG("<Export sett. >","<セッテイカキコミ >"), OPT_FUNC_CALL, { .fun = { export_userdata, NULL } } },
|
||||
{ "<SD Load profile>" , OPT_FUNC_CALL, { .fun = { load_profile_sd, &sd_profile_arg_info } } },
|
||||
{ "<SD Save profile>" , OPT_FUNC_CALL, { .fun = { save_profile_sd, &sd_profile_arg_info } } },
|
||||
{ LNG("<Reset profile>","<セッテイヲショキカ >"), OPT_FUNC_CALL, { .fun = { reset_profile, NULL } } },
|
||||
//{ LNG("<Import sett. >","<セッテイヨミコミ >"), OPT_FUNC_CALL, { .fun = { import_userdata, NULL } } },
|
||||
//{ LNG("<Export sett. >","<セッテイカキコミ >"), OPT_FUNC_CALL, { .fun = { export_userdata, NULL } } },
|
||||
{ LNG("<Fw. update >","<ファームウェアアップデート>"), OPT_FUNC_CALL, { .fun = { fw_update, NULL } } },
|
||||
}))
|
||||
|
||||
@ -338,7 +341,7 @@ void render_osd_page() {
|
||||
const menuitem_t *item;
|
||||
uint32_t row_mask[2] = {0, 0};
|
||||
|
||||
if (!menu_active || (osd_enable != 1))
|
||||
if (!menu_active || (ts.osd_enable != 1))
|
||||
return;
|
||||
|
||||
for (i=0; i < navi[navlvl].m->num_items; i++) {
|
||||
@ -502,6 +505,14 @@ void update_osd_size(mode_data_t *vm_out) {
|
||||
osd->osd_config.y_size = osd_size;
|
||||
}
|
||||
|
||||
void refresh_osd() {
|
||||
if (menu_active) {
|
||||
remote_code = 0;
|
||||
render_osd_page();
|
||||
display_menu(1);
|
||||
}
|
||||
}
|
||||
|
||||
static void vm_select() {
|
||||
vm_edit = vm_sel;
|
||||
tc_h_samplerate = video_modes_plm[vm_edit].timings.h_total;
|
||||
|
||||
@ -23,7 +23,6 @@
|
||||
#include <stdio.h>
|
||||
#include "system.h"
|
||||
#include "userdata.h"
|
||||
#include "fat16_export.h"
|
||||
#include "flash.h"
|
||||
#include "sdcard.h"
|
||||
#include "firmware.h"
|
||||
@ -31,510 +30,417 @@
|
||||
#include "controls.h"
|
||||
#include "av_controller.h"
|
||||
#include "menu.h"
|
||||
#include "utils.h"
|
||||
#include "altera_avalon_pio_regs.h"
|
||||
#include "ff.h"
|
||||
#include "file.h"
|
||||
|
||||
#define UDE_ITEM(ID, VER, ITEM) {{ID, VER, sizeof(ITEM)}, &ITEM}
|
||||
|
||||
// include mode array definitions so that sizeof() can be used
|
||||
#define VM_STATIC_INCLUDE
|
||||
#include "video_modes_list.c"
|
||||
#undef VM_STATIC_INCLUDE
|
||||
|
||||
extern alt_u16 rc_keymap[REMOTE_MAX_KEYS];
|
||||
extern avmode_t cm;
|
||||
extern flash_ctrl_dev flashctrl_dev;
|
||||
extern uint16_t rc_keymap[REMOTE_MAX_KEYS];
|
||||
extern uint8_t input_profiles[AV_LAST];
|
||||
extern avconfig_t tc;
|
||||
extern settings_t ts;
|
||||
extern mode_data_t video_modes_plm[];
|
||||
extern avinput_t target_input;
|
||||
extern alt_u8 update_cur_vm;
|
||||
extern alt_u8 input_profiles[AV_LAST];
|
||||
extern alt_u8 profile_sel;
|
||||
extern alt_u8 def_input, profile_link;
|
||||
extern alt_u8 lcd_bl_timeout;
|
||||
extern alt_u8 auto_input, auto_av1_ypbpr, auto_av2_ypbpr, auto_av3_ypbpr;
|
||||
extern alt_u8 osd_enable, osd_status_timeout, osd_highlight_color, phase_hotkey_enable;
|
||||
extern uint8_t update_cur_vm;
|
||||
extern SD_DEV sdcard_dev;
|
||||
extern char menu_row1[LCD_ROW_LEN+1], menu_row2[LCD_ROW_LEN+1];
|
||||
extern c_shmask_t c_shmask;
|
||||
|
||||
char target_profile_name[PROFILE_NAME_LEN+1];
|
||||
char target_profile_name[USERDATA_NAME_LEN+1], cur_profile_name[USERDATA_NAME_LEN+1];
|
||||
|
||||
int write_userdata(alt_u8 entry)
|
||||
{
|
||||
alt_u8 databuf[PAGESIZE];
|
||||
alt_u16 vm_to_write;
|
||||
alt_u16 pageoffset, srcoffset;
|
||||
alt_u8 pageno;
|
||||
alt_u32 bytes_to_w;
|
||||
int retval, i;
|
||||
const ude_item_map ude_initcfg_items[] = {
|
||||
UDE_ITEM(0, 120, rc_keymap),
|
||||
UDE_ITEM(1, 120, input_profiles),
|
||||
UDE_ITEM(2, 120, ts.profile_link),
|
||||
UDE_ITEM(3, 120, ts.def_input),
|
||||
UDE_ITEM(4, 120, ts.auto_input),
|
||||
UDE_ITEM(5, 120, ts.auto_av1_ypbpr),
|
||||
UDE_ITEM(6, 120, ts.auto_av2_ypbpr),
|
||||
UDE_ITEM(7, 120, ts.auto_av3_ypbpr),
|
||||
UDE_ITEM(8, 120, ts.lcd_bl_timeout),
|
||||
UDE_ITEM(9, 120, ts.osd_enable),
|
||||
UDE_ITEM(10, 120, ts.osd_status_timeout),
|
||||
UDE_ITEM(11, 120, ts.osd_highlight_color),
|
||||
UDE_ITEM(12, 120, ts.phase_hotkey_enable),
|
||||
};
|
||||
|
||||
const ude_item_map ude_profile_items[] = {
|
||||
{{0, 120, sizeof(video_modes_plm_default)}, video_modes_plm},
|
||||
UDE_ITEM(1, 120, c_shmask),
|
||||
// avconfig_t
|
||||
UDE_ITEM(2, 120, tc.pm_240p),
|
||||
UDE_ITEM(3, 120, tc.pm_384p),
|
||||
UDE_ITEM(4, 120, tc.pm_480i),
|
||||
UDE_ITEM(5, 120, tc.pm_480p),
|
||||
UDE_ITEM(6, 120, tc.pm_1080i),
|
||||
UDE_ITEM(7, 120, tc.pt_mode),
|
||||
UDE_ITEM(8, 120, tc.l2_mode),
|
||||
UDE_ITEM(9, 120, tc.l3_mode),
|
||||
UDE_ITEM(10, 120, tc.l4_mode),
|
||||
UDE_ITEM(11, 120, tc.l5_mode),
|
||||
UDE_ITEM(12, 120, tc.l6_mode),
|
||||
UDE_ITEM(13, 120, tc.l5_fmt),
|
||||
UDE_ITEM(14, 120, tc.s480p_mode),
|
||||
UDE_ITEM(15, 120, tc.s400p_mode),
|
||||
UDE_ITEM(16, 120, tc.upsample2x),
|
||||
UDE_ITEM(17, 120, tc.ar_256col),
|
||||
UDE_ITEM(18, 120, tc.default_vic),
|
||||
UDE_ITEM(19, 120, tc.clamp_offset),
|
||||
UDE_ITEM(20, 120, tc.tvp_hpll2x),
|
||||
UDE_ITEM(21, 120, tc.adc_pll_bw),
|
||||
UDE_ITEM(22, 120, tc.fpga_pll_bw),
|
||||
UDE_ITEM(23, 120, tc.sl_mode),
|
||||
UDE_ITEM(24, 120, tc.sl_type),
|
||||
UDE_ITEM(25, 120, tc.sl_hybr_str),
|
||||
UDE_ITEM(26, 120, tc.sl_method),
|
||||
UDE_ITEM(27, 120, tc.sl_altern),
|
||||
UDE_ITEM(28, 120, tc.sl_str),
|
||||
UDE_ITEM(29, 120, tc.sl_id),
|
||||
UDE_ITEM(30, 120, tc.sl_cust_l_str),
|
||||
UDE_ITEM(31, 120, tc.sl_cust_c_str),
|
||||
UDE_ITEM(32, 120, tc.sl_cust_iv_x),
|
||||
UDE_ITEM(33, 120, tc.sl_cust_iv_y),
|
||||
UDE_ITEM(34, 120, tc.mask_br),
|
||||
UDE_ITEM(35, 120, tc.mask_color),
|
||||
UDE_ITEM(36, 120, tc.reverse_lpf),
|
||||
UDE_ITEM(37, 120, tc.shmask_mode),
|
||||
UDE_ITEM(38, 120, tc.shmask_str),
|
||||
UDE_ITEM(39, 120, tc.lumacode_mode),
|
||||
UDE_ITEM(40, 120, tc.lumacode_pal),
|
||||
UDE_ITEM(41, 120, tc.sync_vth),
|
||||
UDE_ITEM(42, 120, tc.linelen_tol),
|
||||
UDE_ITEM(43, 120, tc.vsync_thold),
|
||||
UDE_ITEM(44, 120, tc.pre_coast),
|
||||
UDE_ITEM(45, 120, tc.post_coast),
|
||||
UDE_ITEM(46, 120, tc.ypbpr_cs),
|
||||
UDE_ITEM(47, 120, tc.video_lpf),
|
||||
UDE_ITEM(48, 120, tc.sync_lpf),
|
||||
UDE_ITEM(49, 120, tc.stc_lpf),
|
||||
UDE_ITEM(50, 120, tc.alc_h_filter),
|
||||
UDE_ITEM(51, 120, tc.alc_v_filter),
|
||||
UDE_ITEM(52, 120, tc.col),
|
||||
UDE_ITEM(53, 120, tc.full_vs_bypass),
|
||||
UDE_ITEM(54, 120, tc.audio_dw_sampl),
|
||||
UDE_ITEM(55, 120, tc.audio_swap_lr),
|
||||
UDE_ITEM(56, 120, tc.audio_gain),
|
||||
UDE_ITEM(57, 120, tc.audio_mono),
|
||||
UDE_ITEM(58, 120, tc.tx_mode),
|
||||
UDE_ITEM(59, 120, tc.hdmi_itc),
|
||||
UDE_ITEM(60, 120, tc.hdmi_hdr),
|
||||
UDE_ITEM(61, 120, tc.hdmi_vrr),
|
||||
UDE_ITEM(62, 120, tc.full_tx_setup),
|
||||
UDE_ITEM(63, 120, tc.av3_alt_rgb),
|
||||
UDE_ITEM(64, 120, tc.link_av),
|
||||
};
|
||||
|
||||
int write_userdata(uint8_t entry) {
|
||||
ude_hdr hdr;
|
||||
FIL name_file;
|
||||
char p_filename[14];
|
||||
const ude_item_map *target_map;
|
||||
uint32_t flash_addr, bytes_written;
|
||||
int i=0;
|
||||
|
||||
if (entry > MAX_USERDATA_ENTRY) {
|
||||
printf("invalid entry\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
strncpy(((ude_hdr*)databuf)->userdata_key, "USRDATA", 8);
|
||||
((ude_hdr*)databuf)->type = (entry > MAX_PROFILE) ? UDE_INITCFG : UDE_PROFILE;
|
||||
memset(&hdr, 0x00, sizeof(ude_hdr));
|
||||
strlcpy(hdr.userdata_key, "USRDATA", 8);
|
||||
hdr.type = (entry > MAX_PROFILE) ? UDE_INITCFG : UDE_PROFILE;
|
||||
|
||||
switch (((ude_hdr*)databuf)->type) {
|
||||
case UDE_INITCFG:
|
||||
((ude_hdr*)databuf)->version_major = INITCFG_VER_MAJOR;
|
||||
((ude_hdr*)databuf)->version_minor = INITCFG_VER_MINOR;
|
||||
((ude_initcfg*)databuf)->data_len = sizeof(ude_initcfg) - offsetof(ude_initcfg, last_profile);
|
||||
memcpy(((ude_initcfg*)databuf)->last_profile, input_profiles, sizeof(input_profiles));
|
||||
((ude_initcfg*)databuf)->last_input = target_input;
|
||||
((ude_initcfg*)databuf)->def_input = def_input;
|
||||
((ude_initcfg*)databuf)->profile_link = profile_link;
|
||||
((ude_initcfg*)databuf)->lcd_bl_timeout = lcd_bl_timeout;
|
||||
((ude_initcfg*)databuf)->auto_input = auto_input;
|
||||
((ude_initcfg*)databuf)->auto_av1_ypbpr = auto_av1_ypbpr;
|
||||
((ude_initcfg*)databuf)->auto_av2_ypbpr = auto_av2_ypbpr;
|
||||
((ude_initcfg*)databuf)->auto_av3_ypbpr = auto_av3_ypbpr;
|
||||
((ude_initcfg*)databuf)->osd_enable = osd_enable;
|
||||
((ude_initcfg*)databuf)->osd_status_timeout = osd_status_timeout;
|
||||
((ude_initcfg*)databuf)->osd_highlight_color = osd_highlight_color;
|
||||
((ude_initcfg*)databuf)->phase_hotkey_enable = phase_hotkey_enable;
|
||||
memcpy(((ude_initcfg*)databuf)->keys, rc_keymap, sizeof(rc_keymap));
|
||||
for (i=0; i<sizeof(ude_initcfg); i++)
|
||||
databuf[i] = bitswap8(databuf[i]);
|
||||
/*retval = alt_epcq_controller2_write(epcq_dev, (USERDATA_OFFSET+entry*SECTORSIZE), databuf, sizeof(ude_initcfg));
|
||||
if (retval != 0)
|
||||
return retval;*/
|
||||
if (hdr.type == UDE_INITCFG) {
|
||||
target_map = ude_initcfg_items;
|
||||
hdr.num_items = sizeof(ude_initcfg_items)/sizeof(ude_item_map);
|
||||
|
||||
printf("Initconfig data written (%u bytes)\n", sizeof(ude_initcfg) - offsetof(ude_initcfg, last_profile));
|
||||
break;
|
||||
case UDE_PROFILE:
|
||||
((ude_hdr*)databuf)->version_major = PROFILE_VER_MAJOR;
|
||||
((ude_hdr*)databuf)->version_minor = PROFILE_VER_MINOR;
|
||||
vm_to_write = sizeof(video_modes_plm_default);
|
||||
((ude_profile*)databuf)->avc_data_len = sizeof(avconfig_t);
|
||||
((ude_profile*)databuf)->vm_data_len = vm_to_write;
|
||||
sniprintf(hdr.name, USERDATA_NAME_LEN+1, "INITCFG");
|
||||
} else if (hdr.type == UDE_PROFILE) {
|
||||
target_map = ude_profile_items;
|
||||
hdr.num_items = sizeof(ude_profile_items)/sizeof(ude_item_map);
|
||||
|
||||
if (target_profile_name[0] == 0)
|
||||
sniprintf(target_profile_name, PROFILE_NAME_LEN+1, "<used>");
|
||||
// Check if name override file exists
|
||||
sniprintf(p_filename, sizeof(p_filename), "prof_n_i.txt");
|
||||
if (!file_open(&name_file, p_filename)) {
|
||||
|
||||
strncpy(((ude_profile*)databuf)->name, target_profile_name, PROFILE_NAME_LEN+1);
|
||||
for (i=0; i<=entry; i++) {
|
||||
if (file_get_string(&name_file, target_profile_name, sizeof(target_profile_name)) == NULL)
|
||||
break;
|
||||
}
|
||||
|
||||
pageoffset = offsetof(ude_profile, avc);
|
||||
|
||||
// assume that sizeof(avconfig_t) << PAGESIZE
|
||||
memcpy(databuf+pageoffset, &tc, sizeof(avconfig_t));
|
||||
pageoffset += sizeof(avconfig_t);
|
||||
|
||||
// erase sector and write a full page first, assume sizeof(video_modes_plm) >> PAGESIZE
|
||||
memcpy(databuf+pageoffset, (char*)video_modes_plm, PAGESIZE-pageoffset);
|
||||
srcoffset = PAGESIZE-pageoffset;
|
||||
vm_to_write -= PAGESIZE-pageoffset;
|
||||
for (i=0; i<PAGESIZE; i++)
|
||||
databuf[i] = bitswap8(databuf[i]);
|
||||
/*retval = alt_epcq_controller2_write(epcq_dev, (USERDATA_OFFSET+entry*SECTORSIZE), databuf, PAGESIZE);
|
||||
if (retval != 0)
|
||||
return retval;*/
|
||||
|
||||
// then write the rest page by page
|
||||
pageno = 1;
|
||||
while (vm_to_write > 0) {
|
||||
memcpy(databuf, (char*)video_modes_plm+srcoffset, (vm_to_write > PAGESIZE) ? PAGESIZE : vm_to_write);
|
||||
for (i=0; i<PAGESIZE; i++)
|
||||
databuf[i] = bitswap8(databuf[i]);
|
||||
/*retval = alt_epcq_controller2_write_block(epcq_dev, (USERDATA_OFFSET+entry*SECTORSIZE), (USERDATA_OFFSET+entry*SECTORSIZE+pageno*PAGESIZE), databuf, (vm_to_write > PAGESIZE) ? PAGESIZE : vm_to_write);
|
||||
if (retval != 0)
|
||||
return retval;*/
|
||||
|
||||
srcoffset += PAGESIZE;
|
||||
vm_to_write = (vm_to_write < PAGESIZE) ? 0 : (vm_to_write - PAGESIZE);
|
||||
pageno++;
|
||||
file_close(&name_file);
|
||||
}
|
||||
|
||||
printf("Profile %u data written (%u bytes)\n", entry, sizeof(avconfig_t)+sizeof(video_modes_plm_default));
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
if (i == entry+1) {
|
||||
// strip CR / CRLF
|
||||
target_profile_name[strcspn(target_profile_name, "\r\n")] = 0;
|
||||
|
||||
strlcpy(hdr.name, target_profile_name, USERDATA_NAME_LEN+1);
|
||||
} else if (cur_profile_name[0] == 0) {
|
||||
sniprintf(hdr.name, USERDATA_NAME_LEN+1, "<used>");
|
||||
} else {
|
||||
strlcpy(hdr.name, cur_profile_name, USERDATA_NAME_LEN+1);
|
||||
}
|
||||
}
|
||||
|
||||
flash_addr = flashctrl_dev.flash_size - (16-entry)*FLASH_SECTOR_SIZE;
|
||||
|
||||
// Disable flash write protect and erase sector
|
||||
flash_write_protect(&flashctrl_dev, 0);
|
||||
flash_sector_erase(&flashctrl_dev, flash_addr);
|
||||
|
||||
// Write data into erased sector
|
||||
memcpy((uint32_t*)(INTEL_GENERIC_SERIAL_FLASH_INTERFACE_TOP_0_AVL_MEM_BASE + flash_addr), &hdr, sizeof(ude_hdr));
|
||||
bytes_written = sizeof(ude_hdr);
|
||||
for (i=0; i<hdr.num_items; i++) {
|
||||
memcpy((uint32_t*)(INTEL_GENERIC_SERIAL_FLASH_INTERFACE_TOP_0_AVL_MEM_BASE + flash_addr + bytes_written), &target_map[i].hdr, sizeof(ude_item_hdr));
|
||||
bytes_written += sizeof(ude_item_hdr);
|
||||
memcpy((uint32_t*)(INTEL_GENERIC_SERIAL_FLASH_INTERFACE_TOP_0_AVL_MEM_BASE + flash_addr + bytes_written), target_map[i].data, target_map[i].hdr.data_size);
|
||||
bytes_written += target_map[i].hdr.data_size;
|
||||
}
|
||||
|
||||
// Re-enable write protection
|
||||
flash_write_protect(&flashctrl_dev, 1);
|
||||
|
||||
printf("%lu bytes written into userdata entry %u\n", bytes_written, entry);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int read_userdata(alt_u8 entry, int dry_run)
|
||||
{
|
||||
int retval, i;
|
||||
alt_u8 databuf[PAGESIZE];
|
||||
alt_u16 vm_to_read;
|
||||
alt_u16 pageoffset, dstoffset;
|
||||
alt_u8 pageno;
|
||||
|
||||
target_profile_name[0] = 0;
|
||||
int read_userdata(uint8_t entry, int dry_run) {
|
||||
ude_hdr hdr;
|
||||
ude_item_hdr item_hdr;
|
||||
const ude_item_map *target_map;
|
||||
uint32_t flash_addr, bytes_read;
|
||||
int i, j, target_map_items;
|
||||
|
||||
if (entry > MAX_USERDATA_ENTRY) {
|
||||
printf("invalid entry\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
//retval = alt_epcq_controller2_read(epcq_dev, (USERDATA_OFFSET+entry*SECTORSIZE), databuf, PAGESIZE);
|
||||
for (i=0; i<PAGESIZE; i++)
|
||||
databuf[i] = bitswap8(databuf[i]);
|
||||
if (retval != 0)
|
||||
return retval;
|
||||
flash_addr = flashctrl_dev.flash_size - (16-entry)*FLASH_SECTOR_SIZE;
|
||||
memcpy(&hdr, (uint32_t*)(INTEL_GENERIC_SERIAL_FLASH_INTERFACE_TOP_0_AVL_MEM_BASE + flash_addr), sizeof(ude_hdr));
|
||||
bytes_read = sizeof(ude_hdr);
|
||||
|
||||
if (strncmp(((ude_hdr*)databuf)->userdata_key, "USRDATA", 8)) {
|
||||
if (strncmp(hdr.userdata_key, "USRDATA", 8)) {
|
||||
printf("No userdata found on entry %u\n", entry);
|
||||
return 1;
|
||||
}
|
||||
|
||||
switch (((ude_hdr*)databuf)->type) {
|
||||
case UDE_INITCFG:
|
||||
if ((((ude_hdr*)databuf)->version_major != INITCFG_VER_MAJOR) || (((ude_hdr*)databuf)->version_minor != INITCFG_VER_MINOR)) {
|
||||
printf("Initconfig version %u.%.2u does not match current one\n", ((ude_hdr*)databuf)->version_major, ((ude_hdr*)databuf)->version_minor);
|
||||
return 2;
|
||||
}
|
||||
if (((ude_initcfg*)databuf)->data_len == sizeof(ude_initcfg) - offsetof(ude_initcfg, last_profile)) {
|
||||
if (dry_run)
|
||||
return 0;
|
||||
strlcpy(target_profile_name, hdr.name, USERDATA_NAME_LEN+1);
|
||||
if (dry_run)
|
||||
return 0;
|
||||
|
||||
for (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];
|
||||
def_input = ((ude_initcfg*)databuf)->def_input;
|
||||
if (def_input < AV_LAST)
|
||||
target_input = def_input;
|
||||
else if (((ude_initcfg*)databuf)->last_input < AV_LAST)
|
||||
target_input = ((ude_initcfg*)databuf)->last_input;
|
||||
auto_input = ((ude_initcfg*)databuf)->auto_input;
|
||||
auto_av1_ypbpr = ((ude_initcfg*)databuf)->auto_av1_ypbpr;
|
||||
auto_av2_ypbpr = ((ude_initcfg*)databuf)->auto_av2_ypbpr;
|
||||
auto_av3_ypbpr = ((ude_initcfg*)databuf)->auto_av3_ypbpr;
|
||||
osd_enable = ((ude_initcfg*)databuf)->osd_enable;
|
||||
osd_status_timeout = ((ude_initcfg*)databuf)->osd_status_timeout;
|
||||
osd_highlight_color = ((ude_initcfg*)databuf)->osd_highlight_color;
|
||||
profile_link = ((ude_initcfg*)databuf)->profile_link;
|
||||
profile_sel = input_profiles[AV_TESTPAT]; // Global profile
|
||||
lcd_bl_timeout = ((ude_initcfg*)databuf)->lcd_bl_timeout;
|
||||
phase_hotkey_enable = ((ude_initcfg*)databuf)->phase_hotkey_enable;
|
||||
memcpy(rc_keymap, ((ude_initcfg*)databuf)->keys, sizeof(rc_keymap));
|
||||
printf("RC data read (%u bytes)\n", sizeof(rc_keymap));
|
||||
}
|
||||
break;
|
||||
case UDE_PROFILE:
|
||||
if ((((ude_hdr*)databuf)->version_major != PROFILE_VER_MAJOR) || (((ude_hdr*)databuf)->version_minor != PROFILE_VER_MINOR)) {
|
||||
printf("Profile version %u.%.2u does not match current one\n", ((ude_hdr*)databuf)->version_major, ((ude_hdr*)databuf)->version_minor);
|
||||
return 2;
|
||||
}
|
||||
if ((((ude_profile*)databuf)->avc_data_len == sizeof(avconfig_t)) && (((ude_profile*)databuf)->vm_data_len == sizeof(video_modes_plm_default))) {
|
||||
strncpy(target_profile_name, ((ude_profile*)databuf)->name, PROFILE_NAME_LEN+1);
|
||||
if (dry_run)
|
||||
return 0;
|
||||
target_map = (hdr.type == UDE_INITCFG) ? ude_initcfg_items : ude_profile_items;
|
||||
target_map_items = (hdr.type == UDE_INITCFG) ? sizeof(ude_initcfg_items)/sizeof(ude_item_map) : sizeof(ude_profile_items)/sizeof(ude_item_map);
|
||||
|
||||
vm_to_read = ((ude_profile*)databuf)->vm_data_len;
|
||||
|
||||
pageno = 0;
|
||||
pageoffset = offsetof(ude_profile, avc);
|
||||
|
||||
// assume that sizeof(avconfig_t) << PAGESIZE
|
||||
memcpy(&tc, databuf+pageoffset, sizeof(avconfig_t));
|
||||
pageoffset += sizeof(avconfig_t);
|
||||
|
||||
dstoffset = 0;
|
||||
while (vm_to_read > 0) {
|
||||
if (vm_to_read >= PAGESIZE-pageoffset) {
|
||||
memcpy((char*)video_modes_plm+dstoffset, databuf+pageoffset, PAGESIZE-pageoffset);
|
||||
dstoffset += PAGESIZE-pageoffset;
|
||||
vm_to_read -= PAGESIZE-pageoffset;
|
||||
pageoffset = 0;
|
||||
pageno++;
|
||||
// check
|
||||
//retval = alt_epcq_controller2_read(epcq_dev, (USERDATA_OFFSET+entry*SECTORSIZE+pageno*PAGESIZE), databuf, PAGESIZE);
|
||||
for (i=0; i<PAGESIZE; i++)
|
||||
databuf[i] = bitswap8(databuf[i]);
|
||||
if (retval != 0)
|
||||
return retval;
|
||||
} else {
|
||||
memcpy((char*)video_modes_plm+dstoffset, databuf+pageoffset, vm_to_read);
|
||||
pageoffset += vm_to_read;
|
||||
vm_to_read = 0;
|
||||
}
|
||||
for (i=0; i<hdr.num_items; i++) {
|
||||
memcpy(&item_hdr, (uint32_t*)(INTEL_GENERIC_SERIAL_FLASH_INTERFACE_TOP_0_AVL_MEM_BASE + flash_addr + bytes_read), sizeof(ude_item_hdr));
|
||||
bytes_read += sizeof(ude_item_hdr);
|
||||
for (j=0; j<target_map_items; j++) {
|
||||
if (!memcmp(&item_hdr, &target_map[j].hdr, sizeof(ude_item_hdr))) {
|
||||
memcpy(target_map[j].data, (uint32_t*)(INTEL_GENERIC_SERIAL_FLASH_INTERFACE_TOP_0_AVL_MEM_BASE + flash_addr + bytes_read), item_hdr.data_size);
|
||||
break;
|
||||
}
|
||||
update_cur_vm = 1;
|
||||
|
||||
printf("Profile %u data read (%u bytes)\n", entry, sizeof(avconfig_t)+sizeof(video_modes_plm_default));
|
||||
}
|
||||
break;
|
||||
default:
|
||||
printf("Unknown userdata entry\n");
|
||||
break;
|
||||
bytes_read += item_hdr.data_size;
|
||||
|
||||
if (bytes_read >= FLASH_SECTOR_SIZE) {
|
||||
printf("userdata entry %u corrupted\n", entry);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
if (hdr.type == UDE_PROFILE)
|
||||
update_cur_vm = 1;
|
||||
|
||||
strlcpy(cur_profile_name, target_profile_name, USERDATA_NAME_LEN+1);
|
||||
printf("%lu bytes read from userdata entry %u\n", bytes_read, entry);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int import_userdata()
|
||||
{
|
||||
SDRESULTS res;
|
||||
int retval;
|
||||
int n, entries_imported=0;
|
||||
char *errmsg;
|
||||
alt_u8 databuf[SD_BLK_SIZE];
|
||||
ude_hdr header;
|
||||
alt_u32 btn_vec;
|
||||
int write_userdata_sd(uint8_t entry) {
|
||||
FIL p_file, name_file;
|
||||
ude_hdr hdr;
|
||||
const ude_item_map *target_map;
|
||||
unsigned int bytes_written, bytes_written_tot;
|
||||
char p_filename[14];
|
||||
int i=0, retval=0;
|
||||
|
||||
retval = check_sdcard(databuf);
|
||||
SPI_CS_High();
|
||||
if (retval != 0)
|
||||
goto sd_disable;
|
||||
if (entry == SD_INIT_CONFIG_SLOT)
|
||||
sniprintf(p_filename, sizeof(p_filename), "settings.bin");
|
||||
else
|
||||
sniprintf(p_filename, sizeof(p_filename), "prof%.2u.bin", entry);
|
||||
|
||||
strncpy(menu_row2, "Import? 1=Y, 2=N", LCD_ROW_LEN+1);
|
||||
ui_disp_menu(2);
|
||||
|
||||
while (1) {
|
||||
btn_vec = IORD_ALTERA_AVALON_PIO_DATA(PIO_1_BASE) & RC_MASK;
|
||||
|
||||
if (btn_vec == rc_keymap[RC_BTN1]) {
|
||||
break;
|
||||
} else if (btn_vec == rc_keymap[RC_BTN2]) {
|
||||
retval = UDATA_IMPT_CANCELLED;
|
||||
strncpy(menu_row2, "Cancelled", LCD_ROW_LEN+1);
|
||||
goto sd_disable;
|
||||
}
|
||||
|
||||
usleep(WAITLOOP_SLEEP_US);
|
||||
if (entry > MAX_SD_USERDATA_ENTRY) {
|
||||
printf("invalid entry\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
strncpy(menu_row2, "Loading...", LCD_ROW_LEN+1);
|
||||
ui_disp_menu(2);
|
||||
|
||||
// Import the userdata
|
||||
for (n=0; n<=MAX_USERDATA_ENTRY; ++n) {
|
||||
res = SD_Read(&sdcard_dev, &header, (512+n*SECTORSIZE)/SD_BLK_SIZE, 0, sizeof(header));
|
||||
if (res != SD_OK) {
|
||||
printf("Failed to read SD card\n");
|
||||
retval = -res;
|
||||
goto sd_disable;
|
||||
}
|
||||
|
||||
if (strncmp(header.userdata_key, "USRDATA", 8)) {
|
||||
printf("Not an userdata entry at 0x%x\n", 512+n*SECTORSIZE);
|
||||
continue;
|
||||
}
|
||||
|
||||
if ((header.type == UDE_PROFILE) && ((header.version_major != PROFILE_VER_MAJOR) || (header.version_minor != PROFILE_VER_MINOR))) {
|
||||
printf("Profile version %u.%.2u does not match current one\n", header.version_major, header.version_minor);
|
||||
continue;
|
||||
} else if ((header.type == UDE_INITCFG) && ((header.version_major != INITCFG_VER_MAJOR) || (header.version_minor != INITCFG_VER_MINOR))) {
|
||||
printf("Initconfig version %u.%.2u does not match current one\n", header.version_major, header.version_minor);
|
||||
continue;
|
||||
} else if (header.type > UDE_PROFILE) {
|
||||
printf("Unknown userdata entry type %u\n", header.type);
|
||||
continue;
|
||||
}
|
||||
|
||||
// Just blindly write the entry to flash
|
||||
retval = copy_sd_to_flash((512+n*SECTORSIZE)/SD_BLK_SIZE, (n*PAGES_PER_SECTOR)+(USERDATA_OFFSET/PAGESIZE),
|
||||
(header.type == UDE_PROFILE) ? (sizeof(ude_profile)+sizeof(video_modes_plm_default)) : sizeof(ude_initcfg), databuf);
|
||||
if (!sdcard_dev.mount) {
|
||||
retval = file_mount();
|
||||
if (retval != 0) {
|
||||
printf("Copy from SD to flash failed (error %d)\n", retval);
|
||||
goto sd_disable;
|
||||
printf("SD card not detected %d\n", retval);
|
||||
return -2;
|
||||
}
|
||||
|
||||
entries_imported++;
|
||||
}
|
||||
|
||||
// flash read immediately after write might fail, add some delay
|
||||
usleep(1000);
|
||||
if (f_open(&p_file, p_filename, FA_WRITE|FA_CREATE_ALWAYS) != F_OK) {
|
||||
return -3;
|
||||
}
|
||||
|
||||
read_userdata(INIT_CONFIG_SLOT, 0);
|
||||
profile_sel = input_profiles[target_input];
|
||||
read_userdata(profile_sel, 0);
|
||||
memset(&hdr, 0x00, sizeof(ude_hdr));
|
||||
strlcpy(hdr.userdata_key, "USRDATA", 8);
|
||||
hdr.type = (entry > MAX_SD_PROFILE) ? UDE_INITCFG : UDE_PROFILE;
|
||||
|
||||
sniprintf(menu_row2, LCD_ROW_LEN+1, "%d slots loaded", entries_imported);
|
||||
retval = 1;
|
||||
if (hdr.type == UDE_INITCFG) {
|
||||
target_map = ude_initcfg_items;
|
||||
hdr.num_items = sizeof(ude_initcfg_items)/sizeof(ude_item_map);
|
||||
|
||||
sd_disable:
|
||||
SPI_CS_High();
|
||||
sniprintf(hdr.name, USERDATA_NAME_LEN+1, "INITCFG");
|
||||
} else if (hdr.type == UDE_PROFILE) {
|
||||
target_map = ude_profile_items;
|
||||
hdr.num_items = sizeof(ude_profile_items)/sizeof(ude_item_map);
|
||||
|
||||
// Check if name override file exists
|
||||
sniprintf(p_filename, sizeof(p_filename), "prof_n.txt");
|
||||
if (!file_open(&name_file, p_filename)) {
|
||||
|
||||
for (i=0; i<=entry; i++) {
|
||||
if (file_get_string(&name_file, target_profile_name, sizeof(target_profile_name)) == NULL)
|
||||
break;
|
||||
}
|
||||
|
||||
file_close(&name_file);
|
||||
}
|
||||
|
||||
if (i == entry+1) {
|
||||
// strip CR / CRLF
|
||||
target_profile_name[strcspn(target_profile_name, "\r\n")] = 0;
|
||||
|
||||
strlcpy(hdr.name, target_profile_name, USERDATA_NAME_LEN+1);
|
||||
} else if (cur_profile_name[0] == 0) {
|
||||
sniprintf(hdr.name, USERDATA_NAME_LEN+1, "<used>");
|
||||
} else {
|
||||
strlcpy(hdr.name, cur_profile_name, USERDATA_NAME_LEN+1);
|
||||
}
|
||||
}
|
||||
|
||||
// Write header
|
||||
if ((f_write(&p_file, &hdr, sizeof(ude_hdr), &bytes_written) != F_OK) || (bytes_written != sizeof(ude_hdr))) {
|
||||
retval = -4;
|
||||
goto close_file;
|
||||
}
|
||||
bytes_written_tot = bytes_written;
|
||||
|
||||
// Write data
|
||||
for (i=0; i<hdr.num_items; i++) {
|
||||
if ((f_write(&p_file, &target_map[i].hdr, sizeof(ude_item_hdr), &bytes_written) != F_OK) || (bytes_written != sizeof(ude_item_hdr))) {
|
||||
retval = -5;
|
||||
goto close_file;
|
||||
}
|
||||
bytes_written_tot += bytes_written;
|
||||
|
||||
if ((f_write(&p_file, target_map[i].data, target_map[i].hdr.data_size, &bytes_written) != F_OK) || (bytes_written != target_map[i].hdr.data_size)) {
|
||||
retval = -6;
|
||||
goto close_file;
|
||||
}
|
||||
bytes_written_tot += bytes_written;
|
||||
}
|
||||
|
||||
printf("%u bytes written into userdata entry %u\n", bytes_written_tot, entry);
|
||||
|
||||
close_file:
|
||||
file_close(&p_file);
|
||||
return retval;
|
||||
}
|
||||
|
||||
static alt_u8 poll_yesno(const useconds_t useconds, alt_u32 *const btn_vec_out)
|
||||
{
|
||||
alt_u32 btn_vec;
|
||||
alt_u8 ret = 0U;
|
||||
int read_userdata_sd(uint8_t entry, int dry_run) {
|
||||
FIL p_file;
|
||||
ude_hdr hdr;
|
||||
ude_item_hdr item_hdr;
|
||||
const ude_item_map *target_map;
|
||||
unsigned int bytes_read, bytes_read_tot;
|
||||
char p_filename[14];
|
||||
int i, j, target_map_items, retval=0;
|
||||
|
||||
for (alt_u32 i = 0; i < (useconds/WAITLOOP_SLEEP_US); ++i) {
|
||||
btn_vec = IORD_ALTERA_AVALON_PIO_DATA(PIO_1_BASE) & RC_MASK;
|
||||
if (entry == SD_INIT_CONFIG_SLOT)
|
||||
sniprintf(p_filename, 14, "settings.bin");
|
||||
else
|
||||
sniprintf(p_filename, 14, "prof%.2u.bin", entry);
|
||||
|
||||
for (alt_u32 j = RC_BTN1; j < (REMOTE_MAX_KEYS - 1); ++j) {
|
||||
if (btn_vec == rc_keymap[j]) {
|
||||
ret = 1U;
|
||||
if (entry > MAX_SD_USERDATA_ENTRY) {
|
||||
printf("invalid entry\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (!sdcard_dev.mount) {
|
||||
retval = file_mount();
|
||||
if (retval != 0) {
|
||||
printf("SD card not detected %d\n", retval);
|
||||
return -2;
|
||||
}
|
||||
}
|
||||
|
||||
if (file_open(&p_file, p_filename) != F_OK) {
|
||||
return -3;
|
||||
}
|
||||
|
||||
if ((f_read(&p_file, &hdr, sizeof(ude_hdr), &bytes_read) != F_OK) || (bytes_read != sizeof(ude_hdr))) {
|
||||
printf("Hdr read error\n");
|
||||
retval = -4;
|
||||
goto close_file;
|
||||
}
|
||||
bytes_read_tot = bytes_read;
|
||||
|
||||
if (strncmp(hdr.userdata_key, "USRDATA", 8)) {
|
||||
printf("No userdata found on file\n");
|
||||
retval = -5;
|
||||
goto close_file;
|
||||
}
|
||||
|
||||
strlcpy(target_profile_name, hdr.name, USERDATA_NAME_LEN+1);
|
||||
if (dry_run)
|
||||
goto close_file;
|
||||
|
||||
target_map = (hdr.type == UDE_INITCFG) ? ude_initcfg_items : ude_profile_items;
|
||||
target_map_items = (hdr.type == UDE_INITCFG) ? sizeof(ude_initcfg_items)/sizeof(ude_item_map) : sizeof(ude_profile_items)/sizeof(ude_item_map);
|
||||
|
||||
for (i=0; i<hdr.num_items; i++) {
|
||||
if ((f_read(&p_file, &item_hdr, sizeof(ude_item_hdr), &bytes_read) != F_OK) || (bytes_read != sizeof(ude_item_hdr))) {
|
||||
printf("Item header read fail\n");
|
||||
retval = -6;
|
||||
goto close_file;
|
||||
}
|
||||
bytes_read_tot += sizeof(ude_item_hdr);
|
||||
for (j=0; j<target_map_items; j++) {
|
||||
if (!memcmp(&item_hdr, &target_map[j].hdr, sizeof(ude_item_hdr))) {
|
||||
if ((f_read(&p_file, target_map[j].data, item_hdr.data_size, &bytes_read) != F_OK) || (bytes_read != item_hdr.data_size)) {
|
||||
printf("Item data read fail\n");
|
||||
retval = -7;
|
||||
goto close_file;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (ret)
|
||||
break;
|
||||
|
||||
usleep(WAITLOOP_SLEEP_US);
|
||||
bytes_read_tot += item_hdr.data_size;
|
||||
if (j == target_map_items)
|
||||
f_lseek(&p_file, bytes_read_tot);
|
||||
}
|
||||
|
||||
if (ret)
|
||||
*btn_vec_out = btn_vec;
|
||||
if (hdr.type == UDE_PROFILE)
|
||||
update_cur_vm = 1;
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int export_userdata()
|
||||
{
|
||||
int retval;
|
||||
const char *msg;
|
||||
alt_u8 databuf[SD_BLK_SIZE];
|
||||
alt_u8 prompt_state = 0;
|
||||
useconds_t prompt_delay;
|
||||
const alt_u8 prompt_transitions[] = { 1, 2, 0, 0, };
|
||||
const alt_u8 prompt_ofs[] = { 0, 16, 31, LNG(48, 47), };
|
||||
const char *prompt_msgs =
|
||||
LNG(
|
||||
"SD CARD WILL BE" "\0" // [ 0..15]
|
||||
"OVERWRITTEN!!!" "\0" // [16..30]
|
||||
"Export? 1=Y, 2=N""\0" // [31..47]
|
||||
"Press 1 or 2", // [48..60]
|
||||
"SDカードヲウワガキシマス" "\0" // [ 0..15]
|
||||
"ゴチュウイクダサイ!!!" "\0" // [16..30]
|
||||
"1=ジッコウスル 2=ヤメル" "\0" // [31..46]
|
||||
"ドチラカエランデクダサイ" // [47..60]
|
||||
);
|
||||
alt_u32 btn_vec, sd_block_offset;
|
||||
|
||||
_Static_assert(SD_BLK_SIZE == FAT16_SECTOR_SIZE, "Sector size mismatch");
|
||||
|
||||
retval = check_sdcard(databuf);
|
||||
SPI_CS_High();
|
||||
if (retval != 0) {
|
||||
retval = -retval;
|
||||
goto out;
|
||||
}
|
||||
|
||||
usleep(100000U);
|
||||
while (1) {
|
||||
msg = &prompt_msgs[prompt_ofs[prompt_state]];
|
||||
prompt_delay = (prompt_state == 2) ? 2000000U
|
||||
: ((prompt_state == 3) ? 300000U : 1000000U);
|
||||
prompt_state = prompt_transitions[prompt_state];
|
||||
|
||||
strncpy(menu_row2, msg, LCD_ROW_LEN+1);
|
||||
ui_disp_menu(2);
|
||||
if (poll_yesno(prompt_delay, &btn_vec))
|
||||
goto eval_button;
|
||||
|
||||
continue;
|
||||
eval_button:
|
||||
if (btn_vec == rc_keymap[RC_BTN1]) {
|
||||
break;
|
||||
} else if (btn_vec == rc_keymap[RC_BTN2] ||
|
||||
btn_vec == rc_keymap[RC_BACK])
|
||||
{
|
||||
retval = UDATA_EXPT_CANCELLED;
|
||||
goto out;
|
||||
}
|
||||
prompt_state = 3;
|
||||
}
|
||||
|
||||
usleep(100000U);
|
||||
strncpy(menu_row1,"SD Format", LCD_ROW_LEN+1);
|
||||
strncpy(menu_row2,"1=FAT16, 2=RAW", LCD_ROW_LEN+1);
|
||||
ui_disp_menu(2);
|
||||
if ((!poll_yesno(5000000U, &btn_vec)) || ((btn_vec != rc_keymap[RC_BTN1]) && (btn_vec != rc_keymap[RC_BTN2]))) {
|
||||
retval = UDATA_EXPT_CANCELLED;
|
||||
goto out;
|
||||
}
|
||||
sd_block_offset = (btn_vec == rc_keymap[RC_BTN1]) ? (PROF_16_DATA_OFS/SD_BLK_SIZE) : 0;
|
||||
|
||||
strncpy(menu_row2, LNG("Exporting...", "オマチクダサイ"), LCD_ROW_LEN+1);
|
||||
ui_disp_menu(2);
|
||||
|
||||
// RAW copy
|
||||
if (btn_vec == rc_keymap[RC_BTN2])
|
||||
goto copy_start;
|
||||
|
||||
/* Zero out the boot sector, FATs and root directory. */
|
||||
memset(databuf, 0, SD_BLK_SIZE);
|
||||
for (alt_u32 sector = 0;
|
||||
sector < (FAT16_ROOT_DIR_FIRST_SECTOR + FAT16_ROOT_DIR_SECTORS);
|
||||
++sector)
|
||||
{
|
||||
retval = SD_Write(&sdcard_dev, databuf, sector);
|
||||
if (retval)
|
||||
goto out;
|
||||
}
|
||||
|
||||
/* Generate and write the boot sector. */
|
||||
generate_boot_sector_16(databuf);
|
||||
retval = SD_Write(&sdcard_dev, databuf, 0);
|
||||
if (retval)
|
||||
goto out;
|
||||
|
||||
/* Generate and write the file allocation tables. */
|
||||
for (alt_u16 clusters_written = 0, sd_blk_idx = 0;
|
||||
clusters_written < (PROF_16_DATA_SIZE/FAT16_CLUSTER_SIZE);)
|
||||
{
|
||||
memset(databuf, 0, SD_BLK_SIZE);
|
||||
clusters_written = generate_fat16(databuf, clusters_written);
|
||||
retval = SD_Write(&sdcard_dev, databuf,
|
||||
(FAT16_1_OFS/SD_BLK_SIZE) + sd_blk_idx);
|
||||
if (retval)
|
||||
goto out;
|
||||
|
||||
retval = SD_Write(&sdcard_dev, databuf,
|
||||
(FAT16_2_OFS/SD_BLK_SIZE) + sd_blk_idx);
|
||||
if (retval)
|
||||
goto out;
|
||||
|
||||
++sd_blk_idx;
|
||||
}
|
||||
|
||||
/* Write the directory entry of the settings file. */
|
||||
memset(databuf, 0, SD_BLK_SIZE);
|
||||
memcpy(databuf, prof_dirent_16, PROF_DIRENT_16_SIZE);
|
||||
retval = SD_Write(&sdcard_dev, databuf, PROF_DIRENT_16_OFS/SD_BLK_SIZE);
|
||||
if (retval)
|
||||
goto out;
|
||||
|
||||
copy_start:
|
||||
// Zero out first 512 bytes (1 SD block) of the file
|
||||
memset(databuf, 0, SD_BLK_SIZE);
|
||||
retval = SD_Write(&sdcard_dev, databuf, sd_block_offset++);
|
||||
if (retval)
|
||||
goto out;
|
||||
|
||||
/* This may wear the SD card a bit more than necessary... */
|
||||
retval = copy_flash_to_sd(USERDATA_OFFSET/PAGESIZE,
|
||||
sd_block_offset,
|
||||
(MAX_USERDATA_ENTRY + 1) * SECTORSIZE,
|
||||
databuf);
|
||||
|
||||
out:
|
||||
SPI_CS_High();
|
||||
|
||||
switch (retval) {
|
||||
case 0:
|
||||
msg = LNG("Success", "カンリョウシマシタ"); // Alternative: "カンリョウイタシマシタ"
|
||||
break;
|
||||
case SD_NOINIT:
|
||||
msg = LNG("No SD card det.", "SDカードガミツカリマセン");
|
||||
break;
|
||||
case -EINVAL:
|
||||
msg = LNG("Invalid params.", "パラメータガムコウデス");
|
||||
break;
|
||||
case UDATA_EXPT_CANCELLED:
|
||||
msg = LNG("Cancelled", "キャンセルサレマシタ"); // Alternative: "キャンセルサセテイタダキマス"
|
||||
break;
|
||||
default:
|
||||
msg = LNG("SD/Flash error", "SDカFLASHノエラー"); // フラッシュ would be NG.
|
||||
break;
|
||||
}
|
||||
strncpy(menu_row2, msg, LCD_ROW_LEN+1);
|
||||
|
||||
if (!retval) {
|
||||
return 1;
|
||||
} else {
|
||||
/*
|
||||
* We want the message above to remain on screen, so return a
|
||||
* positive value which nevertheless stands out when debugging.
|
||||
*/
|
||||
return 0x0dead;
|
||||
}
|
||||
strlcpy(cur_profile_name, target_profile_name, USERDATA_NAME_LEN+1);
|
||||
printf("%u bytes read from userdata entry %u\n", bytes_read_tot, entry);
|
||||
|
||||
close_file:
|
||||
file_close(&p_file);
|
||||
return retval;
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user