mirror of
https://github.com/kidoman/embd
synced 2024-12-22 12:50:19 +01:00
refactor
This commit is contained in:
parent
7851abbedf
commit
0842517208
4
bbb.go
4
bbb.go
@ -16,7 +16,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
Describers[HostBBB] = func(rev int) *Descriptor {
|
Register(HostBBB, func(rev int) *Descriptor {
|
||||||
return &Descriptor{
|
return &Descriptor{
|
||||||
GPIODriver: func() GPIODriver {
|
GPIODriver: func() GPIODriver {
|
||||||
return newGPIODriver(bbbPins, newDigitalPin, newBBBAnalogPin)
|
return newGPIODriver(bbbPins, newDigitalPin, newBBBAnalogPin)
|
||||||
@ -26,7 +26,7 @@ func init() {
|
|||||||
return newLEDDriver(bbbLEDMap)
|
return newLEDDriver(bbbLEDMap)
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
var bbbPins = PinMap{
|
var bbbPins = PinMap{
|
||||||
|
@ -18,7 +18,17 @@ type Descriptor struct {
|
|||||||
type Describer func(rev int) *Descriptor
|
type Describer func(rev int) *Descriptor
|
||||||
|
|
||||||
// Describers is a global list of registered host Describers.
|
// Describers is a global list of registered host Describers.
|
||||||
var Describers = map[Host]Describer{}
|
var describers = make(map[Host]Describer)
|
||||||
|
|
||||||
|
func Register(host Host, describer Describer) {
|
||||||
|
if describer == nil {
|
||||||
|
panic("embd: describer is nil")
|
||||||
|
}
|
||||||
|
if _, dup := describers[host]; dup {
|
||||||
|
panic("embd: describer already registered")
|
||||||
|
}
|
||||||
|
describers[host] = describer
|
||||||
|
}
|
||||||
|
|
||||||
// DescribeHost returns the detected host descriptor.
|
// DescribeHost returns the detected host descriptor.
|
||||||
func DescribeHost() (*Descriptor, error) {
|
func DescribeHost() (*Descriptor, error) {
|
||||||
@ -27,7 +37,7 @@ func DescribeHost() (*Descriptor, error) {
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
describer, ok := Describers[host]
|
describer, ok := describers[host]
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, fmt.Errorf("host: invalid host %q", host)
|
return nil, fmt.Errorf("host: invalid host %q", host)
|
||||||
}
|
}
|
||||||
|
4
rpi.go
4
rpi.go
@ -7,7 +7,7 @@
|
|||||||
package embd
|
package embd
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
Describers[HostRPi] = func(rev int) *Descriptor {
|
Register(HostRPi, func(rev int) *Descriptor {
|
||||||
var pins = rpiRev1Pins
|
var pins = rpiRev1Pins
|
||||||
if rev > 1 {
|
if rev > 1 {
|
||||||
pins = rpiRev2Pins
|
pins = rpiRev2Pins
|
||||||
@ -19,7 +19,7 @@ func init() {
|
|||||||
},
|
},
|
||||||
I2CDriver: newI2CDriver,
|
I2CDriver: newI2CDriver,
|
||||||
}
|
}
|
||||||
}
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
var rpiRev1Pins = PinMap{
|
var rpiRev1Pins = PinMap{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user