-
Embed:
(wiki syntax)
Show/hide line numbers
PCA9555.h
00001 #ifndef PCA9555_H 00002 #define PCA9555_H 00003 00004 #include <mbed.h> 00005 00006 00007 class PCA9555 00008 { 00009 public: 00010 00011 // ADDRESS 00012 static const int HARD_ADR = 0x40; 00013 static const int USER_ADR_MASK = 0x07; 00014 00015 00016 // PORT 0 00017 static const int PORT0_INPUT = 0x00; 00018 static const int PORT0_OUTPUT = 0x02; 00019 static const int PORT0_POLAR = 0x04; 00020 static const int PORT0_CONFIG = 0x06; 00021 00022 00023 00024 // PORT 1 00025 static const int PORT1_INPUT = 0x01; 00026 static const int PORT1_OUTPUT = 0x03; 00027 static const int PORT1_POLAR = 0x05; 00028 static const int PORT1_CONFIG = 0x07; 00029 00030 00031 // BIT polarity 00032 static const int NORM_POL_BIT0 = (0 << 0); 00033 static const int NORM_POL_BIT1 = (0 << 1); 00034 static const int NORM_POL_BIT2 = (0 << 2); 00035 static const int NORM_POL_BIT3 = (0 << 3); 00036 static const int NORM_POL_BIT4 = (0 << 4); 00037 static const int NORM_POL_BIT5 = (0 << 5); 00038 static const int NORM_POL_BIT6 = (0 << 6); 00039 static const int NORM_POL_BIT7 = (0 << 7); 00040 00041 static const int INV_POL_BIT0 = (1 << 0); 00042 static const int INV_POL_BIT1 = (1 << 1); 00043 static const int INV_POL_BIT2 = (1 << 2); 00044 static const int INV_POL_BIT3 = (1 << 3); 00045 static const int INV_POL_BIT4 = (1 << 4); 00046 static const int INV_POL_BIT5 = (1 << 5); 00047 static const int INV_POL_BIT6 = (1 << 6); 00048 static const int INV_POL_BIT7 = (1 << 7); 00049 00050 00051 00052 00053 static const int BIT0 = 0; 00054 static const int BIT1 = 1; 00055 static const int BIT2 = 2; 00056 static const int BIT3 = 3; 00057 static const int BIT4 = 4; 00058 static const int BIT5 = 5; 00059 static const int BIT6 = 6; 00060 static const int BIT7 = 7; 00061 00062 00063 00064 00065 //public: 00066 // definitions 00067 typedef enum { _PORT0, _PORT1, _BOTH} _GPIO; 00068 00069 typedef union { 00070 struct{ 00071 unsigned int B0 : 1; 00072 unsigned int B1 : 1; 00073 unsigned int B2 : 1; 00074 unsigned int B3 : 1; 00075 unsigned int B4 : 1; 00076 unsigned int B5 : 1; 00077 unsigned int B6 : 1; 00078 unsigned int B7 : 1; 00079 }Pin; 00080 00081 uint8_t uiPort; 00082 }GPIO; 00083 00084 00085 // function 00086 PCA9555(I2C *_i2c, uint8_t uiAdr); 00087 00088 00089 bool confDirGPIO(_GPIO gpio, uint8_t uiData0, uint8_t uiData1 = NULL); 00090 00091 00092 uint8_t getGPIO0(bool bUpdate); 00093 bool getGPIO0_B0(bool bUpdate); 00094 bool getGPIO0_B1(bool bUpdate); 00095 bool getGPIO0_B2(bool bUpdate); 00096 bool getGPIO0_B3(bool bUpdate); 00097 bool getGPIO0_B4(bool bUpdate); 00098 bool getGPIO0_B5(bool bUpdate); 00099 bool getGPIO0_B6(bool bUpdate); 00100 bool getGPIO0_B7(bool bUpdate); 00101 00102 uint8_t getGPIO1(bool bUpdate); 00103 bool getGPIO1_B0(bool bUpdate); 00104 bool getGPIO1_B1(bool bUpdate); 00105 bool getGPIO1_B2(bool bUpdate); 00106 bool getGPIO1_B3(bool bUpdate); 00107 bool getGPIO1_B4(bool bUpdate); 00108 bool getGPIO1_B5(bool bUpdate); 00109 bool getGPIO1_B6(bool bUpdate); 00110 bool getGPIO1_B7(bool bUpdate); 00111 00112 00113 bool setGPIO(_GPIO gpio, uint8_t uiData0, uint8_t uiData1 = NULL); 00114 bool setGPIO0_B0(bool bBit); 00115 bool setGPIO0_B1(bool bBit); 00116 bool setGPIO0_B2(bool bBit); 00117 bool setGPIO0_B3(bool bBit); 00118 bool setGPIO0_B4(bool bBit); 00119 bool setGPIO0_B5(bool bBit); 00120 bool setGPIO0_B6(bool bBit); 00121 bool setGPIO0_B7(bool bBit); 00122 00123 bool setGPIO1_B0(bool bBit); 00124 bool setGPIO1_B1(bool bBit); 00125 bool setGPIO1_B2(bool bBit); 00126 bool setGPIO1_B3(bool bBit); 00127 bool setGPIO1_B4(bool bBit); 00128 bool setGPIO1_B5(bool bBit); 00129 bool setGPIO1_B6(bool bBit); 00130 bool setGPIO1_B7(bool bBit); 00131 00132 // variable 00133 static const _GPIO PORT0 = _PORT0; 00134 static const _GPIO PORT1 = _PORT1; 00135 static const _GPIO BOTH = _BOTH; 00136 00137 GPIO GPIO0, GPIO1; 00138 00139 00140 //uint8_t uiGPIO0, uiGPIO1; 00141 00142 00143 private: 00144 // functions 00145 bool getGPIO(_GPIO gpio); 00146 00147 // variable 00148 const uint8_t PCA9555_W; 00149 const uint8_t PCA9555_R; 00150 00151 00152 00153 char cCmd[10]; 00154 bool bAck; 00155 00156 // Class 00157 I2C *i2c; 00158 }; 00159 00160 #endif
Generated on Sun Jul 17 2022 11:47:04 by 1.7.2