|
| 1 | +// |
| 2 | +// Example to show how to turn off the power |
| 3 | +// using the I2C battery control chip |
| 4 | +// of the LilyGo T5 S3 E-Paper 4.7" Pro |
| 5 | +// |
| 6 | +#include <FastEPD.h> |
| 7 | +#include <Wire.h> |
| 8 | +FASTEPD epaper; |
| 9 | + |
| 10 | +#define PWRMGMT_ADDR 0x6b |
| 11 | +#define REG09 9 |
| 12 | +#define SDA_PIN 6 |
| 13 | +#define SCL_PIN 5 |
| 14 | +// |
| 15 | +// Shut down the battery power of the LilyGo T5 S3 Pro |
| 16 | +// This is the only way to turn off the power and will only |
| 17 | +// work when the device is running from the battery. If the |
| 18 | +// USB is connected, this will have no effect |
| 19 | +// |
| 20 | +void T5Pro_Shutdown(void) |
| 21 | +{ |
| 22 | +uint8_t u8; |
| 23 | + |
| 24 | + Wire.end(); |
| 25 | + Wire.begin(SDA_PIN, SCL_PIN); // Initialize I2C bus of the power management chip |
| 26 | + Wire.beginTransmission(PWRMGMT_ADDR); |
| 27 | + Wire.write(REG09); // read the old value of register 9 first |
| 28 | + Wire.endTransmission(); |
| 29 | + Wire.requestFrom(PWRMGMT_ADDR, 1); |
| 30 | + u8 = Wire.read(); // read the current register contents |
| 31 | + Wire.beginTransmission(PWRMGMT_ADDR); |
| 32 | + u8 |= 0x20; // set the BATFET_DIS (disable the battery FET) bit |
| 33 | + Wire.write(REG09); // write back the new value |
| 34 | + Wire.write(u8); |
| 35 | + Wire.endTransmission(); // won't even get here :) |
| 36 | +} /* T5Pro_Shutdown() */ |
| 37 | + |
| 38 | +void setup() |
| 39 | +{ |
| 40 | + epaper.initPanel(BB_PANEL_LILYGO_T5PRO); |
| 41 | + epaper.clearWhite(); |
| 42 | + epaper.setFont(FONT_12x16); |
| 43 | + epaper.println("Power off in 5 seconds..."); |
| 44 | + epaper.partialUpdate(false); |
| 45 | + for (int i=10; i>=0; i--) { |
| 46 | + epaper.printf("Counting...%d\n", i); |
| 47 | + epaper.partialUpdate(false); |
| 48 | + delay(500); |
| 49 | + if (i == 5) { |
| 50 | + T5Pro_Shutdown(); |
| 51 | + } |
| 52 | + } |
| 53 | +} |
| 54 | + |
| 55 | +void loop() |
| 56 | +{ |
| 57 | +} |
| 58 | + |
0 commit comments