Mercurial > circuitpython-badge
changeset 2:eff707b7a302 draft
Initial docs
| author | Radomir Dopieralski <sheep-devel@sheep.art.pl> |
|---|---|
| date | Sun, 19 Aug 2018 13:40:21 +0200 |
| parents | 7c924bd8e19e |
| children | 9fd73b085363 |
| files | board/pins.c docs/Makefile docs/conf.py docs/hardware.rst docs/index.rst docs/library.rst docs/make.bat |
| diffstat | 7 files changed, 419 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/board/pins.c Sun Aug 19 13:05:28 2018 +0200 +++ b/board/pins.c Sun Aug 19 13:40:21 2018 +0200 @@ -7,7 +7,6 @@ { MP_ROM_QSTR(MP_QSTR_RADIO0), MP_ROM_PTR(&pin_PA03) }, { MP_ROM_QSTR(MP_QSTR_RADIO1), MP_ROM_PTR(&pin_PA04) }, - { MP_ROM_QSTR(MP_QSTR_RADIO2), MP_ROM_PTR(&pin_PA22) }, { MP_ROM_QSTR(MP_QSTR_RADIO3), MP_ROM_PTR(&pin_PA05) }, { MP_ROM_QSTR(MP_QSTR_RADIO4), MP_ROM_PTR(&pin_PA06) }, { MP_ROM_QSTR(MP_QSTR_RADIO5), MP_ROM_PTR(&pin_PA07) },
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/docs/Makefile Sun Aug 19 13:40:21 2018 +0200 @@ -0,0 +1,20 @@ +# Minimal makefile for Sphinx documentation +# + +# You can set these variables from the command line. +SPHINXOPTS = +SPHINXBUILD = sphinx-build +SPHINXPROJ = Badge +SOURCEDIR = . +BUILDDIR = _build + +# Put it first so that "make" without argument is like "make help". +help: + @$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) + +.PHONY: help Makefile + +# Catch-all target: route all unknown targets to Sphinx using the new +# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS). +%: Makefile + @$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/docs/conf.py Sun Aug 19 13:40:21 2018 +0200 @@ -0,0 +1,172 @@ +# -*- coding: utf-8 -*- +# +# Badge documentation build configuration file, created by +# sphinx-quickstart on Sun Aug 19 13:07:17 2018. +# +# This file is execfile()d with the current directory set to its +# containing dir. +# +# Note that not all possible configuration values are present in this +# autogenerated file. +# +# All configuration values have a default; values that are commented out +# serve to show the default. + +# If extensions (or modules to document with autodoc) are in another directory, +# add these directories to sys.path here. If the directory is relative to the +# documentation root, use os.path.abspath to make it absolute, like shown here. +# +# import os +# import sys +# sys.path.insert(0, os.path.abspath('.')) + + +# -- General configuration ------------------------------------------------ + +# If your documentation needs a minimal Sphinx version, state it here. +# +# needs_sphinx = '1.0' + +# Add any Sphinx extension module names here, as strings. They can be +# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom +# ones. +extensions = ['sphinx.ext.intersphinx', + 'sphinx.ext.imgmath'] + +# Add any paths that contain templates here, relative to this directory. +templates_path = ['_templates'] + +# The suffix(es) of source filenames. +# You can specify multiple suffix as a list of string: +# +# source_suffix = ['.rst', '.md'] +source_suffix = '.rst' + +# The master toctree document. +master_doc = 'index' + +# General information about the project. +project = u'Badge' +copyright = u'2018, Radomir Dopieralski' +author = u'Radomir Dopieralski' + +# 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' +# The full version, including alpha/beta/rc tags. +release = u'1' + +# The language for content autogenerated by Sphinx. Refer to documentation +# for a list of supported languages. +# +# This is also used if you do content translation via gettext catalogs. +# Usually you set "language" from the command line for these cases. +language = None + +# 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'] + +# The name of the Pygments (syntax highlighting) style to use. +pygments_style = 'sphinx' + +# If true, `todo` and `todoList` produce output, else they produce nothing. +todo_include_todos = False + + +# -- Options for HTML output ---------------------------------------------- + +# The theme to use for HTML and HTML Help pages. See the documentation for +# a list of builtin themes. +# +html_theme = 'alabaster' + +# Theme options are theme-specific and customize the look and feel of a theme +# further. For a list of options available for each theme, see the +# documentation. +# +# html_theme_options = {} + +# 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'] + +# Custom sidebar templates, must be a dictionary that maps document names +# to template names. +# +# This is required for the alabaster theme +# refs: http://alabaster.readthedocs.io/en/latest/installation.html#sidebars +html_sidebars = { + '**': [ + 'relations.html', # needs 'show_related': True theme option to display + 'searchbox.html', + ] +} + + +# -- Options for HTMLHelp output ------------------------------------------ + +# Output file base name for HTML help builder. +htmlhelp_basename = 'Badgedoc' + + +# -- 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', +} + +# 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, 'Badge.tex', u'Badge Documentation', + u'Radomir Dopieralski', 'manual'), +] + + +# -- Options for manual page output --------------------------------------- + +# One entry per manual page. List of tuples +# (source start file, name, description, authors, manual section). +man_pages = [ + (master_doc, 'badge', u'Badge Documentation', + [author], 1) +] + + +# -- Options for Texinfo output ------------------------------------------- + +# Grouping the document tree into Texinfo files. List of tuples +# (source start file, target name, title, author, +# dir menu entry, description, category) +texinfo_documents = [ + (master_doc, 'Badge', u'Badge Documentation', + author, 'Badge', 'One line description of project.', + 'Miscellaneous'), +] + + + + +# Example configuration for intersphinx: refer to the Python standard library. +intersphinx_mapping = {'https://docs.python.org/': None}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/docs/hardware.rst Sun Aug 19 13:40:21 2018 +0200 @@ -0,0 +1,72 @@ +Hardware Overview +***************** + +The badge consists of several main components: + +Microcontroller +=============== + +The microcontroller controlling everything is an Atmel SAMD21, an ARM Cortex-M0 +microcontroller running at 48MHz. It has native USB support, which lets us +expose the filesystem on the device as a USB disk and the REPL console as a +serial device. It's running a custom version of CircuitPython, an +implementation of the Python language for microcontrollers based on +MicroPython. + +All of the GPIO pins are exposed in the ``board`` module, which lets us use +them from CircuitPython. + + +Buttons +======= + +The device has eight buttons, arranged into two crosses, that can be used to +control the code running on it. The buttons are connected to GPIO pins on one +end, and to GND on the other, and they are scanned in the background by the +``gamepad`` module. The state of the buttons can be accessed with the +``badge.keys()`` function. + + +Display +======= + +There is a display of 14×11 red pixels on the device, controlled by a +IS31FL3733 chip connected over an I²C bus to the ``board.SDA0`` and +``board.SCL0`` pins. It can be accessed with the ``badge.show()`` function and +its brightness can be adjusted with the ``badge.brightness()`` function. It's +capable of displaying 256 shades of red, however, since most of those shades +are very similar, the library selects only 16 distinct shades that you can use. + + +Accelerometer +============= + +There is a LIS3DH accelerometer in the middle of the board, under the display, +which can be used to read the position and movement of the device. It is also +connected over an I²C protocol to the ``board.SDA0`` and ``board.SCL0`` pins. +It can be accessed with the ``badge.accel()`` function. + + +Radio +===== + +There is an NRF24L01+ radio module on board, connected to the ``board.RADIO*`` +pins. The connections are as follows: + + * ``RADIO0`` — ``CE`` + * ``RADIO1`` — ``CSN`` + * ``RADIO3`` — ``SCK`` + * ``RADIO4`` — ``MOSI`` + * ``RADIO5`` — ``MISO`` + +There are currently no built-in functions or libraries for handling the +communication with this module. And external library needs to be used. + + +Power +===== + +The device is powered with three 1.5V AAA alkaline batteries or the USB port. +The source of power is switched with the power switch. In the "ON" position, +the power comes from the batteries, while in the "OFF" position, it's powered +from the USB port (if it's connected).
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/docs/index.rst Sun Aug 19 13:40:21 2018 +0200 @@ -0,0 +1,23 @@ +.. Badge documentation master file, created by + sphinx-quickstart on Sun Aug 19 13:07:17 2018. + You can adapt this file completely to your liking, but it should at least + contain the root `toctree` directive. + +Welcome to Badge's documentation! +================================= + +.. toctree:: + :maxdepth: 2 + :caption: Contents: + + hardware.rst + library.rst + + + +Indices and tables +================== + +* :ref:`genindex` +* :ref:`modindex` +* :ref:`search`
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/docs/library.rst Sun Aug 19 13:40:21 2018 +0200 @@ -0,0 +1,96 @@ +Library Reference +***************** + +.. module:: badge + +.. function:: init() + + Initialize the module. + + This function switches the display on and performs some basic setup. + + +.. function:: brightness(level) + + Set the brightness of the display, from 0 to 15. + + +.. function:: show(pix) + + Show the provided image on the display, starting at the top left corner. + You will want to call this once for every frame. + + +.. function:: keys() + + Return a number telling which keys have been pressed since the last check. + The number can then be filtered with the ``&`` operator and the ``K_X``, + ``K_DOWN``, ``K_LEFT``, ``K_RIGHT``, ``K_UP``, ``K_O``, ``K_S``, and + ``K_Z`` constants to see whether any of the keys was pressed. + + +.. function:: tick(delay) + + Wait until ``delay`` seconds have passed since the last call to this + function. You can call it every frame to ensure a constant frame rate. + + +.. class:: Pix(width=14, height=11, buffer=None) + + Pix represents a drawing surface, ``width`` pixels wide and ``height`` + pixels high. + + If no ``buffer`` is specified for storing the data, a suitable one will + be automatically created. + + .. classmethod:: from_string(cls, string) + + Creates a new Pix and initialzes its contents from a provided string. + Each line corresponds to one line of the image, and each character + corresponds to a pixel on that line. The brightness of a pixel is + encoded as a single hexadecimal digit, `0` being black and `F` being + white. Characters that are not hex digits will cause an error. + + .. classmethod:: from_text(cls, text, color=None, background=0, colors=None) + + Creates a new Pix and renders the specified text on it. It is exactly + the size needed to fit the specified text. Newlines and other control + characters are rendered as spaces. + + If ``color`` is not specified, it will use yellow and red for the + letters by default. Otherwise it will use the specified color, with + ``background`` color as the background. + + Alternatively, ``colors`` may be specified as a 4-tuple of colors, + and then the ``color`` and ``background`` arguments are ignored, and + the four specified colors are used for rendering the text. + + .. method:: pixel(self, x, y, color=None) + + If ``color`` is specified, sets the pixel at location ``x``, ``y`` to + that color. If not, returns the color of the pixel at that location. + + If the location is out of bounds of the drawing surface, returns 0. + + .. method:: box(self, color, x=0, y=0, width=self.width, height=self.height) + + Draws a filled box with the specified ``color`` with its top left + corner at the specified location and of the specified size. If no + location and size are specified, fills the whole drawing surface. + + .. method:: blit(self, source, dx=0, dy=0, x=0, y=0, width=None, height=None, key=None) + + Copied the ``source`` drawing surface onto this surface at location + specified with ``dx`` and ``dy``. + + If ``x``, ``y``, ``widht`` and ``height`` are specified, only copies + that fragment of the ``source`` image, otherwise copies it whole. + + If ``key`` color is specified, that color is considered transparent + on the source image, and is not copied onto this drawing surface. + + +.. function:: accel() + + Return a triple ``(x, y, z)`` of acceleration values reported by the + on-board accelerometer.
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/docs/make.bat Sun Aug 19 13:40:21 2018 +0200 @@ -0,0 +1,36 @@ +@ECHO OFF + +pushd %~dp0 + +REM Command file for Sphinx documentation + +if "%SPHINXBUILD%" == "" ( + set SPHINXBUILD=sphinx-build +) +set SOURCEDIR=. +set BUILDDIR=_build +set SPHINXPROJ=Badge + +if "%1" == "" goto help + +%SPHINXBUILD% >NUL 2>NUL +if errorlevel 9009 ( + echo. + echo.The 'sphinx-build' command was not found. Make sure you have Sphinx + echo.installed, then set the SPHINXBUILD environment variable to point + echo.to the full path of the 'sphinx-build' executable. Alternatively you + echo.may add the Sphinx directory to PATH. + echo. + echo.If you don't have Sphinx installed, grab it from + echo.http://sphinx-doc.org/ + exit /b 1 +) + +%SPHINXBUILD% -M %1 %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% +goto end + +:help +%SPHINXBUILD% -M help %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% + +:end +popd
