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