mcp23xxx

package
v3.7.2 Latest Latest
Warning

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

Go to latest
Published: Oct 30, 2024 License: Apache-2.0 Imports: 10 Imported by: 1

Documentation

Overview

Package mcp23xxx provides driver for the MCP23 family of IO extenders

Datasheet

https://ww1.microchip.com/downloads/en/DeviceDoc/20001952C.pdf

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 := mcp23xxx.NewI2C(bus, mcp23xxx.MCP23017, 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 provide access to extender pins.
	Pins [][]Pin
}

Dev his a handle for a configured MCP23xxx device.

func NewI2C

func NewI2C(b i2c.Bus, variant Variant, addr uint16) (*Dev, error)

NewI2C initializes an IO extender through I2C connection.

func NewSPI

func NewSPI(b spi.Conn, variant Variant) (*Dev, error)

NewSPI initializes an IO extender through I2C connection.

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 MCP23xxx devices.

type Variant

type Variant string

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

const (
	// MCP23008 8-bit I2C extender. Datasheet: https://www.microchip.com/wwwproducts/en/MCP23008
	MCP23008 Variant = "MCP23008"

	// MCP23S08 8-bit SPI extender. Datasheet: https://www.microchip.com/wwwproducts/en/MCP23S08
	MCP23S08 Variant = "MCP23S08"

	// MCP23009 8-bit I2C extender. Datasheet: https://www.microchip.com/wwwproducts/en/MCP23009
	MCP23009 Variant = "MCP23009"

	// MCP23S09 8-bit SPI extender. Datasheet: https://www.microchip.com/wwwproducts/en/MCP23S09
	MCP23S09 Variant = "MCP23S09"

	// MCP23016 16-bit I2C extender. Datasheet: https://www.microchip.com/wwwproducts/en/MCP23016
	MCP23016 Variant = "MCP23016"

	// MCP23017 8-bit I2C extender. Datasheet: https://www.microchip.com/wwwproducts/en/MCP23017
	MCP23017 Variant = "MCP23017"

	// MCP23S17 8-bit SPI extender. Datasheet: https://www.microchip.com/wwwproducts/en/MCP23S17
	MCP23S17 Variant = "MCP23S17"

	// MCP23018 8-bit I2C extender. Datasheet: https://www.microchip.com/wwwproducts/en/MCP23018
	MCP23018 Variant = "MCP23018"

	// MCP23S18 8-bit SPI extender. Datasheet: https://www.microchip.com/wwwproducts/en/MCP23S18
	MCP23S18 Variant = "MCP23S18"
)

Jump to

Keyboard shortcuts

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