Arjen Hiemstra 751f58fb02 Merge branch '15.10'
* 15.10: (39 commits)
  Remove unused import in StartSliceJob
  conforming to code style
  fix typo's..
  Adjust initial view to be slightly from the side
  uses a different method to check whether a machine name excists
  Sets the languageComboBox to the default language
  Remove per-group settings for now
  Make sure to send all settings when an object overrides the profile
  Properly emit writeStarted in RemovableDriveOutputDevice
  Add xy_offset setting to list of settings that trigger a disallowed area update
  Properly trigger a reslice when the active instance is changed
  Wizardpages without hack
  Only hides the window when there are no more pages
  Only add layer data node after all processing
  Also account for "xy_offset" setting for the disallowed areas
  JSON: workaround for stutter in spiralize vase: set travel speed to printing speed
  Adds a color for the error-messages
  Shows an error message when a user tries to add a printer with a name that already excists.
  JSON: support bottom stair step height defaults changed so that the bottom distance to the model isn't violated too much
  Try to use Protobuf CPP implementation if it is available
  ...
2015-11-13 11:31:29 +01:00

67 lines
2.2 KiB
Python

"""
General interface for Isp based AVR programmers.
The ISP AVR programmer can load firmware into AVR chips. Which are commonly used on 3D printers.
Needs to be subclassed to support different programmers.
Currently only the stk500v2 subclass exists.
This is a python 3 conversion of the code created by David Braam for the Cura project.
"""
from . 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, flash_data):
""" Program a chip with the given flash data. """
self.cur_ext_addr = -1
self.chip = chipDB.getChipFromDB(self.getSignature())
if not self.chip:
raise IspError("Chip with signature: " + str(self.getSignature()) + "not found")
self.chipErase()
print("Flashing %i bytes" % len(flash_data))
self.writeFlash(flash_data)
print("Verifying %i bytes" % len(flash_data))
self.verifyFlash(flash_data)
print("Completed")
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])
sig.append(self.sendISP([0x30, 0x00, 0x02, 0x00])[3])
return sig
def chipErase(self):
"""
Do a full chip erase, clears all data, and lockbits.
"""
self.sendISP([0xAC, 0x80, 0x00, 0x00])
def writeFlash(self, flash_data):
"""
Write the flash data, needs to be implemented in a subclass.
"""
raise IspError("Called undefined writeFlash")
def verifyFlash(self, flash_data):
"""
Verify the flash data, needs to be implemented in a subclass.
"""
raise IspError("Called undefined verifyFlash")
class IspError(Exception):
def __init__(self, value):
self.value = value
def __str__(self):
return repr(self.value)