Implement programmer selection dialog

This tries to categorize the programmers by programming methods, to
allow reducing the size of the combo box to select from.
This commit is contained in:
Joerg Wunsch
2024-03-25 16:57:26 +01:00
parent 5022a36d95
commit 28e05c6840
2 changed files with 277 additions and 1 deletions

View File

@@ -69,6 +69,56 @@ def classify_devices():
result['other'].append(p.desc)
return result
def classify_programmers():
result = {
'isp': [],
'tpi': [],
'pdi': [],
'updi': [],
'jtag': [],
'hv': [],
'other': []
}
pgm = ad.lfirst(ad.cvar.programmers)
while pgm:
p = ad.ldata_programmer(pgm)
pgm = ad.lnext(pgm)
names = []
l = ad.lfirst(p.id)
while l:
names.append(ad.ldata_string(l))
l = ad.lnext(l)
pm = p.prog_modes
matched = False
if (pm & ad.PM_ISP) != 0:
for name in names:
result['isp'].append(name)
matched = True
if (pm & ad.PM_TPI) != 0:
for name in names:
result['tpi'].append(name)
matched = True
if (pm & ad.PM_PDI) != 0:
for name in names:
result['pdi'].append(name)
matched = True
if (pm & ad.PM_UPDI) != 0:
for name in names:
result['updi'].append(name)
matched = True
if (pm & (ad.PM_JTAG | ad.PM_JTAGmkI | ad.PM_XMEGAJTAG)) != 0:
for name in names:
result['jtag'].append(name)
matched = True
if (pm & (ad.PM_HVSP | ad.PM_HVPP)) != 0:
for name in names:
result['hv'].append(name)
matched = True
if not matched:
for name in names:
result['other'].append(name)
return result
def size_to_str(size: int):
if size >= 1024:
return f"{size // 1024} KiB"
@@ -106,7 +156,7 @@ class adgui(QObject):
p = pathlib.Path(argv[0])
srcdir = str(p.parent)
for f in [ "adgui.ui", "about.ui", "device.ui",
"devinfo.ui", "loglevel.ui" ]:
"devinfo.ui", "loglevel.ui", "programmer.ui" ]:
ui = QFile(srcdir + '/' + f)
if not ui.open(QFile.ReadOnly):
print(f"Cannot open {f}: {ui.errorString()}", file = sys.stderr)
@@ -122,6 +172,7 @@ class adgui(QObject):
self.adgui.actionAbout.triggered.connect(self.about.show)
self.adgui.actionDevice.triggered.connect(self.device.show)
self.adgui.actionProgrammer.triggered.connect(self.programmer.show)
self.adgui.loggingArea.setHtml(self.logstring)
(success, message) = avrdude_init()
@@ -150,6 +201,14 @@ class adgui(QObject):
self.device.atxmega.stateChanged.connect(self.update_device_cb)
self.device.avr_de.stateChanged.connect(self.update_device_cb)
self.device.other.stateChanged.connect(self.update_device_cb)
self.programmers = classify_programmers()
self.update_programmer_cb()
self.programmer.isp.stateChanged.connect(self.update_programmer_cb)
self.programmer.tpi.stateChanged.connect(self.update_programmer_cb)
self.programmer.pdi.stateChanged.connect(self.update_programmer_cb)
self.programmer.updi.stateChanged.connect(self.update_programmer_cb)
self.programmer.hv.stateChanged.connect(self.update_programmer_cb)
self.programmer.other.stateChanged.connect(self.update_programmer_cb)
self.device.buttonBox.accepted.connect(self.device_selected)
self.adgui.actionDevice_Info.triggered.connect(self.devinfo.show)
@@ -209,6 +268,20 @@ class adgui(QObject):
for d in self.devices[f]:
self.device.devices.addItem(d)
def update_programmer_cb(self):
fams = list(self.programmers.keys())
self.programmer.programmers.clear()
l = {}
for f in fams:
obj = eval('self.programmer.' + f + '.isChecked()')
if obj:
for d in self.programmers[f]:
l[d] = True
l = list(l.keys())
l.sort()
for k in l:
self.programmer.programmers.addItem(k)
def update_device_info(self):
p = ad.locate_part(ad.cvar.part_list, self.dev_selected)
if not p:

203
src/python/programmer.ui Normal file
View File

@@ -0,0 +1,203 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>PgmSelect</class>
<widget class="QDialog" name="PgmSelect">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>402</width>
<height>263</height>
</rect>
</property>
<property name="windowTitle">
<string>Programmer selection</string>
</property>
<widget class="QDialogButtonBox" name="buttonBox">
<property name="geometry">
<rect>
<x>280</x>
<y>160</y>
<width>81</width>
<height>61</height>
</rect>
</property>
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
</property>
</widget>
<widget class="QGroupBox" name="groupBox">
<property name="geometry">
<rect>
<x>10</x>
<y>10</y>
<width>141</width>
<height>241</height>
</rect>
</property>
<property name="title">
<string>Programmer type:</string>
</property>
<widget class="QCheckBox" name="isp">
<property name="geometry">
<rect>
<x>10</x>
<y>30</y>
<width>92</width>
<height>23</height>
</rect>
</property>
<property name="text">
<string>ISP</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
<widget class="QCheckBox" name="tpi">
<property name="geometry">
<rect>
<x>10</x>
<y>60</y>
<width>92</width>
<height>23</height>
</rect>
</property>
<property name="text">
<string>TPI</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
<widget class="QCheckBox" name="pdi">
<property name="geometry">
<rect>
<x>10</x>
<y>90</y>
<width>92</width>
<height>23</height>
</rect>
</property>
<property name="text">
<string>PDI</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
<widget class="QCheckBox" name="updi">
<property name="geometry">
<rect>
<x>10</x>
<y>120</y>
<width>92</width>
<height>23</height>
</rect>
</property>
<property name="text">
<string>UPDI</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
<widget class="QCheckBox" name="hv">
<property name="geometry">
<rect>
<x>10</x>
<y>180</y>
<width>111</width>
<height>23</height>
</rect>
</property>
<property name="text">
<string>HVSP/HVPP</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
<widget class="QCheckBox" name="other">
<property name="geometry">
<rect>
<x>10</x>
<y>210</y>
<width>92</width>
<height>23</height>
</rect>
</property>
<property name="text">
<string>Other</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
<widget class="QCheckBox" name="jtag">
<property name="geometry">
<rect>
<x>10</x>
<y>150</y>
<width>92</width>
<height>23</height>
</rect>
</property>
<property name="text">
<string>JTAG</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</widget>
<widget class="QComboBox" name="programmers">
<property name="geometry">
<rect>
<x>180</x>
<y>50</y>
<width>201</width>
<height>25</height>
</rect>
</property>
</widget>
</widget>
<resources/>
<connections>
<connection>
<sender>buttonBox</sender>
<signal>accepted()</signal>
<receiver>PgmSelect</receiver>
<slot>accept()</slot>
<hints>
<hint type="sourcelabel">
<x>248</x>
<y>254</y>
</hint>
<hint type="destinationlabel">
<x>157</x>
<y>274</y>
</hint>
</hints>
</connection>
<connection>
<sender>buttonBox</sender>
<signal>rejected()</signal>
<receiver>PgmSelect</receiver>
<slot>reject()</slot>
<hints>
<hint type="sourcelabel">
<x>316</x>
<y>260</y>
</hint>
<hint type="destinationlabel">
<x>286</x>
<y>274</y>
</hint>
</hints>
</connection>
</connections>
</ui>