FreeBSD SPI wrapper for Python
The pyfbsdspi-tspspi project contains a very thin wrapper
around the ioctl requests for the spigen device
on FreeBSD to test various hardware devices from Python. It allows
direct access to the SPI bus on devices like the RaspberryPi when running
under FreeBSD.
Installation
pip install pyfbsdspi-tspspi
Usage
The bus can be instantiated either using context management or by it's
constructor. One can select the bus via it's first constructor
argument (spiDevname):
from fbsdspi import FbsdSPI
from labdevs.spibus import SPIClockPolarity, SPIClockPhase
To instantiate via context management one can use:
with FbsdSPI() as spi:
# Use spi. ....
To instantiate without context mangement:
spi = FbsdSPI()
# Use spi ...
In case one wants to open a different bus device - for example spigen0.1
which would be the second SPI bus on a RaspberryPi one can simply specify the
name as first argument (spiDevname)
with FbsdSPI('/dev/spigen0.1') as spi1:
# spi1. ...
Or without context management:
spi0 = FbsdSPI('/dev/spigen0.0')
spi1 = FbsdSPI('/dev/spigen0.1')
Setting and querying bus clock speed
To query the bus speed one can use the getClockSpeed() method. This yields
the SPI clock frequency in Hz:
print(f"Current clock speed is {spi.getClockSpeed()} Hz")
To set the clock the counterpart setClockSpeed can be used. Again note that
this requires an integer argument in Hz:
spi.setClockSpeed(100000)
Setting and getting the bus mode
As for any SPI abstraction library one can also set the four possible bus modes:
- Clock polarity can be either
IDLE_HIGHorIDLE_LOW - Clock phase can be either
TRAILING_EDGEorLEADING_EDGE
spi.setMode(
clockPolarity = SPIClockPolarity.IDLE_HIGH,
clockPhase = SPIClockPhase.TRAILING_EDGE
)
To query the current mode one can use the getMode API:
print(f"Current mode: {spi.getMode()}")
# Return the tuple (SPIClockPhase, SPIClockPolarity)
Metadata
Release files for pyfbsdspi-tspspi 0.0.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| pyfbsdspi-tspspi-0.0.1.tar.gz | 3.1 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| pyfbsdspi_tspspi-0.0.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 6.2 kB
Release files / pyfbsdspi-tspspi-0.0.1.tar.gz
| Download URL | pyfbsdspi-tspspi-0.0.1.tar.gz |
|---|---|
| Size | 3.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
d4c1ff4481e42d919d3b435dc6b70e09f1b6417c50024ef3993cb0a607bbbe48
|
|
BLAKE2b-256 checksum How to use checksums |
9ab57129f6f809624108106ab191475cb1135dfe0d327694f1f0993c27e0dc37
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.0 CPython/3.8.13
|
Release files / pyfbsdspi_tspspi-0.0.1-py3-none-any.whl
| Download URL | pyfbsdspi_tspspi-0.0.1-py3-none-any.whl |
|---|---|
| Size | 3.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
d4e2531e84c587c89168072ec0de3ad49a75d576c02afb3859e8833d1f7eab8b
|
|
BLAKE2b-256 checksum How to use checksums |
21f51d6eda5e5cda77a0506a9c0289cffa755d91da5f265017ed7654bfaed715
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.0 CPython/3.8.13
|