mirror of
https://github.com/kidoman/embd
synced 2025-07-03 03:47:33 +02:00
add documentation
This commit is contained in:
parent
a35692aabb
commit
0002d02c28
8 changed files with 117 additions and 8 deletions
28
pin.go
28
pin.go
|
@ -1,3 +1,5 @@
|
|||
// Pin mapping support.
|
||||
|
||||
package embd
|
||||
|
||||
import (
|
||||
|
@ -6,16 +8,32 @@ import (
|
|||
)
|
||||
|
||||
const (
|
||||
// CapNormal represents the digital IO capability.
|
||||
CapNormal int = 1 << iota
|
||||
|
||||
// CapI2C represents pins with the I2C capability.
|
||||
CapI2C
|
||||
|
||||
// CapUART represents pins with the UART capability.
|
||||
CapUART
|
||||
|
||||
// CapSPI represents pins with the SPI capability.
|
||||
CapSPI
|
||||
|
||||
// CapGPMS represents pins with the GPMC capability.
|
||||
CapGPMC
|
||||
|
||||
// CapLCD represents pins used to carry LCD data.
|
||||
CapLCD
|
||||
|
||||
// CapPWM represents pins with PWM capability.
|
||||
CapPWM
|
||||
|
||||
// CapAnalog represents pins with analog IO capability.
|
||||
CapAnalog
|
||||
)
|
||||
|
||||
// PinDesc represents a pin descriptor.
|
||||
type PinDesc struct {
|
||||
ID string
|
||||
Aliases []string
|
||||
|
@ -25,8 +43,18 @@ type PinDesc struct {
|
|||
AnalogLogical int
|
||||
}
|
||||
|
||||
// PinMap type represents a collection of pin descriptors.
|
||||
type PinMap []*PinDesc
|
||||
|
||||
// Lookup returns a pin descriptor matching the provided key and capability
|
||||
// combination. This allows the same keys to be used across pins with differing
|
||||
// capabilities. For example, it is perfectly fine to have:
|
||||
//
|
||||
// pin1: {Aliases: [10, GPIO10], Cap: CapNormal}
|
||||
// pin2: {Aliases: [10, AIN0], Cap: CapAnalog}
|
||||
//
|
||||
// Searching for 10 with CapNormal will return pin1 and searching for
|
||||
// 10 with CapAnalog will return pin2. This makes for a very pleasant to use API.
|
||||
func (m PinMap) Lookup(k interface{}, cap int) (*PinDesc, bool) {
|
||||
var ks string
|
||||
switch key := k.(type) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue