mirror of
https://github.com/KevinMidboe/python-gpiozero.git
synced 2025-10-29 17:50:37 +00:00
This PR adds a software SPI implementation. Firstly this removes the absolute necessity for spidev (#140), which also means when it's not present things still work (effectively fixes #185), and also enables any four pins to be used for SPI devices (which don't require the hardware implementation). The software implementation is simplistic but still supports clock polarity and phase, select-high, and variable bits per word. However it doesn't allow precise speeds to be implemented because it just wibbles the clock as fast as it can (which being pure Python isn't actually that fast). Finally, because this PR involves creating a framework for "shared" devices (like SPI devices with multiple channels), it made sense to bung Energenie (#69) in as wells as this is a really simple shared device.
This commit is contained in:
@@ -4,15 +4,22 @@ Generic Devices
|
||||
|
||||
.. currentmodule:: gpiozero
|
||||
|
||||
The GPIO Zero class hierarchy is quite extensive. It contains a couple of base
|
||||
The GPIO Zero class hierarchy is quite extensive. It contains several base
|
||||
classes:
|
||||
|
||||
* :class:`GPIODevice` for individual devices that attach to a single GPIO pin
|
||||
* :class:`Device` is the root of the hierarchy, implementing base functionality
|
||||
like :meth:`~Device.close` and context manager handlers.
|
||||
|
||||
* :class:`CompositeDevice` for devices composed of multiple other devices like
|
||||
HATs
|
||||
* :class:`GPIODevice` represents individual devices that attach to a single
|
||||
GPIO pin
|
||||
|
||||
There are also a couple of `mixin classes`_:
|
||||
* :class:`SPIDevice` represents devices that communicate over an SPI interface
|
||||
(implemented as four GPIO pins)
|
||||
|
||||
* :class:`CompositeDevice` represents devices composed of multiple other
|
||||
devices like HATs
|
||||
|
||||
There are also several `mixin classes`_:
|
||||
|
||||
* :class:`ValuesMixin` which defines the ``values`` properties; there is rarely
|
||||
a need to use this as the base classes mentioned above both include it
|
||||
@@ -21,13 +28,27 @@ There are also a couple of `mixin classes`_:
|
||||
* :class:`SourceMixin` which defines the ``source`` property; this is generally
|
||||
included in novel output device classes
|
||||
|
||||
* :class:`SharedMixin` which causes classes to track their construction and
|
||||
return existing instances when equivalent constructor arguments are passed
|
||||
|
||||
.. _mixin classes: https://en.wikipedia.org/wiki/Mixin
|
||||
|
||||
The current class hierarchies are displayed below. For brevity, the mixin
|
||||
classes are omitted:
|
||||
classes (and some other details) are omitted, and the chart is broken into
|
||||
pieces by base class. The lighter boxes represent classes that are "effectively
|
||||
abstract". These classes aren't directly useful without sub-classing them and
|
||||
adding bits.
|
||||
|
||||
First, the classes below :class:`GPIODevice`:
|
||||
|
||||
.. image:: images/gpio_device_hierarchy.*
|
||||
|
||||
Next, the classes below :class:`SPIDevice`:
|
||||
|
||||
.. image:: images/spi_device_hierarchy.*
|
||||
|
||||
Next, the classes below :class:`CompositeDevice`:
|
||||
|
||||
.. image:: images/composite_device_hierarchy.*
|
||||
|
||||
Finally, for composite devices, the following chart shows which devices are
|
||||
@@ -38,12 +59,16 @@ composed of which other devices:
|
||||
Base Classes
|
||||
============
|
||||
|
||||
.. autoclass:: Device
|
||||
:members: close, closed
|
||||
|
||||
.. autoclass:: GPIODevice(pin)
|
||||
:inherited-members:
|
||||
:members:
|
||||
|
||||
.. autoclass:: CompositeDevice
|
||||
:inherited-members:
|
||||
:members:
|
||||
|
||||
.. autoclass:: SPIDevice
|
||||
:members:
|
||||
|
||||
Input Devices
|
||||
@@ -61,19 +86,34 @@ Input Devices
|
||||
.. autoclass:: SmoothedInputDevice
|
||||
:members:
|
||||
|
||||
.. autoclass:: AnalogInputDevice
|
||||
:members:
|
||||
|
||||
Output Devices
|
||||
==============
|
||||
|
||||
.. autoclass:: OutputDevice(pin, active_high=True, initial_value=False)
|
||||
:members:
|
||||
|
||||
.. autoclass:: DigitalOutputDevice(pin, active_high=True, initial_value=False)
|
||||
:members:
|
||||
|
||||
.. autoclass:: PWMOutputDevice(pin, active_high=True, initial_value=0, frequency=100)
|
||||
:members:
|
||||
|
||||
.. autoclass:: DigitalOutputDevice(pin, active_high=True, initial_value=False)
|
||||
SPI Devices
|
||||
===========
|
||||
|
||||
.. autoclass:: SPIDevice
|
||||
:members:
|
||||
|
||||
.. autoclass:: AnalogInputDevice
|
||||
:members:
|
||||
|
||||
Composite Devices
|
||||
=================
|
||||
|
||||
.. autoclass:: CompositeOutputDevice
|
||||
:members:
|
||||
|
||||
.. autoclass:: LEDCollection
|
||||
:members:
|
||||
|
||||
Mixin Classes
|
||||
@@ -85,3 +125,6 @@ Mixin Classes
|
||||
.. autoclass:: SourceMixin(...)
|
||||
:members:
|
||||
|
||||
.. autoclass:: SharedMixin(...)
|
||||
:members: _shared_key
|
||||
|
||||
|
||||
Reference in New Issue
Block a user