1
0
mirror of https://github.com/kidoman/embd synced 2024-12-22 21:00:05 +01:00

- GPIO -> GPIODriver

- I2C -> I2CDriver
This commit is contained in:
Karan Misra 2014-03-23 06:32:24 +05:30
parent bf8a4be4d9
commit 0405cf3f14
7 changed files with 22 additions and 22 deletions

4
bbb.go
View File

@ -12,10 +12,10 @@ import (
func init() { func init() {
Describers[HostBBB] = func(rev int) *Descriptor { Describers[HostBBB] = func(rev int) *Descriptor {
return &Descriptor{ return &Descriptor{
GPIO: func() GPIO { GPIODriver: func() GPIODriver {
return newGPIODriver(bbbPins, newDigitalPin, newBBBAnalogPin) return newGPIODriver(bbbPins, newDigitalPin, newBBBAnalogPin)
}, },
I2C: newI2CDriver, I2CDriver: newI2CDriver,
LEDDriver: func() LEDDriver { LEDDriver: func() LEDDriver {
return newLEDDriver(bbbLEDMap) return newLEDDriver(bbbLEDMap)
}, },

View File

@ -6,9 +6,9 @@ import (
) )
type Descriptor struct { type Descriptor struct {
GPIO func() GPIO GPIODriver func() GPIODriver
I2C func() I2C I2CDriver func() I2CDriver
LEDDriver func() LEDDriver LEDDriver func() LEDDriver
} }
type Describer func(rev int) *Descriptor type Describer func(rev int) *Descriptor

14
gpio.go
View File

@ -36,14 +36,14 @@ type AnalogPin interface {
Close() error Close() error
} }
type GPIO interface { type GPIODriver interface {
DigitalPin(key interface{}) (DigitalPin, error) DigitalPin(key interface{}) (DigitalPin, error)
AnalogPin(key interface{}) (AnalogPin, error) AnalogPin(key interface{}) (AnalogPin, error)
Close() error Close() error
} }
var gpioInstance GPIO var gpioDriverInstance GPIODriver
func InitGPIO() error { func InitGPIO() error {
desc, err := DescribeHost() desc, err := DescribeHost()
@ -51,21 +51,21 @@ func InitGPIO() error {
return err return err
} }
if desc.GPIO == nil { if desc.GPIODriver == nil {
return ErrFeatureNotSupport return ErrFeatureNotSupport
} }
gpioInstance = desc.GPIO() gpioDriverInstance = desc.GPIODriver()
return nil return nil
} }
func CloseGPIO() error { func CloseGPIO() error {
return gpioInstance.Close() return gpioDriverInstance.Close()
} }
func NewDigitalPin(key interface{}) (DigitalPin, error) { func NewDigitalPin(key interface{}) (DigitalPin, error) {
return gpioInstance.DigitalPin(key) return gpioDriverInstance.DigitalPin(key)
} }
func DigitalWrite(key interface{}, val int) error { func DigitalWrite(key interface{}, val int) error {
@ -105,7 +105,7 @@ func ActiveLow(key interface{}, b bool) error {
} }
func NewAnalogPin(key interface{}) (AnalogPin, error) { func NewAnalogPin(key interface{}) (AnalogPin, error) {
return gpioInstance.AnalogPin(key) return gpioDriverInstance.AnalogPin(key)
} }
func AnalogWrite(key interface{}, val int) error { func AnalogWrite(key interface{}, val int) error {

View File

@ -18,7 +18,7 @@ type gpioDriver struct {
initializedPins map[string]pin initializedPins map[string]pin
} }
func newGPIODriver(pinMap PinMap, dpf func(n int) DigitalPin, apf func(n int) AnalogPin) GPIO { func newGPIODriver(pinMap PinMap, dpf func(n int) DigitalPin, apf func(n int) AnalogPin) GPIODriver {
return &gpioDriver{ return &gpioDriver{
pinMap: pinMap, pinMap: pinMap,
dpf: dpf, dpf: dpf,

12
i2c.go
View File

@ -23,13 +23,13 @@ type I2CBus interface {
WriteWordToReg(addr, reg byte, value uint16) error WriteWordToReg(addr, reg byte, value uint16) error
} }
type I2C interface { type I2CDriver interface {
Bus(l byte) I2CBus Bus(l byte) I2CBus
Close() error Close() error
} }
var i2cInstance I2C var i2cDriverInstance I2CDriver
func InitI2C() error { func InitI2C() error {
desc, err := DescribeHost() desc, err := DescribeHost()
@ -37,19 +37,19 @@ func InitI2C() error {
return err return err
} }
if desc.I2C == nil { if desc.I2CDriver == nil {
return ErrFeatureNotSupport return ErrFeatureNotSupport
} }
i2cInstance = desc.I2C() i2cDriverInstance = desc.I2CDriver()
return nil return nil
} }
func CloseI2C() error { func CloseI2C() error {
return i2cInstance.Close() return i2cDriverInstance.Close()
} }
func NewI2CBus(l byte) I2CBus { func NewI2CBus(l byte) I2CBus {
return i2cInstance.Bus(l) return i2cDriverInstance.Bus(l)
} }

View File

@ -15,7 +15,7 @@ type i2cDriver struct {
busMapLock sync.Mutex busMapLock sync.Mutex
} }
func newI2CDriver() I2C { func newI2CDriver() I2CDriver {
return &i2cDriver{ return &i2cDriver{
busMap: make(map[byte]*i2cBus), busMap: make(map[byte]*i2cBus),
} }

4
rpi.go
View File

@ -8,10 +8,10 @@ func init() {
} }
return &Descriptor{ return &Descriptor{
GPIO: func() GPIO { GPIODriver: func() GPIODriver {
return newGPIODriver(pins, newDigitalPin, nil) return newGPIODriver(pins, newDigitalPin, nil)
}, },
I2C: newI2CDriver, I2CDriver: newI2CDriver,
} }
} }
} }