The PCAL6416A is a low-voltage 16-bit general purpose I/O (GPIO) expander with interrupt. This component library is compatible to basic operation as GPIO expanders: PCAL6416A, 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.
This is a copy of the PCA9555 library by Akifumi "Tedd" OKANO, which is compatible with PCAL6416A chip.
base_classes/PCAL955x.h@0:035111d3d631, 2017-02-15 (annotated)
- Committer:
- andriym
- Date:
- Wed Feb 15 10:07:59 2017 +0000
- Revision:
- 0:035111d3d631
A change of name for the PCAL955x library to make it searchable for people needing PCAL6416A library.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
andriym | 0:035111d3d631 | 1 | /** PCAL955x GPIO with Agile I/O, interrupt and weak pull-up family |
andriym | 0:035111d3d631 | 2 | * |
andriym | 0:035111d3d631 | 3 | * Abstract class for PCAL955x/PCAL6416 family |
andriym | 0:035111d3d631 | 4 | * No instance can be made from this class |
andriym | 0:035111d3d631 | 5 | * |
andriym | 0:035111d3d631 | 6 | * @class PCAL955x |
andriym | 0:035111d3d631 | 7 | * @author Akifumi (Tedd) OKANO, NXP Semiconductors |
andriym | 0:035111d3d631 | 8 | * @version 0.5.1 |
andriym | 0:035111d3d631 | 9 | * @date 07-Mar-2015 |
andriym | 0:035111d3d631 | 10 | * @modified 15-Feb-2017, by Andriy Makukha, Shenzhen MZJ Technology Co. |
andriym | 0:035111d3d631 | 11 | * |
andriym | 0:035111d3d631 | 12 | * Released under the Apache 2 license |
andriym | 0:035111d3d631 | 13 | */ |
andriym | 0:035111d3d631 | 14 | |
andriym | 0:035111d3d631 | 15 | #ifndef MBED_PCAL955x |
andriym | 0:035111d3d631 | 16 | #define MBED_PCAL955x |
andriym | 0:035111d3d631 | 17 | |
andriym | 0:035111d3d631 | 18 | #include "mbed.h" |
andriym | 0:035111d3d631 | 19 | #include "CompGpioExp.h" |
andriym | 0:035111d3d631 | 20 | |
andriym | 0:035111d3d631 | 21 | /** Abstract class for PCAL955x/PCAL6416 family |
andriym | 0:035111d3d631 | 22 | * |
andriym | 0:035111d3d631 | 23 | * No instance can be made from this class |
andriym | 0:035111d3d631 | 24 | */ |
andriym | 0:035111d3d631 | 25 | class PCAL955x : public CompGpioExp |
andriym | 0:035111d3d631 | 26 | { |
andriym | 0:035111d3d631 | 27 | public: |
andriym | 0:035111d3d631 | 28 | enum register_index { |
andriym | 0:035111d3d631 | 29 | INPUT, |
andriym | 0:035111d3d631 | 30 | OUTPUT, |
andriym | 0:035111d3d631 | 31 | POLARITY, |
andriym | 0:035111d3d631 | 32 | CONFIG, |
andriym | 0:035111d3d631 | 33 | ODS0, |
andriym | 0:035111d3d631 | 34 | ODS1, |
andriym | 0:035111d3d631 | 35 | IN_LATCH, |
andriym | 0:035111d3d631 | 36 | PULL_EN, |
andriym | 0:035111d3d631 | 37 | PULL_SEL, |
andriym | 0:035111d3d631 | 38 | INT_MASK, |
andriym | 0:035111d3d631 | 39 | INT_STAT, |
andriym | 0:035111d3d631 | 40 | OPC |
andriym | 0:035111d3d631 | 41 | }; |
andriym | 0:035111d3d631 | 42 | |
andriym | 0:035111d3d631 | 43 | PCAL955x( PinName i2c_sda, PinName i2c_scl, char i2c_address = DEFAULT_I2C_ADDR ); |
andriym | 0:035111d3d631 | 44 | PCAL955x( I2C &i2c_obj, char i2c_address = DEFAULT_I2C_ADDR ); |
andriym | 0:035111d3d631 | 45 | virtual ~PCAL955x(); |
andriym | 0:035111d3d631 | 46 | |
andriym | 0:035111d3d631 | 47 | virtual void write( int pin, int value ); |
andriym | 0:035111d3d631 | 48 | virtual int read( int pin ); |
andriym | 0:035111d3d631 | 49 | virtual void configure( int pin, int value ); |
andriym | 0:035111d3d631 | 50 | virtual int read( void ); |
andriym | 0:035111d3d631 | 51 | virtual void write_with_mask( int bitpattern, int mask_bits ); |
andriym | 0:035111d3d631 | 52 | virtual void configure_with_mask( int bitpattern, int mask_bits ); |
andriym | 0:035111d3d631 | 53 | |
andriym | 0:035111d3d631 | 54 | void write( int bit_pattern ); |
andriym | 0:035111d3d631 | 55 | void polarity( int bit_pattern ); |
andriym | 0:035111d3d631 | 56 | void configure( int bit_pattern ); |
andriym | 0:035111d3d631 | 57 | |
andriym | 0:035111d3d631 | 58 | void interrupt_mask( int bit_pattern ); |
andriym | 0:035111d3d631 | 59 | int interrupt_status( void ); |
andriym | 0:035111d3d631 | 60 | |
andriym | 0:035111d3d631 | 61 | virtual int number_of_pins( void ) = 0; |
andriym | 0:035111d3d631 | 62 | virtual void reg_index_write( char reg_addr, int data ) = 0; |
andriym | 0:035111d3d631 | 63 | virtual int reg_index_read( char reg_addr ) = 0; |
andriym | 0:035111d3d631 | 64 | operator int( void ); |
andriym | 0:035111d3d631 | 65 | |
andriym | 0:035111d3d631 | 66 | protected: |
andriym | 0:035111d3d631 | 67 | enum { |
andriym | 0:035111d3d631 | 68 | DEFAULT_I2C_ADDR = 0x40, |
andriym | 0:035111d3d631 | 69 | }; |
andriym | 0:035111d3d631 | 70 | |
andriym | 0:035111d3d631 | 71 | void bus_write( char *dp, int length ); |
andriym | 0:035111d3d631 | 72 | void bus_read( char reg_addr, char *dp, int length ); |
andriym | 0:035111d3d631 | 73 | |
andriym | 0:035111d3d631 | 74 | private: |
andriym | 0:035111d3d631 | 75 | I2C *i2c_p; |
andriym | 0:035111d3d631 | 76 | I2C &i2c; |
andriym | 0:035111d3d631 | 77 | char address; // I2C slave address |
andriym | 0:035111d3d631 | 78 | int pin_state; |
andriym | 0:035111d3d631 | 79 | int pin_direction; |
andriym | 0:035111d3d631 | 80 | } |
andriym | 0:035111d3d631 | 81 | ; |
andriym | 0:035111d3d631 | 82 | |
andriym | 0:035111d3d631 | 83 | #endif // MBED_PCAL955x |