Documentation ¶
Overview ¶
Package i2c defines interface to an I²C bus and an I²C device.
It includes the adapter Dev to directly address an I²C device on a I²C bus without having to continuously specify the address when doing I/O. This enables the support of conn.Conn.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Bus ¶
type Bus interface { Tx(addr uint16, w, r []byte) error // SetSpeed changes the bus speed, if supported. // // On linux due to the way the I²C sysfs driver is exposed in userland, // calling this function will likely affect *all* I²C buses on the host. SetSpeed(hz int64) error }
Bus defines the interface a concrete I²C driver must implement.
This interface is consummed by a device driver for a device sitting on a bus.
This interface doesn't implement conn.Conn since a device address must be specified. Use i2cdev.Dev as an adapter to get a conn.Conn compatible object.
type BusCloser ¶
BusCloser is an I²C bus that can be closed.
This interface is meant to be handled by the application and not the device driver. A device driver doesn't "own" a bus, hence it must operate on a Bus, not a BusCloser.
type Dev ¶
Dev is a device on a I²C bus.
It implements conn.Conn.
It saves from repeatedly specifying the device address.
Example ¶
//b, err := i2creg.Open("") //defer b.Close() var b Bus // Dev is a valid conn.Conn. d := &Dev{Addr: 23, Bus: b} var _ conn.Conn = d // Send a command and expect a 5 bytes reply. reply := [5]byte{} if err := d.Tx([]byte("A command"), reply[:]); err != nil { log.Fatal(err) }
Output:
type Pins ¶
type Pins interface { // SCL returns the CLK (clock) pin. SCL() gpio.PinIO // SDA returns the DATA pin. SDA() gpio.PinIO }
Pins defines the pins that an I²C bus interconnect is using on the host.
It is expected that a implementer of Bus also implement Pins but this is not a requirement.
Example ¶
//b, err := i2creg.Open("") //defer b.Close() var b Bus // Prints out the gpio pin used. if p, ok := b.(Pins); ok { fmt.Printf("SDA: %s", p.SDA()) fmt.Printf("SCL: %s", p.SCL()) }
Output:
Directories ¶
Path | Synopsis |
---|---|
Package i2creg defines I²C bus registry to list buses present on the host.
|
Package i2creg defines I²C bus registry to list buses present on the host. |
Package i2csmoketest is leveraged by periph-smoketest to verify that an I²C EEPROM device and a DS2483 device can be accessed on an I²C bus.
|
Package i2csmoketest is leveraged by periph-smoketest to verify that an I²C EEPROM device and a DS2483 device can be accessed on an I²C bus. |
Package i2ctest is meant to be used to test drivers over a fake I²C bus.
|
Package i2ctest is meant to be used to test drivers over a fake I²C bus. |