| | |
- __builtin__.object
-
- BaseSPIBus
-
- BaseHardwareSPIBus
class BaseHardwareSPIBus(BaseSPIBus) |
| |
A class for creating SPI buses using hardware peripherals.
BaseHardwareSPIBus implements methods to interact with hardware
implementations of SPI buses.
Attributes:
_port: The SPI device port number.
_device: The SPI device used for the bus. |
| |
- Method resolution order:
- BaseHardwareSPIBus
- BaseSPIBus
- __builtin__.object
Methods defined here:
- __init__(self, port, device)
- Creates a BaseHardwareSPIBus.
Args:
port: Integer. The port to use for the SPI bus.
device: Integer. The device to use for the SPI bus.
Data descriptors defined here:
- device
- Gets the current SPI bus device.
Returns:
The current SPI bus device.
- port
- Gets the SPI device port.
Returns:
The current port used by the SPI bus.
Data and other attributes defined here:
- __abstractmethods__ = frozenset(['_close', '_open', '_set_bit_order', '_set_clock_frequency_hz', '_set_mode', 'read', ...])
Methods inherited from BaseSPIBus:
- close(self)
- Closes the SPI bus.
- open(self)
- Opens the SPI bus.
- read(self, length)
- Reads at most length bytes from the SPI bus.
This method should be implemented by the platform.
Args:
length: Integer. The maximum number of bytes to read from the SPI bus.
- set_bit_order(self, order)
- Sets the SPI bus bit order.
Args:
order: MSB_FIRST or LSB_FIRST. The bit order to set the SPI bus to.
Raises:
ValueError: Thrown if the order is not one of MSB_FIRST or LSB_FIRST.
RuntimeError: Thrown if the bus isn't open.
- set_clock_frequency_hz(self, frequency_hz)
- Sets the clock freqency used by the SPI bus.
Args:
freqency_hz: Float. The frequency to set the SPI bus clock to.
Raises:
ValueError: Thrown if the frequency is less than 0.
RuntimeError: Thrown if the bus isn't open.
- set_mode(self, mode)
- Sets the SPI bus mode.
Args:
mode: Integer between 0 and 3. The mode to set the SPI bus to.
Raises:
ValueError: Thrown if the mode is not between 0 and 3.
RuntimeError: Thrown if the bus isn't open.
- write(self, data)
- Writes data to the SPI bus.
This method should be implemented by the platform.
Args:
data: Bytearray. Data to write over the SPI bus.
Data descriptors inherited from BaseSPIBus:
- __dict__
- dictionary for instance variables (if defined)
- __weakref__
- list of weak references to the object (if defined)
- bit_order
- clock_frequency_hz
- Returns the current SPI bus clock frequency.
Returns:
The current SPI bus clock frequency as a float.
- is_open
- Checks if the SPI bus is open or not.
Returns:
True if the SPI bus is open, False otherwise.
- mode
- Returns the current SPI bus mode.
Returns:
The current SPI bus mode as an integer.
Data and other attributes inherited from BaseSPIBus:
- LSB_FIRST = 1
- MSB_FIRST = 0
- __metaclass__ = <class 'abc.ABCMeta'>
- Metaclass for defining Abstract Base Classes (ABCs).
Use this metaclass to create an ABC. An ABC can be subclassed
directly, and then acts as a mix-in class. You can also register
unrelated concrete classes (even built-in classes) and unrelated
ABCs as 'virtual subclasses' -- these and their descendants will
be considered subclasses of the registering ABC by the built-in
issubclass() function, but the registering ABC won't show up in
their MRO (Method Resolution Order) nor will method
implementations defined by the registering ABC be callable (not
even via super()).
|
class BaseSPIBus(__builtin__.object) |
| |
A class for creating SPI bus peripherals.
BaseSPIBus implements methods to interact with an SPI peripheral. Platforms
are expected to subclass BaseSPIBus and provide platform specific
implementations of _open, _close, _set_clock_frequency_hz, _set_mode,
_set_bit_order, write, and read.
Attributes:
_is_open: Boolean. Whether or not the SPI bus is open.
_clock_frequency_hz: Float. The SPI bus clock frequency.
_mode: Integer between 0 and 3. The SPI bus mode.
_bit_order: MSB_FIRST or LSB_FIRST. The bit order of the SPI bus. |
| |
Methods defined here:
- __init__(self)
- Creates an SPI bus.
- close(self)
- Closes the SPI bus.
- open(self)
- Opens the SPI bus.
- read(self, length)
- Reads at most length bytes from the SPI bus.
This method should be implemented by the platform.
Args:
length: Integer. The maximum number of bytes to read from the SPI bus.
- set_bit_order(self, order)
- Sets the SPI bus bit order.
Args:
order: MSB_FIRST or LSB_FIRST. The bit order to set the SPI bus to.
Raises:
ValueError: Thrown if the order is not one of MSB_FIRST or LSB_FIRST.
RuntimeError: Thrown if the bus isn't open.
- set_clock_frequency_hz(self, frequency_hz)
- Sets the clock freqency used by the SPI bus.
Args:
freqency_hz: Float. The frequency to set the SPI bus clock to.
Raises:
ValueError: Thrown if the frequency is less than 0.
RuntimeError: Thrown if the bus isn't open.
- set_mode(self, mode)
- Sets the SPI bus mode.
Args:
mode: Integer between 0 and 3. The mode to set the SPI bus to.
Raises:
ValueError: Thrown if the mode is not between 0 and 3.
RuntimeError: Thrown if the bus isn't open.
- write(self, data)
- Writes data to the SPI bus.
This method should be implemented by the platform.
Args:
data: Bytearray. Data to write over the SPI bus.
Data descriptors defined here:
- __dict__
- dictionary for instance variables (if defined)
- __weakref__
- list of weak references to the object (if defined)
- bit_order
- clock_frequency_hz
- Returns the current SPI bus clock frequency.
Returns:
The current SPI bus clock frequency as a float.
- is_open
- Checks if the SPI bus is open or not.
Returns:
True if the SPI bus is open, False otherwise.
- mode
- Returns the current SPI bus mode.
Returns:
The current SPI bus mode as an integer.
Data and other attributes defined here:
- LSB_FIRST = 1
- MSB_FIRST = 0
- __abstractmethods__ = frozenset(['_close', '_open', '_set_bit_order', '_set_clock_frequency_hz', '_set_mode', 'read', ...])
- __metaclass__ = <class 'abc.ABCMeta'>
- Metaclass for defining Abstract Base Classes (ABCs).
Use this metaclass to create an ABC. An ABC can be subclassed
directly, and then acts as a mix-in class. You can also register
unrelated concrete classes (even built-in classes) and unrelated
ABCs as 'virtual subclasses' -- these and their descendants will
be considered subclasses of the registering ABC by the built-in
issubclass() function, but the registering ABC won't show up in
their MRO (Method Resolution Order) nor will method
implementations defined by the registering ABC be callable (not
even via super()).
| |