From 3f331285fe8cfa9a2640677ba1f8e11e6dea1a12 Mon Sep 17 00:00:00 2001 From: Tyler Nehowig Date: Thu, 20 Jun 2024 13:40:26 -0500 Subject: [PATCH] Add driver support for M5Stick-C Plus device. --- platformio.ini | 32 +++ src/drivers/devices/M5Stick-CPlus.h | 10 + src/drivers/devices/device.h | 2 + src/drivers/displays/display.cpp | 4 + src/drivers/displays/displayDriver.h | 1 + src/drivers/displays/m5stickCPlusDriver.cpp | 278 ++++++++++++++++++++ 6 files changed, 327 insertions(+) create mode 100644 src/drivers/devices/M5Stick-CPlus.h create mode 100644 src/drivers/displays/m5stickCPlusDriver.cpp diff --git a/platformio.ini b/platformio.ini index 66ea812d..972ec170 100644 --- a/platformio.ini +++ b/platformio.ini @@ -44,6 +44,38 @@ lib_ignore = ;-------------------------------------------------------------------- +[env:M5Stick-CPlus] +platform = espressif32@6.6.0 +board = m5stick-c +framework = arduino +monitor_filters = + esp32_exception_decoder + time + log2file +;board_build.arduino.memory_type = qio_opi +monitor_speed = 115200 +upload_speed = 1500000 +# 2 x 4.5MB app, 6.875MB SPIFFS +board_build.partitions = huge_app.csv +build_flags = + -D M5STICK_CPLUS=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.5.0 + arduino-libraries/NTPClient@^3.2.1 + m5stack/M5StickCPlus@^0.1.0 +lib_ignore = + TFT_eSPI + SD + SD_MMC + rm67162 + HANSOLOminerv2 + +;-------------------------------------------------------------------- + [env:wt32-sc01] platform = espressif32@6.6.0 board = esp-wrover-kit diff --git a/src/drivers/devices/M5Stick-CPlus.h b/src/drivers/devices/M5Stick-CPlus.h new file mode 100644 index 00000000..a396d237 --- /dev/null +++ b/src/drivers/devices/M5Stick-CPlus.h @@ -0,0 +1,10 @@ +#ifndef _M5_STICK_CPLUS_H +#define _M5_STICK_CPLUS_H + +#define PIN_BUTTON_1 37 +#define PIN_BUTTON_2 39 +#define LED_PIN 10 + +#define M5STICKCPLUS_DISPLAY + +#endif \ No newline at end of file diff --git a/src/drivers/devices/device.h b/src/drivers/devices/device.h index 5f82fef5..87f34aaa 100644 --- a/src/drivers/devices/device.h +++ b/src/drivers/devices/device.h @@ -5,6 +5,8 @@ #include "nerdMinerV2.h" #elif defined(M5STICK_C) #include "M5Stick-C.h" +#elif defined(M5STICK_CPLUS) +#include "M5Stick-CPlus.h" #elif defined(DEVKITV1) #include "esp32DevKit.h" #elif defined(TDISPLAY) diff --git a/src/drivers/displays/display.cpp b/src/drivers/displays/display.cpp index d8118ec0..04d3ad48 100644 --- a/src/drivers/displays/display.cpp +++ b/src/drivers/displays/display.cpp @@ -48,6 +48,10 @@ DisplayDriver *currentDisplayDriver = &tDisplayV1Driver; DisplayDriver *currentDisplayDriver = &m5stickCDriver; #endif +#ifdef M5STICKCPLUS_DISPLAY +DisplayDriver *currentDisplayDriver = &m5stickCPlusDriver; +#endif + #ifdef T_HMI_DISPLAY DisplayDriver *currentDisplayDriver = &t_hmiDisplayDriver; #endif diff --git a/src/drivers/displays/displayDriver.h b/src/drivers/displays/displayDriver.h index c2dff756..cdc8ab68 100644 --- a/src/drivers/displays/displayDriver.h +++ b/src/drivers/displays/displayDriver.h @@ -39,6 +39,7 @@ extern DisplayDriver esp32_2432S028RDriver; extern DisplayDriver t_qtDisplayDriver; extern DisplayDriver tDisplayV1Driver; extern DisplayDriver m5stickCDriver; +extern DisplayDriver m5stickCPlusDriver; extern DisplayDriver t_hmiDisplayDriver; #define SCREENS_ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0])) diff --git a/src/drivers/displays/m5stickCPlusDriver.cpp b/src/drivers/displays/m5stickCPlusDriver.cpp new file mode 100644 index 00000000..f50203d1 --- /dev/null +++ b/src/drivers/displays/m5stickCPlusDriver.cpp @@ -0,0 +1,278 @@ +#include "displayDriver.h" + +#ifdef M5STICKCPLUS_DISPLAY + +#include + +#include "media/images_240_135.h" +#include "media/myFonts.h" +#include "media/Free_Fonts.h" +#include "OpenFontRender.h" +#include "version.h" +#include "monitor.h" +#include "rotation.h" + +#define WIDTH 240 +#define HEIGHT 135 + +OpenFontRender render; +TFT_eSPI tft = TFT_eSPI(); // Invoke library, pins defined in User_Setup.h +TFT_eSprite background = TFT_eSprite(&tft); // Invoke library sprite + +int screen_state = 1; + +void m5stickCPlusDriver_Init(void) +{ + M5.begin(); + M5.Axp.ScreenBreath(100); //screen brightness 0 - 100 + + tft.init(); + tft.setRotation(ROTATION_90); + tft.setSwapBytes(true); // Swap the colour byte order when rendering + background.createSprite(WIDTH, HEIGHT); // Background Sprite + background.setSwapBytes(true); + render.setDrawer(background); // Link drawing object to background instance (so font will be rendered on background) + render.setLineSpaceRatio(0.9); // Espaciado entre texto + + // Load the font and check it can be read OK + if (render.loadFont(DigitalNumbers, sizeof(DigitalNumbers))) + { + Serial.println("Initialise error"); + while(1); + return; + } +} + +void m5stickCPlusDriver_AlternateScreenState(void) +{ + if (screen_state==1) { + M5.Lcd.writecommand(ST7789_DISPOFF); + M5.Axp.ScreenBreath(0); + screen_state=0; + } else { + M5.Lcd.writecommand(ST7789_DISPON); + M5.Axp.ScreenBreath(100); + screen_state=1; + } +} + +void m5stickCPlusDriver_AlternateRotation(void) +{ + tft.setRotation( flipRotation(tft.getRotation()) ); +} + +void m5stickCPlusDriver_MinerScreen(unsigned long mElapsed) +{ + mining_data data = getMiningData(mElapsed); + + // Print background screen + background.pushImage(0, 0, MinerWidth, MinerHeight, MinerScreen); + + Serial.printf(">>> Completed %s share(s), %s Khashes, avg. hashrate %s KH/s\n", + data.completedShares.c_str(), data.totalKHashes.c_str(), data.currentHashRate.c_str()); + + // Hashrate + render.setFontSize(30); + render.setCursor(19, 118); + render.setFontColor(TFT_BLACK); + + render.rdrawString(data.currentHashRate.c_str(), 100, 82, TFT_BLACK); + // Total hashes + render.setFontSize(13); + render.rdrawString(data.totalMHashes.c_str(), 200, 106, TFT_BLACK); + // Block templates + render.drawString(data.templates.c_str(), 140, 15, 0xDEDB); + // Best diff + render.drawString(data.bestDiff.c_str(), 140, 36, 0xDEDB); + // 32Bit shares + render.drawString(data.completedShares.c_str(), 140, 56, 0xDEDB); + // Hores + render.setFontSize(9); + render.rdrawString(data.timeMining.c_str(), 226, 80, 0xDEDB); + + // Valid Blocks + render.setFontSize(19); + render.drawString(data.valids.c_str(), 212, 42, 0xDEDB); + + // Print Temp + render.setFontSize(8); + render.rdrawString(data.temp.c_str(), 180, 1, TFT_BLACK); + + render.setFontSize(3); + render.rdrawString(String(0).c_str(), 184, 2, TFT_BLACK); + + // Print Hour + render.setFontSize(8); + render.rdrawString(data.currentTime.c_str(), 215, 1, TFT_BLACK); + + // Push prepared background to screen + background.pushSprite(0, 0); +} + +void m5stickCPlusDriver_ClockScreen(unsigned long mElapsed) +{ + clock_data data = getClockData(mElapsed); + + // Print background screen + background.pushImage(0, 0, minerClockWidth, minerClockHeight, minerClockScreen); + + Serial.printf(">>> Completed %s share(s), %s Khashes, avg. hashrate %s KH/s\n", + data.completedShares.c_str(), data.totalKHashes.c_str(), data.currentHashRate.c_str()); + + // Hashrate + render.setFontSize(20); + render.setCursor(19, 122); + render.setFontColor(TFT_BLACK); + render.rdrawString(data.currentHashRate.c_str(), 70, 103, TFT_BLACK); + + // Print BTC Price + background.setFreeFont(FSSB9); + background.setTextSize(1); + background.setTextDatum(TL_DATUM); + background.setTextColor(TFT_BLACK); + background.drawString(data.btcPrice.c_str(), 148, 1, GFXFF); + + // Print BlockHeight + render.setFontSize(14); + render.rdrawString(data.blockHeight.c_str(), 190, 110, TFT_BLACK); + + // Print Hour + background.setFreeFont(FF22); + background.setTextSize(2); + background.setTextColor(TFT_WHITE, TFT_BLACK); + + background.drawString(data.currentTime.c_str(), 100, 40, GFXFF); + + // Push prepared background to screen + background.pushSprite(0, 0); +} + +void m5stickCPlusDriver_GlobalHashScreen(unsigned long mElapsed) +{ + coin_data data = getCoinData(mElapsed); + + // Print background screen + background.pushImage(0, 0, globalHashWidth, globalHashHeight, globalHashScreen); + + Serial.printf(">>> Completed %s share(s), %s Khashes, avg. hashrate %s KH/s\n", + data.completedShares.c_str(), data.totalKHashes.c_str(), data.currentHashRate.c_str()); + + // Print BTC Price + background.setFreeFont(FSSB9); + background.setTextSize(1); + background.setTextDatum(TL_DATUM); + background.setTextColor(TFT_BLACK); + background.drawString(data.btcPrice.c_str(), 148, 1, GFXFF); + + // Print Last Pool Block + background.setFreeFont(FSS9); + background.setTextDatum(TR_DATUM); + background.setTextColor(TFT_WHITE); + background.drawString(data.halfHourFee.c_str(), 230, 40, GFXFF); + + // Print Difficulty + background.setFreeFont(FSS9); + background.setTextDatum(TR_DATUM); + background.setTextColor(TFT_WHITE); + background.drawString(data.netwrokDifficulty.c_str(), 230, 68, GFXFF); + + // Print Global Hashrate + render.setFontSize(12); + render.rdrawString(data.globalHashRate.c_str(), 205, 115, TFT_BLACK); + + // Print BlockHeight + render.setFontSize(23); + render.rdrawString(data.blockHeight.c_str(), 105, 80, TFT_WHITE); + + // Draw percentage rectangle + int x2 = 2 + (138 * data.progressPercent / 100); + background.fillRect(2, 149, x2, 168, 0xDEDB); + + // Print Remaining BLocks + background.setTextFont(FONT2); + background.setTextSize(1); + background.setTextDatum(MC_DATUM); + background.setTextColor(TFT_BLACK); + background.drawString(data.remainingBlocks.c_str(), 55, 125, FONT2); + + // Push prepared background to screen + background.pushSprite(0, 0); +} + +void tDisplay_BTCprice(unsigned long mElapsed) +{ + clock_data data = getClockData(mElapsed); + + // Print background screen + background.pushImage(0, 0, priceScreenWidth, priceScreenHeight, priceScreen); + + Serial.printf(">>> Completed %s share(s), %s Khashes, avg. hashrate %s KH/s\n", + data.completedShares.c_str(), data.totalKHashes.c_str(), data.currentHashRate.c_str()); + + // Hashrate + render.setFontSize(22); + render.setCursor(19, 122); + render.setFontColor(TFT_BLACK); + render.rdrawString(data.currentHashRate.c_str(), 75, 90, TFT_BLACK); + + // Print BlockHeight + render.setFontSize(16); + render.rdrawString(data.blockHeight.c_str(), 190, 100, TFT_WHITE); + + // Print Hour + background.setFreeFont(FSSB9); + background.setTextSize(1); + background.setTextDatum(TL_DATUM); + background.setTextColor(TFT_BLACK); + background.drawString(data.currentTime.c_str(), 148, 1, GFXFF); + + // Print BTC Price + background.setFreeFont(FF18); + background.setTextDatum(TR_DATUM); + background.setTextSize(2); + background.setTextColor(TFT_WHITE); + background.drawString(data.btcPrice.c_str(), 230, 40, GFXFF); + + // Push prepared background to screen + background.pushSprite(0, 0); +} + +void m5stickCPlusDriver_LoadingScreen(void) +{ + tft.fillScreen(TFT_BLACK); + tft.pushImage(0, 0, initWidth, initHeight, initScreen); + tft.setTextFont(2); + tft.setTextColor(TFT_BLACK); + tft.setCursor(20, 110); + tft.println(CURRENT_VERSION); +} + +void m5stickCPlusDriver_SetupScreen(void) +{ + tft.pushImage(0, 0, setupModeWidth, setupModeHeight, setupModeScreen); +} + +void m5stickCPlusDriver_AnimateCurrentScreen(unsigned long frame) +{ +} + +void m5stickCPlusDriver_DoLedStuff(unsigned long frame) +{ +} + +CyclicScreenFunction m5stickCPlusDriverCyclicScreens[] = { m5stickCPlusDriver_MinerScreen, m5stickCPlusDriver_ClockScreen, m5stickCPlusDriver_GlobalHashScreen, tDisplay_BTCprice}; + +DisplayDriver m5stickCPlusDriver = { + m5stickCPlusDriver_Init, + m5stickCPlusDriver_AlternateScreenState, + m5stickCPlusDriver_AlternateRotation, + m5stickCPlusDriver_LoadingScreen, + m5stickCPlusDriver_SetupScreen, + m5stickCPlusDriverCyclicScreens, + m5stickCPlusDriver_AnimateCurrentScreen, + m5stickCPlusDriver_DoLedStuff, + SCREENS_ARRAY_SIZE(m5stickCPlusDriverCyclicScreens), + 0, + WIDTH, + HEIGHT}; +#endif