@@ -56,8 +56,10 @@ void LiquidCrystal_PCF8574::init(uint8_t i2cAddr, uint8_t rs, uint8_t rw, uint8_
56
56
} // init()
57
57
58
58
59
- void LiquidCrystal_PCF8574::begin (uint8_t cols, uint8_t lines)
59
+ void LiquidCrystal_PCF8574::begin (uint8_t cols, uint8_t lines, TwoWire &wirePort )
60
60
{
61
+ _i2cPort = &wirePort; // Grab which port the user wants us to use
62
+
61
63
_cols = min (cols, (uint8_t )80 );
62
64
_lines = min (lines, (uint8_t )4 );
63
65
@@ -73,7 +75,7 @@ void LiquidCrystal_PCF8574::begin(uint8_t cols, uint8_t lines)
73
75
}
74
76
75
77
// initializing the display
76
- Wire. begin ();
78
+ _i2cPort-> begin ();
77
79
_write2Wire (0x00 , LOW, false );
78
80
delayMicroseconds (50000 );
79
81
@@ -245,7 +247,7 @@ void LiquidCrystal_PCF8574::setBacklight(uint8_t brightness)
245
247
246
248
// Allows us to fill the first 8 CGRAM locations
247
249
// with custom characters
248
- void LiquidCrystal_PCF8574::createChar (uint8_t location, byte charmap[])
250
+ void LiquidCrystal_PCF8574::createChar (uint8_t location, uint8_t charmap[])
249
251
{
250
252
location &= 0x7 ; // we only have 8 locations 0-7
251
253
// Set CGRAM address
@@ -259,12 +261,12 @@ void LiquidCrystal_PCF8574::createChar(uint8_t location, byte charmap[])
259
261
#ifdef __AVR__
260
262
// Allows us to fill the first 8 CGRAM locations
261
263
// with custom characters stored in PROGMEM
262
- void LiquidCrystal_PCF8574::createChar_P (uint8_t location, const byte *charmap) {
264
+ void LiquidCrystal_PCF8574::createChar_P (uint8_t location, const uint8_t *charmap) {
263
265
PGM_P p = reinterpret_cast <PGM_P>(charmap);
264
266
location &= 0x7 ; // we only have 8 locations 0-7
265
267
_send (0x40 | (location << 3 ));
266
268
for (int i = 0 ; i < 8 ; i++) {
267
- byte c = pgm_read_byte (p++);
269
+ uint8_t c = pgm_read_byte (p++);
268
270
write (c);
269
271
}
270
272
} // createChar_P()
@@ -285,12 +287,12 @@ void LiquidCrystal_PCF8574::_send(uint8_t value, bool isData)
285
287
// An I2C transmission has a significant overhead of ~10+1 I2C clock
286
288
// cycles. We consequently only perform it only once per _send().
287
289
288
- Wire. beginTransmission (_i2cAddr);
290
+ _i2cPort-> beginTransmission (_i2cAddr);
289
291
// write high 4 bits
290
292
_writeNibble ((value >> 4 & 0x0F ), isData);
291
293
// write low 4 bits
292
294
_writeNibble ((value & 0x0F ), isData);
293
- Wire. endTransmission ();
295
+ _i2cPort-> endTransmission ();
294
296
} // _send()
295
297
296
298
@@ -317,19 +319,19 @@ void LiquidCrystal_PCF8574::_writeNibble(uint8_t halfByte, bool isData)
317
319
// when the I2C bus is operated beyond the chip's spec in fast mode
318
320
// at 400 kHz.
319
321
320
- Wire. write (data | _enable_mask);
322
+ _i2cPort-> write (data | _enable_mask);
321
323
// delayMicroseconds(1); // enable pulse must be >450ns
322
- Wire. write (data);
324
+ _i2cPort-> write (data);
323
325
// delayMicroseconds(37); // commands need > 37us to settle
324
326
} // _writeNibble
325
327
326
328
327
329
// write a nibble / halfByte with handshake
328
330
void LiquidCrystal_PCF8574::_sendNibble (uint8_t halfByte, bool isData)
329
331
{
330
- Wire. beginTransmission (_i2cAddr);
332
+ _i2cPort-> beginTransmission (_i2cAddr);
331
333
_writeNibble (halfByte, isData);
332
- Wire. endTransmission ();
334
+ _i2cPort-> endTransmission ();
333
335
} // _sendNibble
334
336
335
337
@@ -344,9 +346,9 @@ void LiquidCrystal_PCF8574::_write2Wire(uint8_t data, bool isData, bool enable)
344
346
if (_backlight > 0 )
345
347
data |= _backlight_mask;
346
348
347
- Wire. beginTransmission (_i2cAddr);
348
- Wire. write (data);
349
- Wire. endTransmission ();
349
+ _i2cPort-> beginTransmission (_i2cAddr);
350
+ _i2cPort-> write (data);
351
+ _i2cPort-> endTransmission ();
350
352
} // write2Wire
351
353
352
354
// The End.
0 commit comments