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 hashes)

Uploaded Source

Built Distribution

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

Uploaded Python 3

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