Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -63,3 +63,4 @@ obj/

sdkconfig
sdkconfig.old
sdkconfig.m5stack-stopwatch
10 changes: 7 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
# The following five lines of boilerplate have to be in your project's
# CMakeLists in this exact order for cmake to work correctly
cmake_minimum_required(VERSION 3.16)
cmake_minimum_required(VERSION 3.21)

include($ENV{IDF_PATH}/tools/cmake/project.cmake)
project(StopWatch-UserDemo)

option(STOPWATCH_MCUI_OPTIMIZE "Compile the MooncakeUI component with -O2" ON)
if(STOPWATCH_MCUI_OPTIMIZE)
idf_component_get_property(mcui_component mooncake-ui COMPONENT_LIB)
target_compile_options(${mcui_component} PRIVATE -O2)
endif()
16 changes: 12 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# M5StopWatch-UserDemo
M5Stack StopWatch user demo for hardware evaluation.
M5Stack StopWatch user demo for hardware evaluation. The same firmware supports the C152 and C152-V11 touch controllers, with a multitouch test under **Settings → Diagnostics** on the V11.

## Build

Expand All @@ -11,12 +11,12 @@ python3 ./fetch_repos.py

### Tool Chains

[ESP-IDF v5.5.4](https://docs.espressif.com/projects/esp-idf/en/v5.5.4/esp32s3/index.html)
[ESP-IDF v5.5.5](https://docs.espressif.com/projects/esp-idf/en/v5.5.5/esp32s3/index.html)

### Build

```bash
idf.py build
idf.py -DIDF_TARGET=esp32s3 build
```

### Flash
Expand All @@ -33,4 +33,12 @@ Incorporated into the *M5StopWatch-UserDemo* project by [Simon J. Stuart](https:
Incorporated into the *M5StopWatch-UserDemo* project by [Simon J. Stuart](https://github.com/LK-Simon) the green power indicator LED will now switch off when the AMOLED display is on. This will save a small amount of power, but also eliminate the distracting green LED when it is not necessary.

## PlatformIO/PIOArduino build support
Incorporated into the *M5StopWatch-UserDemo* project by [Simon J. Stuart](https://github.com/LK-Simon) you can now load the repository folder in Visual Studio Code with either PlatformIO or PIOArduino installed, and build/upload the demo directly to your M5Stack StopWatch device.
Incorporated into the *M5StopWatch-UserDemo* project by [Simon J. Stuart](https://github.com/LK-Simon) you can now load the repository folder in Visual Studio Code with either PlatformIO or PIOArduino installed, and build/upload the demo directly to your M5Stack StopWatch device.

The pinned platform requires Core 6.2 or newer. The command below uses [PIOArduino Core 6.2.0](https://pypi.org/project/pioarduino/6.2.0/).

```bash
pio run -e m5stack-stopwatch
```

See [the SDL simulator instructions](simu/README.md) for desktop builds.
2 changes: 1 addition & 1 deletion dependencies.lock
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,6 @@ direct_dependencies:
- espressif/esp_codec_dev
- espressif/i2c_bus
- idf
manifest_hash: c617373befe8b1fa75c13efe199c02fb007e1c544872d4ec5ecea62d8b7d7b93
manifest_hash: 8b8da793bcfa2f6aeb822ba349c41d89cb77026c31f54a43e541ed21295884ce
target: esp32s3
version: 2.0.0
84 changes: 34 additions & 50 deletions fetch_repos.py
Original file line number Diff line number Diff line change
@@ -1,61 +1,45 @@
import os
import subprocess
import json
import subprocess
from pathlib import Path


def clone_or_update_repo(
repo_url, path, ref=None, with_submodules=False, patch_path=None
):
import os

if not os.path.exists(path):
subprocess.run(["git", "clone", repo_url, path], check=True)
else:
subprocess.run(["git", "-C", path, "fetch"], check=True)

if ref:
subprocess.run(["git", "-C", path, "checkout", ref], check=True)

if with_submodules:
subprocess.run(
["git", "-C", path, "submodule", "update", "--init", "--recursive"],
check=True,
)

# 应用 patch
if patch_path:
patch_full_path = (
patch_path
if os.path.isabs(patch_path)
else os.path.join(os.getcwd(), patch_path)
)
# 使用 git apply --check 先检测补丁是否能应用,避免报错
check_result = subprocess.run(
["git", "-C", path, "apply", "--check", patch_full_path]
)
if check_result.returncode == 0:
subprocess.run(["git", "-C", path, "apply", patch_full_path], check=True)
print(f"Applied patch {patch_path} to {path}")
else:
print(f"Patch {patch_path} cannot be applied cleanly to {path}, skipped.")
PROJECT_DIR = Path(__file__).resolve().parent


def fetch_dependencies():
script_dir = os.path.dirname(os.path.abspath(__file__))
config_path = os.path.join(script_dir, "repos.json")
def git(path, *args, check=True, quiet=False):
return subprocess.run(
["git", "-C", str(path), *args],
check=check,
text=True,
stdout=subprocess.PIPE if quiet else None,
stderr=subprocess.DEVNULL if quiet else None,
)

with open(config_path) as f:
repos = json.load(f)

def fetch_dependencies():
repos = json.loads((PROJECT_DIR / "repos.json").read_text(encoding="utf-8"))
for repo in repos:
repo_path = os.path.join(script_dir, repo["path"])
branch = repo.get("branch")
with_submodules = repo.get("with_submodules", False)
patch = repo.get("patch")
if patch and not os.path.isabs(patch):
patch = os.path.join(script_dir, patch)
clone_or_update_repo(repo["url"], repo_path, branch, with_submodules, patch)
path = PROJECT_DIR / repo["path"]
if not path.exists():
path.parent.mkdir(parents=True, exist_ok=True)
git(PROJECT_DIR, "clone", "--no-checkout", repo["url"], str(path))

ref = repo["branch"] + "^{commit}"
target = git(path, "rev-parse", "--verify", ref, check=False, quiet=True)
if target.returncode:
git(path, "fetch", "--tags", "origin")
target = git(path, "rev-parse", "--verify", ref, quiet=True)
# A no-checkout clone may already have the correct HEAD but an empty worktree.
git(path, "checkout", "--detach", target.stdout.strip())
if repo.get("with_submodules"):
git(path, "submodule", "update", "--init", "--recursive")

if patch := repo.get("patch"):
patch_file = str(PROJECT_DIR / patch)
applied = git(path, "apply", "--reverse", "--check", patch_file, check=False, quiet=True)
if applied.returncode:
git(path, "apply", patch_file)


if __name__ == "__main__":
fetch_dependencies()
fetch_dependencies()
27 changes: 23 additions & 4 deletions main/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
include("${CMAKE_CURRENT_LIST_DIR}/../tools/asset_baker/assets.cmake")
file(GLOB_RECURSE MY_SRCS
"apps/*.c"
"apps/*.cc"
"apps/*.cpp"
"assets/*.c"
"assets/*.cc"
"assets/*.cpp"
"hal/*.c"
"hal/*.cc"
"hal/*.cpp"
Expand All @@ -24,4 +22,25 @@ idf_component_register(
"assets/sfx/boot_sfx.bin"
EMBED_TXTFILES
"hal/utils/config_ap/assets/badge_config_ap.html"
)
)

idf_build_get_property(asset_python PYTHON)
stopwatch_bake_assets(${COMPONENT_LIB} "${asset_python}" "${CMAKE_CURRENT_LIST_DIR}" --rgb565-swapped)
idf_build_get_property(firmware_version PROJECT_VER)
target_compile_definitions(${COMPONENT_LIB} PRIVATE STOPWATCH_FIRMWARE_VERSION="${firmware_version}")
target_include_directories(${COMPONENT_LIB} PRIVATE
"${CMAKE_CURRENT_LIST_DIR}/apps/common/arc_top_clock"
"${CMAKE_CURRENT_LIST_DIR}/apps/common/status_bar")

if(CONFIG_STOPWATCH_LAUNCHER_PROFILE)
target_compile_definitions(${COMPONENT_LIB} PRIVATE STOPWATCH_LAUNCHER_PROFILE=1)
target_include_directories(${COMPONENT_LIB} PRIVATE "${CMAKE_CURRENT_LIST_DIR}/hal/display_probe")
endif()

set(STOPWATCH_LAUNCHER_STRIP_ROWS 16 CACHE STRING "Launcher RGB565 strip height")
set_source_files_properties("apps/app_launcher/view/view.cpp" PROPERTIES
COMPILE_DEFINITIONS "STOPWATCH_LAUNCHER_STRIP_ROWS=${STOPWATCH_LAUNCHER_STRIP_ROWS}")

target_compile_options(${COMPONENT_LIB} PRIVATE
$<$<COMPILE_LANGUAGE:CXX>:-std=gnu++20>
)
33 changes: 33 additions & 0 deletions main/Kconfig.projbuild
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
config STOPWATCH_FFT_VECTOR
bool
default y
select MCUI_RENDER_VECTOR

config STOPWATCH_BADGE_CODECS
bool
default y
select MCUI_RENDER_CODEC_JPEG

menu "StopWatch diagnostics"

config STOPWATCH_DISPLAY_PROBE
bool "Boot into the mooncake-ui display probe"
default n
help
Give the probe exclusive access to the CO5300 and log idle,
local-refresh and full-refresh statistics on the console.

config STOPWATCH_INPUT_PROBE
bool "Log touch and IMU snapshots in the display probe"
depends on STOPWATCH_DISPLAY_PROBE
default n

config STOPWATCH_LAUNCHER_PROFILE
bool "Replay and measure Launcher animations on startup"
depends on !STOPWATCH_DISPLAY_PROBE
default n
help
Replay status-bar and carousel animations through the normal Launcher
and emit buffered frame timings over serial.

endmenu
67 changes: 15 additions & 52 deletions main/apps/app_alarm_clock/app_alarm_clock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,18 @@
* SPDX-License-Identifier: MIT
*/
#include "app_alarm_clock.h"
#include "view/trigger_alarm.h"
#include <icon_clock.h>
#include <hal/hal.h>
#include <mooncake.h>
#include <mooncake_log.h>
#include <assets/assets.h>
#include <smooth_lvgl.hpp>

using namespace mooncake;

AppAlarmClock::AppAlarmClock()
{
setAppInfo().name = "AlarmClock";
setAppInfo().icon = (void*)&icon_clock;
setAppInfo().icon = const_cast<mcui::render::SurfaceView*>(&stopwatch_assets::icon_clock);
}

void AppAlarmClock::onCreate()
Expand All @@ -28,29 +28,17 @@ void AppAlarmClock::onCreate()
return;
}

_alarm_clock->onTriggered().connect([this](const model::AlarmClock::AlarmTriggeredEvent& event) {
std::unique_ptr<view::AlarmTriggerView> trigger_view;
{
LvglLockGuard lock;
trigger_view = std::make_unique<view::AlarmTriggerView>();
trigger_view->init(event.time);
}

GetHAL().startAlarm();
_alarm_clock->setTriggerCallback([](const model::AlarmClock::Time24& time) {
auto& hal = GetHAL();
auto trigger_view = std::make_unique<view::AlarmTriggerView>(time);

// Block until confirmed
while (1) {
GetHAL().feedTheDog();
GetHAL().delay(100);

LvglLockGuard lock;
if (trigger_view->isConfirmed()) {
trigger_view.reset();
break;
}
hal.startAlarm();
while (!trigger_view->update()) {
hal.feedTheDog();
hal.delay(10);
}

GetHAL().stopAlarm();
hal.stopAlarm();
hal.invalidateMooncakeFrame();
});
}

Expand All @@ -60,11 +48,8 @@ void AppAlarmClock::onOpen()

_key_manager = std::make_unique<input::KeyManager>();

LvglLockGuard lock;

if (_alarm_clock) {
_list_view = std::make_unique<view::AlarmListView>(*_alarm_clock);
_list_view->init(lv_screen_active());
_view = std::make_unique<view::AlarmClockView>(*_alarm_clock);
}
}

Expand All @@ -79,26 +64,7 @@ void AppAlarmClock::onRunning()
_alarm_clock->update();
}

LvglLockGuard lock;

if (_list_view) {
_list_view->update();

if (_list_view->consumeAddRequested()) {
_list_view.reset();
_add_view = std::make_unique<view::AlarmAddView>();
_add_view->init(lv_screen_active());
}
}

if (_add_view && _add_view->isConfirmed() && _alarm_clock) {
auto time = _add_view->selectedTime();
_alarm_clock->addAlarm(time, true);

_add_view.reset();
_list_view = std::make_unique<view::AlarmListView>(*_alarm_clock);
_list_view->init(lv_screen_active());
}
if (_view) _view->update();
}

void AppAlarmClock::onSleeping()
Expand All @@ -114,10 +80,7 @@ void AppAlarmClock::onClose()

_key_manager.reset();

LvglLockGuard lock;

_list_view.reset();
_add_view.reset();
_view.reset();
}

void AppAlarmClock::onDestroy()
Expand Down
5 changes: 2 additions & 3 deletions main/apps/app_alarm_clock/app_alarm_clock.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,5 @@ class AppAlarmClock : public mooncake::AppAbility {
private:
std::unique_ptr<input::KeyManager> _key_manager;
std::unique_ptr<model::AlarmClock> _alarm_clock;
std::unique_ptr<view::AlarmListView> _list_view;
std::unique_ptr<view::AlarmAddView> _add_view;
};
std::unique_ptr<view::AlarmClockView> _view;
};
Loading
Loading