split config and properties

This commit is contained in:
TT 2017-01-02 19:15:16 +09:00
parent bd2890e6af
commit 9f5259556c
4 changed files with 69 additions and 52 deletions

24
flash.c
View file

@ -89,23 +89,23 @@ int16_t lastsaveid = 0;
int int
caldata_save(int id) caldata_save(int id)
{ {
uint16_t *src = (uint16_t*)&current_config; uint16_t *src = (uint16_t*)&current_props;
uint16_t *dst; uint16_t *dst;
int count = sizeof(config_t) / sizeof(uint16_t); int count = sizeof(properties_t) / sizeof(uint16_t);
if (id < 0 || id >= SAVEAREA_MAX) if (id < 0 || id >= SAVEAREA_MAX)
return -1; return -1;
dst = (uint16_t*)saveareas[id]; dst = (uint16_t*)saveareas[id];
current_config.magic = CONFIG_MAGIC; current_props.magic = CONFIG_MAGIC;
current_config.checksum = 0; current_props.checksum = 0;
current_config.checksum = checksum(&current_config, sizeof current_config); current_props.checksum = checksum(&current_props, sizeof current_props);
flash_unlock(); flash_unlock();
/* erase flash pages */ /* erase flash pages */
void *p = dst; void *p = dst;
void *tail = p + sizeof(config_t); void *tail = p + sizeof(properties_t);
while (p < tail) { while (p < tail) {
flash_erase_page((uint32_t)p); flash_erase_page((uint32_t)p);
p += FLASH_PAGESIZE; p += FLASH_PAGESIZE;
@ -118,7 +118,7 @@ caldata_save(int id)
} }
/* after saving data, make active configuration points to flash */ /* after saving data, make active configuration points to flash */
active = (config_t*)saveareas[id]; active = (properties_t*)saveareas[id];
lastsaveid = id; lastsaveid = id;
return 0; return 0;
@ -127,18 +127,18 @@ caldata_save(int id)
int int
caldata_recall(int id) caldata_recall(int id)
{ {
config_t *src; properties_t *src;
void *dst = &current_config; void *dst = &current_props;
if (id < 0 || id >= SAVEAREA_MAX) if (id < 0 || id >= SAVEAREA_MAX)
return -1; return -1;
// point to saved area on the flash memory // point to saved area on the flash memory
src = (config_t*)saveareas[id]; src = (properties_t*)saveareas[id];
if (src->magic != CONFIG_MAGIC) if (src->magic != CONFIG_MAGIC)
return -1; return -1;
if (checksum(src, sizeof(config_t)) != 0) if (checksum(src, sizeof(properties_t)) != 0)
return -1; return -1;
/* active configuration points to save data on flash memory */ /* active configuration points to save data on flash memory */
@ -146,7 +146,7 @@ caldata_recall(int id)
lastsaveid = id; lastsaveid = id;
/* duplicated saved data onto sram to be able to modify marker/trace */ /* duplicated saved data onto sram to be able to modify marker/trace */
memcpy(dst, src, sizeof(config_t)); memcpy(dst, src, sizeof(properties_t));
return 0; return 0;
} }

28
main.c
View file

@ -309,7 +309,15 @@ uint16_t cal_status;
float cal_data[5][101][2]; float cal_data[5][101][2];
#endif #endif
config_t current_config = { config_t config = {
/* magic */ CONFIG_MAGIC,
/* dac_value */ 1922,
/* grid_color */ 0x1084,
/* trace_colors */ { RGB565(0,255,255), RGB565(255,0,40), RGB565(0,0,255), RGB565(50,255,0) },
/* checksum */ 0
};
properties_t current_props = {
/* magic */ CONFIG_MAGIC, /* magic */ CONFIG_MAGIC,
/* frequency0 */ 1000000, /* frequency0 */ 1000000,
/* frequency1 */ 300000000, /* frequency1 */ 300000000,
@ -318,10 +326,10 @@ config_t current_config = {
/* frequencies */ {}, /* frequencies */ {},
/* cal_data */ {}, /* cal_data */ {},
/* trace[4] */ { /* trace[4] */ {
{ 1, TRC_LOGMAG, 0, 1.0, RGB565(0,255,255), 0 }, { 1, TRC_LOGMAG, 0, 0, 1.0 },
{ 1, TRC_LOGMAG, 1, 1.0, RGB565(255,0,40), 0 }, { 1, TRC_LOGMAG, 1, 0, 1.0 },
{ 1, TRC_SMITH, 0, 1.0, RGB565(0,0,255), 1 }, { 1, TRC_SMITH, 0, 1, 1.0 },
{ 1, TRC_PHASE, 1, 1.0, RGB565(50,255,0), 1 } { 1, TRC_PHASE, 1, 1, 1.0 }
}, },
/* markers[4] */ { /* markers[4] */ {
{ 1, 30 }, { 0, 40 }, { 0, 60 }, { 0, 80 } { 1, 30 }, { 0, 40 }, { 0, 60 }, { 0, 80 }
@ -329,16 +337,16 @@ config_t current_config = {
/* active_marker */ 0, /* active_marker */ 0,
/* checksum */ 0 /* checksum */ 0
}; };
config_t *active = &current_config; properties_t *active = &current_props;
void void
ensure_edit_config(void) ensure_edit_config(void)
{ {
if (active == &current_config) if (active == &current_props)
return; return;
//memcpy(&current_config, active, sizeof(config_t)); //memcpy(&current_props, active, sizeof(config_t));
active = &current_config; active = &current_props;
// move to uncal state // move to uncal state
cal_status = 0; cal_status = 0;
} }
@ -622,7 +630,7 @@ adjust_ed(void)
for (i = 0; i < 101; i++) { for (i = 0; i < 101; i++) {
// z=1/(jwc*z0) = 1/(2*pi*f*c*z0) Note: normalized with Z0 // z=1/(jwc*z0) = 1/(2*pi*f*c*z0) Note: normalized with Z0
// s11ao = (z-1)/(z+1) = (1-1/z)/(1+1/z) = (1-jwcz0)/(1+jwcz0) // s11ao = (z-1)/(z+1) = (1-1/z)/(1+1/z) = (1-jwcz0)/(1+jwcz0)
// prepare 1/s11ao for effeiciency // prepare 1/s11ao to avoid dividing complex
float c = 1000e-15; float c = 1000e-15;
float z0 = 50; float z0 = 50;
//float z = 6.2832 * frequencies[i] * c * z0; //float z = 6.2832 * frequencies[i] * c * z0;

View file

@ -157,15 +157,24 @@ extern const char *trc_type_name[];
// Phase // Phase
typedef struct { typedef struct {
int enabled; uint8_t enabled;
int type; uint8_t type;
int channel; uint8_t channel;
uint8_t polar;
float scale; float scale;
//float ref; //float ref;
uint16_t color;
uint8_t polar;
} trace_t; } trace_t;
typedef struct {
int32_t magic;
uint16_t dac_value;
uint16_t grid_color;
uint16_t trace_color[TRACES_MAX];
int32_t checksum;
} config_t;
extern config_t config;
//extern trace_t trace[TRACES_MAX]; //extern trace_t trace[TRACES_MAX];
void set_trace_type(int t, int type); void set_trace_type(int t, int type);
@ -244,24 +253,24 @@ typedef struct {
int _active_marker; int _active_marker;
int32_t checksum; int32_t checksum;
} config_t; } properties_t;
#define CONFIG_MAGIC 0x436f4e45 /* 'CoNF' */ #define CONFIG_MAGIC 0x436f4e45 /* 'CoNF' */
extern int16_t lastsaveid; extern int16_t lastsaveid;
extern config_t *active; extern properties_t *active;
extern config_t current_config; extern properties_t current_props;
#define frequency0 current_config._frequency0 #define frequency0 current_props._frequency0
#define frequency1 current_config._frequency1 #define frequency1 current_props._frequency1
#define sweep_points current_config._sweep_points #define sweep_points current_props._sweep_points
#define cal_status current_config._cal_status #define cal_status current_props._cal_status
#define frequencies current_config._frequencies #define frequencies current_props._frequencies
#define cal_data active->_cal_data #define cal_data active->_cal_data
#define trace current_config._trace #define trace current_props._trace
#define markers current_config._markers #define markers current_props._markers
#define active_marker current_config._active_marker #define active_marker current_props._active_marker
int caldata_save(int id); int caldata_save(int id);
int caldata_recall(int id); int caldata_recall(int id);

28
plot.c
View file

@ -13,7 +13,7 @@ void frequency_string(char *buf, size_t len, uint32_t freq);
void markmap_all_markers(void); void markmap_all_markers(void);
//#define GRID_COLOR 0x0863 //#define GRID_COLOR 0x0863
uint16_t grid_color = 0x1084; //uint16_t grid_color = 0x1084;
/* indicate dirty cells */ /* indicate dirty cells */
uint16_t markmap[2][8]; uint16_t markmap[2][8];
@ -111,7 +111,7 @@ circle_inout(int x, int y, int r)
int int
polar_grid(int x, int y) polar_grid(int x, int y)
{ {
int c = grid_color; int c = config.grid_color;
int d; int d;
// offset to center // offset to center
@ -155,7 +155,7 @@ polar_grid(int x, int y)
int int
smith_grid(int x, int y) smith_grid(int x, int y)
{ {
int c = grid_color; int c = config.grid_color;
int d; int d;
// offset to center // offset to center
@ -213,7 +213,7 @@ smith_grid(int x, int y)
int int
smith_grid2(int x, int y, float scale) smith_grid2(int x, int y, float scale)
{ {
int c = grid_color; int c = config.grid_color;
int d; int d;
// offset to center // offset to center
@ -310,7 +310,7 @@ const int cirs[][4] = {
int int
smith_grid3(int x, int y) smith_grid3(int x, int y)
{ {
int c = grid_color; int c = config.grid_color;
int d; int d;
// offset to center // offset to center
@ -347,7 +347,7 @@ smith_grid3(int x, int y)
int int
rectangular_grid(int x, int y) rectangular_grid(int x, int y)
{ {
int c = grid_color; int c = config.grid_color;
//#define FREQ(x) (((x) * (fspan / 1000) / (WIDTH-1)) * 1000 + fstart) //#define FREQ(x) (((x) * (fspan / 1000) / (WIDTH-1)) * 1000 + fstart)
//int32_t n = FREQ(x-1) / fgrid; //int32_t n = FREQ(x-1) / fgrid;
//int32_t m = FREQ(x) / fgrid; //int32_t m = FREQ(x) / fgrid;
@ -367,7 +367,7 @@ rectangular_grid(int x, int y)
int int
rectangular_grid_x(int x) rectangular_grid_x(int x)
{ {
int c = grid_color; int c = config.grid_color;
if (x == 0 || x == (WIDTH-1)) if (x == 0 || x == (WIDTH-1))
return c; return c;
if ((((x + grid_offset) * 10) % grid_width) < 10) if ((((x + grid_offset) * 10) % grid_width) < 10)
@ -378,7 +378,7 @@ rectangular_grid_x(int x)
int int
rectangular_grid_y(int y) rectangular_grid_y(int y)
{ {
int c = grid_color; int c = config.grid_color;
if ((y % GRIDY) == 0) if ((y % GRIDY) == 0)
return c; return c;
return 0; return 0;
@ -901,7 +901,7 @@ cell_draw_markers(int m, int n, int w, int h)
int x = CELL_X(index) - x0; int x = CELL_X(index) - x0;
int y = CELL_Y(index) - y0; int y = CELL_Y(index) - y0;
if (x > -6 && x < w+6 && y >= 0 && y < h+12) if (x > -6 && x < w+6 && y >= 0 && y < h+12)
draw_marker(w, h, x, y, trace[t].color, '1' + i); draw_marker(w, h, x, y, config.trace_color[t], '1' + i);
} }
} }
} }
@ -1029,7 +1029,7 @@ draw_cell(int m, int n)
int x2 = CELL_X(trace_index[t][i+1]); int x2 = CELL_X(trace_index[t][i+1]);
int y1 = CELL_Y(trace_index[t][i]); int y1 = CELL_Y(trace_index[t][i]);
int y2 = CELL_Y(trace_index[t][i+1]); int y2 = CELL_Y(trace_index[t][i+1]);
int c = trace[t].color; int c = config.trace_color[t];
cell_drawline(w, h, x1 - x0, y1 - y0, x2 - x0, y2 - y0, c); cell_drawline(w, h, x1 - x0, y1 - y0, x2 - x0, y2 - y0, c);
} }
} }
@ -1038,7 +1038,7 @@ draw_cell(int m, int n)
#if 1 #if 1
/* draw polar plot */ /* draw polar plot */
for (t = 0; t < TRACES_MAX; t++) { for (t = 0; t < TRACES_MAX; t++) {
int c = trace[t].color; int c = config.trace_color[t];
if (!trace[t].enabled || !trace[t].polar) if (!trace[t].enabled || !trace[t].polar)
continue; continue;
for (i = 1; i < 101; i++) { for (i = 1; i < 101; i++) {
@ -1155,10 +1155,10 @@ cell_draw_marker_info(int m, int n, int w, int h)
xpos -= m * CELLWIDTH; xpos -= m * CELLWIDTH;
ypos -= n * CELLHEIGHT; ypos -= n * CELLHEIGHT;
trace_get_info(t, buf, sizeof buf); trace_get_info(t, buf, sizeof buf);
cell_drawstring_5x7(w, h, buf, xpos, ypos, trace[t].color); cell_drawstring_5x7(w, h, buf, xpos, ypos, config.trace_color[t]);
xpos += 84; xpos += 84;
trace_get_value_string(t, buf, sizeof buf, measured[trace[t].channel][idx], frequencies[idx]); trace_get_value_string(t, buf, sizeof buf, measured[trace[t].channel][idx], frequencies[idx]);
cell_drawstring_5x7(w, h, buf, xpos, ypos, trace[t].color); cell_drawstring_5x7(w, h, buf, xpos, ypos, config.trace_color[t]);
j++; j++;
} }
@ -1233,7 +1233,7 @@ draw_cal_status(void)
ili9341_fill(0, y, 10, 6*YSTEP, 0x0000); ili9341_fill(0, y, 10, 6*YSTEP, 0x0000);
if (cal_status & CALSTAT_APPLY) { if (cal_status & CALSTAT_APPLY) {
char c[3] = "C0"; char c[3] = "C0";
if (active == &current_config) if (active == &current_props)
c[1] = '*'; c[1] = '*';
else else
c[1] += lastsaveid; c[1] += lastsaveid;