chiark / gitweb /
Updated all lineends for py files to unix style.
[cura.git] / Cura / avr_isp / ispBase.py
1 import os, struct, sys, time
2
3 from serial import Serial
4
5 import chipDB
6
7 class IspBase():
8         def programChip(self, flashData):
9                 self.curExtAddr = -1
10                 self.chip = chipDB.getChipFromDB(self.getSignature())
11                 if self.chip == False:
12                         raise IspError("Chip with signature: " + str(self.getSignature()) + "not found")
13                 self.chipErase()
14                 
15                 print("Flashing %i bytes" % len(flashData))
16                 self.writeFlash(flashData)
17                 print("Verifying %i bytes" % len(flashData))
18                 self.verifyFlash(flashData)
19
20         #low level ISP commands
21         def getSignature(self):
22                 sig = []
23                 sig.append(self.sendISP([0x30, 0x00, 0x00, 0x00])[3])
24                 sig.append(self.sendISP([0x30, 0x00, 0x01, 0x00])[3])
25                 sig.append(self.sendISP([0x30, 0x00, 0x02, 0x00])[3])
26                 return sig
27         
28         def chipErase(self):
29                 self.sendISP([0xAC, 0x80, 0x00, 0x00])
30
31 class IspError():
32         def __init__(self, value):
33                 self.value = value
34         def __str__(self):
35                 return repr(self.value)