uapi

package
v0.8.1 Latest Latest
Warning

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

Go to latest
Published: May 13, 2022 License: MIT Imports: 5 Imported by: 0

README

uapi

PkgGoDev

GPIOD UAPI is a thin layer over the system ioctl calls that comprise the Linux GPIO UAPI.

This library is used by gpiod to interact with the Linux kernel.

The library is exposed to allow for testing of the UAPI with the minimal amount of Go in the way.

gpiod provides a higher level of abstraction, so for general use you probably want to be using that.

API

Both versions of the GPIO UAPI are supported; the current v2 and the deprecated v1.

V2

The GPIO UAPI v2 comprises eight ioctls (two of which are unchanged from v1):

IOCTL Scope Description
GetChipInfo chip Return information about the chip itself.
GetLineInfoV2 chip Return information about a particular line on the chip.
GetLine chip Request a set of lines, and returns a file handle for ioctl commands. The set may be any subset of the lines supported by the chip, including a single line. This may be used for both input and output lines. The lines remain reserved by the caller until the returned fd is closed.
GetLineValuesV2 line Return the current value of a set of lines in an existing line request.
SetLineValuesV2 line Set the current value of a set of lines in an existing line request.
SetLineConfigV2 line Update the configuration of the lines in an existing line request.
WatchLineInfoV2 chip Add a watch for changes to the info of a particular line on the chip.
UnwatchLineInfo chip Remove a watch for changes to the info of a particular line on the chip.
V1

The GPIO UAPI v1 comprises nine ioctls:

IOCTL Scope Description
GetChipInfo chip Return information about the chip itself.
GetLineInfo chip Return information about a particular line on the chip.
GetLineHandle chip Request a set of lines, and returns a file handle for ioctl commands. The set may be any subset of the lines supported by the chip, including a single line. This may be used for both input and output lines. The lines remain reserved by the caller until the returned fd is closed.
GetLineEvent chip Request an individual input line with edge detection enabled, and returns a file handle for ioctl commands and to return edge events. Events can only be requested on input lines. The line remains reserved by the caller until the returned fd is closed.
GetLineValues line Return the current value of a set of lines in an existing handle or event request.
SetLineValues line Set the current value of a set of lines in an existing handle request.
SetLineConfig line Update the configuration of the lines in an existing handle request.
WatchLineInfo chip Add a watch for changes to the info of a particular line on the chip.
UnwatchLineInfo chip Remove a watch for changes to the info of a particular line on the chip.

Usage

The following is a brief example of the usage of the major functions using v2 of the UAPI:

    f, _ := os.OpenFile("/dev/gpiochip0", unix.O_CLOEXEC, unix.O_RDONLY)

    // get chip info
    ci, _ := uapi.GetChipInfo(f.Fd())
    fmt.Print(ci)

    // get line info
    li, _ := uapi.GetLineInfo(f.Fd(), offset)
    fmt.Print(li)

    // request a line
    lr := uapi.LineRequest{
        Lines: uint32(len(offsets)),
        Config: uapi.LineConfig{
            Flags: uapi.LineFlagV2Output,
        },
        // initialise Offsets, OutputValues and Consumer...
    }
    err := uapi.GetLine(f.Fd(), &lr)

    // request a line with events
    lr = uapi.LineRequest{
        Lines: uint32(len(offsets)),
        Config: uapi.LineConfig{
            Flags: uapi.LineFlagV2Input | uapi.LineFlagV2ActiveLow | uapi.LineFlagV2EdgeBoth,
        },
        // initialise Offsets and Consumer...
    }
    err = uapi.GetLine(f.Fd(), &lr)
    if err != nil {
        // wait on lr.fd for events...

        // read event
        evt, _ := uapi.ReadLineEvent(uintptr(lr.Fd))
        fmt.Print(evt)
    }

    // get values
    var values uapi.LineValues
    err = uapi.GetLineValuesV2(uintptr(lr.Fd), &values)

    // set values
    err = uapi.SetLineValuesV2(uintptr(lr.Fd), values)

    // update line config - change to outputs
    err = uapi.SetLineConfigV2(uintptr(lr.Fd), &uapi.LineConfig{
        Flags: uapi.LineFlagV2Output,
        NumAttrs: 1,
        // initialise OutputValues...
    })

Error handling and other tedious bits, such as initialising the arrays in the requests, omitted for brevity.

Refer to gpiod for a concrete example of uapi usage.

This is essentially the same example using v1 of the UAPI:

    f, _ := os.OpenFile("/dev/gpiochip0", unix.O_CLOEXEC, unix.O_RDONLY)

    // get chip info
    ci, _ := uapi.GetChipInfo(f.Fd())
    fmt.Print(ci)

    // get line info
    li, _ := uapi.GetLineInfo(f.Fd(), offset)
    fmt.Print(li)

    // request a line
    hr := uapi.HandleRequest{
    Lines: uint32(len(offsets)),
    Flags: uapi.HandleRequestOutput,
    // initialise Offsets, DefaultValues and Consumer...
    }
    err := uapi.GetLineHandle(f.Fd(), &hr)

    // request a line with events
    er := uapi.EventRequest{
    Offset:      uint32(offset),
    HandleFlags: uapi.HandleRequestActiveLow,
    EventFlags:  uapi.EventRequestBothEdges,
    // initialise Consumer...
    }
    err = uapi.GetLineEvent(f.Fd(), &er)
    if err != nil {
    // wait on er.fd for events...

    // read event
    evt, _ := uapi.ReadEvent(uintptr(er.Fd))
    fmt.Print(evt)
    }

    // get values
    var values uapi.HandleData
    err = uapi.GetLineValues(uintptr(er.Fd), &values)

    // set values
    values[0] = uint8(value)
    err = uapi.SetLineValues(uintptr(hr.Fd), values)

    // update line config - change to active low
    err = uapi.SetLineConfig(uintptr(hr.Fd), &uapi.HandleConfig{
        Flags: uapi.HandleRequestInput,
    })

Documentation

Overview

Package uapi provides the Linux GPIO UAPI definitions for gpiod.

Package uapi provides the Linux GPIO UAPI definitions for gpiod.

Index

Constants

View Source
const (
	// LinesMax is the maximum number of lines that can be requested in a single
	// request.
	LinesMax int = 64
)

Variables

This section is empty.

Functions

func BytesToString

func BytesToString(a []byte) string

BytesToString is a helper function that converts strings stored in byte arrays, as returned by GetChipInfo and GetLineInfo, into strings.

func GetLine

func GetLine(fd uintptr, request *LineRequest) error

GetLine requests a line from the GPIO character device.

The fd is an open GPIO character device. The lines must not already be requested. The flags in the request will be applied to all lines in the request. If successful, the fd for the line is returned in the request.fd.

func GetLineEvent

func GetLineEvent(fd uintptr, request *EventRequest) error

GetLineEvent requests a line from the GPIO character device with event reporting enabled.

The fd is an open GPIO character device. The line must be an input and must not already be requested. If successful, the fd for the line is returned in the request.fd.

func GetLineHandle

func GetLineHandle(fd uintptr, request *HandleRequest) error

GetLineHandle requests a line from the GPIO character device.

This request is without event reporting. The fd is an open GPIO character device. The lines must not already be requested. The flags in the request will be applied to all lines in the request. If successful, the fd for the line is returned in the request.fd.

func GetLineValues

func GetLineValues(fd uintptr, values *HandleData) error

GetLineValues returns the values of a set of requested lines.

The fd is a requested line, as returned by GetLineHandle or GetLineEvent.

func GetLineValuesV2

func GetLineValuesV2(fd uintptr, values *LineValues) error

GetLineValuesV2 returns the values of a set of requested lines.

The fd is a requested line, as returned by GetLine.

The values returned are the logical values, with inactive being 0.

func SetLineConfig

func SetLineConfig(fd uintptr, config *HandleConfig) error

SetLineConfig sets the config of an existing handle request.

The config flags in the request will be applied to all lines in the handle request.

func SetLineConfigV2

func SetLineConfigV2(fd uintptr, config *LineConfig) error

SetLineConfigV2 sets the config of an existing handle request.

The config flags in the request will be applied to all lines in the request.

func SetLineValues

func SetLineValues(fd uintptr, values HandleData) error

SetLineValues sets the values of a set of requested lines.

The fd is a requested line, as returned by GetLineHandle or GetLineEvent.

func SetLineValuesV2

func SetLineValuesV2(fd uintptr, values LineValues) error

SetLineValuesV2 sets the values of a set of requested lines.

The fd is a requested line, as returned by GetLine.

func UnwatchLineInfo

func UnwatchLineInfo(fd uintptr, offset uint32) error

UnwatchLineInfo clears a watch on info of a line.

Disables the watch on info for the line.

func WatchLineInfo

func WatchLineInfo(fd uintptr, info *LineInfo) error

WatchLineInfo sets a watch on info of a line.

A watch is set on the line indicated by info.Offset. If successful the current line info is returned, else an error is returned.

func WatchLineInfoV2

func WatchLineInfoV2(fd uintptr, info *LineInfoV2) error

WatchLineInfoV2 sets a watch on info of a line.

A watch is set on the line indicated by info.Offset. If successful the current line info is returned, else an error is returned.

Types

type ChangeType

type ChangeType uint32

ChangeType indicates the type of change that has occurred to a line.

const (

	// LineChangedRequested indicates the line has been requested.
	LineChangedRequested ChangeType

	// LineChangedReleased indicates the line has been released.
	LineChangedReleased

	// LineChangedConfig indicates the line configuration has changed.
	LineChangedConfig
)

type ChipInfo

type ChipInfo struct {
	// The system name of the device.
	Name [nameSize]byte

	// An identifying label added by the device driver.
	Label [nameSize]byte

	// The number of lines supported by this chip.
	Lines uint32
}

ChipInfo contains the details of a GPIO chip.

func GetChipInfo

func GetChipInfo(fd uintptr) (ChipInfo, error)

GetChipInfo returns the ChipInfo for the GPIO character device.

The fd is an open GPIO character device.

type DebouncePeriod

type DebouncePeriod time.Duration

DebouncePeriod specifies the time the line must be stable before a level transition is recognized.

func (*DebouncePeriod) Decode

func (d *DebouncePeriod) Decode(la LineAttribute)

Decode populates the DebouncePeriod with value from the LineAttribute.

func (DebouncePeriod) Encode

func (d DebouncePeriod) Encode() (la LineAttribute)

Encode creates a LineAttribute with the value from the DebouncePeriod.

type EventData

type EventData struct {
	// The time the event was detected.
	Timestamp uint64

	// The type of event detected.
	ID EventFlag
	// contains filtered or unexported fields
}

EventData contains the details of a particular line event.

This is returned via the event request fd in response to events.

func ReadEvent

func ReadEvent(fd uintptr) (EventData, error)

ReadEvent reads a single event from a requested line.

The fd is a requested line, as returned by GetLineEvent.

This function is blocking and should only be called when the fd is known to be ready to read.

type EventFlag

type EventFlag uint32

EventFlag indicates the types of events that will be reported.

const (
	// EventRequestRisingEdge requests rising edge events.
	// This means a transition from a low logical state to a high logical state.
	// For active high lines (the default) this means a transition from a
	// physical low to a physical high.
	// Note that for active low lines this means a transition from a physical
	// high to a physical low.
	EventRequestRisingEdge EventFlag = 1 << iota

	// EventRequestFallingEdge requests falling edge events.
	// This means a transition from a high logical state to a low logical state.
	// For active high lines (the default) this means a transition from a
	// physical high to a physical low.
	// Note that for active low lines this means a transition from a physical
	// low to a physical high.
	EventRequestFallingEdge

	// EventRequestBothEdges requests both rising and falling edge events.
	// This is equivalent to requesting both EventRequestRisingEdge and
	// EventRequestRisingEdge.
	EventRequestBothEdges = EventRequestRisingEdge | EventRequestFallingEdge
)

func (EventFlag) IsBothEdges

func (f EventFlag) IsBothEdges() bool

IsBothEdges returns true if both rising and falling edge events have been requested.

func (EventFlag) IsFallingEdge

func (f EventFlag) IsFallingEdge() bool

IsFallingEdge returns true if falling edge events have been requested.

func (EventFlag) IsRisingEdge

func (f EventFlag) IsRisingEdge() bool

IsRisingEdge returns true if rising edge events have been requested.

type EventRequest

type EventRequest struct {
	// The line to be requested.
	Offset uint32

	// The line flags applied to this line.
	HandleFlags HandleFlag

	// The type of events to report.
	EventFlags EventFlag

	// The string identifying the requester to be applied to the line.
	Consumer [nameSize]byte

	// The file handle for the requested line.
	// Set if the request is successful.
	Fd int32
}

EventRequest is a request for control of a line with event reporting enabled.

type HandleConfig

type HandleConfig struct {
	// The flags to be applied to the lines.
	Flags HandleFlag

	// The default values to be applied to output lines (when
	// HandleRequestOutput is set in the Flags).
	DefaultValues [HandlesMax]uint8
	// contains filtered or unexported fields
}

HandleConfig is a request to change the config of an existing request.

Can be applied to both handle and event requests. Event requests cannot be reconfigured to outputs.

type HandleData

type HandleData [HandlesMax]uint8

HandleData contains the logical value for each line. Zero is a logical low and any other value is a logical high.

type HandleFlag

type HandleFlag uint32

HandleFlag contains the

const (
	// HandleRequestInput requests the line as an input.
	//
	// This is ignored if Output is also set.
	HandleRequestInput HandleFlag = 1 << iota

	// HandleRequestOutput requests the line as an output.
	//
	// This takes precedence over Input, if both are set.
	HandleRequestOutput

	// HandleRequestActiveLow requests the line be made active low.
	HandleRequestActiveLow

	// HandleRequestOpenDrain requests the line be made open drain.
	//
	// This option requires the line to be requested as an Output.
	// This cannot be set at the same time as OpenSource.
	HandleRequestOpenDrain

	// HandleRequestOpenSource requests the line be made open source.
	//
	// This option requires the line to be requested as an Output.
	// This cannot be set at the same time as OpenDrain.
	HandleRequestOpenSource

	// HandleRequestPullUp requests the line have pull-up enabled.
	HandleRequestPullUp

	// HandleRequestPullDown requests the line have pull-down enabled.
	HandleRequestPullDown

	// HandleRequestBiasDisable requests the line have bias disabled.
	HandleRequestBiasDisable

	// HandlesMax is the maximum number of lines that can be requested in a
	// single request.
	HandlesMax = 64
)

func (HandleFlag) HasBiasFlag

func (f HandleFlag) HasBiasFlag() bool

HasBiasFlag returns true if any bias flags are set.

func (HandleFlag) IsActiveLow

func (f HandleFlag) IsActiveLow() bool

IsActiveLow returns true if the line is requested as a active low.

func (HandleFlag) IsBiasDisable

func (f HandleFlag) IsBiasDisable() bool

IsBiasDisable returns true if the line is requested with bias disabled.

func (HandleFlag) IsInput

func (f HandleFlag) IsInput() bool

IsInput returns true if the line is requested as an input.

func (HandleFlag) IsOpenDrain

func (f HandleFlag) IsOpenDrain() bool

IsOpenDrain returns true if the line is requested as an open drain.

func (HandleFlag) IsOpenSource

func (f HandleFlag) IsOpenSource() bool

IsOpenSource returns true if the line is requested as an open source.

func (HandleFlag) IsOutput

func (f HandleFlag) IsOutput() bool

IsOutput returns true if the line is requested as an output.

func (HandleFlag) IsPullDown

func (f HandleFlag) IsPullDown() bool

IsPullDown returns true if the line is requested with pull-down enabled.

func (HandleFlag) IsPullUp

func (f HandleFlag) IsPullUp() bool

IsPullUp returns true if the line is requested with pull-up enabled.

type HandleRequest

type HandleRequest struct {
	// The lines to be requested.
	Offsets [HandlesMax]uint32

	// The flags to be applied to the lines.
	Flags HandleFlag

	// The default values to be applied to output lines.
	DefaultValues [HandlesMax]uint8

	// The string identifying the requester to be applied to the lines.
	Consumer [nameSize]byte

	// The number of lines being requested.
	Lines uint32

	// The file handle for the requested lines.
	// Set if the request is successful.
	Fd int32
}

HandleRequest is a request for control of a set of lines. The lines must all be on the same GPIO chip.

type LineAttribute

type LineAttribute struct {
	ID LineAttributeID

	Padding [1]uint32

	Value [8]byte
}

LineAttribute defines a configuration attribute for a line.

func (*LineAttribute) Encode32

func (la *LineAttribute) Encode32(id LineAttributeID, value uint32)

Encode32 populates the LineAttribute using the id and 32-bit value.

func (*LineAttribute) Encode64

func (la *LineAttribute) Encode64(id LineAttributeID, value uint64)

Encode64 populates the LineAttribute using the id and 64-bit value.

func (LineAttribute) Value32

func (la LineAttribute) Value32() uint32

Value32 returns the 32-bit value from the LineAttribute.

func (LineAttribute) Value64

func (la LineAttribute) Value64() uint64

Value64 returns the 64-bit value from the LineAttribute.

type LineAttributeID

type LineAttributeID uint32

LineAttributeID identfies the type of a configuration attribute.

const (
	// LineAttributeIDFlags indicates the attribute contains LineFlagV2 flags.
	LineAttributeIDFlags LineAttributeID = iota + 1

	// LineAttributeIDOutputValues indicates the attribute contains line output values.
	LineAttributeIDOutputValues

	// LineAttributeIDDebounce indicates the attribute contains a debounce period.
	LineAttributeIDDebounce
)

type LineBitmap

type LineBitmap uint64

LineBitmap is a bitmap containing a bit for each line.

func NewLineBitMask

func NewLineBitMask(n int) LineBitmap

NewLineBitMask returns a mask of n bits.

func NewLineBitmap

func NewLineBitmap(vv ...int) LineBitmap

NewLineBitmap creates a bitmap from an array of bit values.

func NewLineBits

func NewLineBits(vv ...int) LineBitmap

NewLineBits creates a new LineBitmap from an array of bit numbers.

func (LineBitmap) Get

func (lb LineBitmap) Get(n int) int

Get returns the value of the nth bit.

func (LineBitmap) Set

func (lb LineBitmap) Set(n, v int) LineBitmap

Set sets the value of the nth bit.

type LineConfig

type LineConfig struct {
	// The flags to be applied to the lines.
	Flags LineFlagV2

	NumAttrs uint32

	// reserved for future use.
	Padding [lineConfigPadSize]uint32

	Attrs [10]LineConfigAttribute
}

LineConfig contains the configuration of a line.

func (*LineConfig) AddAttribute

func (lc *LineConfig) AddAttribute(lca LineConfigAttribute)

AddAttribute adds an attribute to the configuration.

This is an unconditional add - it performs no filtering or consistency checking other than limiting the number of attributes.

func (*LineConfig) RemoveAttribute

func (lc *LineConfig) RemoveAttribute(lca LineConfigAttribute)

RemoveAttribute removes an attribute from the configuration.

func (*LineConfig) RemoveAttributeID

func (lc *LineConfig) RemoveAttributeID(id LineAttributeID)

RemoveAttributeID removes all attributes with a given ID from the configuration.

type LineConfigAttribute

type LineConfigAttribute struct {
	// Attr contains the configuration attribute.
	Attr LineAttribute

	// Mask identifies the lines to which this attribute applies.
	//
	// This is a bitmap of lines in LineRequest.Offsets.
	Mask LineBitmap
}

LineConfigAttribute associates a configuration attribute with one or more requested lines.

type LineEvent

type LineEvent struct {
	// The time the event was detected.
	Timestamp uint64

	// The type of event detected.
	ID LineEventID

	// The line that triggered the event.
	Offset uint32

	// The seqno for this event in all events on all lines in this line request.
	Seqno uint32

	// The seqno for this event in all events in this line.
	LineSeqno uint32

	// reserved for future use
	Padding [lineEventPadSize]uint32
}

LineEvent contains the details of a particular line event.

This is returned via the event request fd in response to events.

func ReadLineEvent

func ReadLineEvent(fd uintptr) (LineEvent, error)

ReadLineEvent reads a single event from a requested line.

The fd is a requested line, as returned by GetLine.

This function is blocking and should only be called when the fd is known to be ready to read.

type LineEventID

type LineEventID uint32

LineEventID indicates the type of event detected.

const (
	// LineEventRisingEdge indicates the event is a rising edge.
	LineEventRisingEdge LineEventID = iota + 1

	// LineEventFallingEdge indicates the event is a falling edge.
	LineEventFallingEdge
)

type LineFlag

type LineFlag uint32

LineFlag are the flags for a line.

const (
	// LineFlagUsed indicates that the line has been requested.
	// It may have been requested by this process or another process.
	// The line cannot be requested again until this flag is clear.
	LineFlagUsed LineFlag = 1 << iota

	// LineFlagIsOut indicates that the line is an output.
	LineFlagIsOut

	// LineFlagActiveLow indicates that the line is active low.
	LineFlagActiveLow

	// LineFlagOpenDrain indicates that the line will pull low when set low but
	// float when set high. This flag only applies to output lines.
	// An output cannot be both open drain and open source.
	LineFlagOpenDrain

	// LineFlagOpenSource indicates that the line will pull high when set high
	// but float when set low. This flag only applies to output lines.
	// An output cannot be both open drain and open source.
	LineFlagOpenSource

	// LineFlagPullUp indicates that the internal line pull up is enabled.
	LineFlagPullUp

	// LineFlagPullDown indicates that the internal line pull down is enabled.
	LineFlagPullDown

	// LineFlagBiasDisabled indicates that the internal line bias is disabled.
	LineFlagBiasDisabled
)

func (LineFlag) IsActiveLow

func (f LineFlag) IsActiveLow() bool

IsActiveLow returns true if the line is active low.

func (LineFlag) IsBiasDisable

func (f LineFlag) IsBiasDisable() bool

IsBiasDisable returns true if the line has bias disabled.

func (LineFlag) IsOpenDrain

func (f LineFlag) IsOpenDrain() bool

IsOpenDrain returns true if the line is open-drain.

func (LineFlag) IsOpenSource

func (f LineFlag) IsOpenSource() bool

IsOpenSource returns true if the line is open-source.

func (LineFlag) IsOut

func (f LineFlag) IsOut() bool

IsOut returns true if the line is an output.

func (LineFlag) IsPullDown

func (f LineFlag) IsPullDown() bool

IsPullDown returns true if the line has pull-down enabled.

func (LineFlag) IsPullUp

func (f LineFlag) IsPullUp() bool

IsPullUp returns true if the line has pull-up enabled.

func (LineFlag) IsUsed

func (f LineFlag) IsUsed() bool

IsUsed returns true if the line is requested.

type LineFlagV2

type LineFlagV2 uint64

LineFlagV2 are the flags for a line.

const (
	// LineFlagV2Used indicates that the line is already in use.
	// It may have been requested by this process or another process,
	// or may be reserved by the kernel.
	//
	// The line cannot be requested until this flag is clear.
	LineFlagV2Used LineFlagV2 = 1 << iota

	// LineFlagV2ActiveLow indicates that the line is active low.
	LineFlagV2ActiveLow

	// LineFlagV2Input indicates that the line direction is an input.
	LineFlagV2Input

	// LineFlagV2Output indicates that the line direction is an output.
	LineFlagV2Output

	// LineFlagV2EdgeRising indicates that edge detection is enabled for rising
	// edges.
	LineFlagV2EdgeRising

	// LineFlagV2EdgeFalling indicates that edge detection is enabled for
	// falling edges.
	LineFlagV2EdgeFalling

	// LineFlagV2OpenDrain indicates that the line drive is open drain.
	LineFlagV2OpenDrain

	// LineFlagV2OpenSource indicates that the line drive is open source.
	LineFlagV2OpenSource

	// LineFlagV2BiasPullUp indicates that the line bias is pull-up.
	LineFlagV2BiasPullUp

	// LineFlagV2BiasPullDown indicates that the line bias is set pull-down.
	LineFlagV2BiasPullDown

	// LineFlagV2BiasDisabled indicates that the line bias is disabled.
	LineFlagV2BiasDisabled

	// LineFlagV2EventClockRealtime indicates that the CLOCK_REALTIME will be
	// the source for event timestamps.
	LineFlagV2EventClockRealtime

	// LineFlagV2DirectionMask is a mask for all direction flags.
	LineFlagV2DirectionMask = LineFlagV2Input | LineFlagV2Output

	// LineFlagV2EdgeMask is a mask for all edge flags.
	LineFlagV2EdgeMask = LineFlagV2EdgeRising | LineFlagV2EdgeFalling

	// LineFlagV2EdgeBoth is a helper value for selecting edge detection on
	// both edges.
	LineFlagV2EdgeBoth = LineFlagV2EdgeMask

	// LineFlagV2DriveMask is a mask for all drive flags.
	LineFlagV2DriveMask = LineFlagV2OpenDrain | LineFlagV2OpenSource

	// LineFlagV2BiasMask is a mask for all bias flags.
	LineFlagV2BiasMask = LineFlagV2BiasDisabled | LineFlagV2BiasPullUp | LineFlagV2BiasPullDown
)

func (*LineFlagV2) Decode

func (f *LineFlagV2) Decode(la LineAttribute)

Decode populates the LineFlagV2 with value from the LineAttribute.

func (LineFlagV2) Encode

func (f LineFlagV2) Encode() (la LineAttribute)

Encode creates a LineAttribute with the value from the LineFlagV2.

func (LineFlagV2) HasRealtimeEventClock

func (f LineFlagV2) HasRealtimeEventClock() bool

HasRealtimeEventClock returns true if the line events will contain real-time timestamps.

func (LineFlagV2) IsActiveLow

func (f LineFlagV2) IsActiveLow() bool

IsActiveLow returns true if the line is active low.

func (LineFlagV2) IsAvailable

func (f LineFlagV2) IsAvailable() bool

IsAvailable returns true if the line is available to be requested.

func (LineFlagV2) IsBiasDisabled

func (f LineFlagV2) IsBiasDisabled() bool

IsBiasDisabled returns true if the line has bias disabled.

func (LineFlagV2) IsBiasPullDown

func (f LineFlagV2) IsBiasPullDown() bool

IsBiasPullDown returns true if the line has pull-down bias enabled.

func (LineFlagV2) IsBiasPullUp

func (f LineFlagV2) IsBiasPullUp() bool

IsBiasPullUp returns true if the line has pull-up bias enabled.

func (LineFlagV2) IsBothEdges

func (f LineFlagV2) IsBothEdges() bool

IsBothEdges returns true if the line has edge detection on both edges.

func (LineFlagV2) IsFallingEdge

func (f LineFlagV2) IsFallingEdge() bool

IsFallingEdge returns true if the line has edge detection on the falling edge.

func (LineFlagV2) IsInput

func (f LineFlagV2) IsInput() bool

IsInput returns true if the line is an input.

func (LineFlagV2) IsOpenDrain

func (f LineFlagV2) IsOpenDrain() bool

IsOpenDrain returns true if the line is an open drain.

func (LineFlagV2) IsOpenSource

func (f LineFlagV2) IsOpenSource() bool

IsOpenSource returns true if the line is an open source.

func (LineFlagV2) IsOutput

func (f LineFlagV2) IsOutput() bool

IsOutput returns true if the line is an output.

func (LineFlagV2) IsRisingEdge

func (f LineFlagV2) IsRisingEdge() bool

IsRisingEdge returns true if the line has edge detection on the rising edge.

func (LineFlagV2) IsUsed

func (f LineFlagV2) IsUsed() bool

IsUsed returns true if the line is not available to be requested.

type LineInfo

type LineInfo struct {
	// The offset of the line within the chip.
	Offset uint32

	// The line flags applied to this line.
	Flags LineFlag

	// The system name for this line.
	Name [nameSize]byte

	// If requested, a string added by the requester to identify the
	// owner of the request.
	Consumer [nameSize]byte
}

LineInfo contains the details of a single line of a GPIO chip.

func GetLineInfo

func GetLineInfo(fd uintptr, offset int) (LineInfo, error)

GetLineInfo returns the LineInfo for one line from the GPIO character device.

The fd is an open GPIO character device. The offset is zero based.

type LineInfoChanged

type LineInfoChanged struct {
	// The updated info.
	Info LineInfo

	// The time the change occurred.
	Timestamp uint64

	// The type of change.
	Type ChangeType
	// contains filtered or unexported fields
}

LineInfoChanged contains the details of a change to line info.

This is returned via the chip fd in response to changes to watched lines.

func ReadLineInfoChanged

func ReadLineInfoChanged(fd uintptr) (LineInfoChanged, error)

ReadLineInfoChanged reads a line info changed event from a chip.

The fd is an open GPIO character device.

This function is blocking and should only be called when the fd is known to be ready to read.

type LineInfoChangedV2

type LineInfoChangedV2 struct {
	// The updated info.
	Info LineInfoV2

	// The time the change occurred.
	Timestamp uint64

	// The type of change.
	Type ChangeType

	// reserved for future use.
	Padding [lineInfoChangedV2PadSize]uint32
}

LineInfoChangedV2 contains the details of a change to line info.

This is returned via the chip fd in response to changes to watched lines.

func ReadLineInfoChangedV2

func ReadLineInfoChangedV2(fd uintptr) (LineInfoChangedV2, error)

ReadLineInfoChangedV2 reads a line info changed event from a chip.

The fd is an open GPIO character device.

This function is blocking and should only be called when the fd is known to be ready to read.

type LineInfoV2

type LineInfoV2 struct {
	// The system name for this line.
	Name [nameSize]byte

	// If requested, a string added by the requester to identify the
	// owner of the request.
	Consumer [nameSize]byte

	// The offset of the line within the chip.
	Offset uint32

	NumAttrs uint32

	Flags LineFlagV2

	Attrs [10]LineAttribute

	// reserved for future use.
	Padding [lineInfoV2PadSize]uint32
}

LineInfoV2 contains the details of a single line of a GPIO chip.

func GetLineInfoV2

func GetLineInfoV2(fd uintptr, offset int) (LineInfoV2, error)

GetLineInfoV2 returns the LineInfoV2 for one line from the GPIO character device.

The fd is an open GPIO character device. The offset is zero based.

type LineRequest

type LineRequest struct {
	// The lines to be requested.
	Offsets [LinesMax]uint32

	// The string identifying the requester to be applied to the lines.
	Consumer [nameSize]byte

	// The configuration for the requested lines
	Config LineConfig

	// The number of lines being requested.
	Lines uint32

	// Minimum size of the event buffer.
	EventBufferSize uint32

	// reserved for future use.
	Padding [lineRequestPadSize]uint32

	// The file handle for the requested lines.
	// Set if the request is successful.
	Fd int32
}

LineRequest is a request for control of a set of lines. The lines must all be on the same GPIO chip.

type LineValues

type LineValues struct {
	// Bits contains the logical value of the the lines.
	//
	// Zero is a logical low (inactive) and 1 is a logical high (active).
	//
	// This is a bitmap of lines in LineRequest.Offsets.
	Bits LineBitmap

	// Mask identifies the lines to which this attribute applies.
	//
	// This is a bitmap of lines in LineRequest.Offsets.
	Mask LineBitmap
}

LineValues contains the output values for a set of lines.

func (LineValues) Get

func (lv LineValues) Get(n int) int

Get returns the value of the nth bit.

type OutputValues

type OutputValues LineBitmap

OutputValues specify the active level of output lines.

func (*OutputValues) Decode

func (ov *OutputValues) Decode(la LineAttribute)

Decode populates the OutputValues with values from the LineAttribute.

func (OutputValues) Encode

func (ov OutputValues) Encode() (la LineAttribute)

Encode creates a LineAttribute with the values from the OutputValues.

Jump to

Keyboard shortcuts

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