The PCAL9555, PCAL9554 series is a low-voltage 16-bit/8-bit General Purpose Input/Output (GPIO) expander with interrupt. This conponent library is compatible to basic operation os GPIO expanders: PCAL9555, PCA9555, PCA9535, PCA9539, PCAL9554, PCA9554 and PCA9538. On addition to this, this library is including mbed-SDK-style APIs. APIs that similar to DigitaiInOut, DigitalOut, DigitalIn, BusInOUt, BusOut and BusIn are available.

Dependents:   PCAL9555_Hello OM13082-JoyStick OM13082_LED OM13082-test ... more

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers PCAL9554.cpp Source File

PCAL9554.cpp

00001 #include    "mbed.h"
00002 #include    "PCAL9554.h"
00003 
00004 
00005 PCAL9554::PCAL9554( PinName i2c_sda, PinName i2c_scl, char i2c_address )
00006     : PCAL955x( i2c_sda, i2c_scl, i2c_address ), n_of_pins( 8 )
00007 {
00008 }
00009 
00010 PCAL9554::PCAL9554( I2C &i2c_obj, char i2c_address )
00011     : PCAL955x( i2c_obj, i2c_address ), n_of_pins( 8 )
00012 {
00013 }
00014 
00015 PCAL9554::~PCAL9554()
00016 {
00017 }
00018 
00019 int PCAL9554::number_of_pins( void )
00020 {
00021     return ( n_of_pins );
00022 }
00023 
00024 void PCAL9554::reg_index_write( char reg_index, int data )
00025 {
00026     char    a[ 2 ];
00027 
00028     a[ 0 ]  = regmap[ reg_index ];
00029     a[ 1 ]  = data;
00030     
00031     bus_write( a, sizeof( a ) );
00032 }
00033 
00034 int PCAL9554::reg_index_read( char reg_index )
00035 {
00036     char    a;
00037 
00038     bus_read( regmap[ reg_index ], &a, sizeof( a ) );
00039 
00040     return ( a );
00041 }
00042 
00043 PCAL9554& PCAL9554::operator= ( int bit_pattern )
00044 {
00045     write( bit_pattern );
00046     return ( *this );
00047 }
00048 
00049 PCAL9554& PCAL9554::operator= ( PCAL9554& rhs )
00050 {
00051     write( rhs.read() );
00052     return *this;
00053 }
00054 
00055 const char PCAL9554::regmap[]   = {
00056     InputPort,
00057     OutoutPort,
00058     PolarityInversionPort,
00059     ConfigurationPort,
00060     OutputDriveStrength0,
00061     OutputDriveStrength1,
00062     InputLatch,
00063     PullUpPullDowmEnable,
00064     PullUpPullDowmSelection,
00065     InterruptMask,
00066     InterruptStatus,
00067     OutputPortConfiguration
00068 };