mirror of
https://github.com/marqs85/ossc.git
synced 2025-02-05 12:33:24 +00:00
Implement loading settings from SD card
This commit is contained in:
parent
a5b329584e
commit
4984ecf418
@ -179,6 +179,7 @@ MENU(menu_settings, P99_PROTECT({ \
|
|||||||
{ LNG("<Reset settings>","<セッテイオショキカ >"), OPT_FUNC_CALL, { .fun = { set_default_avconfig, NULL } } },
|
{ LNG("<Reset settings>","<セッテイオショキカ >"), OPT_FUNC_CALL, { .fun = { set_default_avconfig, NULL } } },
|
||||||
{ 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 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("Link input->prof","Link input->prof"), OPT_AVCONFIG_SELECTION, { .sel = { &profile_link, OPT_WRAP, SETTING_ITEM(off_on_desc) } } },
|
||||||
|
{ "<Import sett. >", OPT_FUNC_CALL, { .fun = { import_userdata, NULL } } },
|
||||||
{ LNG("Initial input","ショキニュウリョク"), OPT_AVCONFIG_SELECTION, { .sel = { &def_input, OPT_WRAP, SETTING_ITEM(avinput_str) } } },
|
{ LNG("Initial input","ショキニュウリョク"), OPT_AVCONFIG_SELECTION, { .sel = { &def_input, OPT_WRAP, SETTING_ITEM(avinput_str) } } },
|
||||||
{ "LCD BL timeout", OPT_AVCONFIG_SELECTION, { .sel = { &lcd_bl_timeout, OPT_WRAP, SETTING_ITEM(lcd_bl_timeout_desc) } } },
|
{ "LCD BL timeout", OPT_AVCONFIG_SELECTION, { .sel = { &lcd_bl_timeout, OPT_WRAP, SETTING_ITEM(lcd_bl_timeout_desc) } } },
|
||||||
{ LNG("<Fw. update >","<ファームウェアアップデート>"), OPT_FUNC_CALL, { .fun = { fw_update, NULL } } },
|
{ LNG("<Fw. update >","<ファームウェアアップデート>"), OPT_FUNC_CALL, { .fun = { fw_update, NULL } } },
|
||||||
|
@ -18,11 +18,15 @@
|
|||||||
//
|
//
|
||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
#include <unistd.h>
|
||||||
#include "userdata.h"
|
#include "userdata.h"
|
||||||
#include "flash.h"
|
#include "flash.h"
|
||||||
|
#include "sdcard.h"
|
||||||
#include "firmware.h"
|
#include "firmware.h"
|
||||||
|
#include "lcd.h"
|
||||||
#include "controls.h"
|
#include "controls.h"
|
||||||
#include "av_controller.h"
|
#include "av_controller.h"
|
||||||
|
#include "altera_avalon_pio_regs.h"
|
||||||
|
|
||||||
extern alt_u16 rc_keymap[REMOTE_MAX_KEYS];
|
extern alt_u16 rc_keymap[REMOTE_MAX_KEYS];
|
||||||
extern avmode_t cm;
|
extern avmode_t cm;
|
||||||
@ -34,6 +38,8 @@ extern alt_u8 input_profiles[AV_LAST];
|
|||||||
extern alt_u8 profile_sel;
|
extern alt_u8 profile_sel;
|
||||||
extern alt_u8 def_input, profile_link;
|
extern alt_u8 def_input, profile_link;
|
||||||
extern alt_u8 lcd_bl_timeout;
|
extern alt_u8 lcd_bl_timeout;
|
||||||
|
extern SD_DEV sdcard_dev;
|
||||||
|
extern char menu_row1[LCD_ROW_LEN+1], menu_row2[LCD_ROW_LEN+1];
|
||||||
|
|
||||||
int write_userdata(alt_u8 entry)
|
int write_userdata(alt_u8 entry)
|
||||||
{
|
{
|
||||||
@ -185,3 +191,84 @@ int read_userdata(alt_u8 entry)
|
|||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int import_userdata()
|
||||||
|
{
|
||||||
|
int retval;
|
||||||
|
char *errmsg;
|
||||||
|
alt_u8 databuf[SD_BLK_SIZE];
|
||||||
|
ude_hdr header;
|
||||||
|
alt_u32 btn_vec;
|
||||||
|
|
||||||
|
retval = check_sdcard(databuf);
|
||||||
|
SPI_CS_High();
|
||||||
|
if (retval != 0)
|
||||||
|
goto failure;
|
||||||
|
|
||||||
|
strncpy(menu_row1, "Import? 1=Y, 2=N", LCD_ROW_LEN+1);
|
||||||
|
*menu_row2 = '\0';
|
||||||
|
lcd_write_menu();
|
||||||
|
|
||||||
|
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;
|
||||||
|
goto failure;
|
||||||
|
}
|
||||||
|
|
||||||
|
usleep(WAITLOOP_SLEEP_US);
|
||||||
|
}
|
||||||
|
|
||||||
|
strncpy(menu_row1, "Loading settings", LCD_ROW_LEN+1);
|
||||||
|
strncpy(menu_row2, "please wait...", LCD_ROW_LEN+1);
|
||||||
|
lcd_write_menu();
|
||||||
|
|
||||||
|
// Import the userdata
|
||||||
|
for (int n=0; n<=MAX_USERDATA_ENTRY; ++n) {
|
||||||
|
retval = SD_Read(&sdcard_dev, &header, (512+n*SECTORSIZE)/SD_BLK_SIZE, 0, sizeof(header));
|
||||||
|
if (retval != 0) {
|
||||||
|
printf("Failed to read SD card\n");
|
||||||
|
retval = -retval;
|
||||||
|
goto failure;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (strncmp(header.userdata_key, "USRDATA", 8)) {
|
||||||
|
printf("Not an userdata entry at %u\n", profile);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((header.version_major != FW_VER_MAJOR) || (header.version_minor != FW_VER_MINOR)) {
|
||||||
|
printf("Data version %u.%u does not match fw\n", header->version_major, header->version_minor);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (header.type > UDE_PROFILE) {
|
||||||
|
printf("Unknown userdata entry\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(ude_initcfg), databuf);
|
||||||
|
if (retval != 0) {
|
||||||
|
printf("Copy from SD to flash failed (error %d)\n", retval);
|
||||||
|
goto failure;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
SPI_CS_High();
|
||||||
|
|
||||||
|
read_userdata(INIT_CONFIG_SLOT);
|
||||||
|
profile_sel = input_profiles[target_input];
|
||||||
|
read_userdata(profile_sel);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
failure:
|
||||||
|
SPI_CS_High();
|
||||||
|
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
@ -31,6 +31,8 @@
|
|||||||
#define MAX_PROFILE 9
|
#define MAX_PROFILE 9
|
||||||
#define INIT_CONFIG_SLOT MAX_USERDATA_ENTRY
|
#define INIT_CONFIG_SLOT MAX_USERDATA_ENTRY
|
||||||
|
|
||||||
|
#define UDATA_IMPT_CANCELLED 104
|
||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
UDE_INITCFG = 0,
|
UDE_INITCFG = 0,
|
||||||
UDE_PROFILE,
|
UDE_PROFILE,
|
||||||
@ -64,5 +66,6 @@ typedef struct {
|
|||||||
|
|
||||||
int write_userdata(alt_u8 entry);
|
int write_userdata(alt_u8 entry);
|
||||||
int read_userdata(alt_u8 entry);
|
int read_userdata(alt_u8 entry);
|
||||||
|
int import_userdata();
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
x
Reference in New Issue
Block a user