Documentation ¶
Overview ¶
Package buses is for I2C and SPI boards that run Linux. This file is for I2C support on those boards.
Package buses offers SPI and I2C buses for generic Linux systems.
Index ¶
- type I2C
- type I2CHandle
- type I2CRegister
- type I2cHandle
- func (h *I2cHandle) Close() error
- func (h *I2cHandle) Read(ctx context.Context, count int) ([]byte, error)
- func (h *I2cHandle) ReadBlockData(ctx context.Context, register byte, numBytes uint8) ([]byte, error)
- func (h *I2cHandle) ReadByteData(ctx context.Context, register byte) (byte, error)
- func (h *I2cHandle) Write(ctx context.Context, tx []byte) error
- func (h *I2cHandle) WriteBlockData(ctx context.Context, register byte, data []byte) error
- func (h *I2cHandle) WriteByteData(ctx context.Context, register, data byte) error
- type SPI
- type SPIHandle
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type I2C ¶
type I2C interface { // OpenHandle locks returns a handle interface that MUST be closed when done. // you cannot have 2 open for the same addr OpenHandle(addr byte) (I2CHandle, error) }
I2C represents a shareable I2C bus on the board.
type I2CHandle ¶
type I2CHandle interface { Write(ctx context.Context, tx []byte) error Read(ctx context.Context, count int) ([]byte, error) ReadByteData(ctx context.Context, register byte) (byte, error) WriteByteData(ctx context.Context, register, data byte) error ReadBlockData(ctx context.Context, register byte, numBytes uint8) ([]byte, error) WriteBlockData(ctx context.Context, register byte, data []byte) error // Close closes the handle and releases the lock on the bus. Close() error }
I2CHandle is similar to an io handle. It MUST be closed to release the bus.
type I2CRegister ¶
An I2CRegister is a lightweight wrapper around a handle for a particular register.
func (*I2CRegister) ReadByteData ¶
func (reg *I2CRegister) ReadByteData(ctx context.Context) (byte, error)
ReadByteData reads a byte from the I2C channel register.
func (*I2CRegister) WriteByteData ¶
func (reg *I2CRegister) WriteByteData(ctx context.Context, data byte) error
WriteByteData writes a byte to the I2C channel register.
type I2cHandle ¶
type I2cHandle struct {
// contains filtered or unexported fields
}
I2cHandle represents a way to talk to a specific device on the I2C bus. Creating a handle locks the bus so nothing else can use it, and closing the handle unlocks it again.
func (*I2cHandle) Read ¶
Read reads the given number of bytes from the handle. For I2C devices that organize their data into registers, prefer using ReadBlockData instead.
func (*I2cHandle) ReadBlockData ¶
func (h *I2cHandle) ReadBlockData(ctx context.Context, register byte, numBytes uint8) ([]byte, error)
ReadBlockData reads the given number of bytes from the I2C device, starting at the given register.
func (*I2cHandle) ReadByteData ¶
ReadByteData reads a single byte from the given register on this I2C device.
func (*I2cHandle) Write ¶
Write writes the given bytes to the handle. For I2C devices that organize their data into registers, prefer using WriteBlockData instead.
func (*I2cHandle) WriteBlockData ¶
WriteBlockData writes the given bytes into the given register on the I2C device.
type SPI ¶
type SPI interface { // OpenHandle locks the shared bus and returns a handle interface that MUST be closed when done. OpenHandle() (SPIHandle, error) Close(ctx context.Context) error }
SPI represents a shareable SPI bus on a generic Linux board.
type SPIHandle ¶
type SPIHandle interface { // Xfer performs a single SPI transfer, that is, the complete transaction from chipselect // enable to chipselect disable. SPI transfers are synchronous, number of bytes received will // be equal to the number of bytes sent. Write-only transfers can usually just discard the // returned bytes. Read-only transfers usually transmit a request/address and continue with // some number of null bytes to equal the expected size of the returning data. Large // transmissions are usually broken up into multiple transfers. There are many different // paradigms for most of the above, and implementation details are chip/device specific. Xfer( ctx context.Context, baud uint, chipSelect string, mode uint, tx []byte, ) ([]byte, error) // Close closes the handle and releases the lock on the bus. Close() error }
SPIHandle is similar to an io handle. It MUST be closed to release the bus.