1
0
mirror of https://github.com/kidoman/embd synced 2024-12-31 17:11:36 +01:00
embd/descriptor.go

45 lines
1.1 KiB
Go
Raw Normal View History

2014-03-23 07:21:22 +05:30
// Host descriptor data structures.
2014-03-03 00:51:23 +05:30
package embd
import (
"errors"
"fmt"
)
2014-03-23 07:21:22 +05:30
// Descriptor represents a host descriptor.
type Descriptor struct {
GPIODriver func() GPIODriver
I2CDriver func() I2CDriver
LEDDriver func() LEDDriver
}
2014-03-23 07:21:22 +05:30
// The Describer type is a Descriptor provider.
type Describer func(rev int) *Descriptor
2014-03-23 07:21:22 +05:30
// Describers is a global list of registered host Describers.
var Describers = map[Host]Describer{}
2014-03-23 07:21:22 +05:30
// DescribeHost returns the detected host descriptor.
2014-03-03 00:51:23 +05:30
func DescribeHost() (*Descriptor, error) {
host, rev, err := DetectHost()
if err != nil {
return nil, err
}
describer, ok := Describers[host]
if !ok {
2014-03-02 19:39:30 +05:30
return nil, fmt.Errorf("host: invalid host %q", host)
}
return describer(rev), nil
}
2014-03-23 07:21:22 +05:30
// ErrFeatureNotSupported is returned when the host does not support a
// particular feature.
2014-03-23 06:41:51 +05:30
var ErrFeatureNotSupported = errors.New("embd: requested feature is not supported")
2014-03-23 07:21:22 +05:30
// ErrFeatureNotImplemented is returned when a particular feature is supported
// by the host but not implemented yet.
2014-03-23 06:41:51 +05:30
var ErrFeatureNotImplemented = errors.New("embd: requested feature is not implemented")