-
PCA9555/PCA9555.cpp@0:3835ff675f6b, 2019-02-01 (annotated)
- Committer:
- x1dmoesc
- Date:
- Fri Feb 01 09:41:20 2019 +0000
- Revision:
- 0:3835ff675f6b
- Child:
- 1:f54358de8a86
New Lib
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
x1dmoesc | 0:3835ff675f6b | 1 | #include <PCA9555.h> |
x1dmoesc | 0:3835ff675f6b | 2 | |
x1dmoesc | 0:3835ff675f6b | 3 | //#include <mbed.h> |
x1dmoesc | 0:3835ff675f6b | 4 | |
x1dmoesc | 0:3835ff675f6b | 5 | //******************************************************************************// |
x1dmoesc | 0:3835ff675f6b | 6 | // uiAdr: user address [A2...A0] |
x1dmoesc | 0:3835ff675f6b | 7 | //******************************************************************************// |
x1dmoesc | 0:3835ff675f6b | 8 | PCA9555::PCA9555(I2C *_i2c, uint8_t uiAdr) // |
x1dmoesc | 0:3835ff675f6b | 9 | : PCA9555_W( HARD_ADR | (uiAdr & USER_ADR_MASK) << 1),// Initialisation of const WRITE |
x1dmoesc | 0:3835ff675f6b | 10 | PCA9555_R( PCA9555_W | 0x01 ){ // Initialisation of const READ |
x1dmoesc | 0:3835ff675f6b | 11 | |
x1dmoesc | 0:3835ff675f6b | 12 | i2c = _i2c; // |
x1dmoesc | 0:3835ff675f6b | 13 | bAck = false; // |
x1dmoesc | 0:3835ff675f6b | 14 | } |
x1dmoesc | 0:3835ff675f6b | 15 | |
x1dmoesc | 0:3835ff675f6b | 16 | |
x1dmoesc | 0:3835ff675f6b | 17 | |
x1dmoesc | 0:3835ff675f6b | 18 | //******************************************************************************// |
x1dmoesc | 0:3835ff675f6b | 19 | // If a bit in this register is set (written with ‘1’), the corresponding port |
x1dmoesc | 0:3835ff675f6b | 20 | // pin is enabled as an input with high-impedance output driver. If a bit in |
x1dmoesc | 0:3835ff675f6b | 21 | // this register is cleared (written with ‘0’), the corresponding port pin is |
x1dmoesc | 0:3835ff675f6b | 22 | // enabled as an output. |
x1dmoesc | 0:3835ff675f6b | 23 | //******************************************************************************// |
x1dmoesc | 0:3835ff675f6b | 24 | bool PCA9555::confDirGPIO(_GPIO gpio, uint8_t uiData0, uint8_t uiData1){ |
x1dmoesc | 0:3835ff675f6b | 25 | |
x1dmoesc | 0:3835ff675f6b | 26 | if (gpio == BOTH){ // both GPIO ports |
x1dmoesc | 0:3835ff675f6b | 27 | cCmd[0] = PORT0_CONFIG; // start with GPIO Port0 |
x1dmoesc | 0:3835ff675f6b | 28 | cCmd[1] = uiData0; // uiData0 for GPIO Port 0 |
x1dmoesc | 0:3835ff675f6b | 29 | cCmd[2] = uiData1; // uiData1 for GPIO Port 1 |
x1dmoesc | 0:3835ff675f6b | 30 | |
x1dmoesc | 0:3835ff675f6b | 31 | bAck = i2c->write(PCA9555_W, cCmd, 3); // send via I2C |
x1dmoesc | 0:3835ff675f6b | 32 | |
x1dmoesc | 0:3835ff675f6b | 33 | } else { // only |
x1dmoesc | 0:3835ff675f6b | 34 | if (gpio == PORT0) cCmd[0] = PORT0_CONFIG; // Port0 |
x1dmoesc | 0:3835ff675f6b | 35 | else cCmd[0] = PORT1_CONFIG; // Port1 |
x1dmoesc | 0:3835ff675f6b | 36 | |
x1dmoesc | 0:3835ff675f6b | 37 | cCmd[1] = uiData0; // uiData |
x1dmoesc | 0:3835ff675f6b | 38 | bAck = i2c->write(PCA9555_W, cCmd, 2); // send via I2C |
x1dmoesc | 0:3835ff675f6b | 39 | } |
x1dmoesc | 0:3835ff675f6b | 40 | |
x1dmoesc | 0:3835ff675f6b | 41 | return bAck; // return (N)ACK |
x1dmoesc | 0:3835ff675f6b | 42 | } |
x1dmoesc | 0:3835ff675f6b | 43 | |
x1dmoesc | 0:3835ff675f6b | 44 | |
x1dmoesc | 0:3835ff675f6b | 45 | //******************************************************************************// |
x1dmoesc | 0:3835ff675f6b | 46 | // |
x1dmoesc | 0:3835ff675f6b | 47 | //******************************************************************************// |
x1dmoesc | 0:3835ff675f6b | 48 | bool PCA9555::getGPIO(_GPIO gpio){ |
x1dmoesc | 0:3835ff675f6b | 49 | |
x1dmoesc | 0:3835ff675f6b | 50 | if (gpio == BOTH){ // both GPIO ports |
x1dmoesc | 0:3835ff675f6b | 51 | cCmd[0] = PORT0_INPUT; // start with GPIO Port0 |
x1dmoesc | 0:3835ff675f6b | 52 | |
x1dmoesc | 0:3835ff675f6b | 53 | bAck = i2c->write(PCA9555_W, cCmd, 1); // send via I2C |
x1dmoesc | 0:3835ff675f6b | 54 | bAck = i2c->read(PCA9555_R, cCmd, 2); // send via I2C |
x1dmoesc | 0:3835ff675f6b | 55 | GPIO0.uiPort = cCmd[0]; |
x1dmoesc | 0:3835ff675f6b | 56 | GPIO1.uiPort = cCmd[1]; |
x1dmoesc | 0:3835ff675f6b | 57 | |
x1dmoesc | 0:3835ff675f6b | 58 | } else { // only |
x1dmoesc | 0:3835ff675f6b | 59 | if (gpio == PORT0) cCmd[0] = PORT0_INPUT; // Port0 |
x1dmoesc | 0:3835ff675f6b | 60 | else cCmd[0] = PORT1_INPUT; // Port1 |
x1dmoesc | 0:3835ff675f6b | 61 | |
x1dmoesc | 0:3835ff675f6b | 62 | bAck = i2c->write(PCA9555_W, cCmd, 1); // send via I2C |
x1dmoesc | 0:3835ff675f6b | 63 | bAck = i2c->read(PCA9555_W, cCmd, 1); // send via I2C |
x1dmoesc | 0:3835ff675f6b | 64 | |
x1dmoesc | 0:3835ff675f6b | 65 | if (gpio == PORT0) GPIO0.uiPort = cCmd[0]; // Port0 |
x1dmoesc | 0:3835ff675f6b | 66 | else GPIO1.uiPort = cCmd[0]; // Port0 |
x1dmoesc | 0:3835ff675f6b | 67 | } |
x1dmoesc | 0:3835ff675f6b | 68 | |
x1dmoesc | 0:3835ff675f6b | 69 | return bAck; // return (N)ACK |
x1dmoesc | 0:3835ff675f6b | 70 | } |
x1dmoesc | 0:3835ff675f6b | 71 | |
x1dmoesc | 0:3835ff675f6b | 72 | |
x1dmoesc | 0:3835ff675f6b | 73 | |
x1dmoesc | 0:3835ff675f6b | 74 | //******************************************************************************// |
x1dmoesc | 0:3835ff675f6b | 75 | // |
x1dmoesc | 0:3835ff675f6b | 76 | //******************************************************************************// |
x1dmoesc | 0:3835ff675f6b | 77 | uint8_t PCA9555::getGPIO0(bool bUpdate){ |
x1dmoesc | 0:3835ff675f6b | 78 | |
x1dmoesc | 0:3835ff675f6b | 79 | if(bUpdate) getGPIO(BOTH); |
x1dmoesc | 0:3835ff675f6b | 80 | |
x1dmoesc | 0:3835ff675f6b | 81 | return GPIO0.uiPort; |
x1dmoesc | 0:3835ff675f6b | 82 | } |
x1dmoesc | 0:3835ff675f6b | 83 | |
x1dmoesc | 0:3835ff675f6b | 84 | |
x1dmoesc | 0:3835ff675f6b | 85 | |
x1dmoesc | 0:3835ff675f6b | 86 | //******************************************************************************// |
x1dmoesc | 0:3835ff675f6b | 87 | // |
x1dmoesc | 0:3835ff675f6b | 88 | //******************************************************************************// |
x1dmoesc | 0:3835ff675f6b | 89 | bool PCA9555::getGPIO0_B0(bool bUpdate){ |
x1dmoesc | 0:3835ff675f6b | 90 | |
x1dmoesc | 0:3835ff675f6b | 91 | if(bUpdate) getGPIO(BOTH); |
x1dmoesc | 0:3835ff675f6b | 92 | |
x1dmoesc | 0:3835ff675f6b | 93 | return (bool) GPIO0.Pin.B0; |
x1dmoesc | 0:3835ff675f6b | 94 | } |
x1dmoesc | 0:3835ff675f6b | 95 | |
x1dmoesc | 0:3835ff675f6b | 96 | |
x1dmoesc | 0:3835ff675f6b | 97 | |
x1dmoesc | 0:3835ff675f6b | 98 | //******************************************************************************// |
x1dmoesc | 0:3835ff675f6b | 99 | // |
x1dmoesc | 0:3835ff675f6b | 100 | //******************************************************************************// |
x1dmoesc | 0:3835ff675f6b | 101 | bool PCA9555::getGPIO0_B1(bool bUpdate){ |
x1dmoesc | 0:3835ff675f6b | 102 | |
x1dmoesc | 0:3835ff675f6b | 103 | if(bUpdate) getGPIO(BOTH); |
x1dmoesc | 0:3835ff675f6b | 104 | |
x1dmoesc | 0:3835ff675f6b | 105 | return GPIO0.Pin.B1; |
x1dmoesc | 0:3835ff675f6b | 106 | |
x1dmoesc | 0:3835ff675f6b | 107 | } |
x1dmoesc | 0:3835ff675f6b | 108 | |
x1dmoesc | 0:3835ff675f6b | 109 | |
x1dmoesc | 0:3835ff675f6b | 110 | |
x1dmoesc | 0:3835ff675f6b | 111 | //******************************************************************************// |
x1dmoesc | 0:3835ff675f6b | 112 | // |
x1dmoesc | 0:3835ff675f6b | 113 | //******************************************************************************// |
x1dmoesc | 0:3835ff675f6b | 114 | bool PCA9555::getGPIO0_B2(bool bUpdate){ |
x1dmoesc | 0:3835ff675f6b | 115 | |
x1dmoesc | 0:3835ff675f6b | 116 | if(bUpdate) getGPIO(BOTH); |
x1dmoesc | 0:3835ff675f6b | 117 | |
x1dmoesc | 0:3835ff675f6b | 118 | return GPIO0.Pin.B2; |
x1dmoesc | 0:3835ff675f6b | 119 | } |
x1dmoesc | 0:3835ff675f6b | 120 | |
x1dmoesc | 0:3835ff675f6b | 121 | |
x1dmoesc | 0:3835ff675f6b | 122 | |
x1dmoesc | 0:3835ff675f6b | 123 | //******************************************************************************// |
x1dmoesc | 0:3835ff675f6b | 124 | // |
x1dmoesc | 0:3835ff675f6b | 125 | //******************************************************************************// |
x1dmoesc | 0:3835ff675f6b | 126 | bool PCA9555::getGPIO0_B3(bool bUpdate){ |
x1dmoesc | 0:3835ff675f6b | 127 | |
x1dmoesc | 0:3835ff675f6b | 128 | if(bUpdate) getGPIO(BOTH); |
x1dmoesc | 0:3835ff675f6b | 129 | |
x1dmoesc | 0:3835ff675f6b | 130 | return GPIO0.Pin.B3; |
x1dmoesc | 0:3835ff675f6b | 131 | |
x1dmoesc | 0:3835ff675f6b | 132 | } |
x1dmoesc | 0:3835ff675f6b | 133 | |
x1dmoesc | 0:3835ff675f6b | 134 | |
x1dmoesc | 0:3835ff675f6b | 135 | |
x1dmoesc | 0:3835ff675f6b | 136 | //******************************************************************************// |
x1dmoesc | 0:3835ff675f6b | 137 | // |
x1dmoesc | 0:3835ff675f6b | 138 | //******************************************************************************// |
x1dmoesc | 0:3835ff675f6b | 139 | bool PCA9555::getGPIO0_B4(bool bUpdate){ |
x1dmoesc | 0:3835ff675f6b | 140 | |
x1dmoesc | 0:3835ff675f6b | 141 | if(bUpdate) getGPIO(BOTH); |
x1dmoesc | 0:3835ff675f6b | 142 | |
x1dmoesc | 0:3835ff675f6b | 143 | return GPIO0.Pin.B4; |
x1dmoesc | 0:3835ff675f6b | 144 | } |
x1dmoesc | 0:3835ff675f6b | 145 | |
x1dmoesc | 0:3835ff675f6b | 146 | |
x1dmoesc | 0:3835ff675f6b | 147 | |
x1dmoesc | 0:3835ff675f6b | 148 | //******************************************************************************// |
x1dmoesc | 0:3835ff675f6b | 149 | // |
x1dmoesc | 0:3835ff675f6b | 150 | //******************************************************************************// |
x1dmoesc | 0:3835ff675f6b | 151 | bool PCA9555::getGPIO0_B5(bool bUpdate){ |
x1dmoesc | 0:3835ff675f6b | 152 | |
x1dmoesc | 0:3835ff675f6b | 153 | if(bUpdate) getGPIO(BOTH); |
x1dmoesc | 0:3835ff675f6b | 154 | |
x1dmoesc | 0:3835ff675f6b | 155 | return GPIO0.Pin.B5; |
x1dmoesc | 0:3835ff675f6b | 156 | |
x1dmoesc | 0:3835ff675f6b | 157 | } |
x1dmoesc | 0:3835ff675f6b | 158 | |
x1dmoesc | 0:3835ff675f6b | 159 | |
x1dmoesc | 0:3835ff675f6b | 160 | |
x1dmoesc | 0:3835ff675f6b | 161 | //******************************************************************************// |
x1dmoesc | 0:3835ff675f6b | 162 | // |
x1dmoesc | 0:3835ff675f6b | 163 | //******************************************************************************// |
x1dmoesc | 0:3835ff675f6b | 164 | bool PCA9555::getGPIO0_B6(bool bUpdate){ |
x1dmoesc | 0:3835ff675f6b | 165 | |
x1dmoesc | 0:3835ff675f6b | 166 | if(bUpdate) getGPIO(BOTH); |
x1dmoesc | 0:3835ff675f6b | 167 | |
x1dmoesc | 0:3835ff675f6b | 168 | return GPIO0.Pin.B6; |
x1dmoesc | 0:3835ff675f6b | 169 | } |
x1dmoesc | 0:3835ff675f6b | 170 | |
x1dmoesc | 0:3835ff675f6b | 171 | |
x1dmoesc | 0:3835ff675f6b | 172 | |
x1dmoesc | 0:3835ff675f6b | 173 | //******************************************************************************// |
x1dmoesc | 0:3835ff675f6b | 174 | // |
x1dmoesc | 0:3835ff675f6b | 175 | //******************************************************************************// |
x1dmoesc | 0:3835ff675f6b | 176 | bool PCA9555::getGPIO0_B7(bool bUpdate){ |
x1dmoesc | 0:3835ff675f6b | 177 | |
x1dmoesc | 0:3835ff675f6b | 178 | if(bUpdate) getGPIO(BOTH); |
x1dmoesc | 0:3835ff675f6b | 179 | |
x1dmoesc | 0:3835ff675f6b | 180 | return GPIO0.Pin.B7; |
x1dmoesc | 0:3835ff675f6b | 181 | |
x1dmoesc | 0:3835ff675f6b | 182 | } |
x1dmoesc | 0:3835ff675f6b | 183 | |
x1dmoesc | 0:3835ff675f6b | 184 | |
x1dmoesc | 0:3835ff675f6b | 185 | //******************************************************************************// |
x1dmoesc | 0:3835ff675f6b | 186 | // |
x1dmoesc | 0:3835ff675f6b | 187 | //******************************************************************************// |
x1dmoesc | 0:3835ff675f6b | 188 | uint8_t PCA9555::getGPIO1(bool bUpdate){ |
x1dmoesc | 0:3835ff675f6b | 189 | |
x1dmoesc | 0:3835ff675f6b | 190 | if(bUpdate) getGPIO(BOTH); |
x1dmoesc | 0:3835ff675f6b | 191 | |
x1dmoesc | 0:3835ff675f6b | 192 | return GPIO1.uiPort; |
x1dmoesc | 0:3835ff675f6b | 193 | } |
x1dmoesc | 0:3835ff675f6b | 194 | |
x1dmoesc | 0:3835ff675f6b | 195 | |
x1dmoesc | 0:3835ff675f6b | 196 | |
x1dmoesc | 0:3835ff675f6b | 197 | //******************************************************************************// |
x1dmoesc | 0:3835ff675f6b | 198 | // |
x1dmoesc | 0:3835ff675f6b | 199 | //******************************************************************************// |
x1dmoesc | 0:3835ff675f6b | 200 | bool PCA9555::getGPIO1_B0(bool bUpdate){ |
x1dmoesc | 0:3835ff675f6b | 201 | |
x1dmoesc | 0:3835ff675f6b | 202 | if(bUpdate) getGPIO(BOTH); |
x1dmoesc | 0:3835ff675f6b | 203 | |
x1dmoesc | 0:3835ff675f6b | 204 | return GPIO1.Pin.B0; |
x1dmoesc | 0:3835ff675f6b | 205 | } |
x1dmoesc | 0:3835ff675f6b | 206 | |
x1dmoesc | 0:3835ff675f6b | 207 | |
x1dmoesc | 0:3835ff675f6b | 208 | |
x1dmoesc | 0:3835ff675f6b | 209 | //******************************************************************************// |
x1dmoesc | 0:3835ff675f6b | 210 | // |
x1dmoesc | 0:3835ff675f6b | 211 | //******************************************************************************// |
x1dmoesc | 0:3835ff675f6b | 212 | bool PCA9555::getGPIO1_B1(bool bUpdate){ |
x1dmoesc | 0:3835ff675f6b | 213 | |
x1dmoesc | 0:3835ff675f6b | 214 | if(bUpdate) getGPIO(BOTH); |
x1dmoesc | 0:3835ff675f6b | 215 | |
x1dmoesc | 0:3835ff675f6b | 216 | return GPIO1.Pin.B1; |
x1dmoesc | 0:3835ff675f6b | 217 | |
x1dmoesc | 0:3835ff675f6b | 218 | } |
x1dmoesc | 0:3835ff675f6b | 219 | |
x1dmoesc | 0:3835ff675f6b | 220 | |
x1dmoesc | 0:3835ff675f6b | 221 | |
x1dmoesc | 0:3835ff675f6b | 222 | //******************************************************************************// |
x1dmoesc | 0:3835ff675f6b | 223 | // |
x1dmoesc | 0:3835ff675f6b | 224 | //******************************************************************************// |
x1dmoesc | 0:3835ff675f6b | 225 | bool PCA9555::getGPIO1_B2(bool bUpdate){ |
x1dmoesc | 0:3835ff675f6b | 226 | |
x1dmoesc | 0:3835ff675f6b | 227 | if(bUpdate) getGPIO(BOTH); |
x1dmoesc | 0:3835ff675f6b | 228 | |
x1dmoesc | 0:3835ff675f6b | 229 | return GPIO1.Pin.B2; |
x1dmoesc | 0:3835ff675f6b | 230 | } |
x1dmoesc | 0:3835ff675f6b | 231 | |
x1dmoesc | 0:3835ff675f6b | 232 | |
x1dmoesc | 0:3835ff675f6b | 233 | |
x1dmoesc | 0:3835ff675f6b | 234 | //******************************************************************************// |
x1dmoesc | 0:3835ff675f6b | 235 | // |
x1dmoesc | 0:3835ff675f6b | 236 | //******************************************************************************// |
x1dmoesc | 0:3835ff675f6b | 237 | bool PCA9555::getGPIO1_B3(bool bUpdate){ |
x1dmoesc | 0:3835ff675f6b | 238 | |
x1dmoesc | 0:3835ff675f6b | 239 | if(bUpdate) getGPIO(BOTH); |
x1dmoesc | 0:3835ff675f6b | 240 | |
x1dmoesc | 0:3835ff675f6b | 241 | return GPIO1.Pin.B3; |
x1dmoesc | 0:3835ff675f6b | 242 | |
x1dmoesc | 0:3835ff675f6b | 243 | } |
x1dmoesc | 0:3835ff675f6b | 244 | |
x1dmoesc | 0:3835ff675f6b | 245 | |
x1dmoesc | 0:3835ff675f6b | 246 | |
x1dmoesc | 0:3835ff675f6b | 247 | //******************************************************************************// |
x1dmoesc | 0:3835ff675f6b | 248 | // |
x1dmoesc | 0:3835ff675f6b | 249 | //******************************************************************************// |
x1dmoesc | 0:3835ff675f6b | 250 | bool PCA9555::getGPIO1_B4(bool bUpdate){ |
x1dmoesc | 0:3835ff675f6b | 251 | |
x1dmoesc | 0:3835ff675f6b | 252 | if(bUpdate) getGPIO(BOTH); |
x1dmoesc | 0:3835ff675f6b | 253 | |
x1dmoesc | 0:3835ff675f6b | 254 | return GPIO1.Pin.B4; |
x1dmoesc | 0:3835ff675f6b | 255 | } |
x1dmoesc | 0:3835ff675f6b | 256 | |
x1dmoesc | 0:3835ff675f6b | 257 | |
x1dmoesc | 0:3835ff675f6b | 258 | |
x1dmoesc | 0:3835ff675f6b | 259 | //******************************************************************************// |
x1dmoesc | 0:3835ff675f6b | 260 | // |
x1dmoesc | 0:3835ff675f6b | 261 | //******************************************************************************// |
x1dmoesc | 0:3835ff675f6b | 262 | bool PCA9555::getGPIO1_B5(bool bUpdate){ |
x1dmoesc | 0:3835ff675f6b | 263 | |
x1dmoesc | 0:3835ff675f6b | 264 | if(bUpdate) getGPIO(BOTH); |
x1dmoesc | 0:3835ff675f6b | 265 | |
x1dmoesc | 0:3835ff675f6b | 266 | return GPIO1.Pin.B5; |
x1dmoesc | 0:3835ff675f6b | 267 | |
x1dmoesc | 0:3835ff675f6b | 268 | } |
x1dmoesc | 0:3835ff675f6b | 269 | |
x1dmoesc | 0:3835ff675f6b | 270 | |
x1dmoesc | 0:3835ff675f6b | 271 | |
x1dmoesc | 0:3835ff675f6b | 272 | //******************************************************************************// |
x1dmoesc | 0:3835ff675f6b | 273 | // |
x1dmoesc | 0:3835ff675f6b | 274 | //******************************************************************************// |
x1dmoesc | 0:3835ff675f6b | 275 | bool PCA9555::getGPIO1_B6(bool bUpdate){ |
x1dmoesc | 0:3835ff675f6b | 276 | |
x1dmoesc | 0:3835ff675f6b | 277 | if(bUpdate) getGPIO(BOTH); |
x1dmoesc | 0:3835ff675f6b | 278 | |
x1dmoesc | 0:3835ff675f6b | 279 | return GPIO1.Pin.B6; |
x1dmoesc | 0:3835ff675f6b | 280 | } |
x1dmoesc | 0:3835ff675f6b | 281 | |
x1dmoesc | 0:3835ff675f6b | 282 | |
x1dmoesc | 0:3835ff675f6b | 283 | |
x1dmoesc | 0:3835ff675f6b | 284 | //******************************************************************************// |
x1dmoesc | 0:3835ff675f6b | 285 | // |
x1dmoesc | 0:3835ff675f6b | 286 | //******************************************************************************// |
x1dmoesc | 0:3835ff675f6b | 287 | bool PCA9555::getGPIO1_B7(bool bUpdate){ |
x1dmoesc | 0:3835ff675f6b | 288 | |
x1dmoesc | 0:3835ff675f6b | 289 | if(bUpdate) getGPIO(BOTH); |
x1dmoesc | 0:3835ff675f6b | 290 | |
x1dmoesc | 0:3835ff675f6b | 291 | return GPIO1.Pin.B7; |
x1dmoesc | 0:3835ff675f6b | 292 | |
x1dmoesc | 0:3835ff675f6b | 293 | } |
x1dmoesc | 0:3835ff675f6b | 294 | |
x1dmoesc | 0:3835ff675f6b | 295 | |
x1dmoesc | 0:3835ff675f6b | 296 | |
x1dmoesc | 0:3835ff675f6b | 297 | //******************************************************************************// |
x1dmoesc | 0:3835ff675f6b | 298 | // |
x1dmoesc | 0:3835ff675f6b | 299 | //******************************************************************************// |
x1dmoesc | 0:3835ff675f6b | 300 | bool PCA9555::setGPIO(_GPIO gpio, uint8_t uiData0, uint8_t uiData1) |
x1dmoesc | 0:3835ff675f6b | 301 | { |
x1dmoesc | 0:3835ff675f6b | 302 | if(gpio == BOTH){ // both GPIO ports |
x1dmoesc | 0:3835ff675f6b | 303 | cCmd[0] = PORT0_OUTPUT; // start with GPIO Port0 |
x1dmoesc | 0:3835ff675f6b | 304 | cCmd[1] = uiData0; // uiData0 for GPIO Port 0 |
x1dmoesc | 0:3835ff675f6b | 305 | cCmd[2] = uiData1; // uiData1 for GPIO Port 1 |
x1dmoesc | 0:3835ff675f6b | 306 | |
x1dmoesc | 0:3835ff675f6b | 307 | bAck = i2c->write(PCA9555_W, cCmd, 3); // send via I2C |
x1dmoesc | 0:3835ff675f6b | 308 | |
x1dmoesc | 0:3835ff675f6b | 309 | } else { // only |
x1dmoesc | 0:3835ff675f6b | 310 | if (gpio == PORT0) cCmd[0] = PORT0_OUTPUT; // Port0 |
x1dmoesc | 0:3835ff675f6b | 311 | else cCmd[0] = PORT1_OUTPUT; // Port1 |
x1dmoesc | 0:3835ff675f6b | 312 | |
x1dmoesc | 0:3835ff675f6b | 313 | cCmd[1] = uiData0; // uiData |
x1dmoesc | 0:3835ff675f6b | 314 | bAck = i2c->write(PCA9555_W, cCmd, 2); // send via I2C |
x1dmoesc | 0:3835ff675f6b | 315 | } |
x1dmoesc | 0:3835ff675f6b | 316 | |
x1dmoesc | 0:3835ff675f6b | 317 | return bAck; // return (N)ACK |
x1dmoesc | 0:3835ff675f6b | 318 | } |
x1dmoesc | 0:3835ff675f6b | 319 | |
x1dmoesc | 0:3835ff675f6b | 320 | |
x1dmoesc | 0:3835ff675f6b | 321 | //******************************************************************************// |
x1dmoesc | 0:3835ff675f6b | 322 | // |
x1dmoesc | 0:3835ff675f6b | 323 | //******************************************************************************// |
x1dmoesc | 0:3835ff675f6b | 324 | bool PCA9555::setGPIO0_B0(bool bBit){ |
x1dmoesc | 0:3835ff675f6b | 325 | |
x1dmoesc | 0:3835ff675f6b | 326 | GPIO0.Pin.B0 = bBit; |
x1dmoesc | 0:3835ff675f6b | 327 | |
x1dmoesc | 0:3835ff675f6b | 328 | return setGPIO(PORT0, GPIO0.uiPort); |
x1dmoesc | 0:3835ff675f6b | 329 | } |
x1dmoesc | 0:3835ff675f6b | 330 | |
x1dmoesc | 0:3835ff675f6b | 331 | |
x1dmoesc | 0:3835ff675f6b | 332 | |
x1dmoesc | 0:3835ff675f6b | 333 | |
x1dmoesc | 0:3835ff675f6b | 334 | //******************************************************************************// |
x1dmoesc | 0:3835ff675f6b | 335 | // |
x1dmoesc | 0:3835ff675f6b | 336 | //******************************************************************************// |
x1dmoesc | 0:3835ff675f6b | 337 | bool PCA9555::setGPIO0_B1(bool bBit){ |
x1dmoesc | 0:3835ff675f6b | 338 | |
x1dmoesc | 0:3835ff675f6b | 339 | GPIO0.Pin.B1 = bBit; |
x1dmoesc | 0:3835ff675f6b | 340 | |
x1dmoesc | 0:3835ff675f6b | 341 | return setGPIO(PORT0, GPIO0.uiPort); |
x1dmoesc | 0:3835ff675f6b | 342 | } |
x1dmoesc | 0:3835ff675f6b | 343 | |
x1dmoesc | 0:3835ff675f6b | 344 | |
x1dmoesc | 0:3835ff675f6b | 345 | |
x1dmoesc | 0:3835ff675f6b | 346 | //******************************************************************************// |
x1dmoesc | 0:3835ff675f6b | 347 | // |
x1dmoesc | 0:3835ff675f6b | 348 | //******************************************************************************// |
x1dmoesc | 0:3835ff675f6b | 349 | bool PCA9555::setGPIO0_B2(bool bBit){ |
x1dmoesc | 0:3835ff675f6b | 350 | |
x1dmoesc | 0:3835ff675f6b | 351 | GPIO0.Pin.B2 = bBit; |
x1dmoesc | 0:3835ff675f6b | 352 | |
x1dmoesc | 0:3835ff675f6b | 353 | return setGPIO(PORT0, GPIO0.uiPort); |
x1dmoesc | 0:3835ff675f6b | 354 | } |
x1dmoesc | 0:3835ff675f6b | 355 | |
x1dmoesc | 0:3835ff675f6b | 356 | |
x1dmoesc | 0:3835ff675f6b | 357 | |
x1dmoesc | 0:3835ff675f6b | 358 | //******************************************************************************// |
x1dmoesc | 0:3835ff675f6b | 359 | // |
x1dmoesc | 0:3835ff675f6b | 360 | //******************************************************************************// |
x1dmoesc | 0:3835ff675f6b | 361 | bool PCA9555::setGPIO0_B4(bool bBit){ |
x1dmoesc | 0:3835ff675f6b | 362 | |
x1dmoesc | 0:3835ff675f6b | 363 | GPIO0.Pin.B4 = bBit; |
x1dmoesc | 0:3835ff675f6b | 364 | |
x1dmoesc | 0:3835ff675f6b | 365 | return setGPIO(PORT0, GPIO0.uiPort); |
x1dmoesc | 0:3835ff675f6b | 366 | } |
x1dmoesc | 0:3835ff675f6b | 367 | |
x1dmoesc | 0:3835ff675f6b | 368 | |
x1dmoesc | 0:3835ff675f6b | 369 | |
x1dmoesc | 0:3835ff675f6b | 370 | //******************************************************************************// |
x1dmoesc | 0:3835ff675f6b | 371 | // |
x1dmoesc | 0:3835ff675f6b | 372 | //******************************************************************************// |
x1dmoesc | 0:3835ff675f6b | 373 | bool PCA9555::setGPIO0_B5(bool bBit){ |
x1dmoesc | 0:3835ff675f6b | 374 | |
x1dmoesc | 0:3835ff675f6b | 375 | GPIO0.Pin.B5 = bBit; |
x1dmoesc | 0:3835ff675f6b | 376 | |
x1dmoesc | 0:3835ff675f6b | 377 | return setGPIO(PORT0, GPIO0.uiPort); |
x1dmoesc | 0:3835ff675f6b | 378 | } |
x1dmoesc | 0:3835ff675f6b | 379 | |
x1dmoesc | 0:3835ff675f6b | 380 | |
x1dmoesc | 0:3835ff675f6b | 381 | |
x1dmoesc | 0:3835ff675f6b | 382 | //******************************************************************************// |
x1dmoesc | 0:3835ff675f6b | 383 | // |
x1dmoesc | 0:3835ff675f6b | 384 | //******************************************************************************// |
x1dmoesc | 0:3835ff675f6b | 385 | bool PCA9555::setGPIO0_B6(bool bBit){ |
x1dmoesc | 0:3835ff675f6b | 386 | |
x1dmoesc | 0:3835ff675f6b | 387 | GPIO0.Pin.B6 = bBit; |
x1dmoesc | 0:3835ff675f6b | 388 | |
x1dmoesc | 0:3835ff675f6b | 389 | return setGPIO(PORT0, GPIO0.uiPort); |
x1dmoesc | 0:3835ff675f6b | 390 | } |
x1dmoesc | 0:3835ff675f6b | 391 | |
x1dmoesc | 0:3835ff675f6b | 392 | |
x1dmoesc | 0:3835ff675f6b | 393 | |
x1dmoesc | 0:3835ff675f6b | 394 | //******************************************************************************// |
x1dmoesc | 0:3835ff675f6b | 395 | // |
x1dmoesc | 0:3835ff675f6b | 396 | //******************************************************************************// |
x1dmoesc | 0:3835ff675f6b | 397 | bool PCA9555::setGPIO0_B7(bool bBit){ |
x1dmoesc | 0:3835ff675f6b | 398 | |
x1dmoesc | 0:3835ff675f6b | 399 | GPIO0.Pin.B7 = bBit; |
x1dmoesc | 0:3835ff675f6b | 400 | |
x1dmoesc | 0:3835ff675f6b | 401 | return setGPIO(PORT0, GPIO0.uiPort); |
x1dmoesc | 0:3835ff675f6b | 402 | } |
x1dmoesc | 0:3835ff675f6b | 403 | |
x1dmoesc | 0:3835ff675f6b | 404 | |
x1dmoesc | 0:3835ff675f6b | 405 | |
x1dmoesc | 0:3835ff675f6b | 406 | //******************************************************************************// |
x1dmoesc | 0:3835ff675f6b | 407 | // |
x1dmoesc | 0:3835ff675f6b | 408 | //******************************************************************************// |
x1dmoesc | 0:3835ff675f6b | 409 | bool PCA9555::setGPIO1_B0(bool bBit){ |
x1dmoesc | 0:3835ff675f6b | 410 | |
x1dmoesc | 0:3835ff675f6b | 411 | GPIO1.Pin.B0 = bBit; |
x1dmoesc | 0:3835ff675f6b | 412 | |
x1dmoesc | 0:3835ff675f6b | 413 | return setGPIO(PORT1, GPIO1.uiPort); |
x1dmoesc | 0:3835ff675f6b | 414 | } |
x1dmoesc | 0:3835ff675f6b | 415 | |
x1dmoesc | 0:3835ff675f6b | 416 | |
x1dmoesc | 0:3835ff675f6b | 417 | |
x1dmoesc | 0:3835ff675f6b | 418 | |
x1dmoesc | 0:3835ff675f6b | 419 | //******************************************************************************// |
x1dmoesc | 0:3835ff675f6b | 420 | // |
x1dmoesc | 0:3835ff675f6b | 421 | //******************************************************************************// |
x1dmoesc | 0:3835ff675f6b | 422 | bool PCA9555::setGPIO1_B1(bool bBit){ |
x1dmoesc | 0:3835ff675f6b | 423 | |
x1dmoesc | 0:3835ff675f6b | 424 | GPIO1.Pin.B1 = bBit; |
x1dmoesc | 0:3835ff675f6b | 425 | |
x1dmoesc | 0:3835ff675f6b | 426 | return setGPIO(PORT1, GPIO1.uiPort); |
x1dmoesc | 0:3835ff675f6b | 427 | } |
x1dmoesc | 0:3835ff675f6b | 428 | |
x1dmoesc | 0:3835ff675f6b | 429 | |
x1dmoesc | 0:3835ff675f6b | 430 | |
x1dmoesc | 0:3835ff675f6b | 431 | //******************************************************************************// |
x1dmoesc | 0:3835ff675f6b | 432 | // |
x1dmoesc | 0:3835ff675f6b | 433 | //******************************************************************************// |
x1dmoesc | 0:3835ff675f6b | 434 | bool PCA9555::setGPIO1_B2(bool bBit){ |
x1dmoesc | 0:3835ff675f6b | 435 | |
x1dmoesc | 0:3835ff675f6b | 436 | GPIO1.Pin.B2 = bBit; |
x1dmoesc | 0:3835ff675f6b | 437 | |
x1dmoesc | 0:3835ff675f6b | 438 | return setGPIO(PORT1, GPIO1.uiPort); |
x1dmoesc | 0:3835ff675f6b | 439 | } |
x1dmoesc | 0:3835ff675f6b | 440 | |
x1dmoesc | 0:3835ff675f6b | 441 | |
x1dmoesc | 0:3835ff675f6b | 442 | |
x1dmoesc | 0:3835ff675f6b | 443 | //******************************************************************************// |
x1dmoesc | 0:3835ff675f6b | 444 | // |
x1dmoesc | 0:3835ff675f6b | 445 | //******************************************************************************// |
x1dmoesc | 0:3835ff675f6b | 446 | bool PCA9555::setGPIO1_B4(bool bBit){ |
x1dmoesc | 0:3835ff675f6b | 447 | |
x1dmoesc | 0:3835ff675f6b | 448 | GPIO1.Pin.B4 = bBit; |
x1dmoesc | 0:3835ff675f6b | 449 | |
x1dmoesc | 0:3835ff675f6b | 450 | return setGPIO(PORT1, GPIO1.uiPort); |
x1dmoesc | 0:3835ff675f6b | 451 | } |
x1dmoesc | 0:3835ff675f6b | 452 | |
x1dmoesc | 0:3835ff675f6b | 453 | |
x1dmoesc | 0:3835ff675f6b | 454 | |
x1dmoesc | 0:3835ff675f6b | 455 | //******************************************************************************// |
x1dmoesc | 0:3835ff675f6b | 456 | // |
x1dmoesc | 0:3835ff675f6b | 457 | //******************************************************************************// |
x1dmoesc | 0:3835ff675f6b | 458 | bool PCA9555::setGPIO1_B5(bool bBit){ |
x1dmoesc | 0:3835ff675f6b | 459 | |
x1dmoesc | 0:3835ff675f6b | 460 | GPIO1.Pin.B5 = bBit; |
x1dmoesc | 0:3835ff675f6b | 461 | |
x1dmoesc | 0:3835ff675f6b | 462 | return setGPIO(PORT1, GPIO1.uiPort); |
x1dmoesc | 0:3835ff675f6b | 463 | } |
x1dmoesc | 0:3835ff675f6b | 464 | |
x1dmoesc | 0:3835ff675f6b | 465 | |
x1dmoesc | 0:3835ff675f6b | 466 | |
x1dmoesc | 0:3835ff675f6b | 467 | //******************************************************************************// |
x1dmoesc | 0:3835ff675f6b | 468 | // |
x1dmoesc | 0:3835ff675f6b | 469 | //******************************************************************************// |
x1dmoesc | 0:3835ff675f6b | 470 | bool PCA9555::setGPIO1_B6(bool bBit){ |
x1dmoesc | 0:3835ff675f6b | 471 | |
x1dmoesc | 0:3835ff675f6b | 472 | GPIO1.Pin.B6 = bBit; |
x1dmoesc | 0:3835ff675f6b | 473 | |
x1dmoesc | 0:3835ff675f6b | 474 | return setGPIO(PORT1, GPIO1.uiPort); |
x1dmoesc | 0:3835ff675f6b | 475 | } |
x1dmoesc | 0:3835ff675f6b | 476 | |
x1dmoesc | 0:3835ff675f6b | 477 | |
x1dmoesc | 0:3835ff675f6b | 478 | |
x1dmoesc | 0:3835ff675f6b | 479 | //******************************************************************************// |
x1dmoesc | 0:3835ff675f6b | 480 | // |
x1dmoesc | 0:3835ff675f6b | 481 | //******************************************************************************// |
x1dmoesc | 0:3835ff675f6b | 482 | bool PCA9555::setGPIO1_B7(bool bBit){ |
x1dmoesc | 0:3835ff675f6b | 483 | |
x1dmoesc | 0:3835ff675f6b | 484 | GPIO1.Pin.B7 = bBit; |
x1dmoesc | 0:3835ff675f6b | 485 | |
x1dmoesc | 0:3835ff675f6b | 486 | return setGPIO(PORT1, GPIO1.uiPort); |
x1dmoesc | 0:3835ff675f6b | 487 | } |
x1dmoesc | 0:3835ff675f6b | 488 |