spi

package
v1.7.1 Latest Latest
Warning

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

Go to latest
Published: Nov 5, 2017 License: Apache-2.0 Imports: 2 Imported by: 0

README

SPI

This package provides drivers for spi devices. It currently must be used along with the raspberry pi adaptor that supports the needed interfaces for spi devices. This uses the experimental spi package which only works on linux systems.

Getting Started

Installing

go get -d -u gobot.io/x/gobot/...

Hardware Support

Gobot has a extensible system for connecting to hardware devices.

The following spi Devices are currently supported:

  • GoPiGo3 Robot

Drivers wanted! :)

The following spi Adaptors are currently supported:

  • Raspberry Pi

Adaptors wanted too!

Documentation

Overview

Package spi provides Gobot drivers for spi devices. Uses "golang.org/x/exp/io/spi" for spi Installing:

go get -d -u gobot.io/x/gobot

For further information refer to spi README: https://github.com/hybridgroup/gobot/blob/master/drivers/spi/README.md

Index

Constants

View Source
const (
	// BusNotInitialized is the initial value for a bus
	BusNotInitialized = -1
)

Variables

This section is empty.

Functions

func WithBus

func WithBus(bus int) func(Config)

WithBus sets which bus to use as a optional param.

Types

type Config

type Config interface {
	// WithBus sets which bus to use
	WithBus(bus int)

	// GetBusOrDefault gets which bus to use
	GetBusOrDefault(def int) int
}

Config is the interface which describes how a Driver can specify optional SPI params such as which SPI bus it wants to use.

func NewConfig

func NewConfig() Config

NewConfig returns a new SPI Config.

type Connection

type Connection SPIOperations

Connection is a connection to an SPI device with a specified address on a specific bus. Used as an alternative to the SPI interface. Implements SPIOperations to talk to the device, wrapping the calls in SetAddress to always target the specified device. Provided by an Adaptor by implementing the SPIConnector interface.

type Connector

type Connector interface {
	// GetConnection returns a connection to device at the specified bus.
	// Bus numbering starts at index 0, the range of valid buses is
	// platform specific.
	GetSpiConnection(busNum, mode int, maxSpeed int64) (device Connection, err error)

	// GetDefaultBus returns the default SPI bus index
	GetSpiDefaultBus() int

	// GetDefaultMode returns the default SPI mode (0/1/2/3)
	GetSpiDefaultMode() int

	// GetSpiDefaultMaxSpeed returns the max SPI speed
	GetSpiDefaultMaxSpeed() int64
}

Connector lets Adaptors provide the interface for Drivers to get access to the SPI buses on platforms that support SPI.

type SPIDevice

type SPIDevice interface {
	SPIOperations
}

SPIDevice is the interface to a specific spi bus

type SPIOperations

type SPIOperations interface {
	Close() error
	SetBitOrder(o xspi.Order) error
	SetBitsPerWord(bits int) error
	SetCSChange(leaveEnabled bool) error
	SetDelay(t time.Duration) error
	SetMaxSpeed(speed int) error
	SetMode(mode xspi.Mode) error
	Tx(w, r []byte) error
}

type SpiConnection

type SpiConnection struct {
	// contains filtered or unexported fields
}

func NewConnection

func NewConnection(bus SPIDevice) (connection *SpiConnection)

NewConnection creates and returns a new connection to a specific spi device on a bus and address

func (*SpiConnection) Close

func (c *SpiConnection) Close() error

func (*SpiConnection) SetBitOrder

func (c *SpiConnection) SetBitOrder(o xspi.Order) error

func (*SpiConnection) SetBitsPerWord

func (c *SpiConnection) SetBitsPerWord(bits int) error

func (*SpiConnection) SetCSChange

func (c *SpiConnection) SetCSChange(leaveEnabled bool) error

func (*SpiConnection) SetDelay

func (c *SpiConnection) SetDelay(t time.Duration) error

func (*SpiConnection) SetMaxSpeed

func (c *SpiConnection) SetMaxSpeed(speed int) error

func (*SpiConnection) SetMode

func (c *SpiConnection) SetMode(mode xspi.Mode) error

func (*SpiConnection) Tx

func (c *SpiConnection) Tx(w, r []byte) error

Jump to

Keyboard shortcuts

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