Documentation
¶
Overview ¶
Package i2c provides low level interactions with the Linux I²C bus.
Before usage you should load the i2c-dev kernel module
sudo modprobe i2c-dev
Each I²C bus can address 127 independent I²C devices, and most Linux systems contain several buses.
Index ¶
- func DefaultDebugf(string, ...interface{})
- type Device
- func (d *Device) Addr() uint8
- func (d *Device) Bus() int
- func (d *Device) Close() error
- func (d *Device) Read(p []byte) (int, error)
- func (d *Device) ReadReg(p []byte, reg byte) (int, error)
- func (d *Device) SetDebugf(debugf func(format string, args ...interface{}))
- func (d *Device) Write(p []byte) (int, error)
- func (d *Device) WriteByte(b byte) (int, error)
- func (d *Device) WriteReg(p []byte, reg byte) (int, error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DefaultDebugf ¶ added in v0.2.0
func DefaultDebugf(string, ...interface{})
DefaultDebugf is a no-op formatted debug printf function used by the Device type by default. This is exported so that you can use it to toggle debug logging back off using Device.SetDebugf().
Types ¶
type Device ¶
type Device struct {
// contains filtered or unexported fields
}
Device is a connection to a device on the I²C bus. It contains a file handle to a specific device address on a numbered I²C bus.
func New ¶
New opens a new file handle on the provided I²C bus, making an ioctl call to request read/write access to the device at the specified address.
Most interactions start with either reads or writes at a specific register address. See ReadReg and WriteReg.
func (*Device) ReadReg ¶
ReadReg reads I2C device data at the specified register address into the buffer provided. This expects you to right-size the buffer so that it only reads the appropriate amount of data.
func (*Device) SetDebugf ¶
SetDebugf sets a formatted debug function, which can be used to hook in to your logging system.