Skip to content

Commit

Permalink
add clearconfig command
Browse files Browse the repository at this point in the history
  • Loading branch information
edy555 committed Jan 19, 2017
1 parent 551ece8 commit 373e56f
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 4 deletions.
18 changes: 18 additions & 0 deletions flash.c
Original file line number Diff line number Diff line change
Expand Up @@ -194,3 +194,21 @@ caldata_recall(int id)

return 0;
}


const uint32_t save_config_prop_area_size = 0x8000;

void
clear_all_config_prop_data(void)
{
flash_unlock();

/* erase flash pages */
void *p = (void*)save_config_area;
void *tail = p + save_config_prop_area_size;
while (p < tail) {
flash_erase_page((uint32_t)p);
p += FLASH_PAGESIZE;
}
}

30 changes: 26 additions & 4 deletions main.c
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,22 @@ static void cmd_saveconfig(BaseSequentialStream *chp, int argc, char *argv[])
chprintf(chp, "Config saved.\r\n");
}

static void cmd_clearconfig(BaseSequentialStream *chp, int argc, char *argv[])
{
if (argc != 1) {
chprintf(chp, "usage: clearconfig {protection key}\r\n");
return;
}

if (strcmp(argv[0], "1234") != 0) {
chprintf(chp, "Key unmatched.\r\n");
return;
}

clear_all_config_prop_data();
chprintf(chp, "Config and all cal data cleared.\r\n");
}

static struct {
int16_t rms[2];
int16_t ave[2];
Expand Down Expand Up @@ -313,6 +329,7 @@ static void cmd_dump(BaseSequentialStream *chp, int argc, char *argv[])
}
}

#if 0
static void cmd_gamma(BaseSequentialStream *chp, int argc, char *argv[])
{
float gamma[2];
Expand All @@ -327,6 +344,7 @@ static void cmd_gamma(BaseSequentialStream *chp, int argc, char *argv[])

chprintf(chp, "%d %d\r\n", gamma[0], gamma[1]);
}
#endif

#if 0
int32_t frequency0 = 1000000;
Expand All @@ -347,6 +365,7 @@ config_t config = {
/* trace_colors[4] */ { RGB565(0,255,255), RGB565(255,0,40), RGB565(0,0,255), RGB565(50,255,0) },
///* touch_cal[4] */ { 620, 600, 160, 190 },
/* touch_cal[4] */ { 620, 600, 130, 180 },
/* default_loadcal */ 0,
/* checksum */ 0
};

Expand Down Expand Up @@ -385,7 +404,7 @@ ensure_edit_config(void)
cal_status = 0;
}


#if 0
static void cmd_scan(BaseSequentialStream *chp, int argc, char *argv[])
{
float gamma[2];
Expand All @@ -412,6 +431,7 @@ static void cmd_scan(BaseSequentialStream *chp, int argc, char *argv[])
}
chMtxUnlock(&mutex);
}
#endif

// main loop for measurement
void sweep(void)
Expand Down Expand Up @@ -1336,15 +1356,16 @@ static const ShellCommand commands[] =
{ "time", cmd_time },
{ "dac", cmd_dac },
{ "saveconfig", cmd_saveconfig },
{ "clearconfig", cmd_clearconfig },
{ "data", cmd_data },
{ "dump", cmd_dump },
{ "frequencies", cmd_frequencies },
{ "port", cmd_port },
{ "stat", cmd_stat },
{ "gain", cmd_gain },
{ "power", cmd_power },
{ "gamma", cmd_gamma },
{ "scan", cmd_scan },
//{ "gamma", cmd_gamma },
//{ "scan", cmd_scan },
{ "sweep", cmd_sweep },
{ "test", cmd_test },
{ "touchcal", cmd_touchcal },
Expand Down Expand Up @@ -1427,7 +1448,8 @@ int main(void)
dacStart(&DACD2, &dac1cfg1);

/* restore frequencies and calibration properties from flash memory */
caldata_recall(0);
if (config.default_loadcal >= 0)
caldata_recall(config.default_loadcal);

/* initial frequencies */
update_frequencies();
Expand Down
3 changes: 3 additions & 0 deletions nanovna.h
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ typedef struct {
uint16_t menu_active_color;
uint16_t trace_color[TRACES_MAX];
int16_t touch_cal[4];
int8_t default_loadcal;
int32_t checksum;
} config_t;

Expand Down Expand Up @@ -290,6 +291,8 @@ int caldata_recall(int id);
int config_save(void);
int config_recall(void);

void clear_all_config_prop_data(void);

/*
* ui.c
*/
Expand Down

0 comments on commit 373e56f

Please sign in to comment.