Skip to content

support M5 corebasic2.7+Module-LoRa433_V1.1+GNSS Module #6807

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 25 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
e2712b4
support M5 corebasic2.7+Module-LoRa433_V1.1+GNSS Module
weekroom Aug 15, 2024
b21551a
Increase sleep wake screen backlight
weekroom Aug 15, 2024
c22cde3
Merge branch 'master' into develop
weekroom Aug 16, 2024
81d0871
Merge branch 'master' into develop
weekroom Aug 19, 2024
c1a0546
Modification conflict
weekroom Aug 22, 2024
cde2ba0
Merge branch 'master' into develop
weekroom Aug 22, 2024
282c6a7
Merge branch 'master' into develop
weekroom Aug 23, 2024
935debe
Merge branch 'master' into develop
weekroom Aug 26, 2024
c651c60
Support M5 core2 +Module-LoRa433_V1.1+GNSS Module
weekroom Aug 26, 2024
7d677d6
Merge branch 'master' into develop
weekroom Aug 27, 2024
d6d29a7
Merge branch 'meshtastic:master' into develop
weekroom Aug 30, 2024
1945805
Modify macro definition, remove and open some features
weekroom Aug 30, 2024
10e9374
Merge branch 'master' into develop
weekroom Sep 2, 2024
11c045c
Merge branch 'master' into develop
weekroom Sep 3, 2024
61212bc
Merge branch 'master' into develop
weekroom Sep 4, 2024
1ddd7dc
Merge branch 'master' into develop
weekroom Sep 13, 2024
f6a6224
Merge branch 'master' into develop
weekroom Sep 18, 2024
e41cede
Merge branch 'master' into develop
weekroom Feb 12, 2025
d9d821f
Added RF95 power upper limit macro definition
weekroom Feb 18, 2025
db9b0e0
Merge branch 'master' into develop
weekroom Feb 27, 2025
a981ea5
Merge branch 'master' into develop
weekroom Feb 27, 2025
3729635
fix the code format by use trunk
imliubo Feb 27, 2025
e45ec50
Merge branch 'master' into develop
weekroom Mar 11, 2025
3db9232
Merge branch 'master' into develop
weekroom May 14, 2025
cda742e
Correct the color definition error
weekroom May 14, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
89 changes: 87 additions & 2 deletions src/ButtonThread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@
#ifdef ARCH_PORTDUINO
#include "platform/portduino/PortduinoGlue.h"
#endif

#if defined(M5STACK_CORE2)
#include <M5Unified.h>
#endif
#define DEBUG_BUTTONS 0
#if DEBUG_BUTTONS
#define LOG_BUTTON(...) LOG_DEBUG(__VA_ARGS__)
Expand Down Expand Up @@ -455,4 +457,87 @@ void ButtonThread::userButtonPressedLongStop()
if (millis() > c_holdOffTime) {
btnEvent = BUTTON_EVENT_LONG_RELEASED;
}
}
}
#if defined(M5STACK_CORE2)
// Define a constant
const unsigned long LONG_PRESS_THRESHOLD = 5000; // Hold the threshold
const unsigned long DOUBLE_CLICK_THRESHOLD = 1000; // Double-click the threshold
const int MAX_CLICKS = 2; // Maximum hits
// Global variable
unsigned long lastClickTime = 0; // The time of the last click
int clickCount = 0; // Click count
unsigned long touch_start_time; // Touch start time
bool is_touching = false; // Mark whether you are currently touching
void ScreenTouch()
{
M5.update();
auto count = M5.Touch.getCount();
if (count == 0)
return;
for (std::size_t i = 0; i < count; ++i) {
auto t = M5.Touch.getDetail(i);

// If touch starts
if (t.wasPressed()) {
touch_start_time = millis(); // Record the time when the touch began
is_touching = true; // Set to touch
}

// Check the current touch status
if (is_touching) {
unsigned long duration = millis() - touch_start_time;
if (duration >= LONG_PRESS_THRESHOLD) {
LOG_INFO("Long Press Detected\n");
powerFSM.trigger(EVENT_PRESS);
screen->startAlert("Shutting down...");
screen->forceDisplay(true);
// Executive logic, such as shutdown, display menu, etc
// To avoid duplicate detection, set is_touching to false here
is_touching = false;
M5.Speaker.tone(3000, 300);
delay(1000);
M5.Power.powerOff();
}
}
// Check if the touch just ended
if (t.wasReleased()) {
if (is_touching) {
unsigned long duration = millis() - touch_start_time;
if (duration < LONG_PRESS_THRESHOLD) {
unsigned long currentTime = millis();
// Check whether it is a double click
if (currentTime - lastClickTime <= DOUBLE_CLICK_THRESHOLD) {
clickCount++;
if (clickCount == MAX_CLICKS) {
LOG_INFO("Double Click Detected\n");
M5.Speaker.tone(2000, 100);
service->refreshLocalMeshNode();
auto sentPosition = service->trySendPosition(NODENUM_BROADCAST, true);
if (screen) {
if (sentPosition)
screen->print("Sent ad-hoc position\n");
else
screen->print("Sent ad-hoc nodeinfo\n");
screen->forceDisplay(true); // Force a new UI frame, then force an EInk update
}
clickCount = 0;
}
} else {
clickCount = 1;
}

lastClickTime = currentTime; // Update last click time
}
}
// Reset the touch status
is_touching = false;
}
// You can add more status checks, such as sliding and dragging
if (t.wasFlickStart()) {
LOG_INFO("Flick Start Detected\n");
M5.Speaker.tone(1000, 100);
powerFSM.trigger(EVENT_PRESS);
}
}
}
#endif
3 changes: 3 additions & 0 deletions src/ButtonThread.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,3 +89,6 @@ class ButtonThread : public concurrency::OSThread
};

extern ButtonThread *buttonThread;
#if defined(M5STACK_CORE2)
void ScreenTouch();
#endif
70 changes: 55 additions & 15 deletions src/graphics/Screen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,15 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "modules/StoreForwardModule.h"
#include "platform/portduino/PortduinoGlue.h"
#endif

#if defined(M5STACK_CORE2)
#include "M5Unified.h"
#define OLED_BLACK OLEDDISPLAY_COLOR::BLACK
#define OLED_WHITE OLEDDISPLAY_COLOR::WHITE
#else
#define OLED_BLACK BLACK
#define OLED_WHITE WHITE
#endif
extern DataInfo DataRegion;
using namespace meshtastic; /** @todo remove */

namespace graphics
Expand Down Expand Up @@ -949,7 +957,24 @@ bool deltaToTimestamp(uint32_t secondsAgo, uint8_t *hours, uint8_t *minutes, int
validCached = true;
return validCached;
}

static void drawLoraMessage(OLEDDisplay *display, OLEDDisplayUiState *state, int16_t x, int16_t y)
{
display->drawString(x + 0, y + 0, myRegion->name);
display->setFont(FONT_MEDIUM);
display->drawString(x + 10, y + 30, "channel: " + String(DataRegion.lora_channel_num + 1));
display->drawString(x + 10, y + 60, "bw: " + String(DataRegion.lora_bw));
display->drawString(x + SCREEN_WIDTH / 2 + 10, y + 30, "freq: " + String(DataRegion.lora_freq));
display->drawString(x + SCREEN_WIDTH / 2 + 10, y + 60, "power: " + String(DataRegion.lora_power_output));
display->drawString(x + 10, y + 90, "sf: " + String(DataRegion.lora_sf));
display->drawString(x + SCREEN_WIDTH / 2 + 10, y + 90, "cr: 4/:" + String(DataRegion.lora_cr));
display->setTextAlignment(TEXT_ALIGN_LEFT);
const char *title = "LoRa";
display->drawString(x + SCREEN_WIDTH / 2 - 20, y + 0, title);
display->setFont(FONT_SMALL);
display->setTextAlignment(TEXT_ALIGN_RIGHT);
display->drawString(x + SCREEN_WIDTH, y, String(DataRegion.lora_channel_name));
display->setTextAlignment(TEXT_ALIGN_LEFT); // Restore left align, just to be kind to any other unsuspecting code
}
/// Draw the last text message we received
static void drawTextMessageFrame(OLEDDisplay *display, OLEDDisplayUiState *state, int16_t x, int16_t y)
{
Expand All @@ -968,7 +993,7 @@ static void drawTextMessageFrame(OLEDDisplay *display, OLEDDisplayUiState *state
display->setFont(FONT_SMALL);
if (config.display.displaymode == meshtastic_Config_DisplayConfig_DisplayMode_INVERTED) {
display->fillRect(0 + x, 0 + y, x + display->getWidth(), y + FONT_HEIGHT_SMALL);
display->setColor(BLACK);
display->setColor(OLED_BLACK);
}

// For time delta
Expand Down Expand Up @@ -1002,7 +1027,7 @@ static void drawTextMessageFrame(OLEDDisplay *display, OLEDDisplayUiState *state
}
}

display->setColor(WHITE);
display->setColor(OLED_WHITE);
#ifndef EXCLUDE_EMOJI
const char *msg = reinterpret_cast<const char *>(mp.decoded.payload.bytes);
if (strcmp(msg, "\U0001F44D") == 0) {
Expand Down Expand Up @@ -1085,10 +1110,10 @@ void Screen::drawColumns(OLEDDisplay *display, int16_t x, int16_t y, const char
int xo = x, yo = y;
while (*f) {
display->drawString(xo, yo, *f);
if ((display->getColor() == BLACK) && config.display.heading_bold)
display->drawString(xo + 1, yo, *f);

display->setColor(WHITE);
if ((display->getColor() == OLED_BLACK) && config.display.heading_bold)
display->drawString(xo + 1, yo, *f);
display->setColor(OLED_WHITE);
yo += FONT_HEIGHT_SMALL;
if (yo > SCREEN_HEIGHT - FONT_HEIGHT_SMALL) {
xo += SCREEN_WIDTH / 2;
Expand Down Expand Up @@ -1517,7 +1542,7 @@ static void drawNodeInfo(OLEDDisplay *display, OLEDDisplayUiState *state, int16_
display->drawCircle(compassX, compassY, compassDiam / 2);

if (config.display.displaymode == meshtastic_Config_DisplayConfig_DisplayMode_INVERTED) {
display->setColor(BLACK);
display->setColor(OLED_BLACK);
}
// Must be after distStr is populated
screen->drawColumns(display, x, y, fields);
Expand Down Expand Up @@ -1632,6 +1657,14 @@ void Screen::handleSetOn(bool on, FrameCallback einkScreensaver)
pinMode(VTFT_LEDA, OUTPUT);
digitalWrite(VTFT_LEDA, TFT_BACKLIGHT_ON);
#endif
#endif
#ifdef TFT_BL
pinMode(TFT_BL, OUTPUT);
digitalWrite(TFT_BL, HIGH);
#endif
#if defined(M5STACK_CORE2)
M5.Power.Axp192.setDCDC3(1000);
M5.Display.setBrightness(130);
#endif
enabled = true;
setInterval(0); // Draw ASAP
Expand All @@ -1650,6 +1683,13 @@ void Screen::handleSetOn(bool on, FrameCallback einkScreensaver)
}
#endif
dispdev->displayOff();
#ifdef TFT_BL
pinMode(TFT_BL, OUTPUT);
digitalWrite(TFT_BL, LOW);
#endif
#if defined(M5STACK_CORE2)
M5.Power.Axp192.setDCDC3(0);
#endif
#ifdef USE_ST7789
SPI1.end();
#if defined(ARCH_ESP32)
Expand Down Expand Up @@ -2156,7 +2196,7 @@ void Screen::setFrames(FrameFocus focus)
fsi.positions.textMessage = numframes;
normalFrames[numframes++] = drawTextMessageFrame;
}

normalFrames[numframes++] = drawLoraMessage;
// then all the nodes
// We only show a few nodes in our scrolling list - because meshes with many nodes would have too many screens
size_t numToShow = min(numMeshNodes, 4U);
Expand Down Expand Up @@ -2442,7 +2482,7 @@ void DebugInfo::drawFrame(OLEDDisplay *display, OLEDDisplayUiState *state, int16

if (config.display.displaymode == meshtastic_Config_DisplayConfig_DisplayMode_INVERTED) {
display->fillRect(0 + x, 0 + y, x + display->getWidth(), y + FONT_HEIGHT_SMALL);
display->setColor(BLACK);
display->setColor(OLED_BLACK);
}

char channelStr[20];
Expand Down Expand Up @@ -2483,7 +2523,7 @@ void DebugInfo::drawFrame(OLEDDisplay *display, OLEDDisplayUiState *state, int16
}
}
#endif
display->setColor(WHITE);
display->setColor(OLED_WHITE);
// Draw the channel name
display->drawString(x, y + FONT_HEIGHT_SMALL, channelStr);
// Draw our hardware ID to assist with bluetooth pairing. Either prefix with Info or S&F Logo
Expand Down Expand Up @@ -2556,7 +2596,7 @@ void DebugInfo::drawFrameWiFi(OLEDDisplay *display, OLEDDisplayUiState *state, i

if (config.display.displaymode == meshtastic_Config_DisplayConfig_DisplayMode_INVERTED) {
display->fillRect(0 + x, 0 + y, x + display->getWidth(), y + FONT_HEIGHT_SMALL);
display->setColor(BLACK);
display->setColor(OLED_BLACK);
}

if (WiFi.status() != WL_CONNECTED) {
Expand All @@ -2576,7 +2616,7 @@ void DebugInfo::drawFrameWiFi(OLEDDisplay *display, OLEDDisplayUiState *state, i
}
}

display->setColor(WHITE);
display->setColor(OLED_WHITE);

/*
- WL_CONNECTED: assigned when connected to a WiFi network;
Expand Down Expand Up @@ -2636,7 +2676,7 @@ void DebugInfo::drawFrameSettings(OLEDDisplay *display, OLEDDisplayUiState *stat

if (config.display.displaymode == meshtastic_Config_DisplayConfig_DisplayMode_INVERTED) {
display->fillRect(0 + x, 0 + y, x + display->getWidth(), y + FONT_HEIGHT_SMALL);
display->setColor(BLACK);
display->setColor(OLED_BLACK);
}

char batStr[20];
Expand Down Expand Up @@ -2682,7 +2722,7 @@ void DebugInfo::drawFrameSettings(OLEDDisplay *display, OLEDDisplayUiState *stat
if (config.display.heading_bold)
display->drawString(x - 1 + SCREEN_WIDTH - display->getStringWidth(uptime.c_str()), y, uptime.c_str());

display->setColor(WHITE);
display->setColor(OLED_WHITE);

// Setup string to assemble analogClock string
std::string analogClock = "";
Expand Down
30 changes: 19 additions & 11 deletions src/graphics/TFTDisplay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -615,7 +615,11 @@ class LGFX : public lgfx::LGFX_Device
cfg.dummy_read_pixel = 8; // Number of bits for dummy read before pixel readout
cfg.dummy_read_bits = 1; // Number of bits for dummy read before non-pixel data read
cfg.readable = true; // Set to true if data can be read
cfg.invert = false; // Set to true if the light/darkness of the panel is reversed
#if defined(M5STACK_COREBASIC)
cfg.invert = true; // Set to true if the light/darkness of the panel is reversed
#else
cfg.invert = false; // Set to true if the light/darkness of the panel is reversed
#endif
cfg.rgb_order = false; // Set to true if the panel's red and blue are swapped
cfg.dlen_16bit =
false; // Set to true for panels that transmit data length in 16-bit units with 16-bit parallel or SPI
Expand All @@ -633,8 +637,10 @@ class LGFX : public lgfx::LGFX_Device
{
auto cfg = _light_instance.config(); // Gets a structure for backlight settings.

cfg.pin_bl = TFT_BL; // Pin number to which the backlight is connected
cfg.invert = false; // true to invert the brightness of the backlight
#if !defined(M5STACK_CORE2)
cfg.pin_bl = TFT_BL; // Pin number to which the backlight is connected
#endif
cfg.invert = false; // true to invert the brightness of the backlight
// cfg.freq = 44100; // PWM frequency of backlight
// cfg.pwm_channel = 1; // PWM channel number to use

Expand Down Expand Up @@ -1035,7 +1041,7 @@ void TFTDisplay::sendCommand(uint8_t com)
display(true);
if (settingsMap[displayBacklight] > 0)
digitalWrite(settingsMap[displayBacklight], TFT_BACKLIGHT_ON);
#elif !defined(RAK14014) && !defined(M5STACK) && !defined(UNPHONE)
#elif !defined(RAK14014) && !defined(M5STACK) && !defined(UNPHONE) && !defined(M5STACK_COREBASIC) && !defined(M5STACK_CORE2)
tft->wakeup();
tft->powerSaveOff();
#endif
Expand All @@ -1047,7 +1053,8 @@ void TFTDisplay::sendCommand(uint8_t com)
unphone.backlight(true); // using unPhone library
#endif
#ifdef RAK14014
#elif !defined(M5STACK) && !defined(ST7789_CS) // T-Deck gets brightness set in Screen.cpp in the handleSetOn function
#elif !defined(M5STACK) && !defined(ST7789_CS) && !defined(M5STACK_COREBASIC) && \
!defined(M5STACK_CORE2) // T-Deck gets brightness set in Screen.cpp in the handleSetOn function
tft->setBrightness(172);
#endif
break;
Expand All @@ -1059,7 +1066,7 @@ void TFTDisplay::sendCommand(uint8_t com)
tft->clear();
if (settingsMap[displayBacklight] > 0)
digitalWrite(settingsMap[displayBacklight], !TFT_BACKLIGHT_ON);
#elif !defined(RAK14014) && !defined(M5STACK) && !defined(UNPHONE)
#elif !defined(RAK14014) && !defined(M5STACK) && !defined(UNPHONE) && !defined(M5STACK_COREBASIC) && !defined(M5STACK_CORE2)
tft->sleep();
tft->powerSaveOn();
#endif
Expand All @@ -1071,7 +1078,7 @@ void TFTDisplay::sendCommand(uint8_t com)
unphone.backlight(false); // using unPhone library
#endif
#ifdef RAK14014
#elif !defined(M5STACK)
#elif !defined(M5STACK) || !defined(M5STACK_COREBASIC)
tft->setBrightness(0);
#endif
break;
Expand Down Expand Up @@ -1105,7 +1112,7 @@ bool TFTDisplay::hasTouch(void)
{
#ifdef RAK14014
return true;
#elif !defined(M5STACK)
#elif !defined(M5STACK) || !defined(M5STACK_COREBASIC)
return tft->touch() != nullptr;
#else
return false;
Expand All @@ -1124,7 +1131,7 @@ bool TFTDisplay::getTouch(int16_t *x, int16_t *y)
} else {
return false;
}
#elif !defined(M5STACK)
#elif !defined(M5STACK) || !defined(M5STACK_COREBASIC)
return tft->getTouch(x, y);
#else
return false;
Expand Down Expand Up @@ -1153,10 +1160,11 @@ bool TFTDisplay::connect()
#ifdef UNPHONE
unphone.backlight(true); // using unPhone library
#endif

#if !defined(M5STACK_CORE2)
tft->init();
#endif

#if defined(M5STACK)
#if defined(M5STACK) || defined(M5STACK_COREBASIC) || defined(M5STACK_CORE2)
tft->setRotation(0);
#elif defined(RAK14014)
tft->setRotation(1);
Expand Down
Loading
Loading