add: humidity (WIP)
This commit is contained in:
		
							
								
								
									
										58
									
								
								vendor/periph.io/x/periph/conn/pin/func.go
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										58
									
								
								vendor/periph.io/x/periph/conn/pin/func.go
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							@@ -0,0 +1,58 @@
 | 
			
		||||
// Copyright 2018 The Periph Authors. All rights reserved.
 | 
			
		||||
// Use of this source code is governed under the Apache License, Version 2.0
 | 
			
		||||
// that can be found in the LICENSE file.
 | 
			
		||||
 | 
			
		||||
package pin
 | 
			
		||||
 | 
			
		||||
import (
 | 
			
		||||
	"strconv"
 | 
			
		||||
	"strings"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
// Func is a pin function.
 | 
			
		||||
//
 | 
			
		||||
// The Func format must be "[A-Z]+", "[A-Z]+_[A-Z]+" or exceptionally
 | 
			
		||||
// "(In|Out)/(Low|High)".
 | 
			
		||||
type Func string
 | 
			
		||||
 | 
			
		||||
// FuncNone is returned by PinFunc.Func() for a Pin without an active
 | 
			
		||||
// functionality.
 | 
			
		||||
const FuncNone 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.
 | 
			
		||||
func (f Func) Specialize(b, l int) Func {
 | 
			
		||||
	if f == FuncNone {
 | 
			
		||||
		return FuncNone
 | 
			
		||||
	}
 | 
			
		||||
	if b != -1 {
 | 
			
		||||
		parts := strings.SplitN(string(f), "_", 2)
 | 
			
		||||
		if len(parts) == 1 {
 | 
			
		||||
			return FuncNone
 | 
			
		||||
		}
 | 
			
		||||
		f = Func(parts[0] + strconv.Itoa(b) + "_" + parts[1])
 | 
			
		||||
	}
 | 
			
		||||
	if l != -1 {
 | 
			
		||||
		f += Func(strconv.Itoa(l))
 | 
			
		||||
	}
 | 
			
		||||
	return f
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// Generalize is the reverse of Specialize().
 | 
			
		||||
func (f Func) Generalize() Func {
 | 
			
		||||
	parts := strings.SplitN(string(f), "_", 2)
 | 
			
		||||
	f = Func(strings.TrimRightFunc(parts[0], isNum))
 | 
			
		||||
	if len(parts) == 2 {
 | 
			
		||||
		f += "_"
 | 
			
		||||
		f += Func(strings.TrimRightFunc(parts[1], isNum))
 | 
			
		||||
	}
 | 
			
		||||
	return f
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
//
 | 
			
		||||
 | 
			
		||||
func isNum(r rune) bool {
 | 
			
		||||
	return r >= '0' && r <= '9'
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										139
									
								
								vendor/periph.io/x/periph/conn/pin/pin.go
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										139
									
								
								vendor/periph.io/x/periph/conn/pin/pin.go
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							@@ -0,0 +1,139 @@
 | 
			
		||||
// Copyright 2016 The Periph Authors. All rights reserved.
 | 
			
		||||
// Use of this source code is governed under the Apache License, Version 2.0
 | 
			
		||||
// that can be found in the LICENSE file.
 | 
			
		||||
 | 
			
		||||
// 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".
 | 
			
		||||
package pin
 | 
			
		||||
 | 
			
		||||
import (
 | 
			
		||||
	"errors"
 | 
			
		||||
 | 
			
		||||
	"periph.io/x/periph/conn"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
// These are well known pins.
 | 
			
		||||
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
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
// Pin is the minimal common interface shared between gpio.PinIO and
 | 
			
		||||
// analog.PinIO.
 | 
			
		||||
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
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// PinFunc is a supplementary interface that enables specifically querying for
 | 
			
		||||
// the pin function.
 | 
			
		||||
//
 | 
			
		||||
// TODO(maruel): It will be merged into interface Pin for v4.
 | 
			
		||||
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
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
//
 | 
			
		||||
 | 
			
		||||
// BasicPin implements Pin as a static pin.
 | 
			
		||||
//
 | 
			
		||||
// It doesn't have a usable functionality.
 | 
			
		||||
type BasicPin struct {
 | 
			
		||||
	N string
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// String implements conn.Resource.
 | 
			
		||||
func (b *BasicPin) String() string {
 | 
			
		||||
	return b.N
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// Halt implements conn.Resource.
 | 
			
		||||
func (b *BasicPin) Halt() error {
 | 
			
		||||
	return nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// Name implements Pin.
 | 
			
		||||
func (b *BasicPin) Name() string {
 | 
			
		||||
	return b.N
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// Number implements Pin.
 | 
			
		||||
//
 | 
			
		||||
// Returns -1 as pin number.
 | 
			
		||||
func (b *BasicPin) Number() int {
 | 
			
		||||
	return -1
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// Function implements Pin.
 | 
			
		||||
//
 | 
			
		||||
// Returns "" as pin function.
 | 
			
		||||
func (b *BasicPin) Function() string {
 | 
			
		||||
	return ""
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// Func implements PinFunc.
 | 
			
		||||
//
 | 
			
		||||
// Returns FuncNone as pin function.
 | 
			
		||||
func (b *BasicPin) Func() Func {
 | 
			
		||||
	return FuncNone
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// SupportedFuncs implements PinFunc.
 | 
			
		||||
//
 | 
			
		||||
// Returns nil.
 | 
			
		||||
func (b *BasicPin) SupportedFuncs() []Func {
 | 
			
		||||
	return nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// SetFunc implements PinFunc.
 | 
			
		||||
func (b *BasicPin) SetFunc(f Func) error {
 | 
			
		||||
	return errors.New("pin: can't change static pin function")
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func init() {
 | 
			
		||||
	INVALID = &BasicPin{N: "INVALID"}
 | 
			
		||||
	GROUND = &BasicPin{N: "GROUND"}
 | 
			
		||||
	V1_8 = &BasicPin{N: "1.8V"}
 | 
			
		||||
	V2_8 = &BasicPin{N: "2.8V"}
 | 
			
		||||
	V3_3 = &BasicPin{N: "3.3V"}
 | 
			
		||||
	V5 = &BasicPin{N: "5V"}
 | 
			
		||||
	DC_IN = &BasicPin{N: "DC_IN"}
 | 
			
		||||
	BAT_PLUS = &BasicPin{N: "BAT+"}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
var _ Pin = INVALID
 | 
			
		||||
var _ PinFunc = INVALID
 | 
			
		||||
							
								
								
									
										7
									
								
								vendor/periph.io/x/periph/conn/pin/pinreg/doc.go
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										7
									
								
								vendor/periph.io/x/periph/conn/pin/pinreg/doc.go
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							@@ -0,0 +1,7 @@
 | 
			
		||||
// Copyright 2016 The Periph Authors. All rights reserved.
 | 
			
		||||
// Use of this source code is governed under the Apache License, Version 2.0
 | 
			
		||||
// that can be found in the LICENSE file.
 | 
			
		||||
 | 
			
		||||
// Package pinreg is a registry for the physical headers (made up of pins) on
 | 
			
		||||
// a host.
 | 
			
		||||
package pinreg
 | 
			
		||||
							
								
								
									
										148
									
								
								vendor/periph.io/x/periph/conn/pin/pinreg/pinreg.go
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										148
									
								
								vendor/periph.io/x/periph/conn/pin/pinreg/pinreg.go
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							@@ -0,0 +1,148 @@
 | 
			
		||||
// Copyright 2016 The Periph Authors. All rights reserved.
 | 
			
		||||
// Use of this source code is governed under the Apache License, Version 2.0
 | 
			
		||||
// that can be found in the LICENSE file.
 | 
			
		||||
 | 
			
		||||
package pinreg
 | 
			
		||||
 | 
			
		||||
import (
 | 
			
		||||
	"errors"
 | 
			
		||||
	"strconv"
 | 
			
		||||
	"sync"
 | 
			
		||||
 | 
			
		||||
	"periph.io/x/periph/conn/gpio"
 | 
			
		||||
	"periph.io/x/periph/conn/gpio/gpioreg"
 | 
			
		||||
	"periph.io/x/periph/conn/pin"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
// All contains all the on-board headers on a micro computer.
 | 
			
		||||
//
 | 
			
		||||
// The map key is the header name, e.g. "P1" or "EULER" and the value is a
 | 
			
		||||
// slice of slice of pin.Pin. For a 2x20 header, it's going to be a slice of
 | 
			
		||||
// [20][2]pin.Pin.
 | 
			
		||||
func All() map[string][][]pin.Pin {
 | 
			
		||||
	mu.Lock()
 | 
			
		||||
	defer mu.Unlock()
 | 
			
		||||
	out := make(map[string][][]pin.Pin, len(allHeaders))
 | 
			
		||||
	for k, v := range allHeaders {
 | 
			
		||||
		outV := make([][]pin.Pin, len(v))
 | 
			
		||||
		for i, w := range v {
 | 
			
		||||
			outW := make([]pin.Pin, len(w))
 | 
			
		||||
			copy(outW, w)
 | 
			
		||||
			outV[i] = outW
 | 
			
		||||
		}
 | 
			
		||||
		out[k] = outV
 | 
			
		||||
	}
 | 
			
		||||
	return out
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// Position returns the position on a pin if found.
 | 
			
		||||
//
 | 
			
		||||
// The header and the pin number. Pin numbers are 1-based.
 | 
			
		||||
//
 | 
			
		||||
// Returns "", 0 if not connected.
 | 
			
		||||
func Position(p pin.Pin) (string, int) {
 | 
			
		||||
	mu.Lock()
 | 
			
		||||
	defer mu.Unlock()
 | 
			
		||||
	pos, _ := byPin[realPin(p).Name()]
 | 
			
		||||
	return pos.name, pos.number
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// IsConnected returns true if the pin is on a header.
 | 
			
		||||
func IsConnected(p pin.Pin) bool {
 | 
			
		||||
	_, i := Position(p)
 | 
			
		||||
	return i != 0
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// Register registers a physical header.
 | 
			
		||||
//
 | 
			
		||||
// It automatically registers all gpio pins to gpioreg.
 | 
			
		||||
func Register(name string, allPins [][]pin.Pin) error {
 | 
			
		||||
	mu.Lock()
 | 
			
		||||
	defer mu.Unlock()
 | 
			
		||||
	if _, ok := allHeaders[name]; ok {
 | 
			
		||||
		return errors.New("pinreg: header " + strconv.Quote(name) + " was already registered")
 | 
			
		||||
	}
 | 
			
		||||
	for i, line := range allPins {
 | 
			
		||||
		for j, pin := range line {
 | 
			
		||||
			if pin == nil || len(pin.Name()) == 0 {
 | 
			
		||||
				return errors.New("pinreg: invalid pin on header " + name + "[" + strconv.Itoa(i+1) + "][" + strconv.Itoa(j+1) + "]")
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
	allHeaders[name] = allPins
 | 
			
		||||
	number := 1
 | 
			
		||||
	for _, line := range allPins {
 | 
			
		||||
		for _, p := range line {
 | 
			
		||||
			byPin[realPin(p).Name()] = position{name, number}
 | 
			
		||||
			number++
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	count := 0
 | 
			
		||||
	for _, row := range allPins {
 | 
			
		||||
		for _, p := range row {
 | 
			
		||||
			count++
 | 
			
		||||
			if _, ok := p.(gpio.PinIO); ok {
 | 
			
		||||
				if err := gpioreg.RegisterAlias(name+"_"+strconv.Itoa(count), p.Name()); err != nil {
 | 
			
		||||
					// Unregister as much as possible.
 | 
			
		||||
					_ = unregister(name)
 | 
			
		||||
					return errors.New("pinreg: " + err.Error())
 | 
			
		||||
				}
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	return nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// Unregister removes a previously registered header.
 | 
			
		||||
//
 | 
			
		||||
// This can happen when an USB device, which exposed an header, is unplugged.
 | 
			
		||||
// This is also useful for unit testing.
 | 
			
		||||
func Unregister(name string) error {
 | 
			
		||||
	mu.Lock()
 | 
			
		||||
	defer mu.Unlock()
 | 
			
		||||
	return unregister(name)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
//
 | 
			
		||||
 | 
			
		||||
type position struct {
 | 
			
		||||
	name   string // Header name
 | 
			
		||||
	number int    // Pin number
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
var (
 | 
			
		||||
	mu         sync.Mutex
 | 
			
		||||
	allHeaders = map[string][][]pin.Pin{} // every known headers as per internal lookup table
 | 
			
		||||
	byPin      = map[string]position{}    // GPIO pin name to position
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
func unregister(name string) error {
 | 
			
		||||
	if hdr, ok := allHeaders[name]; ok {
 | 
			
		||||
		var err error
 | 
			
		||||
		delete(allHeaders, name)
 | 
			
		||||
		count := 0
 | 
			
		||||
		for _, row := range hdr {
 | 
			
		||||
			for _, p := range row {
 | 
			
		||||
				count++
 | 
			
		||||
				if _, ok := p.(gpio.PinIO); ok {
 | 
			
		||||
					if err1 := gpioreg.Unregister(name + "_" + strconv.Itoa(count)); err1 != nil && err == nil {
 | 
			
		||||
						// Continue unregistering as much as possible.
 | 
			
		||||
						err = errors.New("pinreg: " + err1.Error())
 | 
			
		||||
					}
 | 
			
		||||
				}
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
		return err
 | 
			
		||||
	}
 | 
			
		||||
	return errors.New("pinreg: can't unregister unknown header name " + strconv.Quote(name))
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// realPin returns the real pin from an alias.
 | 
			
		||||
func realPin(p pin.Pin) pin.Pin {
 | 
			
		||||
	if r, ok := p.(gpio.RealPin); ok {
 | 
			
		||||
		p = r.Real()
 | 
			
		||||
	}
 | 
			
		||||
	return p
 | 
			
		||||
}
 | 
			
		||||
		Reference in New Issue
	
	Block a user