From 448553120b63f13f48593f1fa681ae2b06197065 Mon Sep 17 00:00:00 2001 From: Guo-Rong <5484552+gkoh@users.noreply.github.com> Date: Fri, 15 Mar 2024 10:09:48 +1030 Subject: [PATCH 1/4] Change platform macros to match M5Unified and M5GFX libraries. Also: - update M5ez library dependency - disable IMU, mic and speaker - cleanup display rotation --- lib/M5ez/library.json | 2 +- lib/M5ez/src/M5ez.cpp | 16 ++++++---------- lib/M5ez/src/M5ez.h | 6 +++--- platformio.ini | 8 ++++---- src/furble.cpp | 4 ++-- 5 files changed, 16 insertions(+), 20 deletions(-) diff --git a/lib/M5ez/library.json b/lib/M5ez/library.json index 9c81926..1ff9100 100644 --- a/lib/M5ez/library.json +++ b/lib/M5ez/library.json @@ -12,7 +12,7 @@ "url": "https://github.com/ropg/M5ez" }, "dependencies": { - "name": "M5Stack" + "name": "M5Unified" }, "version": "2.1.2", "framework": "arduino", diff --git a/lib/M5ez/src/M5ez.cpp b/lib/M5ez/src/M5ez.cpp index da364eb..bf0a813 100644 --- a/lib/M5ez/src/M5ez.cpp +++ b/lib/M5ez/src/M5ez.cpp @@ -764,10 +764,6 @@ void ezSettings::begin() { ez.settings.menuObj.addItem("Theme chooser", ez.theme->menu); } ez.settings.menuObj.addItem("Factory defaults", ez.settings.defaults); - -#ifdef M5STACK_CORE2 - M5.Lcd.setRotation(1); -#endif } void ezSettings::menu() { @@ -836,7 +832,6 @@ void ezBacklight::menu() { _brightness = 48; } float p = float(_brightness) / 2.48; - Serial.println(_brightness); bl.value(p); M5.Display.setBrightness(_brightness); if (b == "Back") @@ -901,11 +896,7 @@ uint16_t ezBacklight::loop(void *private_data) { if (M5.BtnA.wasClicked() || M5.BtnB.wasClicked()) break; ez.yield(); -#if M5STACK_CORE2 - delay(100); -#else M5.Power.lightSleep(100000); -#endif } ez.buttons.releaseWait(); // Make sure the key pressed to wake display gets ignored M5.Display.setBrightness(_brightness); @@ -2229,8 +2220,13 @@ long M5ez::_text_cursor_millis; void M5ez::begin() { auto cfg = M5.config(); + cfg.internal_imu = false; + cfg.internal_spk = false; + cfg.internal_mic = false; M5.begin(cfg); +#if defined(ARDUINO_M5STICK_C) || defined(ARDUINO_M5STICK_C_PLUS) M5.Lcd.setRotation(3); +#endif ezTheme::begin(); ez.screen.begin(); ez.settings.begin(); @@ -2862,7 +2858,7 @@ void M5ez::setFont(const GFXfont *font) { } int16_t M5ez::fontHeight() { -#if M5STICKC_PLUS || M5STACK_CORE2 +#if ARDUINO_M5STICK_C_PLUS || ARDUINO_M5STACK_CORE_ESP32 return M5.Lcd.fontHeight(M5.Lcd.getFont()); #else return 11; diff --git a/lib/M5ez/src/M5ez.h b/lib/M5ez/src/M5ez.h index 01edce9..3170229 100644 --- a/lib/M5ez/src/M5ez.h +++ b/lib/M5ez/src/M5ez.h @@ -61,7 +61,7 @@ #define NO_COLOR TFT_TRANSPARENT -#ifdef M5STICKC_PLUS +#if defined(ARDUINO_M5STICK_C_PLUS) #define TFT_W 240 #define TFT_H 135 #define TFT_FONT sans16 @@ -70,7 +70,7 @@ #define TFT_RADIUS 8 #endif -#ifdef M5STICKC +#if defined(ARDUINO_M5STICK_C) #define TFT_W 160 #define TFT_H 80 #define TFT_FONT hzk16 @@ -79,7 +79,7 @@ #define TFT_RADIUS 3 #endif -#ifdef M5STACK_CORE2 +#if defined(ARDUINO_M5STACK_CORE_ESP32) || defined(ARDUINO_M5STACK_CORE2) #define TFT_W 320 #define TFT_H 240 #define TFT_FONT (&FreeMono12pt7b) diff --git a/platformio.ini b/platformio.ini index adf77fe..6f6e382 100644 --- a/platformio.ini +++ b/platformio.ini @@ -13,16 +13,16 @@ lib_deps = [env:m5stick-c] board = m5stick-c -build_flags = ${furble.build_flags} -D M5STICKC +build_flags = ${furble.build_flags} -D ARDUINO_M5STICK_C [env:m5stick-c-plus] board = m5stick-c -build_flags = ${furble.build_flags} -D M5STICKC_PLUS +build_flags = ${furble.build_flags} -D ARDUINO_M5STICK_C_PLUS [env:m5stack-core] board = m5stack-core-esp32 -build_flags = ${furble.build_flags} -D M5STACK_CORE2 +build_flags = ${furble.build_flags} -D ARDUINO_M5STACK_CORE_ESP32 [env:m5stack-core2] board = m5stack-core2 -build_flags = ${furble.build_flags} -D M5STACK_CORE2 +build_flags = ${furble.build_flags} -D ARDUINO_M5STACK_CORE2 diff --git a/src/furble.cpp b/src/furble.cpp index d45489b..28ed3b5 100644 --- a/src/furble.cpp +++ b/src/furble.cpp @@ -58,14 +58,14 @@ static void show_shutter_control(bool shutter_locked, unsigned long lock_start_m char duration[8] = {0x0}; snprintf(duration, 8, "%02lu:%02lu", minutes, seconds); -#ifdef M5STACK_CORE2 +#if defined(ARDUINO_M5STACK_CORE_ESP32) || defined(ARDUINO_M5STACK_CORE2) ez.msgBox("Remote Shutter", "Shutter Locked|" + String(duration), "Unlock#Unlock#Back", false); #else ez.msgBox("Remote Shutter", "Shutter Locked|" + String(duration) + "||Back: Power", "Unlock#Unlock", false); #endif } else { -#ifdef M5STACK_CORE2 +#if defined(ARDUINO_M5STACK_CORE_ESP32) || defined(ARDUINO_M5STACK_CORE2) ez.msgBox("Remote Shutter", "Lock: Focus+Release", "Release#Focus#Back", false); #else ez.msgBox("Remote Shutter", "Lock: Focus+Release|Back: Power", "Release#Focus", false); From 5c0093aa8950e0447868520654ed3ea5a4f2dedd Mon Sep 17 00:00:00 2001 From: Guo-Rong <5484552+gkoh@users.noreply.github.com> Date: Thu, 21 Mar 2024 15:33:14 +1030 Subject: [PATCH 2/4] Fix M5StickC Plus2 backlight flicker during idle. The M5StickC Plus and Core devices use PWM to control backlight, unlike the M5StickC and M5StickCPlus. During lightSleep() PWM is inactive, so backlight control goes crazy, instead, reduce CPU frequency and just delay, avoid lightSleep. Enable compiler warnings, fix warnings. --- lib/M5ez/src/M5ez.cpp | 30 ++++++++++++++++++++++++++++-- lib/M5ez/src/M5ez.h | 6 +++--- platformio.ini | 10 +++++----- src/furble.cpp | 8 ++++---- src/furble_gps.cpp | 9 ++++++++- src/interval.cpp | 4 ++-- src/spinner.cpp | 2 ++ 7 files changed, 52 insertions(+), 17 deletions(-) diff --git a/lib/M5ez/src/M5ez.cpp b/lib/M5ez/src/M5ez.cpp index bf0a813..7995c74 100644 --- a/lib/M5ez/src/M5ez.cpp +++ b/lib/M5ez/src/M5ez.cpp @@ -887,18 +887,44 @@ void ezBacklight::activity() { _last_activity = millis(); } +void changeCpuPower(bool reduce) { + switch (M5.getBoard()) { + case m5::board_t::board_M5StickC: + case m5::board_t::board_M5StickCPlus: + // do nothing, lightSleep() works with backlight control + break; + default: + // Backlight is PWM controlled, lightSleep() stops PWM + if (reduce) { + setCpuFrequencyMhz(10); + } else { + setCpuFrequencyMhz(80); + } + } +} + uint16_t ezBacklight::loop(void *private_data) { if (!_backlight_off && _inactivity) { if (millis() > _last_activity + 30000 * _inactivity) { _backlight_off = true; M5.Display.setBrightness(64); + changeCpuPower(true); while (true) { if (M5.BtnA.wasClicked() || M5.BtnB.wasClicked()) break; ez.yield(); - M5.Power.lightSleep(100000); + switch (M5.getBoard()) { + case m5::board_t::board_M5StickC: + case m5::board_t::board_M5StickCPlus: + M5.Power.lightSleep(100000); + break; + default: + // PWM inactive during lightSleep, thus display backlight not controlled + delay(100); + } } ez.buttons.releaseWait(); // Make sure the key pressed to wake display gets ignored + changeCpuPower(false); M5.Display.setBrightness(_brightness); activity(); _backlight_off = false; @@ -2224,7 +2250,7 @@ void M5ez::begin() { cfg.internal_spk = false; cfg.internal_mic = false; M5.begin(cfg); -#if defined(ARDUINO_M5STICK_C) || defined(ARDUINO_M5STICK_C_PLUS) +#if ARDUINO_M5STICK_C || ARDUINO_M5STICK_C_PLUS M5.Lcd.setRotation(3); #endif ezTheme::begin(); diff --git a/lib/M5ez/src/M5ez.h b/lib/M5ez/src/M5ez.h index 3170229..19848cd 100644 --- a/lib/M5ez/src/M5ez.h +++ b/lib/M5ez/src/M5ez.h @@ -61,7 +61,7 @@ #define NO_COLOR TFT_TRANSPARENT -#if defined(ARDUINO_M5STICK_C_PLUS) +#if ARDUINO_M5STICK_C_PLUS #define TFT_W 240 #define TFT_H 135 #define TFT_FONT sans16 @@ -70,7 +70,7 @@ #define TFT_RADIUS 8 #endif -#if defined(ARDUINO_M5STICK_C) +#if ARDUINO_M5STICK_C #define TFT_W 160 #define TFT_H 80 #define TFT_FONT hzk16 @@ -79,7 +79,7 @@ #define TFT_RADIUS 3 #endif -#if defined(ARDUINO_M5STACK_CORE_ESP32) || defined(ARDUINO_M5STACK_CORE2) +#if ARDUINO_M5STACK_CORE_ESP32 || ARDUINO_M5STACK_CORE2 #define TFT_W 320 #define TFT_H 240 #define TFT_FONT (&FreeMono12pt7b) diff --git a/platformio.ini b/platformio.ini index 6f6e382..dc82b4a 100644 --- a/platformio.ini +++ b/platformio.ini @@ -1,5 +1,5 @@ [furble] -build_flags = -D FURBLE_VERSION=\"${sysenv.FURBLE_VERSION}\" +build_flags = -Wall -D FURBLE_VERSION=\"${sysenv.FURBLE_VERSION}\" [env] platform = espressif32 @@ -13,16 +13,16 @@ lib_deps = [env:m5stick-c] board = m5stick-c -build_flags = ${furble.build_flags} -D ARDUINO_M5STICK_C +build_flags = ${furble.build_flags} -D ARDUINO_M5STICK_C=1 [env:m5stick-c-plus] board = m5stick-c -build_flags = ${furble.build_flags} -D ARDUINO_M5STICK_C_PLUS +build_flags = ${furble.build_flags} -D ARDUINO_M5STICK_C_PLUS=1 [env:m5stack-core] board = m5stack-core-esp32 -build_flags = ${furble.build_flags} -D ARDUINO_M5STACK_CORE_ESP32 +build_flags = ${furble.build_flags} -D ARDUINO_M5STACK_CORE_ESP32=1 [env:m5stack-core2] board = m5stack-core2 -build_flags = ${furble.build_flags} -D ARDUINO_M5STACK_CORE2 +build_flags = ${furble.build_flags} -D ARDUINO_M5STACK_CORE2=1 diff --git a/src/furble.cpp b/src/furble.cpp index 28ed3b5..50c1686 100644 --- a/src/furble.cpp +++ b/src/furble.cpp @@ -55,17 +55,17 @@ static void show_shutter_control(bool shutter_locked, unsigned long lock_start_m unsigned long seconds = (total_ms / 1000) % 60; prev_update_ms = now; - char duration[8] = {0x0}; - snprintf(duration, 8, "%02lu:%02lu", minutes, seconds); + char duration[16] = {0x0}; + snprintf(duration, 16, "%02lu:%02lu", minutes, seconds); -#if defined(ARDUINO_M5STACK_CORE_ESP32) || defined(ARDUINO_M5STACK_CORE2) +#if ARDUINO_M5STACK_CORE_ESP32 || ARDUINO_M5STACK_CORE2 ez.msgBox("Remote Shutter", "Shutter Locked|" + String(duration), "Unlock#Unlock#Back", false); #else ez.msgBox("Remote Shutter", "Shutter Locked|" + String(duration) + "||Back: Power", "Unlock#Unlock", false); #endif } else { -#if defined(ARDUINO_M5STACK_CORE_ESP32) || defined(ARDUINO_M5STACK_CORE2) +#if ARDUINO_M5STACK_CORE_ESP32 || ARDUINO_M5STACK_CORE2 ez.msgBox("Remote Shutter", "Lock: Focus+Release", "Release#Focus#Back", false); #else ez.msgBox("Remote Shutter", "Lock: Focus+Release|Back: Power", "Release#Focus", false); diff --git a/src/furble_gps.cpp b/src/furble_gps.cpp index 4c845ce..d4b69ac 100644 --- a/src/furble_gps.cpp +++ b/src/furble_gps.cpp @@ -8,6 +8,13 @@ #include "settings.h" static const uint32_t GPS_BAUD = 9600; +#if ARDUINO_M5STACK_CORE_ESP32 || ARDUINO_M5STACK_CORE2 +static const int8_t GPS_RX = 22; +static const int8_t GPS_TX = 21; +#else +static const int8_t GPS_RX = 33; +static const int8_t GPS_TX = 32; +#endif static const uint16_t GPS_SERVICE_MS = 250; static const uint32_t GPS_MAX_AGE_MS = 60 * 1000; @@ -106,7 +113,7 @@ static uint16_t current_service(void *private_data) { void furble_gps_init(void) { furble_gps_enable = settings_load_gps(); - Serial2.begin(GPS_BAUD, SERIAL_8N1, 33, 32); + Serial2.begin(GPS_BAUD, SERIAL_8N1, GPS_RX, GPS_TX); uint8_t width = 4 * M5.Lcd.textWidth("5") + ez.theme->header_hmargin * 2; ez.header.insert(CURRENT_POSITION, "current", width, current_draw_widget); diff --git a/src/interval.cpp b/src/interval.cpp index 88c93e8..84c78f8 100644 --- a/src/interval.cpp +++ b/src/interval.cpp @@ -33,6 +33,8 @@ static void display_interval_msg(interval_state_t state, case INTERVAL_DELAY: statestr = "DELAY"; break; + case INTERVAL_EXIT: + break; } unsigned long rem = next - now; @@ -65,8 +67,6 @@ static void do_interval(FurbleCtx *fctx, interval_t *interval) { const unsigned long config_shutter = sv2ms(&interval->shutter); unsigned int icount = 0; - unsigned long idelay = 0; - unsigned long ishutter = 0; interval_state_t state = INTERVAL_SHUTTER_OPEN; diff --git a/src/spinner.cpp b/src/spinner.cpp index 1ef39ff..7c829f1 100644 --- a/src/spinner.cpp +++ b/src/spinner.cpp @@ -238,6 +238,8 @@ unsigned long sv2ms(SpinValue *sv) { return (sv->value * 1000); case SPIN_UNIT_MS: return (sv->value); + default: + return 0; } return 0; } From 268db27dbd639c504f297db25908bf5dd8a6aab8 Mon Sep 17 00:00:00 2001 From: Guo-Rong <5484552+gkoh@users.noreply.github.com> Date: Thu, 21 Mar 2024 15:47:12 +1030 Subject: [PATCH 3/4] Appease clang-format. --- lib/M5ez/src/M5ez.cpp | 10 +++++----- src/furble_gps.cpp | 8 ++++---- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/lib/M5ez/src/M5ez.cpp b/lib/M5ez/src/M5ez.cpp index 7995c74..4d1aab9 100644 --- a/lib/M5ez/src/M5ez.cpp +++ b/lib/M5ez/src/M5ez.cpp @@ -913,15 +913,15 @@ uint16_t ezBacklight::loop(void *private_data) { if (M5.BtnA.wasClicked() || M5.BtnB.wasClicked()) break; ez.yield(); - switch (M5.getBoard()) { + switch (M5.getBoard()) { case m5::board_t::board_M5StickC: case m5::board_t::board_M5StickCPlus: M5.Power.lightSleep(100000); - break; - default: + break; + default: // PWM inactive during lightSleep, thus display backlight not controlled - delay(100); - } + delay(100); + } } ez.buttons.releaseWait(); // Make sure the key pressed to wake display gets ignored changeCpuPower(false); diff --git a/src/furble_gps.cpp b/src/furble_gps.cpp index d4b69ac..950c509 100644 --- a/src/furble_gps.cpp +++ b/src/furble_gps.cpp @@ -9,11 +9,11 @@ static const uint32_t GPS_BAUD = 9600; #if ARDUINO_M5STACK_CORE_ESP32 || ARDUINO_M5STACK_CORE2 -static const int8_t GPS_RX = 22; -static const int8_t GPS_TX = 21; +static const int8_t GPS_RX = 22; +static const int8_t GPS_TX = 21; #else -static const int8_t GPS_RX = 33; -static const int8_t GPS_TX = 32; +static const int8_t GPS_RX = 33; +static const int8_t GPS_TX = 32; #endif static const uint16_t GPS_SERVICE_MS = 250; static const uint32_t GPS_MAX_AGE_MS = 60 * 1000; From 6cc0525e03693ccc9baccb95ddf9fa36bc6babd1 Mon Sep 17 00:00:00 2001 From: Guo-Rong <5484552+gkoh@users.noreply.github.com> Date: Thu, 21 Mar 2024 16:12:07 +1030 Subject: [PATCH 4/4] Update platformio version. --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index 21c6546..743c865 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1 +1 @@ -platformio==6.1.5 +platformio==6.1.13