@geastack/targets 0.1.99 → 0.1.101
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build-config.json +10 -2
- package/package.json +7 -7
- package/targets/cmake/geatsc-generated-archive-build.mjs +32 -1
- package/targets/esp32/app_project.cmake +2 -2
- package/targets/esp32/chip_bindings/audio/echo_cancellation.cpp +392 -28
- package/targets/esp32/chip_bindings/audio/echo_cancellation.h +18 -2
- package/targets/esp32/chip_bindings/audio/es8311.cpp +117 -13
- package/targets/esp32/chip_bindings/displays/co5300.cpp +68 -28
- package/targets/esp32/components/gea_framework/CMakeLists.txt +17 -1
- package/targets/esp32/components/gea_framework/idf_component.yml +4 -0
- package/targets/esp32/components/gea_vpx/CMakeLists.txt +1 -1
- package/targets/esp32/connectivity/wifi.cpp +800 -543
- package/targets/esp32/display.cpp +121 -26
- package/targets/esp32/gea_framework.cmake +22 -28
- package/targets/esp32/host_sources.cmake +1 -0
- package/targets/esp32/services/comparison_benchmark.h +137 -0
- package/targets/esp32/services/comparison_gesture.h +133 -0
- package/targets/esp32/services/comparison_input_trace.h +64 -0
- package/targets/esp32/services/comparison_upload_capture.h +125 -0
- package/targets/esp32/services/debugger.h +634 -0
- package/targets/esp32/services/device_control.cpp +965 -20
- package/targets/esp32/services/frame_scheduler.cpp +128 -4
- package/targets/esp32/services/heap.cpp +125 -0
- package/targets/esp32/services/opus_benchmark.h +1 -1
- package/targets/esp32/services/storage_service.cpp +119 -104
- package/targets/esp32-p4-m5stack-tab5/dependencies.lock +27 -16
- package/targets/esp32-s3-m5stack-stopwatch/README.md +14 -9
- package/targets/esp32-s3-m5stack-stopwatch/dependencies.lock +54 -1
- package/targets/esp32-s3-m5stack-stopwatch/main/CMakeLists.txt +10 -7
- package/targets/esp32-s3-m5stack-stopwatch/main/buttons.cpp +80 -0
- package/targets/esp32-s3-m5stack-stopwatch/main/idf_component.yml +18 -0
- package/targets/esp32-s3-m5stack-stopwatch/main/include/board.h +38 -17
- package/targets/esp32-s3-m5stack-stopwatch/main/panel_reset.cpp +132 -129
- package/targets/esp32-s3-m5stack-stopwatch/main/power.cpp +253 -0
- package/targets/esp32-s3-m5stack-stopwatch/main/touch.cpp +158 -88
- package/targets/esp32-s3-m5stack-stopwatch/sdkconfig.defaults +13 -0
- package/targets/esp32-s3-touch-amoled-1.8/main/CMakeLists.txt +30 -3
- package/targets/esp32-s3-touch-amoled-2.06/dependencies.lock +10 -148
- package/targets/esp32-s31-espressif-mosaico/README.md +34 -0
- package/targets/esp32-s31-espressif-mosaico/dependencies.lock +49 -1
- package/targets/esp32-s31-espressif-mosaico/main/CMakeLists.txt +23 -5
- package/targets/esp32-s31-espressif-mosaico/main/board_power.cpp +117 -0
- package/targets/esp32-s31-espressif-mosaico/main/camera.cpp +326 -0
- package/targets/esp32-s31-espressif-mosaico/main/idf_component.yml +11 -0
- package/targets/esp32-s31-espressif-mosaico/main/include/board.h +23 -0
- package/targets/esp32-s31-espressif-mosaico/main/nand_mount.cpp +172 -0
- package/targets/esp32-s31-espressif-mosaico/partitions.csv +7 -3
- package/targets/esp32-s31-espressif-mosaico/sdkconfig.defaults +24 -0
|
@@ -1,4 +1,13 @@
|
|
|
1
|
+
#if __has_include("esp_vfs_fat.h")
|
|
2
|
+
#include "esp_vfs_fat.h"
|
|
3
|
+
#define GEA_DEVICE_CONTROL_FAT_DIAGNOSTICS 1
|
|
4
|
+
#else
|
|
5
|
+
#define GEA_DEVICE_CONTROL_FAT_DIAGNOSTICS 0
|
|
6
|
+
#endif
|
|
1
7
|
#include "services/device_control.h"
|
|
8
|
+
#if defined(GEA_NATIVE_DEBUGGER) && GEA_NATIVE_DEBUGGER
|
|
9
|
+
#include "services/debugger.h"
|
|
10
|
+
#endif
|
|
2
11
|
|
|
3
12
|
#include "apps.h"
|
|
4
13
|
#include "canvas.h"
|
|
@@ -12,7 +21,14 @@
|
|
|
12
21
|
#include "host/video.h"
|
|
13
22
|
|
|
14
23
|
extern "C" uint32_t gea_display_completed_chunks() __attribute__((weak));
|
|
24
|
+
extern "C" bool gea_display_wait_for_uploads() __attribute__((weak));
|
|
25
|
+
extern "C" bool gea_frame_capture_boundary_ready() __attribute__((weak));
|
|
15
26
|
#include "services/app_state.h"
|
|
27
|
+
#include "memory_config.h"
|
|
28
|
+
#include "services/comparison_benchmark.h"
|
|
29
|
+
#include "services/comparison_input_trace.h"
|
|
30
|
+
#include "services/comparison_gesture.h"
|
|
31
|
+
#include "services/comparison_upload_capture.h"
|
|
16
32
|
#include "services/storage_service.h"
|
|
17
33
|
#include "ui/internal.h"
|
|
18
34
|
#include "ui/canvas_element.h"
|
|
@@ -38,6 +54,7 @@ extern "C" uint32_t gea_display_completed_chunks() __attribute__((weak));
|
|
|
38
54
|
#include "platform/file_cache.h" // gea::platform::storage::ensureMounted for GEADEV PUSH
|
|
39
55
|
#include "esp_log.h"
|
|
40
56
|
#include "esp_timer.h"
|
|
57
|
+
#include <atomic>
|
|
41
58
|
#if CONFIG_ESP_WIFI_ENABLED
|
|
42
59
|
#include "esp_wifi.h"
|
|
43
60
|
#endif
|
|
@@ -58,9 +75,11 @@ extern "C" uint32_t gea_display_completed_chunks() __attribute__((weak));
|
|
|
58
75
|
#include <cstdlib>
|
|
59
76
|
#include <cstring>
|
|
60
77
|
#include <string>
|
|
78
|
+
#include <new>
|
|
61
79
|
#include <sys/stat.h> // ::mkdir for GEADEV PUSH parent dirs
|
|
62
80
|
#include <sys/time.h>
|
|
63
81
|
#include "esp_system.h" // esp_restart() for GEADEV REBOOT
|
|
82
|
+
#include "esp_rom_sys.h"
|
|
64
83
|
#if CONFIG_IDF_TARGET_ESP32P4
|
|
65
84
|
#include "soc/lp_system_reg.h" // FORCE_DOWNLOAD_BOOT for GEADEV DOWNLOAD
|
|
66
85
|
#elif CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32S3 || CONFIG_IDF_TARGET_ESP32C3
|
|
@@ -69,6 +88,7 @@ extern "C" uint32_t gea_display_completed_chunks() __attribute__((weak));
|
|
|
69
88
|
#if GEA_DEVICE_CONTROL_USB_OTA
|
|
70
89
|
#include "esp_ota_ops.h" // GEADEV OTA
|
|
71
90
|
#include <algorithm>
|
|
91
|
+
#include <vector>
|
|
72
92
|
#endif
|
|
73
93
|
#include "audio.h" // gea::platform::audio::AudioSystem for GEADEV PLAYFILE
|
|
74
94
|
#if GEA_AUDIO_EXPERIMENT
|
|
@@ -125,6 +145,9 @@ SemaphoreHandle_t gCommandMutex = nullptr;
|
|
|
125
145
|
|
|
126
146
|
std::uint32_t crc32Stream(std::uint32_t crc, const std::uint8_t *data, std::size_t n);
|
|
127
147
|
extern "C" bool geaDisplaySnapshotPrefersPresented() __attribute__((weak));
|
|
148
|
+
// Defined by engines that rasterize straight into the panel's DMA buffers (gea-threejs):
|
|
149
|
+
// captures the next presented frame, the only place the real pixels exist.
|
|
150
|
+
extern "C" bool geaDisplayCapturePresentedFrame(std::uint16_t *dst, int pixelCapacity, int *width, int *height) __attribute__((weak));
|
|
128
151
|
|
|
129
152
|
// Mirrors the engine's default (core/packages/engine/ui/tree_render.cpp): a target
|
|
130
153
|
// that does not fuse the replay into the flush keeps a persistent framebuffer.
|
|
@@ -258,6 +281,16 @@ bool captureSnapshotRgb565(std::uint16_t *snapshot, int pixelCapacity, int *widt
|
|
|
258
281
|
{
|
|
259
282
|
using gea::platform::display::Display;
|
|
260
283
|
|
|
284
|
+
// Before the lock: the engine waits for the frame task to present a frame.
|
|
285
|
+
if (geaDisplayCapturePresentedFrame && geaDisplayCapturePresentedFrame(snapshot, pixelCapacity, width, height)) {
|
|
286
|
+
gea::framework::services::AppState::lock();
|
|
287
|
+
const char *presentedAppId = gea::framework::apps::AppManager::currentId();
|
|
288
|
+
if (appIdBuffer && appIdBufferSize > 0)
|
|
289
|
+
std::snprintf(appIdBuffer, appIdBufferSize, "%s", presentedAppId ? presentedAppId : "");
|
|
290
|
+
gea::framework::services::AppState::unlock();
|
|
291
|
+
return *width > 0 && *height > 0;
|
|
292
|
+
}
|
|
293
|
+
|
|
261
294
|
gea::framework::services::AppState::lock();
|
|
262
295
|
bool copied = false;
|
|
263
296
|
bool copiedRetained = false;
|
|
@@ -460,7 +493,7 @@ void writeScreenshot()
|
|
|
460
493
|
#endif // GEA_PIXEL_STORAGE_PACKED
|
|
461
494
|
}
|
|
462
495
|
|
|
463
|
-
#if CONFIG_ESP_CONSOLE_SECONDARY_USB_SERIAL_JTAG
|
|
496
|
+
#if CONFIG_ESP_CONSOLE_USB_SERIAL_JTAG || CONFIG_ESP_CONSOLE_SECONDARY_USB_SERIAL_JTAG
|
|
464
497
|
class ScopedLogSilence {
|
|
465
498
|
public:
|
|
466
499
|
ScopedLogSilence()
|
|
@@ -796,6 +829,20 @@ void handleNode(char *&cursor)
|
|
|
796
829
|
const auto &node = tree.node(nodeId);
|
|
797
830
|
int16_t xs[4] = {};
|
|
798
831
|
int16_t ys[4] = {};
|
|
832
|
+
int commandX0 = 0;
|
|
833
|
+
int commandY0 = 0;
|
|
834
|
+
int commandX1 = 0;
|
|
835
|
+
int commandY1 = 0;
|
|
836
|
+
const auto &displayList = gea::embedded::ui::DisplayList::instance();
|
|
837
|
+
displayList.nodeCommandBounds(nodeId, &commandX0, &commandY0, &commandX1, &commandY1);
|
|
838
|
+
const gea::embedded::ui::DisplayCommand *textCommand = nullptr;
|
|
839
|
+
for (int commandIndex = 0; commandIndex < displayList.nodeCommandCount(nodeId); commandIndex++) {
|
|
840
|
+
const auto *command = displayList.nodeCommandAt(nodeId, commandIndex);
|
|
841
|
+
if (command && command->type == gea::embedded::ui::DisplayCommandType::DrawText) {
|
|
842
|
+
textCommand = command;
|
|
843
|
+
break;
|
|
844
|
+
}
|
|
845
|
+
}
|
|
799
846
|
gea::embedded::ui::ViewRenderer::transformedRectCorners(node,
|
|
800
847
|
false,
|
|
801
848
|
node.layout.x,
|
|
@@ -805,7 +852,7 @@ void handleNode(char *&cursor)
|
|
|
805
852
|
xs,
|
|
806
853
|
ys);
|
|
807
854
|
std::printf(
|
|
808
|
-
"GEADEV:NODE class=%s id=%d parent=%d type=%d display=%d style=%dx%d min=%dx%d max=%dx%d pos=%d,%d,%d,%d transform=%d,%d,%d,%d,%d layout=%d,%d,%d,%d corners=%d,%d;%d,%d;%d,%d;%d,%d ovf=%d,%d,%d scroll=%d,%d,%d,%d\n",
|
|
855
|
+
"GEADEV:NODE class=%s id=%d parent=%d type=%d display=%d style=%dx%d min=%dx%d max=%dx%d pos=%d,%d,%d,%d transform=%d,%d,%d,%d,%d layout=%d,%d,%d,%d corners=%d,%d;%d,%d;%d,%d;%d,%d ovf=%d,%d,%d scroll=%d,%d,%d,%d font=%d,%d,%d opacity=%d commands=%d bounds=%d,%d,%d,%d drawtext=%d,%d,%d,%d,%d,%d,%d,%d,%g\n",
|
|
809
856
|
className,
|
|
810
857
|
nodeId,
|
|
811
858
|
node.parent,
|
|
@@ -844,7 +891,25 @@ void handleNode(char *&cursor)
|
|
|
844
891
|
static_cast<int>(node.layout.scroll_x),
|
|
845
892
|
static_cast<int>(node.layout.scroll_y),
|
|
846
893
|
static_cast<int>(node.layout.scroll_content_width),
|
|
847
|
-
static_cast<int>(node.layout.scroll_content_height)
|
|
894
|
+
static_cast<int>(node.layout.scroll_content_height),
|
|
895
|
+
static_cast<int>(GEA_DIAGNOSTIC_NODE_STYLE(node).font_id),
|
|
896
|
+
static_cast<int>(GEA_DIAGNOSTIC_NODE_STYLE(node).font_size),
|
|
897
|
+
static_cast<int>(GEA_DIAGNOSTIC_NODE_STYLE(node).line_height),
|
|
898
|
+
static_cast<int>(GEA_DIAGNOSTIC_NODE_STYLE(node).opacity),
|
|
899
|
+
displayList.nodeCommandCount(nodeId),
|
|
900
|
+
commandX0,
|
|
901
|
+
commandY0,
|
|
902
|
+
commandX1,
|
|
903
|
+
commandY1,
|
|
904
|
+
textCommand && textCommand->text.text ? static_cast<unsigned char>(textCommand->text.text[0]) : -1,
|
|
905
|
+
textCommand ? textCommand->text.x : 0,
|
|
906
|
+
textCommand ? textCommand->text.y : 0,
|
|
907
|
+
textCommand ? textCommand->bx : 0,
|
|
908
|
+
textCommand ? textCommand->by : 0,
|
|
909
|
+
textCommand ? textCommand->bw : 0,
|
|
910
|
+
textCommand ? textCommand->bh : 0,
|
|
911
|
+
textCommand ? textCommand->text.fontId : -1,
|
|
912
|
+
textCommand ? static_cast<double>(textCommand->text.scale) : 0.0);
|
|
848
913
|
printed++;
|
|
849
914
|
}
|
|
850
915
|
gea::framework::services::AppState::unlock();
|
|
@@ -1007,6 +1072,7 @@ void handleKey(char *&cursor)
|
|
|
1007
1072
|
return;
|
|
1008
1073
|
}
|
|
1009
1074
|
gea::framework::input::queueKeyDown(keyCode);
|
|
1075
|
+
gea::framework::input::queueKeyUp(keyCode);
|
|
1010
1076
|
std::printf("GEADEV:OK KEY keycode=%d\n", keyCode);
|
|
1011
1077
|
}
|
|
1012
1078
|
|
|
@@ -1262,6 +1328,31 @@ void makeParentDirs(const char *path)
|
|
|
1262
1328
|
}
|
|
1263
1329
|
}
|
|
1264
1330
|
|
|
1331
|
+
// A board whose file storage can be rebuilt (the Mosaico's NAND) overrides
|
|
1332
|
+
// this: erase the medium and lay down a fresh filesystem at `mount`. 0 = done.
|
|
1333
|
+
extern "C" __attribute__((weak)) int gea_board_storage_format(const char *mount)
|
|
1334
|
+
{
|
|
1335
|
+
(void)mount;
|
|
1336
|
+
return -1;
|
|
1337
|
+
}
|
|
1338
|
+
|
|
1339
|
+
// GEADEV FORMAT <mount>: the recovery for a volume that reads but no longer
|
|
1340
|
+
// writes (an interrupted write can leave FAT unusable): everything on it is
|
|
1341
|
+
// lost, so the host re-pushes what it needs.
|
|
1342
|
+
void handleFormat(char *args)
|
|
1343
|
+
{
|
|
1344
|
+
char *mount = nextToken(args);
|
|
1345
|
+
if (!mount) {
|
|
1346
|
+
std::printf("GEADEV:FORMAT ERR usage=GEADEV_FORMAT_mount\n");
|
|
1347
|
+
return;
|
|
1348
|
+
}
|
|
1349
|
+
std::printf("GEADEV:FORMAT BUSY mount=%s\n", mount);
|
|
1350
|
+
std::fflush(stdout);
|
|
1351
|
+
const int rc = gea_board_storage_format(mount);
|
|
1352
|
+
if (rc != 0) std::printf("GEADEV:FORMAT ERR mount=%s rc=%d\n", mount, rc);
|
|
1353
|
+
else std::printf("GEADEV:FORMAT OK mount=%s\n", mount);
|
|
1354
|
+
}
|
|
1355
|
+
|
|
1265
1356
|
void handlePush(char *args)
|
|
1266
1357
|
{
|
|
1267
1358
|
char *pathTok = nextToken(args);
|
|
@@ -1313,10 +1404,23 @@ void handlePush(char *args)
|
|
|
1313
1404
|
int stalls = 0;
|
|
1314
1405
|
bool ioError = false;
|
|
1315
1406
|
while (got < size) {
|
|
1407
|
+
#if CONFIG_ESP_CONSOLE_USB_SERIAL_JTAG
|
|
1408
|
+
// Binary payloads must bypass the text-oriented stdin VFS, just like
|
|
1409
|
+
// command bytes. It can block or translate JPEG bytes in a raw upload.
|
|
1410
|
+
const int received = usb_serial_jtag_read_bytes(mem + got, static_cast<std::size_t>(size - got), pdMS_TO_TICKS(50));
|
|
1411
|
+
const std::size_t n = received > 0 ? static_cast<std::size_t>(received) : 0;
|
|
1412
|
+
#else
|
|
1316
1413
|
const std::size_t n = std::fread(mem + got, 1, static_cast<std::size_t>(size - got), stdin);
|
|
1414
|
+
#endif
|
|
1317
1415
|
if (n == 0) {
|
|
1318
1416
|
std::clearerr(stdin); // an idle read sets the sticky EOF flag
|
|
1319
|
-
if (++stalls >
|
|
1417
|
+
if (++stalls >
|
|
1418
|
+
#if CONFIG_ESP_CONSOLE_USB_SERIAL_JTAG
|
|
1419
|
+
800
|
|
1420
|
+
#else
|
|
1421
|
+
20000
|
|
1422
|
+
#endif
|
|
1423
|
+
) { // ~40s of silence → abort
|
|
1320
1424
|
ioError = true;
|
|
1321
1425
|
break;
|
|
1322
1426
|
}
|
|
@@ -1332,12 +1436,27 @@ void handlePush(char *args)
|
|
|
1332
1436
|
if (wrote != static_cast<std::size_t>(size)) ioError = true;
|
|
1333
1437
|
else finalCrc = crc32Stream(0xFFFFFFFFu, mem, static_cast<std::size_t>(size)) ^ 0xFFFFFFFFu;
|
|
1334
1438
|
}
|
|
1335
|
-
|
|
1439
|
+
// fwrite only fills the stdio buffer: the medium is written by the flush
|
|
1440
|
+
// (and the close). A full or failing volume shows up here, not above, and
|
|
1441
|
+
// left unchecked it leaves an empty file behind a "PUSH OK".
|
|
1442
|
+
const int flushed = std::fflush(f);
|
|
1443
|
+
const int flushErrno = errno;
|
|
1444
|
+
const int closed = std::fclose(f);
|
|
1445
|
+
const int closeErrno = errno;
|
|
1336
1446
|
if (mem) heap_caps_free(mem);
|
|
1337
1447
|
if (ioError) {
|
|
1338
1448
|
std::printf("GEADEV:PUSH ERR transfer-failed path=%s got=%ld\n", path, got);
|
|
1339
1449
|
return;
|
|
1340
1450
|
}
|
|
1451
|
+
if (flushed != 0 || closed != 0) {
|
|
1452
|
+
std::uint64_t total = 0, free = 0;
|
|
1453
|
+
#if GEA_DEVICE_CONTROL_FAT_DIAGNOSTICS
|
|
1454
|
+
if (std::strncmp(path, "/nand/", 6) == 0) esp_vfs_fat_info("/nand", &total, &free);
|
|
1455
|
+
#endif
|
|
1456
|
+
std::printf("GEADEV:PUSH ERR write-failed path=%s flush=%d errno=%d close=%d errno=%d nandKB=%llu freeKB=%llu\n", path, flushed, flushErrno, closed, closeErrno,
|
|
1457
|
+
static_cast<unsigned long long>(total / 1024), static_cast<unsigned long long>(free / 1024));
|
|
1458
|
+
return;
|
|
1459
|
+
}
|
|
1341
1460
|
if (haveCrc && finalCrc != expectCrc) {
|
|
1342
1461
|
std::printf("GEADEV:PUSH ERR crc-mismatch path=%s got=0x%08x want=0x%08x\n",
|
|
1343
1462
|
path, static_cast<unsigned>(finalCrc), static_cast<unsigned>(expectCrc));
|
|
@@ -1356,6 +1475,80 @@ void handlePush(char *args)
|
|
|
1356
1475
|
// console -- the ESP32-S31's OTG port -- is flashed without the BOOT button.
|
|
1357
1476
|
// Compiled only for boards that ask for it (GEA_DEVICE_CONTROL_USB_OTA).
|
|
1358
1477
|
#if GEA_DEVICE_CONTROL_USB_OTA
|
|
1478
|
+
// The fallback when the image cannot be staged: a firmware that runs from
|
|
1479
|
+
// PSRAM (XIP) of about its own size leaves no room for the next image, so
|
|
1480
|
+
// Skytail could only be updated from a smaller app. Each 64 KB read goes
|
|
1481
|
+
// straight to flash, erased sector by sector as it is written: a whole-slot
|
|
1482
|
+
// erase up front would hold READY past the host's 15 s wait. stdin reads the TinyUSB CDC FIFO, which leaves
|
|
1483
|
+
// the OUT endpoint un-armed while it is full, so the host waits out a write
|
|
1484
|
+
// instead of losing bytes. The boot slot only changes after the CRC matches; a
|
|
1485
|
+
// bad transfer aborts and the running slot stays the boot slot.
|
|
1486
|
+
static void handleOtaStreamed(const esp_partition_t *slot, long size, std::uint32_t expectCrc)
|
|
1487
|
+
{
|
|
1488
|
+
constexpr std::size_t kChunk = 64 * 1024;
|
|
1489
|
+
auto *buffer = static_cast<std::uint8_t *>(heap_caps_malloc(kChunk, MALLOC_CAP_8BIT));
|
|
1490
|
+
if (!buffer) {
|
|
1491
|
+
std::printf("GEADEV:OTA ERR no-memory bytes=%ld\n", size);
|
|
1492
|
+
return;
|
|
1493
|
+
}
|
|
1494
|
+
esp_ota_handle_t handle = 0;
|
|
1495
|
+
esp_err_t err = esp_ota_begin(slot, OTA_WITH_SEQUENTIAL_WRITES, &handle);
|
|
1496
|
+
if (err != ESP_OK) {
|
|
1497
|
+
heap_caps_free(buffer);
|
|
1498
|
+
std::printf("GEADEV:OTA ERR write-failed slot=%s err=%s\n", slot->label, esp_err_to_name(err));
|
|
1499
|
+
return;
|
|
1500
|
+
}
|
|
1501
|
+
std::printf("GEADEV:OTA READY slot=%s bytes=%ld\n", slot->label, size);
|
|
1502
|
+
std::fflush(stdout);
|
|
1503
|
+
|
|
1504
|
+
std::uint32_t crc = 0xFFFFFFFFu;
|
|
1505
|
+
long got = 0;
|
|
1506
|
+
int stalls = 0;
|
|
1507
|
+
while (got < size && err == ESP_OK) {
|
|
1508
|
+
const std::size_t want = std::min(kChunk, static_cast<std::size_t>(size - got));
|
|
1509
|
+
std::size_t filled = 0;
|
|
1510
|
+
while (filled < want) {
|
|
1511
|
+
const std::size_t n = std::fread(buffer + filled, 1, want - filled, stdin);
|
|
1512
|
+
if (n == 0) {
|
|
1513
|
+
std::clearerr(stdin);
|
|
1514
|
+
if (++stalls > 5000) break;
|
|
1515
|
+
vTaskDelay(pdMS_TO_TICKS(2));
|
|
1516
|
+
continue;
|
|
1517
|
+
}
|
|
1518
|
+
stalls = 0;
|
|
1519
|
+
filled += n;
|
|
1520
|
+
}
|
|
1521
|
+
if (filled < want) break;
|
|
1522
|
+
crc = crc32Stream(crc, buffer, filled);
|
|
1523
|
+
err = esp_ota_write(handle, buffer, filled);
|
|
1524
|
+
got += static_cast<long>(filled);
|
|
1525
|
+
}
|
|
1526
|
+
heap_caps_free(buffer);
|
|
1527
|
+
crc ^= 0xFFFFFFFFu;
|
|
1528
|
+
if (got != size || err != ESP_OK) {
|
|
1529
|
+
esp_ota_abort(handle);
|
|
1530
|
+
if (err != ESP_OK) std::printf("GEADEV:OTA ERR write-failed slot=%s err=%s\n", slot->label, esp_err_to_name(err));
|
|
1531
|
+
else std::printf("GEADEV:OTA ERR transfer-failed got=%ld\n", got);
|
|
1532
|
+
return;
|
|
1533
|
+
}
|
|
1534
|
+
if (crc != expectCrc) {
|
|
1535
|
+
esp_ota_abort(handle);
|
|
1536
|
+
std::printf("GEADEV:OTA ERR crc-mismatch got=0x%08x want=0x%08x\n",
|
|
1537
|
+
static_cast<unsigned>(crc), static_cast<unsigned>(expectCrc));
|
|
1538
|
+
return;
|
|
1539
|
+
}
|
|
1540
|
+
err = esp_ota_end(handle);
|
|
1541
|
+
if (err == ESP_OK) err = esp_ota_set_boot_partition(slot);
|
|
1542
|
+
if (err != ESP_OK) {
|
|
1543
|
+
std::printf("GEADEV:OTA ERR write-failed slot=%s err=%s\n", slot->label, esp_err_to_name(err));
|
|
1544
|
+
return;
|
|
1545
|
+
}
|
|
1546
|
+
std::printf("GEADEV:OTA OK slot=%s bytes=%ld crc=0x%08x\n", slot->label, size, static_cast<unsigned>(crc));
|
|
1547
|
+
std::fflush(stdout);
|
|
1548
|
+
vTaskDelay(pdMS_TO_TICKS(200));
|
|
1549
|
+
esp_restart();
|
|
1550
|
+
}
|
|
1551
|
+
|
|
1359
1552
|
void handleOta(char *args)
|
|
1360
1553
|
{
|
|
1361
1554
|
char *sizeTok = nextToken(args);
|
|
@@ -1380,10 +1573,23 @@ void handleOta(char *args)
|
|
|
1380
1573
|
std::printf("GEADEV:OTA ERR too-large bytes=%ld slot=%u\n", size, static_cast<unsigned>(slot->size));
|
|
1381
1574
|
return;
|
|
1382
1575
|
}
|
|
1383
|
-
|
|
1384
|
-
|
|
1385
|
-
|
|
1386
|
-
|
|
1576
|
+
// Staged in 1 MB pieces, not one image-sized block: a board that runs its
|
|
1577
|
+
// firmware from PSRAM (XIP) never has a free block as large as its own
|
|
1578
|
+
// image -- an 8 MB Skytail image met a 6.8 MB largest block on a fresh boot.
|
|
1579
|
+
constexpr std::size_t kStage = 1024 * 1024;
|
|
1580
|
+
const std::size_t pieces = (static_cast<std::size_t>(size) + kStage - 1) / kStage;
|
|
1581
|
+
std::vector<std::uint8_t *> stage(pieces, nullptr);
|
|
1582
|
+
const auto freeStage = [&stage] {
|
|
1583
|
+
for (std::uint8_t *piece : stage) heap_caps_free(piece);
|
|
1584
|
+
};
|
|
1585
|
+
for (std::size_t i = 0; i < pieces; i++) {
|
|
1586
|
+
const std::size_t length = std::min(kStage, static_cast<std::size_t>(size) - i * kStage);
|
|
1587
|
+
stage[i] = static_cast<std::uint8_t *>(heap_caps_malloc(length, MALLOC_CAP_SPIRAM));
|
|
1588
|
+
if (!stage[i]) {
|
|
1589
|
+
freeStage();
|
|
1590
|
+
handleOtaStreamed(slot, size, expectCrc);
|
|
1591
|
+
return;
|
|
1592
|
+
}
|
|
1387
1593
|
}
|
|
1388
1594
|
std::printf("GEADEV:OTA READY slot=%s bytes=%ld\n", slot->label, size);
|
|
1389
1595
|
std::fflush(stdout);
|
|
@@ -1391,7 +1597,10 @@ void handleOta(char *args)
|
|
|
1391
1597
|
long got = 0;
|
|
1392
1598
|
int stalls = 0;
|
|
1393
1599
|
while (got < size) {
|
|
1394
|
-
const std::size_t
|
|
1600
|
+
const std::size_t piece = static_cast<std::size_t>(got) / kStage;
|
|
1601
|
+
const std::size_t at = static_cast<std::size_t>(got) % kStage;
|
|
1602
|
+
const std::size_t want = std::min(kStage - at, static_cast<std::size_t>(size - got));
|
|
1603
|
+
const std::size_t n = std::fread(stage[piece] + at, 1, want, stdin);
|
|
1395
1604
|
if (n == 0) {
|
|
1396
1605
|
std::clearerr(stdin); // an idle read sets the sticky EOF flag
|
|
1397
1606
|
if (++stalls > 5000) break; // ~10s of silence
|
|
@@ -1402,13 +1611,16 @@ void handleOta(char *args)
|
|
|
1402
1611
|
got += static_cast<long>(n);
|
|
1403
1612
|
}
|
|
1404
1613
|
if (got != size) {
|
|
1405
|
-
|
|
1614
|
+
freeStage();
|
|
1406
1615
|
std::printf("GEADEV:OTA ERR transfer-failed got=%ld\n", got);
|
|
1407
1616
|
return;
|
|
1408
1617
|
}
|
|
1409
|
-
|
|
1618
|
+
std::uint32_t crc = 0xFFFFFFFFu;
|
|
1619
|
+
for (std::size_t i = 0; i < pieces; i++)
|
|
1620
|
+
crc = crc32Stream(crc, stage[i], std::min(kStage, static_cast<std::size_t>(size) - i * kStage));
|
|
1621
|
+
crc ^= 0xFFFFFFFFu;
|
|
1410
1622
|
if (crc != expectCrc) {
|
|
1411
|
-
|
|
1623
|
+
freeStage();
|
|
1412
1624
|
std::printf("GEADEV:OTA ERR crc-mismatch got=0x%08x want=0x%08x\n",
|
|
1413
1625
|
static_cast<unsigned>(crc), static_cast<unsigned>(expectCrc));
|
|
1414
1626
|
return;
|
|
@@ -1417,15 +1629,16 @@ void handleOta(char *args)
|
|
|
1417
1629
|
esp_ota_handle_t handle = 0;
|
|
1418
1630
|
esp_err_t err = esp_ota_begin(slot, static_cast<std::size_t>(size), &handle);
|
|
1419
1631
|
if (err == ESP_OK) {
|
|
1420
|
-
constexpr std::size_t kChunk = 64 * 1024;
|
|
1632
|
+
constexpr std::size_t kChunk = 64 * 1024; // divides kStage: no write spans two pieces
|
|
1421
1633
|
for (long offset = 0; offset < size && err == ESP_OK; offset += static_cast<long>(kChunk)) {
|
|
1422
1634
|
const std::size_t n = std::min<std::size_t>(kChunk, static_cast<std::size_t>(size - offset));
|
|
1423
|
-
|
|
1635
|
+
const std::size_t at = static_cast<std::size_t>(offset);
|
|
1636
|
+
err = esp_ota_write(handle, stage[at / kStage] + at % kStage, n);
|
|
1424
1637
|
}
|
|
1425
1638
|
const esp_err_t ended = esp_ota_end(handle);
|
|
1426
1639
|
if (err == ESP_OK) err = ended;
|
|
1427
1640
|
}
|
|
1428
|
-
|
|
1641
|
+
freeStage();
|
|
1429
1642
|
if (err == ESP_OK) err = esp_ota_set_boot_partition(slot);
|
|
1430
1643
|
if (err != ESP_OK) {
|
|
1431
1644
|
std::printf("GEADEV:OTA ERR write-failed slot=%s err=%s\n", slot->label, esp_err_to_name(err));
|
|
@@ -1702,6 +1915,396 @@ void printNetworkDiagnostics()
|
|
|
1702
1915
|
std::printf("GEADEV:NETDIAG END\n");
|
|
1703
1916
|
}
|
|
1704
1917
|
|
|
1918
|
+
#if GEA_EMBEDDED_COMPARISON_BENCHMARK
|
|
1919
|
+
namespace diagnostic_gesture = gea::platform::comparison::gesture;
|
|
1920
|
+
namespace diagnostic_input = gea::platform::comparison::input;
|
|
1921
|
+
static diagnostic_gesture::Plan *gDiagnosticGesture = nullptr;
|
|
1922
|
+
static bool gDiagnosticTouching = false;
|
|
1923
|
+
|
|
1924
|
+
void diagnosticJsonString(const char *value)
|
|
1925
|
+
{
|
|
1926
|
+
std::putchar('"');
|
|
1927
|
+
for (const unsigned char *p = reinterpret_cast<const unsigned char *>(value); *p; ++p) {
|
|
1928
|
+
if (*p == '"' || *p == '\\') {
|
|
1929
|
+
std::printf("\\%c", *p);
|
|
1930
|
+
} else if (*p < 32) {
|
|
1931
|
+
std::printf("\\u%04x", unsigned(*p));
|
|
1932
|
+
} else {
|
|
1933
|
+
std::putchar(*p);
|
|
1934
|
+
}
|
|
1935
|
+
}
|
|
1936
|
+
std::putchar('"');
|
|
1937
|
+
}
|
|
1938
|
+
|
|
1939
|
+
void collectDiagnosticScroll(diagnostic_gesture::Observation &sample, int filter = -1, bool gestureOnly = false)
|
|
1940
|
+
{
|
|
1941
|
+
gea::framework::services::AppState::lock();
|
|
1942
|
+
sample.actualUs = esp_timer_get_time();
|
|
1943
|
+
sample.count = sample.dropped = 0;
|
|
1944
|
+
auto &tree = gea::embedded::ui::Tree::instance();
|
|
1945
|
+
const int root = tree.mountedRoot();
|
|
1946
|
+
const int count = tree.nodeCount();
|
|
1947
|
+
for (int id = 0; id < count; ++id) {
|
|
1948
|
+
const auto &node = tree.node(id);
|
|
1949
|
+
if (GEA_DIAGNOSTIC_NODE_STYLE(node).display == gea::embedded::ui::kDisplayNone) {
|
|
1950
|
+
continue;
|
|
1951
|
+
}
|
|
1952
|
+
bool mounted = false;
|
|
1953
|
+
for (int parent = id, guard = 0; parent >= 0 && parent < count && guard++ < count;
|
|
1954
|
+
parent = tree.node(parent).parent) {
|
|
1955
|
+
if (GEA_DIAGNOSTIC_NODE_STYLE(tree.node(parent)).display == gea::embedded::ui::kDisplayNone) {
|
|
1956
|
+
break;
|
|
1957
|
+
}
|
|
1958
|
+
if (parent == root) {
|
|
1959
|
+
mounted = true;
|
|
1960
|
+
break;
|
|
1961
|
+
}
|
|
1962
|
+
}
|
|
1963
|
+
if (!mounted) {
|
|
1964
|
+
continue;
|
|
1965
|
+
}
|
|
1966
|
+
int kind = -1;
|
|
1967
|
+
for (unsigned index = 0;
|
|
1968
|
+
index < (gestureOnly ? diagnostic_gesture::kGestureClassCount : std::size(diagnostic_gesture::kClasses));
|
|
1969
|
+
++index) {
|
|
1970
|
+
if ((filter < 0 || filter == int(index)) && tree.hasClass(id, diagnostic_gesture::kClasses[index])) {
|
|
1971
|
+
kind = int(index);
|
|
1972
|
+
break;
|
|
1973
|
+
}
|
|
1974
|
+
}
|
|
1975
|
+
if (kind < 0) {
|
|
1976
|
+
continue;
|
|
1977
|
+
}
|
|
1978
|
+
if (sample.count == diagnostic_gesture::kNodeCapacity) {
|
|
1979
|
+
++sample.dropped;
|
|
1980
|
+
continue;
|
|
1981
|
+
}
|
|
1982
|
+
auto &entry = sample.nodes[sample.count++];
|
|
1983
|
+
entry.id = id;
|
|
1984
|
+
entry.kind = kind;
|
|
1985
|
+
entry.parent = node.parent;
|
|
1986
|
+
entry.x = node.layout.x;
|
|
1987
|
+
entry.y = node.layout.y;
|
|
1988
|
+
entry.width = node.layout.width;
|
|
1989
|
+
entry.height = node.layout.height;
|
|
1990
|
+
entry.scrollX = node.layout.scroll_x;
|
|
1991
|
+
entry.scrollY = node.layout.scroll_y;
|
|
1992
|
+
entry.contentWidth = node.layout.scroll_content_width;
|
|
1993
|
+
entry.contentHeight = node.layout.scroll_content_height;
|
|
1994
|
+
entry.selected = tree.hasClass(id, "selected") || tree.hasClass(id, "roller-selected-track") ||
|
|
1995
|
+
(tree.hasClass(id, "switch") && tree.hasClass(id, "on"))
|
|
1996
|
+
? 1
|
|
1997
|
+
: 0;
|
|
1998
|
+
entry.children = 0;
|
|
1999
|
+
entry.textTruncated = false;
|
|
2000
|
+
entry.text[0] = '\0';
|
|
2001
|
+
for (int child = node.first_child, guard = 0; child >= 0 && child < count && guard++ < count;
|
|
2002
|
+
child = tree.node(child).next_sibling) {
|
|
2003
|
+
++entry.children;
|
|
2004
|
+
}
|
|
2005
|
+
std::size_t length = 0;
|
|
2006
|
+
// Traverse actual descendants without allocations. Keep bounded text and
|
|
2007
|
+
// explicitly disclose truncation; never infer application state privately.
|
|
2008
|
+
for (int descendant = id, guard = 0; descendant >= 0 && descendant < count && guard++ < count;) {
|
|
2009
|
+
const auto ¤t = tree.node(descendant);
|
|
2010
|
+
const auto &text = current.text;
|
|
2011
|
+
if (!text.empty()) {
|
|
2012
|
+
const auto available = sizeof(entry.text) - 1 - length;
|
|
2013
|
+
const auto copied = std::min(available, text.size());
|
|
2014
|
+
std::memcpy(entry.text + length, text.data(), copied);
|
|
2015
|
+
length += copied;
|
|
2016
|
+
entry.text[length] = '\0';
|
|
2017
|
+
entry.textTruncated |= copied != text.size();
|
|
2018
|
+
}
|
|
2019
|
+
if (current.first_child >= 0 && current.first_child < count) {
|
|
2020
|
+
descendant = current.first_child;
|
|
2021
|
+
continue;
|
|
2022
|
+
}
|
|
2023
|
+
int climbed = 0;
|
|
2024
|
+
while (descendant != id && descendant >= 0 && descendant < count &&
|
|
2025
|
+
tree.node(descendant).next_sibling < 0 && climbed++ < count) {
|
|
2026
|
+
descendant = tree.node(descendant).parent;
|
|
2027
|
+
}
|
|
2028
|
+
if (climbed >= count) {
|
|
2029
|
+
break;
|
|
2030
|
+
}
|
|
2031
|
+
if (descendant == id || descendant < 0 || descendant >= count) {
|
|
2032
|
+
break;
|
|
2033
|
+
}
|
|
2034
|
+
descendant = tree.node(descendant).next_sibling;
|
|
2035
|
+
}
|
|
2036
|
+
gea::embedded::ui::ViewRenderer::transformedRectCorners(node, false, node.layout.x, node.layout.y,
|
|
2037
|
+
node.layout.width, node.layout.height, entry.cornerX,
|
|
2038
|
+
entry.cornerY);
|
|
2039
|
+
}
|
|
2040
|
+
gea::framework::services::AppState::unlock();
|
|
2041
|
+
}
|
|
2042
|
+
|
|
2043
|
+
void printDiagnosticNodes(const diagnostic_gesture::Observation &sample)
|
|
2044
|
+
{
|
|
2045
|
+
std::putchar('[');
|
|
2046
|
+
for (unsigned index = 0; index < sample.count; ++index) {
|
|
2047
|
+
const auto &node = sample.nodes[index];
|
|
2048
|
+
std::printf("%s{\"id\":%d,\"parent\":%d,\"class\":", index ? "," : "", node.id, node.parent);
|
|
2049
|
+
diagnosticJsonString(diagnostic_gesture::kClasses[node.kind]);
|
|
2050
|
+
std::printf(
|
|
2051
|
+
",\"x\":%d,\"y\":%d,\"width\":%d,\"height\":%d,\"selected_class\":%d,\"scroll_x\":%d,\"scroll_y\":%d,"
|
|
2052
|
+
"\"content_width\":%d,\"content_height\":%d,\"children_count\":%d,\"text_truncated\":%s,\"corners\":[[%d,%"
|
|
2053
|
+
"d],[%d,%d],[%d,%d],[%d,%d]],\"text\":",
|
|
2054
|
+
node.x, node.y, node.width, node.height, node.selected, node.scrollX, node.scrollY, node.contentWidth,
|
|
2055
|
+
node.contentHeight, node.children, node.textTruncated ? "true" : "false", node.cornerX[0], node.cornerY[0],
|
|
2056
|
+
node.cornerX[1], node.cornerY[1], node.cornerX[2], node.cornerY[2], node.cornerX[3], node.cornerY[3]);
|
|
2057
|
+
diagnosticJsonString(node.text);
|
|
2058
|
+
std::putchar('}');
|
|
2059
|
+
}
|
|
2060
|
+
std::putchar(']');
|
|
2061
|
+
}
|
|
2062
|
+
|
|
2063
|
+
void printDiagnosticInput(const diagnostic_input::Snapshot &trace)
|
|
2064
|
+
{
|
|
2065
|
+
std::putchar('[');
|
|
2066
|
+
for (unsigned index = 0; index < trace.count; ++index) {
|
|
2067
|
+
const auto &entry = trace.entries[index];
|
|
2068
|
+
std::printf("%s[%lld,%d,%d,%d,%d,%d,%d,%d]", index ? "," : "", static_cast<long long>(entry.timestampUs),
|
|
2069
|
+
entry.phase, entry.touching, entry.x, entry.y, entry.pointerId, entry.handlerX, entry.handlerY);
|
|
2070
|
+
}
|
|
2071
|
+
std::putchar(']');
|
|
2072
|
+
}
|
|
2073
|
+
|
|
2074
|
+
void releaseDiagnosticGesture()
|
|
2075
|
+
{
|
|
2076
|
+
if (!gDiagnosticGesture) {
|
|
2077
|
+
return;
|
|
2078
|
+
}
|
|
2079
|
+
heap_caps_free(gDiagnosticGesture->pointerReads.entries);
|
|
2080
|
+
gDiagnosticGesture->~Plan();
|
|
2081
|
+
heap_caps_free(gDiagnosticGesture);
|
|
2082
|
+
gDiagnosticGesture = nullptr;
|
|
2083
|
+
}
|
|
2084
|
+
|
|
2085
|
+
bool beginDiagnosticInput()
|
|
2086
|
+
{
|
|
2087
|
+
constexpr unsigned capacity = 256;
|
|
2088
|
+
auto *storage = static_cast<diagnostic_input::Entry *>(
|
|
2089
|
+
heap_caps_malloc(sizeof(diagnostic_input::Entry) * capacity, MALLOC_CAP_SPIRAM | MALLOC_CAP_8BIT));
|
|
2090
|
+
if (!diagnostic_input::begin(storage, capacity)) {
|
|
2091
|
+
heap_caps_free(storage);
|
|
2092
|
+
return false;
|
|
2093
|
+
}
|
|
2094
|
+
return true;
|
|
2095
|
+
}
|
|
2096
|
+
|
|
2097
|
+
void handleDiagnosticGesture(char *&cursor)
|
|
2098
|
+
{
|
|
2099
|
+
const char *action = nextToken(cursor);
|
|
2100
|
+
if (gea::platform::comparison::enabled.load(std::memory_order_acquire) ||
|
|
2101
|
+
diagnostic_input::recording.load(std::memory_order_acquire) ||
|
|
2102
|
+
gea::platform::comparison::upload::armed.load(std::memory_order_acquire)) {
|
|
2103
|
+
std::puts("GEADEV:ERR GESTURE benchmark-input-trace-or-upload-active");
|
|
2104
|
+
return;
|
|
2105
|
+
}
|
|
2106
|
+
if (tokenEquals(action, "RESET")) {
|
|
2107
|
+
releaseDiagnosticGesture();
|
|
2108
|
+
void *storage = heap_caps_malloc(sizeof(diagnostic_gesture::Plan), MALLOC_CAP_SPIRAM | MALLOC_CAP_8BIT);
|
|
2109
|
+
if (!storage) {
|
|
2110
|
+
std::puts("GEADEV:ERR GESTURE allocation-failed");
|
|
2111
|
+
return;
|
|
2112
|
+
}
|
|
2113
|
+
gDiagnosticGesture = new (storage) diagnostic_gesture::Plan{};
|
|
2114
|
+
std::puts("GEADEV:OK GESTURE RESET");
|
|
2115
|
+
} else if (tokenEquals(action, "CLEAR")) {
|
|
2116
|
+
releaseDiagnosticGesture();
|
|
2117
|
+
std::puts("GEADEV:OK GESTURE CLEAR");
|
|
2118
|
+
} else if (!gDiagnosticGesture) {
|
|
2119
|
+
std::puts("GEADEV:ERR GESTURE reset-required");
|
|
2120
|
+
} else if (tokenEquals(action, "TOUCH")) {
|
|
2121
|
+
int ms, state, x, y;
|
|
2122
|
+
if (std::sscanf(cursor, "%d %d %d %d", &ms, &state, &x, &y) != 4 ||
|
|
2123
|
+
!gDiagnosticGesture->addTouch(ms, state, x, y)) {
|
|
2124
|
+
std::puts("GEADEV:ERR GESTURE invalid-touch");
|
|
2125
|
+
return;
|
|
2126
|
+
}
|
|
2127
|
+
std::puts("GEADEV:OK GESTURE TOUCH");
|
|
2128
|
+
} else if (tokenEquals(action, "OBSERVE")) {
|
|
2129
|
+
int ms;
|
|
2130
|
+
if (std::sscanf(cursor, "%d", &ms) != 1 || !gDiagnosticGesture->addObservation(ms)) {
|
|
2131
|
+
std::puts("GEADEV:ERR GESTURE invalid-observation");
|
|
2132
|
+
return;
|
|
2133
|
+
}
|
|
2134
|
+
std::puts("GEADEV:OK GESTURE OBSERVE");
|
|
2135
|
+
} else if (tokenEquals(action, "BEGIN")) {
|
|
2136
|
+
if (!gDiagnosticGesture->valid() || !beginDiagnosticInput()) {
|
|
2137
|
+
std::puts("GEADEV:ERR GESTURE invalid-plan-or-trace");
|
|
2138
|
+
return;
|
|
2139
|
+
}
|
|
2140
|
+
std::puts("GEADEV:OK GESTURE BEGIN");
|
|
2141
|
+
std::fflush(stdout);
|
|
2142
|
+
diagnostic_gesture::play(
|
|
2143
|
+
*gDiagnosticGesture, [] { return esp_timer_get_time(); },
|
|
2144
|
+
[](std::int64_t remaining) {
|
|
2145
|
+
if (remaining >= 1000) {
|
|
2146
|
+
vTaskDelay(pdMS_TO_TICKS(std::max<std::int64_t>(1, remaining / 1000)));
|
|
2147
|
+
} else {
|
|
2148
|
+
taskYIELD();
|
|
2149
|
+
}
|
|
2150
|
+
},
|
|
2151
|
+
[](int phase, bool touching, int x, int y) {
|
|
2152
|
+
gea::platform::touch::Touchscreen::injectEvent(static_cast<gea::platform::touch::Phase>(phase),
|
|
2153
|
+
touching, x, y);
|
|
2154
|
+
},
|
|
2155
|
+
[](diagnostic_gesture::Observation &sample) { collectDiagnosticScroll(sample, -1, true); });
|
|
2156
|
+
gDiagnosticGesture->pointerReads = diagnostic_input::end();
|
|
2157
|
+
} else if (tokenEquals(action, "RESULT")) {
|
|
2158
|
+
const auto &plan = *gDiagnosticGesture;
|
|
2159
|
+
if (!plan.complete) {
|
|
2160
|
+
std::puts("GEADEV:ERR GESTURE incomplete");
|
|
2161
|
+
return;
|
|
2162
|
+
}
|
|
2163
|
+
std::printf(
|
|
2164
|
+
"SWGESTURE {\"framework\":\"gea\",\"clock_origin_us\":%lld,\"normal_input_authority\":\"TouchRuntime "
|
|
2165
|
+
"consumed dispatch\",\"coordinate_space\":\"logical\",\"events\":[",
|
|
2166
|
+
static_cast<long long>(plan.originUs));
|
|
2167
|
+
for (unsigned index = 0; index < plan.eventCount; ++index) {
|
|
2168
|
+
const auto &event = plan.events[index];
|
|
2169
|
+
std::printf("%s{\"requested_at_ms\":%d,\"actual_at_us\":%lld,\"state\":%d,\"phase\":%d,\"x\":%d,\"y\":%d}",
|
|
2170
|
+
index ? "," : "", event.requestedMs, static_cast<long long>(event.actualUs), event.state,
|
|
2171
|
+
event.phase, event.x, event.y);
|
|
2172
|
+
}
|
|
2173
|
+
std::printf("],\"pointer_reads_dropped\":%u,\"pointer_reads\":", plan.pointerReads.dropped);
|
|
2174
|
+
printDiagnosticInput(plan.pointerReads);
|
|
2175
|
+
std::printf(",\"observations\":[");
|
|
2176
|
+
for (unsigned index = 0; index < plan.observationCount; ++index) {
|
|
2177
|
+
const auto &sample = plan.observations[index];
|
|
2178
|
+
std::printf("%s{\"requested_at_ms\":%d,\"actual_at_us\":%lld,\"nodes_dropped\":%u,\"nodes\":",
|
|
2179
|
+
index ? "," : "", sample.requestedMs, static_cast<long long>(sample.actualUs), sample.dropped);
|
|
2180
|
+
printDiagnosticNodes(sample);
|
|
2181
|
+
std::putchar('}');
|
|
2182
|
+
}
|
|
2183
|
+
std::puts("]}");
|
|
2184
|
+
} else {
|
|
2185
|
+
std::puts("GEADEV:ERR GESTURE unknown-action");
|
|
2186
|
+
}
|
|
2187
|
+
}
|
|
2188
|
+
|
|
2189
|
+
const char *diagnosticOptimization()
|
|
2190
|
+
{
|
|
2191
|
+
#if CONFIG_COMPILER_OPTIMIZATION_PERF
|
|
2192
|
+
return "O2";
|
|
2193
|
+
#elif CONFIG_COMPILER_OPTIMIZATION_DEBUG
|
|
2194
|
+
return "Og";
|
|
2195
|
+
#elif CONFIG_COMPILER_OPTIMIZATION_SIZE
|
|
2196
|
+
return "Os";
|
|
2197
|
+
#elif CONFIG_COMPILER_OPTIMIZATION_NONE
|
|
2198
|
+
return "O0";
|
|
2199
|
+
#else
|
|
2200
|
+
return "unknown";
|
|
2201
|
+
#endif
|
|
2202
|
+
}
|
|
2203
|
+
|
|
2204
|
+
bool lockDiagnosticUploadBoundary()
|
|
2205
|
+
{
|
|
2206
|
+
gea::framework::services::AppState::lock();
|
|
2207
|
+
const auto start = esp_timer_get_time();
|
|
2208
|
+
while (gea_frame_capture_boundary_ready && !gea_frame_capture_boundary_ready()) {
|
|
2209
|
+
if (esp_timer_get_time() - start > 1000000) {
|
|
2210
|
+
gea::framework::services::AppState::unlock();
|
|
2211
|
+
return false;
|
|
2212
|
+
}
|
|
2213
|
+
vTaskDelay(pdMS_TO_TICKS(1));
|
|
2214
|
+
}
|
|
2215
|
+
if (!gea_frame_capture_boundary_ready || !gea_display_wait_for_uploads || !gea_display_wait_for_uploads()) {
|
|
2216
|
+
gea::framework::services::AppState::unlock();
|
|
2217
|
+
return false;
|
|
2218
|
+
}
|
|
2219
|
+
return true;
|
|
2220
|
+
}
|
|
2221
|
+
|
|
2222
|
+
void handleDiagnosticUpload(char *&cursor)
|
|
2223
|
+
{
|
|
2224
|
+
namespace upload = gea::platform::comparison::upload;
|
|
2225
|
+
if (gea::platform::comparison::enabled.load(std::memory_order_acquire) ||
|
|
2226
|
+
diagnostic_input::recording.load(std::memory_order_acquire)) {
|
|
2227
|
+
std::puts("GEADEV:ERR UPLOADSHOT benchmark-or-input-trace-active");
|
|
2228
|
+
return;
|
|
2229
|
+
}
|
|
2230
|
+
const char *action = nextToken(cursor);
|
|
2231
|
+
if (tokenEquals(action, "ARM")) {
|
|
2232
|
+
if (upload::armed.load(std::memory_order_acquire)) {
|
|
2233
|
+
std::puts("GEADEV:ERR UPLOADSHOT already-armed");
|
|
2234
|
+
return;
|
|
2235
|
+
}
|
|
2236
|
+
const int width = gea::platform::display::kNativeWidth, height = gea::platform::display::kNativeHeight;
|
|
2237
|
+
const auto count = std::size_t(width) * height;
|
|
2238
|
+
auto *pixels = static_cast<std::uint16_t *>(
|
|
2239
|
+
heap_caps_malloc(count * 2 + (count + 7) / 8, MALLOC_CAP_SPIRAM | MALLOC_CAP_8BIT));
|
|
2240
|
+
if (!pixels || !lockDiagnosticUploadBoundary()) {
|
|
2241
|
+
heap_caps_free(pixels);
|
|
2242
|
+
std::puts("GEADEV:ERR UPLOADSHOT no-memory-or-display-busy");
|
|
2243
|
+
return;
|
|
2244
|
+
}
|
|
2245
|
+
const bool started = upload::begin(pixels, width, height);
|
|
2246
|
+
if (started) {
|
|
2247
|
+
gea::embedded::ui::Tree::instance().markDisplayListDirty();
|
|
2248
|
+
gea::platform::display::Display::invalidate();
|
|
2249
|
+
}
|
|
2250
|
+
gea::framework::services::AppState::unlock();
|
|
2251
|
+
if (!started) {
|
|
2252
|
+
heap_caps_free(pixels);
|
|
2253
|
+
std::puts("GEADEV:ERR UPLOADSHOT unavailable");
|
|
2254
|
+
return;
|
|
2255
|
+
}
|
|
2256
|
+
std::puts("GEADEV:OK UPLOADSHOT ARM source=co5300-submitted-rgb565 normal-full-invalidate=1");
|
|
2257
|
+
} else if (tokenEquals(action, "DISARM")) {
|
|
2258
|
+
const auto image = upload::end();
|
|
2259
|
+
heap_caps_free(image.pixels);
|
|
2260
|
+
std::puts("GEADEV:OK UPLOADSHOT DISARM");
|
|
2261
|
+
} else if (!action || tokenEquals(action, "READ")) {
|
|
2262
|
+
if (!upload::armed.load(std::memory_order_acquire)) {
|
|
2263
|
+
std::puts("GEADEV:ERR UPLOADSHOT arm-required");
|
|
2264
|
+
return;
|
|
2265
|
+
}
|
|
2266
|
+
if (!lockDiagnosticUploadBoundary()) {
|
|
2267
|
+
std::puts("GEADEV:ERR UPLOADSHOT display-busy");
|
|
2268
|
+
return;
|
|
2269
|
+
}
|
|
2270
|
+
const auto image = upload::end();
|
|
2271
|
+
const auto capturedUs = esp_timer_get_time();
|
|
2272
|
+
gea::framework::services::AppState::unlock();
|
|
2273
|
+
const auto count = std::size_t(image.width) * image.height;
|
|
2274
|
+
if (!image.pixels || image.covered != count || image.errors) {
|
|
2275
|
+
heap_caps_free(image.pixels);
|
|
2276
|
+
std::printf("GEADEV:ERR UPLOADSHOT incomplete covered=%u required=%u errors=%u\n", image.covered,
|
|
2277
|
+
unsigned(count), image.errors);
|
|
2278
|
+
return;
|
|
2279
|
+
}
|
|
2280
|
+
flockfile(stdout);
|
|
2281
|
+
std::printf("GEADEV:UPLOADSHOT BEGIN width=%d height=%d encoding=rgb565-rle-v1 source=co5300-submitted-rgb565 "
|
|
2282
|
+
"completed_dma=1 timestamp_us=%lld submitted_pixels=%llu\n",
|
|
2283
|
+
image.width, image.height, static_cast<long long>(capturedUs),
|
|
2284
|
+
static_cast<unsigned long long>(image.submittedPixels));
|
|
2285
|
+
Base64Writer writer;
|
|
2286
|
+
std::uint16_t value = image.pixels[0], run = 1;
|
|
2287
|
+
for (std::size_t index = 1; index < count; ++index) {
|
|
2288
|
+
if (image.pixels[index] == value && run < 65535) {
|
|
2289
|
+
++run;
|
|
2290
|
+
continue;
|
|
2291
|
+
}
|
|
2292
|
+
writeRun(writer, run, value);
|
|
2293
|
+
value = image.pixels[index];
|
|
2294
|
+
run = 1;
|
|
2295
|
+
}
|
|
2296
|
+
writeRun(writer, run, value);
|
|
2297
|
+
writer.finish();
|
|
2298
|
+
std::puts("GEADEV:UPLOADSHOT END");
|
|
2299
|
+
std::fflush(stdout);
|
|
2300
|
+
funlockfile(stdout);
|
|
2301
|
+
heap_caps_free(image.pixels);
|
|
2302
|
+
} else {
|
|
2303
|
+
std::puts("GEADEV:ERR UPLOADSHOT usage=ARM_READ_DISARM");
|
|
2304
|
+
}
|
|
2305
|
+
}
|
|
2306
|
+
#endif
|
|
2307
|
+
|
|
1705
2308
|
// Optional per-target GEADEV command extension. The weak default (defined at the
|
|
1706
2309
|
// end of this file, outside the namespace) returns false; a target that wants
|
|
1707
2310
|
// extra commands — e.g. the ESP32-P4 camera capture (CAMSTILL / CAMCLIP) in
|
|
@@ -1721,6 +2324,17 @@ void handleCommand(char *line, CommandSource source)
|
|
|
1721
2324
|
return;
|
|
1722
2325
|
}
|
|
1723
2326
|
|
|
2327
|
+
#if defined(GEA_NATIVE_DEBUGGER) && GEA_NATIVE_DEBUGGER
|
|
2328
|
+
if (tokenEquals(command, "DEBUG")) {
|
|
2329
|
+
#if CONFIG_ESP_CONSOLE_USB_SERIAL_JTAG || CONFIG_ESP_CONSOLE_SECONDARY_USB_SERIAL_JTAG
|
|
2330
|
+
ScopedLogSilence silence;
|
|
2331
|
+
gea::debugger::handle(cursor, &usbWriteAll);
|
|
2332
|
+
#else
|
|
2333
|
+
gea::debugger::handle(cursor);
|
|
2334
|
+
#endif
|
|
2335
|
+
return;
|
|
2336
|
+
}
|
|
2337
|
+
#endif
|
|
1724
2338
|
if (tokenEquals(command, "PING")) {
|
|
1725
2339
|
// `gea boards discover` identifies a plugged-in unit from this one
|
|
1726
2340
|
// line: the app it runs, the address it holds (0.0.0.0 without WiFi)
|
|
@@ -1809,6 +2423,231 @@ void handleCommand(char *line, CommandSource source)
|
|
|
1809
2423
|
gea::framework::services::AppState::unlock();
|
|
1810
2424
|
std::printf("GEADEV:VIDEO %s\n", found ? "OK" : "missing-node");
|
|
1811
2425
|
}
|
|
2426
|
+
} else if (tokenEquals(command, "TOUCH")) {
|
|
2427
|
+
#if GEA_EMBEDDED_COMPARISON_BENCHMARK
|
|
2428
|
+
if (gea::platform::comparison::enabled.load(std::memory_order_acquire)) {
|
|
2429
|
+
std::puts("GEADEV:ERR TOUCH benchmark-active");
|
|
2430
|
+
return;
|
|
2431
|
+
}
|
|
2432
|
+
const char *action = nextToken(cursor);
|
|
2433
|
+
int x, y, phase = 0;
|
|
2434
|
+
if (tokenEquals(action, "down")) {
|
|
2435
|
+
phase = 1;
|
|
2436
|
+
} else if (tokenEquals(action, "move") || tokenEquals(action, "2")) {
|
|
2437
|
+
phase = 2;
|
|
2438
|
+
} else if (tokenEquals(action, "up") || tokenEquals(action, "0")) {
|
|
2439
|
+
phase = 3;
|
|
2440
|
+
} else if (tokenEquals(action, "1")) {
|
|
2441
|
+
phase = gDiagnosticTouching ? 2 : 1;
|
|
2442
|
+
}
|
|
2443
|
+
if (!phase || std::sscanf(cursor, "%d %d", &x, &y) != 2) {
|
|
2444
|
+
std::puts("GEADEV:ERR TOUCH usage=down-move-up_x_y");
|
|
2445
|
+
return;
|
|
2446
|
+
}
|
|
2447
|
+
gDiagnosticTouching = phase != 3;
|
|
2448
|
+
gea::platform::touch::Touchscreen::injectEvent(static_cast<gea::platform::touch::Phase>(phase), phase != 3, x,
|
|
2449
|
+
y);
|
|
2450
|
+
std::puts("GEADEV:OK TOUCH");
|
|
2451
|
+
#else
|
|
2452
|
+
std::puts("GEADEV:ERR TOUCH comparison-diagnostic-not-enabled");
|
|
2453
|
+
#endif
|
|
2454
|
+
} else if (tokenEquals(command, "INPUTTRACE")) {
|
|
2455
|
+
#if GEA_EMBEDDED_COMPARISON_BENCHMARK
|
|
2456
|
+
const char *action = nextToken(cursor);
|
|
2457
|
+
if (gea::platform::comparison::enabled.load(std::memory_order_acquire)) {
|
|
2458
|
+
std::puts("GEADEV:ERR INPUTTRACE benchmark-active");
|
|
2459
|
+
return;
|
|
2460
|
+
}
|
|
2461
|
+
if (tokenEquals(action, "BEGIN")) {
|
|
2462
|
+
if (gDiagnosticGesture || !beginDiagnosticInput()) {
|
|
2463
|
+
std::puts("GEADEV:ERR INPUTTRACE unavailable-or-active");
|
|
2464
|
+
return;
|
|
2465
|
+
}
|
|
2466
|
+
std::puts("GEADEV:OK INPUTTRACE BEGIN");
|
|
2467
|
+
} else if (tokenEquals(action, "END")) {
|
|
2468
|
+
if (!diagnostic_input::recording.load(std::memory_order_acquire)) {
|
|
2469
|
+
std::puts("GEADEV:ERR INPUTTRACE inactive");
|
|
2470
|
+
return;
|
|
2471
|
+
}
|
|
2472
|
+
const auto trace = diagnostic_input::end();
|
|
2473
|
+
std::printf("SWINPUT {\"framework\":\"gea\",\"coordinate_space\":\"logical\",\"dropped\":%u,\"samples\":",
|
|
2474
|
+
trace.dropped);
|
|
2475
|
+
printDiagnosticInput(trace);
|
|
2476
|
+
std::puts("}");
|
|
2477
|
+
heap_caps_free(trace.entries);
|
|
2478
|
+
} else {
|
|
2479
|
+
std::puts("GEADEV:ERR INPUTTRACE usage=BEGIN_or_END");
|
|
2480
|
+
}
|
|
2481
|
+
#else
|
|
2482
|
+
std::puts("GEADEV:ERR INPUTTRACE comparison-diagnostic-not-enabled");
|
|
2483
|
+
#endif
|
|
2484
|
+
} else if (tokenEquals(command, "SCROLLSTATE")) {
|
|
2485
|
+
#if GEA_EMBEDDED_COMPARISON_BENCHMARK
|
|
2486
|
+
if (gea::platform::comparison::enabled.load(std::memory_order_acquire)) {
|
|
2487
|
+
std::puts("GEADEV:ERR SCROLLSTATE benchmark-active");
|
|
2488
|
+
return;
|
|
2489
|
+
}
|
|
2490
|
+
int filter = -1;
|
|
2491
|
+
if (const char *name = nextToken(cursor)) {
|
|
2492
|
+
for (unsigned index = 0; index < std::size(diagnostic_gesture::kClasses); ++index) {
|
|
2493
|
+
if (tokenEquals(name, diagnostic_gesture::kClasses[index])) {
|
|
2494
|
+
filter = int(index);
|
|
2495
|
+
}
|
|
2496
|
+
}
|
|
2497
|
+
if (filter < 0) {
|
|
2498
|
+
std::puts("GEADEV:ERR SCROLLSTATE unknown-class");
|
|
2499
|
+
return;
|
|
2500
|
+
}
|
|
2501
|
+
}
|
|
2502
|
+
auto *sample = static_cast<diagnostic_gesture::Observation *>(
|
|
2503
|
+
heap_caps_malloc(sizeof(diagnostic_gesture::Observation), MALLOC_CAP_SPIRAM | MALLOC_CAP_8BIT));
|
|
2504
|
+
if (!sample) {
|
|
2505
|
+
std::puts("GEADEV:ERR SCROLLSTATE allocation-failed");
|
|
2506
|
+
return;
|
|
2507
|
+
}
|
|
2508
|
+
collectDiagnosticScroll(*sample, filter);
|
|
2509
|
+
std::printf("SWSCROLL {\"timestamp_us\":%lld,\"nodes_dropped\":%u,\"nodes\":",
|
|
2510
|
+
static_cast<long long>(sample->actualUs), sample->dropped);
|
|
2511
|
+
printDiagnosticNodes(*sample);
|
|
2512
|
+
std::puts("}");
|
|
2513
|
+
heap_caps_free(sample);
|
|
2514
|
+
#else
|
|
2515
|
+
std::puts("GEADEV:ERR SCROLLSTATE comparison-diagnostic-not-enabled");
|
|
2516
|
+
#endif
|
|
2517
|
+
} else if (tokenEquals(command, "GESTURE")) {
|
|
2518
|
+
#if GEA_EMBEDDED_COMPARISON_BENCHMARK
|
|
2519
|
+
handleDiagnosticGesture(cursor);
|
|
2520
|
+
#else
|
|
2521
|
+
std::puts("GEADEV:ERR GESTURE comparison-diagnostic-not-enabled");
|
|
2522
|
+
#endif
|
|
2523
|
+
} else if (tokenEquals(command, "CLOCKFREEZE")) {
|
|
2524
|
+
#if GEA_EMBEDDED_COMPARISON_BENCHMARK
|
|
2525
|
+
long long epoch;
|
|
2526
|
+
if (gea::platform::comparison::enabled.load(std::memory_order_acquire)) {
|
|
2527
|
+
std::puts("GEADEV:ERR CLOCKFREEZE benchmark-active");
|
|
2528
|
+
return;
|
|
2529
|
+
}
|
|
2530
|
+
if (std::sscanf(cursor, "%lld", &epoch) != 1 || epoch < 0 || epoch > 4102444800LL) {
|
|
2531
|
+
std::puts("GEADEV:ERR CLOCKFREEZE invalid-epoch");
|
|
2532
|
+
return;
|
|
2533
|
+
}
|
|
2534
|
+
gea::platform::comparison::frozenEpochSeconds.store(epoch, std::memory_order_relaxed);
|
|
2535
|
+
std::printf("GEADEV:OK CLOCKFREEZE epoch=%lld\n", epoch);
|
|
2536
|
+
#else
|
|
2537
|
+
std::puts("GEADEV:ERR CLOCKFREEZE comparison-diagnostic-not-enabled");
|
|
2538
|
+
#endif
|
|
2539
|
+
} else if (tokenEquals(command, "UPLOADSHOT")) {
|
|
2540
|
+
#if GEA_EMBEDDED_COMPARISON_BENCHMARK
|
|
2541
|
+
handleDiagnosticUpload(cursor);
|
|
2542
|
+
#else
|
|
2543
|
+
std::puts("GEADEV:ERR UPLOADSHOT comparison-diagnostic-not-enabled");
|
|
2544
|
+
#endif
|
|
2545
|
+
} else if (tokenEquals(command, "COMPLETION")) {
|
|
2546
|
+
#if GEA_EMBEDDED_COMPARISON_BENCHMARK
|
|
2547
|
+
bool on;
|
|
2548
|
+
if (gea::platform::comparison::enabled.load(std::memory_order_acquire) || !parseOnOff(nextToken(cursor), &on)) {
|
|
2549
|
+
std::puts("GEADEV:ERR COMPLETION inactive-benchmark-and-0-or-1-required");
|
|
2550
|
+
return;
|
|
2551
|
+
}
|
|
2552
|
+
gea::platform::comparison::completionFence.store(on, std::memory_order_relaxed);
|
|
2553
|
+
std::printf("GEADEV:OK COMPLETION fence=%d\n", on ? 1 : 0);
|
|
2554
|
+
#else
|
|
2555
|
+
std::puts("GEADEV:ERR COMPLETION comparison-diagnostic-not-enabled");
|
|
2556
|
+
#endif
|
|
2557
|
+
} else if (tokenEquals(command, "BENCH")) {
|
|
2558
|
+
#if GEA_EMBEDDED_COMPARISON_BENCHMARK
|
|
2559
|
+
const char *action = nextToken(cursor);
|
|
2560
|
+
if (tokenEquals(action, "BEGIN")) {
|
|
2561
|
+
if (gDiagnosticGesture || diagnostic_input::recording.load(std::memory_order_acquire) ||
|
|
2562
|
+
gea::platform::comparison::frozenEpochSeconds.load(std::memory_order_relaxed) ||
|
|
2563
|
+
gea::platform::comparison::upload::armed.load(std::memory_order_acquire)) {
|
|
2564
|
+
std::puts("GEADEV:ERR BENCH clear-gesture-input-trace-and-clock-freeze-first");
|
|
2565
|
+
return;
|
|
2566
|
+
}
|
|
2567
|
+
const char *runId = nextToken(cursor);
|
|
2568
|
+
const char *scenario = nextToken(cursor);
|
|
2569
|
+
const auto validName = [](const char *name) {
|
|
2570
|
+
if (!name || !*name || std::strlen(name) >= 64) {
|
|
2571
|
+
return false;
|
|
2572
|
+
}
|
|
2573
|
+
for (const char *p = name; *p; ++p) {
|
|
2574
|
+
if (!std::isalnum(static_cast<unsigned char>(*p)) && *p != '-' && *p != '_' && *p != '.') {
|
|
2575
|
+
return false;
|
|
2576
|
+
}
|
|
2577
|
+
}
|
|
2578
|
+
return true;
|
|
2579
|
+
};
|
|
2580
|
+
if (!validName(runId) || !validName(scenario)) {
|
|
2581
|
+
std::puts(
|
|
2582
|
+
"GEADEV:ERR BENCH usage=BEGIN_run-id_scenario_names-up-to-63-alphanumeric-dash-dot-underscore");
|
|
2583
|
+
return;
|
|
2584
|
+
}
|
|
2585
|
+
gea::platform::comparison::begin(runId, scenario, esp_timer_get_time());
|
|
2586
|
+
std::printf("GEADEV:OK BENCH BEGIN run_id=%s scenario=%s\n", runId, scenario);
|
|
2587
|
+
} else if (tokenEquals(action, "END")) {
|
|
2588
|
+
if (!gea::platform::comparison::enabled.load(std::memory_order_acquire)) {
|
|
2589
|
+
std::puts("GEADEV:ERR BENCH no-active-window");
|
|
2590
|
+
return;
|
|
2591
|
+
}
|
|
2592
|
+
const auto sample = gea::platform::comparison::end(esp_timer_get_time());
|
|
2593
|
+
constexpr auto internal = MALLOC_CAP_INTERNAL | MALLOC_CAP_8BIT;
|
|
2594
|
+
constexpr auto psram = MALLOC_CAP_SPIRAM | MALLOC_CAP_8BIT;
|
|
2595
|
+
char presented[32];
|
|
2596
|
+
const bool completed = sample.completionFence && !sample.completionFailures &&
|
|
2597
|
+
gea_display_completed_chunks && gea_display_wait_for_uploads;
|
|
2598
|
+
if (completed) {
|
|
2599
|
+
std::snprintf(presented, sizeof(presented), "%llu",
|
|
2600
|
+
static_cast<unsigned long long>(sample.presentedFrames));
|
|
2601
|
+
} else {
|
|
2602
|
+
std::snprintf(presented, sizeof(presented), "null");
|
|
2603
|
+
}
|
|
2604
|
+
std::printf(
|
|
2605
|
+
"SWBENCH "
|
|
2606
|
+
"{\"schema_version\":1,\"framework\":\"gea\",\"optimization\":\"%s\",\"variant\":\"%s\",\"run_id\":\"%"
|
|
2607
|
+
"s\",\"scenario\":\"%s\",\"phase\":\"end\","
|
|
2608
|
+
"\"timestamp_us\":%lld,\"window_us\":%lld,\"scheduler_frames\":%llu,\"rendered_frames\":%llu,"
|
|
2609
|
+
"\"presented_frames\":%s,"
|
|
2610
|
+
"\"present_chunks\":%llu,\"present_pixels\":%llu,\"work_us\":%llu,\"work_max_us\":%llu,\"work_p99_"
|
|
2611
|
+
"upper_us\":%lld,"
|
|
2612
|
+
"\"cadence_count\":%llu,\"cadence_sum_us\":%llu,\"cadence_max_us\":%llu,\"cadence_p99_upper_us\":%lld,"
|
|
2613
|
+
"\"presented_cadence_count\":%llu,\"presented_cadence_sum_us\":%llu,\"presented_cadence_max_us\":%llu,"
|
|
2614
|
+
"\"presented_cadence_p99_upper_us\":%lld,"
|
|
2615
|
+
"\"completion_fence\":%s,\"completion_wait_us_sum\":%llu,\"completion_wait_us_max\":%llu,\"completion_"
|
|
2616
|
+
"failures\":%u,"
|
|
2617
|
+
"\"rendered_duration_sum_us\":null,\"heap_min_scope\":\"boot\",\"presented_scope\":\"%s\","
|
|
2618
|
+
"\"internal\":{\"total_bytes\":%u,\"free_bytes\":%u,\"min_free_bytes\":%u,\"largest_free_bytes\":%u},"
|
|
2619
|
+
"\"psram\":{\"total_bytes\":%u,\"free_bytes\":%u,\"min_free_bytes\":%u,\"largest_free_bytes\":%u}}\n",
|
|
2620
|
+
diagnosticOptimization(), sample.completionFence ? "benchmark-fenced" : "benchmark-unfenced",
|
|
2621
|
+
sample.runId, sample.scenario, static_cast<long long>(sample.endUs),
|
|
2622
|
+
static_cast<long long>(sample.endUs - sample.startUs),
|
|
2623
|
+
static_cast<unsigned long long>(sample.schedulerFrames),
|
|
2624
|
+
static_cast<unsigned long long>(sample.renderedFrames), presented,
|
|
2625
|
+
static_cast<unsigned long long>(sample.presentChunks),
|
|
2626
|
+
static_cast<unsigned long long>(sample.presentPixels), static_cast<unsigned long long>(sample.work.sum),
|
|
2627
|
+
static_cast<unsigned long long>(sample.work.maximum),
|
|
2628
|
+
static_cast<long long>(sample.work.percentileUpper(99)),
|
|
2629
|
+
static_cast<unsigned long long>(sample.cadence.count),
|
|
2630
|
+
static_cast<unsigned long long>(sample.cadence.sum),
|
|
2631
|
+
static_cast<unsigned long long>(sample.cadence.maximum),
|
|
2632
|
+
static_cast<long long>(sample.cadence.percentileUpper(99)),
|
|
2633
|
+
static_cast<unsigned long long>(sample.presentedCadence.count),
|
|
2634
|
+
static_cast<unsigned long long>(sample.presentedCadence.sum),
|
|
2635
|
+
static_cast<unsigned long long>(sample.presentedCadence.maximum),
|
|
2636
|
+
static_cast<long long>(sample.presentedCadence.percentileUpper(99)),
|
|
2637
|
+
sample.completionFence ? "true" : "false", static_cast<unsigned long long>(sample.completionWaitSum),
|
|
2638
|
+
static_cast<unsigned long long>(sample.completionWaitMax), unsigned(sample.completionFailures),
|
|
2639
|
+
completed ? "fenced-upload-frame" : "unavailable-unfenced-or-failed",
|
|
2640
|
+
unsigned(heap_caps_get_total_size(internal)), unsigned(heap_caps_get_free_size(internal)),
|
|
2641
|
+
unsigned(heap_caps_get_minimum_free_size(internal)),
|
|
2642
|
+
unsigned(heap_caps_get_largest_free_block(internal)), unsigned(heap_caps_get_total_size(psram)),
|
|
2643
|
+
unsigned(heap_caps_get_free_size(psram)), unsigned(heap_caps_get_minimum_free_size(psram)),
|
|
2644
|
+
unsigned(heap_caps_get_largest_free_block(psram)));
|
|
2645
|
+
} else {
|
|
2646
|
+
std::puts("GEADEV:ERR BENCH expected-BEGIN-or-END");
|
|
2647
|
+
}
|
|
2648
|
+
#else
|
|
2649
|
+
std::puts("GEADEV:ERR BENCH GEA_EMBEDDED_COMPARISON_BENCHMARK-not-enabled");
|
|
2650
|
+
#endif
|
|
1812
2651
|
} else if (tokenEquals(command, "MEM")) {
|
|
1813
2652
|
const unsigned intFree = static_cast<unsigned>(heap_caps_get_free_size(MALLOC_CAP_INTERNAL | MALLOC_CAP_8BIT));
|
|
1814
2653
|
const unsigned intTotal = static_cast<unsigned>(heap_caps_get_total_size(MALLOC_CAP_INTERNAL | MALLOC_CAP_8BIT));
|
|
@@ -1817,15 +2656,16 @@ void handleCommand(char *line, CommandSource source)
|
|
|
1817
2656
|
const unsigned psramFree = static_cast<unsigned>(heap_caps_get_free_size(MALLOC_CAP_SPIRAM | MALLOC_CAP_8BIT));
|
|
1818
2657
|
const unsigned psramTotal = static_cast<unsigned>(heap_caps_get_total_size(MALLOC_CAP_SPIRAM | MALLOC_CAP_8BIT));
|
|
1819
2658
|
const unsigned psramLargest = static_cast<unsigned>(heap_caps_get_largest_free_block(MALLOC_CAP_SPIRAM | MALLOC_CAP_8BIT));
|
|
2659
|
+
const unsigned psramMinFree = static_cast<unsigned>(heap_caps_get_minimum_free_size(MALLOC_CAP_SPIRAM | MALLOC_CAP_8BIT));
|
|
1820
2660
|
const char *appId = gea::framework::apps::AppManager::currentId();
|
|
1821
2661
|
std::printf(
|
|
1822
|
-
"GEADEV:MEM app=%s internal_used=%u internal_free=%u internal_total=%u internal_largest=%u internal_min_free=%u psram_used=%u psram_free=%u psram_total=%u psram_largest=%u flush_rows=%d flush_depth=%d flush_bytes=%d\n",
|
|
2662
|
+
"GEADEV:MEM app=%s internal_used=%u internal_free=%u internal_total=%u internal_largest=%u internal_min_free=%u psram_used=%u psram_free=%u psram_total=%u psram_largest=%u flush_rows=%d flush_depth=%d flush_bytes=%d psram_min_free=%u\n",
|
|
1823
2663
|
appId ? appId : "",
|
|
1824
2664
|
intTotal - intFree, intFree, intTotal, intLargest, intMinFree,
|
|
1825
2665
|
psramTotal - psramFree, psramFree, psramTotal, psramLargest,
|
|
1826
2666
|
gea::platform::display::Display::flushChunkRows(),
|
|
1827
2667
|
gea::platform::display::Display::flushQueueDepth(),
|
|
1828
|
-
gea::platform::display::Display::flushBufferBytes());
|
|
2668
|
+
gea::platform::display::Display::flushBufferBytes(), psramMinFree);
|
|
1829
2669
|
} else if (tokenEquals(command, "HEAPTRACE")) {
|
|
1830
2670
|
#if CONFIG_HEAP_TRACING_STANDALONE
|
|
1831
2671
|
// Allocate records only on demand, outside internal DMA RAM. Emit
|
|
@@ -2030,9 +2870,35 @@ void handleCommand(char *line, CommandSource source)
|
|
|
2030
2870
|
handleListFiles(cursor);
|
|
2031
2871
|
} else if (tokenEquals(command, "RM")) {
|
|
2032
2872
|
handleRemoveFile(cursor);
|
|
2873
|
+
} else if (tokenEquals(command, "FORMAT")) {
|
|
2874
|
+
if (source == CommandSource::Stdio) handleFormat(cursor);
|
|
2875
|
+
else std::printf("GEADEV:FORMAT ERR unsupported-on-usb-direct\n");
|
|
2033
2876
|
} else if (tokenEquals(command, "PULL")) {
|
|
2034
2877
|
handlePull(cursor);
|
|
2035
2878
|
#if GEA_AUDIO_EXPERIMENT
|
|
2879
|
+
} else if (tokenEquals(command, "AUDIOCAPTURE")) {
|
|
2880
|
+
const char *value = nextToken(cursor);
|
|
2881
|
+
char *end = nullptr;
|
|
2882
|
+
const unsigned long offset = value ? std::strtoul(value, &end, 10) : 0;
|
|
2883
|
+
int16_t samples[128 * 3];
|
|
2884
|
+
size_t frames = 0, total = 0;
|
|
2885
|
+
int64_t started = 0;
|
|
2886
|
+
uint32_t drops = 0;
|
|
2887
|
+
const bool ok = value && end && *end == '\0' && offset <= 128000 &&
|
|
2888
|
+
geaAudioAecCaptureRead(offset, samples, 128, &frames, &total, &started, &drops);
|
|
2889
|
+
if (!ok) std::puts("GEADEV:AUDIOCAPTURE ERR");
|
|
2890
|
+
else {
|
|
2891
|
+
char encoded[128 * 3 * 4 + 1];
|
|
2892
|
+
constexpr char digits[] = "0123456789abcdef";
|
|
2893
|
+
const auto *bytes = reinterpret_cast<const uint8_t *>(samples);
|
|
2894
|
+
for (size_t i = 0; i < frames * 6; ++i) {
|
|
2895
|
+
encoded[i * 2] = digits[bytes[i] >> 4];
|
|
2896
|
+
encoded[i * 2 + 1] = digits[bytes[i] & 15];
|
|
2897
|
+
}
|
|
2898
|
+
encoded[frames * 12] = '\0';
|
|
2899
|
+
std::printf("GEADEV:AUDIOCAPTURE OK offset=%lu frames=%u total=%u started_us=%lld drops=%lu data=%s\n",
|
|
2900
|
+
offset, unsigned(frames), unsigned(total), (long long)started, (unsigned long)drops, encoded);
|
|
2901
|
+
}
|
|
2036
2902
|
} else if (tokenEquals(command, "AUDIO")) {
|
|
2037
2903
|
char *key = nextToken(cursor);
|
|
2038
2904
|
char *value = nextToken(cursor);
|
|
@@ -2093,9 +2959,17 @@ void handleCommand(char *line, CommandSource source)
|
|
|
2093
2959
|
handleSetTime(cursor);
|
|
2094
2960
|
} else if (tokenEquals(command, "SCREENSHOT")) {
|
|
2095
2961
|
writeScreenshot();
|
|
2096
|
-
#if CONFIG_ESP_CONSOLE_SECONDARY_USB_SERIAL_JTAG
|
|
2962
|
+
#if CONFIG_ESP_CONSOLE_USB_SERIAL_JTAG || CONFIG_ESP_CONSOLE_SECONDARY_USB_SERIAL_JTAG
|
|
2097
2963
|
} else if (tokenEquals(command, "SCREENSHOTBIN")) {
|
|
2098
|
-
|
|
2964
|
+
// With the primary USB console, stdio commands arrive over the same
|
|
2965
|
+
// USB driver as secondary-console commands. Stream binary pixels through
|
|
2966
|
+
// its reliable bulk writer: the VFS character writer can silently drop
|
|
2967
|
+
// bytes when its TX ring fills during a large screenshot.
|
|
2968
|
+
bool usbSource = source == CommandSource::UsbSerialJtag;
|
|
2969
|
+
#if CONFIG_ESP_CONSOLE_USB_SERIAL_JTAG
|
|
2970
|
+
usbSource = usbSource || source == CommandSource::Stdio;
|
|
2971
|
+
#endif
|
|
2972
|
+
if (usbSource) writeScreenshotUsbRaw();
|
|
2099
2973
|
else std::printf("GEADEV:ERR SCREENSHOTBIN usb-serial-jtag-only\n");
|
|
2100
2974
|
#endif
|
|
2101
2975
|
} else if (tokenEquals(command, "MMUPROBE")) {
|
|
@@ -2161,6 +3035,47 @@ private:
|
|
|
2161
3035
|
bool overflow_ = false;
|
|
2162
3036
|
};
|
|
2163
3037
|
|
|
3038
|
+
#if !CONFIG_ESP_CONSOLE_SECONDARY_USB_SERIAL_JTAG
|
|
3039
|
+
// The console loop turns every 50 ms while idle. When it stops turning (a
|
|
3040
|
+
// command that never returns, a console read that never comes back), the
|
|
3041
|
+
// board is unreachable and only a power cycle used to recover it -- the
|
|
3042
|
+
// stuck task holds nothing the task watchdog watches. Restart instead.
|
|
3043
|
+
std::atomic<std::int64_t> &consoleBeat()
|
|
3044
|
+
{
|
|
3045
|
+
static std::atomic<std::int64_t> beat{0};
|
|
3046
|
+
return beat;
|
|
3047
|
+
}
|
|
3048
|
+
|
|
3049
|
+
std::atomic<bool> &consoleInCommand()
|
|
3050
|
+
{
|
|
3051
|
+
static std::atomic<bool> busy{false};
|
|
3052
|
+
return busy;
|
|
3053
|
+
}
|
|
3054
|
+
|
|
3055
|
+
void startConsoleWatchdog()
|
|
3056
|
+
{
|
|
3057
|
+
static bool started = false;
|
|
3058
|
+
if (started) return;
|
|
3059
|
+
started = true;
|
|
3060
|
+
xTaskCreate(
|
|
3061
|
+
[](void *) {
|
|
3062
|
+
while (true) {
|
|
3063
|
+
vTaskDelay(pdMS_TO_TICKS(1000));
|
|
3064
|
+
const std::int64_t last = consoleBeat().load(std::memory_order_relaxed);
|
|
3065
|
+
if (last == 0) continue;
|
|
3066
|
+
// A streamed OTA or a large push legitimately holds the loop for minutes.
|
|
3067
|
+
const std::int64_t limit = consoleInCommand().load(std::memory_order_relaxed) ? 600000000LL : 20000000LL;
|
|
3068
|
+
if (esp_timer_get_time() - last > limit) {
|
|
3069
|
+
esp_rom_printf("gea_devctl: console stalled for %lld ms, restarting\n",
|
|
3070
|
+
static_cast<long long>((esp_timer_get_time() - last) / 1000));
|
|
3071
|
+
esp_restart();
|
|
3072
|
+
}
|
|
3073
|
+
}
|
|
3074
|
+
},
|
|
3075
|
+
"gea_devctl_wd", 2048, nullptr, configMAX_PRIORITIES - 1, nullptr);
|
|
3076
|
+
}
|
|
3077
|
+
#endif
|
|
3078
|
+
|
|
2164
3079
|
#if !CONFIG_ESP_CONSOLE_SECONDARY_USB_SERIAL_JTAG
|
|
2165
3080
|
class DeviceControlTask {
|
|
2166
3081
|
public:
|
|
@@ -2190,9 +3105,24 @@ public:
|
|
|
2190
3105
|
std::setvbuf(stdout, nullptr, _IONBF, 0);
|
|
2191
3106
|
ESP_LOGI(kTag, "Device control ready: send 'GEADEV PING', 'GEADEV TAP x y', 'GEADEV BACK', or 'GEADEV SCREENSHOT'");
|
|
2192
3107
|
|
|
3108
|
+
#if !CONFIG_ESP_CONSOLE_USB_SERIAL_JTAG
|
|
2193
3109
|
char readBuffer[160];
|
|
3110
|
+
#endif
|
|
2194
3111
|
CommandLineAccumulator parser(CommandSource::Stdio);
|
|
3112
|
+
startConsoleWatchdog();
|
|
2195
3113
|
while (true) {
|
|
3114
|
+
consoleBeat().store(esp_timer_get_time(), std::memory_order_relaxed);
|
|
3115
|
+
#if CONFIG_ESP_CONSOLE_USB_SERIAL_JTAG
|
|
3116
|
+
// fgets waits indefinitely on the driver-backed VFS, so normal USB
|
|
3117
|
+
// silence would stop the heartbeat. Read one byte with a deadline;
|
|
3118
|
+
// never prefetch a PUSH/OTA payload that its handler reads from stdin.
|
|
3119
|
+
char ch;
|
|
3120
|
+
const int n = usb_serial_jtag_read_bytes(&ch, 1, pdMS_TO_TICKS(50));
|
|
3121
|
+
if (n <= 0) continue;
|
|
3122
|
+
consoleInCommand().store(true, std::memory_order_relaxed);
|
|
3123
|
+
parser.feed(&ch, 1);
|
|
3124
|
+
consoleInCommand().store(false, std::memory_order_relaxed);
|
|
3125
|
+
#else
|
|
2196
3126
|
if (!std::fgets(readBuffer, sizeof(readBuffer), stdin)) {
|
|
2197
3127
|
// A console whose read returns 0 when idle (the TinyUSB CDC VFS)
|
|
2198
3128
|
// sets stdin's end-of-file flag, and that flag is sticky: every
|
|
@@ -2201,7 +3131,10 @@ public:
|
|
|
2201
3131
|
vTaskDelay(pdMS_TO_TICKS(50));
|
|
2202
3132
|
continue;
|
|
2203
3133
|
}
|
|
3134
|
+
consoleInCommand().store(true, std::memory_order_relaxed);
|
|
2204
3135
|
parser.feed(readBuffer, std::strlen(readBuffer));
|
|
3136
|
+
consoleInCommand().store(false, std::memory_order_relaxed);
|
|
3137
|
+
#endif
|
|
2205
3138
|
}
|
|
2206
3139
|
}
|
|
2207
3140
|
};
|
|
@@ -2304,6 +3237,18 @@ void startDeviceControlTask()
|
|
|
2304
3237
|
|
|
2305
3238
|
} // namespace gea::platform::esp32::services
|
|
2306
3239
|
|
|
3240
|
+
#if GEA_EMBEDDED_COMPARISON_BENCHMARK
|
|
3241
|
+
extern "C" void gea_touch_trace_consumed(int phase, bool touching, int x, int y, int pointerId, int handlerX,
|
|
3242
|
+
int handlerY)
|
|
3243
|
+
{
|
|
3244
|
+
if (!gea::platform::comparison::input::recording.load(std::memory_order_acquire)) {
|
|
3245
|
+
return;
|
|
3246
|
+
}
|
|
3247
|
+
gea::platform::comparison::input::consumed(esp_timer_get_time(), phase, touching, x, y, pointerId, handlerX,
|
|
3248
|
+
handlerY);
|
|
3249
|
+
}
|
|
3250
|
+
#endif
|
|
3251
|
+
|
|
2307
3252
|
// Weak no-op default for the per-target GEADEV command extension. Targets that
|
|
2308
3253
|
// add commands (e.g. ESP32-P4 camera capture) override this with a strong symbol;
|
|
2309
3254
|
// the linker then picks the override. Defined at global scope to match the
|