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

What is this?

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.

How to use?

Wiring

/media/uploads/nxp_ip/gpio16.png
Wiring between mbed and 16-bit GPIO expander

/media/uploads/nxp_ip/gpio08.png
Wiring between mbed and 8-bit GPIO expander

Very basic register level I/O bit operation

PCAL9555 and PCAL9554 are class libraries for those compatible GPIO expander chips.
Those class libraries provides interface for bit operation of its I/O port.
For 16-bit GPIO expanders, the input/output access and its direction setting can be done by 16-bit data. For 8-bit GPIO expanders, those can be done by 8-bit data.

  #include    "mbed.h"
  #include    "PCAL9555.h"
 
  PCAL9555    gpio( p28, p27, 0xE8 );     //  using PCA9539
 
  int main() {
      gpio.configure( 0xFFFF );           //  Set all pins: input
      printf( "  0x%04X\r\n", (int)gpio );//  Print pins state
 
      gpio.configure( 0x0000 );           //  Set all pins: output
      int count   = 0;
      while(1) {
          gpio.write( count++ );
      }
  }


High level APIs

To use the GPIO expanders more simple, this library is including mbed-SDK-style APIs.
APIs that similar to DigitaiInOut, DigitalOut, DigitalIn, BusInOut, BusOut and BusIn are available.

GpioDigitalOut, GpioDigitaiInOut, GpioDigitalIn

Next code shows sample of DigitalOut equivalent API GpioDigitalOut usage.
A pin on the PCAL9555 is defined as pin and its state is changed by assignment.
(For single pin operation, GpioDigitaiInOut and GpioDigitalIn are available also.)

  #include "mbed.h"
  #include "PCAL9555.h"
  
  PCAL9555        gpio_exp( p28, p27, 0xE8 );    //  SDA, SCL, Slave_address(option)
  GpioDigitalOut  pin( gpio_exp, X0_0 );
   
  int main() {
      while( 1 ) {
          pin = 1;
          wait( 0.2 );
          pin = 0;
          wait( 0.2 );
      }
  }


GpioBusOut, GpioBusInOut, GpioBusIn

BusOut equivalent API GpioBusOut is available too.
In next code, pins are grouped as mypins to manage the output as bus output.
(Same as GpioDigitalInOut and GpioDigitalIn APIs, GpioBusInOut and GpioBusIn are available also.)

  #include "mbed.h"
  #include "PCAL9555.h"
  
  PCAL9555    gpio_exp( p28, p27, 0xE8 );    //  SDA, SCL, Slave_address(option)
  GpioBusOut  mypins( gpio_exp, X0_0, X0_1, X0_2, X0_3 );
   
  int main() {
      while( 1 ) {
          for( int i = 0; i < 16; i++ ) {
              mypins  = i;
              wait( 0.25 );
          }
      }
  }


The high level APIs can be used in combination

Those high level APIs can be used in combination.
Each pins can be managed by instances.

  #include    "mbed.h"
  #include    "PCAL9555.h"
 
  PCAL9555        gpio( p28, p27, 0xE8 );     //  using PCA9539
 
  //  The GPIO pins are grouped in some groups and operated as bus I/O
  GpioBusIn       bus_in( gpio, X0_0, X0_1, X0_2, X0_3 );
  GpioBusOut      bus_out( gpio, X0_4, X0_5, X0_6 );
  GpioBusInOut    bus_io( gpio, X1_7, X1_6, X1_5, X1_4, X1_3, X1_2, X1_1, X1_0 );
  GpioDigitalOut  myled( gpio, X0_7 );
 
  int main() {
      bus_io.input();
      printf( "I/O = 0x%02X\r\n", (int)bus_io );
      printf( "In  = 0x%01X\r\n", (int)bus_in );
 
      bus_io.output();
 
      int count   = 0;
      while(1) {
          bus_out = count;
          bus_io  = count;
          myled   = count & 0x1;
          count++;
          wait( 0.1 );
      }
  }
Committer:
nxp_ip
Date:
Thu Mar 19 02:21:57 2015 +0000
Revision:
1:fd7cfa821b6a
Parent:
0:6c9a51a50eea
API document update

Who changed what in which revision?

UserRevisionLine numberNew contents of line
nxp_ip 0:6c9a51a50eea 1 /** GPIO expander abstraction class
nxp_ip 0:6c9a51a50eea 2 *
nxp_ip 0:6c9a51a50eea 3 * No instance can be made from this class
nxp_ip 0:6c9a51a50eea 4 *
nxp_ip 0:6c9a51a50eea 5 * @class CompGpioExp
nxp_ip 0:6c9a51a50eea 6 * @author Akifumi (Tedd) OKANO, NXP Semiconductors
nxp_ip 1:fd7cfa821b6a 7 * @version 0.6
nxp_ip 1:fd7cfa821b6a 8 * @date 19-Mar-2015
nxp_ip 0:6c9a51a50eea 9 *
nxp_ip 0:6c9a51a50eea 10 * Released under the Apache 2 license
nxp_ip 0:6c9a51a50eea 11 */
nxp_ip 0:6c9a51a50eea 12
nxp_ip 0:6c9a51a50eea 13 #ifndef MBED_CompGpioExp
nxp_ip 0:6c9a51a50eea 14 #define MBED_CompGpioExp
nxp_ip 0:6c9a51a50eea 15
nxp_ip 0:6c9a51a50eea 16 #include "mbed.h"
nxp_ip 0:6c9a51a50eea 17
nxp_ip 0:6c9a51a50eea 18 typedef enum {
nxp_ip 0:6c9a51a50eea 19 // GPIO Expander pin names
nxp_ip 0:6c9a51a50eea 20 X0_0, /**< P0_0 pin */
nxp_ip 0:6c9a51a50eea 21 X0_1, /**< P0_1 pin */
nxp_ip 0:6c9a51a50eea 22 X0_2, /**< P0_2 pin */
nxp_ip 0:6c9a51a50eea 23 X0_3, /**< P0_3 pin */
nxp_ip 0:6c9a51a50eea 24 X0_4, /**< P0_4 pin */
nxp_ip 0:6c9a51a50eea 25 X0_5, /**< P0_5 pin */
nxp_ip 0:6c9a51a50eea 26 X0_6, /**< P0_6 pin */
nxp_ip 0:6c9a51a50eea 27 X0_7, /**< P0_7 pin */
nxp_ip 1:fd7cfa821b6a 28 X1_0, /**< P1_0 pin (for 16-bit GPIO device only) */
nxp_ip 1:fd7cfa821b6a 29 X1_1, /**< P1_1 pin (for 16-bit GPIO device only) */
nxp_ip 1:fd7cfa821b6a 30 X1_2, /**< P1_2 pin (for 16-bit GPIO device only) */
nxp_ip 1:fd7cfa821b6a 31 X1_3, /**< P1_3 pin (for 16-bit GPIO device only) */
nxp_ip 1:fd7cfa821b6a 32 X1_4, /**< P1_4 pin (for 16-bit GPIO device only) */
nxp_ip 1:fd7cfa821b6a 33 X1_5, /**< P1_5 pin (for 16-bit GPIO device only) */
nxp_ip 1:fd7cfa821b6a 34 X1_6, /**< P1_6 pin (for 16-bit GPIO device only) */
nxp_ip 1:fd7cfa821b6a 35 X1_7, /**< P1_7 pin (for 16-bit GPIO device only) */
nxp_ip 0:6c9a51a50eea 36 X0 = X0_0, /**< P0_0 pin */
nxp_ip 0:6c9a51a50eea 37 X1 = X0_1, /**< P0_1 pin */
nxp_ip 0:6c9a51a50eea 38 X2 = X0_2, /**< P0_2 pin */
nxp_ip 0:6c9a51a50eea 39 X3 = X0_3, /**< P0_3 pin */
nxp_ip 0:6c9a51a50eea 40 X4 = X0_4, /**< P0_4 pin */
nxp_ip 0:6c9a51a50eea 41 X5 = X0_5, /**< P0_5 pin */
nxp_ip 0:6c9a51a50eea 42 X6 = X0_6, /**< P0_6 pin */
nxp_ip 0:6c9a51a50eea 43 X7 = X0_7, /**< P0_7 pin */
nxp_ip 1:fd7cfa821b6a 44 X8 = X1_0, /**< P1_0 pin (for 16-bit GPIO device only) */
nxp_ip 1:fd7cfa821b6a 45 X9 = X1_1, /**< P1_1 pin (for 16-bit GPIO device only) */
nxp_ip 1:fd7cfa821b6a 46 X10 = X1_2, /**< P1_2 pin (for 16-bit GPIO device only) */
nxp_ip 1:fd7cfa821b6a 47 X11 = X1_3, /**< P1_3 pin (for 16-bit GPIO device only) */
nxp_ip 1:fd7cfa821b6a 48 X12 = X1_4, /**< P1_4 pin (for 16-bit GPIO device only) */
nxp_ip 1:fd7cfa821b6a 49 X13 = X1_5, /**< P1_5 pin (for 16-bit GPIO device only) */
nxp_ip 1:fd7cfa821b6a 50 X14 = X1_6, /**< P1_6 pin (for 16-bit GPIO device only) */
nxp_ip 1:fd7cfa821b6a 51 X15 = X1_7, /**< P1_7 pin (for 16-bit GPIO device only) */
nxp_ip 0:6c9a51a50eea 52 X_NC = ~0x0L /**< for when the pin is left no-connection */
nxp_ip 0:6c9a51a50eea 53 } GpioPinName;
nxp_ip 0:6c9a51a50eea 54
nxp_ip 0:6c9a51a50eea 55 /** Abstract class for GPIO expander devices
nxp_ip 0:6c9a51a50eea 56 *
nxp_ip 0:6c9a51a50eea 57 * No instance can be made from this class
nxp_ip 0:6c9a51a50eea 58 */
nxp_ip 0:6c9a51a50eea 59 class CompGpioExp
nxp_ip 0:6c9a51a50eea 60 {
nxp_ip 0:6c9a51a50eea 61 public:
nxp_ip 0:6c9a51a50eea 62 CompGpioExp();
nxp_ip 0:6c9a51a50eea 63 virtual ~CompGpioExp();
nxp_ip 0:6c9a51a50eea 64
nxp_ip 0:6c9a51a50eea 65 virtual void write( int pin, int value ) = 0;
nxp_ip 0:6c9a51a50eea 66 virtual int read( int pin ) = 0;
nxp_ip 0:6c9a51a50eea 67 virtual void configure( int pin, int value ) = 0;
nxp_ip 0:6c9a51a50eea 68 virtual int read( void ) = 0;
nxp_ip 0:6c9a51a50eea 69 virtual void write_with_mask( int bitpattern, int mask_bits ) = 0;
nxp_ip 0:6c9a51a50eea 70 virtual void configure_with_mask( int bitpattern, int mask_bits ) = 0;
nxp_ip 0:6c9a51a50eea 71 }
nxp_ip 0:6c9a51a50eea 72 ;
nxp_ip 0:6c9a51a50eea 73
nxp_ip 0:6c9a51a50eea 74 #endif // MBED_CompGpioExp
nxp_ip 0:6c9a51a50eea 75
nxp_ip 0:6c9a51a50eea 76