1
0
mirror of https://github.com/kidoman/embd synced 2024-12-22 12:50:19 +01:00
This commit is contained in:
Karan Misra 2014-03-24 02:50:24 +05:30
parent 7851abbedf
commit 0842517208
3 changed files with 16 additions and 6 deletions

4
bbb.go
View File

@ -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{

View File

@ -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
View File

@ -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{