@@ -21,10 +21,8 @@ void setup()
21
21
22
22
if (EEPROM.read (EEPROMaddress) != 170 )
23
23
{
24
- display.digitalWriteMCP (3 , HIGH);
25
- display.digitalWriteMCP (4 , HIGH);
26
- display.digitalWriteMCP (5 , HIGH);
27
- display.pinModeMCP (6 , INPUT_PULLUP);
24
+ display.einkOn ();
25
+ display.pinModeInternal (MCP23017_INT_ADDR, display.mcpRegsInt , 6 , INPUT_PULLUP);
28
26
display.display ();
29
27
display.einkOn ();
30
28
delay (100 );
@@ -421,7 +419,7 @@ void writeToScreen()
421
419
double readVCOM ()
422
420
{
423
421
double vcomVolts;
424
- writeReg ( 0x01 , B00111111); // enable all rails
422
+ display. einkOn ();
425
423
writeReg (0x04 , (readReg (0x04 ) | B00100000));
426
424
writeToScreen ();
427
425
writeReg (0x04 , (readReg (0x04 ) | B10000000));
@@ -439,62 +437,57 @@ double readVCOM()
439
437
440
438
void writeVCOMToEEPROM (double v)
441
439
{
442
- int vcom = int (abs (v) * 100 );
443
- int vcomH = (vcom >> 8 ) & 1 ;
444
- int vcomL = vcom & 0xFF ;
445
- // First, we have to power up TPS65186
446
- // Pull TPS65186 WAKEUP pin to High
447
- display.digitalWriteMCP (3 , HIGH);
448
-
449
- // Pull TPS65186 PWR pin to High
450
- display.digitalWriteMCP (4 , HIGH);
451
- delay (10 );
440
+ int vcom = int (abs (v) * 100 );
441
+ int vcomH = (vcom >> 8 ) & 1 ;
442
+ int vcomL = vcom & 0xFF ;
452
443
453
- // Send to TPS65186 first 8 bits of VCOM
454
- writeReg ( 0x03 , vcomL );
444
+ // Set MCP23017 pin where TPS65186 INT pin is connectet to input pull up
445
+ display. pinModeInternal (MCP23017_INT_ADDR, display. mcpRegsInt , 6 , INPUT_PULLUP );
455
446
456
- // Send new value of register to TPS
457
- writeReg (0x04 , vcomH);
458
- delay (1 );
447
+ // First power up TPS65186 so we can communicate with it
448
+ display.einkOn ();
459
449
460
- // Program VCOM value to EEPROM
461
- writeReg (0x04 , vcomH | ( 1 << 6 ) );
450
+ // Send to TPS65186 first 8 bits of VCOM
451
+ writeReg (0x03 , vcomL );
462
452
463
- // Wait until EEPROM has been programmed
464
- delay (1 );
465
- do
466
- {
467
- delay (1 );
468
- } while (display.digitalReadMCP (6 ));
453
+ // Send new value of register to TPS
454
+ writeReg (0x04 , vcomH);
455
+ delay (1 );
469
456
470
- // Clear Interrupt flag by reading INT1 register
471
- readReg ( 0x07 );
457
+ // Program VCOM value to EEPROM
458
+ writeReg ( 0x04 , vcomH | ( 1 << 6 ) );
472
459
473
- // Now, power off whole TPS
474
- // Pull TPS65186 WAKEUP pin to Low
475
- display.digitalWriteMCP (3 , LOW);
460
+ // Wait until EEPROM has been programmed
461
+ delay (1 );
462
+ do
463
+ {
464
+ delay (1 );
465
+ } while (display.digitalReadInternal (MCP23017_INT_ADDR, display.mcpRegsInt , 6 ));
476
466
477
- // Pull TPS65186 PWR pin to Low
478
- display. digitalWriteMCP ( 4 , LOW );
467
+ // Clear Interrupt flag by reading INT1 register
468
+ readReg ( 0x07 );
479
469
480
- // Wait a little bit...
481
- delay ( 1000 );
470
+ // Now, power off whole TPS
471
+ display. einkOff ( );
482
472
483
- // Power up TPS again
484
- display. digitalWriteMCP ( 3 , HIGH );
473
+ // Wait a little bit...
474
+ delay ( 1000 );
485
475
486
- delay (10 );
476
+ // Power up TPS again
477
+ display.einkOn ();
487
478
488
- // Read VCOM valuse from registers
489
- vcomL = readReg (0x03 );
490
- vcomH = readReg (0x04 );
479
+ delay (10 );
491
480
492
- if (vcom != (vcomL | (vcomH << 8 )))
493
- {
494
- Serial.println (" \n VCOM EEPROM PROGRAMMING FAILED!\n " );
495
- }
496
- else
497
- {
498
- Serial.println (" \n VCOM EEPROM PROGRAMMING OK\n " );
499
- }
481
+ // Read VCOM valuse from registers
482
+ vcomL = readReg (0x03 );
483
+ vcomH = readReg (0x04 );
484
+
485
+ if (vcom != (vcomL | (vcomH << 8 )))
486
+ {
487
+ Serial.println (" \n VCOM EEPROM PROGRAMMING FAILED!\n " );
488
+ }
489
+ else
490
+ {
491
+ Serial.println (" \n VCOM EEPROM PROGRAMMING OK\n " );
492
+ }
500
493
}
0 commit comments