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 /** PCA(L)9555 16-bit I2C-bus GPIO expander
nxp_ip 0:6c9a51a50eea 2 *
nxp_ip 0:6c9a51a50eea 3 * An operation sample of PCA(L)9555, PCA9535 and PCA9539.
nxp_ip 0:6c9a51a50eea 4 * mbed accesses the PCAL9555 registers through I2C.
nxp_ip 0:6c9a51a50eea 5 *
nxp_ip 0:6c9a51a50eea 6 * @class PCAL9555
nxp_ip 0:6c9a51a50eea 7 * @author Akifumi (Tedd) OKANO, NXP Semiconductors
nxp_ip 1:fd7cfa821b6a 8 * @version 0.6
nxp_ip 1:fd7cfa821b6a 9 * @date 19-Mar-2015
nxp_ip 0:6c9a51a50eea 10 *
nxp_ip 0:6c9a51a50eea 11 * Released under the Apache 2 license
nxp_ip 0:6c9a51a50eea 12 *
nxp_ip 0:6c9a51a50eea 13 * About PCAL9555:
nxp_ip 0:6c9a51a50eea 14 * http://www.nxp.com/products/interface_and_connectivity/i2c/i2c_general_purpose_i_o/series/PCAL9555A.html
nxp_ip 0:6c9a51a50eea 15 */
nxp_ip 0:6c9a51a50eea 16
nxp_ip 0:6c9a51a50eea 17 #ifndef MBED_PCAL9555
nxp_ip 0:6c9a51a50eea 18 #define MBED_PCAL9555
nxp_ip 0:6c9a51a50eea 19
nxp_ip 0:6c9a51a50eea 20 #include "mbed.h"
nxp_ip 0:6c9a51a50eea 21 #include "PCAL955x.h"
nxp_ip 0:6c9a51a50eea 22 #include "CompGpioExpAPI.h"
nxp_ip 0:6c9a51a50eea 23
nxp_ip 0:6c9a51a50eea 24 /** PCAL9555 class
nxp_ip 0:6c9a51a50eea 25 *
nxp_ip 0:6c9a51a50eea 26 * This is a driver code for the Low-voltage 16-bit I2C-bus GPIO with Agile I/O.
nxp_ip 0:6c9a51a50eea 27 * This class provides interface for PCAL9555 operation.
nxp_ip 0:6c9a51a50eea 28 * Detail information is available on next URL.
nxp_ip 0:6c9a51a50eea 29 * http://www.nxp.com/products/interface_and_connectivity/i2c/i2c_general_purpose_i_o/series/PCAL9555A.html
nxp_ip 0:6c9a51a50eea 30 *
nxp_ip 0:6c9a51a50eea 31 * PCAL9555 library's basic IO operation is compatible to PCA9555, PCA9535 and PCA9539.
nxp_ip 0:6c9a51a50eea 32 * This library can be used for those GPIO expander chips also.
nxp_ip 1:fd7cfa821b6a 33 * Next sample code shows operation based on low-level-API (operated by just device instane)
nxp_ip 0:6c9a51a50eea 34 *
nxp_ip 0:6c9a51a50eea 35 * Example:
nxp_ip 0:6c9a51a50eea 36 * @code
nxp_ip 1:fd7cfa821b6a 37 * // GPIO-expander operation sample using a device instance
nxp_ip 1:fd7cfa821b6a 38 *
nxp_ip 0:6c9a51a50eea 39 * #include "mbed.h"
nxp_ip 0:6c9a51a50eea 40 * #include "PCAL9555.h"
nxp_ip 0:6c9a51a50eea 41 *
nxp_ip 0:6c9a51a50eea 42 * PCAL9555 gpio( p28, p27, 0xE8 ); // using PCA9539
nxp_ip 0:6c9a51a50eea 43 *
nxp_ip 0:6c9a51a50eea 44 * int main() {
nxp_ip 0:6c9a51a50eea 45 * gpio.configure( 0xFFFF ); // Set all pins: input
nxp_ip 0:6c9a51a50eea 46 * printf( " 0x%04X\r\n", (int)gpio );// Print pins state
nxp_ip 0:6c9a51a50eea 47 *
nxp_ip 0:6c9a51a50eea 48 * gpio.configure( 0x0000 ); // Set all pins: output
nxp_ip 0:6c9a51a50eea 49 * int count = 0;
nxp_ip 0:6c9a51a50eea 50 * while(1) {
nxp_ip 0:6c9a51a50eea 51 * gpio.write( count++ );
nxp_ip 0:6c9a51a50eea 52 * }
nxp_ip 0:6c9a51a50eea 53 * }
nxp_ip 0:6c9a51a50eea 54 * @endcode
nxp_ip 0:6c9a51a50eea 55 *
nxp_ip 0:6c9a51a50eea 56 * GpioDigitalInOut, GpioDigitalOut, GpioDigitalIn,
nxp_ip 0:6c9a51a50eea 57 * GpioBusInOut, GpioBusOut and GpioBusIn API class are available also.
nxp_ip 1:fd7cfa821b6a 58 * For those high-level-API details, please find those class library page.
nxp_ip 1:fd7cfa821b6a 59 * The GpioDigital* and GpioBus* APIs can be used like next sample code.
nxp_ip 0:6c9a51a50eea 60 *
nxp_ip 0:6c9a51a50eea 61 * @code
nxp_ip 1:fd7cfa821b6a 62 * // GPIO-expander operation sample using high-level-API
nxp_ip 1:fd7cfa821b6a 63 *
nxp_ip 0:6c9a51a50eea 64 * #include "mbed.h"
nxp_ip 0:6c9a51a50eea 65 * #include "PCAL9555.h"
nxp_ip 0:6c9a51a50eea 66 *
nxp_ip 0:6c9a51a50eea 67 * PCAL9555 gpio( p28, p27, 0xE8 ); // using PCA9539
nxp_ip 0:6c9a51a50eea 68 *
nxp_ip 0:6c9a51a50eea 69 * // The GPIO pins are grouped in some groups and operated as bus I/O
nxp_ip 0:6c9a51a50eea 70 * GpioBusIn bus_in( gpio, X0_0, X0_1, X0_2, X0_3 );
nxp_ip 0:6c9a51a50eea 71 * GpioBusOut bus_out( gpio, X0_4, X0_5, X0_6 );
nxp_ip 0:6c9a51a50eea 72 * GpioBusInOut bus_io( gpio, X1_7, X1_6, X1_5, X1_4, X1_3, X1_2, X1_1, X1_0 );
nxp_ip 0:6c9a51a50eea 73 * GpioDigitalOut myled( gpio, X0_7 );
nxp_ip 0:6c9a51a50eea 74 *
nxp_ip 0:6c9a51a50eea 75 * int main() {
nxp_ip 0:6c9a51a50eea 76 * bus_io.input();
nxp_ip 0:6c9a51a50eea 77 * printf( "I/O = 0x%02X\r\n", (int)bus_io );
nxp_ip 0:6c9a51a50eea 78 * printf( "In = 0x%01X\r\n", (int)bus_in );
nxp_ip 0:6c9a51a50eea 79 *
nxp_ip 0:6c9a51a50eea 80 * bus_io.output();
nxp_ip 0:6c9a51a50eea 81 *
nxp_ip 0:6c9a51a50eea 82 * int count = 0;
nxp_ip 0:6c9a51a50eea 83 * while(1) {
nxp_ip 0:6c9a51a50eea 84 * bus_out = count;
nxp_ip 0:6c9a51a50eea 85 * bus_io = count;
nxp_ip 0:6c9a51a50eea 86 * myled = count & 0x1;
nxp_ip 0:6c9a51a50eea 87 * count++;
nxp_ip 0:6c9a51a50eea 88 * wait( 0.1 );
nxp_ip 0:6c9a51a50eea 89 * }
nxp_ip 0:6c9a51a50eea 90 * }
nxp_ip 0:6c9a51a50eea 91 * @endcode
nxp_ip 0:6c9a51a50eea 92 */
nxp_ip 0:6c9a51a50eea 93
nxp_ip 0:6c9a51a50eea 94 class PCAL9555 : public PCAL955x
nxp_ip 0:6c9a51a50eea 95 {
nxp_ip 0:6c9a51a50eea 96 public:
nxp_ip 0:6c9a51a50eea 97 /** Name of the PCAL9555 registers */
nxp_ip 0:6c9a51a50eea 98 enum command_reg {
nxp_ip 1:fd7cfa821b6a 99 InputPort0 = 0x00, /**< InputPort0 register */
nxp_ip 1:fd7cfa821b6a 100 InputPort1, /**< InputPort1 register */
nxp_ip 1:fd7cfa821b6a 101 OutoutPort0, /**< OutoutPort0 register */
nxp_ip 1:fd7cfa821b6a 102 OutoutPort1, /**< OutoutPort1 register */
nxp_ip 1:fd7cfa821b6a 103 PolarityInversionPort0, /**< PolarityInversionPort0 register */
nxp_ip 1:fd7cfa821b6a 104 PolarityInversionPort1, /**< PolarityInversionPort1 register */
nxp_ip 1:fd7cfa821b6a 105 ConfigurationPort0, /**< ConfigurationPort0 register */
nxp_ip 1:fd7cfa821b6a 106 ConfigurationPort1, /**< ConfigurationPort1 register */
nxp_ip 1:fd7cfa821b6a 107 OutputDriveStrength0_0 = 0x40, /**< OutputDriveStrength0_0 register */
nxp_ip 1:fd7cfa821b6a 108 OutputDriveStrength0_1, /**< OutputDriveStrength0_1 register */
nxp_ip 1:fd7cfa821b6a 109 OutputDriveStrength1_0, /**< OutputDriveStrength1_0 register */
nxp_ip 1:fd7cfa821b6a 110 OutputDriveStrength1_1, /**< OutputDriveStrength1_1 register */
nxp_ip 1:fd7cfa821b6a 111 InputLatch0, /**< InputLatch0 register */
nxp_ip 1:fd7cfa821b6a 112 InputLatch1, /**< InputLatch1 register */
nxp_ip 1:fd7cfa821b6a 113 PullUpPullDowmEnable0, /**< PullUpPullDowmEnable0 register */
nxp_ip 1:fd7cfa821b6a 114 PullUpPullDowmEnable1, /**< PullUpPullDowmEnable1 register */
nxp_ip 1:fd7cfa821b6a 115 PullUpPullDowmSelection0, /**< PullUpPullDowmSelection0 register */
nxp_ip 1:fd7cfa821b6a 116 PullUpPullDowmSelection1, /**< PullUpPullDowmSelection1 register */
nxp_ip 1:fd7cfa821b6a 117 InterruptMask0, /**< InterruptMask0 register */
nxp_ip 1:fd7cfa821b6a 118 InterruptMask1, /**< InterruptMask1 register */
nxp_ip 1:fd7cfa821b6a 119 InterruptStatus0, /**< InterruptStatus0 register */
nxp_ip 1:fd7cfa821b6a 120 InterruptStatus1, /**< InterruptStatus1 register */
nxp_ip 1:fd7cfa821b6a 121 OutputPortConfiguration = 0x4F, /**< OutputPortConfiguration register */
nxp_ip 0:6c9a51a50eea 122 };
nxp_ip 0:6c9a51a50eea 123
nxp_ip 1:fd7cfa821b6a 124 #if DOXYGEN_ONLY
nxp_ip 1:fd7cfa821b6a 125 /** GPIO-Expander pin names
nxp_ip 1:fd7cfa821b6a 126 * for when the high-level APIs
nxp_ip 1:fd7cfa821b6a 127 * (GpioDigitalOut, GpioDigitalInOut, GpioDigitalIn,
nxp_ip 1:fd7cfa821b6a 128 * GpioBusOut, GpioBusInOut are GpioBusIn) are used
nxp_ip 1:fd7cfa821b6a 129 */
nxp_ip 1:fd7cfa821b6a 130 typedef enum {
nxp_ip 1:fd7cfa821b6a 131 X0_0, /**< P0_0 pin */
nxp_ip 1:fd7cfa821b6a 132 X0_1, /**< P0_1 pin */
nxp_ip 1:fd7cfa821b6a 133 X0_2, /**< P0_2 pin */
nxp_ip 1:fd7cfa821b6a 134 X0_3, /**< P0_3 pin */
nxp_ip 1:fd7cfa821b6a 135 X0_4, /**< P0_4 pin */
nxp_ip 1:fd7cfa821b6a 136 X0_5, /**< P0_5 pin */
nxp_ip 1:fd7cfa821b6a 137 X0_6, /**< P0_6 pin */
nxp_ip 1:fd7cfa821b6a 138 X0_7, /**< P0_7 pin */
nxp_ip 1:fd7cfa821b6a 139 X1_0, /**< P1_0 pin */
nxp_ip 1:fd7cfa821b6a 140 X1_1, /**< P1_1 pin */
nxp_ip 1:fd7cfa821b6a 141 X1_2, /**< P1_2 pin */
nxp_ip 1:fd7cfa821b6a 142 X1_3, /**< P1_3 pin */
nxp_ip 1:fd7cfa821b6a 143 X1_4, /**< P1_4 pin */
nxp_ip 1:fd7cfa821b6a 144 X1_5, /**< P1_5 pin */
nxp_ip 1:fd7cfa821b6a 145 X1_6, /**< P1_6 pin */
nxp_ip 1:fd7cfa821b6a 146 X1_7, /**< P1_7 pin */
nxp_ip 1:fd7cfa821b6a 147 X0 = X0_0, /**< P0_0 pin */
nxp_ip 1:fd7cfa821b6a 148 X1 = X0_1, /**< P0_1 pin */
nxp_ip 1:fd7cfa821b6a 149 X2 = X0_2, /**< P0_2 pin */
nxp_ip 1:fd7cfa821b6a 150 X3 = X0_3, /**< P0_3 pin */
nxp_ip 1:fd7cfa821b6a 151 X4 = X0_4, /**< P0_4 pin */
nxp_ip 1:fd7cfa821b6a 152 X5 = X0_5, /**< P0_5 pin */
nxp_ip 1:fd7cfa821b6a 153 X6 = X0_6, /**< P0_6 pin */
nxp_ip 1:fd7cfa821b6a 154 X7 = X0_7, /**< P0_7 pin */
nxp_ip 1:fd7cfa821b6a 155 X8 = X1_0, /**< P1_0 pin */
nxp_ip 1:fd7cfa821b6a 156 X9 = X1_1, /**< P1_1 pin */
nxp_ip 1:fd7cfa821b6a 157 X10 = X1_2, /**< P1_2 pin */
nxp_ip 1:fd7cfa821b6a 158 X11 = X1_3, /**< P1_3 pin */
nxp_ip 1:fd7cfa821b6a 159 X12 = X1_4, /**< P1_4 pin */
nxp_ip 1:fd7cfa821b6a 160 X13 = X1_5, /**< P1_5 pin */
nxp_ip 1:fd7cfa821b6a 161 X14 = X1_6, /**< P1_6 pin */
nxp_ip 1:fd7cfa821b6a 162 X15 = X1_7, /**< P1_7 pin */
nxp_ip 1:fd7cfa821b6a 163
nxp_ip 1:fd7cfa821b6a 164 X_NC = ~0x0L /**< for when the pin is left no-connection */
nxp_ip 1:fd7cfa821b6a 165 } GpioPinName;
nxp_ip 1:fd7cfa821b6a 166 #endif
nxp_ip 1:fd7cfa821b6a 167
nxp_ip 0:6c9a51a50eea 168 /** Create a PCAL9555 instance connected to specified I2C pins with specified address
nxp_ip 0:6c9a51a50eea 169 *
nxp_ip 0:6c9a51a50eea 170 * @param i2c_sda I2C-bus SDA pin
nxp_ip 0:6c9a51a50eea 171 * @param i2c_sda I2C-bus SCL pin
nxp_ip 0:6c9a51a50eea 172 * @param i2c_address I2C-bus address (default: 0x40)
nxp_ip 0:6c9a51a50eea 173 */
nxp_ip 0:6c9a51a50eea 174 PCAL9555( PinName i2c_sda, PinName i2c_scl, char i2c_address = PCAL955x::DEFAULT_I2C_ADDR );
nxp_ip 0:6c9a51a50eea 175
nxp_ip 0:6c9a51a50eea 176 /** Create a PCAL9555 instance connected to specified I2C pins with specified address
nxp_ip 0:6c9a51a50eea 177 *
nxp_ip 0:6c9a51a50eea 178 * @param i2c_obj I2C object (instance)
nxp_ip 0:6c9a51a50eea 179 * @param i2c_address I2C-bus address (default: 0x40)
nxp_ip 0:6c9a51a50eea 180 */
nxp_ip 0:6c9a51a50eea 181 PCAL9555( I2C &i2c_obj, char i2c_address = PCAL955x::DEFAULT_I2C_ADDR );
nxp_ip 0:6c9a51a50eea 182
nxp_ip 0:6c9a51a50eea 183 /** Destractor
nxp_ip 0:6c9a51a50eea 184 */
nxp_ip 0:6c9a51a50eea 185 virtual ~PCAL9555();
nxp_ip 0:6c9a51a50eea 186
nxp_ip 0:6c9a51a50eea 187 /** Returns the number of I/O pins
nxp_ip 0:6c9a51a50eea 188 *
nxp_ip 0:6c9a51a50eea 189 * @returns
nxp_ip 0:6c9a51a50eea 190 * The number of I/O pins
nxp_ip 0:6c9a51a50eea 191 */
nxp_ip 0:6c9a51a50eea 192 virtual int number_of_pins( void );
nxp_ip 0:6c9a51a50eea 193
nxp_ip 0:6c9a51a50eea 194 #if DOXYGEN_ONLY
nxp_ip 0:6c9a51a50eea 195
nxp_ip 0:6c9a51a50eea 196 /** Set output port bits
nxp_ip 0:6c9a51a50eea 197 *
nxp_ip 0:6c9a51a50eea 198 * @param bit_pattern 16-bit output pattern for port1 and port0.
nxp_ip 0:6c9a51a50eea 199 *
nxp_ip 0:6c9a51a50eea 200 * @note
nxp_ip 0:6c9a51a50eea 201 * The data for pins, given as integer.
nxp_ip 0:6c9a51a50eea 202 * The 16-bit MSB goes to P1_7 pin and LSB goes to P0_0 pin.
nxp_ip 0:6c9a51a50eea 203 * Data will not come out from the pin if it is configured as input.
nxp_ip 0:6c9a51a50eea 204 *
nxp_ip 0:6c9a51a50eea 205 * @see configure()
nxp_ip 0:6c9a51a50eea 206 */
nxp_ip 0:6c9a51a50eea 207 void write( int bit_pattern );
nxp_ip 0:6c9a51a50eea 208
nxp_ip 0:6c9a51a50eea 209 /** Read pin states
nxp_ip 0:6c9a51a50eea 210 *
nxp_ip 0:6c9a51a50eea 211 * @return
nxp_ip 0:6c9a51a50eea 212 * 16-bit pattern from port1 and port0.
nxp_ip 0:6c9a51a50eea 213 *
nxp_ip 0:6c9a51a50eea 214 * @note
nxp_ip 0:6c9a51a50eea 215 * The data from pins, given as integer.
nxp_ip 0:6c9a51a50eea 216 * The 16-bit port data comes from IO pins, P1_7 as MSB, P0_0 as LSB.
nxp_ip 0:6c9a51a50eea 217 * Data cannot be read if the port is configured as output.
nxp_ip 0:6c9a51a50eea 218 *
nxp_ip 0:6c9a51a50eea 219 * @see configure()
nxp_ip 0:6c9a51a50eea 220 */
nxp_ip 0:6c9a51a50eea 221 int read( void );
nxp_ip 0:6c9a51a50eea 222
nxp_ip 0:6c9a51a50eea 223 /** Polarity setting
nxp_ip 0:6c9a51a50eea 224 *
nxp_ip 0:6c9a51a50eea 225 * @param bit_pattern 16-bit polarity setting pattern for port1 and port0.
nxp_ip 0:6c9a51a50eea 226 * If the bit is set to '1', the state will be inverted.
nxp_ip 0:6c9a51a50eea 227 * (Default state is all '0')
nxp_ip 0:6c9a51a50eea 228 *
nxp_ip 0:6c9a51a50eea 229 * @see configure()
nxp_ip 0:6c9a51a50eea 230 */
nxp_ip 0:6c9a51a50eea 231 void polarity( int bit_pattern );
nxp_ip 0:6c9a51a50eea 232
nxp_ip 0:6c9a51a50eea 233 /** Set IO congiguration
nxp_ip 0:6c9a51a50eea 234 *
nxp_ip 0:6c9a51a50eea 235 * @param bit_pattern 16-bit IO direction setting pattern for port1 and port0.
nxp_ip 0:6c9a51a50eea 236 *
nxp_ip 0:6c9a51a50eea 237 * @note
nxp_ip 0:6c9a51a50eea 238 * The data for pins, given as integer.
nxp_ip 0:6c9a51a50eea 239 * The 16-bit MSB goes to P1_7 pin and LSB goes to P0_0 pin.
nxp_ip 0:6c9a51a50eea 240 * If the bit is set to '1', the pin will be input.
nxp_ip 0:6c9a51a50eea 241 *
nxp_ip 0:6c9a51a50eea 242 * @see write()
nxp_ip 0:6c9a51a50eea 243 * @see read()
nxp_ip 0:6c9a51a50eea 244 */
nxp_ip 0:6c9a51a50eea 245 void configure( int bit_pattern );
nxp_ip 0:6c9a51a50eea 246
nxp_ip 0:6c9a51a50eea 247 /** Set interrupt mask
nxp_ip 0:6c9a51a50eea 248 *
nxp_ip 0:6c9a51a50eea 249 * @param bit_pattern 16-bit interrupt mask
nxp_ip 0:6c9a51a50eea 250 *
nxp_ip 0:6c9a51a50eea 251 * @see interrupt_status()
nxp_ip 0:6c9a51a50eea 252 */
nxp_ip 0:6c9a51a50eea 253 void interrupt_mask( int bit_pattern );
nxp_ip 0:6c9a51a50eea 254
nxp_ip 0:6c9a51a50eea 255 /** Read interrupt status
nxp_ip 0:6c9a51a50eea 256 *
nxp_ip 0:6c9a51a50eea 257 * @return
nxp_ip 0:6c9a51a50eea 258 * 16-bit data from interrupt status registers
nxp_ip 0:6c9a51a50eea 259 *
nxp_ip 0:6c9a51a50eea 260 * @see interrupt_status()
nxp_ip 0:6c9a51a50eea 261 */
nxp_ip 0:6c9a51a50eea 262 int interrupt_status( void );
nxp_ip 0:6c9a51a50eea 263
nxp_ip 0:6c9a51a50eea 264 /** A shorthand for read()
nxp_ip 0:6c9a51a50eea 265 */
nxp_ip 0:6c9a51a50eea 266 operator int( void );
nxp_ip 0:6c9a51a50eea 267
nxp_ip 0:6c9a51a50eea 268 #endif
nxp_ip 0:6c9a51a50eea 269
nxp_ip 0:6c9a51a50eea 270 /** Write 16-bit data into registers
nxp_ip 0:6c9a51a50eea 271 *
nxp_ip 0:6c9a51a50eea 272 * @param reg_index Direst access to registers.
nxp_ip 0:6c9a51a50eea 273 * The registers can be referenced by regiser index
nxp_ip 0:6c9a51a50eea 274 * @param data 16-bit data. Data will be written into two 8-bit registers
nxp_ip 0:6c9a51a50eea 275 */
nxp_ip 0:6c9a51a50eea 276 virtual void reg_index_write( char register_index, int data );
nxp_ip 0:6c9a51a50eea 277
nxp_ip 0:6c9a51a50eea 278 /** Read 16-bit data from registers
nxp_ip 0:6c9a51a50eea 279 *
nxp_ip 0:6c9a51a50eea 280 * @param reg_index Direst access to registers.
nxp_ip 0:6c9a51a50eea 281 * The registers can be referenced by regiser index
nxp_ip 0:6c9a51a50eea 282 *
nxp_ip 0:6c9a51a50eea 283 * @return
nxp_ip 0:6c9a51a50eea 284 * 16-bit data from two registers.
nxp_ip 0:6c9a51a50eea 285 * The register which has lower address will be upper 8-bit data.
nxp_ip 0:6c9a51a50eea 286 */
nxp_ip 0:6c9a51a50eea 287 virtual int reg_index_read( char register_index );
nxp_ip 0:6c9a51a50eea 288
nxp_ip 0:6c9a51a50eea 289 /** A shorthand for write()
nxp_ip 0:6c9a51a50eea 290 */
nxp_ip 0:6c9a51a50eea 291 PCAL9555& operator= ( int bit_pattern );
nxp_ip 0:6c9a51a50eea 292 PCAL9555& operator= ( PCAL9555& rhs );
nxp_ip 0:6c9a51a50eea 293
nxp_ip 0:6c9a51a50eea 294 private:
nxp_ip 0:6c9a51a50eea 295 /** Register index name */
nxp_ip 0:6c9a51a50eea 296 enum RegisterIndex {
nxp_ip 0:6c9a51a50eea 297 InputPort = InputPort0,
nxp_ip 0:6c9a51a50eea 298 OutoutPort = OutoutPort0,
nxp_ip 0:6c9a51a50eea 299 PolarityInversionPort = PolarityInversionPort0,
nxp_ip 0:6c9a51a50eea 300 ConfigurationPort = ConfigurationPort0,
nxp_ip 0:6c9a51a50eea 301 OutputDriveStrength0 = OutputDriveStrength0_0,
nxp_ip 0:6c9a51a50eea 302 OutputDriveStrength1 = OutputDriveStrength1_0,
nxp_ip 0:6c9a51a50eea 303 InputLatch = InputLatch0,
nxp_ip 0:6c9a51a50eea 304 PullUpPullDowmEnable = PullUpPullDowmEnable0,
nxp_ip 0:6c9a51a50eea 305 PullUpPullDowmSelection = PullUpPullDowmSelection0,
nxp_ip 0:6c9a51a50eea 306 InterruptMask = InterruptMask0,
nxp_ip 0:6c9a51a50eea 307 InterruptStatus = InterruptStatus0
nxp_ip 0:6c9a51a50eea 308 };
nxp_ip 0:6c9a51a50eea 309
nxp_ip 0:6c9a51a50eea 310 static const char regmap[];
nxp_ip 0:6c9a51a50eea 311 const int n_of_pins;
nxp_ip 0:6c9a51a50eea 312 }
nxp_ip 0:6c9a51a50eea 313 ;
nxp_ip 0:6c9a51a50eea 314
nxp_ip 0:6c9a51a50eea 315 #endif // MBED_PCAL9555