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
PCAL9554 Class Reference
#include <PCAL9554.h>
Inherits PCAL955x.
Public Types | |
enum | command_reg { InputPort = 0x00, OutoutPort, PolarityInversionPort, ConfigurationPort, OutputDriveStrength0 = 0x40, OutputDriveStrength1, InputLatch, PullUpPullDowmEnable, PullUpPullDowmSelection, InterruptMask, InterruptStatus, OutputPortConfiguration = 0x4F } |
Name of the PCAL9554 registers. More... | |
enum | GpioPinName { X0_0, X0_1, X0_2, X0_3, X0_4, X0_5, X0_6, X0_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, 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 | |
PCAL9554 (PinName i2c_sda, PinName i2c_scl, char i2c_address=PCAL955x::DEFAULT_I2C_ADDR) | |
Create a PCAL9554 instance connected to specified I2C pins with specified address. | |
PCAL9554 (I2C &i2c_obj, char i2c_address=PCAL955x::DEFAULT_I2C_ADDR) | |
Create a PCAL9554 instance connected to specified I2C pins with specified address. | |
virtual | ~PCAL9554 () |
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. | |
PCAL9554 & | operator= (int bit_pattern) |
A shorthand for write() |
Detailed Description
PCAL9554 class.
PCA(L)9554 8-bit I2C-bus GPIO expander.
This is a driver code for the Low-voltage 8-bit I2C-bus GPIO with Agile I/O. This class provides interface for PCAL9554 operation. Detail information is available on next URL. http://www.jp.nxp.com/products/interface_and_connectivity/i2c/i2c_general_purpose_i_o/series/PCAL9554B_PCAL9554C.html
PCAL9554 library's basic IO operation is compatible to PCA9554, PCA9538. 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 "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++ ); } }
GpioDigitalInOut, GpioDigitalOut, GpioDigitalIn, GpioBusInOut, GpioBusOut and GpioBusIn API class are available also. For those API details, please find those class library page. The GpioDigital* and GpioBus* APIs can be used as next sample code.
// GPIO-expander operation sample using high-level-API #include "mbed.h" #include "PCAL9554.h" PCAL9555 gpio( p28, p27, 0xE0 ); // using PCA9538 // The GPIO pins are grouped in some groups and operated as bus I/O GpioBusIn bus_in( gpio, X0, X1, X2, X3 ); GpioBusOut bus_out( gpio, X4, X5, X6 ); GpioDigitalOut myled( gpio, X7 ); int main() { int count = 0; while(1) { printf( "In = 0x%01X\r\n", (int)bus_in ); bus_out = count; myled = count & 0x1; count++; wait( 0.1 ); } }
An operation sample of PCA(L)9554 and PCA9538. mbed accesses the PCAL9554 registers through I2C.
- Version:
- 0.6
- Date:
- 19-Mar-2015
Released under the Apache 2 license
About PCAL9554: http://www.jp.nxp.com/products/interface_and_connectivity/i2c/i2c_general_purpose_i_o/series/PCAL9554B_PCAL9554C.html
Definition at line 87 of file PCAL9554.h.
Member Enumeration Documentation
enum command_reg |
Name of the PCAL9554 registers.
- Enumerator:
Definition at line 92 of file PCAL9554.h.
enum GpioPinName |
GPIO-Expander pin names for when the high-level APIs (GpioDigitalOut, GpioDigitalInOut, GpioDigitalIn, GpioBusOut, GpioBusInOut are GpioBusIn) are used.
- Enumerator:
Definition at line 113 of file PCAL9554.h.
Constructor & Destructor Documentation
PCAL9554 | ( | PinName | i2c_sda, |
PinName | i2c_scl, | ||
char | i2c_address = PCAL955x::DEFAULT_I2C_ADDR |
||
) |
Create a PCAL9554 instance connected to specified I2C pins with specified address.
- Parameters:
-
i2c_sda I2C-bus SDA pin i2c_sda I2C-bus SCL pin i2c_address I2C-bus address (default: 0x40)
Definition at line 5 of file PCAL9554.cpp.
PCAL9554 | ( | I2C & | i2c_obj, |
char | i2c_address = PCAL955x::DEFAULT_I2C_ADDR |
||
) |
Create a PCAL9554 instance connected to specified I2C pins with specified address.
- Parameters:
-
i2c_obj I2C object (instance) i2c_address I2C-bus address (default: 0x40)
Definition at line 10 of file PCAL9554.cpp.
~PCAL9554 | ( | ) | [virtual] |
Destractor.
Definition at line 15 of file PCAL9554.cpp.
Member Function Documentation
void configure | ( | int | bit_pattern ) |
Set IO congiguration.
- Parameters:
-
bit_pattern 16-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. Data will not come out from the pin if it is configured as input.
Reimplemented from PCAL955x.
void interrupt_mask | ( | int | bit_pattern ) |
Set interrupt mask.
- Parameters:
-
bit_pattern 16-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 PCAL9554.cpp.
PCAL9554 & operator= | ( | int | bit_pattern ) |
A shorthand for write()
Definition at line 43 of file PCAL9554.cpp.
void polarity | ( | int | bit_pattern ) |
Polarity setting.
- Parameters:
-
bit_pattern 16-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_index Direst access to registers. The registers can be referenced by regiser index
- Returns:
- 16-bit data from two registers. The register which has lower address will be upper 8-bit data.
Implements PCAL955x.
Definition at line 34 of file PCAL9554.cpp.
void reg_index_write | ( | char | register_index, |
int | data | ||
) | [virtual] |
Write 16-bit data into registers.
- Parameters:
-
reg_index Direst access to registers. The registers can be referenced by regiser index data 16-bit data. Data will be written into two 8-bit registers
Implements PCAL955x.
Definition at line 24 of file PCAL9554.cpp.
void write | ( | int | bit_pattern ) |
Set output port bits.
- Parameters:
-
bit_pattern 16-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.
Generated on Tue Jul 12 2022 18:40:41 by 1.7.2