Andriy Makukha / PCAL6416
Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers PCAL955x.h Source File

PCAL955x.h

00001 /** PCAL955x GPIO with Agile I/O, interrupt and weak pull-up family
00002  *
00003  *  Abstract class for PCAL955x/PCAL6416 family
00004  *  No instance can be made from this class
00005  *
00006  *  @class    PCAL955x
00007  *  @author   Akifumi (Tedd) OKANO, NXP Semiconductors
00008  *  @version  0.5.1
00009  *  @date     07-Mar-2015
00010  *  @modified 15-Feb-2017, by Andriy Makukha, Shenzhen MZJ Technology Co.
00011  *
00012  *  Released under the Apache 2 license
00013  */
00014 
00015 #ifndef     MBED_PCAL955x
00016 #define     MBED_PCAL955x
00017 
00018 #include    "mbed.h"
00019 #include    "CompGpioExp.h"
00020 
00021 /** Abstract class for PCAL955x/PCAL6416 family
00022  *  
00023  *  No instance can be made from this class
00024  */
00025 class PCAL955x : public CompGpioExp
00026 {
00027 public:
00028     enum register_index {
00029         INPUT,
00030         OUTPUT,
00031         POLARITY,
00032         CONFIG,
00033         ODS0,
00034         ODS1,
00035         IN_LATCH,
00036         PULL_EN,
00037         PULL_SEL,
00038         INT_MASK,
00039         INT_STAT,
00040         OPC
00041     };
00042 
00043     PCAL955x( PinName i2c_sda, PinName i2c_scl, char i2c_address = DEFAULT_I2C_ADDR );
00044     PCAL955x( I2C &i2c_obj, char i2c_address = DEFAULT_I2C_ADDR );
00045     virtual ~PCAL955x();
00046 
00047     virtual void    write( int pin, int value );
00048     virtual int     read( int pin );
00049     virtual void    configure( int pin, int value );
00050     virtual int     read( void );   
00051     virtual void    write_with_mask( int bitpattern, int mask_bits );
00052     virtual void    configure_with_mask( int bitpattern, int mask_bits );
00053     
00054     void            write( int bit_pattern );
00055     void            polarity( int bit_pattern );
00056     void            configure( int bit_pattern );
00057 
00058     void            interrupt_mask( int bit_pattern );
00059     int             interrupt_status( void );
00060 
00061     virtual int     number_of_pins( void )                     = 0;
00062     virtual void    reg_index_write( char reg_addr, int data )  = 0;
00063     virtual int     reg_index_read( char reg_addr )             = 0;
00064                     operator int( void );
00065 
00066 protected:
00067     enum {
00068         DEFAULT_I2C_ADDR    = 0x40,
00069     };
00070 
00071     void bus_write( char *dp, int length );
00072     void bus_read( char reg_addr, char *dp, int length );
00073 
00074 private:
00075     I2C             *i2c_p;
00076     I2C             &i2c;
00077     char            address;    //  I2C slave address
00078     int             pin_state;
00079     int             pin_direction;
00080 }
00081 ;
00082 
00083 #endif  //  MBED_PCAL955x