added documentation

This commit is contained in:
Karan Misra 2014-03-23 07:21:22 +05:30
parent 3f88b67361
commit a35692aabb
6 changed files with 57 additions and 0 deletions

7
bbb.go
View File

@ -1,3 +1,10 @@
// BeagleBone Black support.
// The following features are supported on Linux kernel 3.8+
//
// GPIO (both digital (rw) and analog (ro))
// I2C
// LED
package embd
import (

View File

@ -1,3 +1,5 @@
// Host descriptor data structures.
package embd
import (
@ -5,16 +7,20 @@ import (
"fmt"
)
// Descriptor represents a host descriptor.
type Descriptor struct {
GPIODriver func() GPIODriver
I2CDriver func() I2CDriver
LEDDriver func() LEDDriver
}
// The Describer type is a Descriptor provider.
type Describer func(rev int) *Descriptor
// Describers is a global list of registered host Describers.
var Describers = map[Host]Describer{}
// DescribeHost returns the detected host descriptor.
func DescribeHost() (*Descriptor, error) {
host, rev, err := DetectHost()
if err != nil {
@ -29,5 +35,10 @@ func DescribeHost() (*Descriptor, error) {
return describer(rev), nil
}
// ErrFeatureNotSupported is returned when the host does not support a
// particular feature.
var ErrFeatureNotSupported = errors.New("embd: requested feature is not supported")
// ErrFeatureNotImplemented is returned when a particular feature is supported
// by the host but not implemented yet.
var ErrFeatureNotImplemented = errors.New("embd: requested feature is not implemented")

View File

@ -1,3 +1,5 @@
// Host detection.
package embd
import (
@ -7,13 +9,23 @@ import (
"strings"
)
// The Host type represents all the supported host types.
type Host int
const (
// HostNull reprents a null host.
HostNull Host = iota
// HostRPi represents the RaspberryPi.
HostRPi
// HostBBB represents the BeagleBone Black.
HostBBB
// HostCubieTruck represents the Cubie Truck.
HostCubieTruck
// HostGalileo represents the Intel Galileo board.
HostGalileo
)
@ -60,6 +72,7 @@ func kernelVersion() (major, minor, patch int, err error) {
return parseVersion(output)
}
// DetectHost returns the detected host and its revision number.
func DetectHost() (Host, int, error) {
major, minor, patch, err := kernelVersion()
if err != nil {

8
i2c.go
View File

@ -1,5 +1,8 @@
// I2C support.
package embd
// I2CBus interface is used to interact with the I2C bus.
type I2CBus interface {
// ReadByte reads a byte from the given address.
ReadByte(addr byte) (value byte, err error)
@ -23,6 +26,8 @@ type I2CBus interface {
WriteWordToReg(addr, reg byte, value uint16) error
}
// I2CDriver interface interacts with the host descriptors to allow us
// control of I2C communication.
type I2CDriver interface {
Bus(l byte) I2CBus
@ -31,6 +36,7 @@ type I2CDriver interface {
var i2cDriverInstance I2CDriver
// InitI2C initializes the I2C driver.
func InitI2C() error {
desc, err := DescribeHost()
if err != nil {
@ -46,10 +52,12 @@ func InitI2C() error {
return nil
}
// CloseI2C gracefully closes the I2C driver.
func CloseI2C() error {
return i2cDriverInstance.Close()
}
// NewI2CBus returns a I2CBus corresponding to the provided address.
func NewI2CBus(l byte) I2CBus {
return i2cDriverInstance.Bus(l)
}

12
led.go
View File

@ -1,5 +1,8 @@
// LED support.
package embd
// The LED interface is used to control a led on the prototyping board.
type LED interface {
On() error
Off() error
@ -9,6 +12,8 @@ type LED interface {
Close() error
}
// LEDDriver interface interacts with the host descriptors to allow us
// control of the LEDs.
type LEDDriver interface {
LED(key interface{}) (LED, error)
@ -17,6 +22,7 @@ type LEDDriver interface {
var ledDriverInstance LEDDriver
// InitLED initializes the LED driver.
func InitLED() error {
desc, err := DescribeHost()
if err != nil {
@ -32,14 +38,18 @@ func InitLED() error {
return nil
}
// CloseLED gracefully closes the LED driver.
func CloseLED() error {
return ledDriverInstance.Close()
}
// NewLED returns a LED interface which allows control over the LED
// represented by key.
func NewLED(key interface{}) (LED, error) {
return ledDriverInstance.LED(key)
}
// LEDOn switches the corresponding LED on.
func LEDOn(key interface{}) error {
led, err := NewLED(key)
if err != nil {
@ -49,6 +59,7 @@ func LEDOn(key interface{}) error {
return led.On()
}
// LEDOff switches the corresponding LED off.
func LEDOff(key interface{}) error {
led, err := NewLED(key)
if err != nil {
@ -58,6 +69,7 @@ func LEDOff(key interface{}) error {
return led.Off()
}
// LEDToggle toggles the corresponding LED.
func LEDToggle(key interface{}) error {
led, err := NewLED(key)
if err != nil {

6
rpi.go
View File

@ -1,3 +1,9 @@
// RaspberryPi support.
// The following features are supported on Linux kernel 3.8+
//
// GPIO (digital (rw))
// I2C
package embd
func init() {