diff --git a/Makefile b/Makefile index 726e18b..a3adad2 100644 --- a/Makefile +++ b/Makefile @@ -60,13 +60,13 @@ endif # Stack size to be allocated to the Cortex-M process stack. This stack is # the stack used by the main() thread. ifeq ($(USE_PROCESS_STACKSIZE),) - USE_PROCESS_STACKSIZE = 0x200 + USE_PROCESS_STACKSIZE = 0x280 endif # Stack size to the allocated to the Cortex-M main/exceptions stack. This # stack is used for processing interrupts and exceptions. ifeq ($(USE_EXCEPTIONS_STACKSIZE),) - USE_EXCEPTIONS_STACKSIZE = 0x300 + USE_EXCEPTIONS_STACKSIZE = 0x280 endif # diff --git a/main.c b/main.c index 7bf1f92..ba496a8 100644 --- a/main.c +++ b/main.c @@ -446,6 +446,7 @@ void scan_lcd(void) draw_cell_all(); } +#if 0 static void cmd_scan_lcd(BaseSequentialStream *chp, int argc, char *argv[]) { (void)chp; @@ -454,7 +455,7 @@ static void cmd_scan_lcd(BaseSequentialStream *chp, int argc, char *argv[]) pause_sweep(); scan_lcd(); } - +#endif void set_frequencies(void) @@ -841,6 +842,30 @@ const char *trc_channel_name[] = { "S11", "S21" }; +void set_trace_type(int t, int type) +{ + int polar = type == TRC_SMITH || type == TRC_ADMIT || type == TRC_POLAR; + int enabled = type != TRC_OFF; + int force = FALSE; + + if (trace[t].polar != polar) { + trace[t].polar = polar; + force = TRUE; + } + if (trace[t].enabled != enabled) { + trace[t].enabled = enabled; + force = TRUE; + } + if (trace[t].type != type) { + trace[t].type = type; + if (polar) + force = TRUE; + } + if (force) + //force_draw_cells(); + force_set_markmap(); +} + static void cmd_trace(BaseSequentialStream *chp, int argc, char *argv[]) { int t; @@ -865,35 +890,21 @@ static void cmd_trace(BaseSequentialStream *chp, int argc, char *argv[]) } if (argc > 1) { if (strcmp(argv[1], "logmag") == 0) { - trace[t].type = TRC_LOGMAG; - trace[t].polar = FALSE; - trace[t].enabled = TRUE; + set_trace_type(t, TRC_LOGMAG); } else if (strcmp(argv[1], "phase") == 0) { - trace[t].type = TRC_PHASE; - trace[t].polar = FALSE; - trace[t].enabled = TRUE; + set_trace_type(t, TRC_PHASE); } else if (strcmp(argv[1], "polar") == 0) { - trace[t].type = TRC_POLAR; - trace[t].polar = TRUE; - trace[t].enabled = TRUE; + set_trace_type(t, TRC_POLAR); } else if (strcmp(argv[1], "smith") == 0) { - trace[t].type = TRC_SMITH; - trace[t].polar = TRUE; - trace[t].enabled = TRUE; + set_trace_type(t, TRC_SMITH); } else if (strcmp(argv[1], "admit") == 0) { - trace[t].type = TRC_ADMIT; - trace[t].polar = TRUE; - trace[t].enabled = TRUE; + set_trace_type(t, TRC_ADMIT); } else if (strcmp(argv[1], "linear") == 0) { - trace[t].type = TRC_LINEAR; - trace[t].polar = FALSE; - trace[t].enabled = TRUE; + set_trace_type(t, TRC_LINEAR); } else if (strcmp(argv[1], "swr") == 0) { - trace[t].type = TRC_SWR; - trace[t].polar = FALSE; - trace[t].enabled = TRUE; + set_trace_type(t, TRC_SWR); } else if (strcmp(argv[1], "off") == 0) { - trace[t].enabled = FALSE; + set_trace_type(t, TRC_OFF); } else if (strcmp(argv[1], "scale") == 0 && argc >= 3) { trace[t].scale = atoi(argv[2]); goto exit; @@ -1081,7 +1092,7 @@ static const ShellCommand commands[] = { "scan", cmd_scan }, { "sweep", cmd_sweep }, { "test", cmd_test }, - { "plot", cmd_scan_lcd }, + //{ "plot", cmd_scan_lcd }, { "pause", cmd_pause }, { "resume", cmd_resume }, { "cal", cmd_cal }, diff --git a/nanovna.h b/nanovna.h index 378e1ab..c9dbd99 100644 --- a/nanovna.h +++ b/nanovna.h @@ -75,11 +75,13 @@ void ili9341_drawstring_5x7(char *str, int x, int y, uint16_t fg, uint16_t bg); #define WIDTH 291 #define HEIGHT 233 -#define GRIDY 29 - extern int area_width; extern int area_height; +#define GRIDY 29 + +// font + extern const uint16_t x5x7_bits []; extern const uint32_t numfont20x24[][24]; @@ -88,10 +90,12 @@ extern const uint32_t numfont20x24[][24]; #define S_OHM "\036" #define S_DEGREE "\037" +// trace + #define TRACES_MAX 4 enum { - TRC_LOGMAG, TRC_PHASE, TRC_SMITH, TRC_ADMIT, TRC_POLAR, TRC_LINEAR, TRC_SWR + TRC_LOGMAG, TRC_PHASE, TRC_SMITH, TRC_ADMIT, TRC_POLAR, TRC_LINEAR, TRC_SWR, TRC_OFF }; extern const char *trc_type_name[]; @@ -116,7 +120,11 @@ typedef struct { uint8_t polar; } trace_t; -extern trace_t trace[TRACES_MAX]; +//extern trace_t trace[TRACES_MAX]; + +void set_trace_type(int t, int type); + +// marker typedef struct { int enabled; @@ -135,6 +143,7 @@ void redraw_marker(int marker, int update_info); void trace_get_info(int t, char *buf, int len); void plot_into_index(float measured[2][101][2]); void draw_cell_all(void); +void force_set_markmap(void); void draw_cal_status(void); diff --git a/plot.c b/plot.c index c0d5c38..f820051 100644 --- a/plot.c +++ b/plot.c @@ -9,7 +9,6 @@ void cell_draw_marker_info(int m, int n, int w, int h); void draw_frequencies(void); -static inline void force_set_markmap(void); void frequency_string(char *buf, size_t len, uint32_t freq); void markmap_all_markers(void); @@ -176,10 +175,15 @@ smith_grid(int x, int y) return 0; if (d == 0) return c; + + // horizontal axis + if (y == 0) + return c; // shift circle center to right origin x -= P_RADIUS; + // Constant Reactance Circle: 2j : R/2 = 58 if (circle_inout(x, y+58, 58) == 0) return c; @@ -297,6 +301,56 @@ smith_grid2(int x, int y, float scale) return 0; } + +const int cirs[][4] = { + { 0, 58/2, 58/2, 0 }, // Constant Reactance Circle: 2j : R/2 = 58 + { 29/2, 0, 29/2, 1 }, // Constant Resistance Circle: 3 : R/4 = 29 + { 0, 116/2, 116/2, 0 }, // Constant Reactance Circle: 1j : R = 116 + { 58/2, 0, 58/2, 1 }, // Constant Resistance Circle: 1 : R/2 = 58 + { 0, 232/2, 232/2, 0 }, // Constant Reactance Circle: 1/2j : R*2 = 232 + { 87/2, 0, 87/2, 1 }, // Constant Resistance Circle: 1/3 : R*3/4 = 87 + { 0, 464/2, 464/2, 0 }, // Constant Reactance Circle: 1/4j : R*4 = 464 + { 116/2, 0, 116/2, 1 }, // Constant Resistance Circle: 0 : R + { 174/2, 0, 174/2, 1 }, // Constant Resistance Circle: -1/3 : R*3/2 = 174 + { 0, 0, 0, 0 } // sentinel +}; + +int +smith_grid3(int x, int y) +{ + int c = grid_color; + int d; + + // offset to center + x -= P_CENTER_X; + y -= P_CENTER_Y; + + // outer circle + d = circle_inout(x, y, P_RADIUS); + if (d < 0) + return 0; + if (d == 0) + return c; + + // shift circle center to right origin + x -= P_RADIUS /2; + + int i; + for (i = 0; cirs[i][2]; i++) { + d = circle_inout(x+cirs[i][0], y+cirs[i][1], cirs[i][2]); + if (d == 0) + return c; + if (d > 0 && cirs[i][3]) + return 0; + d = circle_inout(x-cirs[i][0], y-cirs[i][1], cirs[i][2]); + if (d == 0) + return c; + if (d > 0 && cirs[i][3]) + return 0; + } + return 0; +} + #if 0 int rectangular_grid(int x, int y) @@ -657,7 +711,7 @@ clear_markmap(void) memset(markmap[current_mappage], 0, sizeof markmap[current_mappage]); } -static inline void +void force_set_markmap(void) { memset(markmap[current_mappage], 0xff, sizeof markmap[current_mappage]); @@ -937,6 +991,11 @@ markmap_all_markers(void) int area_width = WIDTH; int area_height = HEIGHT; +#define GRID_RECTANGULAR (1<<0) +#define GRID_SMITH (1<<1) +#define GRID_ADMIT (1<<2) +#define GRID_POLAR (1<<3) + void draw_cell(int m, int n) { @@ -956,25 +1015,51 @@ draw_cell(int m, int n) if (w <= 0 || h <= 0) return; + uint16_t grid_mode = 0; + for (t = 0; t < TRACES_MAX; t++) { + if (!trace[t].enabled) + continue; + if (!trace[t].polar) + grid_mode |= GRID_RECTANGULAR; + else { + if (trace[t].type == TRC_SMITH) + grid_mode |= GRID_SMITH; + else if (trace[t].type == TRC_ADMIT) + grid_mode |= GRID_ADMIT; + else + grid_mode |= GRID_POLAR; + } + } + PULSE; /* draw grid */ - for (x = 0; x < w; x++) { - uint16_t c = rectangular_grid_x(x+x0); - for (y = 0; y < h; y++) - spi_buffer[y * w + x] = c; - } - for (y = 0; y < h; y++) { - uint16_t c = rectangular_grid_y(y+y0); - for (x = 0; x < w; x++) - spi_buffer[y * w + x] |= c; - } - for (y = 0; y < h; y++) { + if (grid_mode & GRID_RECTANGULAR) { for (x = 0; x < w; x++) { - //uint16_t c = rectangular_grid(x+x0, y+y0); - uint16_t c = smith_grid(x+x0, y+y0); - //uint16_t c = smith_grid2(x+x0, y+y0, 0.5); - //uint16_t c = polar_grid(x+x0, y+y0); - spi_buffer[y * w + x] |= c; + uint16_t c = rectangular_grid_x(x+x0); + for (y = 0; y < h; y++) + spi_buffer[y * w + x] = c; + } + for (y = 0; y < h; y++) { + uint16_t c = rectangular_grid_y(y+y0); + for (x = 0; x < w; x++) + spi_buffer[y * w + x] |= c; + } + } else { + memset(spi_buffer, 0, sizeof spi_buffer); + } + if (grid_mode & (GRID_SMITH|GRID_ADMIT|GRID_POLAR)) { + for (y = 0; y < h; y++) { + for (x = 0; x < w; x++) { + uint16_t c = 0; + if (grid_mode & GRID_SMITH) + c = smith_grid(x+x0, y+y0); + else if (grid_mode & GRID_ADMIT) + c = smith_grid3(x+x0, y+y0); + //c = smith_grid2(x+x0, y+y0, 0.5); + else if (grid_mode & GRID_POLAR) + c = polar_grid(x+x0, y+y0); + spi_buffer[y * w + x] |= c; + } } } PULSE; diff --git a/ui.c b/ui.c index dec8842..ca62be1 100644 --- a/ui.c +++ b/ui.c @@ -37,9 +37,9 @@ struct { #define EVT_DOWN 0x20 #define EVT_REPEAT 0x40 -#define BUTTON_DOWN_LONG_TICKS 10000 -#define BUTTON_DOUBLE_TICKS 5000 -#define BUTTON_DEBOUNCE_TICKS 10 +#define BUTTON_DOWN_LONG_TICKS 1000 +#define BUTTON_DOUBLE_TICKS 500 +#define BUTTON_DEBOUNCE_TICKS 2 /* lever switch assignment */ #define BIT_UP1 3 @@ -231,16 +231,19 @@ menu_trace_cb(int item) if (item < 0 || item >= 4) return; uistat.current_trace = item; + menu_move_back(); } static void menu_format_cb(int item) { - trace[uistat.current_trace].type = item; + set_trace_type(uistat.current_trace, item); + ui_status = FALSE; + ui_hide(); } static void -elect_active_marker(void) +choose_active_marker(void) { int i; for (i = 0; i < 4; i++) @@ -259,7 +262,7 @@ menu_marker_cb(int item) if (active_marker == item) { markers[active_marker].enabled = FALSE; - elect_active_marker(); + choose_active_marker(); } else { active_marker = item; markers[active_marker].enabled = TRUE;