spi

package
v1.8.0 Latest Latest
Warning

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

Go to latest
Published: Dec 21, 2017 License: Apache-2.0 Imports: 7 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:

  • APA102 Programmable LEDs
  • MCP3002 Analog/Digital Converter
  • MCP3004 Analog/Digital Converter
  • MCP3008 Analog/Digital Converter
  • MCP3202 Analog/Digital Converter
  • MCP3204 Analog/Digital Converter
  • MCP3208 Analog/Digital Converter
  • MCP3304 Analog/Digital Converter
  • 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
)
View Source
const MCP3002DriverMaxChannel = 2

MCP3002DriverMaxChannel is the number of channels of this A/D converter.

View Source
const MCP3004DriverMaxChannel = 3

MCP3004DriverMaxChannel is the number of channels of this A/D converter.

View Source
const MCP3008DriverMaxChannel = 8

MCP3008DriverMaxChannel is the number of channels of this A/D converter.

View Source
const MCP3202DriverMaxChannel = 2

MCP3202DriverMaxChannel is the number of channels of this A/D converter.

View Source
const MCP3204DriverMaxChannel = 4

MCP3204DriverMaxChannel is the number of channels of this A/D converter.

View Source
const MCP3208DriverMaxChannel = 8

MCP3208DriverMaxChannel is the number of channels of this A/D converter.

View Source
const MCP3304DriverMaxChannel = 8

MCP3304DriverMaxChannel is the number of channels of this A/D converter.

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 APA102Driver added in v1.8.0

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

APA102Driver is a driver for the APA102 programmable RGB LEDs

func NewAPA102Driver added in v1.8.0

func NewAPA102Driver(a Connector, count int) *APA102Driver

NewAPA102Driver creates a new Gobot Driver for APA102 RGB LEDs.

Params:

     a *Adaptor - the Adaptor to use with this Driver
		count int - how many LEDs are in the array controlled by this driver

func (*APA102Driver) Connection added in v1.8.0

func (d *APA102Driver) Connection() gobot.Connection

Connection returns the Connection of the device.

func (*APA102Driver) Draw added in v1.8.0

func (d *APA102Driver) Draw() error

Draw displays the RGBA values set on the actual LED strip.

func (*APA102Driver) Halt added in v1.8.0

func (d *APA102Driver) Halt() (err error)

Halt stops the driver.

func (*APA102Driver) Name added in v1.8.0

func (d *APA102Driver) Name() string

Name returns the name of the device.

func (*APA102Driver) SetName added in v1.8.0

func (d *APA102Driver) SetName(n string)

SetName sets the name of the device.

func (*APA102Driver) SetRGBA added in v1.8.0

func (d *APA102Driver) SetRGBA(i int, v color.RGBA)

SetRGBA sets the ith LED's color to the given RGBA value. A subsequent call to Draw is required to transmit values to the LED strip.

func (*APA102Driver) Start added in v1.8.0

func (d *APA102Driver) Start() (err error)

Start initializes the driver.

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 MCP3002Driver added in v1.8.0

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

MCP3002Driver is a driver for the MCP3002 A/D converter.

func NewMCP3002Driver added in v1.8.0

func NewMCP3002Driver(a Connector) *MCP3002Driver

NewMCP3002Driver creates a new Gobot Driver for MCP3002 A/D converter

Params:

a *Adaptor - the Adaptor to use with this Driver

func (*MCP3002Driver) AnalogRead added in v1.8.0

func (d *MCP3002Driver) AnalogRead(pin string) (value int, err error)

AnalogRead returns value from analog reading of specified pin

func (*MCP3002Driver) Connection added in v1.8.0

func (d *MCP3002Driver) Connection() gobot.Connection

Connection returns the Connection of the device.

func (*MCP3002Driver) Halt added in v1.8.0

func (d *MCP3002Driver) Halt() (err error)

Halt stops the driver.

func (*MCP3002Driver) Name added in v1.8.0

func (d *MCP3002Driver) Name() string

Name returns the name of the device.

func (*MCP3002Driver) Read added in v1.8.0

func (d *MCP3002Driver) Read(channel int) (result int, err error)

Read reads the current analog data for the desired channel.

func (*MCP3002Driver) SetName added in v1.8.0

func (d *MCP3002Driver) SetName(n string)

SetName sets the name of the device.

func (*MCP3002Driver) Start added in v1.8.0

func (d *MCP3002Driver) Start() (err error)

Start initializes the driver.

type MCP3004Driver added in v1.8.0

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

MCP3004Driver is a driver for the MCP3008 A/D converter.

func NewMCP3004Driver added in v1.8.0

func NewMCP3004Driver(a Connector) *MCP3004Driver

NewMCP3004Driver creates a new Gobot Driver for MCP3004 A/D converter

Params:

a *Adaptor - the Adaptor to use with this Driver

func (*MCP3004Driver) AnalogRead added in v1.8.0

func (d *MCP3004Driver) AnalogRead(pin string) (value int, err error)

AnalogRead returns value from analog reading of specified pin

func (*MCP3004Driver) Connection added in v1.8.0

func (d *MCP3004Driver) Connection() gobot.Connection

Connection returns the Connection of the device.

func (*MCP3004Driver) Halt added in v1.8.0

func (d *MCP3004Driver) Halt() (err error)

Halt stops the driver.

func (*MCP3004Driver) Name added in v1.8.0

func (d *MCP3004Driver) Name() string

Name returns the name of the device.

func (*MCP3004Driver) Read added in v1.8.0

func (d *MCP3004Driver) Read(channel int) (result int, err error)

Read reads the current analog data for the desired channel.

func (*MCP3004Driver) SetName added in v1.8.0

func (d *MCP3004Driver) SetName(n string)

SetName sets the name of the device.

func (*MCP3004Driver) Start added in v1.8.0

func (d *MCP3004Driver) Start() (err error)

Start initializes the driver.

type MCP3008Driver added in v1.8.0

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

MCP3008Driver is a driver for the MCP3008 A/D converter.

func NewMCP3008Driver added in v1.8.0

func NewMCP3008Driver(a Connector) *MCP3008Driver

NewMCP3008Driver creates a new Gobot Driver for MCP3008Driver A/D converter

Params:

a *Adaptor - the Adaptor to use with this Driver

func (*MCP3008Driver) AnalogRead added in v1.8.0

func (d *MCP3008Driver) AnalogRead(pin string) (value int, err error)

AnalogRead returns value from analog reading of specified pin

func (*MCP3008Driver) Connection added in v1.8.0

func (d *MCP3008Driver) Connection() gobot.Connection

Connection returns the Connection of the device.

func (*MCP3008Driver) Halt added in v1.8.0

func (d *MCP3008Driver) Halt() (err error)

Halt stops the driver.

func (*MCP3008Driver) Name added in v1.8.0

func (d *MCP3008Driver) Name() string

Name returns the name of the device.

func (*MCP3008Driver) Read added in v1.8.0

func (d *MCP3008Driver) Read(channel int) (result int, err error)

Read reads the current analog data for the desired channel.

func (*MCP3008Driver) SetName added in v1.8.0

func (d *MCP3008Driver) SetName(n string)

SetName sets the name of the device.

func (*MCP3008Driver) Start added in v1.8.0

func (d *MCP3008Driver) Start() (err error)

Start initializes the driver.

type MCP3202Driver added in v1.8.0

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

MCP3202Driver is a driver for the MCP3202 A/D converter.

func NewMCP3202Driver added in v1.8.0

func NewMCP3202Driver(a Connector) *MCP3202Driver

NewMCP3202Driver creates a new Gobot Driver for MCP3202Driver A/D converter

Params:

a *Adaptor - the Adaptor to use with this Driver

func (*MCP3202Driver) AnalogRead added in v1.8.0

func (d *MCP3202Driver) AnalogRead(pin string) (value int, err error)

AnalogRead returns value from analog reading of specified pin, scaled to 0-1023 value.

func (*MCP3202Driver) Connection added in v1.8.0

func (d *MCP3202Driver) Connection() gobot.Connection

Connection returns the Connection of the device.

func (*MCP3202Driver) Halt added in v1.8.0

func (d *MCP3202Driver) Halt() (err error)

Halt stops the driver.

func (*MCP3202Driver) Name added in v1.8.0

func (d *MCP3202Driver) Name() string

Name returns the name of the device.

func (*MCP3202Driver) Read added in v1.8.0

func (d *MCP3202Driver) Read(channel int) (result int, err error)

Read reads the current analog data for the desired channel.

func (*MCP3202Driver) SetName added in v1.8.0

func (d *MCP3202Driver) SetName(n string)

SetName sets the name of the device.

func (*MCP3202Driver) Start added in v1.8.0

func (d *MCP3202Driver) Start() (err error)

Start initializes the driver.

type MCP3204Driver added in v1.8.0

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

MCP3204Driver is a driver for the MCP3204 A/D converter.

func NewMCP3204Driver added in v1.8.0

func NewMCP3204Driver(a Connector) *MCP3204Driver

NewMCP3204Driver creates a new Gobot Driver for MCP3204Driver A/D converter

Params:

a *Adaptor - the Adaptor to use with this Driver

func (*MCP3204Driver) AnalogRead added in v1.8.0

func (d *MCP3204Driver) AnalogRead(pin string) (value int, err error)

AnalogRead returns value from analog reading of specified pin, scaled to 0-1023 value.

func (*MCP3204Driver) Connection added in v1.8.0

func (d *MCP3204Driver) Connection() gobot.Connection

Connection returns the Connection of the device.

func (*MCP3204Driver) Halt added in v1.8.0

func (d *MCP3204Driver) Halt() (err error)

Halt stops the driver.

func (*MCP3204Driver) Name added in v1.8.0

func (d *MCP3204Driver) Name() string

Name returns the name of the device.

func (*MCP3204Driver) Read added in v1.8.0

func (d *MCP3204Driver) Read(channel int) (result int, err error)

Read reads the current analog data for the desired channel.

func (*MCP3204Driver) SetName added in v1.8.0

func (d *MCP3204Driver) SetName(n string)

SetName sets the name of the device.

func (*MCP3204Driver) Start added in v1.8.0

func (d *MCP3204Driver) Start() (err error)

Start initializes the driver.

type MCP3208Driver added in v1.8.0

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

MCP3208Driver is a driver for the MCP3208 A/D converter.

func NewMCP3208Driver added in v1.8.0

func NewMCP3208Driver(a Connector) *MCP3208Driver

NewMCP3208Driver creates a new Gobot Driver for MCP3208Driver A/D converter

Params:

a *Adaptor - the Adaptor to use with this Driver

func (*MCP3208Driver) AnalogRead added in v1.8.0

func (d *MCP3208Driver) AnalogRead(pin string) (value int, err error)

AnalogRead returns value from analog reading of specified pin, scaled to 0-1023 value.

func (*MCP3208Driver) Connection added in v1.8.0

func (d *MCP3208Driver) Connection() gobot.Connection

Connection returns the Connection of the device.

func (*MCP3208Driver) Halt added in v1.8.0

func (d *MCP3208Driver) Halt() (err error)

Halt stops the driver.

func (*MCP3208Driver) Name added in v1.8.0

func (d *MCP3208Driver) Name() string

Name returns the name of the device.

func (*MCP3208Driver) Read added in v1.8.0

func (d *MCP3208Driver) Read(channel int) (result int, err error)

Read reads the current analog data for the desired channel.

func (*MCP3208Driver) SetName added in v1.8.0

func (d *MCP3208Driver) SetName(n string)

SetName sets the name of the device.

func (*MCP3208Driver) Start added in v1.8.0

func (d *MCP3208Driver) Start() (err error)

Start initializes the driver.

type MCP3304Driver added in v1.8.0

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

MCP3304Driver is a driver for the MCP3304 A/D converter.

func NewMCP3304Driver added in v1.8.0

func NewMCP3304Driver(a Connector) *MCP3304Driver

NewMCP3304Driver creates a new Gobot Driver for MCP3304Driver A/D converter

Params:

a *Adaptor - the Adaptor to use with this Driver

func (*MCP3304Driver) AnalogRead added in v1.8.0

func (d *MCP3304Driver) AnalogRead(pin string) (value int, err error)

AnalogRead returns value from analog reading of specified pin, scaled to 0-1023 value.

func (*MCP3304Driver) Connection added in v1.8.0

func (d *MCP3304Driver) Connection() gobot.Connection

Connection returns the Connection of the device.

func (*MCP3304Driver) Halt added in v1.8.0

func (d *MCP3304Driver) Halt() (err error)

Halt stops the driver.

func (*MCP3304Driver) Name added in v1.8.0

func (d *MCP3304Driver) Name() string

Name returns the name of the device.

func (*MCP3304Driver) Read added in v1.8.0

func (d *MCP3304Driver) Read(channel int) (result int, err error)

Read reads the current analog data for the desired channel.

func (*MCP3304Driver) SetName added in v1.8.0

func (d *MCP3304Driver) SetName(n string)

SetName sets the name of the device.

func (*MCP3304Driver) Start added in v1.8.0

func (d *MCP3304Driver) Start() (err error)

Start initializes the driver.

type SPIDevice

type SPIDevice interface {
	SPIOperations
}

SPIDevice is the interface to a specific spi bus

func GetSpiBus added in v1.8.0

func GetSpiBus(busNum, mode int, maxSpeed int64) (spiDevice SPIDevice, err error)

GetSPIBus is a helper to return a 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