Refactor Display Init

* It makes more sense to put it in the Display class
* The reset should be 2ms, 10ms is worst case
* Also there was a disable call based on display
  that makes more sense to put in the default
  boot switch statement
pull/242/head
Daniel Ansorregui 2023-12-28 15:55:43 +00:00
parent 2b21e50c2f
commit f2c0c91a61
3 changed files with 16 additions and 10 deletions

View File

@ -15,8 +15,10 @@
// Link: https://github.com/sqfmi/Watchy
#include "Display.h"
#include "config.h"
RTC_DATA_ATTR bool displayFullInit = true;
void WatchyDisplay::busyCallback(const void *) {
gpio_wakeup_enable((gpio_num_t)DISPLAY_BUSY, GPIO_INTR_LOW_LEVEL);
esp_sleep_enable_gpio_wakeup();
@ -26,11 +28,16 @@ void WatchyDisplay::busyCallback(const void *) {
WatchyDisplay::WatchyDisplay() :
GxEPD2_EPD(DISPLAY_CS, DISPLAY_DC, DISPLAY_RES, DISPLAY_BUSY, HIGH, 10000000, WIDTH, HEIGHT, panel, hasColor, hasPartialUpdate, hasFastPartialUpdate)
{
// Watchy default initialization
selectSPI(SPI, SPISettings(20000000, MSBFIRST, SPI_MODE0)); // Set SPI to 20Mhz (default is 4Mhz)
// Setup callback and SPI by default
selectSPI(SPI, SPISettings(20000000, MSBFIRST, SPI_MODE0));
setBusyCallback(busyCallback);
}
void WatchyDisplay::initWatchy() {
// Watchy default initialization
init(0, displayFullInit, 2, true);
}
void WatchyDisplay::clearScreen(uint8_t value)
{
writeScreenBuffer(value);
@ -404,6 +411,7 @@ void WatchyDisplay::_Update_Full()
_transferCommand(0x20);
_endTransfer();
_waitWhileBusy("_Update_Full", full_refresh_time);
displayFullInit = false;
}
void WatchyDisplay::_Update_Part()

View File

@ -35,6 +35,7 @@ class WatchyDisplay : public GxEPD2_EPD
static const uint16_t partial_refresh_time = 500; // ms, e.g. 457282us
// constructor
WatchyDisplay();
void initWatchy();
static void busyCallback(const void *);
// methods (virtual)
// Support for Bitmaps (Sprites) to Controller Buffer and to Screen

View File

@ -11,7 +11,6 @@ RTC_DATA_ATTR bool WIFI_CONFIGURED;
RTC_DATA_ATTR bool BLE_CONFIGURED;
RTC_DATA_ATTR weatherData currentWeather;
RTC_DATA_ATTR int weatherIntervalCounter = -1;
RTC_DATA_ATTR bool displayFullInit = true;
RTC_DATA_ATTR long gmtOffset = 0;
RTC_DATA_ATTR bool alreadyInMenu = true;
RTC_DATA_ATTR tmElements_t bootTime;
@ -22,9 +21,8 @@ void Watchy::init(String datetime) {
Wire.begin(SDA, SCL); // init i2c
RTC.init();
// Init the display here for all cases, if unused, it will do nothing
display.init(0, displayFullInit, 10,
true); // 10ms by spec, and fast pulldown reset
// Init the display since is almost sure we will use it
display.epd2.initWatchy();
switch (wakeup_reason) {
case ESP_SLEEP_WAKEUP_EXT0: // RTC Alarm
@ -61,15 +59,14 @@ void Watchy::init(String datetime) {
RTC.read(bootTime);
showWatchFace(false); // full update on reset
vibMotor(75, 4);
// For some reason, seems to be enabled on first boot
esp_sleep_disable_wakeup_source(ESP_SLEEP_WAKEUP_ALL);
break;
}
deepSleep();
}
void Watchy::deepSleep() {
display.hibernate();
if (displayFullInit) // For some reason, seems to be enabled on first boot
esp_sleep_disable_wakeup_source(ESP_SLEEP_WAKEUP_ALL);
displayFullInit = false; // Notify not to init it again
RTC.clearAlarm(); // resets the alarm flag in the RTC
// Set GPIOs 0-39 to input to avoid power leaking out