diff --git a/readthedocs.yml b/.readthedocs.yml similarity index 100% rename from readthedocs.yml rename to .readthedocs.yml diff --git a/.travis.yml b/.travis.yml index 883fd7f..1482448 100644 --- a/.travis.yml +++ b/.travis.yml @@ -16,16 +16,17 @@ deploy: provider: releases api_key: $GITHUB_TOKEN file_glob: true - file: bundles/* + file: $TRAVIS_BUILD_DIR/bundles/* skip_cleanup: true overwrite: true on: tags: true install: - - pip install pylint circuitpython-build-tools + - pip install pylint circuitpython-build-tools Sphinx sphinx-rtd-theme script: - pylint adafruit_max7219/*.py - ([[ ! -d "examples" ]] || pylint --disable=missing-docstring,invalid-name,bad-whitespace examples/*.py) - circuitpython-build-bundles --filename_prefix adafruit-circuitpython-max7219 --library_location . + - cd docs && sphinx-build -E -W -b html . _build/html diff --git a/README.rst b/README.rst index c13d03f..6849cd1 100644 --- a/README.rst +++ b/README.rst @@ -27,9 +27,6 @@ This is easily achieved by downloading Usage Example ============= -Examples -******** - adafruit_max7219.Matrix8x8 Example ---------------------------------- @@ -87,14 +84,6 @@ adafruit_max7219.BCDDigits Example display.show_str(0,'{:9.2f}'.format(-1234.56)) display.show() -API Reference -============= - -.. toctree:: - :maxdepth: 2 - - api - Contributing ============ @@ -125,3 +114,26 @@ Then run the build: .. code-block:: shell circuitpython-build-bundles --filename_prefix adafruit-circuitpython-max7219 --library_location . + +Sphinx documentation +----------------------- + +Sphinx is used to build the documentation based on rST files and comments in the code. First, +install dependencies (feel free to reuse the virtual environment from above): + +.. code-block:: shell + + python3 -m venv .env + source .env/bin/activate + pip install Sphinx sphinx-rtd-theme + +Now, once you have the virtual environment activated: + +.. code-block:: shell + + cd docs + sphinx-build -E -W -b html . _build/html + +This will output the documentation to ``docs/_build/html``. Open the index.html in your browser to +view them. It will also (due to -W) error out on any warning like Travis will. This is a good way to +locally verify it will pass. diff --git a/adafruit_max7219/bcddigits.py b/adafruit_max7219/bcddigits.py index 3318c11..63bc98e 100644 --- a/adafruit_max7219/bcddigits.py +++ b/adafruit_max7219/bcddigits.py @@ -22,7 +22,7 @@ # """ -:mod:`adafruit_max7219.bcddigits.BCDDigits` +`adafruit_max7219.bcddigits.BCDDigits` ==================================================== """ from adafruit_max7219 import max7219 @@ -40,14 +40,12 @@ class BCDDigits(max7219.MAX7219): """ Basic support for display on a 7-Segment BCD display controlled by a Max7219 chip using SPI. + + :param object spi: an spi busio or spi bitbangio object + :param ~digitalio.DigitalInOut cs: digital in/out to use as chip select signal + :param int nDigits: number of led 7-segment digits; default 1; max 8 """ def __init__(self, spi, cs, nDigits=1): - """ - :param object spi: an spi busio or spi bitbangio object - :param ~digitalio.DigitalInOut cs: digital in/out to use as chip select - signal - :param int nDigits: number of led 7-segment digits; default 1; max 8 - """ self._ndigits = nDigits super().__init__(self._ndigits, 8, spi, cs) @@ -66,7 +64,8 @@ def init_display(self): def set_digit(self, dpos, value): """ - set one digit in the display + Display one digit. + :param int dpos: the digit position; zero-based :param int value: integer ranging from 0->15 """ @@ -78,7 +77,8 @@ def set_digit(self, dpos, value): def set_digits(self, start, values): """ - set the display from a list + Display digits from a list. + :param int s: digit to start display zero-based :param list ds: list of integer values ranging from 0->15 """ @@ -89,7 +89,8 @@ def set_digits(self, start, values): def show_dot(self, dpos, bit_value=None): """ - set the decimal point for a digit + The decimal point for a digit. + :param int dpos: the digit to set the decimal point zero-based :param int value: value > zero lights the decimal point, else unlights the point """ @@ -99,7 +100,7 @@ def show_dot(self, dpos, bit_value=None): def clear_all(self): """ - clear all digits and decimal points + Clear all digits and decimal points. """ self.fill(1) for i in range(self._ndigits): @@ -107,7 +108,8 @@ def clear_all(self): def show_str(self, start, strg): """ - displays a numeric str in the display. shows digits 0-9, -, and . + Displays a numeric str in the display. Shows digits ``0-9``, ``-``, and ``.``. + :param int start: start position to show the numeric string :param string str: the numeric string """ @@ -127,7 +129,8 @@ def show_str(self, start, strg): def show_help(self, start): """ - display the word HELP in the display + Display the word HELP in the display. + :param int start: start position to show HELP """ digits = [12, 11, 13, 14] diff --git a/adafruit_max7219/matrices.py b/adafruit_max7219/matrices.py index b22700b..6724cc2 100644 --- a/adafruit_max7219/matrices.py +++ b/adafruit_max7219/matrices.py @@ -22,7 +22,7 @@ # """ -:mod:`adafruit_max7219.matrices.Matrix8x8` +`adafruit_max7219.matrices.Matrix8x8` ==================================================== """ from adafruit_max7219 import max7219 @@ -37,12 +37,13 @@ _DISPLAYTEST = const(15) class Matrix8x8(max7219.MAX7219): - """Driver for a 8x8 LED matrix based on the MAX7219 chip""" + """ + Driver for a 8x8 LED matrix based on the MAX7219 chip. + + :param object spi: an spi busio or spi bitbangio object + :param ~digitalio.DigitalInOut cs: digital in/out to use as chip select signal + """ def __init__(self, spi, cs): - """ - :param object spi: an spi busio or spi bitbangio object - :param ~digitalio.DigitalInOut cs: digital in/out to use as chip select signal - """ super().__init__(8, 8, spi, cs) def init_display(self): @@ -59,7 +60,7 @@ def init_display(self): def text(self, strg, xpos, ypos, bit_value=1): """ - draw text in the 8x8 matrix. + Draw text in the 8x8 matrix. :param int xpos: x position of LED in matrix :param int ypos: y position of LED in matrix @@ -70,6 +71,6 @@ def text(self, strg, xpos, ypos, bit_value=1): def clear_all(self): """ - unlights all matrix leds + Clears all matrix leds. """ self.fill(0) diff --git a/adafruit_max7219/max7219.py b/adafruit_max7219/max7219.py index a95ad5f..3a1ebcb 100644 --- a/adafruit_max7219/max7219.py +++ b/adafruit_max7219/max7219.py @@ -20,30 +20,36 @@ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN # THE SOFTWARE. """ -`adafruit_max7219.MAX7219` - MAX7219 LED Matrix/Digit Display Driver +`adafruit_max7219.max7219` - MAX7219 LED Matrix/Digit Display Driver ======================================================================== CircuitPython library to support MAX7219 LED Matrix/Digit Display Driver. This library supports the use of the MAX7219-based display in CircuitPython, either an 8x8 matrix or a 8 digit 7-segment numeric display. -see also -======== +See Also +========= * matrices.Maxtrix8x8 is a class support an 8x8 led matrix display * bcddigits.BCDDigits is a class that support the 8 digit 7-segment display Beware that most CircuitPython compatible hardware are 3.3v logic level! Make sure that the input pin is 5v tolerant. + * Author(s): Michael McWethy Implementation Notes -------------------- **Hardware:** + * Adafruit `MAX7219CNG LED Matrix/Digit Display Driver - -MAX7219 `_ (Product ID: 453) + MAX7219 `_ (Product ID: 453) + **Software and Dependencies:** -* Adafruit CircuitPython firmware (1.0.0+) for the ESP8622 and M0-based boards: -https://github.com/adafruit/circuitpython/releases + +* Adafruit CircuitPython firmware for the ESP8622 and M0-based boards: + https://github.com/adafruit/circuitpython/releases + * Adafruit's Bus Device library: https://github.com/adafruit/Adafruit_CircuitPython_BusDevice + **Notes:** #. Datasheet: https://cdn-shop.adafruit.com/datasheets/MAX7219.pdf """ @@ -63,18 +69,19 @@ class MAX7219: - """ MAX2719 - driver for displays based on max719 chip_select""" + """ + MAX2719 - driver for displays based on max719 chip_select + + :param int width: the number of pixels wide + :param int height: the number of pixels high + :param object spi: an spi busio or spi bitbangio object + :param ~digitalio.DigitalInOut chip_select: digital in/out to use as chip select signal + :param baudrate: for SPIDevice baudrate (default 8000000) + :param polarity: for SPIDevice polarity (default 0) + :param phase: for SPIDevice phase (default 0) + """ def __init__(self, width, height, spi, cs, *, baudrate=8000000, polarity=0, phase=0): - """ - :param int width: the number of pixels wide - :param int height: the number of pixels high - :param object spi: an spi busio or spi bitbangio object - :param ~digitalio.DigitalInOut chip_select: digital in/out to use as chip select signal - :param baudrate: for SPIDevice baudrate (default 8000000) - :param polarity: for SPIDevice polarity (default 0) - :param phase: for SPIDevice phase (default 0) - """ self._chip_select = cs self._chip_select.direction = digitalio.Direction.OUTPUT @@ -91,12 +98,13 @@ def __init__(self, width, height, spi, cs, *, self.init_display() def init_display(self): - """must be implement by derived class""" + """Must be implemented by derived class (``matrices``, ``bcddigits``)""" pass def brightness(self, value): """ - control the brightness of the display + Controls the brightness of the display. + :param int value: 0->15 dimmest to brightest """ if not 0 <= value <= 15: @@ -105,34 +113,36 @@ def brightness(self, value): def show(self): """ - update the display with recent changes in buffer + Updates the display. """ for ypos in range(8): self.write_cmd(_DIGIT0 + ypos, self._buffer[ypos]) def fill(self, bit_value): """ - set all buffer bits to a col - :param bit_value: int value > 0 set the buffer bit, else clears the buffer bit + Fill the display buffer. + + :param int bit_value: value > 0 set the buffer bit, else clears the buffer bit """ self.framebuf.fill(bit_value) def pixel(self, xpos, ypos, bit_value=None): """ - set one buffer bit + Set one buffer bit + :param xpos: x position to set bit :param ypos: y position to set bit - :param bit_value: int value > 0 sets the buffer bit, else clears the buffer bit + :param int bit_value: value > 0 sets the buffer bit, else clears the buffer bit """ bit_value = 0x01 if bit_value else 0x00 self.framebuf.pixel(xpos, ypos, bit_value) def scroll(self, delta_x, delta_y): - """scolls the display using delta_x,delta_y""" + """Srcolls the display using delta_x,delta_y.""" self.framebuf.scroll(delta_x, delta_y) def write_cmd(self, cmd, data): - """writes a command to spi device""" + """Writes a command to spi device.""" #print('cmd {} data {}'.format(cmd,data)) self._chip_select.value = False with self._spi_device as my_spi_device: diff --git a/api.rst b/api.rst deleted file mode 100644 index daac829..0000000 --- a/api.rst +++ /dev/null @@ -1,15 +0,0 @@ - -Module classes -============== - -Matrices -++++++++ - -.. module:: adafruit_max7219.matrices - :members: - -BCDDigits -+++++++++ - -.. module:: adafruit_max7219.bcddigits.py - :members diff --git a/docs/_static/favicon.ico b/docs/_static/favicon.ico new file mode 100644 index 0000000..5aca983 Binary files /dev/null and b/docs/_static/favicon.ico differ diff --git a/docs/api.rst b/docs/api.rst new file mode 100644 index 0000000..90c64dc --- /dev/null +++ b/docs/api.rst @@ -0,0 +1,11 @@ + +.. If you created a package, create one automodule per module in the package. + +.. automodule:: adafruit_max7219.max7219 + :members: + +.. automodule:: adafruit_max7219.matrices + :members: + +.. automodule:: adafruit_max7219.bcddigits + :members: diff --git a/conf.py b/docs/conf.py similarity index 89% rename from conf.py rename to docs/conf.py index 84a3ade..b1c64a2 100644 --- a/conf.py +++ b/docs/conf.py @@ -2,7 +2,7 @@ import os import sys -sys.path.insert(0, os.path.abspath('.')) +sys.path.insert(0, os.path.abspath('..')) # -- General configuration ------------------------------------------------ @@ -18,7 +18,7 @@ # Uncomment the below if you use native CircuitPython modules such as # digitalio, micropython and busio. List the modules you use. Without it, the # autodoc module docs will fail to generate with a warning. -# autodoc_mock_imports = ["digitalio", "busio"] +autodoc_mock_imports = ["digitalio", "adafruit_bus_device", "micropython", "framebuf"] intersphinx_mapping = {'python': ('https://docs.python.org/3.4', None),'CircuitPython': ('https://circuitpython.readthedocs.io/en/latest/', None)} @@ -28,7 +28,7 @@ source_suffix = '.rst' # The master toctree document. -master_doc = 'README' +master_doc = 'index' # General information about the project. project = u'Adafruit MAX7219 Library' @@ -54,7 +54,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'] +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. @@ -71,6 +71,9 @@ # If true, `todo` and `todoList` produce output, else they produce nothing. todo_include_todos = False +# If this is True, todo emits a warning for each TODO entries. The default is False. +todo_emit_warnings = True + # -- Options for HTML output ---------------------------------------------- @@ -95,6 +98,12 @@ # so a file named "default.css" will overwrite the builtin "default.css". 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' + # Output file base name for HTML help builder. htmlhelp_basename = 'AdafruitMAX7219Librarydoc' diff --git a/docs/examples.rst b/docs/examples.rst new file mode 100644 index 0000000..d805978 --- /dev/null +++ b/docs/examples.rst @@ -0,0 +1,12 @@ +Simple test +------------ + +Ensure your device works with this simple test. + +.. literalinclude:: ../examples/max7219_simpletest.py + :caption: examples/max7219_simpletest.py + :linenos: + +.. literalinclude:: ../examples/showbcddigits.py + :caption: examples/showbcddigits.py + :linenos: \ No newline at end of file diff --git a/docs/index.rst b/docs/index.rst new file mode 100644 index 0000000..1fff48a --- /dev/null +++ b/docs/index.rst @@ -0,0 +1,48 @@ +.. include:: ../README.rst + +Table of Contents +================= + +.. toctree:: + :maxdepth: 4 + :hidden: + + self + +.. toctree:: + :caption: Examples + + examples + +.. toctree:: + :caption: API Reference + :maxdepth: 3 + + api + +.. toctree:: + :caption: Tutorials + +.. toctree:: + :caption: Related Products + + MAX7219CNG LED Matrix/Digit Display Driver + + +.. toctree:: + :caption: Other Links + + Download + CircuitPython Reference Documentation + CircuitPython Support Forum + Discord Chat + Adafruit Learning System + Adafruit Blog + Adafruit Store + +Indices and tables +================== + +* :ref:`genindex` +* :ref:`modindex` +* :ref:`search` diff --git a/examples/showmatrix.py b/examples/max7219_simpletest.py similarity index 100% rename from examples/showmatrix.py rename to examples/max7219_simpletest.py