@@ -88,27 +88,20 @@ bool Inkplate::begin(void)
88
88
if (_beginDone == 1 )
89
89
return 0 ;
90
90
91
+ // Init Arduino Wire (i2C) library.
91
92
Wire.begin ();
92
93
93
- // Turn off the buzzer so it doesn't beep
94
- digitalWriteInternal (IO_INT_ADDR, ioRegsInt, BUZZ_EN, HIGH);
94
+ // Init IO expander.
95
+ memset (ioRegsInt, 0 , 22 );
96
+ memset (ioRegsEx, 0 , 22 );
97
+ ioBegin (IO_INT_ADDR, ioRegsInt);
98
+ ioBegin (IO_EXT_ADDR, ioRegsEx);
95
99
96
100
#ifndef ARDUINO_INKPLATECOLOR
97
101
for (uint32_t i = 0 ; i < 256 ; ++i)
98
102
pinLUT[i] = ((i & B00000011) << 4 ) | (((i & B00001100) >> 2 ) << 18 ) | (((i & B00010000) >> 4 ) << 23 ) |
99
103
(((i & B11100000) >> 5 ) << 25 );
100
104
#endif
101
-
102
- #ifdef ARDUINO_ESP32_DEV
103
- digitalWriteInternal (IO_INT_ADDR, ioRegsInt, 9 , HIGH);
104
- #else
105
- digitalWriteInternal (IO_INT_ADDR, ioRegsInt, 9 , LOW);
106
- #endif
107
-
108
- memset (ioRegsInt, 0 , 22 );
109
- memset (ioRegsEx, 0 , 22 );
110
- ioBegin (IO_INT_ADDR, ioRegsInt);
111
- ioBegin (IO_EXT_ADDR, ioRegsEx);
112
105
pinModeInternal (IO_INT_ADDR, ioRegsInt, VCOM, OUTPUT);
113
106
pinModeInternal (IO_INT_ADDR, ioRegsInt, PWRUP, OUTPUT);
114
107
pinModeInternal (IO_INT_ADDR, ioRegsInt, WAKEUP, OUTPUT);
@@ -148,28 +141,41 @@ bool Inkplate::begin(void)
148
141
149
142
// Set the rest of the internal GPIO expander pins
150
143
pinModeInternal (IO_INT_ADDR, ioRegsInt, INT_APDS, INPUT_PULLUP); // Gesture interrupt pin
151
- pinModeInternal (IO_INT_ADDR, ioRegsInt, INT2_LSM, INPUT_PULLUP); // LSM interrupt pins
152
- pinModeInternal (IO_INT_ADDR, ioRegsInt, INT1_LSM, INPUT_PULLUP);
153
144
154
- pinModeInternal (IO_INT_ADDR, ioRegsInt, BUZZ_EN, OUTPUT); // Buzzer enable
145
+ // LSM interrupt pins. Pins must be set as inputs, since the default state of the INT pin on LSM is push-pull.
146
+ pinModeInternal (IO_INT_ADDR, ioRegsInt, INT2_LSM, INPUT);
147
+ pinModeInternal (IO_INT_ADDR, ioRegsInt, INT1_LSM, INPUT);
148
+
149
+ // Turn off the buzzer so it doesn't beep
150
+ pinModeInternal (IO_INT_ADDR, ioRegsInt, BUZZ_EN, OUTPUT);
155
151
digitalWriteInternal (IO_INT_ADDR, ioRegsInt, BUZZ_EN, HIGH);
156
152
153
+ // Disable microSD card.
157
154
pinModeInternal (IO_INT_ADDR, ioRegsInt, SD_PMOS_PIN, OUTPUT);
158
- digitalWriteInternal (IO_INT_ADDR, ioRegsInt, SD_PMOS_PIN, LOW );
155
+ digitalWriteInternal (IO_INT_ADDR, ioRegsInt, SD_PMOS_PIN, HIGH );
159
156
157
+ // Disable frontlight at start.
160
158
pinModeInternal (IO_INT_ADDR, ioRegsInt, FRONTLIGHT_EN, OUTPUT);
161
159
digitalWriteInternal (IO_INT_ADDR, ioRegsInt, FRONTLIGHT_EN, LOW);
162
160
161
+ // Disable touchscreen.
163
162
pinModeInternal (TOUCHSCREEN_IO_EXPANDER, ioRegsEx, TOUCHSCREEN_EN, OUTPUT);
164
163
digitalWriteInternal (TOUCHSCREEN_IO_EXPANDER, ioRegsEx, TOUCHSCREEN_EN, HIGH);
165
164
165
+ // Set Fuel Gauge GPOUT to input with pull up enabled.
166
+ pinModeInternal (IO_INT_ADDR, ioRegsInt, FG_GPOUT, INPUT_PULLUP);
167
+
168
+ // Disable SPI pins on microSD card.
169
+ sdCardSleep ();
170
+
166
171
// Set the rest of the IO Expander pins to low to reduce power in deep sleep.
167
- for (int i = 2 ; i < 15 ; i++)
172
+ for (int i = 2 ; i < 16 ; i++)
168
173
{
169
174
pinModeInternal (IO_EXT_ADDR, ioRegsEx, i, OUTPUT);
170
175
digitalWriteInternal (IO_EXT_ADDR, ioRegsEx, i, LOW);
171
176
}
172
177
178
+ // Allocate the memory for the framebuffer.
173
179
DMemoryNew = (uint8_t *)ps_malloc (E_INK_WIDTH * E_INK_HEIGHT / 8 );
174
180
_partial = (uint8_t *)ps_malloc (E_INK_WIDTH * E_INK_HEIGHT / 8 );
175
181
_pBuffer = (uint8_t *)ps_malloc (E_INK_WIDTH * E_INK_HEIGHT / 4 );
@@ -516,30 +522,6 @@ uint32_t Inkplate::partialUpdate(bool _forced, bool leaveOn)
516
522
delayMicroseconds (230 );
517
523
}
518
524
519
- // for (int k = 0; k < 60; ++k)
520
- // {
521
- // uint8_t _send = B11111111;
522
- // vscan_start();
523
-
524
- // writeRow(_send);
525
- // for (int i = 0; i < E_INK_HEIGHT / 2; i++)
526
- // {
527
- // hscan_start(pinLUT[_send]);
528
- // delayMicroseconds(1);
529
- // vscan_end();
530
- // }
531
-
532
- // _send = B01010101;
533
-
534
- // writeRow(_send);
535
- // for (int i = 0; i < E_INK_HEIGHT / 2; i++)
536
- // {
537
- // hscan_start(pinLUT[_send]);
538
- // delayMicroseconds(1);
539
- // vscan_end();
540
- // }
541
- // }
542
-
543
525
clean (2 , 2 );
544
526
clean (3 , 1 );
545
527
vscan_start ();
@@ -567,11 +549,9 @@ void Inkplate::wakePeripheral(uint8_t _peripheral)
567
549
if (_peripheral & INKPLATE_ACCELEROMETER)
568
550
{
569
551
// Wake accelerometer
570
- uint8_t accControlReg;
571
- lsm6ds3.readRegister (&accControlReg, 0x13 );
572
- lsm6ds3.writeRegister (0x13 , accControlReg & 0xBF );
573
- delay (2 );
574
- lsm6ds3.beginCore ();
552
+ lsm6ds3.settings .gyroEnabled = 1 ;
553
+ lsm6ds3.settings .accelEnabled = 1 ;
554
+ lsm6ds3.begin (&lsm6ds3.settings );
575
555
}
576
556
577
557
if (_peripheral & INKPLATE_BME688)
@@ -589,11 +569,11 @@ void Inkplate::wakePeripheral(uint8_t _peripheral)
589
569
590
570
if (_peripheral & INKPLATE_FUEL_GAUGE)
591
571
{
592
- uint8_t fuelGaugeControlReg1 = battery. readBlockData ( 0x3A );
593
- uint8_t fuelGaugeControlReg2 = battery. readBlockData ( 0x3B );
594
- fuelGaugeControlReg2 &= 0xCF ;
595
- uint16_t fuelGaugeControlRegToWrite = (fuelGaugeControlReg1 << 8 ) | fuelGaugeControlReg2;
596
- battery. writeOpConfig (fuelGaugeControlRegToWrite );
572
+ // To wake up fuel gauge, just create rising edge signal on GPOUT pin.
573
+ pinModeInternal (IO_INT_ADDR, ioRegsInt, FG_GPOUT, INPUT_PULLUP );
574
+
575
+ // Wait a little bit.
576
+ delayMicroseconds ( 250 );
597
577
}
598
578
}
599
579
@@ -611,20 +591,17 @@ void Inkplate::sleepPeripheral(uint8_t _peripheral)
611
591
{
612
592
if (_peripheral & INKPLATE_ACCELEROMETER)
613
593
{
614
- uint8_t accControlReg;
615
- // First, put the gyro in sleep mode
616
- lsm6ds3.readRegister (&accControlReg, 0x16 );
617
- lsm6ds3.writeRegister (0x16 , accControlReg | 0x80 );
618
- // Then, the accelerometer
619
- lsm6ds3.readRegister (&accControlReg, 0x15 );
620
- lsm6ds3.writeRegister (0x15 , accControlReg | 0x10 );
594
+ lsm6ds3.settings .gyroEnabled = 0 ;
595
+ lsm6ds3.settings .accelEnabled = 0 ;
596
+ lsm6ds3.begin (&lsm6ds3.settings );
621
597
}
622
598
623
599
if (_peripheral & INKPLATE_BME688)
624
600
{
625
601
// Put BME in sleep mode
626
602
uint8_t bmeControlReg = bme688.readByte (BME_CONTROL_ADDR);
627
- bme688.putData (BME_CONTROL_ADDR, bmeControlReg & 0xFC );
603
+ bmeControlReg &= ~(0b00000011 );
604
+ bme688.putData (BME_CONTROL_ADDR, bmeControlReg);
628
605
}
629
606
630
607
if (_peripheral & INKPLATE_APDS9960)
@@ -634,11 +611,11 @@ void Inkplate::sleepPeripheral(uint8_t _peripheral)
634
611
635
612
if (_peripheral & INKPLATE_FUEL_GAUGE)
636
613
{
637
- uint8_t fuelGaugeControlReg1 = battery. readBlockData ( 0x3A );
638
- uint8_t fuelGaugeControlReg2 = battery. readBlockData ( 0x3B );
639
- fuelGaugeControlReg2 |= 0x20 ;
640
- uint16_t fuelGaugeControlRegToWrite = (fuelGaugeControlReg1 << 8 ) | fuelGaugeControlReg2;
641
- battery.writeOpConfig (fuelGaugeControlRegToWrite );
614
+ // First, set the GPOUT pin of the Fuel Gauge to pull down.
615
+ pinModeInternal (IO_INT_ADDR, ioRegsInt, FG_GPOUT, INPUT_PULLDOWN );
616
+
617
+ // Issue a shutdown command.
618
+ battery.shutdown ( );
642
619
}
643
620
}
644
621
0 commit comments