i2cmock

package module
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Mar 4, 2022 License: BSD-3-Clause Imports: 7 Imported by: 0

README

i2cmock

Mock i2c devices easily on any platform.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Bus

type Bus struct {
	// NoLock set to true disables
	// locking bus transaction.
	NoLock bool
	// contains filtered or unexported fields
}

func (*Bus) Add

func (b *Bus) Add(p ...Peripheral)

func (*Bus) Close

func (b *Bus) Close() error

Close should be called after finishing work.

func (*Bus) ReadRegister

func (b *Bus) ReadRegister(address uint8, register uint8, data []byte) error

ReadRegister transmits the register, restarts the connection as a read operation, and reads the response.

Many I2C-compatible devices are organized in terms of registers. This method is a shortcut to easily read such registers. Also, it only works for devices with 7-bit addresses, which is the vast majority.

func (*Bus) SetSpeed

func (b *Bus) SetSpeed(f physic.Frequency) error

func (*Bus) String

func (b *Bus) String() (str string)

func (*Bus) Tx

func (b *Bus) Tx(addr uint16, w, r []byte) error

func (*Bus) WriteRegister

func (b *Bus) WriteRegister(address uint8, register uint8, data []byte) error

WriteRegister transmits first the register and then the data to the peripheral device.

Many I2C-compatible devices are organized in terms of registers. This method is a shortcut to easily write to such registers. Also, it only works for devices with 7-bit addresses, which is the vast majority.

type Peripheral

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

type Registered

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

func NewRegistered

func NewRegistered(addr uint16, regData []byte) Registered

func (Registered) Tx

func (rg Registered) Tx(addr uint16, w, r []byte)

type SPIBus

type SPIBus struct {
	// NoLock set to true disables
	// locking bus transaction.
	NoLock bool
	// contains filtered or unexported fields
}

func (*SPIBus) Add

func (b *SPIBus) Add(p ...Peripheral)

func (*SPIBus) Close

func (b *SPIBus) Close() error

Close should be called after finishing work.

func (*SPIBus) Connect

func (b *SPIBus) Connect(f physic.Frequency, mode spi.Mode, bits int) (spi.Conn, error)

func (*SPIBus) Duplex

func (b *SPIBus) Duplex() conn.Duplex

func (*SPIBus) LimitSpeed

func (b *SPIBus) LimitSpeed(f physic.Frequency) error

func (*SPIBus) SetSpeed

func (b *SPIBus) SetSpeed(f physic.Frequency) error

func (*SPIBus) String

func (b *SPIBus) String() (str string)

func (*SPIBus) Tx

func (s *SPIBus) Tx(w, r []byte) error

func (*SPIBus) TxPackets

func (b *SPIBus) TxPackets(packets []spi.Packet) error

Jump to

Keyboard shortcuts

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