i2c

package
v0.0.0-...-d4933c5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 29, 2023 License: BSD-3-Clause Imports: 5 Imported by: 0

Documentation

Overview

Package i2c allows users to read from and write to a slave I2C device.

Deprecated

This package is not maintained anymore. An actively supported cross-platform alternative is https://periph.io/.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func TenBit

func TenBit(addr int) int

TenBit marks an I2C address as a 10-bit address.

Types

type Devfs

type Devfs struct {
	// Dev is the I2C bus device, e.g. /dev/i2c-1. Required.
	Dev string
}

Devfs is an I2C driver that works against the devfs. You need to load the "i2c-dev" kernel module to use this driver.

func (*Devfs) Open

func (d *Devfs) Open(addr int, tenbit bool) (driver.Conn, error)

type Device

type Device struct {
	// contains filtered or unexported fields
}

Device represents an I2C device. Devices must be closed once they are no longer in use.

func Open

func Open(o driver.Opener, addr int) (*Device, error)

Open opens a connection to an I2C device. All devices must be closed once they are no longer in use. For devices that use 10-bit I2C addresses, addr can be marked as a 10-bit address with TenBit.

Example
package main

import (
	"golang.org/x/exp/io/i2c"
)

func main() {
	d, err := i2c.Open(&i2c.Devfs{Dev: "/dev/i2c-1"}, 0x39)
	if err != nil {
		panic(err)
	}

	// opens a 10-bit address
	d, err = i2c.Open(&i2c.Devfs{Dev: "/dev/i2c-1"}, i2c.TenBit(0x78))
	if err != nil {
		panic(err)
	}

	_ = d
}
Output:

func (*Device) Close

func (d *Device) Close() error

Close closes the device and releases the underlying sources.

func (*Device) Read

func (d *Device) Read(buf []byte) error

Read reads len(buf) bytes from the device.

func (*Device) ReadReg

func (d *Device) ReadReg(reg byte, buf []byte) error

ReadReg is similar to Read but it reads from a register.

func (*Device) Write

func (d *Device) Write(buf []byte) (err error)

Write writes the buffer to the device. If it is required to write to a specific register, the register should be passed as the first byte in the given buffer.

func (*Device) WriteReg

func (d *Device) WriteReg(reg byte, buf []byte) (err error)

WriteReg is similar to Write but writes to a register.

Directories

Path Synopsis
Package driver contains interfaces to be implemented by various I2C implementations.
Package driver contains interfaces to be implemented by various I2C implementations.
example
displayip
Package main contains a program that displays the IPv4 address of the machine on an a Grove-LCD RGB backlight.
Package main contains a program that displays the IPv4 address of the machine on an a Grove-LCD RGB backlight.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL