sysfs

package
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: Mar 22, 2017 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Overview

Package sysfs provides generic access to linux gpio.

It is intended to be used while implementing support for a single board linux computer

Index

Constants

View Source
const (
	// IN gpio direction
	IN = "in"
	// OUT gpio direction
	OUT = "out"
	// HIGH gpio level
	HIGH = 1
	// LOW gpio level
	LOW = 0
	// GPIOPATH default linux gpio path
	GPIOPATH = "/sys/class/gpio"
)
View Source
const (
	// From  /usr/include/linux/i2c-dev.h:
	// ioctl signals
	I2C_SLAVE = 0x0703
	I2C_FUNCS = 0x0705
	I2C_SMBUS = 0x0720
	// Read/write markers
	I2C_SMBUS_READ  = 1
	I2C_SMBUS_WRITE = 0

	// From  /usr/include/linux/i2c.h:
	// Adapter functionality
	I2C_FUNC_SMBUS_READ_BYTE        = 0x00020000
	I2C_FUNC_SMBUS_WRITE_BYTE       = 0x00040000
	I2C_FUNC_SMBUS_READ_BYTE_DATA   = 0x00080000
	I2C_FUNC_SMBUS_WRITE_BYTE_DATA  = 0x00100000
	I2C_FUNC_SMBUS_READ_WORD_DATA   = 0x00200000
	I2C_FUNC_SMBUS_WRITE_WORD_DATA  = 0x00400000
	I2C_FUNC_SMBUS_READ_BLOCK_DATA  = 0x01000000
	I2C_FUNC_SMBUS_WRITE_BLOCK_DATA = 0x02000000
	// Transaction types
	I2C_SMBUS_BYTE             = 1
	I2C_SMBUS_BYTE_DATA        = 2
	I2C_SMBUS_WORD_DATA        = 3
	I2C_SMBUS_PROC_CALL        = 4
	I2C_SMBUS_BLOCK_DATA       = 5
	I2C_SMBUS_I2C_BLOCK_BROKEN = 6
	I2C_SMBUS_BLOCK_PROC_CALL  = 7 /* SMBus 2.0 */
	I2C_SMBUS_I2C_BLOCK_DATA   = 8 /* SMBus 2.0 */
)

Variables

This section is empty.

Functions

func NewI2cDevice

func NewI2cDevice(location string) (d *i2cDevice, err error)

NewI2cDevice returns an io.ReadWriteCloser with the proper ioctrl given an i2c bus location.

func SetFilesystem

func SetFilesystem(f Filesystem)

SetFilesystem sets the filesystem implementation.

func SetSyscall

func SetSyscall(s SystemCaller)

SetSyscall sets the Syscall implementation

func Syscall

func Syscall(trap, a1, a2, a3 uintptr) (r1, r2 uintptr, err syscall.Errno)

Syscall calls either the NativeSyscall or user defined Syscall

Types

type DigitalPin

type DigitalPin interface {
	// Unexport unexports the pin and releases the pin from the operating system
	Unexport() error
	// Export exports the pin for use by the operating system
	Export() error
	// Read reads the current value of the pin
	Read() (int, error)
	// Direction sets the direction for the pin
	Direction(string) error
	// Write writes to the pin
	Write(int) error
}

DigitalPin is the interface for sysfs gpio interactions

func NewDigitalPin

func NewDigitalPin(pin int, v ...string) DigitalPin

NewDigitalPin returns a DigitalPin given the pin number and an optional sysfs pin label. If no label is supplied the default label will prepend "gpio" to the pin number, eg. a pin number of 10 will have a label of "gpio10"

type File

type File interface {
	Write(b []byte) (n int, err error)
	WriteString(s string) (ret int, err error)
	Sync() (err error)
	Read(b []byte) (n int, err error)
	ReadAt(b []byte, off int64) (n int, err error)
	Seek(offset int64, whence int) (ret int64, err error)
	Fd() uintptr
	Close() error
}

A File represents basic IO interactions with the underlying file system

func OpenFile

func OpenFile(name string, flag int, perm os.FileMode) (file File, err error)

OpenFile calls either the NativeFilesystem or user defined OpenFile

type Filesystem

type Filesystem interface {
	OpenFile(name string, flag int, perm os.FileMode) (file File, err error)
}

Filesystem opens files and returns either a native file system or user defined

type I2cDevice

type I2cDevice interface {
	I2cOperations
	SetAddress(int) error
}

I2cDevice is the interface to a specific i2c bus

type I2cOperations added in v1.2.0

type I2cOperations interface {
	io.ReadWriteCloser
	ReadByte() (val uint8, err error)
	ReadByteData(reg uint8) (val uint8, err error)
	ReadWordData(reg uint8) (val uint16, err error)
	WriteByte(val uint8) (err error)
	WriteByteData(reg uint8, val uint8) (err error)
	WriteWordData(reg uint8, val uint16) (err error)
	WriteBlockData(reg uint8, b []byte) (err error)
}

type MockFile

type MockFile struct {
	Contents string
	Seq      int // When this file was last written or read.
	Opened   bool
	Closed   bool
	// contains filtered or unexported fields
}

A MockFile represents a mock file that contains a single string. Any write overwrites, and any read returns from the start.

func (*MockFile) Close

func (f *MockFile) Close() error

Close implements the File interface Close function

func (*MockFile) Fd

func (f *MockFile) Fd() uintptr

Fd returns a random uintprt based on the time of the MockFile creation

func (*MockFile) Read

func (f *MockFile) Read(b []byte) (n int, err error)

Read copies b bytes from f.Contents

func (*MockFile) ReadAt

func (f *MockFile) ReadAt(b []byte, off int64) (n int, err error)

ReadAt calls MockFile.Read

func (*MockFile) Seek added in v0.12.0

func (f *MockFile) Seek(offset int64, whence int) (ret int64, err error)

Seek seeks to a specific offset in a file

func (*MockFile) Sync

func (f *MockFile) Sync() (err error)

Sync implements the File interface Sync function

func (*MockFile) Write

func (f *MockFile) Write(b []byte) (n int, err error)

Write writes string(b) to f.Contents

func (*MockFile) WriteString

func (f *MockFile) WriteString(s string) (ret int, err error)

WriteString writes s to f.Contents

type MockFilesystem

type MockFilesystem struct {
	Seq   int // Increases with each write or read.
	Files map[string]*MockFile
}

MockFilesystem represents a filesystem of mock files.

func NewMockFilesystem

func NewMockFilesystem(files []string) *MockFilesystem

NewMockFilesystem returns a new MockFilesystem given a list of file paths

func (*MockFilesystem) Add

func (fs *MockFilesystem) Add(name string) *MockFile

Add adds a new file to fs.Files given a name, and returns the newly created file

func (*MockFilesystem) OpenFile

func (fs *MockFilesystem) OpenFile(name string, flag int, perm os.FileMode) (file File, err error)

OpenFile opens file name from fs.Files, if the file does not exist it returns an os.PathError

type MockSyscall

type MockSyscall struct {
	Impl func(trap, a1, a2, a3 uintptr) (r1, r2 uintptr, err syscall.Errno)
}

MockSyscall represents the mock Syscall

func (*MockSyscall) Syscall

func (sys *MockSyscall) Syscall(trap, a1, a2, a3 uintptr) (r1, r2 uintptr, err syscall.Errno)

Syscall implements the SystemCaller interface

type NativeFilesystem

type NativeFilesystem struct{}

NativeFilesystem represents the native file system implementation

func (*NativeFilesystem) OpenFile

func (fs *NativeFilesystem) OpenFile(name string, flag int, perm os.FileMode) (file File, err error)

OpenFile calls os.OpenFile().

type NativeSyscall

type NativeSyscall struct{}

NativeSyscall represents the native Syscall

func (*NativeSyscall) Syscall

func (sys *NativeSyscall) Syscall(trap, a1, a2, a3 uintptr) (r1, r2 uintptr, err syscall.Errno)

Syscall calls syscall.Syscall

type SystemCaller

type SystemCaller interface {
	Syscall(trap, a1, a2, a3 uintptr) (r1, r2 uintptr, err syscall.Errno)
}

SystemCaller represents a Syscall

Jump to

Keyboard shortcuts

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