spi

package
v0.0.0-...-53472a3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 28, 2024 License: MIT Imports: 2 Imported by: 0

Documentation

Overview

Package spi provides an example bit-bashed spi driver.

The intent of the package is to demonstrate using GPIO pins to implement bit-bashed interfaces for prototyping.

The package is not related to the SPI device drivers provided by the Linux kernel. Kernel device drivers are the preferred solution for production applications.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Option

type Option func(*SPI)

Option specifies a construction option for the SPI.

func WithCPHA

func WithCPHA(cpha int) Option

WithCPHA sets the cpha for the SPI.

func WithCPOL

func WithCPOL(cpol int) Option

WithCPOL sets the cpol for the SPI.

func WithTclk

func WithTclk(tclk time.Duration) Option

WithTclk sets the clock period for the SPI.

Note that this is the half-cycle period.

type SPI

type SPI struct {
	// time between clock edges (i.e. half the cycle time)
	Tclk time.Duration

	// Clock line
	Sclk *gpiod.Line

	// Slave select - active low
	Ssz *gpiod.Line

	// Master-out slave-in
	Mosi *gpiod.Line

	// Master-in slave-out
	Miso *gpiod.Line
	// contains filtered or unexported fields
}

SPI represents a device connected an SPI bus using 4 GPIO lines.

This is the basis for bit bashed SPI interfaces using GPIO pins. It is not related to the SPI device drivers provided by the Linux kernel.

func New

func New(c *gpiod.Chip, sclk, ssz, mosi, miso int, options ...Option) (*SPI, error)

New creates a SPI.

func (*SPI) ClockIn

func (s *SPI) ClockIn() (int, error)

ClockIn clocks in a data bit from the SPI device on Miso.

Starts and ends just after the falling edge of the clock.

func (*SPI) ClockOut

func (s *SPI) ClockOut(v int) error

ClockOut clocks out a data bit to the SPI device on Mosi.

Starts and ends just after the falling edge of the clock.

func (*SPI) Close

func (s *SPI) Close()

Close releases allocated resources and reverts all output lines to inputs.

Directories

Path Synopsis
Package adc0832 provides a bit bashed device driver ADC0832s.
Package adc0832 provides a bit bashed device driver ADC0832s.
Package mcp3w0c provides bit bashed device drivers for MCP3004/3008/3204/3208 SPI ADCs.
Package mcp3w0c provides bit bashed device drivers for MCP3004/3008/3204/3208 SPI ADCs.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL