periph

package module
v3.6.6+incompatible Latest Latest
Warning

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

Go to latest
Published: Dec 24, 2020 License: Apache-2.0 Imports: 4 Imported by: 0

README

periph - Peripherals I/O in Go

mascot

Documentation is at https://periph.io

GoDoc Go Report Card Coverage Status Build Status

Join us for a chat on gophers.slack.com/messages/periph, get an invite here.

Example

Blink a LED:

package main

import (
    "time"
    "periph.io/x/periph/conn/gpio"
    "periph.io/x/periph/host"
    "periph.io/x/periph/host/rpi"
)

func main() {
    host.Init()
    t := time.NewTicker(500 * time.Millisecond)
    for l := gpio.Low; ; l = !l {
        rpi.P1_33.Out(l)
        <-t.C
    }
}

Curious? Look at supported devices for more examples!

Authors

periph was initiated with ❤️️ and passion by Marc-Antoine Ruel. The full list of contributors is in AUTHORS and CONTRIBUTORS.

Disclaimer

This is not an official Google product (experimental or otherwise), it is just code that happens to be owned by Google.

This project is not affiliated with the Go project.

Documentation

Overview

Package periph is a peripheral I/O library.

Package periph acts as a registry of drivers. It is focused on providing high quality host drivers that provide high-speed access to the hardware on the host computer itself.

To learn more about the goals and design, visit https://periph.io/

Every device driver should register itself in its package init() function by calling periph.MustRegister().

User shall call either host.Init() or hostextra.Init() on startup to initialize all the registered drivers.

Cmd

cmd/ contains executable tools to communicate directly with the devices or the buses.

cmd/ is allowed to import from conn/, devices/ and host/.

Conn

conn/ contains interfaces and registries for all the supported protocols and connections (I²C, SPI, GPIO, etc).

conn/ is not allowed to import from any other package.

Devices

devices/ contains devices drivers that are connected to bus, port or connection (i.e I²C, SPI, 1-wire, GPIO) that can be controlled by the host, i.e. ssd1306 (display controller), bm280 (environmental sensor), etc.

devices/ is allowed to import from conn/ and host/.

Experimental

experimental/ contains the drivers that are in the experimental area, not yet considered stable. See https://periph.io/project/#driver-lifetime-management for the process to move drivers out of this area.

experimental/ is allowed to import from conn/, devices/ and host/.

Host

host/ contains all the implementations relating to the host itself, the CPU and buses that are exposed by the host onto which devices can be connected, i.e. I²C, SPI, GPIO, etc.

host/ is allowed to import from conn/ only.

Example
Output:

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func MustRegister

func MustRegister(d Driver)

MustRegister calls Register() and panics if registration fails.

This is the function to call in a driver's package init() function.

func Register

func Register(d Driver) error

Register registers a driver to be initialized automatically on Init().

The d.String() value must be unique across all registered drivers.

It is an error to call Register() after Init() was called.

Types

type Driver

type Driver interface {
	// String returns the name of the driver, as to be presented to the user.
	//
	// It must be unique in the list of registered drivers.
	String() string
	// Prerequisites returns a list of drivers that must be successfully loaded
	// first before attempting to load this driver.
	//
	// A driver listing a prerequisite not registered is a fatal failure at
	// initialization time.
	Prerequisites() []string
	// After returns a list of drivers that must be loaded first before
	// attempting to load this driver.
	//
	// Unlike Prerequisites(), this driver will still be attempted even if the
	// listed driver is missing or failed to load.
	//
	// This permits serialization without hard requirement.
	After() []string
	// Init initializes the driver.
	//
	// A driver may enter one of the three following state: loaded successfully,
	// was skipped as irrelevant on this host, failed to load.
	//
	// On success, it must return true, nil.
	//
	// When irrelevant (skipped), it must return false, errors.New(<reason>).
	//
	// On failure, it must return true, errors.New(<reason>). The failure must
	// state why it failed, for example an expected OS provided driver couldn't
	// be opened, e.g. /dev/gpiomem on Raspbian.
	Init() (bool, error)
}

Driver is an implementation for a protocol.

type DriverFailure

type DriverFailure struct {
	D   Driver
	Err error
}

DriverFailure is a driver that wasn't loaded, either because it was skipped or because it failed to load.

func (DriverFailure) String

func (d DriverFailure) String() string

type State

type State struct {
	Loaded  []Driver
	Skipped []DriverFailure
	Failed  []DriverFailure
}

State is the state of loaded device drivers.

Each list is sorted by the driver name.

func Init

func Init() (*State, error)

Init initialises all the relevant drivers.

Drivers are started concurrently.

It is safe to call this function multiple times, the previous state is returned on later calls.

Users will want to use host.Init(), which guarantees a baseline of included host drivers.

Directories

Path Synopsis
cmd
Package cmd contains tools.
Package cmd contains tools.
Package conn defines core interfaces for protocols and connections.
Package conn defines core interfaces for protocols and connections.
Package devices is a container for device drivers.
Package devices is a container for device drivers.
experimental
Package host defines the host itself.
Package host defines the host itself.

Jump to

Keyboard shortcuts

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