i2c

package
v0.0.0-...-328052d Latest Latest
Warning

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

Go to latest
Published: May 14, 2023 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Min7BitAddr = 0x08
	Max7BitAddr = 0x77

	Min10BitAddr = 0x7800
	Max10BitAddr = 0x7bff
)

Variables

View Source
var (
	ErrBadAddr     = errors.New("i2c: bad address")
	ErrNack        = errors.New("i2c: NACK")
	ErrUnsupported = errors.New("i2c: unsupported")
)

Functions

This section is empty.

Types

type BaudRateController

type BaudRateController interface {
	SetBaudRate(baudrate uint32) error
}

type Bus

type Bus interface {
	Tx(addr uint16, w, r []byte) error
}

type ByteReaderFrom

type ByteReaderFrom interface{ ReadByteFrom(uint16) (byte, error) }

type ByteWriterTo

type ByteWriterTo interface{ WriteByteTo(byte, uint16) error }

type Controller

type Controller interface {
	Start() error
	Stop() error
	WriteBit(bool) error
	ReadBit() (bool, error)
}

func NewSoftController

func NewSoftController(sda, scl driver.Pin) Controller

NewSoftController will create a generic I2C controller. Pins should be configured as inputs with pull-up and output should be logic-low.

type Device

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

func NewDevice

func NewDevice(bus Bus, addr uint16) *Device

NewDevice returns a new Device with the given bus and address.

func (*Device) Read

func (d *Device) Read(r []byte) (int, error)

func (*Device) ReadByte

func (d *Device) ReadByte() (byte, error)

func (*Device) Tx

func (d *Device) Tx(w, r []byte) (err error)

Tx is a convenience method that sends a write and read request to the device, it uses a reapeated START contidition meaning the bus is not released between the two calls. Otherwise it is the same as calling Write then Read.

func (*Device) Write

func (d *Device) Write(w []byte) (int, error)

func (*Device) WriteByte

func (d *Device) WriteByte(b byte) error

type DeviceID

type DeviceID uint32

type I2C

type I2C struct {
	Controller
}

func New

func New(c Controller) *I2C

func (*I2C) DeviceID

func (i2c *I2C) DeviceID(addr byte) (DeviceID, error)

func (*I2C) Ping

func (i2c *I2C) Ping(addr byte) error

func (*I2C) PingW

func (i2c *I2C) PingW(addr byte) error

func (*I2C) Read

func (i2c *I2C) Read(p []byte) (n int, err error)

Read will read directly from the bus, without any address or start/stop condition.

func (*I2C) ReadByte

func (i2c *I2C) ReadByte() (byte, error)

ReadByte reads a single byte directly from the bus, without any address or start/stop condition.

func (*I2C) ReadByteFrom

func (i2c *I2C) ReadByteFrom(addr uint16) (byte, error)

func (*I2C) ReadFrom

func (i2c *I2C) ReadFrom(p []byte, addr uint16) (int, error)

func (*I2C) ReadRegister

func (i2c *I2C) ReadRegister(addr, reg byte, p []byte) error

func (*I2C) SetBaudrate

func (i2c *I2C) SetBaudrate(baudrate uint32) error

func (*I2C) Tx

func (i2c *I2C) Tx(addr uint16, w, r []byte) (err error)

func (*I2C) TxN

func (i2c *I2C) TxN(addr uint16, w, r []byte) (wn, rn int, err error)

TODO: necessary? rename?

func (*I2C) Write

func (i2c *I2C) Write(p []byte) (int, error)

Write will write directly to the bus, without any address or start/stop condition.

func (*I2C) WriteByte

func (i2c *I2C) WriteByte(b byte) (err error)

WriteByte writes a single byte to the bus, without any address or start/stop condition.

func (*I2C) WriteByteTo

func (i2c *I2C) WriteByteTo(p byte, addr uint16) error

func (*I2C) WriteRegister

func (i2c *I2C) WriteRegister(addr, reg byte, p []byte) error

func (*I2C) WriteTo

func (i2c *I2C) WriteTo(p []byte, addr uint16) (int, error)

type ReaderFrom

type ReaderFrom interface {
	ReadFrom([]byte, uint16) (int, error)
}

type WriterTo

type WriterTo interface {
	WriteTo([]byte, uint16) (int, error)
}

Jump to

Keyboard shortcuts

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