You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

45 lines
687 B

// Generic I²C driver.
package embd
import "sync"
type i2cBusFactory func(byte) I2CBus
type i2cDriver struct {
busMap map[byte]I2CBus
busMapLock sync.Mutex
ibf i2cBusFactory
// NewI2CDriver returns a I2CDriver interface which allows control
// over the I²C subsystem.
func NewI2CDriver(ibf i2cBusFactory) I2CDriver {
return &i2cDriver{
busMap: make(map[byte]I2CBus),
ibf: ibf,
func (i *i2cDriver) Bus(l byte) I2CBus {
defer i.busMapLock.Unlock()
if b, ok := i.busMap[l]; ok {
return b
b := i.ibf(l)
i.busMap[l] = b
return b
func (i *i2cDriver) Close() error {
for _, b := range i.busMap {
return nil