periph

package module
v2.2.0+incompatible Latest Latest
Warning

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

Go to latest
Published: Apr 30, 2018 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()
    for l := gpio.Low; ; l = !l {
        rpi.P1_33.Out(l)
        time.Sleep(500 * time.Millisecond)
    }
}

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
package main

import (
	"fmt"
	"log"

	"periph.io/x/periph/host"
)

func main() {
	// host.Init() registers all the periph-provided host driver automatically,
	// so it is preferable to use than periph.Init().
	//
	// You can also use periph.io/x/extra/hostextra.Init() for additional drivers
	// that depends on cgo and/or third party packages.
	state, err := host.Init()
	if err != nil {
		log.Fatalf("failed to initialize periph: %v", err)
	}

	// Prints the loaded driver.
	fmt.Printf("Using drivers:\n")
	for _, driver := range state.Loaded {
		fmt.Printf("- %s\n", driver)
	}

	// Prints the driver that were skipped as irrelevant on the platform.
	fmt.Printf("Drivers skipped:\n")
	for _, failure := range state.Skipped {
		fmt.Printf("- %s: %s\n", failure.D, failure.Err)
	}

	// Having drivers failing to load may not require process termination. It
	// is possible to continue to run in partial failure mode.
	fmt.Printf("Drivers failed to load:\n")
	for _, failure := range state.Failed {
		fmt.Printf("- %s: %v\n", failure.D, failure.Err)
	}

	// Use pins, buses, devices, etc.
}
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
	// 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.
apa102
apa102 writes to a strip of APA102 LED.
apa102 writes to a strip of APA102 LED.
bmxx80
bmxx80 reads environmental data from a BMP180/BME280/BMP280.
bmxx80 reads environmental data from a BMP180/BME280/BMP280.
gpio-list
gpio-list prints out the function of each GPIO pin.
gpio-list prints out the function of each GPIO pin.
gpio-read
gpio-read reads a GPIO pin.
gpio-read reads a GPIO pin.
gpio-write
gpio-write sets a GPIO pin to low or high.
gpio-write sets a GPIO pin to low or high.
headers-list
headers-list prints out the headers as found on the computer and print the functionality of each pin.
headers-list prints out the headers as found on the computer and print the functionality of each pin.
i2c-io
i2c-io communicates to an I²C device.
i2c-io communicates to an I²C device.
i2c-list
i2c-list lists all I²C buses.
i2c-list lists all I²C buses.
ir
ir reads from an IR receiver via LIRC.
ir reads from an IR receiver via LIRC.
led
led reads the state of a LED or change it.
led reads the state of a LED or change it.
lepton
lepton captures a single image, prints metadata about the camera state or triggers a calibration.
lepton captures a single image, prints metadata about the camera state or triggers a calibration.
onewire-list
onewire-list lists all onewire buses and devices.
onewire-list lists all onewire buses and devices.
periph-info
periph-info prints out information about the loaded periph drivers.
periph-info prints out information about the loaded periph drivers.
periph-smoketest
periph-smoketest runs all known smoke tests.
periph-smoketest runs all known smoke tests.
spi-io
spi-io writes to an SPI port data from stdin and outputs to stdout or writes arguments and outputs hex encoded output.
spi-io writes to an SPI port data from stdin and outputs to stdout or writes arguments and outputs hex encoded output.
spi-list
spi-list lists all SPI ports.
spi-list lists all SPI ports.
ssd1306
ssd1306 writes to a display driven by a ssd1306 controler.
ssd1306 writes to a display driven by a ssd1306 controler.
thermal
thermal reads the state of thermal sensors exposed via sysfs.
thermal reads the state of thermal sensors exposed via sysfs.
tm1637
tm1637 writes to a digits LED display.
tm1637 writes to a digits LED display.
Package conn defines core interfaces for protocols and connections.
Package conn defines core interfaces for protocols and connections.
conntest
Package conntest implements fakes for package conn.
Package conntest implements fakes for package conn.
gpio
Package gpio defines digital pins.
Package gpio defines digital pins.
gpio/gpioreg
Package gpioreg defines a registry for the known digital pins.
Package gpioreg defines a registry for the known digital pins.
gpio/gpiosmoketest
Package gpiosmoketest is leveraged by periph-smoketest to verify that basic GPIO pin functionality work.
Package gpiosmoketest is leveraged by periph-smoketest to verify that basic GPIO pin functionality work.
gpio/gpiostream
Package gpiostream defines digital streams.
Package gpiostream defines digital streams.
gpio/gpiostream/gpiostreamtest
Package gpiostreamtest enables testing device driver using gpiostream.PinIn or PinOut.
Package gpiostreamtest enables testing device driver using gpiostream.PinIn or PinOut.
gpio/gpiotest
Package gpiotest is meant to be used to test drivers using fake Pins.
Package gpiotest is meant to be used to test drivers using fake Pins.
i2c
Package i2c defines interface to an I²C bus and an I²C device.
Package i2c defines interface to an I²C bus and an I²C device.
i2c/i2creg
Package i2creg defines I²C bus registry to list buses present on the host.
Package i2creg defines I²C bus registry to list buses present on the host.
i2c/i2csmoketest
Package i2csmoketest is leveraged by periph-smoketest to verify that an I²C EEPROM device and a DS2483 device can be accessed on an I²C bus.
Package i2csmoketest is leveraged by periph-smoketest to verify that an I²C EEPROM device and a DS2483 device can be accessed on an I²C bus.
i2c/i2ctest
Package i2ctest is meant to be used to test drivers over a fake I²C bus.
Package i2ctest is meant to be used to test drivers over a fake I²C bus.
ir
Package ir defines InfraRed codes for use with a IR remote control.
Package ir defines InfraRed codes for use with a IR remote control.
mmr
Package mmr defines helpers to interact with devices exposing Memory Mapped Registers protocol.
Package mmr defines helpers to interact with devices exposing Memory Mapped Registers protocol.
onewire
Package onewire defines a Dallas Semiconductor / Maxim Integrated 1-wire bus.
Package onewire defines a Dallas Semiconductor / Maxim Integrated 1-wire bus.
onewire/onewirereg
Package onewirereg defines a registry for onewire buses present on the host.
Package onewirereg defines a registry for onewire buses present on the host.
onewire/onewiresmoketest
Package onewiresmoketest is leveraged by periph-smoketest to verify that a 1-wire bus search returns two devices, that a ds18b20 temperature sensor can be read, and that a ds2431 eeprom can be written and read.
Package onewiresmoketest is leveraged by periph-smoketest to verify that a 1-wire bus search returns two devices, that a ds18b20 temperature sensor can be read, and that a ds2431 eeprom can be written and read.
onewire/onewiretest
Package onewiretest is meant to be used to test drivers over a fake 1-wire bus.
Package onewiretest is meant to be used to test drivers over a fake 1-wire bus.
pin
Package pin declare well known pins.
Package pin declare well known pins.
pin/pinreg
Package pinreg is a registry for the physical headers (made up of pins) on a host.
Package pinreg is a registry for the physical headers (made up of pins) on a host.
spi
Package spi defines the SPI protocol.
Package spi defines the SPI protocol.
spi/spireg
Package spireg defines the SPI registry for SPI ports discovered on the host.
Package spireg defines the SPI registry for SPI ports discovered on the host.
spi/spismoketest
Package spismoketest is leveraged by periph-smoketest to verify that an EEPROM device can be accessed on a SPI port.
Package spismoketest is leveraged by periph-smoketest to verify that an EEPROM device can be accessed on a SPI port.
spi/spitest
Package spitest is meant to be used to test drivers over a fake SPI port.
Package spitest is meant to be used to test drivers over a fake SPI port.
Package devices contains interfaces for classes of devices.
Package devices contains interfaces for classes of devices.
apa102
Package apa102 drives a strip of APA102 LEDs connected on a SPI port.
Package apa102 drives a strip of APA102 LEDs connected on a SPI port.
bmxx80
Package bmxx80 controls a Bosch BMP180/BME280/BMP280 device over I²C, or SPI for the BMx280.
Package bmxx80 controls a Bosch BMP180/BME280/BMP280 device over I²C, or SPI for the BMx280.
bmxx80/bmx280smoketest
Package bmx280smoketest is leveraged by periph-smoketest to verify that two BME280/BMP280, one over I²C, one over SPI, read roughly the same temperature, humidity and pressure.
Package bmx280smoketest is leveraged by periph-smoketest to verify that two BME280/BMP280, one over I²C, one over SPI, read roughly the same temperature, humidity and pressure.
devicestest
Package devicestest contains non-hardware devices implementations for testing or emulation purpose.
Package devicestest contains non-hardware devices implementations for testing or emulation purpose.
ds18b20
Package ds18b20 interfaces to Dallas Semi / Maxim DS18B20 and MAX31820 1-wire temperature sensors.
Package ds18b20 interfaces to Dallas Semi / Maxim DS18B20 and MAX31820 1-wire temperature sensors.
ds248x
Package ds248x controls a Maxim DS2483 or DS2482-100 1-wire interface chip over I²C. Datasheets https://www.maximintegrated.com/en/products/digital/one-wire/DS2483.html https://www.maximintegrated.com/en/products/interface/controllers-expanders/DS2482-100.html
Package ds248x controls a Maxim DS2483 or DS2482-100 1-wire interface chip over I²C. Datasheets https://www.maximintegrated.com/en/products/digital/one-wire/DS2483.html https://www.maximintegrated.com/en/products/interface/controllers-expanders/DS2482-100.html
lepton
Package lepton drivers a FLIR Lepton.
Package lepton drivers a FLIR Lepton.
lepton/cci
Package cci declares the Camera Command Interface to interact with a FLIR Lepton over I²C. This protocol controls and queries the camera but is not used to read the images.
Package cci declares the Camera Command Interface to interact with a FLIR Lepton over I²C. This protocol controls and queries the camera but is not used to read the images.
lirc
Package lirc implements InfraRed receiver support through native linux app lirc.
Package lirc implements InfraRed receiver support through native linux app lirc.
ssd1306
Package ssd1306 controls a 128x64 monochrome OLED display via a SSD1306 controller.
Package ssd1306 controls a 128x64 monochrome OLED display via a SSD1306 controller.
ssd1306/image1bit
Package image1bit implements black and white (1 bit per pixel) 2D graphics.
Package image1bit implements black and white (1 bit per pixel) 2D graphics.
ssd1306/ssd1306smoketest
Package ssd1306smoketest is leveraged by periph-smoketest to verify that two SSD1306, one over I²C, one over SPI, can display the same output.
Package ssd1306smoketest is leveraged by periph-smoketest to verify that two SSD1306, one over I²C, one over SPI, can display the same output.
tm1637
Package tm1637 controls a TM1637 device over GPIO pins.
Package tm1637 controls a TM1637 device over GPIO pins.
experimental
cmd/nrzled
nrzled writes to a strip of LEDs using the NRZ protocol.
nrzled writes to a strip of LEDs using the NRZ protocol.
conn/analog
Package analog defines analog pins, both DAC and ADC.
Package analog defines analog pins, both DAC and ADC.
conn/uart
Package uart defines the UART protocol.
Package uart defines the UART protocol.
conn/uart/uartreg
Package uartreg defines the UART registry for UART ports discovered on the host.
Package uartreg defines the UART registry for UART ports discovered on the host.
devices/bitbang
Package bitbang implements conn by banging on the bits (GPIO pins).
Package bitbang implements conn by banging on the bits (GPIO pins).
devices/cap1188
Package cap1188 controls a Microchip cap1188 device over I²C. The cap1188 device is a 8 channel capacitive touch sensor with 8 LED drivers.
Package cap1188 controls a Microchip cap1188 device over I²C. The cap1188 device is a 8 channel capacitive touch sensor with 8 LED drivers.
devices/hd44780
Package hd44780 controls the Hitachi LCD display chipset HD-44780 Datasheet https://www.sparkfun.com/datasheets/LCD/HD44780.pdf
Package hd44780 controls the Hitachi LCD display chipset HD-44780 Datasheet https://www.sparkfun.com/datasheets/LCD/HD44780.pdf
devices/mfrc522
Package mfrc522 controls a Mifare RFID card reader.
Package mfrc522 controls a Mifare RFID card reader.
devices/nrzled
Package nrzled is a driver for LEDs ws2811/ws2812/ws2812b and compatible devices like sk6812 and ucs1903 that uses a single wire NRZ encoded communication protocol.
Package nrzled is a driver for LEDs ws2811/ws2812/ws2812b and compatible devices like sk6812 and ucs1903 that uses a single wire NRZ encoded communication protocol.
devices/piblaster
Package piblaster implements interfacing code is piblaster.
Package piblaster implements interfacing code is piblaster.
driverskeleton
Package driverskeleton is an example that can be copy pasted to help write a new driver, either in devices/ or in host/.
Package driverskeleton is an example that can be copy pasted to help write a new driver, either in devices/ or in host/.
host/pru
Package pru exposes the Programmable Real-Time Unit Subsystem and Industrial Communication Subsystem (PRU-ICSS) functionality found on many Texas Instruments processors.
Package pru exposes the Programmable Real-Time Unit Subsystem and Industrial Communication Subsystem (PRU-ICSS) functionality found on many Texas Instruments processors.
host/sysfs
Package sysfs implements experimental sysfs support not yet in mainline.
Package sysfs implements experimental sysfs support not yet in mainline.
Package host defines the host itself.
Package host defines the host itself.
allwinner
Package allwinner exposes the GPIO functionality that is common to all AllWinner processors.
Package allwinner exposes the GPIO functionality that is common to all AllWinner processors.
allwinner/allwinnersmoketest
Package allwinnersmoketest verifies that allwinner specific functionality work.
Package allwinnersmoketest verifies that allwinner specific functionality work.
am335x
Package am335x exposes functionality for the Texas Instruments Sitara AM335x processor family.
Package am335x exposes functionality for the Texas Instruments Sitara AM335x processor family.
bcm283x
Package bcm283x exposes the BCM283x GPIO functionality.
Package bcm283x exposes the BCM283x GPIO functionality.
bcm283x/bcm283xsmoketest
Package bcm283xsmoketest verifies that bcm283x specific functionality work.
Package bcm283xsmoketest verifies that bcm283x specific functionality work.
beagle
Package beagle regroups subpackages containing BeagleBoard/BeagleBone board family headers definition.
Package beagle regroups subpackages containing BeagleBoard/BeagleBone board family headers definition.
beagle/black
Package black implements headers for the BeagleBone Black and BeagleBone Black Wireless micro-computers.
Package black implements headers for the BeagleBone Black and BeagleBone Black Wireless micro-computers.
beagle/bone
Package bone implements headers J1, P8 and P9 found on many (but not all) BeagleBone micro-computer.
Package bone implements headers J1, P8 and P9 found on many (but not all) BeagleBone micro-computer.
beagle/green
Package green implements headers for the BeagleBone Green and BeagleBone Green Wireless micro-computers.
Package green implements headers for the BeagleBone Green and BeagleBone Green Wireless micro-computers.
chip
Package chip contains header definitions for NextThing Co's C.H.I.P. board.
Package chip contains header definitions for NextThing Co's C.H.I.P. board.
chip/chipsmoketest
Package chipsmoketest is leveraged by periph-smoketest to verify that basic CHIP specific functionality works.
Package chipsmoketest is leveraged by periph-smoketest to verify that basic CHIP specific functionality works.
cpu
Package cpu implements functions relating to the host CPU itself.
Package cpu implements functions relating to the host CPU itself.
distro
Package distro implements common functionality to auto-detect features on the host; generally about linux distributions.
Package distro implements common functionality to auto-detect features on the host; generally about linux distributions.
fs
Package fs provides access to the file system on the host.
Package fs provides access to the file system on the host.
odroidc1
Package odroidc1 contains header definitions for Hardkernel's ODROID C0, C1, and C1+ boards.
Package odroidc1 contains header definitions for Hardkernel's ODROID C0, C1, and C1+ boards.
odroidc1/odroidc1smoketest
Package odroidc1smoketest is leveraged by periph-smoketest to verify that basic ODROID-C1 specific functionality works.
Package odroidc1smoketest is leveraged by periph-smoketest to verify that basic ODROID-C1 specific functionality works.
pine64
Package pine64 contains Pine64 hardware logic.
Package pine64 contains Pine64 hardware logic.
pmem
Package pmem implements handling of physical memory for user space programs.
Package pmem implements handling of physical memory for user space programs.
rpi
Package rpi contains Raspberry Pi hardware logic.
Package rpi contains Raspberry Pi hardware logic.
sysfs
Package sysfs implements a sane library to interact with sysfs provided hardware access.
Package sysfs implements a sane library to interact with sysfs provided hardware access.
sysfs/sysfssmoketest
Package sysfssmoketest verifies that sysfs specific functionality work.
Package sysfssmoketest verifies that sysfs specific functionality work.
videocore
Package videocore interacts with the VideoCore GPU found on bcm283x.
Package videocore interacts with the VideoCore GPU found on bcm283x.

Jump to

Keyboard shortcuts

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