Skip to content

Commit f53d34d

Browse files
committed
Fixed deep sleep current on Inkplate 4 TEMPERA.
1 parent 6af74e2 commit f53d34d

File tree

10 files changed

+71
-69
lines changed

10 files changed

+71
-69
lines changed

examples/Inkplate4TEMPERA/Advanced/Sensors/Inkplate4TEMPERA_Accelerometer_Gyroscope_Read/Inkplate4TEMPERA_Accelerometer_Gyroscope_Read.ino

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,9 @@ void setup()
5959
display.begin(); // Init Inkplate library (you should call this function ONLY ONCE)
6060
display.display(); // Put clear image on display
6161

62+
// Enable the accelerometer & gyroscope.
63+
display.wakePeripheral(INKPLATE_ACCELEROMETER);
64+
6265
// Set text size to be 2x larger than default (5x7px)
6366
display.setTextSize(2);
6467
display.setTextColor(BLACK); // Set the text color to black also

examples/Inkplate4TEMPERA/Advanced/Sensors/Inkplate4TEMPERA_BME688_Read/Inkplate4TEMPERA_BME688_Read.ino

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@ void setup()
3636
display.display(); // Put clear image on display
3737
display.setTextSize(3); // Set text to be 3 times bigger than classic 5x7 px text
3838

39+
// Enable the BME688 sensor.
40+
display.wakePeripheral(INKPLATE_BME688);
41+
3942
display.bme688.begin(); // Init the sensor
4043
}
4144

examples/Inkplate4TEMPERA/Advanced/Sensors/Inkplate4TEMPERA_Fuel_Gauge/Inkplate4TEMPERA_Fuel_Gauge.ino

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,12 @@ void setup()
4646
display.begin(); // Init Inkplate library (you should call this function ONLY ONCE)
4747
display.display(); // Put clear image on display
4848

49+
// Enable the Fuel Gauge.
50+
// NOTE!
51+
// Fuel Gauge is disabled by default. That will impact accuracy of the SoC (State of Charge). You can enable it,
52+
// but it will have an impact on the deep sleep current (it will add additional 30-50uA).
53+
display.wakePeripheral(INKPLATE_FUEL_GAUGE);
54+
4955
display.battery.begin(); // Init the fuel gauge
5056
// Note: You don't actually need to call display.battery.begin() to enable drawing power from the battery
5157
// Inkplate will do this automatically, this is just if you want to init the fuel gauge

examples/Inkplate4TEMPERA/Projects/Inkplate4TEMPERA_Image_Frame_Gesture/Inkplate4TEMPERA_Image_Frame_Gesture.ino

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,9 @@ void setup()
6464
display.setTextColor(BLACK); // Set text color to black
6565
display.setTextSize(5); // Scale text to be five times bigger then original (5x7 px)
6666

67+
// Enable the APDS9960 gesture sensor.
68+
display.wakePeripheral(INKPLATE_APDS9960);
69+
6770
// Init SD card
6871
if (!display.sdCardInit())
6972
{

src/boards/Inkplate4TEMPERA.cpp

Lines changed: 42 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -88,27 +88,20 @@ bool Inkplate::begin(void)
8888
if (_beginDone == 1)
8989
return 0;
9090

91+
// Init Arduino Wire (i2C) library.
9192
Wire.begin();
9293

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);
9599

96100
#ifndef ARDUINO_INKPLATECOLOR
97101
for (uint32_t i = 0; i < 256; ++i)
98102
pinLUT[i] = ((i & B00000011) << 4) | (((i & B00001100) >> 2) << 18) | (((i & B00010000) >> 4) << 23) |
99103
(((i & B11100000) >> 5) << 25);
100104
#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);
112105
pinModeInternal(IO_INT_ADDR, ioRegsInt, VCOM, OUTPUT);
113106
pinModeInternal(IO_INT_ADDR, ioRegsInt, PWRUP, OUTPUT);
114107
pinModeInternal(IO_INT_ADDR, ioRegsInt, WAKEUP, OUTPUT);
@@ -148,28 +141,41 @@ bool Inkplate::begin(void)
148141

149142
// Set the rest of the internal GPIO expander pins
150143
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);
153144

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);
155151
digitalWriteInternal(IO_INT_ADDR, ioRegsInt, BUZZ_EN, HIGH);
156152

153+
// Disable microSD card.
157154
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);
159156

157+
// Disable frontlight at start.
160158
pinModeInternal(IO_INT_ADDR, ioRegsInt, FRONTLIGHT_EN, OUTPUT);
161159
digitalWriteInternal(IO_INT_ADDR, ioRegsInt, FRONTLIGHT_EN, LOW);
162160

161+
// Disable touchscreen.
163162
pinModeInternal(TOUCHSCREEN_IO_EXPANDER, ioRegsEx, TOUCHSCREEN_EN, OUTPUT);
164163
digitalWriteInternal(TOUCHSCREEN_IO_EXPANDER, ioRegsEx, TOUCHSCREEN_EN, HIGH);
165164

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+
166171
// 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++)
168173
{
169174
pinModeInternal(IO_EXT_ADDR, ioRegsEx, i, OUTPUT);
170175
digitalWriteInternal(IO_EXT_ADDR, ioRegsEx, i, LOW);
171176
}
172177

178+
// Allocate the memory for the framebuffer.
173179
DMemoryNew = (uint8_t *)ps_malloc(E_INK_WIDTH * E_INK_HEIGHT / 8);
174180
_partial = (uint8_t *)ps_malloc(E_INK_WIDTH * E_INK_HEIGHT / 8);
175181
_pBuffer = (uint8_t *)ps_malloc(E_INK_WIDTH * E_INK_HEIGHT / 4);
@@ -516,30 +522,6 @@ uint32_t Inkplate::partialUpdate(bool _forced, bool leaveOn)
516522
delayMicroseconds(230);
517523
}
518524

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-
543525
clean(2, 2);
544526
clean(3, 1);
545527
vscan_start();
@@ -567,11 +549,9 @@ void Inkplate::wakePeripheral(uint8_t _peripheral)
567549
if (_peripheral & INKPLATE_ACCELEROMETER)
568550
{
569551
// 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);
575555
}
576556

577557
if (_peripheral & INKPLATE_BME688)
@@ -589,11 +569,11 @@ void Inkplate::wakePeripheral(uint8_t _peripheral)
589569

590570
if (_peripheral & INKPLATE_FUEL_GAUGE)
591571
{
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);
597577
}
598578
}
599579

@@ -611,20 +591,17 @@ void Inkplate::sleepPeripheral(uint8_t _peripheral)
611591
{
612592
if (_peripheral & INKPLATE_ACCELEROMETER)
613593
{
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);
621597
}
622598

623599
if (_peripheral & INKPLATE_BME688)
624600
{
625601
// Put BME in sleep mode
626602
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);
628605
}
629606

630607
if (_peripheral & INKPLATE_APDS9960)
@@ -634,11 +611,11 @@ void Inkplate::sleepPeripheral(uint8_t _peripheral)
634611

635612
if (_peripheral & INKPLATE_FUEL_GAUGE)
636613
{
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();
642619
}
643620
}
644621

src/boards/Inkplate4TEMPERA.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,9 @@
5555
// Buzzer enable pin (pin P1_4 on internal IO expander)
5656
#define BUZZ_EN 12
5757

58+
// Pin for Fuel Gauge GPOUT.
59+
#define FG_GPOUT 15
60+
5861
#define DATA 0x0E8C0030 // D0-D7 = GPIO4 GPIO5 GPIO18 GPIO19 GPIO23 GPIO25 GPIO26 GPIO27
5962

6063
#define CL 0x01 // GPIO0

src/include/Touch.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ bool Touch::tsInit(uint8_t _pwrState)
184184
*/
185185
void Touch::tsShutdown()
186186
{
187-
digitalWriteInternal(TOUCHSCREEN_IO_EXPANDER, TOUCHSCREEN_IO_REGS, TOUCHSCREEN_EN, LOW);
187+
digitalWriteInternal(TOUCHSCREEN_IO_EXPANDER, TOUCHSCREEN_IO_REGS, TOUCHSCREEN_EN, HIGH);
188188
}
189189

190190
/**

src/libs/BQ27441/src/libs/SparkFun_BQ27441_Arduino_Library/src/SparkFunBQ27441.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -471,6 +471,13 @@ uint16_t BQ27441::status(void)
471471
return readControlWord(BQ27441_CONTROL_STATUS);
472472
}
473473

474+
// Added by Soldered Electronics.
475+
void BQ27441::shutdown()
476+
{
477+
readControlWord(BQ27441_CONTROL_SHUTDOWN_ENABLE);
478+
readControlWord(BQ27441_CONTROL_SHUTDOWN);
479+
}
480+
474481
/***************************** Private Functions *****************************/
475482

476483
// Check if the BQ27441-G1A is sealed or not.

src/libs/BQ27441/src/libs/SparkFun_BQ27441_Arduino_Library/src/SparkFunBQ27441.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -373,6 +373,9 @@ class BQ27441
373373
*/
374374
uint8_t readBlockData(uint8_t offset);
375375

376+
// Added by Soldered Electronics. Enable or disable hibernate state to reduce power consumption.
377+
void shutdown();
378+
376379
private:
377380
uint8_t _deviceAddress; // Stores the BQ27441-G1A's I2C address
378381
bool _sealFlag; // Global to identify that IC was previously sealed

src/libs/LSM6DS3/src/libs/SparkFun_LSM6DS3_Arduino_Library/src/SparkFunLSM6DS3.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -417,9 +417,6 @@ status_t LSM6DS3::begin(SensorSettings *pSettingsYouWanted)
417417
// Setup the accelerometer******************************
418418

419419
// First, wake the device
420-
// This was added by Soldered due to the fact that on Inkplate 4TEMPERA peripherals are off by default
421-
settings.accelEnabled = 1;
422-
settings.gyroEnabled = 1;
423420

424421
dataToWrite = 0; // Start Fresh!
425422
if (settings.accelEnabled == 1)

0 commit comments

Comments
 (0)