From 80470965b5ae9f44adab1395131c0f91d5b1b624 Mon Sep 17 00:00:00 2001 From: dherrada Date: Thu, 12 Mar 2020 19:41:04 -0400 Subject: [PATCH] Ran black, updated to pylint 2.x --- .github/workflows/build.yml | 2 +- adafruit_vs1053.py | 108 ++++++++++++++++-------------- docs/conf.py | 120 +++++++++++++++++++++------------- examples/vs1053_simpletest.py | 40 ++++++------ setup.py | 54 +++++++-------- 5 files changed, 176 insertions(+), 148 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_vs1053.py b/adafruit_vs1053.py index 9fb224f..692e3a6 100644 --- a/adafruit_vs1053.py +++ b/adafruit_vs1053.py @@ -66,53 +66,56 @@ __repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_VS1053.git" # pylint: disable=bad-whitespace -_COMMAND_BAUDRATE = const(250000) # Speed for command transfers (MUST be slow) -_DATA_BAUDRATE = const(8000000) # Speed for data transfers (fast!) - -_VS1053_SCI_READ = const(0x03) -_VS1053_SCI_WRITE = const(0x02) - -_VS1053_REG_MODE = const(0x00) -_VS1053_REG_STATUS = const(0x01) -_VS1053_REG_BASS = const(0x02) -_VS1053_REG_CLOCKF = const(0x03) -_VS1053_REG_DECODETIME = const(0x04) -_VS1053_REG_AUDATA = const(0x05) -_VS1053_REG_WRAM = const(0x06) -_VS1053_REG_WRAMADDR = const(0x07) -_VS1053_REG_HDAT0 = const(0x08) -_VS1053_REG_HDAT1 = const(0x09) -_VS1053_REG_VOLUME = const(0x0B) - -_VS1053_GPIO_DDR = const(0xC017) -_VS1053_GPIO_IDATA = const(0xC018) -_VS1053_GPIO_ODATA = const(0xC019) - -_VS1053_INT_ENABLE = const(0xC01A) - -_VS1053_MODE_SM_DIFF = const(0x0001) -_VS1053_MODE_SM_LAYER12 = const(0x0002) -_VS1053_MODE_SM_RESET = const(0x0004) -_VS1053_MODE_SM_CANCEL = const(0x0008) -_VS1053_MODE_SM_EARSPKLO = const(0x0010) -_VS1053_MODE_SM_TESTS = const(0x0020) -_VS1053_MODE_SM_STREAM = const(0x0040) -_VS1053_MODE_SM_SDINEW = const(0x0800) -_VS1053_MODE_SM_ADPCM = const(0x1000) -_VS1053_MODE_SM_LINE1 = const(0x4000) -_VS1053_MODE_SM_CLKRANGE = const(0x8000) +_COMMAND_BAUDRATE = const(250000) # Speed for command transfers (MUST be slow) +_DATA_BAUDRATE = const(8000000) # Speed for data transfers (fast!) + +_VS1053_SCI_READ = const(0x03) +_VS1053_SCI_WRITE = const(0x02) + +_VS1053_REG_MODE = const(0x00) +_VS1053_REG_STATUS = const(0x01) +_VS1053_REG_BASS = const(0x02) +_VS1053_REG_CLOCKF = const(0x03) +_VS1053_REG_DECODETIME = const(0x04) +_VS1053_REG_AUDATA = const(0x05) +_VS1053_REG_WRAM = const(0x06) +_VS1053_REG_WRAMADDR = const(0x07) +_VS1053_REG_HDAT0 = const(0x08) +_VS1053_REG_HDAT1 = const(0x09) +_VS1053_REG_VOLUME = const(0x0B) + +_VS1053_GPIO_DDR = const(0xC017) +_VS1053_GPIO_IDATA = const(0xC018) +_VS1053_GPIO_ODATA = const(0xC019) + +_VS1053_INT_ENABLE = const(0xC01A) + +_VS1053_MODE_SM_DIFF = const(0x0001) +_VS1053_MODE_SM_LAYER12 = const(0x0002) +_VS1053_MODE_SM_RESET = const(0x0004) +_VS1053_MODE_SM_CANCEL = const(0x0008) +_VS1053_MODE_SM_EARSPKLO = const(0x0010) +_VS1053_MODE_SM_TESTS = const(0x0020) +_VS1053_MODE_SM_STREAM = const(0x0040) +_VS1053_MODE_SM_SDINEW = const(0x0800) +_VS1053_MODE_SM_ADPCM = const(0x1000) +_VS1053_MODE_SM_LINE1 = const(0x4000) +_VS1053_MODE_SM_CLKRANGE = const(0x8000) # pylint: enable=bad-whitespace class VS1053: """Class-level buffer for read and write commands.""" + # This is NOT thread/re-entrant safe (by design, for less memory hit). _SCI_SPI_BUFFER = bytearray(4) def __init__(self, spi, cs, xdcs, dreq): # Create SPI device for VS1053 self._cs = digitalio.DigitalInOut(cs) - self._vs1053_spi = SPIDevice(spi, self._cs, baudrate=_COMMAND_BAUDRATE, polarity=0, phase=0) + self._vs1053_spi = SPIDevice( + spi, self._cs, baudrate=_COMMAND_BAUDRATE, polarity=0, phase=0 + ) # Setup control lines. self._xdcs = digitalio.DigitalInOut(xdcs) self._xdcs.switch_to_output(value=True) @@ -122,8 +125,11 @@ def __init__(self, spi, cs, xdcs, dreq): self.reset() # Check version is 4 (VS1053 ID). if self.version != 4: - raise RuntimeError('Expected version 4 (VS1053) but got: {} Check wiring!' - .format(self.version)) + raise RuntimeError( + "Expected version 4 (VS1053) but got: {} Check wiring!".format( + self.version + ) + ) def _sci_write(self, address, value): # Write a 16-bit big-endian value to the provided 8-bit address. @@ -145,14 +151,16 @@ def _sci_read(self, address): # pylint: disable=no-member spi.configure(baudrate=_COMMAND_BAUDRATE) spi.write(self._SCI_SPI_BUFFER, end=2) - time.sleep(0.00001) # Delay 10 microseconds (at least) + time.sleep(0.00001) # Delay 10 microseconds (at least) spi.readinto(self._SCI_SPI_BUFFER, end=2) # pylint: enable=no-member return (self._SCI_SPI_BUFFER[0] << 8) | self._SCI_SPI_BUFFER[1] def soft_reset(self): """Perform a quick soft reset of the VS1053.""" - self._sci_write(_VS1053_REG_MODE, _VS1053_MODE_SM_SDINEW | _VS1053_MODE_SM_RESET) + self._sci_write( + _VS1053_REG_MODE, _VS1053_MODE_SM_SDINEW | _VS1053_MODE_SM_RESET + ) time.sleep(0.1) def reset(self): @@ -198,7 +206,7 @@ def byte_rate(self): """Return the bit rate in bytes per second (computed each second). Useful to know if a song is being played and how fast it's happening. """ - self._sci_write(_VS1053_REG_WRAMADDR, 0x1e05) + self._sci_write(_VS1053_REG_WRAMADDR, 0x1E05) return self._sci_read(_VS1053_REG_WRAM) def start_playback(self): @@ -207,17 +215,21 @@ def start_playback(self): buffers of music data to the play_data function. """ # Reset playback. - self._sci_write(_VS1053_REG_MODE, _VS1053_MODE_SM_LINE1 | _VS1053_MODE_SM_SDINEW) + self._sci_write( + _VS1053_REG_MODE, _VS1053_MODE_SM_LINE1 | _VS1053_MODE_SM_SDINEW + ) # Resync. - self._sci_write(_VS1053_REG_WRAMADDR, 0x1e29) + self._sci_write(_VS1053_REG_WRAMADDR, 0x1E29) self._sci_write(_VS1053_REG_WRAM, 0) # Set time to zero. self.decode_time = 0 def stop_playback(self): """Stop any playback of audio.""" - self._sci_write(_VS1053_REG_MODE, _VS1053_MODE_SM_LINE1 | _VS1053_MODE_SM_SDINEW | - _VS1053_MODE_SM_CANCEL) + self._sci_write( + _VS1053_REG_MODE, + _VS1053_MODE_SM_LINE1 | _VS1053_MODE_SM_SDINEW | _VS1053_MODE_SM_CANCEL, + ) def play_data(self, data_buffer, start=0, end=None): """Send a buffer of file data to the VS1053 for playback. Make sure @@ -250,8 +262,7 @@ def sine_test(self, n, seconds): with self._vs1053_spi as spi: # pylint: disable=no-member spi.configure(baudrate=_DATA_BAUDRATE) - spi.write(bytes([0x53, 0xEF, 0x6E, n & 0xFF, 0x00, 0x00, - 0x00, 0x00])) + spi.write(bytes([0x53, 0xEF, 0x6E, n & 0xFF, 0x00, 0x00, 0x00, 0x00])) # pylint: enable=no-member finally: self._xdcs.value = True @@ -261,8 +272,7 @@ def sine_test(self, n, seconds): with self._vs1053_spi as spi: # pylint: disable=no-member spi.configure(baudrate=_DATA_BAUDRATE) - spi.write(bytes([0x45, 0x78, 0x69, 0x74, 0x00, 0x00, 0x00, - 0x00])) + spi.write(bytes([0x45, 0x78, 0x69, 0x74, 0x00, 0x00, 0x00, 0x00])) # pylint: enable=no-member finally: self._xdcs.value = True diff --git a/docs/conf.py b/docs/conf.py index e33346b..936a09e 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,40 @@ # autodoc_mock_imports = ["digitalio", "busio"] -intersphinx_mapping = {'python': ('https://docs.python.org/3.4', None),'BusDevice': ('https://circuitpython.readthedocs.io/projects/busdevice/en/latest/', None),'Register': ('https://circuitpython.readthedocs.io/projects/register/en/latest/', None),'CircuitPython': ('https://circuitpython.readthedocs.io/en/latest/', None)} +intersphinx_mapping = { + "python": ("https://docs.python.org/3.4", None), + "BusDevice": ( + "https://circuitpython.readthedocs.io/projects/busdevice/en/latest/", + None, + ), + "Register": ( + "https://circuitpython.readthedocs.io/projects/register/en/latest/", + 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 VS1053 Library' -copyright = u'2018 Tony DiCola' -author = u'Tony DiCola' +project = u"Adafruit VS1053 Library" +copyright = u"2018 Tony DiCola" +author = u"Tony DiCola" # 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 +69,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 +81,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 +96,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 = 'AdafruitVs1053Librarydoc' +htmlhelp_basename = "AdafruitVs1053Librarydoc" # -- 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, 'AdafruitVS1053Library.tex', u'AdafruitVS1053 Library Documentation', - author, 'manual'), + ( + master_doc, + "AdafruitVS1053Library.tex", + u"AdafruitVS1053 Library Documentation", + author, + "manual", + ), ] # -- Options for manual page output --------------------------------------- @@ -144,8 +159,13 @@ # One entry per manual page. List of tuples # (source start file, name, description, authors, manual section). man_pages = [ - (master_doc, 'AdafruitVS1053library', u'Adafruit VS1053 Library Documentation', - [author], 1) + ( + master_doc, + "AdafruitVS1053library", + u"Adafruit VS1053 Library Documentation", + [author], + 1, + ) ] # -- Options for Texinfo output ------------------------------------------- @@ -154,7 +174,13 @@ # (source start file, target name, title, author, # dir menu entry, description, category) texinfo_documents = [ - (master_doc, 'AdafruitVS1053Library', u'Adafruit VS1053 Library Documentation', - author, 'AdafruitVS1053Library', 'One line description of project.', - 'Miscellaneous'), + ( + master_doc, + "AdafruitVS1053Library", + u"Adafruit VS1053 Library Documentation", + author, + "AdafruitVS1053Library", + "One line description of project.", + "Miscellaneous", + ), ] diff --git a/examples/vs1053_simpletest.py b/examples/vs1053_simpletest.py index 427a647..e9b9579 100644 --- a/examples/vs1053_simpletest.py +++ b/examples/vs1053_simpletest.py @@ -19,20 +19,20 @@ # Define pins connected to VS1053: # For FeatherWing with Feather M0: -SDCS = board.D5 # Pin connected to SD card CS line. -MP3CS = board.D6 # Pin connected to VS1053 CS line. -DREQ = board.D9 # Pin connected to VS1053 DREQ line. -XDCS = board.D10 # Pin connected to VS1053 D/C line. +SDCS = board.D5 # Pin connected to SD card CS line. +MP3CS = board.D6 # Pin connected to VS1053 CS line. +DREQ = board.D9 # Pin connected to VS1053 DREQ line. +XDCS = board.D10 # Pin connected to VS1053 D/C line. # Other configuration: -PLAYBACK_FILE = '/sd/test.wav' # Name of file to play. - # This should be the full path - # including /sd prefix if on - # sd card. +PLAYBACK_FILE = "/sd/test.wav" # Name of file to play. +# This should be the full path +# including /sd prefix if on +# sd card. -BUFFER_SIZE = 128 # Size in bytes of the MP3 data buffer for sending data to - # the VS1053. +BUFFER_SIZE = 128 # Size in bytes of the MP3 data buffer for sending data to +# the VS1053. # Setup SPI bus (hardware SPI). @@ -42,12 +42,12 @@ sd_cs = digitalio.DigitalInOut(SDCS) sdcard = adafruit_sdcard.SDCard(spi, sd_cs) vfs = storage.VfsFat(sdcard) -storage.mount(vfs, '/sd') +storage.mount(vfs, "/sd") # To list all the files on the SD card root uncomment: -#import os -#print('SD card root contains:') -#print(os.listdir('/sd')) +# import os +# print('SD card root contains:') +# print(os.listdir('/sd')) # Setup VS1053. vs1053 = adafruit_vs1053.VS1053(spi, MP3CS, XDCS, DREQ) @@ -57,9 +57,9 @@ vs1053.set_volume(0, 0) # Play a test tone (this works). -print('Playing test tone for two seconds...') +print("Playing test tone for two seconds...") vs1053.sine_test(0x44, 2.0) -print('Done playing tone!') +print("Done playing tone!") # Play back a MP3 file by starting playback, then reading a buffer of data # at a time and sending it to the VS1053. @@ -68,14 +68,14 @@ # the VS1053 making static, stopping, and eventually requiring a hard reset. # We'll need to look into interrupt support perhaps to monitor DREQ like in the # arduino library. -print('Playing {}...'.format(PLAYBACK_FILE)) +print("Playing {}...".format(PLAYBACK_FILE)) vs1053.start_playback() -with open(PLAYBACK_FILE, 'rb') as infile: +with open(PLAYBACK_FILE, "rb") as infile: music_data = infile.read(BUFFER_SIZE) - while music_data is not None and music_data != '': + while music_data is not None and music_data != "": while not vs1053.ready_for_data: pass vs1053.play_data(music_data, end=len(music_data)) music_data = infile.read(BUFFER_SIZE) -print('Done!') +print("Done!") diff --git a/setup.py b/setup.py index 6690fc8..dfc4ba5 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,48 +15,39 @@ 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-vs1053', - + name="adafruit-circuitpython-vs1053", use_scm_version=True, - setup_requires=['setuptools_scm'], - - description='Driver for interacting and playing media files with the VS1053 audio codec over a ' - 'SPI connection.', + setup_requires=["setuptools_scm"], + description="Driver for interacting and playing media files with the VS1053 audio codec over a " + "SPI connection.", 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_VS1053', - + url="https://github.com/adafruit/Adafruit_CircuitPython_VS1053", # Author details - author='Adafruit Industries', - author_email='circuitpython@adafruit.com', - - install_requires=['Adafruit-Blinka', 'adafruit-circuitpython-busdevice'], - + author="Adafruit Industries", + author_email="circuitpython@adafruit.com", + install_requires=["Adafruit-Blinka", "adafruit-circuitpython-busdevice"], # 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 audio codec vs1053 spi hardware micropython circuitpython', - + keywords="adafruit audio codec vs1053 spi hardware micropython circuitpython", # You can just specify the packages manually here if your project is # simple. Or you can use find_packages(). - py_modules=['adafruit_vs1053'], -) \ No newline at end of file + py_modules=["adafruit_vs1053"], +)