comparison python/st-util.py @ 279:2ccd57b1d78c

Fix register allocator to do burn2 OK
author Windel Bouwman
date Sat, 12 Oct 2013 09:56:23 +0200
parents dd8bbb963458
children
comparison
equal deleted inserted replaced
278:9fca39eebe50 279:2ccd57b1d78c
17 fl.addRow('Chip id:', QLabel('0x{0:X}'.format(parent.stl.ChipId))) 17 fl.addRow('Chip id:', QLabel('0x{0:X}'.format(parent.stl.ChipId)))
18 fl.addRow('Current mode:', QLabel(parent.stl.CurrentModeString)) 18 fl.addRow('Current mode:', QLabel(parent.stl.CurrentModeString))
19 fl.addRow('Status:', QLabel(parent.stl.StatusString)) 19 fl.addRow('Status:', QLabel(parent.stl.StatusString))
20 20
21 class RegisterModel(QAbstractTableModel): 21 class RegisterModel(QAbstractTableModel):
22 def __init__(self): 22 def __init__(self):
23 super().__init__() 23 super().__init__()
24 self.regCount = 15 24 self.regCount = 15
25 self.device = None 25 self.device = None
26 def rowCount(self, parent): 26
27 def rowCount(self, parent):
27 if parent.isValid(): 28 if parent.isValid():
28 return 0 29 return 0
29 if self.device: 30 if self.device:
30 return 21 # TODO make variable 31 return 21 # TODO make variable
31 else: 32 else:
32 return 0 33 return 0
33 def setDevice(self, dev): 34
35 def setDevice(self, dev):
34 self.device = dev 36 self.device = dev
35 self.modelReset.emit() 37 self.modelReset.emit()
36 def columnCount(self, parent): 38
39 def columnCount(self, parent):
37 if parent.isValid(): 40 if parent.isValid():
38 return 0 41 return 0
39 return 2 42 return 2
40 def data(self, index, role): 43
44 def data(self, index, role):
41 if index.isValid(): 45 if index.isValid():
42 row, col = index.row(), index.column() 46 row, col = index.row(), index.column()
43 if role == Qt.DisplayRole: 47 if role == Qt.DisplayRole:
44 if col == 0: 48 if col == 0:
45 return 'R{0}'.format(row) 49 if row == 15:
50 return 'PC'
51 elif row == 14:
52 return 'LR'
53 elif row == 13:
54 return 'SP'
55 else:
56 return 'R{0}'.format(row)
46 elif col == 1: 57 elif col == 1:
47 v = self.device.iface.read_reg(row) 58 v = self.device.iface.read_reg(row)
48 return '0x{0:X}'.format(v) 59 return '0x{0:X}'.format(v)
49 def setData(self, index, value, role): 60
61 def setData(self, index, value, role):
50 if index.isValid(): 62 if index.isValid():
51 row = index.row() 63 row = index.row()
52 col = index.column() 64 col = index.column()
53 if role == Qt.EditRole and col == 1: 65 if role == Qt.EditRole and col == 1:
54 value = int(value, 16) 66 value = int(value, 16)
55 self.device.iface.write_reg(row, value) 67 self.device.iface.write_reg(row, value)
56 return True 68 return True
57 return False 69 return False
58 def flags(self, index): 70
71 def flags(self, index):
59 if index.isValid(): 72 if index.isValid():
60 row = index.row() 73 row = index.row()
61 col = index.column() 74 col = index.column()
62 if col == 1: 75 if col == 1:
63 return super().flags(index) | Qt.ItemIsEditable 76 return super().flags(index) | Qt.ItemIsEditable
64 return super().flags(index) 77 return super().flags(index)
65 def refresh(self): 78
79 def refresh(self):
66 if self.device: 80 if self.device:
67 fromIndex = self.index(0, 1) 81 fromIndex = self.index(0, 1)
68 toIndex = self.index(21, 1) 82 toIndex = self.index(21, 1)
69 self.dataChanged.emit(fromIndex, toIndex) 83 self.dataChanged.emit(fromIndex, toIndex)
70 84
71 85
72 class RegisterView(QTableView): 86 class RegisterView(QTableView):
73 def __init__(self): 87 def __init__(self):
74 super().__init__() 88 super().__init__()
75 self.mdl = RegisterModel() 89 self.mdl = RegisterModel()
76 self.setModel(self.mdl) 90 self.setModel(self.mdl)
77 def refresh(self): 91
92 def refresh(self):
78 if self.mdl.device: 93 if self.mdl.device:
79 self.setEnabled(not self.mdl.device.Running) 94 self.setEnabled(not self.mdl.device.Running)
80 self.mdl.refresh() 95 self.mdl.refresh()
96
81 97
82 class MemoryView(QWidget): 98 class MemoryView(QWidget):
83 BlockSize = 0x100 99 BlockSize = 0x100
84 def __init__(self): 100 def __init__(self):
85 super().__init__() 101 super().__init__()