31 lines
576 B
Go
31 lines
576 B
Go
package i2c
|
|
|
|
import (
|
|
"git.openpdu.org/OpenPDU/openpdu/syslog"
|
|
I2C "periph.io/x/conn/v3/i2c"
|
|
I2CREG "periph.io/x/conn/v3/i2c/i2creg"
|
|
"periph.io/x/host/v3"
|
|
)
|
|
|
|
var I2Cbus I2C.Bus
|
|
|
|
func init() {
|
|
var err error
|
|
|
|
syslog.Info("i2c setup")
|
|
|
|
// Make sure periph is initialized.
|
|
if _, err = host.Init(); err != nil {
|
|
syslog.Err(err.Error())
|
|
}
|
|
|
|
// Use i2creg I²C bus registry to find the first available I²C bus.
|
|
// i2cbus, err = i2creg.Open("/dev/i2c-1")
|
|
I2Cbus, err = I2CREG.Open("")
|
|
if err != nil {
|
|
syslog.Err(err.Error())
|
|
}
|
|
|
|
syslog.Info("i2c setup completed")
|
|
}
|