NAME

HiPi::Device::I2C

VERSION

Version 0.01

SYNOPSYS

use HiPi::Device::I2C qw( ioctl );

my $i2c = HiPi::Device::I2C->new('/dev/i2c-1');

$i2c->select_address( 0x20 );

$i2c->smbus_write($regadress, @bytes);

my @bytes = $i2c->smbus_read($regadress, $numbytes);

DESCRIPTION

Experimental interface to I2C. Currently used by HiPi::MCP23017 and HiPi::Control::LCD::HTBackpackV2 in i2c mode.

METHODS

new

$i2c = HiPi::Device::I2C->new('/dev/i2c-1');

Pass the i2c device name to the constructor

select_address

$i2c->select_address( $address );

Pass the address of the i2c device you wish to control. For example, the default address of the popular MCP23017 device is 0x20

$i2c->select_address( 0x20 );

smbus_write

$i2c->smbus_write( @vals );

Use smbus interface to write data.

If scalar @vals == 1 then calls i2c_smbus_write_byte( file, $vals[0])

If scalar @vals == 2 then calls i2c_smbus_write_byte_data( file, $vals[0], $vals[1])

Else calls i2c_smbus_write_i2c_block_data(file, $vals[0], \@vals[1 ..-1])

smbus_read

my @vals $i2c->smbus_read( $cmdval, $numbytes );

Use smbus interface to read data.

If $cmdval is not defined then calls i2c_smbus_read_byte( file )

If $numbytes <= 1 then calls i2c_smbus_read_byte_data( file, $cmdval)

Else calls i2c_smbus_read_ic2_block_data(file, $cmdval, $numbytes)

LICENSE

This work is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3 of the License, or any later version.

License Note

I would normally release any Perl code under the Perl Artistic License but this module wraps several GPL / LGPL C libraries and I feel that the licensing of the entire distribution is simpler if the Perl code is under GPL too.

AUTHOR

Mark Dootson, <mdootson at cpan.org>

COPYRIGHT

Copyright (C) 2012-2013 Mark Dootson, all rights reserved.