first commit
This commit is contained in:
commit
5893b00dd2
1669 changed files with 1982740 additions and 0 deletions
|
|
@ -0,0 +1,41 @@
|
|||
{
|
||||
"build": {
|
||||
"arduino": {
|
||||
"memory_type": "qio_opi",
|
||||
"ldscript": "esp32s3_out.ld",
|
||||
"partitions": "default_8MB.csv"
|
||||
},
|
||||
"core": "esp32",
|
||||
"extra_flags": [
|
||||
"-DARDUINO_M5STACK_ATOMS3R",
|
||||
"-DBOARD_HAS_PSRAM",
|
||||
"-DARDUINO_USB_MODE=1",
|
||||
"-DARDUINO_USB_CDC_ON_BOOT=1",
|
||||
"-DARDUINO_RUNNING_CORE=1",
|
||||
"-DARDUINO_EVENT_RUNNING_CORE=1"
|
||||
],
|
||||
"f_cpu": "240000000L",
|
||||
"f_flash": "80000000L",
|
||||
"flash_mode": "dio",
|
||||
"mcu": "esp32s3",
|
||||
"variant": "m5stack_atoms3"
|
||||
},
|
||||
"connectivity": [
|
||||
"bluetooth",
|
||||
"wifi"
|
||||
],
|
||||
"frameworks": [
|
||||
"arduino",
|
||||
"espidf"
|
||||
],
|
||||
"name": "M5Stack AtomS3R",
|
||||
"upload": {
|
||||
"flash_size": "8MB",
|
||||
"maximum_ram_size": 327680,
|
||||
"maximum_size": 8388608,
|
||||
"require_upload_port": true,
|
||||
"speed": 460800
|
||||
},
|
||||
"url": "https://docs.m5stack.com/en/core/AtomS3R",
|
||||
"vendor": "M5Stack"
|
||||
}
|
||||
|
|
@ -0,0 +1,33 @@
|
|||
{
|
||||
"build": {
|
||||
"core": "esp32",
|
||||
"extra_flags": [
|
||||
"-DARDUINO_M5STACK_NANOC6"
|
||||
],
|
||||
"f_cpu": "160000000L",
|
||||
"f_flash": "80000000L",
|
||||
"flash_mode": "qio",
|
||||
"mcu": "esp32c6",
|
||||
"variant": "esp32c6"
|
||||
},
|
||||
"connectivity": [
|
||||
"wifi"
|
||||
],
|
||||
"debug": {
|
||||
"openocd_target": "esp32c6.cfg"
|
||||
},
|
||||
"frameworks": [
|
||||
"arduino",
|
||||
"espidf"
|
||||
],
|
||||
"name": "M5Stack NanoC6",
|
||||
"upload": {
|
||||
"flash_size": "4MB",
|
||||
"maximum_ram_size": 327680,
|
||||
"maximum_size": 4194384,
|
||||
"require_upload_port": true,
|
||||
"speed": 460800
|
||||
},
|
||||
"url": "https://docs.m5stack.com/en/core/M5NanoC6",
|
||||
"vendor": "M5Stack"
|
||||
}
|
||||
|
|
@ -0,0 +1,40 @@
|
|||
{
|
||||
"build": {
|
||||
"arduino":{
|
||||
"ldscript": "esp32_out.ld",
|
||||
"partitions": "default_8MB.csv"
|
||||
},
|
||||
"core": "esp32",
|
||||
"extra_flags": [
|
||||
"-DM5STACK_M5STICK_CPLUS2",
|
||||
"-DBOARD_HAS_PSRAM",
|
||||
"-mfix-esp32-psram-cache-issue",
|
||||
"-mfix-esp32-psram-cache-strategy=memw",
|
||||
"-DARDUINO_RUNNING_CORE=1",
|
||||
"-DARDUINO_EVENT_RUNNING_CORE=1"
|
||||
],
|
||||
"f_cpu": "240000000L",
|
||||
"f_flash": "80000000L",
|
||||
"flash_mode": "dio",
|
||||
"mcu": "esp32",
|
||||
"variant": "m5stick_c"
|
||||
},
|
||||
"connectivity": [
|
||||
"wifi",
|
||||
"bluetooth"
|
||||
],
|
||||
"frameworks": [
|
||||
"arduino",
|
||||
"espidf"
|
||||
],
|
||||
"name": "M5Stick-CPlus2",
|
||||
"upload": {
|
||||
"flash_size": "8MB",
|
||||
"maximum_ram_size": 327680,
|
||||
"maximum_size": 8388608,
|
||||
"require_upload_port": true,
|
||||
"speed": 1500000
|
||||
},
|
||||
"url": "https://docs.m5stack.com/en/core/M5StickC%20PLUS2",
|
||||
"vendor": "M5Stack"
|
||||
}
|
||||
21
libraries/M5UnitUnified/pio_project/custom_script.py
Normal file
21
libraries/M5UnitUnified/pio_project/custom_script.py
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
# Remove compile target
|
||||
Import("env")
|
||||
|
||||
EXCLUDE_FILES = (env.GetProjectOption("custom_exclude_src_files") or []).split(' ')
|
||||
|
||||
|
||||
def skip_from_build(node):
|
||||
src_path = node.get_abspath()
|
||||
#filename = os.path.basename(src_path)
|
||||
|
||||
#print(EXCLUDE_FILES)
|
||||
#print('>>>> {}'.format(src_path))
|
||||
# for ef in EXCLUDE_FILES:
|
||||
# if 'I2C_Class.cpp' in src_path and 'I2C_Class.cpp' in ef:
|
||||
# print('>>>> {} {}'.format(src_path, ef))
|
||||
|
||||
if any(ef in src_path for ef in EXCLUDE_FILES):
|
||||
return None
|
||||
return node
|
||||
|
||||
env.AddBuildMiddleware(skip_from_build, "*.cpp")
|
||||
274
libraries/M5UnitUnified/pio_project/platformio.ini
Normal file
274
libraries/M5UnitUnified/pio_project/platformio.ini
Normal file
|
|
@ -0,0 +1,274 @@
|
|||
;-----------------------------------------------------------------------
|
||||
; For UnitTest and examples using M5UnitUnified local sources
|
||||
;-----------------------------------------------------------------------
|
||||
[platformio]
|
||||
src_dir = ../src
|
||||
|
||||
[env]
|
||||
build_flags = -Wall -Wextra -Wreturn-local-addr -Werror=format -Werror=return-local-addr
|
||||
|
||||
test_framework = googletest
|
||||
test_build_src = true
|
||||
|
||||
; My local sources
|
||||
lib_extra_dirs = ./lib
|
||||
../
|
||||
|
||||
lib_ldf_mode = deep
|
||||
lib_deps=m5stack/M5Unified
|
||||
m5stack/M5Utility
|
||||
m5stack/M5HAL
|
||||
m5stack/M5Unit-ENV
|
||||
m5stack/M5Unit-METER
|
||||
m5stack/M5Unit-HUB
|
||||
m5stack/M5Unit-GESTURE
|
||||
m5stack/M5Unit-HEART
|
||||
m5stack/M5Unit-TOF
|
||||
m5stack/M5Unit-WEIGHT
|
||||
m5stack/M5Unit-ANADIG
|
||||
m5stack/M5Unit-COLOR
|
||||
m5stack/M5Unit-THERMO
|
||||
m5stack/M5Unit-EXTIO
|
||||
m5stack/M5Unit-INFRARED
|
||||
m5stack/M5Unit-CRYPTO
|
||||
https://github.com/m5stack/M5Unit-RFID
|
||||
https://github.com/m5stack/M5Unit-DISTANCE
|
||||
https://github.com/m5stack/M5Unit-KEYBOARD
|
||||
; https://github.com/m5stack/M5Unit-KEYBOARD#develop
|
||||
; boschsensortec/BME68x Sensor library@1.2.40408
|
||||
; boschsensortec/bsec2@1.8.2610
|
||||
|
||||
; Ignore DL'd M5UnitUnified, using local!
|
||||
lib_ignore = M5UnitUnified
|
||||
|
||||
; --------------------------------
|
||||
[m5base]
|
||||
monitor_speed = 115200
|
||||
monitor_filters = esp32_exception_decoder, time
|
||||
upload_speed = 1500000
|
||||
test_speed = 115200
|
||||
test_filter= embedded/test_update
|
||||
test_ignore= native/*
|
||||
;Arduino-esp 2.0.4 (Changed Wire) at 5.1.0
|
||||
platform = espressif32 @6.8.1
|
||||
;platform = espressif32 @ 5.0.0
|
||||
framework = arduino
|
||||
|
||||
[Core]
|
||||
extends = m5base
|
||||
board = m5stack-grey
|
||||
;m5stack-core-esp32-16M ;;6.8.0 or later
|
||||
;m5stack-core-esp32
|
||||
lib_deps = ${env.lib_deps}
|
||||
|
||||
[Core2]
|
||||
extends = m5base
|
||||
board = m5stack-core2
|
||||
lib_deps = ${env.lib_deps}
|
||||
|
||||
[CoreS3]
|
||||
extends = m5base
|
||||
board = m5stack-cores3
|
||||
lib_deps = ${env.lib_deps}
|
||||
|
||||
[Fire]
|
||||
extends = m5base
|
||||
board = m5stack-fire
|
||||
lib_deps = ${env.lib_deps}
|
||||
|
||||
[StampS3]
|
||||
;include M5Capsule, DinMeter
|
||||
extends = m5base
|
||||
board = m5stack-stamps3
|
||||
lib_deps = ${env.lib_deps}
|
||||
|
||||
[Dial]
|
||||
extends = m5base
|
||||
board = m5stack-stamps3
|
||||
lib_deps = ${env.lib_deps}
|
||||
m5stack/M5Dial
|
||||
|
||||
[AtomMatrix]
|
||||
extends = m5base
|
||||
board = m5stack-atom
|
||||
lib_deps = ${env.lib_deps}
|
||||
|
||||
[AtomS3]
|
||||
extends = m5base
|
||||
board = m5stack-atoms3
|
||||
lib_deps = ${env.lib_deps}
|
||||
|
||||
; Using ./boards/m5stack-atoms3r.json
|
||||
[AtomS3R]
|
||||
extends = m5base
|
||||
board = m5stack-atoms3r
|
||||
lib_deps = ${env.lib_deps}
|
||||
|
||||
; Using ./boards/m5stack-nanoc6.json
|
||||
[NanoC6]
|
||||
extends = m5base
|
||||
board = m5stack-nanoc6
|
||||
platform = https://github.com/platformio/platform-espressif32.git
|
||||
platform_packages =
|
||||
platformio/framework-arduinoespressif32 @ https://github.com/espressif/arduino-esp32.git#3.0.7
|
||||
platformio/framework-arduinoespressif32-libs @ https://github.com/espressif/esp32-arduino-libs.git#idf-release/v5.1
|
||||
board_build.partitions = default.csv
|
||||
lib_deps = ${env.lib_deps}
|
||||
lib_ignore = ${env.lib_ignore}
|
||||
bsec2
|
||||
|
||||
[StickCPlus]
|
||||
extends = m5base
|
||||
board = m5stick-c
|
||||
lib_deps = ${env.lib_deps}
|
||||
|
||||
; Using ./boards/m5stick-cplus2.json
|
||||
[StickCPlus2]
|
||||
extends = m5base
|
||||
board = m5stick-cplus2
|
||||
lib_deps = ${env.lib_deps}
|
||||
|
||||
[Paper]
|
||||
extends = m5base
|
||||
board = m5stack-fire
|
||||
lib_deps = ${env.lib_deps}
|
||||
|
||||
[CoreInk]
|
||||
extends = m5base
|
||||
board = m5stack-coreink
|
||||
lib_deps = ${env.lib_deps}
|
||||
|
||||
[sdl]
|
||||
build_flags = -O3 -xc++ -std=c++14 -lSDL2
|
||||
-arch arm64 ; for arm mac
|
||||
-I"/usr/local/include/SDL2" ; for intel mac homebrew SDL2
|
||||
-L"/usr/local/lib" ; for intel mac homebrew SDL2
|
||||
-I"${sysenv.HOMEBREW_PREFIX}/include/SDL2" ; for arm mac homebrew SDL2
|
||||
-L"${sysenv.HOMEBREW_PREFIX}/lib" ; for arm mac homebrew SDL2
|
||||
platform = native
|
||||
test_filter= native/*
|
||||
test_ignore= embedded/*
|
||||
lib_deps = ${env.lib_deps}
|
||||
|
||||
; --------------------------------
|
||||
;Choose build options
|
||||
[option_release]
|
||||
build_type=release
|
||||
build_flags = ${env.build_flags}
|
||||
-DCORE_DEBUG_LEVEL=3
|
||||
-DLOG_LOCAL_LEVEL=3
|
||||
-DAPP_LOG_LEVEL=3
|
||||
-DM5_LOG_LEVEL=3
|
||||
|
||||
[option_log]
|
||||
build_type=release
|
||||
build_flags = ${env.build_flags}
|
||||
-DCORE_DEBUG_LEVEL=5
|
||||
-DLOG_LOCAL_LEVEL=5
|
||||
-DAPP_LOG_LEVEL=5
|
||||
|
||||
[option_debug]
|
||||
build_type=debug
|
||||
build_flags = ${env.build_flags}
|
||||
-DCORE_DEBUG_LEVEL=5
|
||||
-DLOG_LOCAL_LEVEL=5
|
||||
-DAPP_LOG_LEVEL=5
|
||||
-DDEBUG
|
||||
|
||||
[option_map]
|
||||
build_type=release
|
||||
build_flags = ${env.build_flags}
|
||||
-DCORE_DEBUG_LEVEL=3
|
||||
-DLOG_LOCAL_LEVEL=3
|
||||
-DAPP_LOG_LEVEL=3
|
||||
-DM5_LOG_LEVEL=0
|
||||
-Wl,-Map,output.map
|
||||
|
||||
; Require at leaset C++14 after 1.13.0
|
||||
[test_fw]
|
||||
lib_deps = google/googletest@1.12.1
|
||||
|
||||
; --------------------------------
|
||||
; [env:test_native]
|
||||
; extends = sdl, option_release
|
||||
; build_flags = ${sdl.build_flags} ${option_release.build_flags}
|
||||
; lib_deps = ${sdl.lib_deps}
|
||||
; ${test_fw.lib_deps}
|
||||
; ;lib_compat_mode= off
|
||||
; ; Removal of out-of-M5UnitUnified files that cause errors
|
||||
; extra_scripts = pre:custom_script.py
|
||||
; custom_exclude_src_files=bme68xLibrary.cpp bsec2.cpp BMP280.cpp DHT12.cpp M5Unit-ENV/I2C_Class.cpp SCD4X.cpp SHT3X.cpp M5Unit-ENV/QMP6988.cpp SHT4X.cpp utility.cpp M5UnitKmeterISO.cpp M5UnitWeightI2C.cpp
|
||||
; lib_ignore = M5UnitUnified
|
||||
; bsec2
|
||||
; BME68x Sensor library
|
||||
|
||||
[env:test_Core]
|
||||
extends=Core, option_release
|
||||
lib_deps = ${Core.lib_deps}
|
||||
${test_fw.lib_deps}
|
||||
|
||||
[env:test_Core2]
|
||||
extends=Core2, option_release
|
||||
lib_deps = ${Core2.lib_deps}
|
||||
${test_fw.lib_deps}
|
||||
|
||||
[env:test_CoreS3]
|
||||
extends=CoreS3, option_release
|
||||
lib_deps = ${CoreS3.lib_deps}
|
||||
${test_fw.lib_deps}
|
||||
|
||||
[env:test_Fire]
|
||||
extends=Fire, option_release
|
||||
lib_deps = ${Fire.lib_deps}
|
||||
${test_fw.lib_deps}
|
||||
|
||||
[env:test_StampS3]
|
||||
extends=StampS3, option_release
|
||||
lib_deps = ${StampS3.lib_deps}
|
||||
${test_fw.lib_deps}
|
||||
|
||||
[env:test_Dial]
|
||||
extends=Dial, option_release
|
||||
lib_deps = ${Dial.lib_deps}
|
||||
${test_fw.lib_deps}
|
||||
|
||||
[env:test_AtomMatrix]
|
||||
extends=AtomMatrix, option_release
|
||||
lib_deps = ${AtomMatrix.lib_deps}
|
||||
${test_fw.lib_deps}
|
||||
|
||||
[env:test_AtomS3]
|
||||
extends=AtomS3, option_release
|
||||
lib_deps = ${AtomS3.lib_deps}
|
||||
${test_fw.lib_deps}
|
||||
|
||||
[env:test_AtomS3R]
|
||||
extends=AtomS3R, option_release
|
||||
lib_deps = ${AtomS3R.lib_deps}
|
||||
${test_fw.lib_deps}
|
||||
|
||||
[env:test_NanoC6]
|
||||
extends=NanoC6, option_release
|
||||
lib_deps = ${NanoC6.lib_deps}
|
||||
${test_fw.lib_deps}
|
||||
|
||||
[env:test_StickCPlus]
|
||||
extends=StickCPlus, option_release
|
||||
lib_deps = ${StickCPlus.lib_deps}
|
||||
${test_fw.lib_deps}
|
||||
|
||||
[env:test_StickCPlus2]
|
||||
extends=StickCPlus2, option_release
|
||||
lib_deps = ${StickCPlus2.lib_deps}
|
||||
${test_fw.lib_deps}
|
||||
|
||||
[env:test_Paper]
|
||||
extends=Paper, option_release
|
||||
lib_deps = ${Paper.lib_deps}
|
||||
${test_fw.lib_deps}
|
||||
|
||||
[env:test_CoreInk]
|
||||
extends=CoreInk, option_release
|
||||
lib_deps = ${CoreInk.lib_deps}
|
||||
${test_fw.lib_deps}
|
||||
|
||||
60
libraries/M5UnitUnified/pio_project/test/common_main.cpp
Normal file
60
libraries/M5UnitUnified/pio_project/test/common_main.cpp
Normal file
|
|
@ -0,0 +1,60 @@
|
|||
/*
|
||||
* SPDX-FileCopyrightText: 2024 M5Stack Technology CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*/
|
||||
/*
|
||||
main for UnitTest on native
|
||||
*/
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
// C++ version
|
||||
#if __cplusplus >= 202002L
|
||||
#pragma message "C++20 or later"
|
||||
#elif __cplusplus >= 201703L
|
||||
#pragma message "C++17 or later"
|
||||
#elif __cplusplus >= 201402L
|
||||
#pragma message "C++14 or later"
|
||||
#elif __cplusplus >= 201103L
|
||||
#pragma message "C++11 or later"
|
||||
#else
|
||||
#error "Need C++11 or later"
|
||||
#endif
|
||||
// Compiler
|
||||
#if defined(__clang__)
|
||||
#pragma message "Clang"
|
||||
#elif defined(_MSC_VER)
|
||||
#pragma message "MSVC"
|
||||
#elif defined(__BORLANDC__)
|
||||
#pragma message "BORLANDC"
|
||||
#elif defined(__MINGW32__) || defined(__MINGW64__)
|
||||
#pragma message "MINGW"
|
||||
#elif defined(__INTEL_COMPILER)
|
||||
#pragma message "ICC"
|
||||
#elif defined(__GNUG__)
|
||||
#pragma message "GCC"
|
||||
#else
|
||||
#pragma message "Unknown compiler"
|
||||
#endif
|
||||
|
||||
/*
|
||||
For native test, this main() is used.
|
||||
If the Arduino framework is used, the framework library main is used.
|
||||
*/
|
||||
#if !defined(ARDUINO)
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
testing::InitGoogleTest(&argc, argv);
|
||||
|
||||
#ifdef GTEST_FILTER
|
||||
::testing::GTEST_FLAG(filter) = GTEST_FILTER;
|
||||
#endif
|
||||
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wunused-result"
|
||||
RUN_ALL_TESTS();
|
||||
#pragma GCC diagnostic pop
|
||||
// Always return zero-code and allow PlatformIO to parse results
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
|
@ -0,0 +1,61 @@
|
|||
/*
|
||||
* SPDX-FileCopyrightText: 2024 M5Stack Technology CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*/
|
||||
/*
|
||||
main for UnitTest on embedded
|
||||
*/
|
||||
#include <gtest/gtest.h>
|
||||
#include <M5Unified.h>
|
||||
#include <esp_system.h>
|
||||
|
||||
#pragma message "Embedded setup/loop"
|
||||
|
||||
#if __has_include(<esp_idf_version.h>)
|
||||
#include <esp_idf_version.h>
|
||||
#else // esp_idf_version.h has been introduced in Arduino 1.0.5 (ESP-IDF3.3)
|
||||
#define ESP_IDF_VERSION_VAL(major, minor, patch) ((major << 16) | (minor << 8) | (patch))
|
||||
#define ESP_IDF_VERSION ESP_IDF_VERSION_VAL(3, 2, 0)
|
||||
#endif
|
||||
|
||||
namespace {
|
||||
auto& lcd = M5.Display;
|
||||
} // namespace
|
||||
|
||||
void test()
|
||||
{
|
||||
lcd.fillRect(0, 0, lcd.width() >> 1, lcd.height(), RUN_ALL_TESTS() ? TFT_RED : TFT_GREEN);
|
||||
}
|
||||
|
||||
void setup()
|
||||
{
|
||||
delay(1500);
|
||||
|
||||
M5.begin();
|
||||
|
||||
M5_LOGI("CPP %ld", __cplusplus);
|
||||
M5_LOGI("ESP-IDF Version %d.%d.%d", (ESP_IDF_VERSION >> 16) & 0xFF, (ESP_IDF_VERSION >> 8) & 0xFF,
|
||||
ESP_IDF_VERSION & 0xFF);
|
||||
M5_LOGI("BOARD:%X", M5.getBoard());
|
||||
M5_LOGI("Heap: %u", esp_get_free_heap_size());
|
||||
|
||||
lcd.clear(TFT_DARKGRAY);
|
||||
::testing::InitGoogleTest();
|
||||
|
||||
#ifdef GTEST_FILTER
|
||||
::testing::GTEST_FLAG(filter) = GTEST_FILTER;
|
||||
#endif
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
test();
|
||||
#if 0
|
||||
delay(1000);
|
||||
esp_restart();
|
||||
#endif
|
||||
while (true) {
|
||||
delay(10000);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,48 @@
|
|||
/*
|
||||
* SPDX-FileCopyrightText: 2024 M5Stack Technology CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*/
|
||||
/*
|
||||
UnitTest for M5UnitComponet
|
||||
*/
|
||||
#include <gtest/gtest.h>
|
||||
#include <M5UnitComponent.hpp>
|
||||
#include <M5UnitUnified.hpp>
|
||||
#include "unit_dummy.hpp"
|
||||
#include <Wire.h>
|
||||
|
||||
using namespace m5::unit;
|
||||
|
||||
TEST(Component, Update)
|
||||
{
|
||||
UnitUnified units;
|
||||
UnitDummy u;
|
||||
EXPECT_FALSE(u.isRegistered());
|
||||
|
||||
{
|
||||
auto cfg = u.component_config();
|
||||
EXPECT_FALSE(cfg.self_update); // false as default
|
||||
|
||||
EXPECT_EQ(u.count, 0U);
|
||||
EXPECT_TRUE(units.add(u, Wire));
|
||||
|
||||
units.update(); // Dont call u.update() because unit was not begun.
|
||||
EXPECT_EQ(u.count, 0U);
|
||||
|
||||
EXPECT_TRUE(units.begin());
|
||||
units.update(); // Call u.update()
|
||||
EXPECT_EQ(u.count, 1U);
|
||||
|
||||
cfg.self_update = true;
|
||||
u.component_config(cfg);
|
||||
cfg = u.component_config();
|
||||
EXPECT_TRUE(cfg.self_update);
|
||||
|
||||
units.update(); // Don't call u.update()
|
||||
EXPECT_EQ(u.count, 1U);
|
||||
|
||||
u.update(); // If component_config.self_update is true, you have to call it yourself
|
||||
EXPECT_EQ(u.count, 2U);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,80 @@
|
|||
/*
|
||||
* SPDX-FileCopyrightText: 2024 M5Stack Technology CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*/
|
||||
/*
|
||||
UnitTest for M5UnitComponet
|
||||
*/
|
||||
#include <gtest/gtest.h>
|
||||
#include <M5UnitComponent.hpp>
|
||||
#include "unit_dummy.hpp"
|
||||
|
||||
TEST(Component, Children)
|
||||
{
|
||||
m5::unit::UnitDummy u0, u1, u2, u3;
|
||||
|
||||
//
|
||||
EXPECT_FALSE(u0.hasParent());
|
||||
EXPECT_FALSE(u0.hasSiblings());
|
||||
EXPECT_FALSE(u0.hasChildren());
|
||||
|
||||
EXPECT_EQ(0U, u0.childrenSize());
|
||||
EXPECT_FALSE(u0.add(u1, 0));
|
||||
|
||||
// add 1
|
||||
auto cfg = u0.component_config();
|
||||
cfg.max_children = 1;
|
||||
u0.component_config(cfg);
|
||||
EXPECT_LT(u1.channel(), 0);
|
||||
EXPECT_TRUE(u0.add(u1, 0));
|
||||
EXPECT_FALSE(u0.add(u1, 1));
|
||||
EXPECT_FALSE(u0.add(u2, 1));
|
||||
|
||||
EXPECT_FALSE(u0.hasParent());
|
||||
EXPECT_FALSE(u0.hasSiblings());
|
||||
EXPECT_TRUE(u0.hasChildren());
|
||||
EXPECT_EQ(1U, u0.childrenSize());
|
||||
|
||||
EXPECT_EQ(0, u1.channel());
|
||||
EXPECT_TRUE(u1.hasParent());
|
||||
EXPECT_FALSE(u1.hasSiblings());
|
||||
EXPECT_FALSE(u1.hasChildren());
|
||||
|
||||
// add 2
|
||||
cfg = u0.component_config();
|
||||
cfg.max_children = 2;
|
||||
u0.component_config(cfg);
|
||||
|
||||
EXPECT_LT(u2.channel(), 0);
|
||||
EXPECT_FALSE(u0.add(u2, 0)); // same channel (failed)
|
||||
EXPECT_LT(u2.channel(), 0);
|
||||
EXPECT_TRUE(u0.add(u2, 3));
|
||||
|
||||
EXPECT_FALSE(u0.hasParent());
|
||||
EXPECT_FALSE(u0.hasSiblings());
|
||||
EXPECT_TRUE(u0.hasChildren());
|
||||
EXPECT_EQ(2U, u0.childrenSize());
|
||||
|
||||
EXPECT_TRUE(u1.hasParent());
|
||||
EXPECT_TRUE(u1.hasSiblings());
|
||||
EXPECT_FALSE(u1.hasChildren());
|
||||
|
||||
EXPECT_TRUE(u2.hasParent());
|
||||
EXPECT_TRUE(u2.hasSiblings());
|
||||
EXPECT_FALSE(u2.hasChildren());
|
||||
EXPECT_EQ(3, u2.channel());
|
||||
|
||||
EXPECT_LT(u3.channel(), 0);
|
||||
EXPECT_FALSE(u0.add(u3, 2)); // max = 2 (failed)
|
||||
EXPECT_LT(u3.channel(), 0);
|
||||
|
||||
// iteration
|
||||
m5::unit::UnitDummy* ptr[] = {&u1, &u2};
|
||||
size_t i = 0;
|
||||
for (auto it = u0.childBegin(); it != u0.childEnd(); ++it) {
|
||||
EXPECT_EQ(&(*it), ptr[i++]);
|
||||
// printf("[%u]:%s\n", it->port(), (*it).deviceName());
|
||||
}
|
||||
EXPECT_EQ(i, u0.childrenSize());
|
||||
}
|
||||
22
libraries/M5UnitUnified/pio_project/test/unit_dummy.cpp
Normal file
22
libraries/M5UnitUnified/pio_project/test/unit_dummy.cpp
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
/*
|
||||
* SPDX-FileCopyrightText: 2024 M5Stack Technology CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*/
|
||||
/*
|
||||
UnitTest for M5UnitComponent
|
||||
*/
|
||||
#include "unit_dummy.hpp"
|
||||
#include <M5Utility.hpp>
|
||||
|
||||
using namespace m5::utility::mmh3;
|
||||
|
||||
namespace m5 {
|
||||
namespace unit {
|
||||
|
||||
const char UnitDummy::name[] = "UnitDummy";
|
||||
const m5::unit::types::uid_t UnitDummy::uid{"UnitDummy"_mmh3};
|
||||
const m5::unit::types::attr_t UnitDummy::attr{0};
|
||||
|
||||
} // namespace unit
|
||||
} // namespace m5
|
||||
40
libraries/M5UnitUnified/pio_project/test/unit_dummy.hpp
Normal file
40
libraries/M5UnitUnified/pio_project/test/unit_dummy.hpp
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
/*
|
||||
* SPDX-FileCopyrightText: 2024 M5Stack Technology CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*/
|
||||
/*
|
||||
UnitTest for M5UnitComponent
|
||||
*/
|
||||
#ifndef M5_UNIT_COMPONENT_TEST_UNIT_DUMMY_HPP
|
||||
#define M5_UNIT_COMPONENT_TEST_UNIT_DUMMY_HPP
|
||||
|
||||
#include <M5UnitComponent.hpp>
|
||||
|
||||
namespace m5 {
|
||||
namespace unit {
|
||||
// DummyComponent for UnitTest
|
||||
class UnitDummy : public m5::unit::Component {
|
||||
M5_UNIT_COMPONENT_HPP_BUILDER(UnitDummy, 0x00);
|
||||
|
||||
public:
|
||||
UnitDummy() : Component(0x01)
|
||||
{
|
||||
}
|
||||
virtual ~UnitDummy()
|
||||
{
|
||||
}
|
||||
|
||||
virtual bool begin() override
|
||||
{
|
||||
return true;
|
||||
}
|
||||
virtual void update(const bool force = false) override
|
||||
{
|
||||
++count;
|
||||
}
|
||||
uint32_t count{};
|
||||
};
|
||||
} // namespace unit
|
||||
} // namespace m5
|
||||
#endif
|
||||
169
libraries/M5UnitUnified/pio_project/test/unit_unified_test.cpp
Normal file
169
libraries/M5UnitUnified/pio_project/test/unit_unified_test.cpp
Normal file
|
|
@ -0,0 +1,169 @@
|
|||
/*
|
||||
* SPDX-FileCopyrightText: 2024 M5Stack Technology CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*/
|
||||
/*
|
||||
UnitTest for M5UnitUnified
|
||||
*/
|
||||
#include <gtest/gtest.h>
|
||||
#include <M5Unified.h>
|
||||
|
||||
#include <M5UnitComponent.hpp>
|
||||
#include <M5UnitUnified.hpp>
|
||||
|
||||
#include <M5UnitUnifiedENV.h>
|
||||
#include <M5UnitUnifiedMETER.h>
|
||||
#include <M5UnitUnifiedHUB.h>
|
||||
#include <M5UnitUnifiedGESTURE.h>
|
||||
#include <M5UnitUnifiedHEART.h>
|
||||
#include <M5UnitUnifiedTOF.h>
|
||||
#include <M5UnitUnifiedWEIGHT.h>
|
||||
#include <M5UnitUnifiedANADIG.h>
|
||||
#include <M5UnitUnifiedCOLOR.h>
|
||||
#include <M5UnitUnifiedTHERMO.h>
|
||||
#include <M5UnitUnifiedDISTANCE.h>
|
||||
#include <M5UnitUnifiedEXTIO.h>
|
||||
#include <M5UnitUnifiedINFRARED.h>
|
||||
#include <M5UnitUnifiedCRYPTO.h>
|
||||
|
||||
#include <M5UnitUnifiedRFID.h>
|
||||
#include <M5UnitUnifiedKEYBOARD.h>
|
||||
|
||||
#include <algorithm>
|
||||
#include <utility>
|
||||
|
||||
namespace {
|
||||
|
||||
#if 0
|
||||
// Get the equivalent of a unique type name without RTTI
|
||||
template <typename U>
|
||||
const char* TypeName() {
|
||||
return __PRETTY_FUNCTION__;
|
||||
}
|
||||
#endif
|
||||
|
||||
std::vector<m5::unit::Component*> vec;
|
||||
|
||||
template <class U>
|
||||
void each_unit_test()
|
||||
{
|
||||
SCOPED_TRACE(U::name);
|
||||
|
||||
U* unit = new U();
|
||||
EXPECT_TRUE((bool)unit);
|
||||
|
||||
M5_LOGI(">>%02XH %08X [%s]", U::DEFAULT_ADDRESS, U::uid, U::name);
|
||||
|
||||
// Are the values the same via class and via instance?
|
||||
EXPECT_EQ(+U::DEFAULT_ADDRESS, unit->address());
|
||||
EXPECT_STREQ(U::name, unit->deviceName());
|
||||
EXPECT_EQ(U::uid, unit->identifier());
|
||||
EXPECT_EQ(U::attr, unit->attribute());
|
||||
|
||||
// Identical IDs exist?
|
||||
for (auto&& e : vec) {
|
||||
EXPECT_NE(unit->identifier(), e->identifier()) << unit->deviceName() << " / " << e->deviceName();
|
||||
}
|
||||
|
||||
// Move
|
||||
{
|
||||
U tmp;
|
||||
// Move constructor
|
||||
U mc(std::move(tmp));
|
||||
// assign by move
|
||||
U mc2;
|
||||
mc2 = std::move(mc);
|
||||
}
|
||||
|
||||
vec.push_back(unit);
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
// Check each value and check duplicate uid
|
||||
TEST(UnitUnified, EachUnit)
|
||||
{
|
||||
// ENV
|
||||
each_unit_test<m5::unit::UnitSCD40>();
|
||||
each_unit_test<m5::unit::UnitSCD41>();
|
||||
each_unit_test<m5::unit::UnitSHT30>();
|
||||
each_unit_test<m5::unit::UnitQMP6988>();
|
||||
each_unit_test<m5::unit::UnitENV3>();
|
||||
each_unit_test<m5::unit::UnitBME688>();
|
||||
each_unit_test<m5::unit::UnitSGP30>();
|
||||
each_unit_test<m5::unit::UnitSHT40>();
|
||||
each_unit_test<m5::unit::UnitBMP280>();
|
||||
each_unit_test<m5::unit::UnitENV4>();
|
||||
|
||||
// METER
|
||||
each_unit_test<m5::unit::UnitADS1113>();
|
||||
each_unit_test<m5::unit::UnitADS1114>();
|
||||
each_unit_test<m5::unit::UnitADS1115>();
|
||||
each_unit_test<m5::unit::meter::UnitEEPROM>();
|
||||
each_unit_test<m5::unit::UnitAmeter>();
|
||||
each_unit_test<m5::unit::UnitVmeter>();
|
||||
each_unit_test<m5::unit::UnitKmeterISO>();
|
||||
each_unit_test<m5::unit::UnitDualKmeter>();
|
||||
|
||||
// HUB
|
||||
each_unit_test<m5::unit::UnitPCA9548AP>();
|
||||
|
||||
// GESTURE
|
||||
each_unit_test<m5::unit::UnitPAJ7620U2>();
|
||||
|
||||
// HEART
|
||||
each_unit_test<m5::unit::UnitMAX30100>();
|
||||
each_unit_test<m5::unit::UnitMAX30102>();
|
||||
|
||||
// TOF
|
||||
each_unit_test<m5::unit::UnitVL53L0X>();
|
||||
each_unit_test<m5::unit::UnitVL53L1X>();
|
||||
|
||||
// WEIGHT
|
||||
each_unit_test<m5::unit::UnitWeightI2C>();
|
||||
each_unit_test<m5::unit::UnitMiniScales>();
|
||||
|
||||
// ANADIG
|
||||
each_unit_test<m5::unit::UnitMCP4725>();
|
||||
each_unit_test<m5::unit::UnitGP8413>();
|
||||
each_unit_test<m5::unit::UnitADS11XX>();
|
||||
each_unit_test<m5::unit::UnitADS1110>();
|
||||
each_unit_test<m5::unit::UnitADS1100>();
|
||||
|
||||
// COLOR
|
||||
each_unit_test<m5::unit::UnitTCS34725>();
|
||||
|
||||
// THERMO
|
||||
each_unit_test<m5::unit::UnitMLX90614>();
|
||||
each_unit_test<m5::unit::UnitMLX90614BAA>();
|
||||
each_unit_test<m5::unit::UnitNCIR2>();
|
||||
|
||||
// DISTANCE
|
||||
each_unit_test<m5::unit::UnitRCWL9620>();
|
||||
|
||||
// EXTIO
|
||||
each_unit_test<m5::unit::UnitExtIO2>();
|
||||
|
||||
// INFRARED
|
||||
each_unit_test<m5::unit::UnitSTHS34PF80>();
|
||||
|
||||
// CRYPTO
|
||||
each_unit_test<m5::unit::UnitATECC608B>();
|
||||
each_unit_test<m5::unit::UnitATECC608B_TNGTLS>();
|
||||
|
||||
// RFID
|
||||
each_unit_test<m5::unit::UnitMFRC522>();
|
||||
each_unit_test<m5::unit::UnitWS1850S>();
|
||||
|
||||
// KEYBOARD
|
||||
each_unit_test<m5::unit::UnitKeyboard>();
|
||||
each_unit_test<m5::unit::UnitKeyboardBitwise>();
|
||||
each_unit_test<m5::unit::UnitCardKB>();
|
||||
each_unit_test<m5::unit::UnitFacesQWERTY>();
|
||||
|
||||
for (auto&& e : vec) {
|
||||
delete e;
|
||||
}
|
||||
vec.clear();
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue