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,21 +137,21 @@ 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)
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
read_hex_page(file_state, page_addr, page_size, page_buffer) read_hex_page(file_state, page_addr, page_size, page_buffer)
@ -158,7 +160,7 @@ class AVRprog:
print("skipping") print("skipping")
continue continue
#print("From HEX file: ", page_buffer) # print("From HEX file: ", page_buffer)
self._flash_page(bytearray(page_buffer), page_addr, page_size) self._flash_page(bytearray(page_buffer), page_addr, page_size)
if not verify: if not verify:
@ -170,20 +172,23 @@ class AVRprog:
print("Verifying page @ $%04X" % page_addr) print("Verifying page @ $%04X" % page_addr)
read_buffer = bytearray(page_size) read_buffer = bytearray(page_size)
self.read(page_addr, read_buffer) self.read(page_addr, read_buffer)
#print("From memory: ", read_buffer) # print("From memory: ", read_buffer)
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,16 +201,16 @@ 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
read_hex_page(file_state, page_addr, page_size, page_buffer) read_hex_page(file_state, page_addr, page_size, page_buffer)
@ -213,21 +218,24 @@ class AVRprog:
print("Verifying page @ $%04X" % page_addr) print("Verifying page @ $%04X" % page_addr)
read_buffer = bytearray(page_size) read_buffer = bytearray(page_size)
self.read(page_addr, read_buffer) self.read(page_addr, read_buffer)
#print("From memory: ", read_buffer) # print("From memory: ", read_buffer)
#print("From file : ", page_buffer) # print("From file : ", page_buffer)
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]
@ -253,10 +261,11 @@ class AVRprog:
""" """
self.begin(clock=_SLOW_CLOCK) self.begin(clock=_SLOW_CLOCK)
lock and self._transaction((0xAC, 0xE0, 0, lock)) 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)) 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.
@ -323,18 +331,18 @@ class AVRprog:
Requires calling begin() beforehand to put in programming mode. Requires calling begin() beforehand to put in programming mode.
""" """
last_addr = 0 last_addr = 0
for i in range(len(read_buffer)//2): for i in range(len(read_buffer) // 2):
read_addr = addr//2 + i # read 'words' so address is half read_addr = addr // 2 + i # read 'words' so address is half
if (last_addr >> 16) != (read_addr >> 16): if (last_addr >> 16) != (read_addr >> 16):
# load extended byte # 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)) self._transaction((0x4D, 0, read_addr >> 16, 0))
high = self._transaction((0x28, read_addr >> 8, read_addr, 0))[2] high = self._transaction((0x28, read_addr >> 8, read_addr, 0))[2]
low = self._transaction((0x20, 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)) # print("%04X: %02X %02X" % (read_addr*2, low, high))
read_buffer[i*2] = low read_buffer[i * 2] = low
read_buffer[i*2+1] = high read_buffer[i * 2 + 1] = high
last_addr = read_addr last_addr = read_addr
@ -344,9 +352,9 @@ class AVRprog:
self._transaction((0x48, addr >> 8, addr, high)) self._transaction((0x48, addr >> 8, addr, high))
def _flash_page(self, page_buffer, page_addr, page_size): def _flash_page(self, page_buffer, page_addr, page_size):
page_addr //= 2 # address is by 'words' not bytes! page_addr //= 2 # address is by 'words' not bytes!
for i in range(page_size/2): # page indexed 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] lo_byte, hi_byte = page_buffer[2 * i : 2 * i + 2]
self._flash_word(i, lo_byte, hi_byte) self._flash_word(i, lo_byte, hi_byte)
# load extended byte # load extended byte
@ -362,16 +370,17 @@ class AVRprog:
command = bytearray([i & 0xFF for i in command]) command = bytearray([i & 0xFF for i in command])
self._spi.write_readinto(command, reply) self._spi.write_readinto(command, reply)
#s = [hex(i) for i in command] # s = [hex(i) for i in command]
#print("Sending %s reply %s" % ([hex(i) for i in command], [hex(i) for i in reply])) # print("Sending %s reply %s" % ([hex(i) for i in command], [hex(i) for i in reply]))
if reply[2] != command[1]: if reply[2] != command[1]:
raise RuntimeError("SPI transaction failed") raise RuntimeError("SPI transaction failed")
return reply[1:] # first byte is ignored return reply[1:] # first byte is ignored
def _busy_wait(self): def _busy_wait(self):
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
@ -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 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. 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
# we're looking for next time! # we're looking for next time!
if (line_addr + hex_len) <= page_addr: if (line_addr + hex_len) <= page_addr:
#print("Hex is prior to page address range") # print("Hex is prior to page address range")
continue continue
# parse out all remaining hex bytes including the checksum # parse out all remaining hex bytes including the checksum
byte_buffer = [] byte_buffer = []
for i in range(hex_len + 1): 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! # check chksum now!
chksum = hex_len + (line_addr >> 8) + (line_addr & 0xFF) + rec_type + sum(byte_buffer) chksum = (
#print("checksum: "+hex(chksum)) hex_len
+ (line_addr >> 8)
+ (line_addr & 0xFF)
+ rec_type
+ sum(byte_buffer)
)
# print("checksum: "+hex(chksum))
if (chksum & 0xFF) != 0: if (chksum & 0xFF) != 0:
raise RuntimeError("HEX Checksum fail") raise RuntimeError("HEX Checksum fail")
# get rid of that checksum byte # get rid of that checksum byte
byte_buffer.pop() 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 page_idx = line_addr - page_addr
line_idx = 0 line_idx = 0
while (page_idx < page_size) and (line_idx < hex_len): 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] page_buffer[page_idx] = byte_buffer[line_idx]
line_idx += 1 line_idx += 1
page_idx += 1 page_idx += 1
if page_idx == page_size: 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?

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,59 +84,62 @@ 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 ---------------------------------------------
latex_elements = { 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': '',
# # Latex figure (float) alignment
# 'preamble': '', #
# 'figure_align': 'htbp',
# Latex figure (float) alignment
#
# 'figure_align': 'htbp',
} }
# Grouping the document tree into LaTeX files. List of tuples # Grouping the document tree into LaTeX files. List of tuples
# (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,36 +23,43 @@ 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)
avrprog.end() avrprog.end()
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,19 +20,21 @@ 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)
avrprog.end() avrprog.end()
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,19 +20,21 @@ 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)
avrprog.end() avrprog.end()
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

@ -18,34 +18,39 @@ spi = busio.SPI(board.SCK, board.MOSI, board.MISO)
avrprog = adafruit_avrprog.AVRprog() avrprog = adafruit_avrprog.AVRprog()
avrprog.init(spi, board.D5) 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! # we can generate an 6 MHz clock for driving bare chips too!
clock_pwm = pulseio.PWMOut(board.D9, frequency=6000000, duty_cycle=65536//2) clock_pwm = pulseio.PWMOut(board.D9, frequency=6000000, duty_cycle=65536 // 2)
#pylint: enable-msg=no-member # pylint: enable-msg=no-member
# 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)
avrprog.end() avrprog.end()
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

@ -12,10 +12,10 @@ spi = busio.SPI(board.SCK, board.MOSI, board.MISO)
avrprog = adafruit_avrprog.AVRprog() avrprog = adafruit_avrprog.AVRprog()
avrprog.init(spi, board.D5) 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! # we can generate an 6 MHz clock for driving bare chips too!
clock_pwm = pulseio.PWMOut(board.D9, frequency=6000000, duty_cycle=65536//2) clock_pwm = pulseio.PWMOut(board.D9, frequency=6000000, duty_cycle=65536 // 2)
#pylint: enable-msg=no-member # pylint: enable-msg=no-member
avrprog.begin() avrprog.begin()
print("Signature bytes: ", [hex(i) for i in avrprog.read_signature()]) print("Signature bytes: ", [hex(i) for i in avrprog.read_signature()])

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"],
) )