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

improve doc

This commit is contained in:
Karan Misra 2013-12-09 03:25:29 +05:30
parent f51069beb0
commit 92e466966e

View File

@ -14,21 +14,28 @@ import (
const ( const (
delay = 20 delay = 20
slaveCmd = 0x0703 slaveCmd = 0x0703 // Cmd to set slave address
rdrwCmd = 0x0707 rdrwCmd = 0x0707 // Cmd to read/write data together
I2C_M_RD = 0x0001 rd = 0x0001
) )
type Bus interface { type Bus interface {
// Read a byte from the given address.
ReadByte(addr byte) (value byte, err error) ReadByte(addr byte) (value byte, err error)
// Write a byte to the given address.
WriteByte(addr, value byte) error WriteByte(addr, value byte) error
// Write a bunch of bytes ot the given address.
WriteBytes(addr byte, value []byte) error WriteBytes(addr byte, value []byte) error
// Read a bunch of bytes (len(value)) from the given address and register.
ReadFromReg(addr, reg byte, value []byte) (err error) ReadFromReg(addr, reg byte, value []byte) (err error)
// Read a byte from the given address and register.
ReadByteFromReg(addr, reg byte) (value byte, err error) ReadByteFromReg(addr, reg byte) (value byte, err error)
// Read a int from the given address and register.
ReadInt(addr, reg byte) (value int, err error) ReadInt(addr, reg byte) (value int, err error)
// Write a byte to the given address and register.
WriteToReg(addr, reg, value byte) error WriteToReg(addr, reg, value byte) error
} }
@ -46,6 +53,8 @@ type i2c_rdwr_ioctl_data struct {
var busMap map[byte]*bus var busMap map[byte]*bus
var busMapLock sync.Mutex var busMapLock sync.Mutex
// Default instance of the i2c bus
var Default Bus var Default Bus
type bus struct { type bus struct {
@ -180,7 +189,7 @@ func (b *bus) ReadFromReg(addr, reg byte, value []byte) (err error) {
messages[0].buf = uintptr(unsafe.Pointer(&reg)) messages[0].buf = uintptr(unsafe.Pointer(&reg))
messages[1].addr = uint16(addr) messages[1].addr = uint16(addr)
messages[1].flags = I2C_M_RD messages[1].flags = rd
messages[1].len = uint16(len(value)) messages[1].len = uint16(len(value))
messages[1].buf = uintptr(unsafe.Pointer(hdrp.Data)) messages[1].buf = uintptr(unsafe.Pointer(hdrp.Data))