Lucas Citolin / Mbed OS Autoline
Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers PCA9555.h Source File

PCA9555.h

00001 /* ICTS PLC Board Library
00002  *
00003  * PCA9555.h
00004  *
00005  *  Created on: 24 de mai de 2018
00006  *      Author: Claudio Pinheiro
00007  */
00008 
00009 #ifndef PCA9555_H_
00010 #define PCA9555_H_
00011 
00012 #include "mbed.h"
00013 
00014 #define FIXED_ADDRESS 0x40
00015 
00016 typedef enum {
00017     PCA9555_PORT0,
00018     PCA9555_PORT1
00019 } PCA9555_Port_enum;
00020 
00021 enum {
00022     COMMAND_INPUT_PORT0,
00023     COMMAND_INPUT_PORT1,
00024     COMMAND_OUTPUT_PORT0,
00025     COMMAND_OUTPUT_PORT1,
00026     COMMAND_POL_INVERSION_PORT0,
00027     COMMAND_POL_INVERSION_PORT1,
00028     COMMAND_CONFIGURATION_PORT0,
00029     COMMAND_CONFIGURATION_PORT1
00030 };
00031 
00032 class PCA9555 {
00033 public:
00034     PCA9555() {};
00035 
00036     /* Create interface to PCA9555 IC connected to a given I2C bus
00037      *
00038      * @param *i2cBus Pointer to I2C bus
00039      * @param address PCA9555 bus address
00040      */
00041     PCA9555(I2C *i2cBus, int address);
00042 
00043     virtual ~PCA9555();
00044 
00045     /* Configure direction of PCA955 ports
00046      *
00047      * @param configPort0 Configuration for Port 0
00048      * @param configPort1 Configuration for Port 1
00049      */
00050     void configDirAll(char configPort0, char configPort1);
00051 
00052     /* Write to a specific port
00053      *
00054      * @param port PCA9555 port
00055      * @param value Value to be writen to port
00056      */
00057     int write(PCA9555_Port_enum port, char value);
00058 
00059     char read(PCA9555_Port_enum port);
00060 
00061     int read(PCA9555_Port_enum port, char* value);
00062 
00063     int setBit(PCA9555_Port_enum port, char mask);
00064 
00065     int clearBit(PCA9555_Port_enum port, char mask);
00066 
00067     char getI2CAddress(void) {return i2c_address;};
00068 private:
00069     I2C *i2c_bus;
00070     char i2c_address;
00071     char cmd[3];
00072 };
00073 
00074 #endif /* PCA9555_H_ */