aboutsummaryrefslogtreecommitdiff
path: root/main.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'main.cpp')
-rw-r--r--main.cpp47
1 files changed, 35 insertions, 12 deletions
diff --git a/main.cpp b/main.cpp
index 811a08f..4449f46 100644
--- a/main.cpp
+++ b/main.cpp
@@ -107,14 +107,14 @@ public:
virtual bool generate(stringstream &out, const string &ref, const vector<const net *> usages) override {
static map<int, string> gpio_map{
- {2, "10"},
- {3, "11"},
- {4, "12"},
- {5, "13"},
- {6, "14"},
- {7, "15"},
- {8, "16"},
- {9, "17"},
+ {2, "10"},
+ {3, "11"},
+ {4, "12"},
+ {5, "13"},
+ {6, "14"},
+ {7, "15"},
+ {8, "16"},
+ {9, "17"},
{10, "18"},
{11, "9"},
@@ -138,16 +138,39 @@ public:
};
out << "#include <stddef.h>" << endl;
+ out << "#include <qm_gpio.h>" << endl;
out << endl;
+ out << "enum schematic_direction {" << endl;
+ out << " schematic_direction_out = 1," << endl;
+ out << " schematic_direction_in = 2" << endl;
+ out << "};" << endl;;
for (auto &usage: usages) {
auto node = usage->node_for_ref(ref);
auto gpio = gpio_map.find(node->pin);
- if (gpio != gpio_map.end()) {
- out << "static const uint8_t SCHEMATIC_" << usage->name << " = " << gpio->second << ";" << endl;
+ if (gpio == gpio_map.end()) {
+ continue;
}
+
+ out << "static const uint8_t SCHEMATIC_" << usage->name << " = " << gpio->second << ";" << endl;
+ out << endl;
+ out << "static inline" << endl;
+ out << "qm_rc_t schematic_PUSH_BUTTON_direction(enum schematic_direction dir) {" << endl;
+ out << " qm_gpio_port_config_t cfg;" << endl;
+ out << "" << endl;
+ out << " qm_gpio_get_config(QM_GPIO_0, &cfg);" << endl;
+ out << "" << endl;
+ out << " if (dir == schematic_direction_out) {" << endl;
+ out << " cfg.direction |= BIT(SCHEMATIC_PUSH_BUTTON);" << endl;
+ out << " } else {" << endl;
+ out << " cfg.direction &= ~BIT(SCHEMATIC_PUSH_BUTTON);" << endl;
+ out << " }" << endl;
+ out << "" << endl;
+ out << " return qm_gpio_set_config(QM_GPIO_0, &cfg);" << endl;
+ out << "}" << endl;
+ out << endl;
}
return true;
@@ -236,7 +259,8 @@ bool generate(const char *ref, const trygvis::kicad::netlist::netlist &netlist,
out << "/*" << endl;
out << "THIS FILE IS GENERATED. DO NOT EDIT." << endl;
out << endl;
- out << "Generated from schematic for reference " << ref << ", part " << partName << " in library " << library->name << "." << endl;
+ out << "Generated from schematic for reference " << ref << ", part " << partName << " in library " <<
+ library->name << "." << endl;
out << "*/" << endl;
out << endl;
@@ -244,7 +268,6 @@ bool generate(const char *ref, const trygvis::kicad::netlist::netlist &netlist,
part->generate(out, ref, usages);
- out << endl;
out << "#endif // SCHEMATIC_H" << endl;
return true;