Merge pull request #17 from adafruit/pylint-update

Ran black, updated to pylint 2.x
This commit is contained in:
Kattni 2020-03-17 12:15:37 -04:00 committed by GitHub
commit 485ca0bf23
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 239 additions and 197 deletions

View file

@ -40,7 +40,7 @@ jobs:
source actions-ci/install.sh source actions-ci/install.sh
- name: Pip install pylint, black, & Sphinx - name: Pip install pylint, black, & Sphinx
run: | 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 - name: Library version
run: git describe --dirty --always --tags run: git describe --dirty --always --tags
- name: PyLint - name: PyLint

View file

@ -54,43 +54,46 @@ from digitalio import Direction, DigitalInOut
_SLOW_CLOCK = 100000 _SLOW_CLOCK = 100000
_FAST_CLOCK = 1000000 _FAST_CLOCK = 1000000
class AVRprog: class AVRprog:
""" """
Helper class used to program AVR chips from CircuitPython. Helper class used to program AVR chips from CircuitPython.
""" """
class Boards: class Boards:
""" """
Some well known board definitions. Some well known board definitions.
""" """
# pylint: disable=too-few-public-methods # pylint: disable=too-few-public-methods
ATtiny13a = { ATtiny13a = {
'name': "ATtiny13a", "name": "ATtiny13a",
'sig': [0x1E, 0x90, 0x07], "sig": [0x1E, 0x90, 0x07],
'flash_size': 1024, "flash_size": 1024,
'page_size': 32, "page_size": 32,
'fuse_mask': (0xFF, 0xFF, 0x00, 0x03), "fuse_mask": (0xFF, 0xFF, 0x00, 0x03),
'clock_speed': 100000 "clock_speed": 100000,
} }
ATtiny85 = { ATtiny85 = {
'name': "ATtiny85", "name": "ATtiny85",
'sig': [0x1E, 0x93, 0x0B], "sig": [0x1E, 0x93, 0x0B],
'flash_size': 8192, "flash_size": 8192,
'page_size': 64, "page_size": 64,
'fuse_mask': (0xFF, 0xFF, 0x07, 0x3F) "fuse_mask": (0xFF, 0xFF, 0x07, 0x3F),
} }
ATmega328p = { ATmega328p = {
'name': "ATmega328p", "name": "ATmega328p",
'sig': [0x1E, 0x95, 0x0F], "sig": [0x1E, 0x95, 0x0F],
'flash_size': 32768, "flash_size": 32768,
'page_size': 128, "page_size": 128,
'fuse_mask': (0xFF, 0xFF, 0x07, 0x3F), "fuse_mask": (0xFF, 0xFF, 0x07, 0x3F),
} }
ATmega2560 = { ATmega2560 = {
'name': "ATmega2560", "name": "ATmega2560",
'sig': [0x1E, 0x98, 0x01], "sig": [0x1E, 0x98, 0x01],
'flash_size': 262144, "flash_size": 262144,
'page_size': 256, "page_size": 256,
'fuse_mask': (0xFF, 0xFF, 0x07, 0x3F) "fuse_mask": (0xFF, 0xFF, 0x07, 0x3F),
} }
_spi = None _spi = None
@ -107,7 +110,6 @@ class AVRprog:
self._rst.direction = Direction.OUTPUT self._rst.direction = Direction.OUTPUT
self._rst.value = True self._rst.value = True
def verify_sig(self, chip, verbose=False): def verify_sig(self, chip, verbose=False):
""" """
Verify that the chip is connected properly, responds to commands, Verify that the chip is connected properly, responds to commands,
@ -118,7 +120,7 @@ class AVRprog:
self.end() self.end()
if verbose: if verbose:
print("Found signature: %s" % [hex(i) for i in sig]) print("Found signature: %s" % [hex(i) for i in sig])
if sig != chip['sig']: if sig != chip["sig"]:
return False return False
return True return True
@ -135,16 +137,16 @@ class AVRprog:
print("Erasing chip....") print("Erasing chip....")
self.erase_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) self.begin(clock=clock_speed)
# create a file state dictionary # create a file state dictionary
file_state = {'line': 0, 'ext_addr': 0, 'eof': False} file_state = {"line": 0, "ext_addr": 0, "eof": False}
file_state['f'] = open(file_name, 'r') 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: if verbose:
print("Programming page $%04X..." % page_addr, end="") print("Programming page $%04X..." % page_addr, end="")
page_buffer = bytearray(page_size) page_buffer = bytearray(page_size)
@ -175,15 +177,18 @@ class AVRprog:
if page_buffer != read_buffer: if page_buffer != read_buffer:
if verbose: if verbose:
# pylint: disable=line-too-long # 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 # pylint: enable=line-too-long
self.end() self.end()
return False return False
if file_state['eof']: if file_state["eof"]:
break # we're done, bail! break # we're done, bail!
file_state['f'].close() file_state["f"].close()
self.end() self.end()
return True return True
@ -196,13 +201,13 @@ class AVRprog:
raise RuntimeError("Signature read failure") raise RuntimeError("Signature read failure")
# create a file state dictionary # create a file state dictionary
file_state = {'line': 0, 'ext_addr': 0, 'eof': False} file_state = {"line": 0, "ext_addr": 0, "eof": False}
file_state['f'] = open(file_name, 'r') file_state["f"] = open(file_name, "r")
page_size = chip['page_size'] page_size = chip["page_size"]
clock_speed = getattr(chip, 'clock_speed', _FAST_CLOCK) clock_speed = getattr(chip, "clock_speed", _FAST_CLOCK)
self.begin(clock=clock_speed) 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) page_buffer = bytearray(page_size)
for b in range(page_size): for b in range(page_size):
page_buffer[b] = 0xFF # make an empty page page_buffer[b] = 0xFF # make an empty page
@ -219,15 +224,18 @@ class AVRprog:
if page_buffer != read_buffer: if page_buffer != read_buffer:
if verbose: if verbose:
# pylint: disable=line-too-long # 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 # pylint: enable=line-too-long
self.end() self.end()
return False return False
if file_state['eof']: if file_state["eof"]:
break # we're done, bail! break # we're done, bail!
file_state['f'].close() file_state["f"].close()
self.end() self.end()
return True return True
@ -236,7 +244,7 @@ class AVRprog:
Read the 4 fuses and return them in a list (low, high, ext, lock) 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 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) self.begin(clock=_SLOW_CLOCK)
low = self._transaction((0x50, 0, 0, 0))[2] & mask[0] low = self._transaction((0x50, 0, 0, 0))[2] & mask[0]
high = self._transaction((0x58, 0x08, 0, 0))[2] & mask[1] high = self._transaction((0x58, 0x08, 0, 0))[2] & mask[1]
@ -257,6 +265,7 @@ class AVRprog:
high and self._transaction((0xAC, 0xA8, 0, high)) 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() self.end()
# pylint: enable=unused-argument,expression-not-assigned # pylint: enable=unused-argument,expression-not-assigned
def verify_fuses(self, chip, low=None, high=None, ext=None, lock=None): def verify_fuses(self, chip, low=None, high=None, ext=None, lock=None):
@ -274,7 +283,6 @@ class AVRprog:
return False return False
return True return True
def erase_chip(self): def erase_chip(self):
""" """
Fully erases the chip. Fully erases the chip.
@ -372,6 +380,7 @@ class AVRprog:
while self._transaction((0xF0, 0, 0, 0))[2] & 0x01: while self._transaction((0xF0, 0, 0, 0))[2] & 0x01:
pass pass
def read_hex_page(file_state, page_addr, page_size, page_buffer): def read_hex_page(file_state, page_addr, page_size, page_buffer):
""" """
Helper function that does the Intel Hex parsing. Takes in a dictionary Helper function that does the Intel Hex parsing. Takes in a dictionary
@ -392,51 +401,52 @@ def read_hex_page(file_state, page_addr, page_size, page_buffer):
line does not contain any more data we can use. line does not contain any more data we can use.
""" """
while True: # read until our page_buff is full! while True: # read until our page_buff is full!
orig_loc = file_state['f'].tell() # in case we have to 'back up' 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 line = file_state["f"].readline() # read one line from the HEX file
file_state['line'] += 1 file_state["line"] += 1
if not line: if not line:
file_state['eof'] = True file_state["eof"] = True
return False return False
# print(line) # print(line)
if line[0] != ':': # lines must start with ':' if line[0] != ":": # lines must start with ':'
raise RuntimeError("HEX line %d doesn't start with :" % file_state['line']) raise RuntimeError("HEX line %d doesn't start with :" % file_state["line"])
# Try to parse the line length, address, and record type # Try to parse the line length, address, and record type
try: try:
hex_len = int(line[1:3], 16) hex_len = int(line[1:3], 16)
line_addr = int(line[3:7], 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) rec_type = int(line[7:9], 16)
except ValueError: 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']: if file_state["ext_addr"]:
line_addr += 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)) # print("Hex len: %d, addr %04X, record type %d " % (hex_len, line_addr, rec_type))
# We should only look for data type records (0x00) # We should only look for data type records (0x00)
if rec_type == 1: if rec_type == 1:
file_state['eof'] = True file_state["eof"] = True
return False # reached end of file return False # reached end of file
if rec_type == 2: if rec_type == 2:
file_state['ext_addr'] = int(line[9:13], 16) << 4 file_state["ext_addr"] = int(line[9:13], 16) << 4
# print("Extended addr: %05X" % file_state['ext_addr']) # print("Extended addr: %05X" % file_state['ext_addr'])
continue continue
if rec_type == 3: # sometimes appears, we ignore this if rec_type == 3: # sometimes appears, we ignore this
continue continue
elif rec_type != 0: # if not the above or a data record... if rec_type != 0: # if not the above or a data record...
raise RuntimeError("Unsupported record type %d on line %d" % raise RuntimeError(
(rec_type, file_state['line'])) "Unsupported record type %d on line %d" % (rec_type, file_state["line"])
)
# check if this file file is either after the current page # 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 # (in which case, we've read all we can for this page and should
# commence flasing...) # commence flasing...)
if line_addr >= (page_addr + page_size): if line_addr >= (page_addr + page_size):
# print("Hex is past page address range") # print("Hex is past page address range")
file_state['f'].seek(orig_loc) # back up! file_state["f"].seek(orig_loc) # back up!
file_state['line'] -= 1 file_state["line"] -= 1
return True return True
# or, this line does not yet reach the current page address, in which # 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 # case which should just keep reading in hopes we reach the address
@ -451,7 +461,13 @@ def read_hex_page(file_state, page_addr, page_size, page_buffer):
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! # check chksum now!
chksum = hex_len + (line_addr >> 8) + (line_addr & 0xFF) + rec_type + sum(byte_buffer) chksum = (
hex_len
+ (line_addr >> 8)
+ (line_addr & 0xFF)
+ rec_type
+ sum(byte_buffer)
)
# print("checksum: "+hex(chksum)) # print("checksum: "+hex(chksum))
if (chksum & 0xFF) != 0: if (chksum & 0xFF) != 0:
raise RuntimeError("HEX Checksum fail") raise RuntimeError("HEX Checksum fail")

View file

@ -2,7 +2,8 @@
import os import os
import sys import sys
sys.path.insert(0, os.path.abspath('..'))
sys.path.insert(0, os.path.abspath(".."))
# -- General configuration ------------------------------------------------ # -- General configuration ------------------------------------------------
@ -10,9 +11,9 @@ sys.path.insert(0, os.path.abspath('..'))
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom # extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
# ones. # ones.
extensions = [ extensions = [
'sphinx.ext.autodoc', "sphinx.ext.autodoc",
'sphinx.ext.intersphinx', "sphinx.ext.intersphinx",
'sphinx.ext.viewcode', "sphinx.ext.viewcode",
] ]
# Uncomment the below if you use native CircuitPython modules such as # Uncomment the below if you use native CircuitPython modules such as
@ -20,29 +21,32 @@ extensions = [
# autodoc module docs will fail to generate with a warning. # autodoc module docs will fail to generate with a warning.
# autodoc_mock_imports = ["digitalio"] # 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. # 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. # The master toctree document.
master_doc = 'index' master_doc = "index"
# General information about the project. # General information about the project.
project = u'Adafruit AVRprog Library' project = u"Adafruit AVRprog Library"
copyright = u'2017 ladyada' copyright = u"2017 ladyada"
author = u'ladyada' author = u"ladyada"
# The version info for the project you're documenting, acts as replacement for # The version info for the project you're documenting, acts as replacement for
# |version| and |release|, also used in various other places throughout the # |version| and |release|, also used in various other places throughout the
# built documents. # built documents.
# #
# The short X.Y version. # The short X.Y version.
version = u'1.0' version = u"1.0"
# The full version, including alpha/beta/rc tags. # 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 # The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages. # for a list of supported languages.
@ -54,7 +58,7 @@ language = None
# List of patterns, relative to source directory, that match files and # List of patterns, relative to source directory, that match files and
# directories to ignore when looking for source files. # directories to ignore when looking for source files.
# This patterns also effect to html_static_path and html_extra_path # 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 # The reST default role (used for this markup: `text`) to use for all
# documents. # documents.
@ -66,7 +70,7 @@ default_role = "any"
add_function_parentheses = True add_function_parentheses = True
# The name of the Pygments (syntax highlighting) style to use. # 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. # If true, `todo` and `todoList` produce output, else they produce nothing.
todo_include_todos = False todo_include_todos = False
@ -80,32 +84,33 @@ todo_emit_warnings = True
# The theme to use for HTML and HTML Help pages. See the documentation for # The theme to use for HTML and HTML Help pages. See the documentation for
# a list of builtin themes. # 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 if not on_rtd: # only import and set the theme if we're building docs locally
try: try:
import sphinx_rtd_theme 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: except:
html_theme = 'default' html_theme = "default"
html_theme_path = ['.'] html_theme_path = ["."]
else: else:
html_theme_path = ['.'] html_theme_path = ["."]
# Add any paths that contain custom static files (such as style sheets) here, # 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, # relative to this directory. They are copied after the builtin static files,
# so a file named "default.css" will overwrite the builtin "default.css". # 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 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 # the docs. This file should be a Windows icon file (.ico) being 16x16 or 32x32
# pixels large. # pixels large.
# #
html_favicon = '_static/favicon.ico' html_favicon = "_static/favicon.ico"
# Output file base name for HTML help builder. # Output file base name for HTML help builder.
htmlhelp_basename = 'AdafruitAvrprogLibrarydoc' htmlhelp_basename = "AdafruitAvrprogLibrarydoc"
# -- Options for LaTeX output --------------------------------------------- # -- Options for LaTeX output ---------------------------------------------
@ -113,15 +118,12 @@ latex_elements = {
# The paper size ('letterpaper' or 'a4paper'). # The paper size ('letterpaper' or 'a4paper').
# #
# 'papersize': 'letterpaper', # 'papersize': 'letterpaper',
# The font size ('10pt', '11pt' or '12pt'). # The font size ('10pt', '11pt' or '12pt').
# #
# 'pointsize': '10pt', # 'pointsize': '10pt',
# Additional stuff for the LaTeX preamble. # Additional stuff for the LaTeX preamble.
# #
# 'preamble': '', # 'preamble': '',
# Latex figure (float) alignment # Latex figure (float) alignment
# #
# 'figure_align': 'htbp', # 'figure_align': 'htbp',
@ -131,8 +133,13 @@ latex_elements = {
# (source start file, target name, title, # (source start file, target name, title,
# author, documentclass [howto, manual, or own class]). # author, documentclass [howto, manual, or own class]).
latex_documents = [ 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 --------------------------------------- # -- Options for manual page output ---------------------------------------
@ -140,8 +147,13 @@ latex_documents = [
# One entry per manual page. List of tuples # One entry per manual page. List of tuples
# (source start file, name, description, authors, manual section). # (source start file, name, description, authors, manual section).
man_pages = [ 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 ------------------------------------------- # -- Options for Texinfo output -------------------------------------------
@ -150,7 +162,13 @@ man_pages = [
# (source start file, target name, title, author, # (source start file, target name, title, author,
# dir menu entry, description, category) # dir menu entry, description, category)
texinfo_documents = [ texinfo_documents = [
(master_doc, 'AdafruitAVRprogLibrary', u'Adafruit AVRprog Library Documentation', (
author, 'AdafruitAVRprogLibrary', 'One line description of project.', master_doc,
'Miscellaneous'), "AdafruitAVRprogLibrary",
u"Adafruit AVRprog Library Documentation",
author,
"AdafruitAVRprogLibrary",
"One line description of project.",
"Miscellaneous",
),
] ]

View file

@ -23,13 +23,14 @@ avrprog.init(spi, board.D5)
# http://svn.savannah.nongnu.org/viewvc/*checkout*/avrdude/trunk/avrdude/avrdude.conf.in # http://svn.savannah.nongnu.org/viewvc/*checkout*/avrdude/trunk/avrdude/avrdude.conf.in
# You can also use the predefined values in AVRprog.Boards # You can also use the predefined values in AVRprog.Boards
atmega2560 = { atmega2560 = {
'name': "ATmega2560", "name": "ATmega2560",
'sig': [0x1E, 0x98, 0x01], "sig": [0x1E, 0x98, 0x01],
'flash_size': 262144, "flash_size": 262144,
'page_size': 256, "page_size": 256,
'fuse_mask': (0xFF, 0xFF, 0x07, 0x3F) "fuse_mask": (0xFF, 0xFF, 0x07, 0x3F),
} }
def error(err): def error(err):
""" Helper to print out errors for us and then halt """ """ Helper to print out errors for us and then halt """
print("ERROR: " + err) print("ERROR: " + err)
@ -37,22 +38,28 @@ def error(err):
while True: while True:
pass pass
while input("Ready to GO, type 'G' here to start> ") != 'G':
while input("Ready to GO, type 'G' here to start> ") != "G":
pass pass
if not avrprog.verify_sig(atmega2560, verbose=True): if not avrprog.verify_sig(atmega2560, verbose=True):
error("Signature read failure") error("Signature read failure")
print("Found", atmega2560['name']) print("Found", atmega2560["name"])
# Since we are unsetting the lock fuse, an erase is required! # Since we are unsetting the lock fuse, an erase is required!
avrprog.erase_chip() avrprog.erase_chip()
avrprog.write_fuses(atmega2560, low=0xFF, high=0xD8, ext=0x05, lock=0x3F) 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): 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") 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) avrprog.write_fuses(atmega2560, lock=0x0F)
if not avrprog.verify_fuses(atmega2560, lock=0x0F): if not avrprog.verify_fuses(atmega2560, lock=0x0F):

View file

@ -20,6 +20,7 @@ avrprog.init(spi, board.D5)
# Each chip has to have a definition so the script knows how to find it # Each chip has to have a definition so the script knows how to find it
attiny13 = avrprog.Boards.ATtiny13a attiny13 = avrprog.Boards.ATtiny13a
def error(err): def error(err):
""" Helper to print out errors for us and then halt """ """ Helper to print out errors for us and then halt """
print("ERROR: " + err) print("ERROR: " + err)
@ -27,12 +28,13 @@ def error(err):
while True: while True:
pass pass
while input("Ready to GO, type 'G' here to start> ") != 'G':
while input("Ready to GO, type 'G' here to start> ") != "G":
pass pass
if not avrprog.verify_sig(attiny13, verbose=True): if not avrprog.verify_sig(attiny13, verbose=True):
error("Signature read failure") error("Signature read failure")
print("Found", attiny13['name']) print("Found", attiny13["name"])
avrprog.write_fuses(attiny13, low=0x7A, high=0xFF) avrprog.write_fuses(attiny13, low=0x7A, high=0xFF)
if not avrprog.verify_fuses(attiny13, low=0x7A, high=0xFF): if not avrprog.verify_fuses(attiny13, low=0x7A, high=0xFF):

View file

@ -20,6 +20,7 @@ avrprog.init(spi, board.D5)
# Each chip has to have a definition so the script knows how to find it # Each chip has to have a definition so the script knows how to find it
attiny85 = avrprog.Boards.ATtiny85 attiny85 = avrprog.Boards.ATtiny85
def error(err): def error(err):
""" Helper to print out errors for us and then halt """ """ Helper to print out errors for us and then halt """
print("ERROR: " + err) print("ERROR: " + err)
@ -27,12 +28,13 @@ def error(err):
while True: while True:
pass pass
while input("Ready to GO, type 'G' here to start> ") != 'G':
while input("Ready to GO, type 'G' here to start> ") != "G":
pass pass
if not avrprog.verify_sig(attiny85, verbose=True): if not avrprog.verify_sig(attiny85, verbose=True):
error("Signature read failure") error("Signature read failure")
print("Found", attiny85['name']) print("Found", attiny85["name"])
avrprog.write_fuses(attiny85, low=0xF1, high=0xD5, ext=0x06, lock=0x3F) 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): if not avrprog.verify_fuses(attiny85, low=0xF1, high=0xD5, ext=0x06, lock=0x3F):

View file

@ -26,6 +26,7 @@ clock_pwm = pulseio.PWMOut(board.D9, frequency=6000000, duty_cycle=65536//2)
# Each chip has to have a definition so the script knows how to find it # Each chip has to have a definition so the script knows how to find it
atmega328p = avrprog.Boards.ATmega328p atmega328p = avrprog.Boards.ATmega328p
def error(err): def error(err):
""" Helper to print out errors for us and then halt """ """ Helper to print out errors for us and then halt """
print("ERROR: " + err) print("ERROR: " + err)
@ -33,19 +34,23 @@ def error(err):
while True: while True:
pass pass
while input("Ready to GO, type 'G' here to start> ") != 'G':
while input("Ready to GO, type 'G' here to start> ") != "G":
pass pass
if not avrprog.verify_sig(atmega328p, verbose=True): if not avrprog.verify_sig(atmega328p, verbose=True):
error("Signature read failure") error("Signature read failure")
print("Found", atmega328p['name']) print("Found", atmega328p["name"])
# Since we are unsetting the lock fuse, an erase is required! # Since we are unsetting the lock fuse, an erase is required!
avrprog.erase_chip() avrprog.erase_chip()
avrprog.write_fuses(atmega328p, low=0xFF, high=0xDE, ext=0x05, lock=0x3F) 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): 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") print("Programming flash from file")
avrprog.program_file(atmega328p, "optiboot_atmega328.hex", verbose=True, verify=True) avrprog.program_file(atmega328p, "optiboot_atmega328.hex", verbose=True, verify=True)

View file

@ -7,6 +7,7 @@ https://github.com/pypa/sampleproject
# Always prefer setuptools over distutils # Always prefer setuptools over distutils
from setuptools import setup, find_packages from setuptools import setup, find_packages
# To use a consistent encoding # To use a consistent encoding
from codecs import open from codecs import open
from os import path from os import path
@ -14,47 +15,38 @@ from os import path
here = path.abspath(path.dirname(__file__)) here = path.abspath(path.dirname(__file__))
# Get the long description from the README 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() long_description = f.read()
setup( setup(
name='adafruit-circuitpython-avrprog', name="adafruit-circuitpython-avrprog",
use_scm_version=True, use_scm_version=True,
setup_requires=['setuptools_scm'], setup_requires=["setuptools_scm"],
description="CircuitPython helper library for programming AVR chips.",
description='CircuitPython helper library for programming AVR chips.',
long_description=long_description, long_description=long_description,
long_description_content_type='text/x-rst', long_description_content_type="text/x-rst",
# The project's main homepage. # The project's main homepage.
url='https://github.com/adafruit/Adafruit_CircuitPython_AVRprog', url="https://github.com/adafruit/Adafruit_CircuitPython_AVRprog",
# Author details # Author details
author='Adafruit Industries', author="Adafruit Industries",
author_email='circuitpython@adafruit.com', author_email="circuitpython@adafruit.com",
install_requires=["Adafruit-Blinka"],
install_requires=['Adafruit-Blinka'],
# Choose your license # Choose your license
license='MIT', license="MIT",
# See https://pypi.python.org/pypi?%3Aaction=list_classifiers # See https://pypi.python.org/pypi?%3Aaction=list_classifiers
classifiers=[ classifiers=[
'Development Status :: 3 - Alpha', "Development Status :: 3 - Alpha",
'Intended Audience :: Developers', "Intended Audience :: Developers",
'Topic :: Software Development :: Libraries', "Topic :: Software Development :: Libraries",
'Topic :: System :: Hardware', "Topic :: System :: Hardware",
'License :: OSI Approved :: MIT License', "License :: OSI Approved :: MIT License",
'Programming Language :: Python :: 3', "Programming Language :: Python :: 3",
'Programming Language :: Python :: 3.4', "Programming Language :: Python :: 3.4",
'Programming Language :: Python :: 3.5', "Programming Language :: Python :: 3.5",
], ],
# What does your project relate to? # 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 # You can just specify the packages manually here if your project is
# simple. Or you can use find_packages(). # simple. Or you can use find_packages().
py_modules=['adafruit_avrprog'], py_modules=["adafruit_avrprog"],
) )