diff --git a/lib/TFT_eSPI/User_Setup_Select.h b/lib/TFT_eSPI/User_Setup_Select.h index 2e5c8b96..ebff0211 100644 --- a/lib/TFT_eSPI/User_Setup_Select.h +++ b/lib/TFT_eSPI/User_Setup_Select.h @@ -149,6 +149,8 @@ #ifdef LILYGO_S3_T_EMBED #include // For the LilyGo T-Embed S3 based ESP32S3 with ST7789 170 x 320 TFT #endif +#ifdef M5_STICKS3 +#include // M5Stack StickS3 (ESP32-S3-PICO) with ST7789P3 135 x 240 TFT #ifdef M5_CARDPUTER_ADV #include // M5Stack Cardputer Adv (ESP32-S3) with ST7789V2 240 x 135 TFT #endif diff --git a/lib/TFT_eSPI/User_Setups/Setup216_M5_StickS3.h b/lib/TFT_eSPI/User_Setups/Setup216_M5_StickS3.h new file mode 100644 index 00000000..bdd9926b --- /dev/null +++ b/lib/TFT_eSPI/User_Setups/Setup216_M5_StickS3.h @@ -0,0 +1,31 @@ +// ST7789P3 135 x 240 display - M5Stack StickS3 (ESP32-S3-PICO) +#define USER_SETUP_ID 216 + +#define ST7789_DRIVER + +#define TFT_WIDTH 135 +#define TFT_HEIGHT 240 + +#define TFT_INVERSION_ON +#define TFT_BACKLIGHT_ON 1 + +#define TFT_MISO -1 +#define TFT_MOSI 39 +#define TFT_SCLK 40 +#define TFT_CS 41 +#define TFT_DC 45 +#define TFT_RST 21 +#define TFT_BL 38 + +#define LOAD_GLCD +#define LOAD_FONT2 +#define LOAD_FONT4 +#define LOAD_FONT6 +#define LOAD_FONT7 +#define LOAD_FONT8 +#define LOAD_GFXFF + +#define SMOOTH_FONT + +#define SPI_FREQUENCY 40000000 +#define SPI_READ_FREQUENCY 20000000 diff --git a/platformio.ini b/platformio.ini index 6fff6673..40395b0d 100644 --- a/platformio.ini +++ b/platformio.ini @@ -98,7 +98,7 @@ framework = arduino extra_scripts = pre:auto_firmware_version.py post:post_build_merge.py -monitor_filters = +monitor_filters = esp32_exception_decoder time log2file @@ -107,17 +107,17 @@ monitor_speed = 115200 upload_speed = 1500000 # 2 x 4.5MB app, 6.875MB SPIFFS board_build.partitions = huge_app.csv -build_flags = +build_flags = -D M5STICK_CPLUS=1 ;-D DEBUG_MINING=1 -lib_deps = +lib_deps = https://github.com/takkaO/OpenFontRender#v1.2 bblanchon/ArduinoJson@^6.21.5 https://github.com/tzapu/WiFiManager.git#v2.0.17 mathertel/OneButton@^2.5.0 arduino-libraries/NTPClient@^3.2.1 m5stack/M5StickCPlus@^0.1.0 -lib_ignore = +lib_ignore = TFT_eSPI SD SD_MMC @@ -126,6 +126,38 @@ lib_ignore = ;-------------------------------------------------------------------- +[env:M5-StickS3] +platform = espressif32@6.6.0 +board = esp32-s3-devkitc-1 +framework = arduino +extra_scripts = + pre:auto_firmware_version.py + post:post_build_merge.py +monitor_filters = + esp32_exception_decoder + time + log2file +board_build.arduino.memory_type = qio_opi +monitor_speed = 115200 +upload_speed = 921600 +board_build.partitions = huge_app.csv +build_flags = + -D BOARD_HAS_PSRAM + -D ARDUINO_USB_MODE=1 + -D ARDUINO_USB_CDC_ON_BOOT=1 + -D M5_STICKS3=1 + ;-D DEBUG_MINING=1 +lib_deps = + https://github.com/takkaO/OpenFontRender#v1.2 + bblanchon/ArduinoJson@^6.21.5 + https://github.com/tzapu/WiFiManager.git#v2.0.17 + mathertel/oneButton@^2.6.1 + arduino-libraries/NTPClient@^3.2.1 +lib_ignore = + HANSOLOminerv2 + +;-------------------------------------------------------------------- + [env:wt32-sc01] platform = espressif32@6.6.0 board = esp-wrover-kit diff --git a/src/drivers/devices/device.h b/src/drivers/devices/device.h index 29073a9c..cb6bb540 100644 --- a/src/drivers/devices/device.h +++ b/src/drivers/devices/device.h @@ -23,6 +23,8 @@ #include "lilygoS3Dongle.h" #elif defined(LILYGO_S3_T_EMBED) #include "lilygoS3TEmbed.h" +#elif defined(M5_STICKS3) +#include "m5StickS3.h" #elif defined(M5_CARDPUTER_ADV) #include "m5CardputerAdv.h" #elif defined(ESP32_2432S028R) diff --git a/src/drivers/devices/m5StickS3.h b/src/drivers/devices/m5StickS3.h new file mode 100644 index 00000000..6bf86be3 --- /dev/null +++ b/src/drivers/devices/m5StickS3.h @@ -0,0 +1,9 @@ +#ifndef _M5_STICKS3_H +#define _M5_STICKS3_H + +#define PIN_BUTTON_1 11 +#define PIN_BUTTON_2 12 + +#define V1_DISPLAY + +#endif diff --git a/src/drivers/displays/display.cpp b/src/drivers/displays/display.cpp index 1b1b17fe..4277b490 100644 --- a/src/drivers/displays/display.cpp +++ b/src/drivers/displays/display.cpp @@ -44,7 +44,9 @@ DisplayDriver *currentDisplayDriver = &esp32_2432S028RDriver; DisplayDriver *currentDisplayDriver = &t_qtDisplayDriver; #endif -#ifdef V1_DISPLAY +#if defined(M5_STICKS3) +DisplayDriver *currentDisplayDriver = &m5StickS3Driver; +#elif defined(V1_DISPLAY) DisplayDriver *currentDisplayDriver = &tDisplayV1Driver; #endif @@ -69,6 +71,7 @@ DisplayDriver *currentDisplayDriver = &ssd1306DisplayDriver; #endif + // Initialize the display void initDisplay() { diff --git a/src/drivers/displays/displayDriver.h b/src/drivers/displays/displayDriver.h index 0159c404..fb0897d4 100644 --- a/src/drivers/displays/displayDriver.h +++ b/src/drivers/displays/displayDriver.h @@ -43,6 +43,7 @@ extern DisplayDriver m5stickCDriver; extern DisplayDriver m5stickCPlusDriver; extern DisplayDriver t_hmiDisplayDriver; extern DisplayDriver sp_kcDisplayDriver; +extern DisplayDriver m5StickS3Driver; extern DisplayDriver ssd1306DisplayDriver; #define SCREENS_ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0])) diff --git a/src/drivers/displays/m5StickS3Driver.cpp b/src/drivers/displays/m5StickS3Driver.cpp new file mode 100644 index 00000000..599794bd --- /dev/null +++ b/src/drivers/displays/m5StickS3Driver.cpp @@ -0,0 +1,77 @@ +#include "displayDriver.h" + +#ifdef M5_STICKS3 + +#include +#include + +// Reusing functions from tDisplayV1Driver.cpp, only the display +// initialization differs + +extern void tDisplay_Init(void); +extern void tDisplay_AlternateScreenState(void); +extern void tDisplay_AlternateRotation(void); +extern void tDisplay_LoadingScreen(void); +extern void tDisplay_SetupScreen(void); +extern void tDisplay_AnimateCurrentScreen(unsigned long); +extern void tDisplay_DoLedStuff(unsigned long); +extern void tDisplay_MinerScreen(unsigned long); +extern void tDisplay_ClockScreen(unsigned long); +extern void tDisplay_GlobalHashScreen(unsigned long); +extern void tDisplay_BTCprice(unsigned long); + +// M5PM1 PMIC (I2C 0x6E, SDA=47, SCL=48) gates the LCD power rail via PM1_G2. +// Without this sequence the ST7789P3 has no VCC and the screen stays black + +static void m5pm1_rmw(uint8_t reg, uint8_t setBits, uint8_t clearBits) +{ + const uint8_t addr = 0x6E; + Wire.beginTransmission(addr); + Wire.write(reg); + if (Wire.endTransmission(false) != 0) return; + if (Wire.requestFrom(addr, (uint8_t)1) != 1) return; + uint8_t v = Wire.read(); + v = (v & ~clearBits) | setBits; + Wire.beginTransmission(addr); + Wire.write(reg); + Wire.write(v); + Wire.endTransmission(); +} + +static void m5StickS3_enableLcdPower(void) +{ + Wire.begin(47, 48); + const uint8_t G2 = 1 << 2; + m5pm1_rmw(0x16, 0, G2); // FUNC0: PM1_G2 -> GPIO function + m5pm1_rmw(0x10, G2, 0); // MODE: PM1_G2 -> output + m5pm1_rmw(0x13, 0, G2); // DRV: PM1_G2 -> push-pull + m5pm1_rmw(0x11, G2, 0); // OUT: PM1_G2 -> high (LCD power on) +} + +static void m5StickS3_Init(void) +{ + m5StickS3_enableLcdPower(); + tDisplay_Init(); +} + +static CyclicScreenFunction m5StickS3CyclicScreens[] = { + tDisplay_MinerScreen, + tDisplay_ClockScreen, + tDisplay_GlobalHashScreen, + tDisplay_BTCprice}; + +DisplayDriver m5StickS3Driver = { + m5StickS3_Init, + tDisplay_AlternateScreenState, + tDisplay_AlternateRotation, + tDisplay_LoadingScreen, + tDisplay_SetupScreen, + m5StickS3CyclicScreens, + tDisplay_AnimateCurrentScreen, + tDisplay_DoLedStuff, + SCREENS_ARRAY_SIZE(m5StickS3CyclicScreens), + 0, + 240, + 135}; + +#endif