Skip to content
Open
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
14 changes: 14 additions & 0 deletions projects/APPLaunch/main/SConstruct
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,18 @@ Import('env')
with open(env['PROJECT_TOOL_S']) as f:
exec(f.read())

def pkg_config_cflags(pkg):
try:
return subprocess.check_output(['pkg-config', '--cflags', pkg], text=True).split()
except Exception:
return []

def pkg_config_ldflags(pkg):
try:
return subprocess.check_output(['pkg-config', '--libs', pkg], text=True).split()
except Exception:
return []

rootfs_path=os.environ.get("CONFIG_TOOLCHAIN_SYSROOT", "")

def wget_github(url):
Expand Down Expand Up @@ -107,6 +119,8 @@ lvgl_component['SRCS'] = list(filter(
SRCS += Glob('hal/*.c*')
# x86
if 'linux_x86_sdl2_config_defaults.mk' in os.environ.get("CONFIG_DEFAULT_FILE", ''):
DEFINITIONS += ['-DHAL_PLATFORM_SDL=1']

lvgl_component['DEFINITIONS'] += pkg_config_cflags("freetype2")
lvgl_component['REQUIREMENTS'] += pkg_config_ldflags("freetype2")

Expand Down
71 changes: 71 additions & 0 deletions projects/Compass/SConstruct
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
from pathlib import Path
import os
import platform
import shutil
import sys

arch = platform.machine()
homebrew_toolchain = "/opt/homebrew/bin"
has_homebrew_aarch64 = os.path.exists(os.path.join(homebrew_toolchain, "aarch64-linux-gnu-gcc"))

version = "v0.0.3"
static_lib = "static_lib"
update = False

if "CardputerZero" in os.environ:
if not os.path.exists("build/config/config_tmp.mk"):
os.makedirs("build/config", exist_ok=True)
with open("build/config/config_tmp.mk", "w") as f:
f.write("CONFIG_V9_5_LV_USE_LINUX_FBDEV=y\n")
f.write("CONFIG_V9_5_LV_DRAW_SW_ASM_NEON=y\n")
f.write("CONFIG_V9_5_LV_USE_DRAW_SW_ASM=1\n")
f.write("CONFIG_V9_5_LV_USE_EVDEV=y\n")
if has_homebrew_aarch64:
f.write(f'CONFIG_TOOLCHAIN_PATH="{homebrew_toolchain}"\n')
f.write('CONFIG_TOOLCHAIN_PREFIX="aarch64-linux-gnu-"\n')
f.write(f'''CONFIG_TOOLCHAIN_SYSROOT="{os.path.join(sys.path[0], "static_lib")}"\n''')
elif arch != "aarch64":
if not os.path.exists("build/config/config_tmp.mk"):
os.makedirs("build/config", exist_ok=True)
with open("build/config/config_tmp.mk", "w") as f:
f.write("CONFIG_V9_5_LV_USE_SDL=y\n")
else:
if not os.path.exists("build/config/config_tmp.mk"):
os.makedirs("build/config", exist_ok=True)
with open("build/config/config_tmp.mk", "w") as f:
f.write("CONFIG_V9_5_LV_USE_LINUX_FBDEV=y\n")
f.write("CONFIG_V9_5_LV_DRAW_SW_ASM_NEON=y\n")
f.write("CONFIG_V9_5_LV_USE_DRAW_SW_ASM=1\n")
f.write("CONFIG_V9_5_LV_USE_EVDEV=y\n")

local_path = Path(os.getcwd())
sdk_path = local_path.parent.parent / "SDK"
os.environ["SDK_PATH"] = str(sdk_path)
os.environ["EXT_COMPONENTS_PATH"] = str(sdk_path.parent / "ext_components")

env = SConscript(
str(sdk_path / "tools" / "scons" / "project.py"),
variant_dir=os.getcwd(),
duplicate=0,
)

if not os.path.exists(static_lib):
update = True
else:
try:
with open(str(Path(static_lib) / "version"), "r") as f:
if version != f.read().strip():
update = True
except Exception:
update = True

if update and "CardputerZero" in os.environ:
with open(env["PROJECT_TOOL_S"]) as f:
exec(f.read())
down_url = "https://github.com/dianjixz/M5CardputerZero-UserDemo/releases/download/{}/sdk_bsp.tar.gz".format(
version
)
down_path = check_wget_down(down_url, "static_lib_{}.tar.gz".format(version))
if os.path.exists(static_lib):
shutil.rmtree(static_lib)
shutil.move(down_path, static_lib)
6 changes: 6 additions & 0 deletions projects/Compass/applications/Compass.desktop
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[Desktop Entry]
Name=Compass
Exec=/usr/share/Compass/bin/M5CardputerZero-Compass
Terminal=false
Icon=share/images/Compass.png
Type=Application
16 changes: 16 additions & 0 deletions projects/Compass/config_defaults.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
CONFIG_LVGL_COMPONENT_ENABLED=y
CONFIG_LVGL_9_5_SRC=y
CONFIG_V9_5_LV_USE_CLIB_MALLOC=y
CONFIG_V9_5_LV_USE_CLIB_STRING=y
CONFIG_V9_5_LV_USE_CLIB_SPRINTF=y

CONFIG_V9_5_LV_FONT_MONTSERRAT_10=y
CONFIG_V9_5_LV_FONT_MONTSERRAT_12=y
CONFIG_V9_5_LV_FONT_MONTSERRAT_14=y
CONFIG_V9_5_LV_FONT_MONTSERRAT_16=y
CONFIG_V9_5_LV_FONT_MONTSERRAT_26=y
CONFIG_V9_5_LV_FONT_DEFAULT_MONTSERRAT_14=y

CONFIG_V9_5_LV_USE_FREETYPE=y
CONFIG_V9_5_LV_FREETYPE_CACHE_FT_GLYPH_CNT=64

25 changes: 25 additions & 0 deletions projects/Compass/linux_x86_cross_cp0_config_defaults.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@

CONFIG_TOOLCHAIN_PREFIX="aarch64-linux-gnu-"

CONFIG_LVGL_COMPONENT_ENABLED=y
CONFIG_LVGL_9_5_SRC=y

CONFIG_V9_5_LV_USE_CLIB_MALLOC=y
CONFIG_V9_5_LV_USE_CLIB_STRING=y
CONFIG_V9_5_LV_USE_CLIB_SPRINTF=y

CONFIG_V9_5_LV_FONT_MONTSERRAT_10=y
CONFIG_V9_5_LV_FONT_MONTSERRAT_12=y
CONFIG_V9_5_LV_FONT_MONTSERRAT_14=y
CONFIG_V9_5_LV_FONT_MONTSERRAT_16=y
CONFIG_V9_5_LV_FONT_MONTSERRAT_26=y
CONFIG_V9_5_LV_FONT_DEFAULT_MONTSERRAT_14=y


CONFIG_V9_5_LV_USE_LINUX_FBDEV=y
CONFIG_V9_5_LV_DRAW_SW_ASM_NEON=y
CONFIG_V9_5_LV_USE_DRAW_SW_ASM=1
CONFIG_V9_5_LV_USE_EVDEV=y
CONFIG_V9_5_LV_OS_PTHREAD=y
CONFIG_V9_5_LV_DRAW_THREAD_STACK_SIZE=65536
CONFIG_V9_5_LV_DRAW_THREAD_PRIO=3
22 changes: 22 additions & 0 deletions projects/Compass/linux_x86_sdl2_config_defaults.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@

# CONFIG_TOOLCHAIN_PREFIX="aarch64-linux-gnu-"

CONFIG_LVGL_COMPONENT_ENABLED=y
CONFIG_LVGL_9_5_SRC=y

CONFIG_V9_5_LV_USE_CLIB_MALLOC=y
CONFIG_V9_5_LV_USE_CLIB_STRING=y
CONFIG_V9_5_LV_USE_CLIB_SPRINTF=y

CONFIG_V9_5_LV_FONT_MONTSERRAT_10=y
CONFIG_V9_5_LV_FONT_MONTSERRAT_12=y
CONFIG_V9_5_LV_FONT_MONTSERRAT_14=y
CONFIG_V9_5_LV_FONT_MONTSERRAT_16=y
CONFIG_V9_5_LV_FONT_MONTSERRAT_26=y
CONFIG_V9_5_LV_FONT_DEFAULT_MONTSERRAT_14=y


CONFIG_V9_5_LV_USE_SDL=y
CONFIG_V9_5_LV_OS_PTHREAD=y
CONFIG_V9_5_LV_DRAW_THREAD_STACK_SIZE=65536
CONFIG_V9_5_LV_DRAW_THREAD_PRIO=3
113 changes: 113 additions & 0 deletions projects/Compass/main/SConstruct
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
import os

Import("env")
with open(env["PROJECT_TOOL_S"]) as f:
exec(f.read())

if "CONFIG_TOOLCHAIN_PREFIX" in os.environ:
env["RANLIB"] = '${_concat(GCCPREFIX, "ranlib", GCCSUFFIX, __env__)}'
env["RANLIBCOM"] = "$RANLIB $TARGET"
env["ARFLAGS"] = ["rcs"]

SRCS = Glob("src/*.c*")
INCLUDE = [ADir("."), ADir("include")]
PRIVATE_INCLUDE = []
REQUIREMENTS = ["lvgl_component", "pthread", "freetype"]
if "CONFIG_V9_5_LV_USE_SDL" not in os.environ:
REQUIREMENTS += ["input", "xkbcommon", "udev"]
STATIC_LIB = []
DYNAMIC_LIB = []
DEFINITIONS = []
DEFINITIONS_PRIVATE = []
LDFLAGS = []
LINK_SEARCH_PATH = []
STATIC_FILES = []
MULTIARCH_INCLUDE = None

if "CONFIG_TOOLCHAIN_SYSROOT" in os.environ:
sysroot = os.environ["CONFIG_TOOLCHAIN_SYSROOT"].strip('"')
multiarch_include = os.path.join(sysroot, "usr", "include", "aarch64-linux-gnu")
if os.path.isdir(multiarch_include):
INCLUDE += [multiarch_include]
MULTIARCH_INCLUDE = multiarch_include
multiarch_lib = os.path.join(sysroot, "usr", "lib", "aarch64-linux-gnu")
if os.path.isdir(multiarch_lib):
LDFLAGS += [f"-B{multiarch_lib}", f"-Wl,-rpath-link,{multiarch_lib}"]
LINK_SEARCH_PATH += [multiarch_lib]

lvgl_component = list(filter(lambda x: x["target"] == "lvgl_component", env["COMPONENTS"]))[0]
if MULTIARCH_INCLUDE:
for component in env["COMPONENTS"]:
component["INCLUDE"] += [MULTIARCH_INCLUDE]

# FreeType support
freetype_includes = []
freetype_link_paths = []
if "CONFIG_TOOLCHAIN_SYSROOT" in os.environ:
sysroot = os.environ["CONFIG_TOOLCHAIN_SYSROOT"].strip('"')
ft_inc = os.path.join(sysroot, "usr", "include", "freetype2")
ft_lib = os.path.join(sysroot, "usr", "lib", "aarch64-linux-gnu")
if os.path.isdir(ft_inc):
freetype_includes += [ft_inc]
if os.path.isdir(ft_lib):
freetype_link_paths += [ft_lib]

# Also check project local static_lib (for cross-compilation or local sysroot)
local_static_lib = os.path.join(os.path.dirname(str(Dir('.').srcnode())), "static_lib")
local_ft_inc = os.path.join(local_static_lib, "usr", "include", "freetype2")
local_ft_lib = os.path.join(local_static_lib, "usr", "lib", "aarch64-linux-gnu")
if os.path.isdir(local_ft_inc):
freetype_includes += [local_ft_inc]
if os.path.isdir(local_ft_lib):
freetype_link_paths += [local_ft_lib]

# Fallback to system paths
if not freetype_includes:
for ft_inc in ["/usr/include/freetype2", "/usr/local/include/freetype2"]:
if os.path.exists(ft_inc):
freetype_includes += [ft_inc]
if not freetype_link_paths:
for ft_lib in ["/usr/lib", "/usr/local/lib"]:
if os.path.exists(ft_lib):
freetype_link_paths += [ft_lib]

for component in env["COMPONENTS"]:
component["INCLUDE"] += freetype_includes
component["LINK_SEARCH_PATH"] += freetype_link_paths

if "CONFIG_V9_5_LV_USE_SDL" in os.environ:
lvgl_component["REQUIREMENTS"] += ["SDL2"]
lvgl_component["INCLUDE"] += ["/usr/include/SDL2"]
for sdl_include in [
"/opt/homebrew/include",
"/opt/homebrew/include/SDL2",
"/usr/local/include",
"/usr/local/include/SDL2",
]:
if os.path.exists(sdl_include):
lvgl_component["INCLUDE"] += [sdl_include]
for sdl_lib in ["/opt/homebrew/lib", "/usr/local/lib"]:
if os.path.exists(sdl_lib):
lvgl_component["LINK_SEARCH_PATH"] += [sdl_lib]
lvgl_component["DEFINITIONS"] += ["-D_REENTRANT"]
for src in list(lvgl_component["SRCS"]):
if "lv_sdl_keyboard.c" in str(src):
lvgl_component["SRCS"].remove(src)

env["COMPONENTS"].append(
{
"target": "M5CardputerZero-Compass",
"SRCS": SRCS,
"INCLUDE": INCLUDE,
"PRIVATE_INCLUDE": PRIVATE_INCLUDE,
"REQUIREMENTS": REQUIREMENTS,
"STATIC_LIB": STATIC_LIB,
"DYNAMIC_LIB": DYNAMIC_LIB,
"DEFINITIONS": DEFINITIONS,
"DEFINITIONS_PRIVATE": DEFINITIONS_PRIVATE,
"LDFLAGS": LDFLAGS,
"LINK_SEARCH_PATH": LINK_SEARCH_PATH,
"STATIC_FILES": STATIC_FILES,
"REGISTER": "project",
}
)
30 changes: 30 additions & 0 deletions projects/Compass/main/include/app_font.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#pragma once

#include "lvgl/lvgl.h"

namespace ui::font {

/* codemap used by font 'assets/svgfont.ttf' (Unicode Private Use Area) */
/* C++ compiler automatically converts \uXXXX to correct UTF-8 bytes */
inline constexpr const char* ICON_EXIT = "\uEA01"; // .svgfont-exit
inline constexpr const char* ICON_FAST_FORWARD = "\uEA02"; // .svgfont-fast_forward
inline constexpr const char* ICON_FAST_REWIND = "\uEA03"; // .svgfont-fast_rewind
inline constexpr const char* ICON_LIST = "\uEA04"; // .svgfont-list
inline constexpr const char* ICON_PAUSE = "\uEA05"; // .svgfont-pause
inline constexpr const char* ICON_PLAY = "\uEA06"; // .svgfont-play
inline constexpr const char* ICON_RECORD = "\uEA07"; // .svgfont-record
inline constexpr const char* ICON_SAMPLE_RATE = "\uEA08"; // .svgfont-sample_rate
inline constexpr const char* ICON_SPEED = "\uEA09"; // .svgfont-speed
inline constexpr const char* ICON_STOP = "\uEA0A"; // .svgfont-stop

class AppFont {
public:
static void init();
static void deinit();
static lv_font_t* svgfont(int32_t size);

private:
AppFont() = delete;
};

} // namespace ui::font
Loading