aboutsummaryrefslogtreecommitdiff
path: root/templates
diff options
context:
space:
mode:
Diffstat (limited to 'templates')
-rw-r--r--templates/arduino-uno.py19
-rw-r--r--templates/intel-quark-d2000.py69
-rw-r--r--templates/nodemcu.py19
3 files changed, 107 insertions, 0 deletions
diff --git a/templates/arduino-uno.py b/templates/arduino-uno.py
new file mode 100644
index 0000000..a7b4ec7
--- /dev/null
+++ b/templates/arduino-uno.py
@@ -0,0 +1,19 @@
+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
+""")
diff --git a/templates/intel-quark-d2000.py b/templates/intel-quark-d2000.py
new file mode 100644
index 0000000..85572c5
--- /dev/null
+++ b/templates/intel-quark-d2000.py
@@ -0,0 +1,69 @@
+global generateHeader
+gpio_map = {
+ 2: '10',
+ 3: '11',
+ 4: '12',
+ 5: '13',
+ 6: '14',
+ 7: '15',
+ 8: '16',
+ 9: '17',
+ 10: '18',
+
+ 11: '9',
+ 13: '20',
+ 14: '21',
+ 15: '22',
+ 16: '23',
+ 18: '19',
+
+ 21: '24',
+
+ 31: '0',
+ 32: '1',
+ 33: '2',
+ 34: '3',
+ 35: '4',
+ 36: '5',
+ 37: '6',
+ 38: '7',
+ 39: '8'
+}
+
+generateHeader.println("""
+#include <stddef.h>
+#include <qm_gpio.h>
+
+enum schematic_direction {
+ schematic_direction_out = 1,
+ schematic_direction_in = 2
+};
+""")
+
+usages = generateHeader.netlist.find_usages_of(generateHeader.ref)
+
+for usage in usages:
+ node = usage.node_for_ref(generateHeader.ref)
+
+ gpio = gpio_map.get(node.pin)
+
+ if gpio is None:
+ continue
+
+ generateHeader.println(
+ 'static const uint8_t SCHEMATIC_' + usage.name + ' = ' + gpio + ';\n'
+ '\n'
+ 'static inline\n'
+ 'qm_rc_t schematic_' + usage.name + '_direction(enum schematic_direction dir) {\n'
+ ' qm_gpio_port_config_t cfg;\n'
+ '\n'
+ ' qm_gpio_get_config(QM_GPIO_0, &cfg);\n'
+ '\n'
+ ' if (dir == schematic_direction_out) {\n'
+ ' cfg.direction |= BIT(SCHEMATIC_' + usage.name + ');\n'
+ ' } else {\n'
+ ' cfg.direction &= ~BIT(SCHEMATIC_' + usage.name + ');\n'
+ ' }\n'
+ '\n'
+ ' return qm_gpio_set_config(QM_GPIO_0, &cfg);\n'
+ '}')
diff --git a/templates/nodemcu.py b/templates/nodemcu.py
new file mode 100644
index 0000000..a7b4ec7
--- /dev/null
+++ b/templates/nodemcu.py
@@ -0,0 +1,19 @@
+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
+""")