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/CompGpioExp/GpioBus/GpioBusInOut.h
- Committer:
- andriym
- Date:
- 2017-02-15
- Revision:
- 0:035111d3d631
File content as of revision 0:035111d3d631:
/** GpioBusInOut API for GPIO-expander component class * * @author Akifumi (Tedd) OKANO, NXP Semiconductors * @version 0.6 * @date 19-Mar-2015 * * Released under the Apache 2 license */ #ifndef MBED_GpioBusInOut #define MBED_GpioBusInOut #include "mbed.h" #include "GpioDigitalInOut.h" /** GpioBusInOut class * * @class GpioBusInOut * * "GpioBusInOut" class works like "BusInOut" class of mbed-SDK. * This class provides pin oriented API, abstracting the GPIO-expander chip. * * Example: * @code * #include "mbed.h" * #include "PCAL9555.h" * * PCAL9555 gpio_exp( p28, p27, 0xE8 ); // SDA, SCL, Slave_address(option) * GpioBusInOut pins( gpio_exp, X0_0, X0_1, X0_2 ); * * int main() { * while(1) { * pins.output(); * pins = 0x3; * wait( 1 ); * pins.input(); * wait( 1 ); * if( pins == 0x6 ) { * printf( "Hello!\n" ); * } * } * } * @endcode */ class GpioBusInOut { public: #if DOXYGEN_ONLY /** GPIO-Expander pin names */ typedef enum { X0_0, /**< P0_0 pin */ X0_1, /**< P0_1 pin */ X0_2, /**< P0_2 pin */ X0_3, /**< P0_3 pin */ X0_4, /**< P0_4 pin */ X0_5, /**< P0_5 pin */ X0_6, /**< P0_6 pin */ X0_7, /**< P0_7 pin */ X1_0, /**< P1_0 pin (for 16-bit GPIO device only) */ X1_1, /**< P1_1 pin (for 16-bit GPIO device only) */ X1_2, /**< P1_2 pin (for 16-bit GPIO device only) */ X1_3, /**< P1_3 pin (for 16-bit GPIO device only) */ X1_4, /**< P1_4 pin (for 16-bit GPIO device only) */ X1_5, /**< P1_5 pin (for 16-bit GPIO device only) */ X1_6, /**< P1_6 pin (for 16-bit GPIO device only) */ X1_7, /**< P1_7 pin (for 16-bit GPIO device only) */ X0 = X0_0, /**< P0_0 pin */ X1 = X0_1, /**< P0_1 pin */ X2 = X0_2, /**< P0_2 pin */ X3 = X0_3, /**< P0_3 pin */ X4 = X0_4, /**< P0_4 pin */ X5 = X0_5, /**< P0_5 pin */ X6 = X0_6, /**< P0_6 pin */ X7 = X0_7, /**< P0_7 pin */ X8 = X1_0, /**< P1_0 pin (for 16-bit GPIO device only) */ X9 = X1_1, /**< P1_1 pin (for 16-bit GPIO device only) */ X10 = X1_2, /**< P1_2 pin (for 16-bit GPIO device only) */ X11 = X1_3, /**< P1_3 pin (for 16-bit GPIO device only) */ X12 = X1_4, /**< P1_4 pin (for 16-bit GPIO device only) */ X13 = X1_5, /**< P1_5 pin (for 16-bit GPIO device only) */ X14 = X1_6, /**< P1_6 pin (for 16-bit GPIO device only) */ X15 = X1_7, /**< P1_7 pin (for 16-bit GPIO device only) */ X_NC = ~0x0L /**< for when the pin is left no-connection */ } GpioPinName; #endif /** Create an GpioBusInOut, connected to the specified pins * * @param gpiop Instance of GPIO expander device * @param p<n> DigitalInOut pin to connect to bus bit p<n> (GpioPinName) * * @note * It is only required to specify as many pin variables as is required * for the bus; the rest will default to NC (not connected) */ GpioBusInOut( CompGpioExp &gpiop, GpioPinName p0, GpioPinName p1 = X_NC, GpioPinName p2 = X_NC, GpioPinName p3 = X_NC, GpioPinName p4 = X_NC, GpioPinName p5 = X_NC, GpioPinName p6 = X_NC, GpioPinName p7 = X_NC, GpioPinName p8 = X_NC, GpioPinName p9 = X_NC, GpioPinName p10 = X_NC, GpioPinName p11 = X_NC, GpioPinName p12 = X_NC, GpioPinName p13 = X_NC, GpioPinName p14 = X_NC, GpioPinName p15 = X_NC ); GpioBusInOut( CompGpioExp &gpiop, GpioPinName pins[ 16 ] ); /** * Destractor */ virtual ~GpioBusInOut(); /* Group: Access Methods */ /** Write the value to the output bus * * @param value An integer specifying a bit to write for every corresponding DigitalInOut pin */ void write( int value ); /** Read the value currently output on the bus * * @returns * An integer with each bit corresponding to associated DigitalInOut pin setting */ int read(); /** Set as an output */ void output(); /** Set as an input */ void input(); /** A shorthand for write() */ GpioBusInOut& operator= ( int rhs ); GpioBusInOut& operator= ( GpioBusInOut& rhs ); /** A shorthand for read() */ operator int( void ); protected: CompGpioExp *gpio_p; int pin_list[ 16 ]; int mask_bits; void init( CompGpioExp &gpiop, GpioPinName pins[16] ); int make_bitpattern( int value ); } ; #endif // MBED_GpioBusInOut