gpio

package module
v0.0.0-...-c6b66f6 Latest Latest
Warning

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

Go to latest
Published: Sep 13, 2016 License: BSD-2-Clause Imports: 6 Imported by: 4

README

gpio

GPIO for Go

testing

Please run the 'blink' example found under examples/blink. Proper tests will be added soon.

alternatives

https://github.com/mrmorphic/hwio is another project aiming to expose the hardware capabilities of embedded systems via Go.

Documentation

Overview

Package gpio provides a user space interface to GPIO pins.

Index

Constants

View Source
const (
	GPIO0     = 0
	GPIO1     = 1
	GPIO2     = 2
	GPIO3     = 3
	GPIO4     = 4
	GPIO7     = 7
	GPIO8     = 8
	GPIO9     = 9
	GPIO10    = 10
	GPIO11    = 11
	GPIO17    = 17
	GPIO18    = 18
	GPIO22    = 22
	GPIO23    = 23
	GPIO24    = 24
	GPIO25    = 25
	GPIOCount = 16 // the number of GPIO pins available
)

Variables

This section is empty.

Functions

func WriteFile

func WriteFile(path string, format string, args ...interface{}) error

Types

type Edge

type Edge string

Edge represents the edge on which a pin interrupt is triggered

const (
	EdgeNone    Edge = "none"
	EdgeRising  Edge = "rising"
	EdgeFalling Edge = "falling"
	EdgeBoth    Edge = "both"
)

type IRQEvent

type IRQEvent func()

IRQEvent defines the callback function used to inform the caller of an interrupt.

type Mode

type Mode string

Mode represents a state of a GPIO pin

const (
	ModeInput  Mode = "in"
	ModeOutput Mode = "out"
	ModePWM         = "pwm"
)

type Pin

type Pin struct {
	Number int // the pin number

	ModePath  string   // the path to the /direction FD to avoid string joining each time
	EdgePath  string   // the path to the /edge FD to avoid string joining each time
	ValueFile *os.File // the file handle for the value file

	Initial bool // is this the initial epoll trigger?
	// contains filtered or unexported fields
}

Pin represents a GPIO pin.

func (*Pin) BeginWatch

func (p *Pin) BeginWatch(edge Edge, callback IRQEvent) error

func (*Pin) Clear

func (p *Pin) Clear()

Clear sets the pin level low.

func (*Pin) Close

func (p *Pin) Close() error

Close destroys the virtual files on the filesystem, unexporting the pin.

func (*Pin) EndWatch

func (p *Pin) EndWatch() error

EndWatch stops watching the pin

func (*Pin) Err

func (p *Pin) Err() error

Err returns the last error encountered.

func (*Pin) Get

func (p *Pin) Get() bool

Get retrieves the current pin level.

func (*Pin) GetMode

func (p *Pin) GetMode() Mode

func (*Pin) Mode

func (p *Pin) Mode() Mode

Mode retrieves the current mode of the pin.

func (*Pin) Set

func (p *Pin) Set()

Set sets the pin level high.

func (*Pin) SetMode

func (p *Pin) SetMode(mode Mode)

SetMode sets the mode of the pin.

func (*Pin) Wait

func (p *Pin) Wait(condition bool)

Wait blocks while waits for the pin state to match the condition, then returns.

type Pinner

type Pinner interface {
	Mode() Mode                      // gets the current pin mode
	SetMode(Mode)                    // set the current pin mode
	Set()                            // sets the pin state high
	Clear()                          // sets the pin state low
	Close() error                    // if applicable, closes the pin
	Get() bool                       // returns the current pin state
	BeginWatch(Edge, IRQEvent) error // calls the function argument when an edge trigger event occurs
	EndWatch() error                 // stops watching the pin
	Wait(bool)                       // wait for pin state to match boolean argument

	Err() error // returns the last error state
}

Pinner represents a GPIO pin.

func OpenPin

func OpenPin(n int, mode Mode) (Pinner, error)

OpenPin exports the pin, creating the virtual files necessary for interacting with the pin. It also sets the mode for the pin, making it ready for use.

Directories

Path Synopsis
examples
package rpi provides a GPIO implementation customised for the RPi.
package rpi provides a GPIO implementation customised for the RPi.

Jump to

Keyboard shortcuts

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