pin

package
v3.8.0+incompatible Latest Latest
Warning

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

Go to latest
Published: Aug 30, 2021 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Overview

Package pin declare well known pins.

pin is about physical pins, not about their logical function.

While not a protocol strictly speaking, these are "well known constants".

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BasicPin

type BasicPin struct {
	N string
}

BasicPin implements Pin as a static pin.

It doesn't have a usable functionality.

Example
package main

import (
	"fmt"

	"periph.io/x/periph/conn/pin"
)

func main() {
	// Declare a basic pin, that is not a GPIO, for registration on an header.
	b := &pin.BasicPin{N: "Exotic"}
	fmt.Println(b)

}
Output:

Exotic
var (
	INVALID  *BasicPin // Either floating or invalid pin
	GROUND   *BasicPin // Ground
	V1_8     *BasicPin // 1.8V (filtered)
	V2_8     *BasicPin // 2.8V (filtered)
	V3_3     *BasicPin // 3.3V (filtered)
	V5       *BasicPin // 5V (filtered)
	DC_IN    *BasicPin // DC IN; this is normally the 5V input
	BAT_PLUS *BasicPin // LiPo Battery + connector
)

These are well known pins.

func (*BasicPin) Func

func (b *BasicPin) Func() Func

Func implements PinFunc.

Returns FuncNone as pin function.

func (*BasicPin) Function

func (b *BasicPin) Function() string

Function implements Pin.

Returns "" as pin function.

func (*BasicPin) Halt

func (b *BasicPin) Halt() error

Halt implements conn.Resource.

func (*BasicPin) Name

func (b *BasicPin) Name() string

Name implements Pin.

func (*BasicPin) Number

func (b *BasicPin) Number() int

Number implements Pin.

Returns -1 as pin number.

func (*BasicPin) SetFunc

func (b *BasicPin) SetFunc(f Func) error

SetFunc implements PinFunc.

func (*BasicPin) String

func (b *BasicPin) String() string

String implements conn.Resource.

func (*BasicPin) SupportedFuncs

func (b *BasicPin) SupportedFuncs() []Func

SupportedFuncs implements PinFunc.

Returns nil.

type Func

type Func string

Func is a pin function.

The Func format must be "[A-Z]+", "[A-Z]+_[A-Z]+" or exceptionally "(In|Out)/(Low|High)".

const FuncNone Func = ""

FuncNone is returned by PinFunc.Func() for a Pin without an active functionality.

func (Func) Generalize

func (f Func) Generalize() Func

Generalize is the reverse of Specialize().

Example
package main

import (
	"fmt"

	"periph.io/x/periph/conn/pin"
)

func main() {
	fmt.Println(pin.Func("SPI1_CS2").Generalize())
	fmt.Println(pin.Func("SPI1_MOSI").Generalize())
	fmt.Println(pin.Func("CSI_D3").Generalize())
	fmt.Println(pin.Func("INVALID").Generalize())
}
Output:

SPI_CS
SPI_MOSI
CSI_D
INVALID

func (Func) Specialize

func (f Func) Specialize(b, l int) Func

Specialize converts a "BUS_LINE" function and appends the bug number and line number, to look like "BUS0_LINE1".

Use -1 to not add a bus or line number.

Example
package main

import (
	"fmt"

	"periph.io/x/periph/conn/pin"
	"periph.io/x/periph/conn/spi"
)

func main() {
	// Specializes both bus and line.
	fmt.Println(spi.CS.Specialize(1, 2))
	// Specializes only bus.
	fmt.Println(spi.MOSI.Specialize(1, -1))
	// Specializes only line.
	fmt.Println(pin.Func("CSI_D").Specialize(-1, 3))
	// Specializes neither.
	fmt.Println(pin.Func("INVALID").Specialize(-1, -1))
}
Output:

SPI1_CS2
SPI1_MOSI
CSI_D3
INVALID

type Pin

type Pin interface {
	conn.Resource
	// Name returns the name of the pin.
	Name() string
	// Number returns the logical pin number or a negative number if the pin is
	// not a GPIO, e.g. GROUND, V3_3, etc.
	Number() int
	// Function returns a user readable string representation of what the pin is
	// configured to do. Common case is In and Out but it can be bus specific pin
	// name.
	//
	// Deprecated: Use PinFunc.Func. Will be removed in v4.
	Function() string
}

Pin is the minimal common interface shared between gpio.PinIO and analog.PinIO.

type PinFunc

type PinFunc interface {
	// Func returns the pin's current function.
	//
	// The returned value may be specialized or generalized, depending on the
	// actual port. For example it will likely be generalized for ports served
	// over USB (like a FT232H with D0 set as SPI_MOSI) but specialized for
	// ports on the base board (like a RPi3 with GPIO10 set as SPI0_MOSI).
	Func() Func
	// SupportedFuncs returns the possible functions this pin support.
	//
	// Do not mutate the returned slice.
	SupportedFuncs() []Func
	// SetFunc sets the pin function.
	//
	// Example use is to reallocate a RPi3's GPIO14 active function between
	// UART0_TX and UART1_TX.
	SetFunc(f Func) error
}

PinFunc is a supplementary interface that enables specifically querying for the pin function.

TODO(maruel): It will be merged into interface Pin for v4.

Example
package main

import (
	"log"

	"periph.io/x/periph/conn/gpio/gpioreg"
	"periph.io/x/periph/conn/pin"
	"periph.io/x/periph/conn/uart"
)

func main() {
	p := gpioreg.ByName("GPIO14")
	if p == nil {
		log.Fatal("not running on a raspberry pi")
	}
	pf, ok := p.(pin.PinFunc)
	if !ok {
		log.Fatal("pin.PinFunc is not implemented")
	}
	// Select UART1_TX.
	f := uart.TX.Specialize(1, -1)
	if err := pf.SetFunc(f); err != nil {
		log.Fatal(err)
	}
}
Output:

Directories

Path Synopsis
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.

Jump to

Keyboard shortcuts

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