io

package module
v0.0.0-...-c5124e8 Latest Latest
Warning

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

Go to latest
Published: Jun 16, 2021 License: Apache-2.0 Imports: 7 Imported by: 1

README

gpio

Go GPIO library.

The base library contains interface code to drivers and hardware.

The action directory contains types that use the lower layer interface code to build more complex actions e.g a stepper motor driver that uses individual GPIO elements to control the different inputs to the motor.

The sensor directory contains types that provide a higher level interface to sensors that are accessed via the lower layer interface types.

The examples directory contains sample programs that demonstrate the use of the library.

Documentation

Index

Constants

View Source
const (
	IN  = iota // Default
	OUT = iota
)

Mode

View Source
const (
	NONE    = iota // Default
	RISING  = iota
	FALLING = iota
	BOTH    = iota
)

Edge

View Source
const (
	I2cFlagRead   = 1 << iota // Message is to be read, not written
	I2cFlagTenBit             // Address is 10 bit address
)

Flags

View Source
const (
	SPI_MODE_0 = 0
	SPI_MODE_1 = 1
	SPI_MODE_2 = 2
	SPI_MODE_3 = 3

	SPI_MODE_CS_HIGH   = 0x04
	SPI_MODE_LSB_FIRST = 0x08
	// SPI_MODE_3WIRE	   = 0x10	3 wire mode is not supported.
	SPI_MODE_LOOP  = 0x20
	SPI_MODE_NO_CS = 0x40
	SPI_MODE_READY = 0x80
)

Spi driver modes.

View Source
const I2cMaxMsgs = 42 // Maximum number of messages allowed in transaction

Variables

View Source
var (
	ErrRetriesExceeded = errors.New("retries exceeded")
)
View Source
var Verify = false

Verify will enable waiting for exported files to become writable. This is necessary if the process is not running as root - systemd and udev will change the group permissions on the exported files, but this takes some time to do. If we try and access the files before the file group/modes are changed, we will get a permission error. This can be overridden.

Functions

This section is empty.

Types

type Gpio

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

Gpio represents one GPIO pin.

func OutputPin

func OutputPin(gpio int) (*Gpio, error)

OutputPin opens a GPIO pin and sets the direction as OUTPUT.

func Pin

func Pin(gpio int) (*Gpio, error)

Pin opens a GPIO pin as an input (by default)

func (*Gpio) Close

func (g *Gpio) Close()

Close the GPIO pin and unexport it.

func (*Gpio) Direction

func (g *Gpio) Direction(d int) error

Direction sets the mode (direction) of the GPIO pin.

func (*Gpio) Edge

func (g *Gpio) Edge(e int) error

Edge sets the edge detection on the GPIO pin.

func (*Gpio) Get

func (g *Gpio) Get() (int, error)

Get returns the current value of the GPIO pin.

func (*Gpio) GetTimeout

func (g *Gpio) GetTimeout(tout time.Duration) (int, error)

GetTimeout is used when detecting edges, and a timeout is required. A timeout of 0 is interpreted as no timeout.

func (*Gpio) Set

func (g *Gpio) Set(v int) error

Set the output of the GPIO pin (only valid for OUTPUT pins)

type HwPwm

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

func NewHwPWM

func NewHwPWM(unit int) (*HwPwm, error)

NewHwPWM creates a new hardware PWM controller.

func (*HwPwm) Close

func (p *HwPwm) Close()

Close closes the PWM controller

func (*HwPwm) Set

func (p *HwPwm) Set(period time.Duration, duty int) error

Set sets the PWM parameters.

type I2C

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

I2C represents one I2C device

func NewI2C

func NewI2C(bus int) (*I2C, error)

NewI2C creates and initialises a new I2C device.

func (*I2C) Addr

func (i2 *I2C) Addr(addr uint16) error

Addr sets the default address.

func (*I2C) Close

func (i2 *I2C) Close()

Close closes the device.

func (*I2C) Message

func (i2 *I2C) Message(msgs []I2cMsg) error

Message writes or reads the list of messages to/from the peripheral device.

func (*I2C) Read

func (i2 *I2C) Read(reg byte, b []byte) error

Read builds a message slice that writes an 8 bit register value to the device and then reads data from the peripheral device.

func (*I2C) ReadReg

func (i2 *I2C) ReadReg(reg byte) (byte, error)

ReadReg reads one 8 bit register from the peripheral device by writing a register address and then reading 1 byte from the device.

func (*I2C) Retries

func (i2 *I2C) Retries(r int) error

Retries sets the default number of message retries.

func (*I2C) TenBit

func (i2 *I2C) TenBit(ten bool) error

TenBit enables 10 bit addresses.

func (*I2C) Timeout

func (i2 *I2C) Timeout(tout time.Duration) error

Timeout sets the default timeout for the bus.

func (*I2C) Write

func (i2 *I2C) Write(reg byte, data []byte) error

Write builds a message to write a register address to the peripheral device followed by the byte data.

func (*I2C) WriteReg

func (i2 *I2C) WriteReg(reg, data byte) error

WriteReg writes one register in the peripheral device.

type I2cMsg

type I2cMsg struct {
	Addr  uint16
	Flags int
	Buf   []byte
}

I2cMsg represents a single read or write message.

type PWM

type PWM interface {
	Close()
	Set(time.Duration, int) error
}

Interface for PWM controllers

type Setter

type Setter interface {
	Set(int) error
}

Setter is an interface for setting an output value on a GPIO

type Spi

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

func NewSpi

func NewSpi(unit int) (*Spi, error)

NewSpi creates and initialises a SPI device.

func (*Spi) Bits

func (s *Spi) Bits(bits byte) error

Bits selects the word size of the transfer (usually 8 or 9 bits)

func (*Spi) Close

func (s *Spi) Close()

Close closes the SPI controller

func (*Spi) Mode

func (s *Spi) Mode(m uint32) error

Mode sets the mode, which is a combination of mode flags.

func (*Spi) Read

func (s *Spi) Read(b []byte) (int, error)

Read reads a message from the SPI devices

func (*Spi) Speed

func (s *Spi) Speed(speed uint32) error

Speed sets the speed of the interface.

func (*Spi) Write

func (s *Spi) Write(b []byte) (int, error)

Write writes the message to the SPI device.

func (*Spi) Xfer

func (s *Spi) Xfer(wb []byte) ([]byte, error)

Xfer builds and sends a message request. The receive buffer is returned. TODO: The interface will support multiple messages.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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