1
0
mirror of https://github.com/kidoman/embd synced 2024-12-22 12:50:19 +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() {
Describers[HostBBB] = func(rev int) *Descriptor {
return &Descriptor{
GPIO: func() GPIO {
GPIODriver: func() GPIODriver {
return newGPIODriver(bbbPins, newDigitalPin, newBBBAnalogPin)
},
I2C: newI2CDriver,
I2CDriver: newI2CDriver,
LEDDriver: func() LEDDriver {
return newLEDDriver(bbbLEDMap)
},

View File

@ -6,8 +6,8 @@ import (
)
type Descriptor struct {
GPIO func() GPIO
I2C func() I2C
GPIODriver func() GPIODriver
I2CDriver func() I2CDriver
LEDDriver func() LEDDriver
}

14
gpio.go
View File

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

View File

@ -18,7 +18,7 @@ type gpioDriver struct {
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{
pinMap: pinMap,
dpf: dpf,

12
i2c.go
View File

@ -23,13 +23,13 @@ type I2CBus interface {
WriteWordToReg(addr, reg byte, value uint16) error
}
type I2C interface {
type I2CDriver interface {
Bus(l byte) I2CBus
Close() error
}
var i2cInstance I2C
var i2cDriverInstance I2CDriver
func InitI2C() error {
desc, err := DescribeHost()
@ -37,19 +37,19 @@ func InitI2C() error {
return err
}
if desc.I2C == nil {
if desc.I2CDriver == nil {
return ErrFeatureNotSupport
}
i2cInstance = desc.I2C()
i2cDriverInstance = desc.I2CDriver()
return nil
}
func CloseI2C() error {
return i2cInstance.Close()
return i2cDriverInstance.Close()
}
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
}
func newI2CDriver() I2C {
func newI2CDriver() I2CDriver {
return &i2cDriver{
busMap: make(map[byte]*i2cBus),
}

4
rpi.go
View File

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