From 8ad734ff3906f0834748c8408d190f6c36f11106 Mon Sep 17 00:00:00 2001 From: Werner Almesberger Date: Sun, 24 Jul 2016 01:03:23 -0300 Subject: [PATCH] sch2fig/: better error reporting; add features of Neo900 sheet 2 --- sch2fig/Makefile | 2 +- sch2fig/fig.c | 37 +++++++++++++++++++++++++++++++++---- sch2fig/fig.h | 2 ++ sch2fig/lib.c | 2 +- sch2fig/sch.c | 18 ++++++++++++++---- sch2fig/style.h | 4 ++++ sch2fig/util.h | 4 ++++ 7 files changed, 59 insertions(+), 10 deletions(-) diff --git a/sch2fig/Makefile b/sch2fig/Makefile index 7cf80d9..a4a041c 100644 --- a/sch2fig/Makefile +++ b/sch2fig/Makefile @@ -34,5 +34,5 @@ sch: test: $(NAME) ./$(NAME) $(NEO900_HW)/neo900.lib \ $(KICAD_LIBS)/powered.lib \ - $(NEO900_HW)/neo900_SS_1.sch \ + $(NEO900_HW)/neo900_SS_2.sch \ >out.fig diff --git a/sch2fig/fig.c b/sch2fig/fig.c index edc092c..bb979ca 100644 --- a/sch2fig/fig.c +++ b/sch2fig/fig.c @@ -14,7 +14,9 @@ #include #include #include +#include +#include "util.h" #include "style.h" #include "text.h" #include "fig.h" @@ -96,8 +98,8 @@ void fig_glabel(int x, int y, const char *s, int dir, int dim, .vert = text_mid, }; int n = 6; - int vx[5]; - int vy[5]; + int vx[7]; + int vy[7]; int half = (dim >> 1) + GLABEL_OFFSET; switch (dir) { @@ -106,7 +108,7 @@ void fig_glabel(int x, int y, const char *s, int dir, int dim, txt.hor = text_max; break; default: - abort(); + assert(0); } switch (shape) { @@ -136,8 +138,24 @@ void fig_glabel(int x, int y, const char *s, int dir, int dim, text_rel(&txt, text_min, text_mid, -GLABEL_OFFSET- half, 0, vx + 5, vy + 5); break; + case fig_bidir: + text_shift(&txt, txt.hor, text_mid, -GLABEL_OFFSET - half, 0); + n = 7; + text_rel(&txt, text_min, text_min, + -GLABEL_OFFSET, GLABEL_OFFSET, vx + 1, vy + 1); + text_rel(&txt, text_max, text_min, + GLABEL_OFFSET, GLABEL_OFFSET, vx + 2, vy + 2); + text_rel(&txt, text_max, text_mid, GLABEL_OFFSET + half, 0, + vx + 3, vy + 3); + text_rel(&txt, text_max, text_max, + GLABEL_OFFSET, -GLABEL_OFFSET, vx + 4, vy + 4); + text_rel(&txt, text_min, text_max, + -GLABEL_OFFSET, -GLABEL_OFFSET, vx + 5, vy + 5); + text_rel(&txt, text_min, text_mid, -GLABEL_OFFSET- half, 0, + vx + 6, vy + 6); + break; default: - abort(); + assert(0); } text_fig(&txt, COLOR_GLABEL, LAYER_GLABEL); @@ -159,6 +177,17 @@ void fig_junction(int x, int y) } +void fig_noconn(int x, int y) +{ + int vx[2] = { x - NOCONN_LEN, x + NOCONN_LEN }; + int vy[2] = { y - NOCONN_LEN, y + NOCONN_LEN }; + + fig_poly(2, vx, vy, COLOR_NOCONN, LAYER_NOCONN); + swap(vy[0], vy[1]); + fig_poly(2, vx, vy, COLOR_NOCONN, LAYER_NOCONN); +} + + void fig_wire(int sx, int sy, int ex, int ey) { // TypeStyle FillCol AreaFil Cap FwdAr diff --git a/sch2fig/fig.h b/sch2fig/fig.h index 73e2266..006f14e 100644 --- a/sch2fig/fig.h +++ b/sch2fig/fig.h @@ -22,6 +22,7 @@ enum fig_shape { fig_in, // Input fig_out, // Output fig_tri, // 3State + fig_bidir, // Bidirectional }; @@ -35,6 +36,7 @@ void fig_glabel(int x, int y, const char *s, int dir, int dim, enum fig_shape shape); void fig_junction(int x, int y); +void fig_noconn(int x, int y); void fig_wire(int sx, int sy, int ex, int ey); void fig_line(int sx, int sy, int ex, int ey); diff --git a/sch2fig/lib.c b/sch2fig/lib.c index cb098b3..b5e480a 100644 --- a/sch2fig/lib.c +++ b/sch2fig/lib.c @@ -262,7 +262,7 @@ static enum text_style decode_style(const char *s) { if (!strcmp(s, "Normal")) return text_normal; - abort(); + assert(0); } diff --git a/sch2fig/sch.c b/sch2fig/sch.c index 4d09264..b491a7e 100644 --- a/sch2fig/sch.c +++ b/sch2fig/sch.c @@ -16,6 +16,7 @@ #include #include #include +#include #include "util.h" #include "misc.h" @@ -38,6 +39,8 @@ static enum fig_shape do_decode_shape(const char *s) return fig_out; if (!strcmp(s, "3State")) return fig_tri; + if (!strcmp(s, "BiDi")) + return fig_bidir; fprintf(stderr, "unknown shape: \"%s\"\n", s); exit(1); } @@ -110,7 +113,7 @@ static bool parse_field(struct sch_ctx *ctx, const char *line) txt->rot = 90; break; default: - abort(); + assert(0); } switch (hor) { @@ -124,7 +127,7 @@ static bool parse_field(struct sch_ctx *ctx, const char *line) txt->hor = text_max; break; default: - abort(); + assert(0); } switch (vert) { @@ -138,7 +141,7 @@ static bool parse_field(struct sch_ctx *ctx, const char *line) txt->vert = text_max; break; default: - abort(); + assert(0); } // @@@ decode font @@ -249,6 +252,13 @@ bool sch_parse(struct sch_ctx *ctx, const char *line) return 1; } + /* NoConn */ + + if (sscanf(line, "NoConn ~ %d %d", &x, &y) == 2) { + fig_noconn(x, y); + return 1; + } + /* Wire */ if (sscanf(line, "Wire Wire Line%n", &n) == 0 && n) { @@ -347,5 +357,5 @@ bool sch_parse(struct sch_ctx *ctx, const char *line) void sch_init(struct sch_ctx *ctx) { ctx->state = sch_descr; - ctx->lineno++; + ctx->lineno = 0; } diff --git a/sch2fig/style.h b/sch2fig/style.h index 1da7c65..5c6c6c6 100644 --- a/sch2fig/style.h +++ b/sch2fig/style.h @@ -24,6 +24,7 @@ #define COLOR_SHEET_DWG COLOR_BLUE #define COLOR_TEXT COLOR_BLUE #define COLOR_WIRE COLOR_GREEN4 +#define COLOR_NOCONN COLOR_BLUE #define COLOR_GLABEL COLOR_RED4 #define COLOR_FIELD COLOR_CYAN3 #define COLOR_PIN_NAME COLOR_FIELD @@ -33,6 +34,7 @@ #define LAYER_GLABEL 20 #define LAYER_TEXT 30 +#define LAYER_NOCONN 40 #define LAYER_WIRES 50 #define LAYER_FIELD 60 #define LAYER_PIN_NAME LAYER_FIELD @@ -46,6 +48,8 @@ #define JUNCTION_R 40 +#define NOCONN_LEN 25 + #define GLABEL_OFFSET 20 #endif /* !STYLE_H */ diff --git a/sch2fig/util.h b/sch2fig/util.h index 4f2bec7..8849421 100644 --- a/sch2fig/util.h +++ b/sch2fig/util.h @@ -38,6 +38,10 @@ stralloc_tmp; }) +#define swap(a, b) \ + ({ typeof(a) _tmp = (a); a = (b); b = _tmp; }) + + #define unsupported(s) \ fprintf(stderr, __FILE__ ":%d: unsupported: " s "\n", __LINE__)