Documentation
¶
Overview ¶
Package gpio implements linux GPIO character device interface.
Index ¶
- Constants
- func ChipDevices() (chips []string)
- type Chip
- func (c *Chip) Close() (err error)
- func (c *Chip) Info() (info ChipInfo, err error)
- func (c *Chip) LineInfo(offset uint32) (info LineInfo, err error)
- func (c *Chip) OpenLine(offset uint32, defaultValue byte, flags LineFlag, consumer string) (line *Line, err error)
- func (c *Chip) OpenLineWithEvents(offset uint32, flags LineFlag, eventFlags EventFlag, consumer string) (line *LineWithEvent, err error)
- func (c *Chip) OpenLines(offsets []uint32, defaultValues []byte, flags LineFlag, consumer string) (*Lines, error)
- type ChipInfo
- type Event
- type EventFlag
- type Line
- type LineFlag
- type LineInfo
- type LineWithEvent
- type Lines
Constants ¶
const ( // Direction input. Input = LineFlag(sys.GPIOHANDLE_REQUEST_INPUT) // Direction output. Output = LineFlag(sys.GPIOHANDLE_REQUEST_OUTPUT) // ActiveLow inverts the value for writing. ActiveLow LineFlag = LineFlag(sys.GPIOHANDLE_REQUEST_ACTIVE_LOW) // OpenDrain // // https://embeddedartistry.com/blog/2018/6/4/demystifying-microcontroller-gpio-settings#open-drain-output= // "Unlike push-pull, an open-drain output can only sink current. The output has two states: low and high-impedance. // In order to achieve a logical high output on the line, a pull-up resistor is used to connect the open-drain output // to the desired output voltage level. // You can think of an open-drain GPIO as behaving like a switch which is either connected to ground or disconnected." OpenDrain = LineFlag(sys.GPIOHANDLE_REQUEST_OPEN_DRAIN) OpenSource = LineFlag(sys.GPIOHANDLE_REQUEST_OPEN_SOURCE) )
const ( RisingEdge EventFlag = EventFlag(sys.GPIOEVENT_REQUEST_RISING_EDGE) FallingEdge = EventFlag(sys.GPIOEVENT_EVENT_FALLING_EDGE) BothEdges = RisingEdge | FallingEdge )
Variables ¶
This section is empty.
Functions ¶
func ChipDevices ¶
func ChipDevices() (chips []string)
ChipDevices returns all available GPIO chip devices. The returned paths can be used to call OpenChip.
Types ¶
type Chip ¶
type Chip struct {
// contains filtered or unexported fields
}
Chip is certain GPIO chip.
func (*Chip) LineInfo ¶
LineInfo returns the information about a certain GPIO line. Offset is the local line offset on this GPIO chip.
func (*Chip) OpenLine ¶
func (c *Chip) OpenLine(offset uint32, defaultValue byte, flags LineFlag, consumer string) (line *Line, err error)
OpenLine opens a single GPIO line on this chip. It is equivalent to call OpenLines with a single offset and devault value if Output is set.
func (*Chip) OpenLineWithEvents ¶
func (c *Chip) OpenLineWithEvents(offset uint32, flags LineFlag, eventFlags EventFlag, consumer string) (line *LineWithEvent, err error)
OpenLineWithEvents opens a single GPIO line on this chip for input and GPIO events.
func (*Chip) OpenLines ¶
func (c *Chip) OpenLines(offsets []uint32, defaultValues []byte, flags LineFlag, consumer string) (*Lines, error)
OpenLines opens up to 64 lines on this GPIO chip at once. Parameter offsets are the local line offsets on this chip. Parameter defaultValues specifies the default output values, if Output is set in flags. Value should be 0 (low) or 1 (high), anything else than 0 be interpreted as 1 (high). DefaultValues is ignored if Output is not set in flags. If there are more default values than requested output lines, the extra values will be discarded, and if there are less values, the missing values will be 0s. Parameter flags is or'ed LineFlag values that will be applied to all quested lines. Parameter consumer is a desired consumer label for the selected GPIO line(s) such as "my-bitbanged-relay".
type ChipInfo ¶
type ChipInfo struct { // The Linux kernel name of this GPIO chip. Name string // A functional name for this GPIO chip, such as a product number, may be empty. Label string // Number of GPIO lines on this chip. NumLines uint32 }
ChipInfo is the information about a certain GPIO chip.
type Line ¶
type Line Lines
Line is an opened GPIO line.
type LineInfo ¶
type LineInfo struct { // The offset of this line on the chip. Offset uint32 // The name of this GPIO line, such as the output pin of the line on the // chip, a rail or a pin header name on a board, as specified by the gpio // chip, may be empty. Name string // A functional name for the consumer of this GPIO line as set by // whatever is using it, will be empty if there is no current user but may // also be empty if the consumer doesn't set this up. Consumer string // contains filtered or unexported fields }
LineInfo represents the information about a certain GPIO line
func (*LineInfo) OpenSource ¶
ActiveLow returns whether the GPIO line is configured as open-source.
type LineWithEvent ¶
type LineWithEvent struct {
// contains filtered or unexported fields
}
LineWithEvent is an opened GPIO line whose events can be subscribed.
func (*LineWithEvent) Close ¶
func (l *LineWithEvent) Close() (err error)
func (*LineWithEvent) Events ¶
func (l *LineWithEvent) Events() <-chan *Event
Events returns a channel from which the occurrence time of GPIO events can be read. The GPIO events of this line will be sent to the returned channel, and the channel is closed when l is closed.
Package gpio will not block sending to the channel: it only keeps the lastest value in the channel.
func (*LineWithEvent) Value ¶
func (l *LineWithEvent) Value() (value byte, err error)
Value returns the current value of the GPIO line. 1 (high) or 0 (low).
Directories
¶
Path | Synopsis |
---|---|
Package gpiosysfs implements linux GPIO Sysfs Interface.
|
Package gpiosysfs implements linux GPIO Sysfs Interface. |
samples
Module
|
|
internal
|
|
c
Package c is used is test code only.
|
Package c is used is test code only. |
fdevents
Package fdevents implements epoll_wait loop for GPIO events and exposes a channel interface.
|
Package fdevents implements epoll_wait loop for GPIO events and exposes a channel interface. |
sys
Package sys wraps necessary linux syscalls to implement GPIO interface.
|
Package sys wraps necessary linux syscalls to implement GPIO interface. |
samples
module
|