tca95xx

package
v3.7.4 Latest Latest
Warning

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

Go to latest
Published: Mar 16, 2025 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Overview

Package tca95xx provides an interface to the Texas Instruments TCA95 series of 8-bit I²C extenders.

The following variants are supported:

  • PCA9536 - address: 0x41
  • TCA6408A - addresses: 0x20, 0x21
  • TCA6416 - addresses: 0x20, 0x21
  • TCA6416A - addresses: 0x20, 0x21
  • TCA9534 - addresses: 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27
  • TCA9534A - addresses: 0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f
  • TCA9535 - addresses: 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27
  • TCA9537 - address: 0x49
  • TCA9538 - address: 0x70, 0x71, 0x72, 0x73
  • TCA9539 - address: 0x74, 0x75, 0x76, 0x77
  • TCA9554 - addresses: 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27
  • TCA9555 - addresses: 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27

Both gpio.Pin and conn.Conn interfaces are supported.

Example
// Make sure periph is initialized.
if _, err := host.Init(); err != nil {
	log.Fatal(err)
}

// Open default I²C bus.
bus, err := i2creg.Open("")
if err != nil {
	log.Fatalf("failed to open I²C: %v", err)
}
defer bus.Close()

// Create a new I2C IO extender
extender, err := tca95xx.New(bus, tca95xx.TCA9534, 0x20)
if err != nil {
	log.Fatalln(err)
}

for _, port := range extender.Pins {
	for _, pin := range port {
		err = pin.In(gpio.Float, gpio.NoEdge)
		if err != nil {
			log.Fatalln(err)
		}
		level := pin.Read()
		fmt.Printf("%s\t%s\n", pin.Name(), level.String())
	}
}

if err != nil {
	log.Fatalln(err)
}
Output:

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Dev

type Dev struct {
	Pins  [][]Pin     // Pins is a double array structured as: [port][pin].
	Conns []conn.Conn // Conns uses the same [port] array structure.
}

Dev is a TCA95xx series I²C extender with two ways to interact with the pins on the extender chip - as per pin gpio.Pin, or as per port conn.Conn connections.

func New

func New(bus i2c.Bus, variant Variant, addr uint16) (*Dev, error)

New returns a device object that communicates over I²C to the TCA95xx device family of I/O extenders.

func (*Dev) Close

func (d *Dev) Close() error

Close removes any registration to the device.

type Pin

type Pin interface {
	gpio.PinIO
	// SetPolarityInverted if set to true, GPIO register bit reflects the same logic state of the input pin.
	SetPolarityInverted(p bool) error
	// IsPolarityInverted returns true if the value of the input pin reflects inverted logic state.
	IsPolarityInverted() (bool, error)
}

Pin extends gpio.PinIO interface with features supported by tca95xx devices.

type Variant

type Variant string

Variant is the type denoting a specific variant of the family.

const (
	PCA9536  Variant = "PCA9536"  // PCA9536  8-bit I²C extender. Datasheet: https://www.ti.com/lit/gpn/pca9536
	TCA6408A Variant = "TCA6408A" // TCA6408A 8-bit I²C extender. Datasheet: https://www.ti.com/lit/gpn/tca6408a
	TCA6416  Variant = "TCA6416"  // TCA6416  8-bit I²C extender. Datasheet: https://www.ti.com/lit/gpn/tca6416
	TCA6416A Variant = "TCA6416A" // TCA6416A 8-bit I²C extender. Datasheet: https://www.ti.com/lit/gpn/tca6416a
	TCA9534  Variant = "TCA9534"  // TCA9534  8-bit I²C extender. Datasheet: https://www.ti.com/lit/gpn/tca9534
	TCA9534A Variant = "TCA9534A" // TCA9534A 8-bit I²C extender. Datasheet: https://www.ti.com/lit/gpn/tca9534a
	TCA9535  Variant = "TCA9535"  // TCA9535  8-bit I²C extender. Datasheet: https://www.ti.com/lit/gpn/tca9535
	TCA9537  Variant = "TCA9537"  // TCA9537  8-bit I²C extender. Datasheet: https://www.ti.com/lit/gpn/tca9537
	TCA9538  Variant = "TCA9538"  // TCA9538  8-bit I²C extender. Datasheet: https://www.ti.com/lit/gpn/tca9538
	TCA9539  Variant = "TCA9539"  // TCA9539  8-bit I²C extender. Datasheet: https://www.ti.com/lit/gpn/tca9539
	TCA9554  Variant = "TCA9554"  // TCA9554  8-bit I²C extender. Datasheet: https://www.ti.com/lit/gpn/tca9554
	TCA9555  Variant = "TCA9555"  // TCA9555  8-bit I²C extender. Datasheet: https://www.ti.com/lit/gpn/tca9555
)

Jump to

Keyboard shortcuts

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