mirror of
https://github.com/ttrftech/NanoVNA.git
synced 2025-12-06 03:31:59 +01:00
Huge reduce flash usage (about 5k), remove cal_data and _frequencies properties from data section
Use void loadDefaultProps() for load default properties (default loaded also on error load from flash) Move some constants to nanovna.h
This commit is contained in:
parent
cc3370c962
commit
ccb3693516
19
flash.c
19
flash.c
|
|
@ -122,12 +122,15 @@ config_recall(void)
|
||||||
|
|
||||||
#define SAVEAREA_MAX 5
|
#define SAVEAREA_MAX 5
|
||||||
|
|
||||||
const uint32_t saveareas[] =
|
const uint32_t saveareas[SAVEAREA_MAX] = {
|
||||||
{ 0x08018800, 0x0801a000, 0x0801b800, 0x0801d000, 0x0801e800 };
|
SAVE_CONFIG_0_ADDR,
|
||||||
|
SAVE_CONFIG_1_ADDR,
|
||||||
|
SAVE_CONFIG_2_ADDR,
|
||||||
|
SAVE_CONFIG_3_ADDR,
|
||||||
|
SAVE_CONFIG_4_ADDR };
|
||||||
|
|
||||||
int16_t lastsaveid = 0;
|
int16_t lastsaveid = 0;
|
||||||
|
|
||||||
|
|
||||||
int
|
int
|
||||||
caldata_save(int id)
|
caldata_save(int id)
|
||||||
{
|
{
|
||||||
|
|
@ -172,15 +175,15 @@ caldata_recall(int id)
|
||||||
void *dst = ¤t_props;
|
void *dst = ¤t_props;
|
||||||
|
|
||||||
if (id < 0 || id >= SAVEAREA_MAX)
|
if (id < 0 || id >= SAVEAREA_MAX)
|
||||||
return -1;
|
goto load_default;
|
||||||
|
|
||||||
// point to saved area on the flash memory
|
// point to saved area on the flash memory
|
||||||
src = (properties_t*)saveareas[id];
|
src = (properties_t*)saveareas[id];
|
||||||
|
|
||||||
if (src->magic != CONFIG_MAGIC)
|
if (src->magic != CONFIG_MAGIC)
|
||||||
return -1;
|
goto load_default;
|
||||||
if (checksum(src, sizeof *src - sizeof src->checksum) != src->checksum)
|
if (checksum(src, sizeof *src - sizeof src->checksum) != src->checksum)
|
||||||
return -1;
|
goto load_default;
|
||||||
|
|
||||||
/* active configuration points to save data on flash memory */
|
/* active configuration points to save data on flash memory */
|
||||||
active_props = src;
|
active_props = src;
|
||||||
|
|
@ -188,8 +191,10 @@ caldata_recall(int 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(properties_t));
|
memcpy(dst, src, sizeof(properties_t));
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
load_default:
|
||||||
|
loadDefaultProps();
|
||||||
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
const properties_t *
|
const properties_t *
|
||||||
|
|
|
||||||
83
main.c
83
main.c
|
|
@ -725,28 +725,43 @@ config_t config = {
|
||||||
.trace_color = { DEFAULT_TRACE_1_COLOR, DEFAULT_TRACE_2_COLOR, DEFAULT_TRACE_3_COLOR, DEFAULT_TRACE_4_COLOR },
|
.trace_color = { DEFAULT_TRACE_1_COLOR, DEFAULT_TRACE_2_COLOR, DEFAULT_TRACE_3_COLOR, DEFAULT_TRACE_4_COLOR },
|
||||||
// .touch_cal = { 693, 605, 124, 171 }, // 2.4 inch LCD panel
|
// .touch_cal = { 693, 605, 124, 171 }, // 2.4 inch LCD panel
|
||||||
.touch_cal = { 338, 522, 153, 192 }, // 2.8 inch LCD panel
|
.touch_cal = { 338, 522, 153, 192 }, // 2.8 inch LCD panel
|
||||||
.default_loadcal = 0,
|
|
||||||
.harmonic_freq_threshold = 300000000
|
.harmonic_freq_threshold = 300000000
|
||||||
};
|
};
|
||||||
|
|
||||||
properties_t current_props = {
|
properties_t current_props;
|
||||||
.magic = CONFIG_MAGIC,
|
properties_t *active_props = ¤t_props;
|
||||||
._frequency0 = 50000, // start = 50kHz
|
|
||||||
._frequency1 = 900000000, // end = 900MHz
|
// NanoVNA Default settings
|
||||||
._sweep_points = POINTS_COUNT,
|
static const trace_t def_trace[TRACES_MAX] = {//enable, type, channel, reserved, scale, refpos
|
||||||
._trace = {/*enable, type, channel, reserved, scale, refpos*/
|
|
||||||
{ 1, TRC_LOGMAG, 0, 0, 10.0, NGRIDY-1 },
|
{ 1, TRC_LOGMAG, 0, 0, 10.0, NGRIDY-1 },
|
||||||
{ 1, TRC_LOGMAG, 1, 0, 10.0, NGRIDY-1 },
|
{ 1, TRC_LOGMAG, 1, 0, 10.0, NGRIDY-1 },
|
||||||
{ 1, TRC_SMITH, 0, 0, 1.0, 0 },
|
{ 1, TRC_SMITH, 0, 0, 1.0, 0 },
|
||||||
{ 1, TRC_PHASE, 1, 0, 90.0, NGRIDY/2 }
|
{ 1, TRC_PHASE, 1, 0, 90.0, NGRIDY/2 }
|
||||||
},
|
|
||||||
._markers = {
|
|
||||||
{ 1, 30, 0 }, { 0, 40, 0 }, { 0, 60, 0 }, { 0, 80, 0 }
|
|
||||||
},
|
|
||||||
._velocity_factor = 0.7,
|
|
||||||
._marker_smith_format = MS_RLC
|
|
||||||
};
|
};
|
||||||
properties_t *active_props = ¤t_props;
|
|
||||||
|
static const marker_t def_markers[MARKERS_MAX] = {
|
||||||
|
{ 1, 30, 0 }, { 0, 40, 0 }, { 0, 60, 0 }, { 0, 80, 0 }
|
||||||
|
};
|
||||||
|
|
||||||
|
// Load propeties default settings
|
||||||
|
void loadDefaultProps(void){
|
||||||
|
current_props.magic = CONFIG_MAGIC;
|
||||||
|
current_props._frequency0 = 50000; // start = 50kHz
|
||||||
|
current_props._frequency1 = 900000000; // end = 900MHz
|
||||||
|
current_props._sweep_points = POINTS_COUNT;
|
||||||
|
current_props._cal_status = 0;
|
||||||
|
//This data not loaded by default
|
||||||
|
//current_props._frequencies[POINTS_COUNT];
|
||||||
|
//current_props._cal_data[5][POINTS_COUNT][2];
|
||||||
|
//=============================================
|
||||||
|
current_props._electrical_delay = 0.0;
|
||||||
|
memcpy(current_props._trace, def_trace, sizeof(def_trace));
|
||||||
|
memcpy(current_props._markers, def_markers, sizeof(def_markers));
|
||||||
|
current_props._velocity_factor = 0.7;
|
||||||
|
current_props._active_marker = 0;
|
||||||
|
current_props._domain_mode = 0;
|
||||||
|
current_props._marker_smith_format = MS_RLC;
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
ensure_edit_config(void)
|
ensure_edit_config(void)
|
||||||
|
|
@ -768,20 +783,19 @@ bool sweep(bool break_on_operation)
|
||||||
int i;
|
int i;
|
||||||
// blink LED while scanning
|
// blink LED while scanning
|
||||||
palClearPad(GPIOC, GPIOC_LED);
|
palClearPad(GPIOC, GPIOC_LED);
|
||||||
for (i = 0; i < sweep_points; i++) {
|
for (i = 0; i < sweep_points; i++) { // 8365
|
||||||
int delay = set_frequency(frequencies[i]);
|
int delay = set_frequency(frequencies[i]); // 1560
|
||||||
tlv320aic3204_select(0); // CH0:REFLECT
|
tlv320aic3204_select(0); // 60 CH0:REFLECT
|
||||||
wait_dsp(delay);
|
|
||||||
|
|
||||||
/* calculate reflection coefficient */
|
wait_dsp(delay); // 3270
|
||||||
(*sample_func)(measured[0][i]);
|
// calculate reflection coefficient
|
||||||
|
(*sample_func)(measured[0][i]); // 60
|
||||||
tlv320aic3204_select(1); // CH1:TRANSMISSION
|
|
||||||
wait_dsp(DELAY_CHANNEL_CHANGE);
|
|
||||||
|
|
||||||
/* calculate transmission coefficient */
|
|
||||||
(*sample_func)(measured[1][i]);
|
|
||||||
|
|
||||||
|
tlv320aic3204_select(1); // 60 CH1:TRANSMISSION
|
||||||
|
wait_dsp(DELAY_CHANNEL_CHANGE); // 2700
|
||||||
|
// calculate transmission coefficient
|
||||||
|
(*sample_func)(measured[1][i]); // 60
|
||||||
|
// ======== 170 ===========
|
||||||
if (cal_status & CALSTAT_APPLY)
|
if (cal_status & CALSTAT_APPLY)
|
||||||
apply_error_term_at(i);
|
apply_error_term_at(i);
|
||||||
|
|
||||||
|
|
@ -928,9 +942,6 @@ freq_mode_centerspan(void)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#define START_MIN 50000
|
|
||||||
#define STOP_MAX 2700000000U
|
|
||||||
|
|
||||||
void
|
void
|
||||||
set_sweep_frequency(int type, uint32_t freq)
|
set_sweep_frequency(int type, uint32_t freq)
|
||||||
{
|
{
|
||||||
|
|
@ -1472,14 +1483,12 @@ VNA_SHELL_FUNCTION(cmd_recall)
|
||||||
int id = my_atoi(argv[0]);
|
int id = my_atoi(argv[0]);
|
||||||
if (id < 0 || id >= SAVEAREA_MAX)
|
if (id < 0 || id >= SAVEAREA_MAX)
|
||||||
goto usage;
|
goto usage;
|
||||||
|
// Check for success
|
||||||
if (caldata_recall(id) == 0) {
|
if (caldata_recall(id) == -1)
|
||||||
// success
|
shell_printf("Err, default load\r\n");
|
||||||
update_frequencies();
|
update_frequencies();
|
||||||
redraw_request |= REDRAW_CAL_STATUS;
|
redraw_request |= REDRAW_CAL_STATUS;
|
||||||
}
|
|
||||||
return;
|
return;
|
||||||
|
|
||||||
usage:
|
usage:
|
||||||
shell_printf("recall {id}\r\n");
|
shell_printf("recall {id}\r\n");
|
||||||
}
|
}
|
||||||
|
|
@ -2203,6 +2212,8 @@ int main(void)
|
||||||
|
|
||||||
/* restore config */
|
/* restore config */
|
||||||
config_recall();
|
config_recall();
|
||||||
|
/* restore frequencies and calibration 0 slot properties from flash memory */
|
||||||
|
caldata_recall(0);
|
||||||
|
|
||||||
dac1cfg1.init = config.dac_value;
|
dac1cfg1.init = config.dac_value;
|
||||||
/*
|
/*
|
||||||
|
|
@ -2214,10 +2225,6 @@ int main(void)
|
||||||
/* initial frequencies */
|
/* initial frequencies */
|
||||||
update_frequencies();
|
update_frequencies();
|
||||||
|
|
||||||
/* restore frequencies and calibration properties from flash memory */
|
|
||||||
if (config.default_loadcal >= 0)
|
|
||||||
caldata_recall(config.default_loadcal);
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* I2S Initialize
|
* I2S Initialize
|
||||||
*/
|
*/
|
||||||
|
|
|
||||||
16
nanovna.h
16
nanovna.h
|
|
@ -25,6 +25,8 @@
|
||||||
/*
|
/*
|
||||||
* main.c
|
* main.c
|
||||||
*/
|
*/
|
||||||
|
#define START_MIN 50000
|
||||||
|
#define STOP_MAX 2700000000U
|
||||||
|
|
||||||
#define POINTS_COUNT 101
|
#define POINTS_COUNT 101
|
||||||
extern float measured[2][POINTS_COUNT][2];
|
extern float measured[2][POINTS_COUNT][2];
|
||||||
|
|
@ -82,9 +84,21 @@ uint32_t get_sweep_frequency(int type);
|
||||||
double my_atof(const char *p);
|
double my_atof(const char *p);
|
||||||
|
|
||||||
void toggle_sweep(void);
|
void toggle_sweep(void);
|
||||||
|
void loadDefaultProps(void);
|
||||||
|
|
||||||
extern int8_t sweep_enabled;
|
extern int8_t sweep_enabled;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* flash.c
|
||||||
|
*/
|
||||||
|
#define SAVEAREA_MAX 5
|
||||||
|
|
||||||
|
#define SAVE_CONFIG_0_ADDR 0x08018800
|
||||||
|
#define SAVE_CONFIG_1_ADDR 0x0801a000
|
||||||
|
#define SAVE_CONFIG_2_ADDR 0x0801b800
|
||||||
|
#define SAVE_CONFIG_3_ADDR 0x0801d000
|
||||||
|
#define SAVE_CONFIG_4_ADDR 0x0801e800
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* ui.c
|
* ui.c
|
||||||
*/
|
*/
|
||||||
|
|
@ -223,7 +237,7 @@ typedef struct {
|
||||||
uint16_t menu_active_color;
|
uint16_t menu_active_color;
|
||||||
uint16_t trace_color[TRACES_MAX];
|
uint16_t trace_color[TRACES_MAX];
|
||||||
int16_t touch_cal[4];
|
int16_t touch_cal[4];
|
||||||
int8_t default_loadcal;
|
int8_t reserved_1;
|
||||||
uint32_t harmonic_freq_threshold;
|
uint32_t harmonic_freq_threshold;
|
||||||
|
|
||||||
uint8_t _reserved[24];
|
uint8_t _reserved[24];
|
||||||
|
|
|
||||||
3
ui.c
3
ui.c
|
|
@ -490,12 +490,11 @@ static void
|
||||||
menu_recall_cb(int item, uint8_t data)
|
menu_recall_cb(int item, uint8_t data)
|
||||||
{
|
{
|
||||||
(void)item;
|
(void)item;
|
||||||
if (caldata_recall(data) == 0) {
|
caldata_recall(data);
|
||||||
menu_move_back();
|
menu_move_back();
|
||||||
ui_mode_normal();
|
ui_mode_normal();
|
||||||
update_grid();
|
update_grid();
|
||||||
draw_cal_status();
|
draw_cal_status();
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue