Skip to main content

spigen device ioctl wrapper for FreeBSD

Project description

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_HIGH or IDLE_LOW
  • Clock phase can be either TRAILING_EDGE or LEADING_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)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pyfbsdspi-tspspi-0.0.1.tar.gz (3.1 kB view details)

Uploaded Source

Built Distribution

pyfbsdspi_tspspi-0.0.1-py3-none-any.whl (3.1 kB view details)

Uploaded Python 3

File details

Details for the file pyfbsdspi-tspspi-0.0.1.tar.gz.

File metadata

  • Download URL: pyfbsdspi-tspspi-0.0.1.tar.gz
  • Upload date:
  • Size: 3.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.0 CPython/3.8.13

File hashes

Hashes for pyfbsdspi-tspspi-0.0.1.tar.gz
Algorithm Hash digest
SHA256 d4c1ff4481e42d919d3b435dc6b70e09f1b6417c50024ef3993cb0a607bbbe48
MD5 41828dd6cb28087911409b8632bec5d5
BLAKE2b-256 9ab57129f6f809624108106ab191475cb1135dfe0d327694f1f0993c27e0dc37

See more details on using hashes here.

File details

Details for the file pyfbsdspi_tspspi-0.0.1-py3-none-any.whl.

File metadata

File hashes

Hashes for pyfbsdspi_tspspi-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 d4e2531e84c587c89168072ec0de3ad49a75d576c02afb3859e8833d1f7eab8b
MD5 20b6902e32e0c312552cbafa0f459dfb
BLAKE2b-256 21f51d6eda5e5cda77a0506a9c0289cffa755d91da5f265017ed7654bfaed715

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page