-
Notifications
You must be signed in to change notification settings - Fork 1
/
skimibowi.py
394 lines (358 loc) · 17.7 KB
/
skimibowi.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
#!/usr/bin/env python
# MIT license
#
# Skimibowi - SKiDL Microcontroller Board Wizard
# Copyright (C) 2019 Jussi Vestman
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
import argparse
from PySide2 import QtCore
from PySide2 import QtWidgets
from controller import footprints
from controller import battery_footprints
from controller import regulators
from controller import resistor_footprints
from controller import usb_connector_footprints
from controller import fuse_footprints
from controller import onewire_connector_footprints
from controller import load_settings
from controller import generate_skidl
from controller import generate_from_settings
class QIComboBox(QtWidgets.QComboBox):
def __init__(self, parent=None):
super(QIComboBox, self).__init__(parent)
class Skimibowi(QtWidgets.QWizard):
def __init__(self, parent=None):
super(Skimibowi, self).__init__(parent)
self.addPage(MCU(self))
self.addPage(PowerManagementPage(self))
self.addPage(PeripheralsPage(self))
self.addPage(SerialSettingsPage(self))
self.addPage(I2CSettingsPage(self))
self.addPage(SpiSettingsPage(self))
self.addPage(FootprintsPage(self))
self.addPage(FinalPage(self))
self.setWindowTitle("Skidl Microcontroller Board Wizard")
self.label = QtWidgets.QLabel("")
self.label.setAlignment(QtCore.Qt.AlignTop)
self.setSideWidget(self.label)
self.currentIdChanged.connect(self.id_changed)
self.resize(640, 480)
def id_changed(self):
"""Update wizard pages list in the left side pane of the Wizard"""
titles = ""
for page_id in self.pageIds():
pagename = self.page(page_id).title()
if page_id == self.currentId():
pagename = '<b>' + pagename + '</b>'
titles += '<p>' + pagename + '</p>'
self.label.setText(titles)
class MCU(QtWidgets.QWizardPage):
"""Wizard page for configuring the MCU being used"""
def __init__(self, parent=None):
super(MCU, self).__init__(parent)
self.setTitle("Microcontroller")
self.comboBox = QIComboBox(self)
self.comboBox.addItems(footprints.keys())
self.resetButton = QtWidgets.QCheckBox("Reset button")
self.resetLine = QtWidgets.QCheckBox("Reset line")
self.flashButton = QtWidgets.QCheckBox("Flash button")
self.ftdi_header = QtWidgets.QCheckBox("FTDI header")
self.led = QtWidgets.QCheckBox("Power-on led on GPIO0")
self.icsp = QtWidgets.QCheckBox("ICSP header")
self.crystal_frequency_label = QtWidgets.QLabel("Crystal Frequency")
self.crystal_frequency = QIComboBox(self)
self.crystal_frequency.addItems(['10Mhz', '12MHz', '16MHz', '20MHz'])
layout = QtWidgets.QVBoxLayout()
layout.addWidget(self.comboBox)
layout.addWidget(self.resetButton)
layout.addWidget(self.resetLine)
layout.addWidget(self.flashButton)
layout.addWidget(self.ftdi_header)
layout.addWidget(self.led)
layout.addWidget(self.icsp)
layout.addWidget(self.crystal_frequency_label)
layout.addWidget(self.crystal_frequency)
self.registerField("mcu", self.comboBox, "currentText")
self.registerField("reset", self.resetLine)
self.registerField("Reset button", self.resetButton)
self.registerField("Flash button", self.flashButton)
self.registerField("FTDI header", self.ftdi_header)
self.registerField("led", self.led)
self.registerField("icsp", self.icsp)
self.registerField("crystal_frequency", self.crystal_frequency, "currentText")
self.setLayout(layout)
class PowerManagementPage(QtWidgets.QWizardPage):
"""Wizard page for configuring board power management devices and networks"""
def __init__(self, parent=None):
super(PowerManagementPage, self).__init__(parent)
self.setTitle('Power Management')
self.label1 = QtWidgets.QLabel('Battery')
self.powersource = QIComboBox(self)
self.powersource.addItems(battery_footprints.keys())
self.layout = QtWidgets.QVBoxLayout()
self.layout.addWidget(self.label1)
self.layout.addWidget(self.powersource)
self.layout.addWidget(QtWidgets.QLabel("Regulator"))
self.regulator = QIComboBox(self)
self.regulator.addItems(regulators.keys())
self.layout.addWidget(self.regulator)
self.caps = QtWidgets.QGroupBox("Regulator bypass capasitors")
self.caps.layout = QtWidgets.QHBoxLayout()
self.caps.setLayout(self.caps.layout)
self.layout.addWidget(self.caps)
self.caps.layout.addWidget(QtWidgets.QLabel("Vin"))
self.vin_bypass_cap = QtWidgets.QLineEdit()
self.caps.layout.addWidget(self.vin_bypass_cap)
self.caps.layout.addWidget(QtWidgets.QLabel("Vout"))
self.vout_bypass_cap = QtWidgets.QLineEdit()
self.caps.layout.addWidget(self.vout_bypass_cap)
self.layout.addWidget(QtWidgets.QLabel('Battery management'))
self.battery_management = QIComboBox(self)
self.battery_management.addItem('No battery management ic')
self.battery_management.addItem('MCP73871-2AA')
self.battery_management.addItem('MCP73831')
self.layout.addWidget(self.battery_management)
self.layout.addWidget(QtWidgets.QLabel("MCU power rail"))
self.mcurail = QIComboBox(self)
self.mcurail.addItems(["+VBatt", "+3V", "+3V3", "+5V"])
self.layout.addWidget(self.mcurail)
self.layout.addWidget(QtWidgets.QLabel("Fuse"))
self.fuse = QIComboBox(self)
self.fuse.addItems(fuse_footprints.keys())
self.layout.addWidget(self.fuse)
self.switch = QtWidgets.QCheckBox("Add power switch")
self.layout.addWidget(self.switch)
self.autoselect = QtWidgets.QCheckBox("+5V/USB Auto Selector")
self.layout.addWidget(self.autoselect)
self.setLayout(self.layout)
self.registerField("mcurail", self.mcurail, "currentText")
self.registerField("powersource", self.powersource, "currentText")
self.registerField("regulator", self.regulator, "currentText")
self.registerField("regulator_vin_bypass_cap", self.vin_bypass_cap)
self.registerField("regulator_vout_bypass_cap", self.vout_bypass_cap)
self.registerField("battery_management", self.battery_management, "currentText")
self.registerField("fuse", self.fuse, "currentText")
self.registerField("switch", self.switch)
self.registerField("autoselect", self.autoselect)
class FootprintsPage(QtWidgets.QWizardPage):
"""Wizard page for configuring default footprints for classes of devices and board footprint"""
def __init__(self, parent=None):
super(FootprintsPage, self).__init__(parent)
self.setTitle("Footprints")
self.common_footprint_label = QtWidgets.QLabel()
self.common_footprint = QIComboBox(self)
self.common_footprint.addItems(resistor_footprints.keys())
self.registerField('common_footprint', self.common_footprint, 'currentText')
self.transistor_footprint_label = QtWidgets.QLabel()
self.transistor_footprint_label.setText("Transistor footprint")
self.transistor_footprint = QIComboBox(self)
self.transistor_footprint.addItems(["THT", "SOT-223", "SOT-23"])
self.registerField('transistor_footprint', self.transistor_footprint, 'currentText')
self.crystal_footprint_label = QtWidgets.QLabel()
self.crystal_footprint_label.setText("Crystal footprint")
self.crystal_footprint = QIComboBox(self)
self.crystal_footprint.addItems(["HC-49", "CST"])
self.registerField('crystal_footprint', self.crystal_footprint, 'currentText')
self.button_footprint_label = QtWidgets.QLabel()
self.button_footprint_label.setText("Tactile button footprint")
self.button_footprint = QIComboBox(self)
self.button_footprint.addItem("b3u-1000")
self.registerField('button_footprint', self.button_footprint, 'currentText')
self.board_footprint_label = QtWidgets.QLabel()
self.board_footprint = QIComboBox(self)
self.board_footprint.addItem("None")
self.board_footprint.addItem("Arduino Uno R3")
self.board_footprint.addItem("Arduino Nano")
self.board_footprint.addItem("Wemos D1 Mini")
self.board_footprint.addItem("Adafruit Feather")
self.registerField('board_footprint', self.board_footprint, 'currentText')
layout = QtWidgets.QVBoxLayout()
layout.addWidget(self.common_footprint_label)
layout.addWidget(self.common_footprint)
layout.addWidget(self.transistor_footprint_label)
layout.addWidget(self.transistor_footprint)
layout.addWidget(self.crystal_footprint_label)
layout.addWidget(self.crystal_footprint)
layout.addWidget(self.button_footprint_label)
layout.addWidget(self.button_footprint)
layout.addWidget(self.board_footprint_label)
layout.addWidget(self.board_footprint)
self.setLayout(layout)
def initializePage(self):
self.common_footprint_label.setText("Capasitor, resistor and diode form factor")
self.board_footprint_label.setText("Board outline footprint")
class PeripheralsPage(QtWidgets.QWizardPage):
def __init__(self, parent=None):
super(PeripheralsPage, self).__init__(parent)
self.setTitle("Peripherals")
self.peripherals = {}
self.usb_uart_label = QtWidgets.QLabel()
self.usb_uart_label.setText("USB Uart")
self.usb_uart = QIComboBox(self)
self.usb_uart.addItem("No USB")
self.usb_uart.addItem("FT231")
self.usb_uart.addItem("FT232RL")
self.usb_uart.addItem("CP2102N-A01-GQFN24")
self.usb_uart.addItem("CP2104")
self.usb_uart.addItem("VUSB-AVR")
self.registerField("usb_uart", self.usb_uart, "currentText")
self.usb_connector_label = QtWidgets.QLabel()
self.usb_connector_label.setText("USB Connector")
self.usb_connector = QIComboBox(self)
self.usb_connector.addItems(usb_connector_footprints.keys())
self.registerField("usb_connector", self.usb_connector, "currentText")
self.adc_label = QtWidgets.QLabel()
self.adc_label.setText("ADC pin")
self.adc_voltage_divider = QtWidgets.QComboBox()
self.adc_voltage_divider.addItems(['1.0V', '3.0V', '3V3', '4.5V', '5V', '6V', '9V', '12V', '24V'])
self.onewire_label = QtWidgets.QLabel()
self.onewire_label.setText("Onewire")
self.peripherals["DS18B20"] = QtWidgets.QCheckBox("DS18B20")
self.registerField("DS18B20", self.peripherals["DS18B20"])
self.peripherals["DS18B20U"] = QtWidgets.QCheckBox("DS18B20U")
self.registerField("DS18B20U", self.peripherals["DS18B20U"])
self.onewire_connector_label = QtWidgets.QLabel()
self.onewire_connector_label.setText("Onewire connector")
self.onewire_connector = QtWidgets.QComboBox()
self.onewire_connector.addItems(onewire_connector_footprints.keys())
self.registerField("onewire_connector", self.onewire_connector, "currentText")
layout = QtWidgets.QVBoxLayout()
layout.addWidget(self.usb_uart_label)
layout.addWidget(self.usb_uart)
layout.addWidget(self.usb_connector_label)
layout.addWidget(self.usb_connector)
layout.addWidget(self.adc_label)
layout.addWidget(self.adc_voltage_divider)
layout.addWidget(self.onewire_label)
layout.addWidget(self.peripherals["DS18B20"])
layout.addWidget(self.peripherals["DS18B20U"])
layout.addWidget(self.onewire_connector_label)
layout.addWidget(self.onewire_connector)
self.setLayout(layout)
class SerialSettingsPage(QtWidgets.QWizardPage):
"""Wizard page for configuring serial bus connected peripherals"""
def __init__(self, parent=None):
super(SerialSettingsPage, self).__init__(parent)
self.setTitle("Serial devices")
self.layout = QtWidgets.QVBoxLayout()
self.setLayout(self.layout)
self.hc12_group = QtWidgets.QGroupBox("")
self.hc12 = QtWidgets.QCheckBox("HC-12")
self.registerField('hc12', self.hc12)
self.hc12_group.layout = QtWidgets.QHBoxLayout()
self.hc12_group.layout.addWidget(self.hc12)
self.hc12_group.setLayout(self.hc12_group.layout)
self.hc12_label = QtWidgets.QLabel('Bus:')
self.hc12_group.layout.addWidget(self.hc12_label)
self.hc12_label.setAlignment(QtCore.Qt.AlignRight | QtCore.Qt.AlignVCenter)
self.hc12_serial = QIComboBox(self)
self.hc12_serial.addItem("TXD/RXD")
self.hc12_serial.addItem("TXD2/RXD2")
self.registerField("hc12_serial", self.hc12_serial, "currentText")
self.hc12_group.layout.addWidget(self.hc12_serial)
self.layout.addWidget(self.hc12_group)
class SpiSettingsPage(QtWidgets.QWizardPage):
"""Wizard page for configuring SPI bus connected peripherals"""
def __init__(self, parent=None):
super(SpiSettingsPage, self).__init__(parent)
self.setTitle("SPI devices")
self.layout = QtWidgets.QVBoxLayout()
self.setLayout(self.layout)
self.addDeviceGroupBox("sh1106", "sh1106")
self.addDeviceGroupBox("si4463", "Si4463")
def addDeviceGroupBox(self, name, title):
gp = QtWidgets.QGroupBox("")
checkbox = QtWidgets.QCheckBox(title)
self.registerField(name, checkbox)
gp.layout = QtWidgets.QHBoxLayout()
gp.layout.addWidget(checkbox)
gp.setLayout(gp.layout)
label = QtWidgets.QLabel('CS:')
gp.layout.addWidget(label)
label.setAlignment(QtCore.Qt.AlignRight | QtCore.Qt.AlignVCenter)
combobox = QIComboBox(self)
combobox.addItem("GPIO1")
combobox.addItem("GPIO2")
self.registerField(f"{name}_cs", combobox, "currentText")
gp.layout.addWidget(combobox)
self.layout.addWidget(gp)
class I2CSettingsPage(QtWidgets.QWizardPage):
"""Wizard page for configuring SPI bus connected peripherals"""
def __init__(self, parent=None):
super(I2CSettingsPage, self).__init__(parent)
self.setTitle("I2C devices")
self.layout = QtWidgets.QVBoxLayout()
self.setLayout(self.layout)
self.addDeviceGroupBox("ina219", "INA219")
self.addDeviceGroupBox("si5351", "Si5351A")
def addDeviceGroupBox(self, name, title):
gp = QtWidgets.QGroupBox("")
checkbox = QtWidgets.QCheckBox(title)
self.registerField(name, checkbox)
gp.layout = QtWidgets.QHBoxLayout()
gp.layout.addWidget(checkbox)
gp.setLayout(gp.layout)
self.layout.addWidget(gp)
class FinalPage(QtWidgets.QWizardPage):
"""Wizard page for generating SKiDL source code"""
def __init__(self, parent=None):
super(FinalPage, self).__init__(parent)
self.setTitle("Generate Skidl")
self.filename_label = QtWidgets.QLabel("Filename")
self.filename = QtWidgets.QLineEdit()
self.filename.setText("mcu.py")
self.pcb_title_label = QtWidgets.QLabel("Title")
self.pcb_title = QtWidgets.QLineEdit()
self.author_label = QtWidgets.QLabel("Author")
self.author = QtWidgets.QLineEdit()
self.generate_labels = QtWidgets.QCheckBox("Generate subcircuit labels")
self.registerField("filename", self.filename)
self.registerField("generate_labels", self.generate_labels)
self.registerField("title", self.pcb_title)
self.registerField("author", self.author)
self.generate = QtWidgets.QPushButton("&Generate")
layout = QtWidgets.QVBoxLayout()
layout.addWidget(self.filename_label)
layout.addWidget(self.filename)
layout.addWidget(self.pcb_title_label)
layout.addWidget(self.pcb_title)
layout.addWidget(self.author_label)
layout.addWidget(self.author)
layout.addWidget(self.generate_labels)
layout.addWidget(self.generate)
self.generate.clicked.connect(self.generate_handler)
self.setLayout(layout)
def generate_handler(self):
generate_skidl(self)
if __name__ == '__main__':
import sys
parser = argparse.ArgumentParser(description='Skimibowi - SKiDL Microcontroller Board Wizard')
parser.add_argument('--no-window', metavar='FILE', help='Do not show ui, but generate SKiDL from settings.yml')
parser.add_argument('-f', metavar='settings.yml', help='Settings.yml filename')
args = parser.parse_args()
settings_file = args.f or 'settings.yml'
if args.no_window:
generate_from_settings(args.no_window, settings_file)
else:
app = QtWidgets.QApplication(sys.argv)
wizard = Skimibowi()
wizard.show()
load_settings(wizard, settings_file)
sys.exit(app.exec_())