aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--cli/generate-header.cpp15
-rw-r--r--core/include/trygvis/kicad.h94
-rw-r--r--core/kicad.cpp14
-rw-r--r--kicad/kicad_utils.lib50
-rw-r--r--python/include/trygvis/kicad/GenerateHeaderPy.h2
-rw-r--r--python/kicad_utils_py.cpp9
-rw-r--r--templates/arduino-uno.py4
-rw-r--r--templates/intel-quark-d2000.py3
-rw-r--r--templates/nodemcu-arduino.py65
-rw-r--r--templates/nodemcu.py19
10 files changed, 141 insertions, 134 deletions
diff --git a/cli/generate-header.cpp b/cli/generate-header.cpp
index 9d5a4f4..3ff39f6 100644
--- a/cli/generate-header.cpp
+++ b/cli/generate-header.cpp
@@ -1,4 +1,4 @@
-#include "trygvis/kicad.h"
+#include "trygvis/kicad/netlist.h"
using namespace trygvis::kicad;
using trygvis::kicad::netlist::component;
@@ -172,7 +172,7 @@ public:
python_init_error(const string &what) : runtime_error(what) {}
};
- python_init(const char *argv0, const vector<fs::path> &python_paths) {
+ python_init(bool debug, const char *argv0, const vector<fs::path> &python_paths) {
std::wstring_convert<codecvt_utf8<wchar_t>> converter;
wstring pythonpath(Py_GetPath());
@@ -182,7 +182,10 @@ public:
}
pythonpath = converter.from_bytes(path.string() + PATH_SEPARATOR) + pythonpath;
}
- wcerr << "PYTHONPATH: " << pythonpath << endl;
+
+ if (debug) {
+ wcerr << "PYTHONPATH: " << pythonpath << endl;
+ }
Py_SetPath(pythonpath.c_str());
program = Py_DecodeLocale(argv0, NULL);
@@ -191,7 +194,9 @@ public:
}
Py_SetProgramName(program);
- show_py_info();
+ if (debug) {
+ show_py_info();
+ }
Py_Initialize();
}
@@ -246,7 +251,7 @@ int main(int argc, char **argv) {
basedir / "lib",
};
- python_init python(argv[0], module_paths);
+ python_init python(opts.debug, argv[0], module_paths);
try {
auto ok = generate(opts.ref, &netlist, out, py_template.value());
diff --git a/core/include/trygvis/kicad.h b/core/include/trygvis/kicad.h
index bae250b..4b76868 100644
--- a/core/include/trygvis/kicad.h
+++ b/core/include/trygvis/kicad.h
@@ -1,10 +1,6 @@
#pragma once
#include <experimental/optional>
-#include <ostream>
-#include <stdexcept>
-#include <string>
-#include <vector>
namespace trygvis {
namespace kicad {
@@ -13,93 +9,3 @@ using opt = std::experimental::optional<T>;
using std::experimental::nullopt;
} // namespace kicad
} // namespace trygvis
-
-namespace trygvis {
-namespace kicad {
-namespace netlist {
-
-struct lib_source {
- const std::string lib;
- const std::string part;
-
- lib_source(const std::string &lib, const std::string &part) : lib(lib), part(part) {}
-};
-
-struct component {
- const std::string ref;
- const std::string value;
- const lib_source _lib_source;
-
- component(const std::string &ref, const std::string &value, const lib_source &_lib_source) :
- ref(ref), value(value), _lib_source(_lib_source) {}
-};
-
-struct pin {
- int num;
- std::string name;
- std::string type;
-};
-
-struct part {
- std::vector<pin> pins;
-};
-
-class node {
-public:
- const std::string ref;
- const int pin;
-
- node(const std::string &ref, int pin) : ref(ref), pin(pin) {}
-};
-
-class net {
-public:
- const int code;
- const std::string name;
- const std::vector<node> nodes;
-
- net(int code, const std::string &name, const std::vector<node> &nodes) : code(code), name(name), nodes(nodes) {}
-
- const node *node_for_ref(const std::string &ref) const;
-};
-
-struct netlist {
- std::vector<component> components;
- std::vector<part> parts;
- std::vector<net> nets;
-
- opt<const component *> find_component(const std::string &ref) const;
-
- std::vector<const net *> find_usage_of(const std::string &ref) const;
-};
-
-class kicad_parse_exception : public std::runtime_error {
-public:
- explicit kicad_parse_exception(const std::vector<std::string> &messages) :
- runtime_error("Parse error"), messages(messages) {}
-
- explicit kicad_parse_exception(const std::string &message) :
- runtime_error("Parse error"), messages({message}) {}
-
- ~kicad_parse_exception() {}
-
- const std::vector<std::string> messages;
-};
-
-class kicad_net_loader {
-public:
- kicad_net_loader();
-
- virtual ~kicad_net_loader();
-
- netlist load(std::string path, std::ostream &err);
-
- void setDebug(bool debug);
-
-private:
- bool debug_;
-};
-
-} // namespace netlist
-} // namespace kicad
-} // namespace trygvis
diff --git a/core/kicad.cpp b/core/kicad.cpp
index a553b62..c0315e6 100644
--- a/core/kicad.cpp
+++ b/core/kicad.cpp
@@ -1,4 +1,4 @@
-#include "trygvis/kicad.h"
+#include "trygvis/kicad/netlist.h"
#include "trygvis/antlr.h"
#include "trygvis/string_utils.h"
#include <KicadNetLexer.h>
@@ -35,7 +35,7 @@ opt<const component *> netlist::find_component(const string &ref) const {
return std::experimental::nullopt;
}
-vector<const net *> netlist::find_usage_of(const string &ref) const {
+vector<const net *> netlist::find_nets_using_ref(const string &ref) const {
vector<const net *> usage;
for (auto &net : nets) {
@@ -91,15 +91,9 @@ public:
name = name.substr(1);
}
-// cerr << "exitNet: " << "code=" << code << ", name=" << name << ", nodes=" << nodes.size() << endl;
+ bool hasName = !startsWith(name, "Net-(");
-// if (nodes.size() > 1) {
-// cerr << "Net#" << code << ": " << name << endl;
-// for (auto &node: nodes) {
-// cerr << " Node: " << node.ref << "#" << node.pin << endl;
-// }
-// }
- nets.emplace_back(code, name, nodes);
+ nets.emplace_back(code, hasName ? opt<string>(name) : nullopt, nodes);
nodes.clear();
}
diff --git a/kicad/kicad_utils.lib b/kicad/kicad_utils.lib
index fb4746d..fa368e4 100644
--- a/kicad/kicad_utils.lib
+++ b/kicad/kicad_utils.lib
@@ -95,4 +95,54 @@ X F_8 39 -350 1150 200 D 50 50 1 1 I
ENDDRAW
ENDDEF
#
+# NODEMCU
+#
+DEF NODEMCU U 0 40 Y Y 1 F N
+F0 "U" 0 -300 60 H V C CNN
+F1 "NODEMCU" 0 -200 60 H V C CNN
+F2 "" 0 -300 60 H V C CNN
+F3 "" 0 -300 60 H V C CNN
+DRAW
+T 0 250 -700 60 0 0 0 FLASH Normal 0 C C
+T 0 -250 -700 60 0 0 0 RST Normal 0 C C
+P 2 0 0 0 -200 700 150 700 N
+P 16 0 0 0 -200 600 -200 950 -150 950 -150 800 -100 800 -100 950 -50 950 -50 800 0 800 0 950 50 950 50 800 100 800 100 950 150 950 250 950 N
+C -250 -825 50 0 1 0 N
+C 250 -825 50 0 1 0 N
+S -550 -1000 550 1000 0 1 0 N
+S -325 -750 -175 -900 0 1 0 N
+S 175 -750 325 -900 0 1 0 N
+X Vin 1 -750 -650 200 R 50 50 1 1 I
+X GND 2 -750 -550 200 R 50 50 1 1 I
+X RST 3 -750 -450 200 R 50 50 1 1 I
+X EN 4 -750 -350 200 R 50 50 1 1 I
+X 3V3 5 -750 -250 200 R 50 50 1 1 I
+X GND 6 -750 -150 200 R 50 50 1 1 I
+X CLK 7 -750 -50 200 R 50 50 1 1 I
+X SD0 8 -750 50 200 R 50 50 1 1 I
+X CMD 9 -750 150 200 R 50 50 1 1 I
+X SD1 10 -750 250 200 R 50 50 1 1 I
+X D4 20 750 350 200 L 50 50 1 1 I
+X 3V3 30 750 -650 200 L 50 50 1 1 I
+X SD2 11 -750 350 200 R 50 50 1 1 w
+X 3V3 21 750 250 200 L 50 50 1 1 I
+X SD3 12 -750 450 200 R 50 50 1 1 I
+X GND 22 750 150 200 L 50 50 1 1 I
+X RSV 13 -750 550 200 R 50 50 1 1 N
+X D5 23 750 50 200 L 50 50 1 1 I
+X RSV 14 -750 650 200 R 50 50 1 1 N
+X D6 24 750 -50 200 L 50 50 1 1 I
+X A0 15 -750 750 200 R 50 50 1 1 I
+X D7 25 750 -150 200 L 50 50 1 1 I
+X D0 16 750 750 200 L 50 50 1 1 I
+X D8 26 750 -250 200 L 50 50 1 1 I
+X D1 17 750 650 200 L 50 50 1 1 I
+X RX 27 750 -350 200 L 50 50 1 1 I
+X D2 18 750 550 200 L 50 50 1 1 I
+X TX 28 750 -450 200 L 50 50 1 1 I
+X D3 19 750 450 200 L 50 50 1 1 I
+X GND 29 750 -550 200 L 50 50 1 1 I
+ENDDRAW
+ENDDEF
+#
#End Library
diff --git a/python/include/trygvis/kicad/GenerateHeaderPy.h b/python/include/trygvis/kicad/GenerateHeaderPy.h
index 893b7ed..9e831e9 100644
--- a/python/include/trygvis/kicad/GenerateHeaderPy.h
+++ b/python/include/trygvis/kicad/GenerateHeaderPy.h
@@ -1,7 +1,7 @@
#ifndef KICAD_UTILS_GENERATEHEADEPY_H
#define KICAD_UTILS_GENERATEHEADEPY_H
-#include "trygvis/kicad.h"
+#include "trygvis/kicad/netlist.h"
#include "pybind11/pybind11.h"
#include <memory>
#include <sstream>
diff --git a/python/kicad_utils_py.cpp b/python/kicad_utils_py.cpp
index 6cd3948..8cb91ee 100644
--- a/python/kicad_utils_py.cpp
+++ b/python/kicad_utils_py.cpp
@@ -6,6 +6,11 @@ using namespace std;
using namespace trygvis::kicad::netlist;
using namespace trygvis::kicad::python;
+static
+py::object net_name(const net &n) {
+ return n.name ? static_cast<py::object>(py::str(n.name.value())) : py::none();
+}
+
void init_module(py::module &m) {
py::class_<node>(m, "node").
def_readonly("ref", &node::ref).
@@ -13,12 +18,12 @@ void init_module(py::module &m) {
py::class_<net>(m, "net").
def_readonly("code", &net::code).
- def_readonly("name", &net::name).
+ def_property_readonly("name", &net_name).
def_readonly("nodes", &net::nodes).
def("node_for_ref", &net::node_for_ref, py::return_value_policy::reference);
py::class_<nl>(m, "netlist").
- def("find_usages_of", &nl::find_usage_of, py::return_value_policy::reference);
+ def("find_nets_using_ref", &nl::find_nets_using_ref, py::return_value_policy::reference);
py::class_<GenerateHeaderPy>(m, "GenerateHeader").
def(py::init<const string &, nl *>()).
diff --git a/templates/arduino-uno.py b/templates/arduino-uno.py
index a7b4ec7..ada59a3 100644
--- a/templates/arduino-uno.py
+++ b/templates/arduino-uno.py
@@ -4,7 +4,7 @@ generateHeader.println("""
namespace schematic {
""")
-usages = generateHeader.netlist.find_usages_of(generateHeader.ref)
+usages = generateHeader.netlist.find_nets_using_ref(generateHeader.ref)
for usage in usages:
node = usage.node_for_ref(generateHeader.ref)
@@ -12,7 +12,7 @@ for usage in usages:
if 7 <= node.pin <= 12:
generateHeader.println("static const int ANALOG_" + usage.name + " = " + str(node.pin - 7) + ";")
elif 13 <= node.pin <= 26:
- generateHeader.println("static const int ANALOG_" + usage.name + " = " + str(node.pin - 13) + ";")
+ generateHeader.println("static const int " + usage.name + " = " + str(node.pin - 13) + ";")
generateHeader.println("""
} // namespace schematic
diff --git a/templates/intel-quark-d2000.py b/templates/intel-quark-d2000.py
index 85572c5..5bc69e0 100644
--- a/templates/intel-quark-d2000.py
+++ b/templates/intel-quark-d2000.py
@@ -1,4 +1,5 @@
global generateHeader
+
gpio_map = {
2: '10',
3: '11',
@@ -40,7 +41,7 @@ enum schematic_direction {
};
""")
-usages = generateHeader.netlist.find_usages_of(generateHeader.ref)
+usages = generateHeader.netlist.find_nets_using_ref(generateHeader.ref)
for usage in usages:
node = usage.node_for_ref(generateHeader.ref)
diff --git a/templates/nodemcu-arduino.py b/templates/nodemcu-arduino.py
new file mode 100644
index 0000000..1f258e6
--- /dev/null
+++ b/templates/nodemcu-arduino.py
@@ -0,0 +1,65 @@
+global generateHeader
+
+gpio_map = {
+ # Left side
+ 1: None, # Vin
+ 2: None, # GND
+ 3: None, # RST
+ 4: None, # EN
+ 5: None, # 3V3
+ 6: None, # GND
+ 7: None, # CLK
+ 8: None, # SD0
+ 9: None, # CMD
+ 10: None, # SD1
+ 11: '9', # SD2
+ 12: '10', # SD3
+ 13: None, # RSV
+ 14: None, # RSV
+ 15: '0', # A0
+
+ # Right side
+ 16: '16',
+ 17: '5',
+ 18: '4',
+ 19: '0',
+ 20: '2',
+ 21: None, # 3V3
+ 22: None, # Gnd
+ 23: '14',
+ 24: '12',
+ 25: '13',
+ 26: '15',
+ 27: '3',
+ 28: '1',
+ 29: None, # GND
+ 30: None, # 3V3
+}
+
+usages = generateHeader.netlist.find_nets_using_ref(generateHeader.ref)
+
+entries = []
+
+for usage in usages:
+ if usage.name is None:
+ continue
+
+ node = usage.node_for_ref(generateHeader.ref)
+
+ name = gpio_map.get(node.pin)
+
+ if name is None:
+ continue
+
+ entries.append([usage.name, name])
+
+generateHeader.println("""
+namespace schematic {
+""")
+
+for x in sorted(entries, key=lambda e: e[0]):
+ generateHeader.println("static const int " + x[0]+ " = " + x[1] + ";")
+
+generateHeader.println("""
+} // namespace schematic
+""")
diff --git a/templates/nodemcu.py b/templates/nodemcu.py
deleted file mode 100644
index a7b4ec7..0000000
--- a/templates/nodemcu.py
+++ /dev/null
@@ -1,19 +0,0 @@
-global generateHeader
-
-generateHeader.println("""
-namespace schematic {
-""")
-
-usages = generateHeader.netlist.find_usages_of(generateHeader.ref)
-
-for usage in usages:
- node = usage.node_for_ref(generateHeader.ref)
-
- if 7 <= node.pin <= 12:
- generateHeader.println("static const int ANALOG_" + usage.name + " = " + str(node.pin - 7) + ";")
- elif 13 <= node.pin <= 26:
- generateHeader.println("static const int ANALOG_" + usage.name + " = " + str(node.pin - 13) + ";")
-
-generateHeader.println("""
-} // namespace schematic
-""")