From 8f760649e37e9986350e90dce47d651f83bc375b Mon Sep 17 00:00:00 2001 From: dherrada Date: Sun, 15 Mar 2020 17:20:12 -0400 Subject: [PATCH] Ran black, updated to pylint 2.x --- .github/workflows/build.yml | 2 +- adafruit_avrprog.py | 206 ++++++++++-------- docs/conf.py | 110 ++++++---- examples/avrprog_program_mega2560.py | 27 ++- examples/avrprog_program_tiny13a.py | 8 +- examples/avrprog_program_trinket85.py | 8 +- examples/avrprog_program_uno328.py | 19 +- examples/avrprog_read_signature_simpletest.py | 6 +- setup.py | 50 ++--- 9 files changed, 239 insertions(+), 197 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index fff3aa9..1dad804 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -40,7 +40,7 @@ jobs: source actions-ci/install.sh - name: Pip install pylint, black, & Sphinx run: | - pip install --force-reinstall pylint==1.9.2 black==19.10b0 Sphinx sphinx-rtd-theme + pip install --force-reinstall pylint black==19.10b0 Sphinx sphinx-rtd-theme - name: Library version run: git describe --dirty --always --tags - name: PyLint diff --git a/adafruit_avrprog.py b/adafruit_avrprog.py index 42670b4..fb4458f 100644 --- a/adafruit_avrprog.py +++ b/adafruit_avrprog.py @@ -54,43 +54,46 @@ _SLOW_CLOCK = 100000 _FAST_CLOCK = 1000000 + class AVRprog: """ Helper class used to program AVR chips from CircuitPython. """ + class Boards: """ Some well known board definitions. """ + # pylint: disable=too-few-public-methods ATtiny13a = { - 'name': "ATtiny13a", - 'sig': [0x1E, 0x90, 0x07], - 'flash_size': 1024, - 'page_size': 32, - 'fuse_mask': (0xFF, 0xFF, 0x00, 0x03), - 'clock_speed': 100000 + "name": "ATtiny13a", + "sig": [0x1E, 0x90, 0x07], + "flash_size": 1024, + "page_size": 32, + "fuse_mask": (0xFF, 0xFF, 0x00, 0x03), + "clock_speed": 100000, } ATtiny85 = { - 'name': "ATtiny85", - 'sig': [0x1E, 0x93, 0x0B], - 'flash_size': 8192, - 'page_size': 64, - 'fuse_mask': (0xFF, 0xFF, 0x07, 0x3F) + "name": "ATtiny85", + "sig": [0x1E, 0x93, 0x0B], + "flash_size": 8192, + "page_size": 64, + "fuse_mask": (0xFF, 0xFF, 0x07, 0x3F), } ATmega328p = { - 'name': "ATmega328p", - 'sig': [0x1E, 0x95, 0x0F], - 'flash_size': 32768, - 'page_size': 128, - 'fuse_mask': (0xFF, 0xFF, 0x07, 0x3F), + "name": "ATmega328p", + "sig": [0x1E, 0x95, 0x0F], + "flash_size": 32768, + "page_size": 128, + "fuse_mask": (0xFF, 0xFF, 0x07, 0x3F), } ATmega2560 = { - 'name': "ATmega2560", - 'sig': [0x1E, 0x98, 0x01], - 'flash_size': 262144, - 'page_size': 256, - 'fuse_mask': (0xFF, 0xFF, 0x07, 0x3F) + "name": "ATmega2560", + "sig": [0x1E, 0x98, 0x01], + "flash_size": 262144, + "page_size": 256, + "fuse_mask": (0xFF, 0xFF, 0x07, 0x3F), } _spi = None @@ -107,7 +110,6 @@ def init(self, spi_bus, rst_pin): self._rst.direction = Direction.OUTPUT self._rst.value = True - def verify_sig(self, chip, verbose=False): """ Verify that the chip is connected properly, responds to commands, @@ -118,7 +120,7 @@ def verify_sig(self, chip, verbose=False): self.end() if verbose: print("Found signature: %s" % [hex(i) for i in sig]) - if sig != chip['sig']: + if sig != chip["sig"]: return False return True @@ -135,21 +137,21 @@ def program_file(self, chip, file_name, verbose=False, verify=True): print("Erasing chip....") self.erase_chip() - clock_speed = getattr(chip, 'clock_speed', _FAST_CLOCK) + clock_speed = getattr(chip, "clock_speed", _FAST_CLOCK) self.begin(clock=clock_speed) # create a file state dictionary - file_state = {'line': 0, 'ext_addr': 0, 'eof': False} - file_state['f'] = open(file_name, 'r') + file_state = {"line": 0, "ext_addr": 0, "eof": False} + file_state["f"] = open(file_name, "r") - page_size = chip['page_size'] + page_size = chip["page_size"] - for page_addr in range(0, chip['flash_size'], page_size): + for page_addr in range(0, chip["flash_size"], page_size): if verbose: print("Programming page $%04X..." % page_addr, end="") page_buffer = bytearray(page_size) for b in range(page_size): - page_buffer[b] = 0xFF # make an empty page + page_buffer[b] = 0xFF # make an empty page read_hex_page(file_state, page_addr, page_size, page_buffer) @@ -158,7 +160,7 @@ def program_file(self, chip, file_name, verbose=False, verify=True): print("skipping") continue - #print("From HEX file: ", page_buffer) + # print("From HEX file: ", page_buffer) self._flash_page(bytearray(page_buffer), page_addr, page_size) if not verify: @@ -170,20 +172,23 @@ def program_file(self, chip, file_name, verbose=False, verify=True): print("Verifying page @ $%04X" % page_addr) read_buffer = bytearray(page_size) self.read(page_addr, read_buffer) - #print("From memory: ", read_buffer) + # print("From memory: ", read_buffer) if page_buffer != read_buffer: if verbose: # pylint: disable=line-too-long - print("Verify fail at address %04X\nPage should be: %s\nBut contains: %s" % (page_addr, page_buffer, read_buffer)) + print( + "Verify fail at address %04X\nPage should be: %s\nBut contains: %s" + % (page_addr, page_buffer, read_buffer) + ) # pylint: enable=line-too-long self.end() return False - if file_state['eof']: - break # we're done, bail! + if file_state["eof"]: + break # we're done, bail! - file_state['f'].close() + file_state["f"].close() self.end() return True @@ -196,16 +201,16 @@ def verify_file(self, chip, file_name, verbose=False): raise RuntimeError("Signature read failure") # create a file state dictionary - file_state = {'line': 0, 'ext_addr': 0, 'eof': False} - file_state['f'] = open(file_name, 'r') + file_state = {"line": 0, "ext_addr": 0, "eof": False} + file_state["f"] = open(file_name, "r") - page_size = chip['page_size'] - clock_speed = getattr(chip, 'clock_speed', _FAST_CLOCK) + page_size = chip["page_size"] + clock_speed = getattr(chip, "clock_speed", _FAST_CLOCK) self.begin(clock=clock_speed) - for page_addr in range(0x0, chip['flash_size'], page_size): + for page_addr in range(0x0, chip["flash_size"], page_size): page_buffer = bytearray(page_size) for b in range(page_size): - page_buffer[b] = 0xFF # make an empty page + page_buffer[b] = 0xFF # make an empty page read_hex_page(file_state, page_addr, page_size, page_buffer) @@ -213,21 +218,24 @@ def verify_file(self, chip, file_name, verbose=False): print("Verifying page @ $%04X" % page_addr) read_buffer = bytearray(page_size) self.read(page_addr, read_buffer) - #print("From memory: ", read_buffer) - #print("From file : ", page_buffer) + # print("From memory: ", read_buffer) + # print("From file : ", page_buffer) if page_buffer != read_buffer: if verbose: # pylint: disable=line-too-long - print("Verify fail at address %04X\nPage should be: %s\nBut contains: %s" % (page_addr, page_buffer, read_buffer)) + print( + "Verify fail at address %04X\nPage should be: %s\nBut contains: %s" + % (page_addr, page_buffer, read_buffer) + ) # pylint: enable=line-too-long self.end() return False - if file_state['eof']: - break # we're done, bail! + if file_state["eof"]: + break # we're done, bail! - file_state['f'].close() + file_state["f"].close() self.end() return True @@ -236,7 +244,7 @@ def read_fuses(self, chip): Read the 4 fuses and return them in a list (low, high, ext, lock) Each fuse is bitwise-&'s with the chip's fuse mask for simplicity """ - mask = chip['fuse_mask'] + mask = chip["fuse_mask"] self.begin(clock=_SLOW_CLOCK) low = self._transaction((0x50, 0, 0, 0))[2] & mask[0] high = self._transaction((0x58, 0x08, 0, 0))[2] & mask[1] @@ -253,10 +261,11 @@ def write_fuses(self, chip, low=None, high=None, ext=None, lock=None): """ self.begin(clock=_SLOW_CLOCK) lock and self._transaction((0xAC, 0xE0, 0, lock)) - low and self._transaction((0xAC, 0xA0, 0, low)) + low and self._transaction((0xAC, 0xA0, 0, low)) high and self._transaction((0xAC, 0xA8, 0, high)) - ext and self._transaction((0xAC, 0xA4, 0, ext)) + ext and self._transaction((0xAC, 0xA4, 0, ext)) self.end() + # pylint: enable=unused-argument,expression-not-assigned def verify_fuses(self, chip, low=None, high=None, ext=None, lock=None): @@ -274,7 +283,6 @@ def verify_fuses(self, chip, low=None, high=None, ext=None, lock=None): return False return True - def erase_chip(self): """ Fully erases the chip. @@ -323,18 +331,18 @@ def read(self, addr, read_buffer): Requires calling begin() beforehand to put in programming mode. """ last_addr = 0 - for i in range(len(read_buffer)//2): - read_addr = addr//2 + i # read 'words' so address is half + for i in range(len(read_buffer) // 2): + read_addr = addr // 2 + i # read 'words' so address is half if (last_addr >> 16) != (read_addr >> 16): # load extended byte - #print("Loading extended address", read_addr >> 16) + # print("Loading extended address", read_addr >> 16) self._transaction((0x4D, 0, read_addr >> 16, 0)) high = self._transaction((0x28, read_addr >> 8, read_addr, 0))[2] low = self._transaction((0x20, read_addr >> 8, read_addr, 0))[2] - #print("%04X: %02X %02X" % (read_addr*2, low, high)) - read_buffer[i*2] = low - read_buffer[i*2+1] = high + # print("%04X: %02X %02X" % (read_addr*2, low, high)) + read_buffer[i * 2] = low + read_buffer[i * 2 + 1] = high last_addr = read_addr @@ -344,9 +352,9 @@ def _flash_word(self, addr, low, high): self._transaction((0x48, addr >> 8, addr, high)) def _flash_page(self, page_buffer, page_addr, page_size): - page_addr //= 2 # address is by 'words' not bytes! - for i in range(page_size/2): # page indexed by words, not bytes - lo_byte, hi_byte = page_buffer[2*i:2*i+2] + page_addr //= 2 # address is by 'words' not bytes! + for i in range(page_size / 2): # page indexed by words, not bytes + lo_byte, hi_byte = page_buffer[2 * i : 2 * i + 2] self._flash_word(i, lo_byte, hi_byte) # load extended byte @@ -362,16 +370,17 @@ def _transaction(self, command): command = bytearray([i & 0xFF for i in command]) self._spi.write_readinto(command, reply) - #s = [hex(i) for i in command] - #print("Sending %s reply %s" % ([hex(i) for i in command], [hex(i) for i in reply])) + # s = [hex(i) for i in command] + # print("Sending %s reply %s" % ([hex(i) for i in command], [hex(i) for i in reply])) if reply[2] != command[1]: raise RuntimeError("SPI transaction failed") - return reply[1:] # first byte is ignored + return reply[1:] # first byte is ignored def _busy_wait(self): while self._transaction((0xF0, 0, 0, 0))[2] & 0x01: pass + def read_hex_page(file_state, page_addr, page_size, page_buffer): """ Helper function that does the Intel Hex parsing. Takes in a dictionary @@ -391,84 +400,91 @@ def read_hex_page(file_state, page_addr, page_size, page_buffer): we've done the best job we can with filling the buffer and the next line does not contain any more data we can use. """ - while True: # read until our page_buff is full! - orig_loc = file_state['f'].tell() # in case we have to 'back up' - line = file_state['f'].readline() # read one line from the HEX file - file_state['line'] += 1 + while True: # read until our page_buff is full! + orig_loc = file_state["f"].tell() # in case we have to 'back up' + line = file_state["f"].readline() # read one line from the HEX file + file_state["line"] += 1 if not line: - file_state['eof'] = True + file_state["eof"] = True return False - #print(line) - if line[0] != ':': # lines must start with ':' - raise RuntimeError("HEX line %d doesn't start with :" % file_state['line']) + # print(line) + if line[0] != ":": # lines must start with ':' + raise RuntimeError("HEX line %d doesn't start with :" % file_state["line"]) # Try to parse the line length, address, and record type try: hex_len = int(line[1:3], 16) line_addr = int(line[3:7], 16) - file_state['line_addr'] = line_addr + file_state["line_addr"] = line_addr rec_type = int(line[7:9], 16) except ValueError: - raise RuntimeError("Could not parse HEX line %d addr" % file_state['line']) + raise RuntimeError("Could not parse HEX line %d addr" % file_state["line"]) - if file_state['ext_addr']: - line_addr += file_state['ext_addr'] - #print("Hex len: %d, addr %04X, record type %d " % (hex_len, line_addr, rec_type)) + if file_state["ext_addr"]: + line_addr += file_state["ext_addr"] + # print("Hex len: %d, addr %04X, record type %d " % (hex_len, line_addr, rec_type)) # We should only look for data type records (0x00) if rec_type == 1: - file_state['eof'] = True - return False # reached end of file + file_state["eof"] = True + return False # reached end of file if rec_type == 2: - file_state['ext_addr'] = int(line[9:13], 16) << 4 - #print("Extended addr: %05X" % file_state['ext_addr']) + file_state["ext_addr"] = int(line[9:13], 16) << 4 + # print("Extended addr: %05X" % file_state['ext_addr']) continue if rec_type == 3: # sometimes appears, we ignore this continue - elif rec_type != 0: # if not the above or a data record... - raise RuntimeError("Unsupported record type %d on line %d" % - (rec_type, file_state['line'])) + if rec_type != 0: # if not the above or a data record... + raise RuntimeError( + "Unsupported record type %d on line %d" % (rec_type, file_state["line"]) + ) # check if this file file is either after the current page # (in which case, we've read all we can for this page and should # commence flasing...) if line_addr >= (page_addr + page_size): - #print("Hex is past page address range") - file_state['f'].seek(orig_loc) # back up! - file_state['line'] -= 1 + # print("Hex is past page address range") + file_state["f"].seek(orig_loc) # back up! + file_state["line"] -= 1 return True # or, this line does not yet reach the current page address, in which # case which should just keep reading in hopes we reach the address # we're looking for next time! if (line_addr + hex_len) <= page_addr: - #print("Hex is prior to page address range") + # print("Hex is prior to page address range") continue # parse out all remaining hex bytes including the checksum byte_buffer = [] for i in range(hex_len + 1): - byte_buffer.append(int(line[9+i*2:11+i*2], 16)) + byte_buffer.append(int(line[9 + i * 2 : 11 + i * 2], 16)) # check chksum now! - chksum = hex_len + (line_addr >> 8) + (line_addr & 0xFF) + rec_type + sum(byte_buffer) - #print("checksum: "+hex(chksum)) + chksum = ( + hex_len + + (line_addr >> 8) + + (line_addr & 0xFF) + + rec_type + + sum(byte_buffer) + ) + # print("checksum: "+hex(chksum)) if (chksum & 0xFF) != 0: raise RuntimeError("HEX Checksum fail") # get rid of that checksum byte byte_buffer.pop() - #print([hex(i) for i in byte_buffer]) + # print([hex(i) for i in byte_buffer]) - #print("line addr $%04X page addr $%04X" % (line_addr, page_addr)) + # print("line addr $%04X page addr $%04X" % (line_addr, page_addr)) page_idx = line_addr - page_addr line_idx = 0 while (page_idx < page_size) and (line_idx < hex_len): - #print("page_idx = %d, line_idx = %d" % (page_idx, line_idx)) + # print("page_idx = %d, line_idx = %d" % (page_idx, line_idx)) page_buffer[page_idx] = byte_buffer[line_idx] line_idx += 1 page_idx += 1 if page_idx == page_size: - return True # ok we've read a full page, can bail now! + return True # ok we've read a full page, can bail now! - return False # we...shouldn't get here? + return False # we...shouldn't get here? diff --git a/docs/conf.py b/docs/conf.py index 71dc3c2..c93c167 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -2,7 +2,8 @@ import os import sys -sys.path.insert(0, os.path.abspath('..')) + +sys.path.insert(0, os.path.abspath("..")) # -- General configuration ------------------------------------------------ @@ -10,9 +11,9 @@ # extensions coming with Sphinx (named 'sphinx.ext.*') or your custom # ones. extensions = [ - 'sphinx.ext.autodoc', - 'sphinx.ext.intersphinx', - 'sphinx.ext.viewcode', + "sphinx.ext.autodoc", + "sphinx.ext.intersphinx", + "sphinx.ext.viewcode", ] # Uncomment the below if you use native CircuitPython modules such as @@ -20,29 +21,32 @@ # autodoc module docs will fail to generate with a warning. # autodoc_mock_imports = ["digitalio"] -intersphinx_mapping = {'python': ('https://docs.python.org/3.4', None),'CircuitPython': ('https://circuitpython.readthedocs.io/en/latest/', None)} +intersphinx_mapping = { + "python": ("https://docs.python.org/3.4", None), + "CircuitPython": ("https://circuitpython.readthedocs.io/en/latest/", None), +} # Add any paths that contain templates here, relative to this directory. -templates_path = ['_templates'] +templates_path = ["_templates"] -source_suffix = '.rst' +source_suffix = ".rst" # The master toctree document. -master_doc = 'index' +master_doc = "index" # General information about the project. -project = u'Adafruit AVRprog Library' -copyright = u'2017 ladyada' -author = u'ladyada' +project = u"Adafruit AVRprog Library" +copyright = u"2017 ladyada" +author = u"ladyada" # The version info for the project you're documenting, acts as replacement for # |version| and |release|, also used in various other places throughout the # built documents. # # The short X.Y version. -version = u'1.0' +version = u"1.0" # The full version, including alpha/beta/rc tags. -release = u'1.0' +release = u"1.0" # The language for content autogenerated by Sphinx. Refer to documentation # for a list of supported languages. @@ -54,7 +58,7 @@ # List of patterns, relative to source directory, that match files and # directories to ignore when looking for source files. # This patterns also effect to html_static_path and html_extra_path -exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store', '.env', 'CODE_OF_CONDUCT.md'] +exclude_patterns = ["_build", "Thumbs.db", ".DS_Store", ".env", "CODE_OF_CONDUCT.md"] # The reST default role (used for this markup: `text`) to use for all # documents. @@ -66,7 +70,7 @@ add_function_parentheses = True # The name of the Pygments (syntax highlighting) style to use. -pygments_style = 'sphinx' +pygments_style = "sphinx" # If true, `todo` and `todoList` produce output, else they produce nothing. todo_include_todos = False @@ -80,59 +84,62 @@ # The theme to use for HTML and HTML Help pages. See the documentation for # a list of builtin themes. # -on_rtd = os.environ.get('READTHEDOCS', None) == 'True' +on_rtd = os.environ.get("READTHEDOCS", None) == "True" if not on_rtd: # only import and set the theme if we're building docs locally try: import sphinx_rtd_theme - html_theme = 'sphinx_rtd_theme' - html_theme_path = [sphinx_rtd_theme.get_html_theme_path(), '.'] + + html_theme = "sphinx_rtd_theme" + html_theme_path = [sphinx_rtd_theme.get_html_theme_path(), "."] except: - html_theme = 'default' - html_theme_path = ['.'] + html_theme = "default" + html_theme_path = ["."] else: - html_theme_path = ['.'] + html_theme_path = ["."] # Add any paths that contain custom static files (such as style sheets) here, # relative to this directory. They are copied after the builtin static files, # so a file named "default.css" will overwrite the builtin "default.css". -html_static_path = ['_static'] +html_static_path = ["_static"] # The name of an image file (relative to this directory) to use as a favicon of # the docs. This file should be a Windows icon file (.ico) being 16x16 or 32x32 # pixels large. # -html_favicon = '_static/favicon.ico' +html_favicon = "_static/favicon.ico" # Output file base name for HTML help builder. -htmlhelp_basename = 'AdafruitAvrprogLibrarydoc' +htmlhelp_basename = "AdafruitAvrprogLibrarydoc" # -- Options for LaTeX output --------------------------------------------- latex_elements = { - # The paper size ('letterpaper' or 'a4paper'). - # - # 'papersize': 'letterpaper', - - # The font size ('10pt', '11pt' or '12pt'). - # - # 'pointsize': '10pt', - - # Additional stuff for the LaTeX preamble. - # - # 'preamble': '', - - # Latex figure (float) alignment - # - # 'figure_align': 'htbp', + # The paper size ('letterpaper' or 'a4paper'). + # + # 'papersize': 'letterpaper', + # The font size ('10pt', '11pt' or '12pt'). + # + # 'pointsize': '10pt', + # Additional stuff for the LaTeX preamble. + # + # 'preamble': '', + # Latex figure (float) alignment + # + # 'figure_align': 'htbp', } # Grouping the document tree into LaTeX files. List of tuples # (source start file, target name, title, # author, documentclass [howto, manual, or own class]). latex_documents = [ - (master_doc, 'AdafruitAVRprogLibrary.tex', u'AdafruitAVRprog Library Documentation', - author, 'manual'), + ( + master_doc, + "AdafruitAVRprogLibrary.tex", + u"AdafruitAVRprog Library Documentation", + author, + "manual", + ), ] # -- Options for manual page output --------------------------------------- @@ -140,8 +147,13 @@ # One entry per manual page. List of tuples # (source start file, name, description, authors, manual section). man_pages = [ - (master_doc, 'AdafruitAVRproglibrary', u'Adafruit AVRprog Library Documentation', - [author], 1) + ( + master_doc, + "AdafruitAVRproglibrary", + u"Adafruit AVRprog Library Documentation", + [author], + 1, + ) ] # -- Options for Texinfo output ------------------------------------------- @@ -150,7 +162,13 @@ # (source start file, target name, title, author, # dir menu entry, description, category) texinfo_documents = [ - (master_doc, 'AdafruitAVRprogLibrary', u'Adafruit AVRprog Library Documentation', - author, 'AdafruitAVRprogLibrary', 'One line description of project.', - 'Miscellaneous'), + ( + master_doc, + "AdafruitAVRprogLibrary", + u"Adafruit AVRprog Library Documentation", + author, + "AdafruitAVRprogLibrary", + "One line description of project.", + "Miscellaneous", + ), ] diff --git a/examples/avrprog_program_mega2560.py b/examples/avrprog_program_mega2560.py index 2b83736..8a06749 100644 --- a/examples/avrprog_program_mega2560.py +++ b/examples/avrprog_program_mega2560.py @@ -23,36 +23,43 @@ # http://svn.savannah.nongnu.org/viewvc/*checkout*/avrdude/trunk/avrdude/avrdude.conf.in # You can also use the predefined values in AVRprog.Boards atmega2560 = { - 'name': "ATmega2560", - 'sig': [0x1E, 0x98, 0x01], - 'flash_size': 262144, - 'page_size': 256, - 'fuse_mask': (0xFF, 0xFF, 0x07, 0x3F) + "name": "ATmega2560", + "sig": [0x1E, 0x98, 0x01], + "flash_size": 262144, + "page_size": 256, + "fuse_mask": (0xFF, 0xFF, 0x07, 0x3F), } + def error(err): """ Helper to print out errors for us and then halt """ - print("ERROR: "+err) + print("ERROR: " + err) avrprog.end() while True: pass -while input("Ready to GO, type 'G' here to start> ") != 'G': + +while input("Ready to GO, type 'G' here to start> ") != "G": pass if not avrprog.verify_sig(atmega2560, verbose=True): error("Signature read failure") -print("Found", atmega2560['name']) +print("Found", atmega2560["name"]) # Since we are unsetting the lock fuse, an erase is required! avrprog.erase_chip() avrprog.write_fuses(atmega2560, low=0xFF, high=0xD8, ext=0x05, lock=0x3F) if not avrprog.verify_fuses(atmega2560, low=0xFF, high=0xD8, ext=0x05, lock=0x3F): - error("Failure programming fuses: "+str([hex(i) for i in avrprog.read_fuses(atmega2560)])) + error( + "Failure programming fuses: " + + str([hex(i) for i in avrprog.read_fuses(atmega2560)]) + ) print("Programming flash from file") -avrprog.program_file(atmega2560, "stk500boot_v2_mega2560.hex", verbose=True, verify=True) +avrprog.program_file( + atmega2560, "stk500boot_v2_mega2560.hex", verbose=True, verify=True +) avrprog.write_fuses(atmega2560, lock=0x0F) if not avrprog.verify_fuses(atmega2560, lock=0x0F): diff --git a/examples/avrprog_program_tiny13a.py b/examples/avrprog_program_tiny13a.py index d8e90d5..59251ba 100644 --- a/examples/avrprog_program_tiny13a.py +++ b/examples/avrprog_program_tiny13a.py @@ -20,19 +20,21 @@ # Each chip has to have a definition so the script knows how to find it attiny13 = avrprog.Boards.ATtiny13a + def error(err): """ Helper to print out errors for us and then halt """ - print("ERROR: "+err) + print("ERROR: " + err) avrprog.end() while True: pass -while input("Ready to GO, type 'G' here to start> ") != 'G': + +while input("Ready to GO, type 'G' here to start> ") != "G": pass if not avrprog.verify_sig(attiny13, verbose=True): error("Signature read failure") -print("Found", attiny13['name']) +print("Found", attiny13["name"]) avrprog.write_fuses(attiny13, low=0x7A, high=0xFF) if not avrprog.verify_fuses(attiny13, low=0x7A, high=0xFF): diff --git a/examples/avrprog_program_trinket85.py b/examples/avrprog_program_trinket85.py index 693b9bd..fafe828 100644 --- a/examples/avrprog_program_trinket85.py +++ b/examples/avrprog_program_trinket85.py @@ -20,19 +20,21 @@ # Each chip has to have a definition so the script knows how to find it attiny85 = avrprog.Boards.ATtiny85 + def error(err): """ Helper to print out errors for us and then halt """ - print("ERROR: "+err) + print("ERROR: " + err) avrprog.end() while True: pass -while input("Ready to GO, type 'G' here to start> ") != 'G': + +while input("Ready to GO, type 'G' here to start> ") != "G": pass if not avrprog.verify_sig(attiny85, verbose=True): error("Signature read failure") -print("Found", attiny85['name']) +print("Found", attiny85["name"]) avrprog.write_fuses(attiny85, low=0xF1, high=0xD5, ext=0x06, lock=0x3F) if not avrprog.verify_fuses(attiny85, low=0xF1, high=0xD5, ext=0x06, lock=0x3F): diff --git a/examples/avrprog_program_uno328.py b/examples/avrprog_program_uno328.py index f939519..2a0d5ac 100644 --- a/examples/avrprog_program_uno328.py +++ b/examples/avrprog_program_uno328.py @@ -18,34 +18,39 @@ avrprog = adafruit_avrprog.AVRprog() avrprog.init(spi, board.D5) -#pylint: disable-msg=no-member +# pylint: disable-msg=no-member # we can generate an 6 MHz clock for driving bare chips too! -clock_pwm = pulseio.PWMOut(board.D9, frequency=6000000, duty_cycle=65536//2) -#pylint: enable-msg=no-member +clock_pwm = pulseio.PWMOut(board.D9, frequency=6000000, duty_cycle=65536 // 2) +# pylint: enable-msg=no-member # Each chip has to have a definition so the script knows how to find it atmega328p = avrprog.Boards.ATmega328p + def error(err): """ Helper to print out errors for us and then halt """ - print("ERROR: "+err) + print("ERROR: " + err) avrprog.end() while True: pass -while input("Ready to GO, type 'G' here to start> ") != 'G': + +while input("Ready to GO, type 'G' here to start> ") != "G": pass if not avrprog.verify_sig(atmega328p, verbose=True): error("Signature read failure") -print("Found", atmega328p['name']) +print("Found", atmega328p["name"]) # Since we are unsetting the lock fuse, an erase is required! avrprog.erase_chip() avrprog.write_fuses(atmega328p, low=0xFF, high=0xDE, ext=0x05, lock=0x3F) if not avrprog.verify_fuses(atmega328p, low=0xFF, high=0xDE, ext=0x05, lock=0x3F): - error("Failure programming fuses: "+str([hex(i) for i in avrprog.read_fuses(atmega328p)])) + error( + "Failure programming fuses: " + + str([hex(i) for i in avrprog.read_fuses(atmega328p)]) + ) print("Programming flash from file") avrprog.program_file(atmega328p, "optiboot_atmega328.hex", verbose=True, verify=True) diff --git a/examples/avrprog_read_signature_simpletest.py b/examples/avrprog_read_signature_simpletest.py index 0160261..a919929 100644 --- a/examples/avrprog_read_signature_simpletest.py +++ b/examples/avrprog_read_signature_simpletest.py @@ -12,10 +12,10 @@ avrprog = adafruit_avrprog.AVRprog() avrprog.init(spi, board.D5) -#pylint: disable-msg=no-member +# pylint: disable-msg=no-member # we can generate an 6 MHz clock for driving bare chips too! -clock_pwm = pulseio.PWMOut(board.D9, frequency=6000000, duty_cycle=65536//2) -#pylint: enable-msg=no-member +clock_pwm = pulseio.PWMOut(board.D9, frequency=6000000, duty_cycle=65536 // 2) +# pylint: enable-msg=no-member avrprog.begin() print("Signature bytes: ", [hex(i) for i in avrprog.read_signature()]) diff --git a/setup.py b/setup.py index 7248a9d..5208ba9 100644 --- a/setup.py +++ b/setup.py @@ -7,6 +7,7 @@ # Always prefer setuptools over distutils from setuptools import setup, find_packages + # To use a consistent encoding from codecs import open from os import path @@ -14,47 +15,38 @@ here = path.abspath(path.dirname(__file__)) # Get the long description from the README file -with open(path.join(here, 'README.rst'), encoding='utf-8') as f: +with open(path.join(here, "README.rst"), encoding="utf-8") as f: long_description = f.read() setup( - name='adafruit-circuitpython-avrprog', - + name="adafruit-circuitpython-avrprog", use_scm_version=True, - setup_requires=['setuptools_scm'], - - description='CircuitPython helper library for programming AVR chips.', + setup_requires=["setuptools_scm"], + description="CircuitPython helper library for programming AVR chips.", long_description=long_description, - long_description_content_type='text/x-rst', - + long_description_content_type="text/x-rst", # The project's main homepage. - url='https://github.com/adafruit/Adafruit_CircuitPython_AVRprog', - + url="https://github.com/adafruit/Adafruit_CircuitPython_AVRprog", # Author details - author='Adafruit Industries', - author_email='circuitpython@adafruit.com', - - install_requires=['Adafruit-Blinka'], - + author="Adafruit Industries", + author_email="circuitpython@adafruit.com", + install_requires=["Adafruit-Blinka"], # Choose your license - license='MIT', - + license="MIT", # See https://pypi.python.org/pypi?%3Aaction=list_classifiers classifiers=[ - 'Development Status :: 3 - Alpha', - 'Intended Audience :: Developers', - 'Topic :: Software Development :: Libraries', - 'Topic :: System :: Hardware', - 'License :: OSI Approved :: MIT License', - 'Programming Language :: Python :: 3', - 'Programming Language :: Python :: 3.4', - 'Programming Language :: Python :: 3.5', + "Development Status :: 3 - Alpha", + "Intended Audience :: Developers", + "Topic :: Software Development :: Libraries", + "Topic :: System :: Hardware", + "License :: OSI Approved :: MIT License", + "Programming Language :: Python :: 3", + "Programming Language :: Python :: 3.4", + "Programming Language :: Python :: 3.5", ], - # What does your project relate to? - keywords='adafruit avr spi atmega attiny hardware micropython circuitpython', - + keywords="adafruit avr spi atmega attiny hardware micropython circuitpython", # You can just specify the packages manually here if your project is # simple. Or you can use find_packages(). - py_modules=['adafruit_avrprog'], + py_modules=["adafruit_avrprog"], )