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 ¶
- Variables
- func SetSpeedHook(h func(hz int64) error) error
- type I2C
- type LED
- func (l *LED) Function() string
- func (l *LED) In(pull gpio.Pull, edge gpio.Edge) error
- func (l *LED) Name() string
- func (l *LED) Number() int
- func (l *LED) Out(level gpio.Level) error
- func (l *LED) Pull() gpio.Pull
- func (l *LED) Read() gpio.Level
- func (l *LED) String() string
- func (l *LED) WaitForEdge(timeout time.Duration) bool
- type Pin
- func (p *Pin) Function() string
- func (p *Pin) In(pull gpio.Pull, edge gpio.Edge) error
- func (p *Pin) Name() string
- func (p *Pin) Number() int
- func (p *Pin) Out(l gpio.Level) error
- func (p *Pin) Pull() gpio.Pull
- func (p *Pin) Read() gpio.Level
- func (p *Pin) String() string
- func (p *Pin) WaitForEdge(timeout time.Duration) bool
- type SPI
- func (s *SPI) CLK() gpio.PinOut
- func (s *SPI) CS() gpio.PinOut
- func (s *SPI) Close() error
- func (s *SPI) Connect(maxHz int64, mode spi.Mode, bits int) (spi.Conn, error)
- func (s *SPI) LimitSpeed(maxHz int64) error
- func (s *SPI) MISO() gpio.PinIn
- func (s *SPI) MOSI() gpio.PinOut
- func (s *SPI) MaxTxSize() int
- func (s *SPI) String() string
- type ThermalSensor
Examples ¶
Constants ¶
This section is empty.
Variables ¶
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.
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.
var ThermalSensors []*ThermalSensor
ThermalSensors is all the sensors discovered on this host via sysfs.
Functions ¶
func SetSpeedHook ¶
SetSpeedHook 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 ¶
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.
Example ¶
b, err := NewI2C(1) if err != nil { log.Fatal(err) } defer b.Close() if err := b.Tx(23, []byte{0x10}, nil); err != nil { log.Fatal(err) }
Output:
func (*I2C) Close ¶
Close closes the handle to the I²C driver. It is not a requirement to close before process termination.
func (*I2C) SCL ¶
SCL implements i2c.Pins.
It will fail if host.Init() wasn't called. host.Init() is transparently called by host.MakeI2C().
type LED ¶
type LED struct {
// contains filtered or unexported fields
}
LED represents one LED on the system.
func LEDByName ¶
LEDByName returns a *LED for the LED name, if any.
For all practical purpose, a LED is considered an output-only gpio.PinOut.
Example ¶
// Commented out due to cycle import. //if _, err := host.Init(); err != nil { // log.Fatalf("failed to initialize periph: %v", err) //} for _, led := range LEDs { fmt.Printf("- %s: %s\n", led, led.Function()) } led, err := LEDByName("LED0") if err != nil { log.Fatalf("failed to find LED: %v", err) } led.Out(gpio.Low)
Output:
type Pin ¶
type Pin struct {
// contains filtered or unexported fields
}
Pin represents one GPIO pin as found by sysfs.
type SPI ¶
SPI is an open SPI port.
func NewSPI ¶
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 deffs. For example if the path is /dev/spidev0.1, busNumber should be 0 and chipSelect should be 1.
Example ¶
b, err := NewSPI(0, 0) if err != nil { log.Fatal(err) } defer b.Close() c, err := b.Connect(1000000, spi.Mode3, 8) if err != nil { log.Fatal(err) } if err := c.Tx([]byte{0x10}, nil); err != nil { log.Fatal(err) }
Output:
func (*SPI) Close ¶
Close closes the handle to the SPI driver. It is not a requirement to close before process termination.
func (*SPI) LimitSpeed ¶
LimitSpeed implements spi.ConnCloser.
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 devices.Device. It is a noop.
func (*ThermalSensor) Sense ¶
func (t *ThermalSensor) Sense(env *devices.Environment) error
Sense implements devices.Environmental.
func (*ThermalSensor) SenseContinuous ¶
func (t *ThermalSensor) SenseContinuous(interval time.Duration) (<-chan devices.Environment, error)
SenseContinuous implements devices.Environmental.
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.