T-Dongle-S3 device support added

This commit is contained in:
Roman Mashta 2023-08-31 18:44:58 +03:00
parent bdffef1f37
commit 7a574d1b47
14 changed files with 267 additions and 24 deletions

View File

@ -130,10 +130,16 @@
#ifdef NERDMINERV2
#include <User_Setups/Setup206_LilyGo_T_Display_S3.h>
#endif
#ifdef NERMINER_S3_AMOLED
#include <User_Setups/Setup206_LilyGo_T_Display_S3.h> //Just a stub. No driver implementation for S3 AMOLED in TFT_eSPI
#endif
#ifdef NERMINER_S3_DONGLE
#include <User_Setups/Setup300_TTGO_T_Dongle.h> //Just a stub. No driver implementation for S3 AMOLED in TFT_eSPI
#endif
//#include <User_Setups/Setup301_BW16_ST7735.h> // Setup file for Bw16-based boards with ST7735 160 x 80 TFT
//#include <User_Setups/SetupX_Template.h> // Template file for a setup

View File

@ -0,0 +1,38 @@
#define USER_SETUP_ID 300
#define ST7735_DRIVER
#define TFT_WIDTH 80
#define TFT_HEIGHT 160
#define TFT_RST 1
#define TFT_MISO -1
#define TFT_MOSI 3
#define TFT_SCLK 5
#define TFT_CS 4
#define TFT_DC 2
// #define TFT_BL 38
// #define TFT_BACKLIGHT_ON LOW
#define ST7735_GREENTAB160x80 // For 160 x 80 display (BGR, inverted, 26 offset)
#define LOAD_GLCD // Font 1. Original Adafruit 8 pixel font needs ~1820 bytes in FLASH
#define LOAD_FONT2 // Font 2. Small 16 pixel high font, needs ~3534 bytes in FLASH, 96 characters
#define LOAD_FONT4 // Font 4. Medium 26 pixel high font, needs ~5848 bytes in FLASH, 96 characters
#define LOAD_FONT6 // Font 6. Large 48 pixel font, needs ~2666 bytes in FLASH, only characters 1234567890:-.apm
#define LOAD_FONT7 // Font 7. 7 segment 48 pixel font, needs ~2438 bytes in FLASH, only characters 1234567890:.
#define LOAD_FONT8 // Font 8. Large 75 pixel font needs ~3256 bytes in FLASH, only characters 1234567890:-.
//#define LOAD_FONT8N // Font 8. Alternative to Font 8 above, slightly narrower, so 3 digits fit a 160 pixel TFT
#define LOAD_GFXFF // FreeFonts. Include access to the 48 Adafruit_GFX free fonts FF1 to FF48 and custom fonts
// Comment out the #define below to stop the SPIFFS filing system and smooth font code being loaded
// this will save ~20kbytes of FLASH
#define SMOOTH_FONT
#define SPI_FREQUENCY 50000000 // Actually sets it to 26.67MHz = 80/3
// #define SPI_FREQUENCY 40000000 // Maximum to use SPIFFS
// #define SPI_FREQUENCY 80000000
#define TFT_RGB_ORDER TFT_BGR

View File

@ -104,6 +104,8 @@ platform = espressif32
board = lilygo-t-display-s3
framework = arduino
board_build.partitions = huge_app.csv
build_flags =
-DNERMINER_S3_AMOLED
-DBOARD_HAS_PSRAM
@ -115,3 +117,22 @@ lib_deps =
mathertel/OneButton @ ^2.0.3
arduino-libraries/NTPClient
https://github.com/golden-guy/Arduino_wolfssl.git#v5.5.4
[env:NerminerV2-S3-DONGLE]
platform = espressif32
board = esp32-s3-devkitc-1
framework = arduino
board_build.partitions = huge_app.csv
build_flags =
-DNERMINER_S3_DONGLE
-DBOARD_HAS_PSRAM
-DARDUINO_USB_CDC_ON_BOOT
lib_deps =
https://github.com/takkaO/OpenFontRender
bblanchon/ArduinoJson@^6.21.2
https://github.com/tzapu/WiFiManager.git
mathertel/OneButton @ ^2.0.3
arduino-libraries/NTPClient
https://github.com/golden-guy/Arduino_wolfssl.git#v5.5.4

View File

@ -56,6 +56,11 @@ void setup()
button1.setPressTicks(5000);
button1.attachLongPressStart(reset_configurations);
pinMode(LED_PIN, OUTPUT);
#elif defined(NERMINER_S3_DONGLE)
button1.setPressTicks(5000);
button1.attachClick(switchToNextScreen);
button1.attachDoubleClick(alternateScreenRotation);
button1.attachLongPressStart(reset_configurations);
#endif

View File

@ -12,6 +12,10 @@ DisplayDriver *currentDisplayDriver = &tDisplayDriver;
DisplayDriver *currentDisplayDriver = &amoledDisplayDriver;
#endif
#ifdef DONGLE_DISPLAY
DisplayDriver *currentDisplayDriver = &dongleDisplayDriver;
#endif
// Initialize the display
void initDisplay() {
currentDisplayDriver->initDisplay();
@ -52,3 +56,8 @@ void drawCurrentScreen(unsigned long mElapsed) {
currentDisplayDriver->cyclic_screens[currentDisplayDriver->current_cyclic_screen](mElapsed);
}
// Animate the current cyclic screen
void animateCurrentScreen(unsigned long frame) {
currentDisplayDriver->animateCurrentScreen(frame);
}

View File

@ -13,5 +13,6 @@ void resetToFirstScreen();
void drawLoadingScreen();
void drawSetupScreen();
void drawCurrentScreen(unsigned long mElapsed);
void animateCurrentScreen(unsigned long frame);
#endif // DISPLAY_H

View File

@ -5,6 +5,8 @@
#define NO_DISPLAY
#elif defined(NERMINER_S3_AMOLED)
#define AMOLED_DISPLAY
#elif defined(NERMINER_S3_DONGLE)
#define DONGLE_DISPLAY
#else
#define T_DISPLAY
#endif
@ -13,6 +15,7 @@ typedef void (*AlternateFunction)(void);
typedef void (*DriverInitFunction)(void);
typedef void (*ScreenFunction)(void);
typedef void (*CyclicScreenFunction)(unsigned long mElapsed);
typedef void (*AnimateCurrentScreenFunction)(unsigned long frame);
typedef struct {
DriverInitFunction initDisplay; // Initialize the display
@ -21,6 +24,7 @@ typedef struct {
ScreenFunction loadingScreen; // Explicit loading screen
ScreenFunction setupScreen; // Explicit setup screen
CyclicScreenFunction *cyclic_screens; // Array of cyclic screens
AnimateCurrentScreenFunction animateCurrentScreen; // Animate the current cyclic screen
int num_cyclic_screens; // Number of cyclic screens
int current_cyclic_screen; // Current cyclic screen being displayed
int screenWidth; // Screen width
@ -32,6 +36,7 @@ extern DisplayDriver *currentDisplayDriver;
extern DisplayDriver noDisplayDriver;
extern DisplayDriver tDisplayDriver;
extern DisplayDriver amoledDisplayDriver;
extern DisplayDriver dongleDisplayDriver;
#define SCREENS_ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))

View File

@ -204,6 +204,9 @@ void amoledDisplay_SetupScreen(void) {
lcd_PushColors(0, 0, WIDTH, HEIGHT, (uint16_t *)background.getPointer());
}
void amoledDisplay_AnimateCurrentScreen(unsigned long frame) {
}
CyclicScreenFunction amoledDisplayCyclicScreens[] = { amoledDisplay_MinerScreen, amoledDisplay_ClockScreen, amoledDisplay_GlobalHashScreen };
DisplayDriver amoledDisplayDriver = {
@ -213,6 +216,7 @@ DisplayDriver amoledDisplayDriver = {
amoledDisplay_LoadingScreen,
amoledDisplay_SetupScreen,
amoledDisplayCyclicScreens,
amoledDisplay_AnimateCurrentScreen,
SCREENS_ARRAY_SIZE(amoledDisplayCyclicScreens),
0,
WIDTH,

View File

@ -0,0 +1,135 @@
#include "../drivers.h"
#ifdef DONGLE_DISPLAY
#include <TFT_eSPI.h>
#include "media/images.h"
#include "media/myFonts.h"
#include "media/Free_Fonts.h"
#include "version.h"
#include "monitor.h"
#include "OpenFontRender.h"
#define WIDTH 160
#define HEIGHT 80
#define BUFFER_WIDTH WIDTH
#define BUFFER_HEIGHT HEIGHT * 4
#define SCROLL_SPEED 1
int pos_y = 0;
int delta_y = SCROLL_SPEED;
int max_y = BUFFER_HEIGHT - HEIGHT;
OpenFontRender render;
TFT_eSPI tft = TFT_eSPI();
TFT_eSprite background = TFT_eSprite(&tft);
#define BACK_COLOR TFT_BLACK
#define VALUE_COLOR TFT_WHITE
#define KEY_COLOR TFT_WHITE
#define CLEAR_SCREEN() \
int32_t x = 4, y = 8; \
background.setTextSize(1);\
background.setTextFont(FONT2);\
background.setTextColor(KEY_COLOR);\
background.fillRect(0, 0, BUFFER_WIDTH, BUFFER_HEIGHT, BACK_COLOR);\
render.setFontSize(24);\
#define PRINT_STR(key, value, x, y)\
{\
background.drawString(String(key).c_str(), x, y);\
y -= 8;\
render.rdrawString(String(value).c_str(), WIDTH - 4, y, VALUE_COLOR);\
y += 40;\
max_y = y;\
}
#define PUSH_SCREEN() \
background.pushSprite(0,0);
void dongleDisplay_Init(void) {
tft.init();
tft.setRotation(3);
tft.setSwapBytes(true);
tft.fillScreen(TFT_RED);
background.createSprite(BUFFER_WIDTH, BUFFER_HEIGHT);
background.setSwapBytes(true);
render.setDrawer(background);
render.setLineSpaceRatio(0.9);
// Load the font and check it can be read OK
//if (render.loadFont(NotoSans_Bold, sizeof(NotoSans_Bold))) {
if (render.loadFont(DigitalNumbers, sizeof(DigitalNumbers))){
Serial.println("Initialise error");
return;
}
}
void dongleDisplay_AlternateScreenState(void) {
}
void dongleDisplay_AlternateRotation(void) {
tft.getRotation() == 1 ? tft.setRotation(3) : tft.setRotation(1);
}
void dongleDisplay_MinerScreen(unsigned long mElapsed) {
mining_data data = getMiningData(mElapsed);
//Print background screen
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());
CLEAR_SCREEN();
PRINT_STR("M.Hashes", data.totalMHashes, x, y)
PRINT_STR("Templates", data.templates, x, y)
PRINT_STR("Best Diff", data.bestDiff, x, y)
PRINT_STR("Shares", data.completedShares, x, y)
PRINT_STR("Hash rate", data.currentHashRate, x, y)
PRINT_STR("Valids", data.valids, x, y)
PRINT_STR("Temp", data.temp, x, y)
PRINT_STR("Time", data.currentTime, x, y)
}
void dongleDisplay_LoadingScreen(void) {
CLEAR_SCREEN();
PRINT_STR("Initializing...","", x, y);
PUSH_SCREEN();
}
void dongleDisplay_SetupScreen(void) {
CLEAR_SCREEN();
PRINT_STR("Use WiFi for setup...","", x, y);
PUSH_SCREEN();
}
void dongleDisplay_AnimateCurrentScreen(unsigned long frame) {
if(pos_y >= max_y - HEIGHT) {
delta_y = -SCROLL_SPEED;
pos_y = max_y - HEIGHT;
} else if(pos_y <= 0) {
delta_y = SCROLL_SPEED;
pos_y = 0;
}
pos_y += delta_y;
background.pushSprite(0, -pos_y);
}
CyclicScreenFunction dongleDisplayCyclicScreens[] = { dongleDisplay_MinerScreen };
DisplayDriver dongleDisplayDriver = {
dongleDisplay_Init,
dongleDisplay_AlternateScreenState,
dongleDisplay_AlternateRotation,
dongleDisplay_LoadingScreen,
dongleDisplay_SetupScreen,
dongleDisplayCyclicScreens,
dongleDisplay_AnimateCurrentScreen,
SCREENS_ARRAY_SIZE(dongleDisplayCyclicScreens),
0,
WIDTH,
HEIGHT
};
#endif

View File

@ -33,10 +33,14 @@ void noDisplay_NoScreen(unsigned long mElapsed) {
}
void noDisplay_LoadingScreen(void) {
Serial.println("Initializing...");
}
}
void noDisplay_SetupScreen(void) {
Serial.println("Setup...");
}
}
void tDisplay_AnimateCurrentScreen(unsigned long frame) {
}
CyclicScreenFunction noDisplayCyclicScreens[] = { noDisplay_NoScreen };
@ -47,6 +51,7 @@ DisplayDriver noDisplayDriver = {
noDisplay_LoadingScreen,
noDisplay_SetupScreen,
noDisplayCyclicScreens,
noDisplay_AnimateCurrentScreen,
SCREENS_ARRAY_SIZE(noDisplayCyclicScreens),
0,
0,

View File

@ -17,7 +17,7 @@ OpenFontRender render;
TFT_eSPI tft = TFT_eSPI(); // Invoke library, pins defined in User_Setup.h
TFT_eSprite background = TFT_eSprite(&tft); // Invoke library sprite
void smoledDisplay_Init(void) {
void tDisplay_Init(void) {
tft.init();
tft.setRotation(1);
tft.setSwapBytes(true);// Swap the colour byte order when rendering
@ -199,15 +199,19 @@ void tDisplay_SetupScreen(void) {
tft.pushImage(0, 0, setupModeWidth, setupModeHeight, setupModeScreen);
}
void tDisplay_AnimateCurrentScreen(unsigned long frame) {
}
CyclicScreenFunction tDisplayCyclicScreens[] = { tDisplay_MinerScreen, tDisplay_ClockScreen, tDisplay_GlobalHashScreen };
DisplayDriver tDisplayDriver = {
smoledDisplay_Init,
tDisplay_Init,
tDisplay_AlternateScreenState,
tDisplay_AlternateRotation,
tDisplay_LoadingScreen,
tDisplay_SetupScreen,
tDisplayCyclicScreens,
tDisplay_AnimateCurrentScreen,
SCREENS_ARRAY_SIZE(tDisplayCyclicScreens),
0,
WIDTH,

View File

@ -372,6 +372,9 @@ void runMiner(void * task_id) {
}
}
#define DELAY 100
#define REDRAW_EVERY 10
void runMonitor(void *name){
Serial.println("[MONITOR] started");
@ -380,26 +383,30 @@ void runMonitor(void *name){
resetToFirstScreen();
while(1){
unsigned long mElapsed = millis()-mLastCheck;
mLastCheck = millis();
unsigned long currentKHashes = (Mhashes*1000) + hashes/1000;
elapsedKHs = currentKHashes - totalKHashes;
totalKHashes = currentKHashes;
drawCurrentScreen(mElapsed);
//Monitor state when hashrate is 0.0
if(elapsedKHs == 0) {
Serial.printf(">>> [i] Miner: newJob>%s / inRun>%s) - Client: connected>%s / subscribed>%s / wificonnected>%s\n",
mMiner.newJob ? "true" : "false", mMiner.inRun ? "true" : "false",
client.connected() ? "true" : "false", isMinerSuscribed ? "true" : "false", WiFi.status() == WL_CONNECTED ? "true" : "false");
}
unsigned long frame = 0;
while(1){
if((frame % REDRAW_EVERY) == 0){
unsigned long mElapsed = millis()-mLastCheck;
mLastCheck = millis();
unsigned long currentKHashes = (Mhashes*1000) + hashes/1000;
elapsedKHs = currentKHashes - totalKHashes;
totalKHashes = currentKHashes;
drawCurrentScreen(mElapsed);
//Monitor state when hashrate is 0.0
if(elapsedKHs == 0) {
Serial.printf(">>> [i] Miner: newJob>%s / inRun>%s) - Client: connected>%s / subscribed>%s / wificonnected>%s\n",
mMiner.newJob ? "true" : "false", mMiner.inRun ? "true" : "false",
client.connected() ? "true" : "false", isMinerSuscribed ? "true" : "false", WiFi.status() == WL_CONNECTED ? "true" : "false");
}
}
animateCurrentScreen(frame);
// Pause the task for 1000ms
vTaskDelay(1000 / portTICK_PERIOD_MS);
vTaskDelay(DELAY / portTICK_PERIOD_MS);
frame++;
}
}

View File

@ -145,7 +145,7 @@ void init_WifiManager()
// Change to true when testing to force configuration every time we run
bool forceConfig = false;
#if !defined(DEVKITV1)
#if !defined(DEVKITV1) & !defined(NERMINER_S3_DONGLE)
// Check if button2 is pressed to enter configMode with actual configuration
if(!digitalRead(PIN_BUTTON_2)){
Serial.println(F("Button pressed to force start config mode"));

View File

@ -14,7 +14,10 @@
#define PIN_BUTTON_1 0
#define PIN_BUTTON_2 21
#define PIN_ENABLE5V 15
#elif defined(NERMINER_S3_DONGLE)
#define PIN_BUTTON_1 0
#define PIN_BUTTON_2 -1
#define PIN_ENABLE5V -1
#endif
void init_WifiManager();