i2csoft

package
v0.20.0 Latest Latest
Warning

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

Go to latest
Published: Apr 28, 2022 License: BSD-3-Clause Imports: 3 Imported by: 6

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type I2C

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

I2C is an I2C implementation by Software. Since it is implemented by software, it can be used with microcontrollers that do not have I2C function. This is not efficient but works around broken or missing drivers.

func New

func New(sclPin, sdaPin machine.Pin) *I2C

New returns the i2csoft driver. For the arguments, specify the pins to be used as SCL and SDA. As I2C is implemented in software, any GPIO pin can be specified.

func (*I2C) Configure

func (i2c *I2C) Configure(config I2CConfig) error

Configure is intended to setup the I2C interface.

func (*I2C) ReadRegister

func (i2c *I2C) 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 (*I2C) SetBaudRate

func (i2c *I2C) SetBaudRate(br uint32)

SetBaudRate sets the communication speed for the I2C.

func (*I2C) Tx

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

Tx does a single I2C transaction at the specified address. It clocks out the given address, writes the bytes in w, reads back len(r) bytes and stores them in r, and generates a stop condition on the bus.

func (*I2C) WriteRegister

func (i2c *I2C) 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 I2CConfig

type I2CConfig struct {
	Frequency uint32
	SCL       machine.Pin
	SDA       machine.Pin
}

I2CConfig is used to store config info for I2C.

Jump to

Keyboard shortcuts

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