@geastack/targets 0.1.110 → 0.1.111

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.
@@ -0,0 +1,35 @@
1
+ #include "power.h"
2
+
3
+ #include "chip_bindings/expanders/elecrow_stc8h1k17.h"
4
+
5
+ // The battery (PH2.0 J3, TP4059 charger) is gauged by the STC8H1K17
6
+ // board-control MCU: it divides VBAT into its ADC and reads the charger's
7
+ // CHRG/DONE pins, and the P4 reads the result over I2C.
8
+ namespace gea::platform::power {
9
+
10
+ namespace {
11
+ namespace board_control = gea::platform::esp32::chip_bindings::expanders;
12
+ }
13
+
14
+ bool Power::init()
15
+ {
16
+ board_control::Stc8h1k17Battery battery;
17
+ return board_control::stc8h1k17Battery(battery);
18
+ }
19
+
20
+ int Power::batteryPercent()
21
+ {
22
+ board_control::Stc8h1k17Battery battery;
23
+ if (!board_control::stc8h1k17Battery(battery)) return -1;
24
+ // No cell fitted reads as (almost) no voltage: report "no battery".
25
+ if (battery.batteryMillivolts < 2500) return -1;
26
+ return battery.levelPercent > 100 ? 100 : battery.levelPercent;
27
+ }
28
+
29
+ bool Power::charging()
30
+ {
31
+ board_control::Stc8h1k17Battery battery;
32
+ return board_control::stc8h1k17Battery(battery) && battery.chargeState == 1;
33
+ }
34
+
35
+ } // namespace gea::platform::power
@@ -2,6 +2,9 @@
2
2
 
3
3
  #include "freertos/FreeRTOS.h"
4
4
  #include "freertos/semphr.h"
5
+ #include "freertos/task.h"
6
+
7
+ #include <atomic>
5
8
 
6
9
  namespace gea::framework::services {
7
10
 
@@ -22,18 +25,33 @@ public:
22
25
  return mutex_ != nullptr;
23
26
  }
24
27
 
28
+ // The frame task holds the lock for a whole frame and takes it again
29
+ // straight after releasing it. A FreeRTOS mutex does not hand itself to a
30
+ // waiter on give, so while the app renders continuously (a blinking caret is
31
+ // enough) a lower-priority waiter -- the GEADEV console reading the tree or
32
+ // the screen -- went ~30 s without it. The task that just released steps
33
+ // aside for one tick when someone is waiting; nobody waits on a normal frame.
25
34
  void lock()
26
35
  {
27
- if (mutex_) xSemaphoreTake(mutex_, portMAX_DELAY);
36
+ if (!mutex_) return;
37
+ if (waiting_.load(std::memory_order_acquire) > 0 && lastReleaser_ == xTaskGetCurrentTaskHandle())
38
+ vTaskDelay(1);
39
+ waiting_.fetch_add(1, std::memory_order_acq_rel);
40
+ xSemaphoreTake(mutex_, portMAX_DELAY);
41
+ waiting_.fetch_sub(1, std::memory_order_acq_rel);
28
42
  }
29
43
 
30
44
  void unlock()
31
45
  {
32
- if (mutex_) xSemaphoreGive(mutex_);
46
+ if (!mutex_) return;
47
+ lastReleaser_ = xTaskGetCurrentTaskHandle();
48
+ xSemaphoreGive(mutex_);
33
49
  }
34
50
 
35
51
  private:
36
52
  SemaphoreHandle_t mutex_ = nullptr;
53
+ std::atomic<int> waiting_{0};
54
+ TaskHandle_t lastReleaser_ = nullptr;
37
55
  };
38
56
 
39
57
  } // namespace
@@ -253,12 +253,26 @@ private:
253
253
  void flushLine()
254
254
  {
255
255
  if (lineLength_ <= 0) return;
256
+ // One line at a time under the stdout lock: other output can fall between
257
+ // data lines (the host skips it) but never inside one. Holding the lock
258
+ // for the whole ~10 s stream blocked every task that logged meanwhile,
259
+ // and the task watchdog's register dump then landed inside the data.
260
+ flockfile(stdout);
256
261
  std::printf("GEADEV:DATA ");
257
262
  std::fwrite(line_, 1, static_cast<std::size_t>(lineLength_), stdout);
258
263
  std::printf("\n");
264
+ funlockfile(stdout);
259
265
  lineLength_ = 0;
266
+ // The console write can busy-wait on the UART FIFO; over a ~10 s frame
267
+ // that starved this core's idle task and tripped the task watchdog,
268
+ // whose register dump then landed in the data. Let it run now and then.
269
+ if (++linesSinceYield_ >= 32) {
270
+ linesSinceYield_ = 0;
271
+ vTaskDelay(1);
272
+ }
260
273
  }
261
274
 
275
+ int linesSinceYield_ = 0;
262
276
  static constexpr int kLineLength = 76;
263
277
  static constexpr char kAlphabet[] =
264
278
  "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
@@ -375,8 +389,28 @@ bool captureSnapshotPacked(std::uint8_t *snapshot, int byteCapacity, int *width,
375
389
  }
376
390
  #endif // GEA_PIXEL_STORAGE_PACKED
377
391
 
392
+ // Silences ESP log output for its lifetime: a log line printed into the middle
393
+ // of a streamed reply (a screenshot's base64, the debugger protocol) corrupts it.
394
+ class ScopedLogSilence {
395
+ public:
396
+ ScopedLogSilence()
397
+ : previous_(esp_log_level_get(nullptr))
398
+ {
399
+ esp_log_level_set("*", ESP_LOG_NONE);
400
+ }
401
+
402
+ ~ScopedLogSilence()
403
+ {
404
+ esp_log_level_set("*", previous_);
405
+ }
406
+
407
+ private:
408
+ esp_log_level_t previous_;
409
+ };
410
+
378
411
  void writeScreenshot()
379
412
  {
413
+ ScopedLogSilence silence;
380
414
  int width = 0;
381
415
  int height = 0;
382
416
  char appIdBuffer[96];
@@ -411,7 +445,6 @@ void writeScreenshot()
411
445
  return;
412
446
  }
413
447
 
414
- flockfile(stdout);
415
448
  std::printf("GEADEV:SCREENSHOT BEGIN width=%d height=%d encoding=rgb565-rle-v1 app=%s\n",
416
449
  width,
417
450
  height,
@@ -438,7 +471,6 @@ void writeScreenshot()
438
471
  writer.finish();
439
472
  std::printf("GEADEV:SCREENSHOT END\n");
440
473
  std::fflush(stdout);
441
- funlockfile(stdout);
442
474
 
443
475
  if (heapCapsAllocated) heap_caps_free(snapshot);
444
476
  else std::free(snapshot);
@@ -463,7 +495,6 @@ void writeScreenshot()
463
495
  const char *liveAppId = gea::framework::apps::AppManager::currentId();
464
496
  std::snprintf(appIdBuffer, sizeof(appIdBuffer), "%s", liveAppId ? liveAppId : "");
465
497
  gea::framework::services::AppState::unlock();
466
- flockfile(stdout);
467
498
  std::printf("GEADEV:SCREENSHOT BEGIN width=%d height=%d encoding=rgb565-rle-v1 app=%s\n", width, height, appIdBuffer);
468
499
  Base64Writer writer;
469
500
  using gea::framework::graphics::pixel::toRgb565;
@@ -483,7 +514,6 @@ void writeScreenshot()
483
514
  writer.finish();
484
515
  std::printf("GEADEV:SCREENSHOT END\n");
485
516
  std::fflush(stdout);
486
- funlockfile(stdout);
487
517
  return;
488
518
  }
489
519
 
@@ -497,7 +527,6 @@ void writeScreenshot()
497
527
  return;
498
528
  }
499
529
 
500
- flockfile(stdout);
501
530
  std::printf("GEADEV:SCREENSHOT BEGIN width=%d height=%d encoding=rgb565-rle-v1 app=%s\n",
502
531
  width,
503
532
  height,
@@ -522,7 +551,6 @@ void writeScreenshot()
522
551
  writer.finish();
523
552
  std::printf("GEADEV:SCREENSHOT END\n");
524
553
  std::fflush(stdout);
525
- funlockfile(stdout);
526
554
 
527
555
  if (heapCapsAllocated) heap_caps_free(snapshot);
528
556
  else std::free(snapshot);
@@ -530,23 +558,6 @@ void writeScreenshot()
530
558
  }
531
559
 
532
560
  #if CONFIG_ESP_CONSOLE_USB_SERIAL_JTAG || CONFIG_ESP_CONSOLE_SECONDARY_USB_SERIAL_JTAG
533
- class ScopedLogSilence {
534
- public:
535
- ScopedLogSilence()
536
- : previous_(esp_log_level_get(nullptr))
537
- {
538
- esp_log_level_set("*", ESP_LOG_NONE);
539
- }
540
-
541
- ~ScopedLogSilence()
542
- {
543
- esp_log_level_set("*", previous_);
544
- }
545
-
546
- private:
547
- esp_log_level_t previous_;
548
- };
549
-
550
561
  bool usbWriteAll(const void *data, std::size_t size)
551
562
  {
552
563
  const auto *bytes = static_cast<const std::uint8_t *>(data);
@@ -847,6 +858,16 @@ void handleI2cScan()
847
858
  std::printf("GEADEV:I2CSCAN END count=%d\n", count);
848
859
  }
849
860
 
861
+ // A string as one whitespace-free token: printable ASCII as is, everything
862
+ // else (space, backslash, UTF-8 bytes) as \xHH.
863
+ void printEscaped(const char *text)
864
+ {
865
+ for (const unsigned char *c = reinterpret_cast<const unsigned char *>(text); *c; ++c) {
866
+ if (*c > 0x20 && *c < 0x7f && *c != '\\') std::putchar(*c);
867
+ else std::printf("\\x%02X", *c);
868
+ }
869
+ }
870
+
850
871
  void handleNode(char *&cursor)
851
872
  {
852
873
  const char *className = nextToken(cursor);
@@ -945,6 +966,21 @@ void handleNode(char *&cursor)
945
966
  textCommand ? textCommand->bh : 0,
946
967
  textCommand ? textCommand->text.fontId : -1,
947
968
  textCommand ? static_cast<double>(textCommand->text.scale) : 0.0);
969
+ // An input's value and the text it draws (bullets on a password), so a
970
+ // host can drive the on-screen keyboard and check what each key did.
971
+ const char *value = tree.getAttribute(nodeId, "value");
972
+ if (value || (textCommand && textCommand->text.text)) {
973
+ std::printf("GEADEV:NODETEXT id=%d focused=%d caret=%d value=", nodeId,
974
+ tree.activeInputId() == nodeId ? 1 : 0, tree.activeInputId() == nodeId ? tree.activeInputCaret() : -1);
975
+ printEscaped(value ? value : "");
976
+ std::printf(" text=");
977
+ printEscaped(textCommand && textCommand->text.text ? textCommand->text.text : "");
978
+ std::printf("\n");
979
+ int revealFrom = 0, revealTo = 0;
980
+ if (tree.inputPasswordReveal(nodeId, &revealFrom, &revealTo))
981
+ std::printf("GEADEV:NODEREVEAL id=%d from=%d to=%d frame_ms=%d now_ms=%d\n", nodeId, revealFrom, revealTo,
982
+ tree.lastFrameMs(), static_cast<int>(esp_timer_get_time() / 1000));
983
+ }
948
984
  printed++;
949
985
  }
950
986
  gea::framework::services::AppState::unlock();
@@ -0,0 +1,18 @@
1
+ cmake_minimum_required(VERSION 3.16)
2
+
3
+ # Resolve exactly what main/idf_component.yml pins. The component manager's
4
+ # "is there a newer version" pass reads registry metadata for releases this
5
+ # board never uses, and newer esp_hosted releases gate their USB-host transports
6
+ # on `$CONFIG{ESP_HOSTED_HOST_USB_*} == 1` rules that no Kconfig in the build
7
+ # defines -- which stops every fresh dependency solve at configure time.
8
+ set(ENV{IDF_COMPONENT_CHECK_NEW_VERSION} 0)
9
+
10
+ set(EXTRA_COMPONENT_DIRS "${CMAKE_CURRENT_LIST_DIR}/../esp32/components")
11
+ include("${CMAKE_CURRENT_LIST_DIR}/../esp32/app_project.cmake")
12
+ set(GEA_EMBEDDED_APP "tic-tac-toe" CACHE STRING "Example app to build (must match a package.json gea.id)")
13
+ set(PROJECT_VER "${GEA_EMBEDDED_APP}" CACHE STRING "Firmware app id" FORCE)
14
+
15
+ include($ENV{IDF_PATH}/tools/cmake/project.cmake)
16
+ idf_build_set_property(MINIMAL_BUILD ON)
17
+ gea_solve_dependencies_in_build_dir()
18
+ project(gea_embedded)