gpiosysfs

package
v0.0.0-...-8327cd9 Latest Latest
Warning

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

Go to latest
Published: Sep 19, 2019 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package gpiosysfs implements linux GPIO Sysfs Interface.

Ref: https://www.kernel.org/doc/Documentation/gpio/sysfs.txt

GPIO Sysfs Interface is deprecated. New applications are supposed to use the character device implementation: github.com/mkch/gpio

Index

Constants

View Source
const (
	In      Direction = "in"   // RW. The pin is configured as input.
	Out               = "out"  // RW. The pin is configured as output, usually initialized to low.
	OutLow            = "low"  // W. Configure the pin as output and initialize it to low.
	OutHigh           = "high" // W. Configure the pin as output and initialize it to high.
)

Available directions.

View Source
const (
	// None means no edge is selected to generate interrupts.
	None Edge = "none"
	// Rising edges is is selected to generate interrupts. Rising: level is getting to high from low.
	Rising = "rising"
	// Falling edges is is selected to generate interrupts. Falling: level is getting to low from hight.
	Falling = "falling"
	// Both rising and falling edges are selected to generate interrupts.
	Both = "both"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Chip

type Chip struct {
	Base  int    // The first GPIO managed by this chip.
	Label string // The Label fo this chip. Provided for diagnostics (not always unique)
	Ngpio int    // How many GPIOs this chip manges. The GPIOs managed by this chip are in the range of Base to Base + ngpio - 1.
}

Chip is the information of a GPIO controller chip.

func Controller

func Controller(n int) (Chip, error)

Controller returns the GPIO controller #n.

func Controllers

func Controllers() (chips []Chip, err error)

Controllers returns all GPIO controllers available.

type Direction

type Direction string

Direction is the IO direction.

type Edge

type Edge string

Edge is the signal edge that will make Interrupt send value to the channel.

type Event

type Event = fdevents.Event

type Pin

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

Pin is a GPIO pin.

func OpenPin

func OpenPin(n int) (pin *Pin, err error)

OpenPin opens the GPIO pin #n for IO.

func (*Pin) ActiveLow

func (pin *Pin) ActiveLow(value bool, err error)

ActiveLow returns whether the pin is configured as active low.

func (*Pin) Close

func (pin *Pin) Close() (err error)

Close closes the pin.

func (*Pin) Direction

func (pin *Pin) Direction() (dir Direction, err error)

Direction returns the IO direction of the pin. The return values is In or Out.

func (*Pin) Edge

func (pin *Pin) Edge() (edge Edge, err error)

Edge returns which edges are selected to generate interrupts.

func (*Pin) SetActiveLow

func (pin *Pin) SetActiveLow(value bool) (err error)

SetActiveLow sets whether pin is configured as active low.

func (*Pin) SetDirection

func (pin *Pin) SetDirection(direction Direction) (err error)

SetDirection sets the IO direction of the pin. pin.SetDirection(Out) may fail if Edge is not None.

func (*Pin) SetEdge

func (pin *Pin) SetEdge(edge Edge) (err error)

SetEdge sets which edges are selected to generate interrupts. Not all GPIO pins are configured to support edge selection, so, Edge should be called to confirm the desired edge are set actually.

func (*Pin) SetValue

func (pin *Pin) SetValue(value byte) (err error)

SetValue set the current value of the pin. 1 for high and 0 for low.

func (*Pin) Value

func (pin *Pin) Value() (value byte, err error)

Value returns the current value of the pin. 1 for high and 0 for low.

type PinWithEvent

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

PinWithEvent is an opened GPIO pin whose events can be read.

func OpenPinWithEvents

func OpenPinWithEvents(n int) (pin *PinWithEvent, err error)

OpenPinWithEvents opens a GPIO pin for input and GPIO events.

func (*PinWithEvent) Close

func (pin *PinWithEvent) Close() (err error)

func (*PinWithEvent) Events

func (pin *PinWithEvent) Events() <-chan *Event

Events returns a channel from which the occurrence time of GPIO events can be read. The GPIO events of this pin will be sent to the returned channel, and the channel is closed when l is closed.

Package gpiosysfs will not block sending to the channel: it only keeps the lastest value in the channel.

Jump to

Keyboard shortcuts

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