From 5305cf4fabe904072b294e908336c13127ff5e48 Mon Sep 17 00:00:00 2001 From: dherrada Date: Thu, 12 Mar 2020 19:42:11 -0400 Subject: [PATCH 1/2] Ran black, updated to pylint 2.x --- .github/workflows/build.yml | 2 +- adafruit_miniesptool.py | 207 ++++++++++++++----------- docs/conf.py | 112 +++++++------ examples/miniesptool_esp32argon.py | 83 ++++++---- examples/miniesptool_esp32multifile.py | 77 +++++---- examples/miniesptool_esp32nina.py | 9 +- examples/miniesptool_esp8266program.py | 7 +- setup.py | 52 +++---- 8 files changed, 316 insertions(+), 233 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_miniesptool.py b/adafruit_miniesptool.py index ed9f625..30204f3 100644 --- a/adafruit_miniesptool.py +++ b/adafruit_miniesptool.py @@ -58,55 +58,64 @@ __version__ = "0.0.0-auto.0" __repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_miniesptool.git" -SYNC_PACKET = b'\x07\x07\x12 UUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUU' +SYNC_PACKET = b"\x07\x07\x12 UUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUU" ESP32_DATAREGVALUE = 0x15122500 ESP8266_DATAREGVALUE = 0x00062000 # Commands supported by ESP8266 ROM bootloader # pylint: disable=bad-whitespace -ESP_FLASH_BEGIN = 0x02 -ESP_FLASH_DATA = 0x03 -ESP_FLASH_END = 0x04 -ESP_MEM_BEGIN = 0x05 -ESP_MEM_END = 0x06 -ESP_MEM_DATA = 0x07 -ESP_SYNC = 0x08 -ESP_WRITE_REG = 0x09 -ESP_READ_REG = 0x0a -ESP_SPI_SET_PARAMS = 0x0b -ESP_SPI_ATTACH = 0x0d -ESP_CHANGE_BAUDRATE = 0x0f -ESP_SPI_FLASH_MD5 = 0x13 -ESP_CHECKSUM_MAGIC = 0xef - -ESP8266 = 0x8266 -ESP32 = 0x32 +ESP_FLASH_BEGIN = 0x02 +ESP_FLASH_DATA = 0x03 +ESP_FLASH_END = 0x04 +ESP_MEM_BEGIN = 0x05 +ESP_MEM_END = 0x06 +ESP_MEM_DATA = 0x07 +ESP_SYNC = 0x08 +ESP_WRITE_REG = 0x09 +ESP_READ_REG = 0x0A +ESP_SPI_SET_PARAMS = 0x0B +ESP_SPI_ATTACH = 0x0D +ESP_CHANGE_BAUDRATE = 0x0F +ESP_SPI_FLASH_MD5 = 0x13 +ESP_CHECKSUM_MAGIC = 0xEF + +ESP8266 = 0x8266 +ESP32 = 0x32 # pylint: enable=bad-whitespace FLASH_SIZES = { - '512KB':0x00, - '256KB':0x10, - '1MB':0x20, - '2MB':0x30, - '4MB':0x40, - '2MB-c1': 0x50, - '4MB-c1':0x60, - '8MB':0x80, - '16MB':0x90, + "512KB": 0x00, + "256KB": 0x10, + "1MB": 0x20, + "2MB": 0x30, + "4MB": 0x40, + "2MB-c1": 0x50, + "4MB-c1": 0x60, + "8MB": 0x80, + "16MB": 0x90, } -class miniesptool: # pylint: disable=invalid-name + +class miniesptool: # pylint: disable=invalid-name """A miniature version of esptool, a programming command line tool for ESP8266 and ESP32 chips. This version is minimized to work on CircuitPython boards, so you can burn ESP firmware direct from the CPy disk drive. Handy when you have an ESP module wired to a board and need to upload new AT firmware. Its slow! Expect a few minutes when programming 1 MB flash.""" + FLASH_WRITE_SIZE = 0x200 - FLASH_SECTOR_SIZE = 0x1000 # Flash sector size, minimum unit of erase. + FLASH_SECTOR_SIZE = 0x1000 # Flash sector size, minimum unit of erase. ESP_ROM_BAUD = 115200 - def __init__(self, uart, gpio0_pin, # pylint: disable=too-many-arguments - reset_pin, *, flashsize, baudrate=ESP_ROM_BAUD): + def __init__( + self, + uart, + gpio0_pin, # pylint: disable=too-many-arguments + reset_pin, + *, + flashsize, + baudrate=ESP_ROM_BAUD + ): gpio0_pin.direction = Direction.OUTPUT reset_pin.direction = Direction.OUTPUT self._gpio0pin = gpio0_pin @@ -118,8 +127,8 @@ def __init__(self, uart, gpio0_pin, # pylint: disable=too-many-arguments self._chipfamily = None self._chipname = None self._flashsize = flashsize - #self._debug_led = DigitalInOut(board.D13) - #self._debug_led.direction = Direction.OUTPUT + # self._debug_led = DigitalInOut(board.D13) + # self._debug_led.direction = Direction.OUTPUT @property def debug(self): @@ -141,7 +150,7 @@ def baudrate(self): def baudrate(self, baud): if self._chipfamily == ESP8266: raise NotImplementedError("Baud rate can only change on ESP32") - buffer = struct.pack('> 16) & 0xff, (mac3 >> 8) & 0xff, mac3 & 0xff) - elif ((mac1 >> 16) & 0xff) == 0: - oui = (0x18, 0xfe, 0x34) - elif ((mac1 >> 16) & 0xff) == 1: - oui = (0xac, 0xd0, 0x74) + oui = ((mac3 >> 16) & 0xFF, (mac3 >> 8) & 0xFF, mac3 & 0xFF) + elif ((mac1 >> 16) & 0xFF) == 0: + oui = (0x18, 0xFE, 0x34) + elif ((mac1 >> 16) & 0xFF) == 1: + oui = (0xAC, 0xD0, 0x74) else: raise RuntimeError("Couldnt determine OUI") mac_addr[0] = oui[0] mac_addr[1] = oui[1] mac_addr[2] = oui[2] - mac_addr[3] = (mac1>>8) & 0xff - mac_addr[4] = mac1 & 0xff - mac_addr[5] = (mac0>>24) & 0xff + mac_addr[3] = (mac1 >> 8) & 0xFF + mac_addr[4] = mac1 & 0xFF + mac_addr[5] = (mac0 >> 24) & 0xFF if self._chipfamily == ESP32: mac_addr[0] = mac2 >> 8 & 0xFF mac_addr[1] = mac2 & 0xFF @@ -206,7 +215,7 @@ def chip_type(self): def chip_name(self): """The specific name of the chip, e.g. ESP8266EX, to the best of our ability to determine without a stub bootloader.""" - self.chip_type # pylint: disable=pointless-statement + self.chip_type # pylint: disable=pointless-statement self._read_efuses() if self.chip_type == ESP32: @@ -222,11 +231,11 @@ def _read_efuses(self): if self._chipfamily == ESP8266: base_addr = 0x3FF00050 elif self._chipfamily == ESP32: - base_addr = 0x6001a000 + base_addr = 0x6001A000 else: raise RuntimeError("Don't know what chip this is") for i in range(4): - self._efuses[i] = self.read_register(base_addr + 4*i) + self._efuses[i] = self.read_register(base_addr + 4 * i) def get_erase_size(self, offset, size): """Calculate an erase size given a specific size in bytes. @@ -251,8 +260,9 @@ def flash_begin(self, *, size=0, offset=0): if self._chipfamily == ESP32: self.check_command(ESP_SPI_ATTACH, bytes([0] * 8)) # We are harcoded for 4MB flash on ESP32 - buffer = struct.pack(' 0: - c = self._uart.read(1) # pylint: disable=invalid-name - if c == b'\xDB': + c = self._uart.read(1) # pylint: disable=invalid-name + if c == b"\xDB": escaped_byte = True elif escaped_byte: - if c == b'\xDD': - reply += b'\xDC' - elif c == b'\xDC': - reply += b'\xC0' + if c == b"\xDD": + reply += b"\xDC" + elif c == b"\xDC": + reply += b"\xC0" else: reply += [0xDB, c] escaped_byte = False else: reply += c - if reply and reply[0] != 0xc0: + if reply and reply[0] != 0xC0: # packets must start with 0xC0 del reply[0] if len(reply) > 1 and reply[1] != 0x01: @@ -363,17 +380,16 @@ def get_response(self, opcode, timeout=0.1): # pylint: disable=too-many-branches value = reply[5:9] data = reply[9:-1] if self._debug: - print("value:", [hex(i) for i in value], - "data:", [hex(i) for i in data]) + print("value:", [hex(i) for i in value], "data:", [hex(i) for i in data]) return (value, data) def read_register(self, reg): """Read a register within the ESP chip RAM, returns a 4-element list""" if self._debug: print("Reading register 0x%08x" % reg) - packet = struct.pack('I', reg) + packet = struct.pack("I", reg) register = self.check_command(ESP_READ_REG, packet)[0] - return struct.unpack('I', bytearray(register))[0] + return struct.unpack("I", bytearray(register))[0] def reset(self, program_mode=False): """Perform a hard-reset into ROM bootloader using gpio0 and reset""" @@ -386,10 +402,12 @@ def reset(self, program_mode=False): def flash_block(self, data, seq, timeout=0.1): """Send one block of data to program into SPI Flash memory""" - self.check_command(ESP_FLASH_DATA, - struct.pack(' 0: - print('\rWriting at 0x%08x... (%d %%)' % - (address + seq * self.FLASH_WRITE_SIZE, 100 * (seq + 1) // blocks), end='') + print( + "\rWriting at 0x%08x... (%d %%)" + % ( + address + seq * self.FLASH_WRITE_SIZE, + 100 * (seq + 1) // blocks, + ), + end="", + ) block = file.read(self.FLASH_WRITE_SIZE) # Pad the last block - block = block + b'\xff' * (self.FLASH_WRITE_SIZE - len(block)) - #print(block) + block = block + b"\xff" * (self.FLASH_WRITE_SIZE - len(block)) + # print(block) self.flash_block(block, seq, timeout=2) seq += 1 written += len(block) - print("Took %.2fs to write %d bytes" % - (time.monotonic()-stamp, filesize)) + print("Took %.2fs to write %d bytes" % (time.monotonic() - stamp, filesize)) if md5: print("Verifying MD5sum ", md5) calcd = self.md5(offset, filesize) @@ -427,7 +450,9 @@ def _sync(self): any hardware resetting""" self.send_command(0x08, SYNC_PACKET) for _ in range(8): - reply, data = self.get_response(0x08, 0.1) # pylint: disable=unused-variable + reply, data = self.get_response( + 0x08, 0.1 + ) # pylint: disable=unused-variable if not data: continue if len(data) > 1 and data[0] == 0 and data[1] == 0: @@ -460,10 +485,10 @@ def slip_encode(buffer): 0xdb is replaced with 0xdb 0xdd and 0xc0 is replaced with 0xdb 0xdc""" encoded = [] for b in buffer: - if b == 0xdb: - encoded += [0xdb, 0xdd] - elif b == 0xc0: - encoded += [0xdb, 0xdc] + if b == 0xDB: + encoded += [0xDB, 0xDD] + elif b == 0xC0: + encoded += [0xDB, 0xDC] else: encoded += [b] return bytearray(encoded) diff --git a/docs/conf.py b/docs/conf.py index 6068abe..98b15e9 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,10 +11,10 @@ # extensions coming with Sphinx (named 'sphinx.ext.*') or your custom # ones. extensions = [ - 'sphinx.ext.autodoc', - 'sphinx.ext.intersphinx', - 'sphinx.ext.napoleon', - 'sphinx.ext.todo', + "sphinx.ext.autodoc", + "sphinx.ext.intersphinx", + "sphinx.ext.napoleon", + "sphinx.ext.todo", ] # TODO: Please Read! @@ -23,29 +24,32 @@ # autodoc_mock_imports = ["digitalio", "busio"] -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 miniesptool Library' -copyright = u'2018 ladyada' -author = u'ladyada' +project = u"Adafruit miniesptool Library" +copyright = u"2018 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. @@ -57,7 +61,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. @@ -69,7 +73,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 @@ -84,59 +88,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 = 'AdafruitMiniesptoolLibrarydoc' +htmlhelp_basename = "AdafruitMiniesptoolLibrarydoc" # -- 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, 'AdafruitminiesptoolLibrary.tex', u'Adafruitminiesptool Library Documentation', - author, 'manual'), + ( + master_doc, + "AdafruitminiesptoolLibrary.tex", + u"Adafruitminiesptool Library Documentation", + author, + "manual", + ), ] # -- Options for manual page output --------------------------------------- @@ -144,8 +151,13 @@ # One entry per manual page. List of tuples # (source start file, name, description, authors, manual section). man_pages = [ - (master_doc, 'Adafruitminiesptoollibrary', u'Adafruit miniesptool Library Documentation', - [author], 1) + ( + master_doc, + "Adafruitminiesptoollibrary", + u"Adafruit miniesptool Library Documentation", + [author], + 1, + ) ] # -- Options for Texinfo output ------------------------------------------- @@ -154,7 +166,13 @@ # (source start file, target name, title, author, # dir menu entry, description, category) texinfo_documents = [ - (master_doc, 'AdafruitminiesptoolLibrary', u'Adafruit miniesptool Library Documentation', - author, 'AdafruitminiesptoolLibrary', 'One line description of project.', - 'Miscellaneous'), + ( + master_doc, + "AdafruitminiesptoolLibrary", + u"Adafruit miniesptool Library Documentation", + author, + "AdafruitminiesptoolLibrary", + "One line description of project.", + "Miscellaneous", + ), ] diff --git a/examples/miniesptool_esp32argon.py b/examples/miniesptool_esp32argon.py index e75e5fe..2a78267 100644 --- a/examples/miniesptool_esp32argon.py +++ b/examples/miniesptool_esp32argon.py @@ -2,16 +2,16 @@ import board import busio -from digitalio import DigitalInOut, Direction # pylint: disable=unused-import +from digitalio import DigitalInOut, Direction # pylint: disable=unused-import import adafruit_miniesptool print("ESP32 mini prog") # With a Metro or Feather M4 -#uart = busio.UART(TX, RX, baudrate=115200, timeout=1) -#resetpin = DigitalInOut(board.D5) -#gpio0pin = DigitalInOut(board.D6) +# uart = busio.UART(TX, RX, baudrate=115200, timeout=1) +# resetpin = DigitalInOut(board.D5) +# gpio0pin = DigitalInOut(board.D6) # With a Particle Argon, we need to also turn off flow control uart = busio.UART(board.ESP_RX, board.ESP_TX, baudrate=115200, timeout=1) @@ -21,8 +21,9 @@ esp_cts.direction = Direction.OUTPUT esp_cts.value = False -esptool = adafruit_miniesptool.miniesptool(uart, gpio0pin, resetpin, - flashsize=4*1024*1024) +esptool = adafruit_miniesptool.miniesptool( + uart, gpio0pin, resetpin, flashsize=4 * 1024 * 1024 +) esptool.debug = False esptool.sync() @@ -34,51 +35,73 @@ print("MAC ADDR: ", [hex(i) for i in esptool.mac_addr]) # 0x10000 ota_data_initial.bin -esptool.flash_file("esp32/ota_data_initial.bin", 0x10000, - '84d04c9d6cc8ef35bf825d51a5277699') +esptool.flash_file( + "esp32/ota_data_initial.bin", 0x10000, "84d04c9d6cc8ef35bf825d51a5277699" +) # 0x1000 bootloader/bootloader.bin -esptool.flash_file("esp32/bootloader/bootloader.bin", 0x1000, - '195dae16eda6ab703a45928182baa863') +esptool.flash_file( + "esp32/bootloader/bootloader.bin", 0x1000, "195dae16eda6ab703a45928182baa863" +) # 0x20000 at_customize.bin -esptool.flash_file("esp32/at_customize.bin", 0x20000, - '9853055e077ba0c90cd70691b9d8c3d5') +esptool.flash_file( + "esp32/at_customize.bin", 0x20000, "9853055e077ba0c90cd70691b9d8c3d5" +) # 0x24000 customized_partitions/server_cert.bin -esptool.flash_file("esp32/customized_partitions/server_cert.bin", 0x24000, - '766fa1e87aabb9ab78ff4023f6feb4d3') +esptool.flash_file( + "esp32/customized_partitions/server_cert.bin", + 0x24000, + "766fa1e87aabb9ab78ff4023f6feb4d3", +) # 0x26000 customized_partitions/server_key.bin -esptool.flash_file("esp32/customized_partitions/server_key.bin", 0x26000, - '05da7907776c3d5160f26bf870592459') +esptool.flash_file( + "esp32/customized_partitions/server_key.bin", + 0x26000, + "05da7907776c3d5160f26bf870592459", +) # 0x28000 customized_partitions/server_ca.bin -esptool.flash_file("esp32/customized_partitions/server_ca.bin", 0x28000, - 'e0169f36f9cb09c6705343792d353c0a') +esptool.flash_file( + "esp32/customized_partitions/server_ca.bin", + 0x28000, + "e0169f36f9cb09c6705343792d353c0a", +) # 0x2a000 customized_partitions/client_cert.bin -esptool.flash_file("esp32/customized_partitions/client_cert.bin", 0x2a000, - '428ed3bae5d58b721b8254cbeb8004ff') +esptool.flash_file( + "esp32/customized_partitions/client_cert.bin", + 0x2A000, + "428ed3bae5d58b721b8254cbeb8004ff", +) # 0x2c000 customized_partitions/client_key.bin -esptool.flash_file("esp32/customized_partitions/client_key.bin", 0x2c000, - '136f563811930a5d3bf04c946f430ced') +esptool.flash_file( + "esp32/customized_partitions/client_key.bin", + 0x2C000, + "136f563811930a5d3bf04c946f430ced", +) # 0x2e000 customized_partitions/client_ca.bin -esptool.flash_file("esp32/customized_partitions/client_ca.bin", 0x2e000, - '25ab638695819daae67bcd8a4bfc5626') +esptool.flash_file( + "esp32/customized_partitions/client_ca.bin", + 0x2E000, + "25ab638695819daae67bcd8a4bfc5626", +) # 0xf000 phy_init_data.bin -esptool.flash_file("esp32/phy_init_data.bin", 0xf000, - 'bc9854aa3687ca73e25d213d20113b23') +esptool.flash_file( + "esp32/phy_init_data.bin", 0xF000, "bc9854aa3687ca73e25d213d20113b23" +) # 0x100000 esp-at.bin -esptool.flash_file("esp32/esp-at.bin", 0x100000, - 'ae256e4ab546354cd8dfa241e1056996') +esptool.flash_file("esp32/esp-at.bin", 0x100000, "ae256e4ab546354cd8dfa241e1056996") # 0x8000 partitions_at.bin -esptool.flash_file("esp32/partitions_at.bin", 0x8000, - 'd3d1508993d61aedf17280140fc22a6b') +esptool.flash_file( + "esp32/partitions_at.bin", 0x8000, "d3d1508993d61aedf17280140fc22a6b" +) esptool.reset() time.sleep(0.5) diff --git a/examples/miniesptool_esp32multifile.py b/examples/miniesptool_esp32multifile.py index f782279..96d9521 100644 --- a/examples/miniesptool_esp32multifile.py +++ b/examples/miniesptool_esp32multifile.py @@ -2,7 +2,7 @@ import board import busio -from digitalio import DigitalInOut, Direction # pylint: disable=unused-import +from digitalio import DigitalInOut, Direction # pylint: disable=unused-import import adafruit_miniesptool print("ESP32 mini prog") @@ -22,8 +22,9 @@ esp_cts.value = False """ -esptool = adafruit_miniesptool.miniesptool(uart, gpio0pin, resetpin, - flashsize=4*1024*1024) +esptool = adafruit_miniesptool.miniesptool( + uart, gpio0pin, resetpin, flashsize=4 * 1024 * 1024 +) esptool.debug = False esptool.sync() @@ -35,51 +36,73 @@ print("MAC ADDR: ", [hex(i) for i in esptool.mac_addr]) # 0x10000 ota_data_initial.bin -esptool.flash_file("esp32/ota_data_initial.bin", 0x10000, - '84d04c9d6cc8ef35bf825d51a5277699') +esptool.flash_file( + "esp32/ota_data_initial.bin", 0x10000, "84d04c9d6cc8ef35bf825d51a5277699" +) # 0x1000 bootloader/bootloader.bin -esptool.flash_file("esp32/bootloader/bootloader.bin", 0x1000, - '894e5f067a44773ac1ae987a14e85787') +esptool.flash_file( + "esp32/bootloader/bootloader.bin", 0x1000, "894e5f067a44773ac1ae987a14e85787" +) # 0x20000 at_customize.bin -esptool.flash_file("esp32/at_customize.bin", 0x20000, - '9853055e077ba0c90cd70691b9d8c3d5') +esptool.flash_file( + "esp32/at_customize.bin", 0x20000, "9853055e077ba0c90cd70691b9d8c3d5" +) # 0x24000 customized_partitions/server_cert.bin -esptool.flash_file("esp32/customized_partitions/server_cert.bin", 0x24000, - '766fa1e87aabb9ab78ff4023f6feb4d3') +esptool.flash_file( + "esp32/customized_partitions/server_cert.bin", + 0x24000, + "766fa1e87aabb9ab78ff4023f6feb4d3", +) # 0x26000 customized_partitions/server_key.bin -esptool.flash_file("esp32/customized_partitions/server_key.bin", 0x26000, - '05da7907776c3d5160f26bf870592459') +esptool.flash_file( + "esp32/customized_partitions/server_key.bin", + 0x26000, + "05da7907776c3d5160f26bf870592459", +) # 0x28000 customized_partitions/server_ca.bin -esptool.flash_file("esp32/customized_partitions/server_ca.bin", 0x28000, - 'e0169f36f9cb09c6705343792d353c0a') +esptool.flash_file( + "esp32/customized_partitions/server_ca.bin", + 0x28000, + "e0169f36f9cb09c6705343792d353c0a", +) # 0x2a000 customized_partitions/client_cert.bin -esptool.flash_file("esp32/customized_partitions/client_cert.bin", 0x2a000, - '428ed3bae5d58b721b8254cbeb8004ff') +esptool.flash_file( + "esp32/customized_partitions/client_cert.bin", + 0x2A000, + "428ed3bae5d58b721b8254cbeb8004ff", +) # 0x2c000 customized_partitions/client_key.bin -esptool.flash_file("esp32/customized_partitions/client_key.bin", 0x2c000, - '136f563811930a5d3bf04c946f430ced') +esptool.flash_file( + "esp32/customized_partitions/client_key.bin", + 0x2C000, + "136f563811930a5d3bf04c946f430ced", +) # 0x2e000 customized_partitions/client_ca.bin -esptool.flash_file("esp32/customized_partitions/client_ca.bin", 0x2e000, - '25ab638695819daae67bcd8a4bfc5626') +esptool.flash_file( + "esp32/customized_partitions/client_ca.bin", + 0x2E000, + "25ab638695819daae67bcd8a4bfc5626", +) # 0xf000 phy_init_data.bin -esptool.flash_file("esp32/phy_init_data.bin", 0xf000, - 'bc9854aa3687ca73e25d213d20113b23') +esptool.flash_file( + "esp32/phy_init_data.bin", 0xF000, "bc9854aa3687ca73e25d213d20113b23" +) # 0x100000 esp-at.bin -esptool.flash_file("esp32/esp-at.bin", 0x100000, - '7018a1b4c8a5c108377ecda7632b899c') +esptool.flash_file("esp32/esp-at.bin", 0x100000, "7018a1b4c8a5c108377ecda7632b899c") # 0x8000 partitions_at.bin -esptool.flash_file("esp32/partitions_at.bin", 0x8000, - 'd3d1508993d61aedf17280140fc22a6b') +esptool.flash_file( + "esp32/partitions_at.bin", 0x8000, "d3d1508993d61aedf17280140fc22a6b" +) esptool.reset() time.sleep(0.5) diff --git a/examples/miniesptool_esp32nina.py b/examples/miniesptool_esp32nina.py index df29107..af1409e 100644 --- a/examples/miniesptool_esp32nina.py +++ b/examples/miniesptool_esp32nina.py @@ -1,7 +1,7 @@ import time import board import busio -from digitalio import DigitalInOut, Direction # pylint: disable=unused-import +from digitalio import DigitalInOut, Direction # pylint: disable=unused-import import adafruit_miniesptool print("ESP32 Nina-FW") @@ -10,8 +10,9 @@ resetpin = DigitalInOut(board.D5) gpio0pin = DigitalInOut(board.D6) -esptool = adafruit_miniesptool.miniesptool(uart, gpio0pin, resetpin, - flashsize=4*1024*1024) +esptool = adafruit_miniesptool.miniesptool( + uart, gpio0pin, resetpin, flashsize=4 * 1024 * 1024 +) esptool.sync() print("Synced") @@ -22,7 +23,7 @@ print("MAC ADDR: ", [hex(i) for i in esptool.mac_addr]) # Note: Make sure to use the LATEST nina-fw binary release! -esptool.flash_file("NINA_W102-1.3.1.bin",0x0,'3f9d2765dd3b7b1eab61e1eccae73e44') +esptool.flash_file("NINA_W102-1.3.1.bin", 0x0, "3f9d2765dd3b7b1eab61e1eccae73e44") esptool.reset() time.sleep(0.5) diff --git a/examples/miniesptool_esp8266program.py b/examples/miniesptool_esp8266program.py index 7cfa323..4a2e19b 100644 --- a/examples/miniesptool_esp8266program.py +++ b/examples/miniesptool_esp8266program.py @@ -10,8 +10,9 @@ resetpin = DigitalInOut(board.D5) gpio0pin = DigitalInOut(board.D6) # On ESP8266 we will 'sync' to the baudrate in initialization -esptool = adafruit_miniesptool.miniesptool(uart, gpio0pin, resetpin, - flashsize=1024*1024, baudrate=256000) +esptool = adafruit_miniesptool.miniesptool( + uart, gpio0pin, resetpin, flashsize=1024 * 1024, baudrate=256000 +) esptool.debug = False esptool.sync() @@ -19,7 +20,7 @@ print("Synced") print(esptool.chip_name) print("MAC ADDR: ", [hex(i) for i in esptool.mac_addr]) -esptool.flash_file("esp8266/AT_firmware_1.6.2.0.bin", 0x0 ) +esptool.flash_file("esp8266/AT_firmware_1.6.2.0.bin", 0x0) # 0x3FC000 esp_init_data_default_v05.bin esptool.flash_file("esp8266/esp_init_data_default_v05.bin", 0x3FC000) # 0x3FE000 blank.bin diff --git a/setup.py b/setup.py index 2f4c39e..4225b18 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-miniesptool', - + name="adafruit-circuitpython-miniesptool", use_scm_version=True, - setup_requires=['setuptools_scm'], - - description='CircuitPython ROM loader for ESP chips, works with ESP8266 or ESP32.', + setup_requires=["setuptools_scm"], + description="CircuitPython ROM loader for ESP chips, works with ESP8266 or ESP32.", 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_miniesptool', - + url="https://github.com/adafruit/Adafruit_CircuitPython_miniesptool", # Author details - author='Adafruit Industries', - author_email='circuitpython@adafruit.com', - - install_requires=['Adafruit-Blinka', 'pyserial'], - + author="Adafruit Industries", + author_email="circuitpython@adafruit.com", + install_requires=["Adafruit-Blinka", "pyserial"], # 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 miniesptool esp8266 esp32 esp software micropython circuitpython', - + keywords="adafruit miniesptool esp8266 esp32 esp software micropython circuitpython", # You can just specify the packages manually here if your project is # simple. Or you can use find_packages(). - py_modules=['adafruit_miniesptool'], -) \ No newline at end of file + py_modules=["adafruit_miniesptool"], +) From 9539ddae295cc89b1c442588332f6f082aba2fc2 Mon Sep 17 00:00:00 2001 From: dherrada Date: Mon, 16 Mar 2020 17:17:22 -0400 Subject: [PATCH 2/2] Ran black, updated to pylint 2.x --- adafruit_miniesptool.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/adafruit_miniesptool.py b/adafruit_miniesptool.py index 30204f3..4aa29bf 100644 --- a/adafruit_miniesptool.py +++ b/adafruit_miniesptool.py @@ -220,7 +220,7 @@ def chip_name(self): if self.chip_type == ESP32: return "ESP32" - elif self.chip_type == ESP8266: + if self.chip_type == ESP8266: if self._efuses[0] & (1 << 4) or self._efuses[2] & (1 << 16): return "ESP8285" return "ESP8266EX" @@ -327,9 +327,9 @@ def send_command(self, opcode, buffer): packet = [0xC0, 0x00] # direction packet.append(opcode) - packet += [x for x in struct.pack("H", len(buffer))] - packet += [x for x in self.slip_encode(struct.pack("I", checksum))] - packet += [x for x in self.slip_encode(buffer)] + packet.extend(struct.pack("H", len(buffer))) + packet.extend(self.slip_encode(struct.pack("I", checksum))) + packet.extend(self.slip_encode(buffer)) packet += [0xC0] if self._debug: print([hex(x) for x in packet]) @@ -450,9 +450,9 @@ def _sync(self): any hardware resetting""" self.send_command(0x08, SYNC_PACKET) for _ in range(8): - reply, data = self.get_response( + reply, data = self.get_response( # pylint: disable=unused-variable 0x08, 0.1 - ) # pylint: disable=unused-variable + ) if not data: continue if len(data) > 1 and data[0] == 0 and data[1] == 0: