chiark / gitweb /
Merge pull request #601 from CapnBry/reloadscene
[cura.git] / Cura / avr_isp / ispBase.py
index 6c3537216d2244fcee404f9da588d6471039b117..ffee7285ad1d9eefd2f88d106129b0747dad98de 100644 (file)
@@ -1,14 +1,24 @@
-import os, struct, sys, time
+"""
+General interface for Isp based AVR programmers.
+The ISP AVR programmer can load firmware into AVR chips. Which are commonly used on 3D printers.
 
-from serial import Serial
+ Needs to be subclassed to support different programmers.
+ Currently only the stk500v2 subclass exists.
+"""
+__copyright__ = "Copyright (C) 2013 David Braam - Released under terms of the AGPLv3 License"
 
 import chipDB
 
 class IspBase():
+       """
+       Base class for ISP based AVR programmers.
+       Functions in this class raise an IspError when something goes wrong.
+       """
        def programChip(self, flashData):
+               """ Program a chip with the given flash data. """
                self.curExtAddr = -1
                self.chip = chipDB.getChipFromDB(self.getSignature())
-               if self.chip == False:
+               if not self.chip:
                        raise IspError("Chip with signature: " + str(self.getSignature()) + "not found")
                self.chipErase()
                
@@ -17,8 +27,11 @@ class IspBase():
                print("Verifying %i bytes" % len(flashData))
                self.verifyFlash(flashData)
 
-       #low level ISP commands
        def getSignature(self):
+               """
+               Get the AVR signature from the chip. This is a 3 byte array which describes which chip we are connected to.
+               This is important to verify that we are programming the correct type of chip and that we use proper flash block sizes.
+               """
                sig = []
                sig.append(self.sendISP([0x30, 0x00, 0x00, 0x00])[3])
                sig.append(self.sendISP([0x30, 0x00, 0x01, 0x00])[3])
@@ -26,8 +39,23 @@ class IspBase():
                return sig
        
        def chipErase(self):
+               """
+               Do a full chip erase, clears all data, and lockbits.
+               """
                self.sendISP([0xAC, 0x80, 0x00, 0x00])
 
+       def writeFlash(self, flashData):
+               """
+               Write the flash data, needs to be implemented in a subclass.
+               """
+               raise IspError("Called undefined writeFlash")
+
+       def verifyFlash(self, flashData):
+               """
+               Verify the flash data, needs to be implemented in a subclass.
+               """
+               raise IspError("Called undefined verifyFlash")
+
 class IspError():
        def __init__(self, value):
                self.value = value