|
|
|
@ -25,7 +25,7 @@ const SkipAddr uint16 = 0xFFFF
|
|
|
|
|
|
|
|
|
|
|
|
// I2C represents an I²C master implemented as bit-banging on 2 GPIO pins.
|
|
|
|
// I2C represents an I²C master implemented as bit-banging on 2 GPIO pins.
|
|
|
|
type I2C struct {
|
|
|
|
type I2C struct {
|
|
|
|
lock sync.Mutex
|
|
|
|
mu sync.Mutex
|
|
|
|
scl gpio.PinIO // Clock line
|
|
|
|
scl gpio.PinIO // Clock line
|
|
|
|
sda gpio.PinIO // Data line
|
|
|
|
sda gpio.PinIO // Data line
|
|
|
|
halfCycle time.Duration
|
|
|
|
halfCycle time.Duration
|
|
|
|
@ -42,8 +42,8 @@ func (i *I2C) Close() error {
|
|
|
|
|
|
|
|
|
|
|
|
// Tx implements i2c.Conn.
|
|
|
|
// Tx implements i2c.Conn.
|
|
|
|
func (i *I2C) Tx(addr uint16, w, r []byte) error {
|
|
|
|
func (i *I2C) Tx(addr uint16, w, r []byte) error {
|
|
|
|
i.lock.Lock()
|
|
|
|
i.mu.Lock()
|
|
|
|
defer i.lock.Unlock()
|
|
|
|
defer i.mu.Unlock()
|
|
|
|
runtime.LockOSThread()
|
|
|
|
runtime.LockOSThread()
|
|
|
|
defer runtime.UnlockOSThread()
|
|
|
|
defer runtime.UnlockOSThread()
|
|
|
|
//syscall.Setpriority(which, who, prio)
|
|
|
|
//syscall.Setpriority(which, who, prio)
|
|
|
|
@ -90,8 +90,8 @@ func (i *I2C) Tx(addr uint16, w, r []byte) error {
|
|
|
|
|
|
|
|
|
|
|
|
// Speed implements i2c.Conn.
|
|
|
|
// Speed implements i2c.Conn.
|
|
|
|
func (i *I2C) Speed(hz int64) error {
|
|
|
|
func (i *I2C) Speed(hz int64) error {
|
|
|
|
i.lock.Lock()
|
|
|
|
i.mu.Lock()
|
|
|
|
defer i.lock.Unlock()
|
|
|
|
defer i.mu.Unlock()
|
|
|
|
i.halfCycle = time.Second / time.Duration(hz) / time.Duration(2)
|
|
|
|
i.halfCycle = time.Second / time.Duration(hz) / time.Duration(2)
|
|
|
|
return nil
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|