Device::Chip::Base::RegisteredI2C - base class for drivers of register-oriented I²C chips
Device::Chip::Base::RegisteredI2C
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.
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.
$len
The following methods documented with a trailing call to ->get return Future instances.
->get
$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_then_read
$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.
write
$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.
$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.
write_reg
Paul Evans <leonerd@leonerd.org.uk>
To install Device::Chip, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Device::Chip
CPAN shell
perl -MCPAN -e shell install Device::Chip
For more information on module installation, please visit the detailed CPAN module installation guide.