sysfs

package
v3.4.0+incompatible Latest Latest
Warning

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

Go to latest
Published: Dec 21, 2018 License: Apache-2.0 Imports: 24 Imported by: 0

Documentation

Overview

Package sysfs implements a sane library to interact with sysfs provided hardware access.

sysfs a virtual file system rooted at /sys/.

This package also include drivers using devfs.

https://www.kernel.org/doc/Documentation/filesystems/sysfs.txt

Index

Examples

Constants

This section is empty.

Variables

View Source
var LEDs []*LED

LEDs is all the leds discovered on this host via sysfs.

Depending on the user context, the LEDs may be read-only or writeable.

View Source
var Pins map[int]*Pin

Pins is all the pins exported by GPIO sysfs.

Some CPU architectures have the pin numbers start at 0 and use consecutive pin numbers but this is not the case for all CPU architectures, some have gaps in the pin numbering.

This global variable is initialized once at driver initialization and isn't mutated afterward. Do not modify it.

View Source
var ThermalSensors []*ThermalSensor

ThermalSensors is all the sensors discovered on this host via sysfs. It includes 'thermal' devices as well as temperature 'hwmon' devices, so pre-configured onewire temperature sensors will be discovered automatically.

Functions

func I2CSetSpeedHook

func I2CSetSpeedHook(h func(f physic.Frequency) error) error

I2CSetSpeedHook can be set by a driver to enable changing the I²C buses speed.

Types

type I2C

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

I2C is an open I²C bus via sysfs.

It can be used to communicate with multiple devices from multiple goroutines.

func NewI2C

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

NewI2C opens an I²C bus via its sysfs interface as described at https://www.kernel.org/doc/Documentation/i2c/dev-interface.

busNumber is the bus number as exported by sysfs. For example if the path is /dev/i2c-1, busNumber should be 1.

The resulting object is safe for concurent use.

Do not use sysfs.NewI2C() directly as the package sysfs is providing a https://periph.io/x/periph/conn/i2c Linux-specific implementation.

periph.io works on many OSes!

Instead, use https://periph.io/x/periph/conn/i2c/i2creg#Open. This permits it to work on all operating systems, or devices like I²C over USB.

func (*I2C) Close

func (i *I2C) Close() error

Close closes the handle to the I²C driver. It is not a requirement to close before process termination.

func (*I2C) SCL

func (i *I2C) SCL() gpio.PinIO

SCL implements i2c.Pins.

func (*I2C) SDA

func (i *I2C) SDA() gpio.PinIO

SDA implements i2c.Pins.

func (*I2C) SetSpeed

func (i *I2C) SetSpeed(f physic.Frequency) error

SetSpeed implements i2c.Bus.

func (*I2C) String

func (i *I2C) String() string

func (*I2C) Tx

func (i *I2C) Tx(addr uint16, w, r []byte) error

Tx execute a transaction as a single operation unit.

type LED

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

LED represents one LED on the system.

func LEDByName

func LEDByName(name string) (*LED, error)

LEDByName returns a *LED for the LED name, if any.

For all practical purpose, a LED is considered an output-only gpio.PinOut.

Example
package main

import (
	"fmt"
	"log"

	"periph.io/x/periph/conn/gpio"
	"periph.io/x/periph/host"
	"periph.io/x/periph/host/sysfs"
)

func main() {
	// Make sure periph is initialized.
	if _, err := host.Init(); err != nil {
		log.Fatal(err)
	}

	for _, led := range sysfs.LEDs {
		fmt.Printf("- %s: %s\n", led, led.Function())
	}
	led, err := sysfs.LEDByName("LED0")
	if err != nil {
		log.Fatalf("failed to find LED: %v", err)
	}
	if err := led.Out(gpio.Low); err != nil {
		log.Fatal(err)
	}
}
Output:

func (*LED) DefaultPull

func (l *LED) DefaultPull() gpio.Pull

DefaultPull implements gpio.PinIn.

func (*LED) Func

func (l *LED) Func() pin.Func

Func implements pin.PinFunc.

func (*LED) Function

func (l *LED) Function() string

Function implements pin.Pin.

func (*LED) Halt

func (l *LED) Halt() error

Halt implements conn.Resource.

It turns the light off.

func (*LED) In

func (l *LED) In(pull gpio.Pull, edge gpio.Edge) error

In implements gpio.PinIn.

func (*LED) Name

func (l *LED) Name() string

Name implements pin.Pin.

func (*LED) Number

func (l *LED) Number() int

Number implements pin.Pin.

func (*LED) Out

func (l *LED) Out(level gpio.Level) error

Out implements gpio.PinOut.

func (*LED) PWM

func (l *LED) PWM(d gpio.Duty, f physic.Frequency) error

PWM implements gpio.PinOut.

This sets the intensity level, if supported. The frequency is ignored.

func (*LED) Pull

func (l *LED) Pull() gpio.Pull

Pull implements gpio.PinIn.

func (*LED) Read

func (l *LED) Read() gpio.Level

Read implements gpio.PinIn.

func (*LED) SetFunc

func (l *LED) SetFunc(f pin.Func) error

SetFunc implements pin.PinFunc.

func (*LED) String

func (l *LED) String() string

String implements conn.Resource.

func (*LED) SupportedFuncs

func (l *LED) SupportedFuncs() []pin.Func

SupportedFuncs implements pin.PinFunc.

func (*LED) WaitForEdge

func (l *LED) WaitForEdge(timeout time.Duration) bool

WaitForEdge implements gpio.PinIn.

type Pin

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

Pin represents one GPIO pin as found by sysfs.

func (*Pin) DefaultPull

func (p *Pin) DefaultPull() gpio.Pull

DefaultPull implements gpio.PinIn.

It returns gpio.PullNoChange since gpio sysfs has no support for input pull resistor.

func (*Pin) Func

func (p *Pin) Func() pin.Func

Func implements pin.PinFunc.

func (*Pin) Function

func (p *Pin) Function() string

Function implements pin.Pin.

func (*Pin) Halt

func (p *Pin) Halt() error

Halt implements conn.Resource.

It stops edge detection if enabled.

func (*Pin) In

func (p *Pin) In(pull gpio.Pull, edge gpio.Edge) error

In implements gpio.PinIn.

func (*Pin) Name

func (p *Pin) Name() string

Name implements pin.Pin.

func (*Pin) Number

func (p *Pin) Number() int

Number implements pin.Pin.

func (*Pin) Out

func (p *Pin) Out(l gpio.Level) error

Out implements gpio.PinOut.

func (*Pin) PWM

func (p *Pin) PWM(gpio.Duty, physic.Frequency) error

PWM implements gpio.PinOut.

This is not supported on sysfs.

func (*Pin) Pull

func (p *Pin) Pull() gpio.Pull

Pull implements gpio.PinIn.

It returns gpio.PullNoChange since gpio sysfs has no support for input pull resistor.

func (*Pin) Read

func (p *Pin) Read() gpio.Level

Read implements gpio.PinIn.

func (*Pin) SetFunc

func (p *Pin) SetFunc(f pin.Func) error

SetFunc implements pin.PinFunc.

func (*Pin) String

func (p *Pin) String() string

String implements conn.Resource.

func (*Pin) SupportedFuncs

func (p *Pin) SupportedFuncs() []pin.Func

SupportedFuncs implements pin.PinFunc.

func (*Pin) WaitForEdge

func (p *Pin) WaitForEdge(timeout time.Duration) bool

WaitForEdge implements gpio.PinIn.

type SPI

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

SPI is an open SPI port.

func NewSPI

func NewSPI(busNumber, chipSelect int) (*SPI, error)

NewSPI opens a SPI port via its devfs interface as described at https://www.kernel.org/doc/Documentation/spi/spidev and https://www.kernel.org/doc/Documentation/spi/spi-summary

The resulting object is safe for concurrent use.

busNumber is the bus number as exported by devfs. For example if the path is /dev/spidev0.1, busNumber should be 0 and chipSelect should be 1.

It is recommended to use https://periph.io/x/periph/conn/spi/spireg#Open instead of using NewSPI() directly as the package sysfs is providing a Linux-specific implementation. periph.io works on many OSes! This permits it to work on all operating systems, or devices like SPI over USB.

func (*SPI) CLK

func (s *SPI) CLK() gpio.PinOut

CLK implements spi.Pins.

func (*SPI) CS

func (s *SPI) CS() gpio.PinOut

CS implements spi.Pins.

func (*SPI) Close

func (s *SPI) Close() error

Close closes the handle to the SPI driver. It is not a requirement to close before process termination.

Note that the object is not reusable afterward.

func (*SPI) Connect

func (s *SPI) Connect(f physic.Frequency, mode spi.Mode, bits int) (spi.Conn, error)

Connect implements spi.Port.

It must be called before any I/O.

func (*SPI) LimitSpeed

func (s *SPI) LimitSpeed(f physic.Frequency) error

LimitSpeed implements spi.ConnCloser.

func (*SPI) MISO

func (s *SPI) MISO() gpio.PinIn

MISO implements spi.Pins.

func (*SPI) MOSI

func (s *SPI) MOSI() gpio.PinOut

MOSI implements spi.Pins.

func (*SPI) MaxTxSize

func (s *SPI) MaxTxSize() int

MaxTxSize implements conn.Limits

func (*SPI) String

func (s *SPI) String() string

type ThermalSensor

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

ThermalSensor represents one thermal sensor on the system.

func ThermalSensorByName

func ThermalSensorByName(name string) (*ThermalSensor, error)

ThermalSensorByName returns a *ThermalSensor for the sensor name, if any.

func (*ThermalSensor) Halt

func (t *ThermalSensor) Halt() error

Halt implements conn.Resource. It is a noop.

func (*ThermalSensor) Precision

func (t *ThermalSensor) Precision(e *physic.Env)

Precision implements physic.SenseEnv.

func (*ThermalSensor) Sense

func (t *ThermalSensor) Sense(e *physic.Env) error

Sense implements physic.SenseEnv.

func (*ThermalSensor) SenseContinuous

func (t *ThermalSensor) SenseContinuous(interval time.Duration) (<-chan physic.Env, error)

SenseContinuous implements physic.SenseEnv.

func (*ThermalSensor) String

func (t *ThermalSensor) String() string

func (*ThermalSensor) Type

func (t *ThermalSensor) Type() string

Type returns the type of sensor as exported by sysfs.

Directories

Path Synopsis
Package sysfssmoketest verifies that sysfs specific functionality work.
Package sysfssmoketest verifies that sysfs specific functionality work.

Jump to

Keyboard shortcuts

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