ina260

package
v0.17.1 Latest Latest
Warning

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

Go to latest
Published: Jul 1, 2021 License: BSD-3-Clause Imports: 1 Imported by: 3

Documentation

Index

Constants

View Source
const (
	REG_CONFIG     = 0x00
	REG_CURRENT    = 0x01
	REG_BUSVOLTAGE = 0x02
	REG_POWER      = 0x03
	REG_MASKENABLE = 0x06
	REG_ALERTLIMIT = 0x07
	REG_MANF_ID    = 0xFE
	REG_DIE_ID     = 0xFF
)

Registers

View Source
const (
	MANF_ID        = 0x5449 // TI
	DEVICE_ID      = 0x2270 // 227h
	DEVICE_ID_MASK = 0xFFF0

	AVGMODE_1    = 0
	AVGMODE_4    = 1
	AVGMODE_16   = 2
	AVGMODE_64   = 3
	AVGMODE_128  = 4
	AVGMODE_256  = 5
	AVGMODE_512  = 6
	AVGMODE_1024 = 7

	CONVTIME_140USEC  = 0
	CONVTIME_204USEC  = 1
	CONVTIME_332USEC  = 2
	CONVTIME_588USEC  = 3
	CONVTIME_1100USEC = 4 // 1.1 ms
	CONVTIME_2116USEC = 5 // 2.1 ms
	CONVTIME_4156USEC = 6 // 4.2 ms
	CONVTIME_8244USEC = 7 // 8.2 ms

	MODE_CONTINUOUS = 0x4
	MODE_TRIGGERED  = 0x0
	MODE_VOLTAGE    = 0x2
	MODE_NO_VOLTAGE = 0x0
	MODE_CURRENT    = 0x1
	MODE_NO_CURRENT = 0x0
)

Well-Known Values

View Source
const Address = 0x40

The default I2C address for this device.

The actual address is configurable by connecting address pins.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	// One of AVGMODE_XXX
	AverageMode byte

	// One of CONVTIME_XXXXUSEC
	VoltConvTime byte

	// One of CONVTIME_XXXXUSEC
	CurrentConvTime byte

	// Multiple of MODE_XXXX
	Mode byte
}

Config holds the configuration of the INA260 device.

type Device

type Device struct {
	Address uint16
	// contains filtered or unexported fields
}

Device wraps an I2C connection to an INA260 device.

func New

func New(bus drivers.I2C) Device

New creates a new INA260 connection. The I2C bus must already be configured.

This function only creates the Device object, it does not touch the device.

func (*Device) Configure

func (d *Device) Configure(cfg Config)

Configure sets up the device.

This only needs to be called to override built-in defaults. By default, the device starts with:

* AverageMode = AVGMODE_1 * VoltConvTime = CONVTIME_1100USEC * CurrentConvTime = CONVTIME_1100USEC * Mode = MODE_CONTINUOUS | MODE_VOLTAGE | MODE_CURRENT

func (*Device) Connected

func (d *Device) Connected() bool

Connected returns whether an INA260 has been found.

func (*Device) Current

func (d *Device) Current() int32

Gets the measured current in µA (max resolution 1.25mA)

func (*Device) Power

func (d *Device) Power() int32

Gets the measured power in µW (max resolution 10mW)

func (*Device) ReadRegister

func (d *Device) ReadRegister(reg uint8) uint16

Read a register

func (*Device) Reset

func (d *Device) Reset()

Resets the device, setting all registers to default values

func (*Device) Voltage

func (d *Device) Voltage() int32

Gets the measured voltage in µV (max resolution 1.25mV)

func (*Device) WriteRegister

func (d *Device) WriteRegister(reg uint8, v uint16)

Write to a register

Jump to

Keyboard shortcuts

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