mirror of
https://github.com/kidoman/embd
synced 2025-07-03 20:07:40 +02:00
make the framework easier to begin with
This commit is contained in:
parent
ef87ad7879
commit
3d08995000
26 changed files with 237 additions and 170 deletions
23
i2c/i2c.go
23
i2c/i2c.go
|
@ -1,6 +1,8 @@
|
|||
// Package i2c enables gophers i2c speaking ability.
|
||||
package i2c
|
||||
|
||||
import "github.com/kidoman/embd/host"
|
||||
|
||||
type Bus interface {
|
||||
// ReadByte reads a byte from the given address.
|
||||
ReadByte(addr byte) (value byte, err error)
|
||||
|
@ -29,3 +31,24 @@ type I2C interface {
|
|||
|
||||
Close() error
|
||||
}
|
||||
|
||||
var instance I2C
|
||||
|
||||
func Open() error {
|
||||
desc, err := host.Describe()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
instance = desc.I2C().(I2C)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func Close() error {
|
||||
return instance.Close()
|
||||
}
|
||||
|
||||
func NewBus(l byte) Bus {
|
||||
return instance.Bus(l)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue