From d5b8f83850e94644dcfaa97cb9c735047f0239b6 Mon Sep 17 00:00:00 2001 From: yetanothercarbot <55005345+yetanothercarbot@users.noreply.github.com> Date: Wed, 12 Mar 2025 19:50:24 +1000 Subject: [PATCH] Update T-Watch support (add PMIC support) --- src/dev/esp32/esp32.cpp | 5 ++++ src/dev/esp32/esp32.h | 2 ++ src/dev/esp32/twatch.cpp | 39 ++++++++++++++++++++++++++++++ src/dev/esp32/twatch.h | 20 +++++++++++++++ user_setups/esp32/ttgo-t-watch.ini | 5 ++-- 5 files changed, 69 insertions(+), 2 deletions(-) create mode 100644 src/dev/esp32/twatch.cpp create mode 100644 src/dev/esp32/twatch.h diff --git a/src/dev/esp32/esp32.cpp b/src/dev/esp32/esp32.cpp index a5ec6266..803801b5 100644 --- a/src/dev/esp32/esp32.cpp +++ b/src/dev/esp32/esp32.cpp @@ -451,6 +451,11 @@ long Esp32Device::get_uptime() #elif defined(M5STACK) || defined(M5STACKLGFX) #warning Building for M5Stack core2 #include "dev/esp32/m5stackcore2.h" + +#elif defined(TWATCH) +#warning Building for TTGo T-Watch +#include "dev/esp32/twatch.h" + #else dev::Esp32Device haspDevice; #endif diff --git a/src/dev/esp32/esp32.h b/src/dev/esp32/esp32.h index e39d7bd1..9fca83f2 100644 --- a/src/dev/esp32/esp32.h +++ b/src/dev/esp32/esp32.h @@ -86,6 +86,8 @@ class Esp32Device : public BaseDevice { #elif defined(M5STACK) || defined (M5STACKLGFX) // #warning Building for M5Stack core2 #include "m5stackcore2.h" +#elif defined(TWATCH) +#include "twatch.h" #else using dev::Esp32Device; extern dev::Esp32Device haspDevice; diff --git a/src/dev/esp32/twatch.cpp b/src/dev/esp32/twatch.cpp new file mode 100644 index 00000000..180eb4f3 --- /dev/null +++ b/src/dev/esp32/twatch.cpp @@ -0,0 +1,39 @@ +#include "twatch.h" + +#if defined(TWATCH) + +#include "Wire.h" +#include "dev/esp32/esp32.h" + +/* + * This covers the TWatch 2019 and 2020 PMIC. Only the init function is implemented + * because the TWatch 2020 v1 variant has not just the backlight connected to LDO2, + * but also the power for the display controller. This shouldn't get regulated down + * or be switched off (since the latter would require display being re-inited) so we + * don't let the user switch it off. + * + * This *could* get fixed, by detecting hardware type and changing behaviour, but + * this device isn't particularly common and OpenHASP probably isn't the proper tool + * for this hardware. It's nice to have some support though. +*/ +namespace dev { + void TWatch::init(void) { + Wire.begin(); + + Wire.beginTransmission(53); + Wire.write(0x12); + Wire.write(0b00000110); // Enable LDO2, DC-DC3, disable others + Wire.endTransmission(); + + // Section set LDO2 to 3.3V + uint8_t ldo_ctrl = ~0; + Wire.beginTransmission(53); + Wire.write(0x28); + Wire.write(ldo_ctrl); + Wire.endTransmission(); + } +} + +dev::TWatch haspDevice; + +#endif \ No newline at end of file diff --git a/src/dev/esp32/twatch.h b/src/dev/esp32/twatch.h new file mode 100644 index 00000000..c2746cea --- /dev/null +++ b/src/dev/esp32/twatch.h @@ -0,0 +1,20 @@ +#ifndef HASP_DEVICE_TWATCH +#define HASP_DEVICE_TWATCH + +#if defined(TWATCH) + +#include "esp32.h" + +namespace dev { + class TWatch : public Esp32Device { + public: + void init() override; + }; + +} + +using dev::TWatch; +extern dev::TWatch haspDevice; + +#endif +#endif \ No newline at end of file diff --git a/user_setups/esp32/ttgo-t-watch.ini b/user_setups/esp32/ttgo-t-watch.ini index 91b114ba..75ea24ff 100644 --- a/user_setups/esp32/ttgo-t-watch.ini +++ b/user_setups/esp32/ttgo-t-watch.ini @@ -28,6 +28,7 @@ build_flags = -D TOUCH_RST=-1 -D TOUCH_SDA=23 -D TOUCH_SCL=32 + -D TWATCH=1 ;endregion lib_deps = @@ -40,7 +41,7 @@ extends = ttgo-t-watch, flash_16mb build_flags = ${ttgo-t-watch.build_flags} - -D HASP_MODEL="TTgo T-Watch 2019" + -D HASP_MODEL="TTGo T-Watch 2019" -D INVERT_COLORS=1 [env:ttgo-t-watch-2020] @@ -48,7 +49,7 @@ extends = ttgo-t-watch, flash_16mb build_flags = ${ttgo-t-watch.build_flags} - -D HASP_MODEL="TTgo T-Watch 2020" + -D HASP_MODEL="TTGo T-Watch 2020" -D TFT_ROTATION=0 ;-D TFT_ROTATION=2 -D TOUCH_OFFSET_ROTATION=4 ; 1=swap xy, 2=invert x, 4=inverty \ No newline at end of file