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@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 | /** GpioBusInOut API for GPIO-expander component class |
andriym | 0:035111d3d631 | 2 | * |
andriym | 0:035111d3d631 | 3 | * @author Akifumi (Tedd) OKANO, NXP Semiconductors |
andriym | 0:035111d3d631 | 4 | * @version 0.6 |
andriym | 0:035111d3d631 | 5 | * @date 19-Mar-2015 |
andriym | 0:035111d3d631 | 6 | * |
andriym | 0:035111d3d631 | 7 | * Released under the Apache 2 license |
andriym | 0:035111d3d631 | 8 | */ |
andriym | 0:035111d3d631 | 9 | |
andriym | 0:035111d3d631 | 10 | #ifndef MBED_GpioBusInOut |
andriym | 0:035111d3d631 | 11 | #define MBED_GpioBusInOut |
andriym | 0:035111d3d631 | 12 | |
andriym | 0:035111d3d631 | 13 | #include "mbed.h" |
andriym | 0:035111d3d631 | 14 | #include "GpioDigitalInOut.h" |
andriym | 0:035111d3d631 | 15 | |
andriym | 0:035111d3d631 | 16 | /** GpioBusInOut class |
andriym | 0:035111d3d631 | 17 | * |
andriym | 0:035111d3d631 | 18 | * @class GpioBusInOut |
andriym | 0:035111d3d631 | 19 | * |
andriym | 0:035111d3d631 | 20 | * "GpioBusInOut" class works like "BusInOut" class of mbed-SDK. |
andriym | 0:035111d3d631 | 21 | * This class provides pin oriented API, abstracting the GPIO-expander chip. |
andriym | 0:035111d3d631 | 22 | * |
andriym | 0:035111d3d631 | 23 | * Example: |
andriym | 0:035111d3d631 | 24 | * @code |
andriym | 0:035111d3d631 | 25 | * #include "mbed.h" |
andriym | 0:035111d3d631 | 26 | * #include "PCAL9555.h" |
andriym | 0:035111d3d631 | 27 | * |
andriym | 0:035111d3d631 | 28 | * PCAL9555 gpio_exp( p28, p27, 0xE8 ); // SDA, SCL, Slave_address(option) |
andriym | 0:035111d3d631 | 29 | * GpioBusInOut pins( gpio_exp, X0_0, X0_1, X0_2 ); |
andriym | 0:035111d3d631 | 30 | * |
andriym | 0:035111d3d631 | 31 | * int main() { |
andriym | 0:035111d3d631 | 32 | * while(1) { |
andriym | 0:035111d3d631 | 33 | * pins.output(); |
andriym | 0:035111d3d631 | 34 | * pins = 0x3; |
andriym | 0:035111d3d631 | 35 | * wait( 1 ); |
andriym | 0:035111d3d631 | 36 | * pins.input(); |
andriym | 0:035111d3d631 | 37 | * wait( 1 ); |
andriym | 0:035111d3d631 | 38 | * if( pins == 0x6 ) { |
andriym | 0:035111d3d631 | 39 | * printf( "Hello!\n" ); |
andriym | 0:035111d3d631 | 40 | * } |
andriym | 0:035111d3d631 | 41 | * } |
andriym | 0:035111d3d631 | 42 | * } * @endcode |
andriym | 0:035111d3d631 | 43 | */ |
andriym | 0:035111d3d631 | 44 | class GpioBusInOut |
andriym | 0:035111d3d631 | 45 | { |
andriym | 0:035111d3d631 | 46 | public: |
andriym | 0:035111d3d631 | 47 | |
andriym | 0:035111d3d631 | 48 | #if DOXYGEN_ONLY |
andriym | 0:035111d3d631 | 49 | /** GPIO-Expander pin names */ |
andriym | 0:035111d3d631 | 50 | typedef enum { |
andriym | 0:035111d3d631 | 51 | X0_0, /**< P0_0 pin */ |
andriym | 0:035111d3d631 | 52 | X0_1, /**< P0_1 pin */ |
andriym | 0:035111d3d631 | 53 | X0_2, /**< P0_2 pin */ |
andriym | 0:035111d3d631 | 54 | X0_3, /**< P0_3 pin */ |
andriym | 0:035111d3d631 | 55 | X0_4, /**< P0_4 pin */ |
andriym | 0:035111d3d631 | 56 | X0_5, /**< P0_5 pin */ |
andriym | 0:035111d3d631 | 57 | X0_6, /**< P0_6 pin */ |
andriym | 0:035111d3d631 | 58 | X0_7, /**< P0_7 pin */ |
andriym | 0:035111d3d631 | 59 | X1_0, /**< P1_0 pin (for 16-bit GPIO device only) */ |
andriym | 0:035111d3d631 | 60 | X1_1, /**< P1_1 pin (for 16-bit GPIO device only) */ |
andriym | 0:035111d3d631 | 61 | X1_2, /**< P1_2 pin (for 16-bit GPIO device only) */ |
andriym | 0:035111d3d631 | 62 | X1_3, /**< P1_3 pin (for 16-bit GPIO device only) */ |
andriym | 0:035111d3d631 | 63 | X1_4, /**< P1_4 pin (for 16-bit GPIO device only) */ |
andriym | 0:035111d3d631 | 64 | X1_5, /**< P1_5 pin (for 16-bit GPIO device only) */ |
andriym | 0:035111d3d631 | 65 | X1_6, /**< P1_6 pin (for 16-bit GPIO device only) */ |
andriym | 0:035111d3d631 | 66 | X1_7, /**< P1_7 pin (for 16-bit GPIO device only) */ |
andriym | 0:035111d3d631 | 67 | X0 = X0_0, /**< P0_0 pin */ |
andriym | 0:035111d3d631 | 68 | X1 = X0_1, /**< P0_1 pin */ |
andriym | 0:035111d3d631 | 69 | X2 = X0_2, /**< P0_2 pin */ |
andriym | 0:035111d3d631 | 70 | X3 = X0_3, /**< P0_3 pin */ |
andriym | 0:035111d3d631 | 71 | X4 = X0_4, /**< P0_4 pin */ |
andriym | 0:035111d3d631 | 72 | X5 = X0_5, /**< P0_5 pin */ |
andriym | 0:035111d3d631 | 73 | X6 = X0_6, /**< P0_6 pin */ |
andriym | 0:035111d3d631 | 74 | X7 = X0_7, /**< P0_7 pin */ |
andriym | 0:035111d3d631 | 75 | X8 = X1_0, /**< P1_0 pin (for 16-bit GPIO device only) */ |
andriym | 0:035111d3d631 | 76 | X9 = X1_1, /**< P1_1 pin (for 16-bit GPIO device only) */ |
andriym | 0:035111d3d631 | 77 | X10 = X1_2, /**< P1_2 pin (for 16-bit GPIO device only) */ |
andriym | 0:035111d3d631 | 78 | X11 = X1_3, /**< P1_3 pin (for 16-bit GPIO device only) */ |
andriym | 0:035111d3d631 | 79 | X12 = X1_4, /**< P1_4 pin (for 16-bit GPIO device only) */ |
andriym | 0:035111d3d631 | 80 | X13 = X1_5, /**< P1_5 pin (for 16-bit GPIO device only) */ |
andriym | 0:035111d3d631 | 81 | X14 = X1_6, /**< P1_6 pin (for 16-bit GPIO device only) */ |
andriym | 0:035111d3d631 | 82 | X15 = X1_7, /**< P1_7 pin (for 16-bit GPIO device only) */ |
andriym | 0:035111d3d631 | 83 | |
andriym | 0:035111d3d631 | 84 | X_NC = ~0x0L /**< for when the pin is left no-connection */ |
andriym | 0:035111d3d631 | 85 | } GpioPinName; |
andriym | 0:035111d3d631 | 86 | #endif |
andriym | 0:035111d3d631 | 87 | |
andriym | 0:035111d3d631 | 88 | /** Create an GpioBusInOut, connected to the specified pins |
andriym | 0:035111d3d631 | 89 | * |
andriym | 0:035111d3d631 | 90 | * @param gpiop Instance of GPIO expander device |
andriym | 0:035111d3d631 | 91 | * @param p<n> DigitalInOut pin to connect to bus bit p<n> (GpioPinName) |
andriym | 0:035111d3d631 | 92 | * |
andriym | 0:035111d3d631 | 93 | * @note |
andriym | 0:035111d3d631 | 94 | * It is only required to specify as many pin variables as is required |
andriym | 0:035111d3d631 | 95 | * for the bus; the rest will default to NC (not connected) |
andriym | 0:035111d3d631 | 96 | */ |
andriym | 0:035111d3d631 | 97 | GpioBusInOut( CompGpioExp &gpiop, |
andriym | 0:035111d3d631 | 98 | GpioPinName p0, GpioPinName p1 = X_NC, GpioPinName p2 = X_NC, GpioPinName p3 = X_NC, |
andriym | 0:035111d3d631 | 99 | GpioPinName p4 = X_NC, GpioPinName p5 = X_NC, GpioPinName p6 = X_NC, GpioPinName p7 = X_NC, |
andriym | 0:035111d3d631 | 100 | GpioPinName p8 = X_NC, GpioPinName p9 = X_NC, GpioPinName p10 = X_NC, GpioPinName p11 = X_NC, |
andriym | 0:035111d3d631 | 101 | GpioPinName p12 = X_NC, GpioPinName p13 = X_NC, GpioPinName p14 = X_NC, GpioPinName p15 = X_NC ); |
andriym | 0:035111d3d631 | 102 | GpioBusInOut( CompGpioExp &gpiop, GpioPinName pins[ 16 ] ); |
andriym | 0:035111d3d631 | 103 | |
andriym | 0:035111d3d631 | 104 | /** |
andriym | 0:035111d3d631 | 105 | * Destractor |
andriym | 0:035111d3d631 | 106 | */ |
andriym | 0:035111d3d631 | 107 | virtual ~GpioBusInOut(); |
andriym | 0:035111d3d631 | 108 | |
andriym | 0:035111d3d631 | 109 | /* Group: Access Methods */ |
andriym | 0:035111d3d631 | 110 | |
andriym | 0:035111d3d631 | 111 | /** Write the value to the output bus |
andriym | 0:035111d3d631 | 112 | * |
andriym | 0:035111d3d631 | 113 | * @param value An integer specifying a bit to write for every corresponding DigitalInOut pin |
andriym | 0:035111d3d631 | 114 | */ |
andriym | 0:035111d3d631 | 115 | void write( int value ); |
andriym | 0:035111d3d631 | 116 | |
andriym | 0:035111d3d631 | 117 | /** Read the value currently output on the bus |
andriym | 0:035111d3d631 | 118 | * |
andriym | 0:035111d3d631 | 119 | * @returns |
andriym | 0:035111d3d631 | 120 | * An integer with each bit corresponding to associated DigitalInOut pin setting |
andriym | 0:035111d3d631 | 121 | */ |
andriym | 0:035111d3d631 | 122 | int read(); |
andriym | 0:035111d3d631 | 123 | |
andriym | 0:035111d3d631 | 124 | /** Set as an output |
andriym | 0:035111d3d631 | 125 | */ |
andriym | 0:035111d3d631 | 126 | void output(); |
andriym | 0:035111d3d631 | 127 | |
andriym | 0:035111d3d631 | 128 | /** Set as an input |
andriym | 0:035111d3d631 | 129 | */ |
andriym | 0:035111d3d631 | 130 | void input(); |
andriym | 0:035111d3d631 | 131 | |
andriym | 0:035111d3d631 | 132 | /** A shorthand for write() |
andriym | 0:035111d3d631 | 133 | */ |
andriym | 0:035111d3d631 | 134 | GpioBusInOut& operator= ( int rhs ); |
andriym | 0:035111d3d631 | 135 | GpioBusInOut& operator= ( GpioBusInOut& rhs ); |
andriym | 0:035111d3d631 | 136 | |
andriym | 0:035111d3d631 | 137 | /** A shorthand for read() |
andriym | 0:035111d3d631 | 138 | */ |
andriym | 0:035111d3d631 | 139 | operator int( void ); |
andriym | 0:035111d3d631 | 140 | |
andriym | 0:035111d3d631 | 141 | protected: |
andriym | 0:035111d3d631 | 142 | CompGpioExp *gpio_p; |
andriym | 0:035111d3d631 | 143 | int pin_list[ 16 ]; |
andriym | 0:035111d3d631 | 144 | int mask_bits; |
andriym | 0:035111d3d631 | 145 | |
andriym | 0:035111d3d631 | 146 | void init( CompGpioExp &gpiop, GpioPinName pins[16] ); |
andriym | 0:035111d3d631 | 147 | int make_bitpattern( int value ); |
andriym | 0:035111d3d631 | 148 | } |
andriym | 0:035111d3d631 | 149 | ; |
andriym | 0:035111d3d631 | 150 | |
andriym | 0:035111d3d631 | 151 | #endif // MBED_GpioBusInOut |