Commits

Ben Bass committed 09339ba

add initial sphinx docs

  • Participants
  • Parent commits aac8f24

Comments (0)

Files changed (26)

 syntax: glob
 *.pyc
 *.pyo
+.idea
+docs/_build
 MANIFEST
+# Makefile for Sphinx documentation
+#
+
+# You can set these variables from the command line.
+SPHINXOPTS    =
+SPHINXBUILD   = sphinx-build
+PAPER         =
+BUILDDIR      = _build
+
+# Internal variables.
+PAPEROPT_a4     = -D latex_paper_size=a4
+PAPEROPT_letter = -D latex_paper_size=letter
+ALLSPHINXOPTS   = -d $(BUILDDIR)/doctrees $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) .
+# the i18n builder cannot share the environment and doctrees with the others
+I18NSPHINXOPTS  = $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) .
+
+.PHONY: help clean html dirhtml singlehtml pickle json htmlhelp qthelp devhelp epub latex latexpdf text man changes linkcheck doctest gettext
+
+help:
+	@echo "Please use \`make <target>' where <target> is one of"
+	@echo "  html       to make standalone HTML files"
+	@echo "  dirhtml    to make HTML files named index.html in directories"
+	@echo "  singlehtml to make a single large HTML file"
+	@echo "  pickle     to make pickle files"
+	@echo "  json       to make JSON files"
+	@echo "  htmlhelp   to make HTML files and a HTML help project"
+	@echo "  qthelp     to make HTML files and a qthelp project"
+	@echo "  devhelp    to make HTML files and a Devhelp project"
+	@echo "  epub       to make an epub"
+	@echo "  latex      to make LaTeX files, you can set PAPER=a4 or PAPER=letter"
+	@echo "  latexpdf   to make LaTeX files and run them through pdflatex"
+	@echo "  text       to make text files"
+	@echo "  man        to make manual pages"
+	@echo "  texinfo    to make Texinfo files"
+	@echo "  info       to make Texinfo files and run them through makeinfo"
+	@echo "  gettext    to make PO message catalogs"
+	@echo "  changes    to make an overview of all changed/added/deprecated items"
+	@echo "  linkcheck  to check all external links for integrity"
+	@echo "  doctest    to run all doctests embedded in the documentation (if enabled)"
+
+clean:
+	-rm -rf $(BUILDDIR)/*
+
+html:
+	$(SPHINXBUILD) -b html $(ALLSPHINXOPTS) $(BUILDDIR)/html
+	@echo
+	@echo "Build finished. The HTML pages are in $(BUILDDIR)/html."
+
+dirhtml:
+	$(SPHINXBUILD) -b dirhtml $(ALLSPHINXOPTS) $(BUILDDIR)/dirhtml
+	@echo
+	@echo "Build finished. The HTML pages are in $(BUILDDIR)/dirhtml."
+
+singlehtml:
+	$(SPHINXBUILD) -b singlehtml $(ALLSPHINXOPTS) $(BUILDDIR)/singlehtml
+	@echo
+	@echo "Build finished. The HTML page is in $(BUILDDIR)/singlehtml."
+
+pickle:
+	$(SPHINXBUILD) -b pickle $(ALLSPHINXOPTS) $(BUILDDIR)/pickle
+	@echo
+	@echo "Build finished; now you can process the pickle files."
+
+json:
+	$(SPHINXBUILD) -b json $(ALLSPHINXOPTS) $(BUILDDIR)/json
+	@echo
+	@echo "Build finished; now you can process the JSON files."
+
+htmlhelp:
+	$(SPHINXBUILD) -b htmlhelp $(ALLSPHINXOPTS) $(BUILDDIR)/htmlhelp
+	@echo
+	@echo "Build finished; now you can run HTML Help Workshop with the" \
+	      ".hhp project file in $(BUILDDIR)/htmlhelp."
+
+qthelp:
+	$(SPHINXBUILD) -b qthelp $(ALLSPHINXOPTS) $(BUILDDIR)/qthelp
+	@echo
+	@echo "Build finished; now you can run "qcollectiongenerator" with the" \
+	      ".qhcp project file in $(BUILDDIR)/qthelp, like this:"
+	@echo "# qcollectiongenerator $(BUILDDIR)/qthelp/pylibftdi.qhcp"
+	@echo "To view the help file:"
+	@echo "# assistant -collectionFile $(BUILDDIR)/qthelp/pylibftdi.qhc"
+
+devhelp:
+	$(SPHINXBUILD) -b devhelp $(ALLSPHINXOPTS) $(BUILDDIR)/devhelp
+	@echo
+	@echo "Build finished."
+	@echo "To view the help file:"
+	@echo "# mkdir -p $$HOME/.local/share/devhelp/pylibftdi"
+	@echo "# ln -s $(BUILDDIR)/devhelp $$HOME/.local/share/devhelp/pylibftdi"
+	@echo "# devhelp"
+
+epub:
+	$(SPHINXBUILD) -b epub $(ALLSPHINXOPTS) $(BUILDDIR)/epub
+	@echo
+	@echo "Build finished. The epub file is in $(BUILDDIR)/epub."
+
+latex:
+	$(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex
+	@echo
+	@echo "Build finished; the LaTeX files are in $(BUILDDIR)/latex."
+	@echo "Run \`make' in that directory to run these through (pdf)latex" \
+	      "(use \`make latexpdf' here to do that automatically)."
+
+latexpdf:
+	$(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex
+	@echo "Running LaTeX files through pdflatex..."
+	$(MAKE) -C $(BUILDDIR)/latex all-pdf
+	@echo "pdflatex finished; the PDF files are in $(BUILDDIR)/latex."
+
+text:
+	$(SPHINXBUILD) -b text $(ALLSPHINXOPTS) $(BUILDDIR)/text
+	@echo
+	@echo "Build finished. The text files are in $(BUILDDIR)/text."
+
+man:
+	$(SPHINXBUILD) -b man $(ALLSPHINXOPTS) $(BUILDDIR)/man
+	@echo
+	@echo "Build finished. The manual pages are in $(BUILDDIR)/man."
+
+texinfo:
+	$(SPHINXBUILD) -b texinfo $(ALLSPHINXOPTS) $(BUILDDIR)/texinfo
+	@echo
+	@echo "Build finished. The Texinfo files are in $(BUILDDIR)/texinfo."
+	@echo "Run \`make' in that directory to run these through makeinfo" \
+	      "(use \`make info' here to do that automatically)."
+
+info:
+	$(SPHINXBUILD) -b texinfo $(ALLSPHINXOPTS) $(BUILDDIR)/texinfo
+	@echo "Running Texinfo files through makeinfo..."
+	make -C $(BUILDDIR)/texinfo info
+	@echo "makeinfo finished; the Info files are in $(BUILDDIR)/texinfo."
+
+gettext:
+	$(SPHINXBUILD) -b gettext $(I18NSPHINXOPTS) $(BUILDDIR)/locale
+	@echo
+	@echo "Build finished. The message catalogs are in $(BUILDDIR)/locale."
+
+changes:
+	$(SPHINXBUILD) -b changes $(ALLSPHINXOPTS) $(BUILDDIR)/changes
+	@echo
+	@echo "The overview file is in $(BUILDDIR)/changes."
+
+linkcheck:
+	$(SPHINXBUILD) -b linkcheck $(ALLSPHINXOPTS) $(BUILDDIR)/linkcheck
+	@echo
+	@echo "Link check complete; look for any errors in the above output " \
+	      "or in $(BUILDDIR)/linkcheck/output.txt."
+
+doctest:
+	$(SPHINXBUILD) -b doctest $(ALLSPHINXOPTS) $(BUILDDIR)/doctest
+	@echo "Testing of doctests in the sources finished, look at the " \
+	      "results in $(BUILDDIR)/doctest/output.txt."

docs/bit_server.rst

+bit_server Module
+=================
+
+.. automodule:: bit_server
+    :members:
+    :undoc-members:
+    :show-inheritance:
+# -*- coding: utf-8 -*-
+#
+# pylibftdi documentation build configuration file, created by
+# sphinx-quickstart on Mon Oct 31 22:36:38 2011.
+#
+# 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.
+
+import sys, os
+
+# 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.
+#sys.path.insert(0, os.path.abspath('.'))
+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.autodoc', 'sphinx.ext.viewcode']
+
+# Add any paths that contain templates here, relative to this directory.
+templates_path = ['_templates']
+
+# The suffix of source filenames.
+source_suffix = '.rst'
+
+# The encoding of source files.
+#source_encoding = 'utf-8-sig'
+
+# The master toctree document.
+master_doc = 'index'
+
+# General information about the project.
+project = u'pylibftdi'
+copyright = u'2011, Ben Bass'
+
+# 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 = '0.8.1'
+# The full version, including alpha/beta/rc tags.
+release = '0.8.1'
+
+# The language for content autogenerated by Sphinx. Refer to documentation
+# for a list of supported languages.
+#language = None
+
+# There are two options for replacing |today|: either, you set today to some
+# non-false value, then it is used:
+#today = ''
+# Else, today_fmt is used as the format for a strftime call.
+#today_fmt = '%B %d, %Y'
+
+# List of patterns, relative to source directory, that match files and
+# directories to ignore when looking for source files.
+exclude_patterns = ['_build']
+
+# The reST default role (used for this markup: `text`) to use for all documents.
+#default_role = None
+
+# If true, '()' will be appended to :func: etc. cross-reference text.
+#add_function_parentheses = True
+
+# If true, the current module name will be prepended to all description
+# unit titles (such as .. function::).
+#add_module_names = True
+
+# If true, sectionauthor and moduleauthor directives will be shown in the
+# output. They are ignored by default.
+#show_authors = False
+
+# The name of the Pygments (syntax highlighting) style to use.
+pygments_style = 'sphinx'
+
+# A list of ignored prefixes for module index sorting.
+#modindex_common_prefix = []
+
+
+# -- 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 = 'default'
+
+# 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 themes here, relative to this directory.
+#html_theme_path = []
+
+# The name for this set of Sphinx documents.  If None, it defaults to
+# "<project> v<release> documentation".
+#html_title = None
+
+# A shorter title for the navigation bar.  Default is the same as html_title.
+#html_short_title = None
+
+# The name of an image file (relative to this directory) to place at the top
+# of the sidebar.
+#html_logo = None
+
+# The name of an image file (within the static path) to use as favicon of the
+# docs.  This file should be a Windows icon file (.ico) being 16x16 or 32x32
+# pixels large.
+#html_favicon = None
+
+# 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']
+
+# If not '', a 'Last updated on:' timestamp is inserted at every page bottom,
+# using the given strftime format.
+#html_last_updated_fmt = '%b %d, %Y'
+
+# If true, SmartyPants will be used to convert quotes and dashes to
+# typographically correct entities.
+#html_use_smartypants = True
+
+# Custom sidebar templates, maps document names to template names.
+#html_sidebars = {}
+
+# Additional templates that should be rendered to pages, maps page names to
+# template names.
+#html_additional_pages = {}
+
+# If false, no module index is generated.
+#html_domain_indices = True
+
+# If false, no index is generated.
+#html_use_index = True
+
+# If true, the index is split into individual pages for each letter.
+#html_split_index = False
+
+# If true, links to the reST sources are added to the pages.
+#html_show_sourcelink = True
+
+# If true, "Created using Sphinx" is shown in the HTML footer. Default is True.
+#html_show_sphinx = True
+
+# If true, "(C) Copyright ..." is shown in the HTML footer. Default is True.
+#html_show_copyright = True
+
+# If true, an OpenSearch description file will be output, and all pages will
+# contain a <link> tag referring to it.  The value of this option must be the
+# base URL from which the finished HTML is served.
+#html_use_opensearch = ''
+
+# This is the file name suffix for HTML files (e.g. ".xhtml").
+#html_file_suffix = None
+
+# Output file base name for HTML help builder.
+htmlhelp_basename = 'pylibftdidoc'
+
+
+# -- 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': '',
+}
+
+# Grouping the document tree into LaTeX files. List of tuples
+# (source start file, target name, title, author, documentclass [howto/manual]).
+latex_documents = [
+  ('index', 'pylibftdi.tex', u'pylibftdi Documentation',
+   u'Ben Bass', 'manual'),
+]
+
+# The name of an image file (relative to this directory) to place at the top of
+# the title page.
+#latex_logo = None
+
+# For "manual" documents, if this is true, then toplevel headings are parts,
+# not chapters.
+#latex_use_parts = False
+
+# If true, show page references after internal links.
+#latex_show_pagerefs = False
+
+# If true, show URL addresses after external links.
+#latex_show_urls = False
+
+# Documents to append as an appendix to all manuals.
+#latex_appendices = []
+
+# If false, no module index is generated.
+#latex_domain_indices = True
+
+
+# -- Options for manual page output --------------------------------------------
+
+# One entry per manual page. List of tuples
+# (source start file, name, description, authors, manual section).
+man_pages = [
+    ('index', 'pylibftdi', u'pylibftdi Documentation',
+     [u'Ben Bass'], 1)
+]
+
+# If true, show URL addresses after external links.
+#man_show_urls = False
+
+
+# -- 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 = [
+  ('index', 'pylibftdi', u'pylibftdi Documentation', u'Ben Bass',
+   'pylibftdi', 'One line description of project.', 'Miscellaneous'),
+]
+
+# Documents to append as an appendix to all manuals.
+#texinfo_appendices = []
+
+# If false, no module index is generated.
+#texinfo_domain_indices = True
+
+# How to display URL addresses: 'footnote', 'no', or 'inline'.
+#texinfo_show_urls = 'footnote'
+.. pylibftdi documentation master file, created by
+   sphinx-quickstart on Mon Oct 31 22:36:38 2011.
+   You can adapt this file completely to your liking, but it should at least
+   contain the root `toctree` directive.
+
+Welcome to pylibftdi's documentation!
+=====================================
+
+Contents:
+
+.. toctree::
+   :maxdepth: 2
+
+   introduction
+   tutorial
+   pylibftdi
+
+Indices and tables
+==================
+
+* :ref:`genindex`
+* :ref:`modindex`
+* :ref:`search`
+

docs/introduction.rst

+Introduction
+============
+
+pylibftdi is a minimal Pythonic interface to FTDI devices using libftdi_.
+
+.. _libftdi: http://www.intra2net.com/en/developer/libftdi/
+
+:Features:
+
+ - Supports Python 2 and Python 3
+ - Supports parallel and serial devices
+ - Support for multiple devices
+ - File-like interface wherever appropriate
+ - Cross-platform
+
+:Limitations:
+
+ - Currently only one port per device is used; I've not tested with dual
+   port devices yet.
+ - The API might change prior to reaching a 1.0 release.
+
+Usage
+-----
+
+The primary interface is the ``Device`` class in the pylibftdi package; this
+gives serial access on relevant FTDI devices (e.g. the UM232R), providing a
+file-like interface (read, write).  Baudrate is controlled with the ``baudrate``
+property.
+
+If a Device instance is created with ``mode='t'`` (text mode) then read() and
+write() can use the given ``encoding`` (defaulting to latin-1). This doesn't
+make a lot of difference on Python 2 (and can be omitted), but allows easier
+integration with passing unicode strings between devices in Python 3.
+
+Multiple devices are supported by passing the desired device serial number (as
+a string) in the ``device_id`` parameter - this is the first parameter in both
+Device() and BitBangDevice() constructors. Alternatively the device 'description'
+can be given, and an attempt will be made to match this if matching by serial
+number fails.
+
+History & Motivation
+--------------------
+This package is the result of various bits of work using FTDI's
+devices, primarily for controlling external devices.  Some of this
+is documented on the codedstructure blog, codedstructure.blogspot.com
+
+At least two other open-source Python FTDI wrappers exist, and each
+of these may be best for some projects.
+
+ * ftd2xx_ - ctypes binding to FTDI's own D2XX driver
+ * pyftdi_ - a C extension libftdi binding
+ 
+.. _ftd2xx: http://pypi.python.org/pypi/ftd2xx
+.. _pyftdi: http://git.marcansoft.com/?p=pyftdi.git
+
+pylibftdi exists in the gap between these two projects; ftd2xx uses
+the (closed-source) D2XX driver, but provides a high-level Python
+interface, while pyftdi works with libftdi but is very low-level.
+The aim for pylibftdi is to work with the libftdi, but to provide
+a high-level Pythonic interface.  Various wrappers and utility
+functions are also part of the distribution; following Python's
+batteries included approach, there are various interesting devices
+supported out-of-the-box - or at least there will be soon!
+
+Plans
+-----
+ * Add more examples: SPI devices, knight-rider effects, input devices, MIDI...
+ * Perhaps add support for D2XX driver, though the name then becomes a
+   slight liability ;)
+ * General code quality improvements: solid unit tests, decent documentation.
+
+License
+-------
+
+Copyright (c) 2010-2011 Ben Bass <benbass@codedstructure.net>
+
+pylibftdi is released under the MIT licence; see the file "LICENSE.txt"
+for information.
+
+All trademarks referenced herein are property of their respective
+holders.
+libFTDI itself is developed by Intra2net AG.  No association with
+Intra2net is claimed or implied, but I have found their library
+helpful and had fun with it...
+
+lcd Module
+==========
+
+.. automodule:: lcd
+    :members:
+    :undoc-members:
+    :show-inheritance:

docs/led_flash.rst

+led_flash Module
+================
+
+.. automodule:: led_flash
+    :members:
+    :undoc-members:
+    :show-inheritance:

docs/list_devices.rst

+list_devices Module
+===================
+
+.. automodule:: list_devices
+    :members:
+    :undoc-members:
+    :show-inheritance:
+@ECHO OFF
+
+REM Command file for Sphinx documentation
+
+if "%SPHINXBUILD%" == "" (
+	set SPHINXBUILD=sphinx-build
+)
+set BUILDDIR=_build
+set ALLSPHINXOPTS=-d %BUILDDIR%/doctrees %SPHINXOPTS% .
+set I18NSPHINXOPTS=%SPHINXOPTS% .
+if NOT "%PAPER%" == "" (
+	set ALLSPHINXOPTS=-D latex_paper_size=%PAPER% %ALLSPHINXOPTS%
+	set I18NSPHINXOPTS=-D latex_paper_size=%PAPER% %I18NSPHINXOPTS%
+)
+
+if "%1" == "" goto help
+
+if "%1" == "help" (
+	:help
+	echo.Please use `make ^<target^>` where ^<target^> is one of
+	echo.  html       to make standalone HTML files
+	echo.  dirhtml    to make HTML files named index.html in directories
+	echo.  singlehtml to make a single large HTML file
+	echo.  pickle     to make pickle files
+	echo.  json       to make JSON files
+	echo.  htmlhelp   to make HTML files and a HTML help project
+	echo.  qthelp     to make HTML files and a qthelp project
+	echo.  devhelp    to make HTML files and a Devhelp project
+	echo.  epub       to make an epub
+	echo.  latex      to make LaTeX files, you can set PAPER=a4 or PAPER=letter
+	echo.  text       to make text files
+	echo.  man        to make manual pages
+	echo.  texinfo    to make Texinfo files
+	echo.  gettext    to make PO message catalogs
+	echo.  changes    to make an overview over all changed/added/deprecated items
+	echo.  linkcheck  to check all external links for integrity
+	echo.  doctest    to run all doctests embedded in the documentation if enabled
+	goto end
+)
+
+if "%1" == "clean" (
+	for /d %%i in (%BUILDDIR%\*) do rmdir /q /s %%i
+	del /q /s %BUILDDIR%\*
+	goto end
+)
+
+if "%1" == "html" (
+	%SPHINXBUILD% -b html %ALLSPHINXOPTS% %BUILDDIR%/html
+	if errorlevel 1 exit /b 1
+	echo.
+	echo.Build finished. The HTML pages are in %BUILDDIR%/html.
+	goto end
+)
+
+if "%1" == "dirhtml" (
+	%SPHINXBUILD% -b dirhtml %ALLSPHINXOPTS% %BUILDDIR%/dirhtml
+	if errorlevel 1 exit /b 1
+	echo.
+	echo.Build finished. The HTML pages are in %BUILDDIR%/dirhtml.
+	goto end
+)
+
+if "%1" == "singlehtml" (
+	%SPHINXBUILD% -b singlehtml %ALLSPHINXOPTS% %BUILDDIR%/singlehtml
+	if errorlevel 1 exit /b 1
+	echo.
+	echo.Build finished. The HTML pages are in %BUILDDIR%/singlehtml.
+	goto end
+)
+
+if "%1" == "pickle" (
+	%SPHINXBUILD% -b pickle %ALLSPHINXOPTS% %BUILDDIR%/pickle
+	if errorlevel 1 exit /b 1
+	echo.
+	echo.Build finished; now you can process the pickle files.
+	goto end
+)
+
+if "%1" == "json" (
+	%SPHINXBUILD% -b json %ALLSPHINXOPTS% %BUILDDIR%/json
+	if errorlevel 1 exit /b 1
+	echo.
+	echo.Build finished; now you can process the JSON files.
+	goto end
+)
+
+if "%1" == "htmlhelp" (
+	%SPHINXBUILD% -b htmlhelp %ALLSPHINXOPTS% %BUILDDIR%/htmlhelp
+	if errorlevel 1 exit /b 1
+	echo.
+	echo.Build finished; now you can run HTML Help Workshop with the ^
+.hhp project file in %BUILDDIR%/htmlhelp.
+	goto end
+)
+
+if "%1" == "qthelp" (
+	%SPHINXBUILD% -b qthelp %ALLSPHINXOPTS% %BUILDDIR%/qthelp
+	if errorlevel 1 exit /b 1
+	echo.
+	echo.Build finished; now you can run "qcollectiongenerator" with the ^
+.qhcp project file in %BUILDDIR%/qthelp, like this:
+	echo.^> qcollectiongenerator %BUILDDIR%\qthelp\pylibftdi.qhcp
+	echo.To view the help file:
+	echo.^> assistant -collectionFile %BUILDDIR%\qthelp\pylibftdi.ghc
+	goto end
+)
+
+if "%1" == "devhelp" (
+	%SPHINXBUILD% -b devhelp %ALLSPHINXOPTS% %BUILDDIR%/devhelp
+	if errorlevel 1 exit /b 1
+	echo.
+	echo.Build finished.
+	goto end
+)
+
+if "%1" == "epub" (
+	%SPHINXBUILD% -b epub %ALLSPHINXOPTS% %BUILDDIR%/epub
+	if errorlevel 1 exit /b 1
+	echo.
+	echo.Build finished. The epub file is in %BUILDDIR%/epub.
+	goto end
+)
+
+if "%1" == "latex" (
+	%SPHINXBUILD% -b latex %ALLSPHINXOPTS% %BUILDDIR%/latex
+	if errorlevel 1 exit /b 1
+	echo.
+	echo.Build finished; the LaTeX files are in %BUILDDIR%/latex.
+	goto end
+)
+
+if "%1" == "text" (
+	%SPHINXBUILD% -b text %ALLSPHINXOPTS% %BUILDDIR%/text
+	if errorlevel 1 exit /b 1
+	echo.
+	echo.Build finished. The text files are in %BUILDDIR%/text.
+	goto end
+)
+
+if "%1" == "man" (
+	%SPHINXBUILD% -b man %ALLSPHINXOPTS% %BUILDDIR%/man
+	if errorlevel 1 exit /b 1
+	echo.
+	echo.Build finished. The manual pages are in %BUILDDIR%/man.
+	goto end
+)
+
+if "%1" == "texinfo" (
+	%SPHINXBUILD% -b texinfo %ALLSPHINXOPTS% %BUILDDIR%/texinfo
+	if errorlevel 1 exit /b 1
+	echo.
+	echo.Build finished. The Texinfo files are in %BUILDDIR%/texinfo.
+	goto end
+)
+
+if "%1" == "gettext" (
+	%SPHINXBUILD% -b gettext %I18NSPHINXOPTS% %BUILDDIR%/locale
+	if errorlevel 1 exit /b 1
+	echo.
+	echo.Build finished. The message catalogs are in %BUILDDIR%/locale.
+	goto end
+)
+
+if "%1" == "changes" (
+	%SPHINXBUILD% -b changes %ALLSPHINXOPTS% %BUILDDIR%/changes
+	if errorlevel 1 exit /b 1
+	echo.
+	echo.The overview file is in %BUILDDIR%/changes.
+	goto end
+)
+
+if "%1" == "linkcheck" (
+	%SPHINXBUILD% -b linkcheck %ALLSPHINXOPTS% %BUILDDIR%/linkcheck
+	if errorlevel 1 exit /b 1
+	echo.
+	echo.Link check complete; look for any errors in the above output ^
+or in %BUILDDIR%/linkcheck/output.txt.
+	goto end
+)
+
+if "%1" == "doctest" (
+	%SPHINXBUILD% -b doctest %ALLSPHINXOPTS% %BUILDDIR%/doctest
+	if errorlevel 1 exit /b 1
+	echo.
+	echo.Testing of doctests in the sources finished, look at the ^
+results in %BUILDDIR%/doctest/output.txt.
+	goto end
+)
+
+:end
+pylibftdi
+=========
+
+.. toctree::
+   :maxdepth: 4
+
+   pylibftdi

docs/pylibftdi.examples.rst

+examples Package
+================
+
+:mod:`examples` Package
+-----------------------
+
+.. automodule:: pylibftdi.examples
+    :members:
+    :undoc-members:
+    :show-inheritance:
+
+:mod:`bit_server` Module
+------------------------
+
+.. automodule:: pylibftdi.examples.bit_server
+    :members:
+    :undoc-members:
+    :show-inheritance:
+
+:mod:`lcd` Module
+-----------------
+
+.. automodule:: pylibftdi.examples.lcd
+    :members:
+    :undoc-members:
+    :show-inheritance:
+
+:mod:`led_flash` Module
+-----------------------
+
+.. automodule:: pylibftdi.examples.led_flash
+    :members:
+    :undoc-members:
+    :show-inheritance:
+
+:mod:`list_devices` Module
+--------------------------
+
+.. automodule:: pylibftdi.examples.list_devices
+    :members:
+    :undoc-members:
+    :show-inheritance:
+

docs/pylibftdi.rst

+pylibftdi Package
+=================
+
+:mod:`pylibftdi` Package
+------------------------
+
+.. automodule:: pylibftdi.__init__
+    :members:
+    :undoc-members:
+    :show-inheritance:
+
+:mod:`_base` Module
+-------------------
+
+.. automodule:: pylibftdi._base
+    :members:
+    :undoc-members:
+    :show-inheritance:
+
+:mod:`bitbang` Module
+---------------------
+
+.. automodule:: pylibftdi.bitbang
+    :members:
+    :undoc-members:
+    :show-inheritance:
+
+:mod:`driver` Module
+--------------------
+
+.. automodule:: pylibftdi.driver
+    :members:
+    :undoc-members:
+    :show-inheritance:
+
+:mod:`test_bitbang` Module
+--------------------------
+
+.. automodule:: pylibftdi.test_bitbang
+    :members:
+    :undoc-members:
+    :show-inheritance:
+
+:mod:`test_common` Module
+-------------------------
+
+.. automodule:: pylibftdi.test_common
+    :members:
+    :undoc-members:
+    :show-inheritance:
+
+:mod:`test_driver` Module
+-------------------------
+
+.. automodule:: pylibftdi.test_driver
+    :members:
+    :undoc-members:
+    :show-inheritance:
+
+:mod:`util` Module
+------------------
+
+.. automodule:: pylibftdi.util
+    :members:
+    :undoc-members:
+    :show-inheritance:
+
+Subpackages
+-----------
+
+.. toctree::
+
+    pylibftdi.examples
+

docs/tutorial.rst

+Tutorial
+========
+
+pylibftdi is a minimal Pythonic interface to FTDI devices using libftdi_.
+
+.. _libftdi: http://www.intra2net.com/en/developer/libftdi/
+
+Usage
+-----
+
+The primary interface is the ``Device`` class in the pylibftdi package; this
+gives serial access on relevant FTDI devices (e.g. the UM232R), providing a
+file-like interface (read, write).  Baudrate is controlled with the ``baudrate``
+property.
+
+If a Device instance is created with ``mode='t'`` (text mode) then read() and
+write() can use the given ``encoding`` (defaulting to latin-1). This doesn't
+make a lot of difference on Python 2 (and can be omitted), but allows easier
+integration with passing unicode strings between devices in Python 3.
+
+Multiple devices are supported by passing the desired device serial number (as
+a string) in the ``device_id`` parameter - this is the first parameter in both
+Device() and BitBangDevice() constructors. Alternatively the device 'description'
+can be given, and an attempt will be made to match this if matching by serial
+number fails.
+
+Examples
+~~~~~~~~
+
+::
+
+    >>> from pylibftdi import Device
+    >>>
+    >>> with Device(mode='t') as dev:
+    ...     dev.baudrate = 115200
+    ...     dev.write('Hello World')
+
+The pylibftdi.BitBangDevice wrapper provides access to the parallel IO mode of
+operation through the ``port`` and ``direction`` properties.  These provide an
+8 bit IO port including all the relevant bit operations to make things simple.
+
+::
+
+    >>> from pylibftdi import BitBangDevice
+    >>>
+    >>> with BitBangDevice('FTE00P4L') as bb:
+    ...     bb.direction = 0x0F  # four LSB are output(1), four MSB are input(0)
+    ...     bb.port |= 2         # set bit 1
+    ...     bb.port &= 0xFE      # clear bit 0
+
+There is support for a number of external devices and protocols, specifically
+for interfacing with HD44780 LCDs using the 4-bit interface.
+

examples/bit_server.py

-"""
-bit_server.py - remote HTTP interface to bit-bangged FTDI port
-This runs as a web server, connect to port 8008
-
-Change HTTP_PORT for different port number or supply alternate as args[1]
-
-Requires:
- - pylibftdi
-"""
-
-from BaseHTTPServer import HTTPServer, BaseHTTPRequestHandler
-from cStringIO import StringIO
-from SocketServer import ThreadingMixIn
-import sys
-from pylibftdi import BitBangDevice
-
-HTTP_PORT = 8008
-
-
-class ThreadingServer(ThreadingMixIn, HTTPServer):
-    pass
-
-
-def get_page():
-    port = switch.port
-    page = """
-<!DOCTYPE html>
-<html>
-<head>
- <title>%s - pylibftdi</title>
-</head>
-<body>
-<div>
-""" % port
-    for i in range(8):
-        bit = 7-i
-        is_on = port & (1 << bit)
-        color = '#00FF00' if is_on else '#FF0000'
-        page += """
-<fieldset style="background-color: %s; display: inline-block; margin:0px; padding: 8px;">
-<form action="" method="post" >
-<input type="checkbox" onchange="document.querySelector('[name=bit%d]').value=this.value; document.forms[%d].submit()" %s />
-<input type="hidden" name="bit%d" />
-</form>
-</fieldset>
-""" % (color, bit, i, 'checked="checked"' if is_on else '', bit)
-    page += """
-</div>
-DATA=%s
-</body>
-</html>
-""" % port
-    return page
-
-class ReqHandler(BaseHTTPRequestHandler):
-    def do_GET(self):
-        f = self.send_head()
-        if f:
-            self.wfile.write(f.read())
-            f.close()
-
-    def do_POST(self):
-        length = self.headers.getheader('content-length')
-        nbytes = int(length)
-        query = self.rfile.read(nbytes)
-        # this is lazy and fragile - assumes only a single
-        # query parameter XXX
-        if query.startswith('bit'):
-            bit = int(query[3])
-            value = 1 if query.rsplit('=', 1)[-1] == 'on' else 0
-            if value:
-                switch.port |= (1 << bit)
-            else:
-                switch.port &= 255^(1 << bit)
-
-        f = self.send_head()
-        if f:
-            self.wfile.write(f.read())
-            f.close()
-
-    def send_head(self):
-        f = StringIO()
-        f.write(get_page())
-        length = f.tell()
-        f.seek(0)
-        self.send_response(200)
-        self.send_header("Content-type", "text/html")
-        self.send_header("Content-Length", str(length))
-        self.end_headers()
-        return f
-
-def runserver(port = HTTP_PORT):
-    serveraddr = ('', port)
-    srvr = ThreadingServer(serveraddr, ReqHandler)
-    srvr.serve_forever()
-
-if __name__ == '__main__':
-    import threading, time, webbrowser
-    switch = BitBangDevice()
-
-    try:
-        HTTP_PORT = int(sys.argv[1])
-    except TypeError:
-        print "Usage: FtdiWebServer [portnumber]"
-    except IndexError:
-        pass
-
-    t = threading.Thread(target = runserver, args = (HTTP_PORT,))
-    t.setDaemon(True)
-    t.start()
-    time.sleep(0.5)
-    retry = 10
-    while retry:
-        try:
-            webbrowser.open('http://localhost:%d'%HTTP_PORT)
-        except EnvironmentError:
-            time.sleep(1)
-            retry -= 1
-        else:
-            break
-
-    # wait for Ctrl-C
-    try:
-        while 1: time.sleep(1)
-    except KeyboardInterrupt:
-        pass

examples/lcd.py

-"""
-Write a string (argv[1] if run from command line) to a HD44780
-LCD module connected via a FTDI UM232R/245R module using pylibftdi
-
-example usage:
-
-# while true;
->   do python lcd.py $( awk '{print $1}' /proc/loadavg);
->   sleep 5;
-> done
-
-Copyright (c) 2010-2011 Ben Bass <benbass@codedstructure.net>
-All rights reserved.
-"""
-
-from pylibftdi import BitBangDevice, Bus
-
-
-class LCD(object):
-    """
-    The UM232R/245R is wired to the LCD as follows:
-       DB0..3 to LCD D4..D7 (pin 11..pin 14)
-       DB6 to LCD 'RS' (pin 4)
-       DB7 to LCD 'E' (pin 6)
-    """
-    data = Bus(0, 4)
-    rs = Bus(6)
-    e = Bus(7)
-
-    def __init__(self, driver):
-        # The Bus descriptor assumes we have a 'driver'
-        # attribute which provides a port
-        self.driver = driver
-
-    def init_four_bit(self):
-        """
-        set the LCD's 4 bit mode, since we only have
-        8 data lines and need at least 2 to strobe
-        data into the module and select between data
-        and commands.
-        """
-        self.rs = 0
-        self.data = 3
-        self.e = 1; self.e = 0
-        self.e = 1; self.e = 0
-        self.e = 1; self.e = 0
-        self.data = 2
-        self.e = 1; self.e = 0
-
-    def _write_raw(self, rs, x):
-        # rs determines whether this is a command
-        # or a data byte. Write the data as two
-        # nibbles. Ahhh... nibbles. QBasic anyone?
-        self.rs = rs
-        self.data = x >> 4
-        self.e = 1; self.e = 0
-        self.data = x & 0x0F
-        self.e = 1; self.e = 0
-
-    def write_cmd(self, x):
-        self._write_raw(0, x)
-
-    def write_data(self, x):
-        self._write_raw(1, x)
-
-def display(string, device_id=None):
-    """
-    Display the given string on an attached LCD
-    an optional `device_id` can be given.
-    """
-    with BitBangDevice(device_id) as bb:
-
-        # These LCDs are quite slow - and the actual baudrate
-        # is 16x this in bitbang mode...
-        bb.baudrate = 60
-
-        lcd = LCD(bb)
-        lcd.init_four_bit()
-
-        # 001xxxxx - function set
-        lcd.write_cmd(0x20)
-        # 00000001 - clear display
-        lcd.write_cmd(0x01)
-        # 000001xx - entry mode set
-        # bit 1: inc(1)/dec(0)
-        # bit 0: shift display
-        lcd.write_cmd(0x06)
-        # 00001xxx - display config
-        # bit 2: display on
-        # bit 1: display cursor
-        # bit 0: blinking cursor
-        lcd.write_cmd(0x0C)
-
-        for i in string:
-            lcd.write_data(ord(i))
-
-
-if __name__ == '__main__':
-    import sys
-    if len(sys.argv) == 2:
-        display(sys.argv[1])
-    else:
-        print("Usage: %s 'display string'")

examples/led_flash.py

-"""
-Flash an LED connected via a FTDI UM232R/245R module using pylibftdi
-
-Copyright (c) 2010-2011 Ben Bass <benbass@codedstructure.net>
-All rights reserved.
-"""
-
-import time
-from pylibftdi import BitBangDriver
-
-def flash_forever(rate):
-    "toggle bit zero at rate Hz"
-    # put an LED with 1Kohm or similar series resistor
-    # on D0 pin
-    with BitBangDriver() as bb:
-        while True:
-            time.sleep(1.0/(2*rate))
-            bb.port ^= 1
-
-if __name__ == '__main__':
-    flash_forever(1)

examples/list_devices.py

-
-from pylibftdi import Driver
-
-for device in Driver().list_devices():
-    print("%s:%s:%s"%(tuple(x.decode('latin1') for x in device)))

pylibftdi/__init__.py

 rather than a problem with the libftdi library.
 """
 
-__VERSION__ = "0.8.1"
+__VERSION__ = "0.9pre"
 __AUTHOR__ = "Ben Bass"
 
 

pylibftdi/examples/__init__.py

+"pylibftdi examples"

pylibftdi/examples/bit_server.py

+"""
+bit_server.py - remote HTTP interface to bit-bangged FTDI port
+This runs as a web server, connect to port 8008
+
+Change HTTP_PORT for different port number or supply alternate as args[1]
+
+Requires:
+ - pylibftdi
+"""
+
+from BaseHTTPServer import HTTPServer, BaseHTTPRequestHandler
+from cStringIO import StringIO
+from SocketServer import ThreadingMixIn
+import sys
+from pylibftdi import BitBangDevice
+
+HTTP_PORT = 8008
+
+
+class ThreadingServer(ThreadingMixIn, HTTPServer):
+    pass
+
+
+def get_page():
+    port = switch.port
+    page = """
+<!DOCTYPE html>
+<html>
+<head>
+ <title>%s - pylibftdi</title>
+</head>
+<body>
+<div>
+""" % port
+    for i in range(8):
+        bit = 7-i
+        is_on = port & (1 << bit)
+        color = '#00FF00' if is_on else '#FF0000'
+        page += """
+<fieldset style="background-color: %s; display: inline-block; margin:0px; padding: 8px;">
+<form action="" method="post" >
+<input type="checkbox" onchange="document.querySelector('[name=bit%d]').value=this.value; document.forms[%d].submit()" %s />
+<input type="hidden" name="bit%d" />
+</form>
+</fieldset>
+""" % (color, bit, i, 'checked="checked"' if is_on else '', bit)
+    page += """
+</div>
+DATA=%s
+</body>
+</html>
+""" % port
+    return page
+
+class ReqHandler(BaseHTTPRequestHandler):
+    def do_GET(self):
+        f = self.send_head()
+        if f:
+            self.wfile.write(f.read())
+            f.close()
+
+    def do_POST(self):
+        length = self.headers.getheader('content-length')
+        nbytes = int(length)
+        query = self.rfile.read(nbytes)
+        # this is lazy and fragile - assumes only a single
+        # query parameter XXX
+        if query.startswith('bit'):
+            bit = int(query[3])
+            value = 1 if query.rsplit('=', 1)[-1] == 'on' else 0
+            if value:
+                switch.port |= (1 << bit)
+            else:
+                switch.port &= 255^(1 << bit)
+
+        f = self.send_head()
+        if f:
+            self.wfile.write(f.read())
+            f.close()
+
+    def send_head(self):
+        f = StringIO()
+        f.write(get_page())
+        length = f.tell()
+        f.seek(0)
+        self.send_response(200)
+        self.send_header("Content-type", "text/html")
+        self.send_header("Content-Length", str(length))
+        self.end_headers()
+        return f
+
+def runserver(port = HTTP_PORT):
+    serveraddr = ('', port)
+    srvr = ThreadingServer(serveraddr, ReqHandler)
+    srvr.serve_forever()
+
+if __name__ == '__main__':
+    import threading, time, webbrowser
+    switch = BitBangDevice()
+
+    try:
+        HTTP_PORT = int(sys.argv[1])
+    except TypeError:
+        print "Usage: FtdiWebServer [portnumber]"
+    except IndexError:
+        pass
+
+    t = threading.Thread(target = runserver, args = (HTTP_PORT,))
+    t.setDaemon(True)
+    t.start()
+    time.sleep(0.5)
+    retry = 10
+    while retry:
+        try:
+            webbrowser.open('http://localhost:%d'%HTTP_PORT)
+        except EnvironmentError:
+            time.sleep(1)
+            retry -= 1
+        else:
+            break
+
+    # wait for Ctrl-C
+    try:
+        while 1: time.sleep(1)
+    except KeyboardInterrupt:
+        pass

pylibftdi/examples/lcd.py

+"""
+Write a string (argv[1] if run from command line) to a HD44780
+LCD module connected via a FTDI UM232R/245R module using pylibftdi
+
+example usage:
+
+# while true;
+>   do python lcd.py $( awk '{print $1}' /proc/loadavg);
+>   sleep 5;
+> done
+
+Copyright (c) 2010-2011 Ben Bass <benbass@codedstructure.net>
+All rights reserved.
+"""
+
+from pylibftdi import BitBangDevice, Bus
+
+
+class LCD(object):
+    """
+    The UM232R/245R is wired to the LCD as follows:
+       DB0..3 to LCD D4..D7 (pin 11..pin 14)
+       DB6 to LCD 'RS' (pin 4)
+       DB7 to LCD 'E' (pin 6)
+    """
+    data = Bus(0, 4)
+    rs = Bus(6)
+    e = Bus(7)
+
+    def __init__(self, driver):
+        # The Bus descriptor assumes we have a 'driver'
+        # attribute which provides a port
+        self.driver = driver
+
+    def init_four_bit(self):
+        """
+        set the LCD's 4 bit mode, since we only have
+        8 data lines and need at least 2 to strobe
+        data into the module and select between data
+        and commands.
+        """
+        self.rs = 0
+        self.data = 3
+        self.e = 1; self.e = 0
+        self.e = 1; self.e = 0
+        self.e = 1; self.e = 0
+        self.data = 2
+        self.e = 1; self.e = 0
+
+    def _write_raw(self, rs, x):
+        # rs determines whether this is a command
+        # or a data byte. Write the data as two
+        # nibbles. Ahhh... nibbles. QBasic anyone?
+        self.rs = rs
+        self.data = x >> 4
+        self.e = 1; self.e = 0
+        self.data = x & 0x0F
+        self.e = 1; self.e = 0
+
+    def write_cmd(self, x):
+        self._write_raw(0, x)
+
+    def write_data(self, x):
+        self._write_raw(1, x)
+
+def display(string, device_id=None):
+    """
+    Display the given string on an attached LCD
+    an optional `device_id` can be given.
+    """
+    with BitBangDevice(device_id) as bb:
+
+        # These LCDs are quite slow - and the actual baudrate
+        # is 16x this in bitbang mode...
+        bb.baudrate = 60
+
+        lcd = LCD(bb)
+        lcd.init_four_bit()
+
+        # 001xxxxx - function set
+        lcd.write_cmd(0x20)
+        # 00000001 - clear display
+        lcd.write_cmd(0x01)
+        # 000001xx - entry mode set
+        # bit 1: inc(1)/dec(0)
+        # bit 0: shift display
+        lcd.write_cmd(0x06)
+        # 00001xxx - display config
+        # bit 2: display on
+        # bit 1: display cursor
+        # bit 0: blinking cursor
+        lcd.write_cmd(0x0C)
+
+        for i in string:
+            lcd.write_data(ord(i))
+
+
+if __name__ == '__main__':
+    import sys
+    if len(sys.argv) == 2:
+        display(sys.argv[1])
+    else:
+        print("Usage: %s 'display string'")

pylibftdi/examples/led_flash.py

+"""
+Flash an LED connected via a FTDI UM232R/245R module using pylibftdi
+
+Copyright (c) 2010-2011 Ben Bass <benbass@codedstructure.net>
+All rights reserved.
+"""
+
+import time
+from pylibftdi import BitBangDriver
+
+def flash_forever(rate):
+    "toggle bit zero at rate Hz"
+    # put an LED with 1Kohm or similar series resistor
+    # on D0 pin
+    with BitBangDriver() as bb:
+        while True:
+            time.sleep(1.0/(2*rate))
+            bb.port ^= 1
+
+if __name__ == '__main__':
+    flash_forever(1)

pylibftdi/examples/list_devices.py

+
+from pylibftdi import Driver
+
+
+def get_devices():
+    dev_list = []
+    for device in Driver().list_devices():
+        dev_list.append("%s:%s:%s" % (tuple(x.decode('latin1') for x in device)))
+
+
+if __name__ == '__main__':
+    print('\n'.join(get_devices()))

pylibftdi/util.py

 class Bus(object):
     """
     This class is a descriptor for a bus of a given width starting
-    at a given offset (0 = LSB).  Thet driver which does the actual
+    at a given offset (0 = LSB).  The driver which does the actual
     reading and writing is assumed to be a BitBangDriver instance
     in the 'driver' attribute of the object to which this is attached.
     """
 
 setup(
     name="pylibftdi",
-    version="0.8.1",
+    version="0.9pre",
     description="Pythonic interface to FTDI devices using libftdi",
     long_description=open('README.txt').read(),
     author="Ben Bass",