The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Device::Chip::Base::RegisteredI2C - base class for drivers of register-oriented I²C chips

DESCRIPTION

This subclass of Device::Chip provides some handy utility methods to implement a chip driver that supports a chip which (largely) operates on the common pattern of registers; that is, that writes to and reads from the chip are performed on numerically-indexed register locations, holding independent values. This is a common pattern that a lot of I²C chips adhere to.

CONSTANTS

REG_DATA_SIZE

Gives the number of bits of data each register occupies. Normally this value is 8, but sometimes chips like high-resolution ADCs and DACs might work with a larger size like 16 or 24. This value ought to be a multiple of 8.

Overriding this constant to a different value will affect the interpretation of the $len parameter to the register reading and writing methods.

METHODS

The following methods documented with a trailing call to ->get return Future instances.

read_reg

   $val = $chip->read_reg( $reg, $len )->get

Performs a write_then_read I²C transaction, sending the register number as a single byte value, then attempts to read the given number of register slots.

write_reg

   $chip->write_reg( $reg, $val )->get

Performs a write I²C transaction, sending the register number as a single byte value followed by the data to write into it.

cached_read_reg

   $val = $chip->cached_read_reg( $reg, $len )->get

Implements a cache around the given register location. Returns the last value known to have been read from or written to the register; or reads it from the actual chip if no interaction has yet been made. Once a cache slot has been created for the register by calling this method, the read_reg and write_reg methods will also keep it updated.

This method should be used by chip drivers for interacting with configuration-style registers; that is, registers that the chip itself will treat as simple storage of values. It is not suitable for registers that the chip itself will update.

cached_write_reg

   $chip->cached_write_reg( $reg, $val )->get

Optionally writes a new value for the given register location. This method will invoke write_reg except if the register already exists in the cache and already has the given value according to the cache.

This method should be used by chip drivers for interacting with configuration-style registers; that is, registers that the chip itself will treat as simple storage of values. It is not suitable for registers that the chip itself will update.

AUTHOR

Paul Evans <leonerd@leonerd.org.uk>