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.

Embed: (wiki syntax)

« Back to documentation index

PCAL6416 Class Reference

PCAL6416 Class Reference

PCAL6416 class. More...

#include <PCAL6416.h>

Inherits PCAL955x.

Public Types

enum  command_reg {
  InputPort0 = 0x00, InputPort1, OutoutPort0, OutoutPort1,
  PolarityInversionPort0, PolarityInversionPort1, ConfigurationPort0, ConfigurationPort1,
  OutputDriveStrength0_0 = 0x40, OutputDriveStrength0_1, OutputDriveStrength1_0, OutputDriveStrength1_1,
  InputLatch0, InputLatch1, PullUpPullDowmEnable0, PullUpPullDowmEnable1,
  PullUpPullDowmSelection0, PullUpPullDowmSelection1, InterruptMask0, InterruptMask1,
  InterruptStatus0, InterruptStatus1, OutputPortConfiguration = 0x4F
}
 

Name of the PCAL6416 registers.

More...
enum  GpioPinName {
  X0_0, X0_1, X0_2, X0_3,
  X0_4, X0_5, X0_6, X0_7,
  X1_0, X1_1, X1_2, X1_3,
  X1_4, X1_5, X1_6, X1_7,
  X0 = X0_0, X1 = X0_1, X2 = X0_2, X3 = X0_3,
  X4 = X0_4, X5 = X0_5, X6 = X0_6, X7 = X0_7,
  X8 = X1_0, X9 = X1_1, X10 = X1_2, X11 = X1_3,
  X12 = X1_4, X13 = X1_5, X14 = X1_6, X15 = X1_7,
  X_NC = ~0x0L
}
 

GPIO-Expander pin names for when the high-level APIs (GpioDigitalOut, GpioDigitalInOut, GpioDigitalIn, GpioBusOut, GpioBusInOut are GpioBusIn) are used.

More...

Public Member Functions

 PCAL6416 (PinName i2c_sda, PinName i2c_scl, char i2c_address=PCAL955x::DEFAULT_I2C_ADDR)
 Create a PCAL6416 instance connected to specified I2C pins with specified address.
 PCAL6416 (I2C &i2c_obj, char i2c_address=PCAL955x::DEFAULT_I2C_ADDR)
 Create a PCAL6416 instance connected to specified I2C pins with specified address.
virtual ~PCAL6416 ()
 Destractor.
virtual int number_of_pins (void)
 Returns the number of I/O pins.
void write (int bit_pattern)
 Set output port bits.
int read (void)
 Read pin states.
void polarity (int bit_pattern)
 Polarity setting.
void configure (int bit_pattern)
 Set IO congiguration.
void interrupt_mask (int bit_pattern)
 Set interrupt mask.
int interrupt_status (void)
 Read interrupt status.
 operator int (void)
 A shorthand for read()
virtual void reg_index_write (char register_index, int data)
 Write 16-bit data into registers.
virtual int reg_index_read (char register_index)
 Read 16-bit data from registers.
PCAL6416operator= (int bit_pattern)
 A shorthand for write()

Detailed Description

PCAL6416 class.

PCAL6416A 16-bit I2C-bus GPIO expander.

This is a driver code for the Low-voltage 16-bit I2C-bus GPIO with Agile I/O. This class provides interface for PCAL6416 operation. Detail information is available on next URL. http://www.nxp.com/documents/data_sheet/PCAL6416A.pdf

PCAL9555 library's basic IO operation is compatible to PCA9555, PCA9535, PCAL6416A and PCA9539. This library can be used for those GPIO expander chips also. Next sample code shows operation based on low-level-API (operated by just device instane)

Example:

  //  GPIO-expander operation sample using a device instance
  
  #include    "mbed.h"
  #include    "PCAL6416.h"

  PCAL6416    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++ );
      }
  }

GpioDigitalInOut, GpioDigitalOut, GpioDigitalIn, GpioBusInOut, GpioBusOut and GpioBusIn API class are available also. For those high-level-API details, please find those class library page. The GpioDigital* and GpioBus* APIs can be used like next sample code.

  //  GPIO-expander operation sample using high-level-API
  
  #include    "mbed.h"
  #include    "PCAL6416.h"

  PCAL6416        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 );
      }
  }

An operation sample of PCA(L)9555, PCA9535, PCA9539 and PCAL6416. mbed accesses the PCAL6416 registers through I2C.

Author:
Akifumi (Tedd) OKANO, NXP Semiconductors
Version:
0.6.1
Date:
19-Mar-2015 15-Feb-2017, by Andriy Makukha, Shenzhen MZJ Technology Co.

Released under the Apache 2 license

About PCAL6416: http://www.nxp.com/documents/data_sheet/PCAL6416A.pdf

Definition at line 95 of file PCAL6416.h.


Member Enumeration Documentation

Name of the PCAL6416 registers.

Enumerator:
InputPort0 

InputPort0 register.

InputPort1 

InputPort1 register.

OutoutPort0 

OutoutPort0 register.

OutoutPort1 

OutoutPort1 register.

PolarityInversionPort0 

PolarityInversionPort0 register.

PolarityInversionPort1 

PolarityInversionPort1 register.

ConfigurationPort0 

ConfigurationPort0 register.

ConfigurationPort1 

ConfigurationPort1 register.

OutputDriveStrength0_0 

OutputDriveStrength0_0 register.

OutputDriveStrength0_1 

OutputDriveStrength0_1 register.

OutputDriveStrength1_0 

OutputDriveStrength1_0 register.

OutputDriveStrength1_1 

OutputDriveStrength1_1 register.

InputLatch0 

InputLatch0 register.

InputLatch1 

InputLatch1 register.

PullUpPullDowmEnable0 

PullUpPullDowmEnable0 register.

PullUpPullDowmEnable1 

PullUpPullDowmEnable1 register.

PullUpPullDowmSelection0 

PullUpPullDowmSelection0 register.

PullUpPullDowmSelection1 

PullUpPullDowmSelection1 register.

InterruptMask0 

InterruptMask0 register.

InterruptMask1 

InterruptMask1 register.

InterruptStatus0 

InterruptStatus0 register.

InterruptStatus1 

InterruptStatus1 register.

OutputPortConfiguration 

OutputPortConfiguration register.

Definition at line 99 of file PCAL6416.h.

GPIO-Expander pin names for when the high-level APIs (GpioDigitalOut, GpioDigitalInOut, GpioDigitalIn, GpioBusOut, GpioBusInOut are GpioBusIn) are used.

Enumerator:
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.

X1_1 

P1_1 pin.

X1_2 

P1_2 pin.

X1_3 

P1_3 pin.

X1_4 

P1_4 pin.

X1_5 

P1_5 pin.

X1_6 

P1_6 pin.

X1_7 

P1_7 pin.

X0 

P0_0 pin.

X1 

P0_1 pin.

X2 

P0_2 pin.

X3 

P0_3 pin.

X4 

P0_4 pin.

X5 

P0_5 pin.

X6 

P0_6 pin.

X7 

P0_7 pin.

X8 

P1_0 pin.

X9 

P1_1 pin.

X10 

P1_2 pin.

X11 

P1_3 pin.

X12 

P1_4 pin.

X13 

P1_5 pin.

X14 

P1_6 pin.

X15 

P1_7 pin.

X_NC 

for when the pin is left no-connection

Definition at line 131 of file PCAL6416.h.


Constructor & Destructor Documentation

PCAL6416 ( PinName  i2c_sda,
PinName  i2c_scl,
char  i2c_address = PCAL955x::DEFAULT_I2C_ADDR 
)

Create a PCAL6416 instance connected to specified I2C pins with specified address.

Parameters:
i2c_sdaI2C-bus SDA pin
i2c_sdaI2C-bus SCL pin
i2c_addressI2C-bus address (default: 0x40)

Definition at line 5 of file PCAL6416.cpp.

PCAL6416 ( I2C &  i2c_obj,
char  i2c_address = PCAL955x::DEFAULT_I2C_ADDR 
)

Create a PCAL6416 instance connected to specified I2C pins with specified address.

Parameters:
i2c_objI2C object (instance)
i2c_addressI2C-bus address (default: 0x40)

Definition at line 10 of file PCAL6416.cpp.

~PCAL6416 (  ) [virtual]

Destractor.

Definition at line 15 of file PCAL6416.cpp.


Member Function Documentation

void configure ( int  bit_pattern )

Set IO congiguration.

Parameters:
bit_pattern16-bit IO direction setting pattern for port1 and port0.
Note:
The data for pins, given as integer. The 16-bit MSB goes to P1_7 pin and LSB goes to P0_0 pin. If the bit is set to '1', the pin will be input.
See also:
write()
read()

Reimplemented from PCAL955x.

void interrupt_mask ( int  bit_pattern )

Set interrupt mask.

Parameters:
bit_pattern16-bit interrupt mask
See also:
interrupt_status()

Reimplemented from PCAL955x.

int interrupt_status ( void   )

Read interrupt status.

Returns:
16-bit data from interrupt status registers
See also:
interrupt_status()

Reimplemented from PCAL955x.

int number_of_pins ( void   ) [virtual]

Returns the number of I/O pins.

Returns:
The number of I/O pins

Implements PCAL955x.

Definition at line 19 of file PCAL6416.cpp.

operator int ( void   )

A shorthand for read()

Reimplemented from PCAL955x.

PCAL6416 & operator= ( int  bit_pattern )

A shorthand for write()

Definition at line 44 of file PCAL6416.cpp.

void polarity ( int  bit_pattern )

Polarity setting.

Parameters:
bit_pattern16-bit polarity setting pattern for port1 and port0. If the bit is set to '1', the state will be inverted. (Default state is all '0')
See also:
configure()

Reimplemented from PCAL955x.

int read ( void   ) [virtual]

Read pin states.

Returns:
16-bit pattern from port1 and port0.
Note:
The data from pins, given as integer. The 16-bit port data comes from IO pins, P1_7 as MSB, P0_0 as LSB. Data cannot be read if the port is configured as output.
See also:
configure()

Reimplemented from PCAL955x.

int reg_index_read ( char  register_index ) [virtual]

Read 16-bit data from registers.

Parameters:
reg_indexRegisterIndex (like InputPort, OutoutPort, ConfigurationPort, etc.)
Returns:
16-bit data from each pair of registers. The register which has lower address will be upper 8-bit data.

Implements PCAL955x.

Definition at line 35 of file PCAL6416.cpp.

void reg_index_write ( char  register_index,
int  data 
) [virtual]

Write 16-bit data into registers.

Parameters:
reg_indexRegisterIndex (like InputPort, OutoutPort, ConfigurationPort, etc.)
data16-bit data. Data will be written into the pair of 8-bit registers.

Implements PCAL955x.

Definition at line 24 of file PCAL6416.cpp.

void write ( int  bit_pattern )

Set output port bits.

Parameters:
bit_pattern16-bit output pattern for port1 and port0.
Note:
The data for pins, given as integer. The 16-bit MSB goes to P1_7 pin and LSB goes to P0_0 pin. Data will not come out from the pin if it is configured as input.
See also:
configure()

Reimplemented from PCAL955x.