mirror of
https://github.com/kidoman/embd
synced 2025-07-03 11:57:38 +02:00
simplify package structure
This commit is contained in:
parent
3cae4064dc
commit
36f2c0486d
41 changed files with 736 additions and 885 deletions
51
i2c.go
Normal file
51
i2c.go
Normal file
|
@ -0,0 +1,51 @@
|
|||
package embd
|
||||
|
||||
type I2CBus interface {
|
||||
// ReadByte reads a byte from the given address.
|
||||
ReadByte(addr byte) (value byte, err error)
|
||||
// WriteByte writes a byte to the given address.
|
||||
WriteByte(addr, value byte) error
|
||||
// WriteBytes writes a slice bytes to the given address.
|
||||
WriteBytes(addr byte, value []byte) error
|
||||
|
||||
// ReadFromReg reads n (len(value)) bytes from the given address and register.
|
||||
ReadFromReg(addr, reg byte, value []byte) error
|
||||
// ReadByteFromReg reads a byte from the given address and register.
|
||||
ReadByteFromReg(addr, reg byte) (value byte, err error)
|
||||
// ReadU16FromReg reads a unsigned 16 bit integer from the given address and register.
|
||||
ReadWordFromReg(addr, reg byte) (value uint16, err error)
|
||||
|
||||
// WriteToReg writes len(value) bytes to the given address and register.
|
||||
WriteToReg(addr, reg byte, value []byte) error
|
||||
// WriteByteToReg writes a byte to the given address and register.
|
||||
WriteByteToReg(addr, reg, value byte) error
|
||||
// WriteU16ToReg
|
||||
WriteWordToReg(addr, reg byte, value uint16) error
|
||||
}
|
||||
|
||||
type I2C interface {
|
||||
Bus(l byte) I2CBus
|
||||
|
||||
Close() error
|
||||
}
|
||||
|
||||
var i2cInstance I2C
|
||||
|
||||
func InitI2C() error {
|
||||
desc, err := DescribeHost()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
i2cInstance = desc.I2C()
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func CloseI2C() error {
|
||||
return i2cInstance.Close()
|
||||
}
|
||||
|
||||
func NewI2CBus(l byte) I2CBus {
|
||||
return i2cInstance.Bus(l)
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue