@geastack/targets 0.1.108 → 0.1.109

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,169 @@
1
+ // Elecrow CrowPanel Advance board control: the slow control lines (backlight,
2
+ // touch reset, amplifier mute and shutdown) sit behind one of two parts,
3
+ // depending on the board revision, and this binding probes which at init.
4
+ //
5
+ // V1.0-V1.2: a PCA9557 I/O expander at 0x18. IO1 backlight enable, IO2 touch
6
+ // reset, IO3 amplifier mute, IO4 amplifier shutdown (high = off).
7
+ // V1.3+: an STC8H1K28 board-control MCU at 0x30 that takes single-byte
8
+ // writes with no register: 0..245 backlight (0 brightest, 245
9
+ // off), 248 enable the speaker amplifier, 250 recover touch.
10
+ // Elecrow documents no other command, so none is sent.
11
+ //
12
+ // The board definition names lines by the PCA9557's pin numbers; on an STC
13
+ // board each line maps onto the command that does the same job. Lines with no
14
+ // STC equivalent (mute, amplifier off) succeed without sending anything.
15
+
16
+ #include "chip_bindings/expanders/io_expander.h"
17
+ #include "expanders/pca9557/pca9557.h"
18
+ #include "board.h"
19
+ #include "i2c.h"
20
+
21
+ #include <algorithm>
22
+
23
+ #include "driver/i2c_master.h"
24
+ #include "esp_log.h"
25
+ #include "freertos/FreeRTOS.h"
26
+ #include "freertos/semphr.h"
27
+ #include "freertos/task.h"
28
+
29
+ namespace gea::platform::esp32::chip_bindings::expanders {
30
+ namespace {
31
+
32
+ constexpr char kTag[] = "board_ctrl";
33
+ constexpr std::uint8_t kStcAddress = 0x30;
34
+ constexpr std::uint8_t kPcaAddress = 0x18;
35
+ constexpr int kLineBacklight = 1;
36
+ constexpr int kLineTouchReset = 2;
37
+ constexpr int kLineShutdown = 4;
38
+ constexpr std::uint8_t kStcBacklightOff = 245;
39
+ constexpr std::uint8_t kStcSpeakerOn = 248;
40
+ constexpr std::uint8_t kStcTouchRecover = 250;
41
+ constexpr int kTimeoutMs = 50;
42
+
43
+ enum class Controller { None, Stc, Pca9557 };
44
+
45
+ class ElecrowBoardControl final : public IoExpander, private gea::chips::pca9557::Bus {
46
+ public:
47
+ bool init() override {
48
+ Guard guard(lock_);
49
+ if (controller_ != Controller::None) return true;
50
+ auto bus = gea::platform::i2c::Bus::primary();
51
+ if (!bus.available()) return false;
52
+ auto handle = static_cast<i2c_master_bus_handle_t>(bus.nativeHandle());
53
+ // Give the board-control MCU time to come up after power-on (Elecrow
54
+ // waits 50 ms after starting the bus).
55
+ vTaskDelay(pdMS_TO_TICKS(50));
56
+ if (i2c_master_probe(handle, kStcAddress, kTimeoutMs) == ESP_OK && attach(handle, kStcAddress)) {
57
+ controller_ = Controller::Stc;
58
+ ESP_LOGI(kTag, "STC8H board-control MCU at 0x%02x (board V1.3+)", kStcAddress);
59
+ return true;
60
+ }
61
+ if (i2c_master_probe(handle, kPcaAddress, kTimeoutMs) == ESP_OK && attach(handle, kPcaAddress) &&
62
+ pca_.configure(*this, static_cast<std::uint8_t>(gea::platform::board::expander.initialOutputs),
63
+ static_cast<std::uint8_t>(gea::platform::board::expander.initialDirections))) {
64
+ controller_ = Controller::Pca9557;
65
+ ESP_LOGI(kTag, "PCA9557 expander at 0x%02x (board V1.0-V1.2)", kPcaAddress);
66
+ return true;
67
+ }
68
+ ESP_LOGE(kTag, "neither the STC board MCU (0x30) nor the PCA9557 (0x18) answered");
69
+ return false;
70
+ }
71
+
72
+ bool writePin(int pin, bool high) override {
73
+ if (!init()) return false;
74
+ Guard guard(lock_);
75
+ if (controller_ == Controller::Pca9557) return pca_.setPin(*this, pin, high);
76
+ switch (pin) {
77
+ case kLineBacklight: return send(high ? levelCommand(backlightPercent_) : kStcBacklightOff);
78
+ case kLineTouchReset: {
79
+ if (high) return true;
80
+ // Elecrow's recovery holds INT (GPIO1) low for 120 ms after the
81
+ // command; gt911.cpp holds it across this call and ~110 ms more.
82
+ const bool sent = send(kStcTouchRecover);
83
+ vTaskDelay(pdMS_TO_TICKS(20));
84
+ return sent;
85
+ }
86
+ case kLineShutdown: return high ? true : send(kStcSpeakerOn);
87
+ default: return true;
88
+ }
89
+ }
90
+
91
+ bool readPin(int pin, bool &high) override {
92
+ if (!init()) return false;
93
+ Guard guard(lock_);
94
+ if (controller_ == Controller::Pca9557) return pca_.readPin(*this, pin, high);
95
+ high = false;
96
+ return false;
97
+ }
98
+
99
+ bool setInput(int pin, bool input) override {
100
+ if (!init()) return false;
101
+ Guard guard(lock_);
102
+ if (controller_ == Controller::Pca9557) return pca_.setInput(*this, pin, input);
103
+ return false;
104
+ }
105
+
106
+ bool setLevel(int pin, int percent) override {
107
+ if (pin != kLineBacklight || !init()) return false;
108
+ Guard guard(lock_);
109
+ if (controller_ != Controller::Stc) return false;
110
+ backlightPercent_ = std::clamp(percent, 0, 100);
111
+ return send(backlightPercent_ > 0 ? levelCommand(backlightPercent_) : kStcBacklightOff);
112
+ }
113
+
114
+ const char *name() const {
115
+ return controller_ == Controller::Stc ? "elecrow-stc8h" : controller_ == Controller::Pca9557 ? "pca9557" : "none";
116
+ }
117
+
118
+ private:
119
+ struct Guard {
120
+ explicit Guard(SemaphoreHandle_t mutex) : mutex_(mutex) { xSemaphoreTakeRecursive(mutex_, portMAX_DELAY); }
121
+ ~Guard() { xSemaphoreGiveRecursive(mutex_); }
122
+ SemaphoreHandle_t mutex_;
123
+ };
124
+
125
+ // 100% -> 0 (brightest), 1% -> 244 (dimmest that is still on).
126
+ static std::uint8_t levelCommand(int percent) {
127
+ percent = std::clamp(percent, 1, 100);
128
+ return static_cast<std::uint8_t>(((100 - percent) * (kStcBacklightOff - 1)) / 99);
129
+ }
130
+
131
+ bool attach(i2c_master_bus_handle_t handle, std::uint8_t address) {
132
+ i2c_device_config_t config{};
133
+ config.dev_addr_length = I2C_ADDR_BIT_LEN_7;
134
+ config.device_address = address;
135
+ config.scl_speed_hz = 400000;
136
+ return i2c_master_bus_add_device(handle, &config, &device_) == ESP_OK;
137
+ }
138
+
139
+ bool send(std::uint8_t command) {
140
+ return i2c_master_transmit(device_, &command, 1, kTimeoutMs) == ESP_OK;
141
+ }
142
+
143
+ bool write(std::uint8_t reg, std::uint8_t value) override {
144
+ const std::uint8_t bytes[] = {reg, value};
145
+ return i2c_master_transmit(device_, bytes, 2, kTimeoutMs) == ESP_OK;
146
+ }
147
+
148
+ bool read(std::uint8_t reg, std::uint8_t &value) override {
149
+ return i2c_master_transmit_receive(device_, &reg, 1, &value, 1, kTimeoutMs) == ESP_OK;
150
+ }
151
+
152
+ StaticSemaphore_t mutexStorage_{};
153
+ SemaphoreHandle_t lock_ = xSemaphoreCreateRecursiveMutexStatic(&mutexStorage_);
154
+ i2c_master_dev_handle_t device_ = nullptr;
155
+ gea::chips::pca9557::Driver pca_;
156
+ Controller controller_ = Controller::None;
157
+ int backlightPercent_ = 100;
158
+ };
159
+
160
+ ElecrowBoardControl &instance() {
161
+ static ElecrowBoardControl driver;
162
+ return driver;
163
+ }
164
+
165
+ } // namespace
166
+
167
+ IoExpander &ioExpander() { return instance(); }
168
+ const char *ioExpanderDriverName() { return instance().name(); }
169
+ } // namespace gea::platform::esp32::chip_bindings::expanders
@@ -23,6 +23,10 @@ namespace gea::platform::esp32::chip_bindings::expanders
23
23
  virtual bool readPin(int pin, bool &high) = 0;
24
24
  // Not all expanders support per-pin direction.
25
25
  virtual bool setInput(int pin, bool input) { return false; }
26
+ // A line that carries a level rather than on/off (a backlight driven by a
27
+ // board-control MCU): 0-100 percent. Expanders whose lines are plain
28
+ // outputs decline, and the caller falls back to writePin.
29
+ virtual bool setLevel(int pin, int percent) { return false; }
26
30
  };
27
31
 
28
32
  IoExpander &ioExpander();
@@ -0,0 +1,129 @@
1
+ // BM8563 real-time clock on the board's primary I2C bus.
2
+ //
3
+ // The RTC keeps wall-clock time across power cycles (it has its own coin cell),
4
+ // so it is the source of the system clock at boot: restoreSystemTime() reads it
5
+ // and calls settimeofday() unless the chip reports it lost power. Every later
6
+ // wall-clock change made through gea::platform::clock::setEpochMs (the
7
+ // companion's SETTIME, an app setting the time) is written back to the chip,
8
+ // which overrides the host's settimeofday-only default.
9
+
10
+ #include "rtc/bm8563/bm8563.h"
11
+ #include "host/clock.h"
12
+ #include "i2c.h"
13
+
14
+ #include <cmath>
15
+ #include <ctime>
16
+ #include <sys/time.h>
17
+
18
+ #include "driver/i2c_master.h"
19
+ #include "esp_log.h"
20
+
21
+ namespace gea::platform::rtc {
22
+ void restoreSystemTime();
23
+ }
24
+
25
+ namespace {
26
+
27
+ constexpr char kTag[] = "bm8563";
28
+ constexpr int kI2cTimeoutMs = 50;
29
+
30
+ class EspI2cRegisterBus final : public gea::chips::bm8563::RegisterBus {
31
+ public:
32
+ bool attach() {
33
+ if (device_) return true;
34
+ auto bus = gea::platform::i2c::Bus::primary();
35
+ if (!bus.available()) return false;
36
+ i2c_device_config_t config{};
37
+ config.dev_addr_length = I2C_ADDR_BIT_LEN_7;
38
+ config.device_address = gea::chips::bm8563::kI2cAddress;
39
+ config.scl_speed_hz = gea::chips::bm8563::kI2cFrequencyHz;
40
+ return i2c_master_bus_add_device(static_cast<i2c_master_bus_handle_t>(bus.nativeHandle()), &config, &device_) ==
41
+ ESP_OK;
42
+ }
43
+
44
+ bool writeRegisters(std::uint8_t reg, const std::uint8_t *data, std::size_t length) override {
45
+ std::uint8_t buffer[16];
46
+ if (length + 1 > sizeof(buffer)) return false;
47
+ buffer[0] = reg;
48
+ for (std::size_t i = 0; i < length; ++i) buffer[i + 1] = data[i];
49
+ return i2c_master_transmit(device_, buffer, length + 1, kI2cTimeoutMs) == ESP_OK;
50
+ }
51
+
52
+ bool readRegisters(std::uint8_t reg, std::uint8_t *data, std::size_t length) override {
53
+ return i2c_master_transmit_receive(device_, &reg, 1, data, length, kI2cTimeoutMs) == ESP_OK;
54
+ }
55
+
56
+ private:
57
+ i2c_master_dev_handle_t device_ = nullptr;
58
+ };
59
+
60
+ EspI2cRegisterBus g_bus;
61
+ gea::chips::bm8563::RealTimeClock g_clock(g_bus);
62
+ bool g_ready = false;
63
+
64
+ bool ready() {
65
+ if (g_ready) return true;
66
+ if (!g_bus.attach()) {
67
+ ESP_LOGW(kTag, "I2C bus unavailable; no RTC");
68
+ return false;
69
+ }
70
+ if (!g_clock.begin()) {
71
+ ESP_LOGW(kTag, "RTC did not answer at 0x%02x", gea::chips::bm8563::kI2cAddress);
72
+ return false;
73
+ }
74
+ g_ready = true;
75
+ return true;
76
+ }
77
+
78
+ // The RTC holds UTC, which is what the system clock (time_t) counts.
79
+ bool writeUtc(time_t seconds) {
80
+ if (!ready()) return false;
81
+ std::tm utc{};
82
+ gmtime_r(&seconds, &utc);
83
+ gea::chips::bm8563::DateTime time;
84
+ time.year = utc.tm_year + 1900;
85
+ time.month = utc.tm_mon + 1;
86
+ time.day = utc.tm_mday;
87
+ time.weekday = utc.tm_wday;
88
+ time.hour = utc.tm_hour;
89
+ time.minute = utc.tm_min;
90
+ time.second = utc.tm_sec;
91
+ return g_clock.setDateTime(time);
92
+ }
93
+
94
+ } // namespace
95
+
96
+ void gea::platform::rtc::restoreSystemTime() {
97
+ if (!ready()) return;
98
+ gea::chips::bm8563::DateTime time;
99
+ bool valid = false;
100
+ if (!g_clock.readDateTime(time, valid)) {
101
+ ESP_LOGW(kTag, "RTC read failed");
102
+ return;
103
+ }
104
+ if (!valid) {
105
+ ESP_LOGI(kTag, "RTC lost power; system clock left unset until the time is set");
106
+ return;
107
+ }
108
+ std::tm utc{};
109
+ utc.tm_year = time.year - 1900;
110
+ utc.tm_mon = time.month - 1;
111
+ utc.tm_mday = time.day;
112
+ utc.tm_hour = time.hour;
113
+ utc.tm_min = time.minute;
114
+ utc.tm_sec = time.second;
115
+ const time_t seconds = timegm(&utc);
116
+ timeval now{seconds, 0};
117
+ settimeofday(&now, nullptr);
118
+ ESP_LOGI(kTag, "system clock restored from RTC: %04d-%02d-%02d %02d:%02d:%02d UTC", time.year, time.month, time.day,
119
+ time.hour, time.minute, time.second);
120
+ }
121
+
122
+ bool gea::platform::clock::setEpochMs(double timestamp) {
123
+ if (!std::isfinite(timestamp) || timestamp < 0) return false;
124
+ const auto seconds = static_cast<time_t>(timestamp / 1000);
125
+ timeval now{seconds, static_cast<suseconds_t>((timestamp - seconds * 1000.0) * 1000)};
126
+ if (settimeofday(&now, nullptr) != 0) return false;
127
+ if (!writeUtc(seconds)) ESP_LOGW(kTag, "system clock set, but the RTC write failed");
128
+ return true;
129
+ }
@@ -18,6 +18,7 @@
18
18
  #include "pixel.h"
19
19
  #include "touch.h" // Touchscreen::injectEvent for GEADEV DRAG/SWIPE
20
20
  #include "wifi.h" // network::wifi() for GEADEV PING ip=/mac=
21
+ #include "host/clock.h"
21
22
  #include "host/video.h"
22
23
  #include "ui/node_features.h"
23
24
 
@@ -149,6 +150,9 @@ extern "C" bool geaDisplaySnapshotPrefersPresented() __attribute__((weak));
149
150
  // Defined by engines that rasterize straight into the panel's DMA buffers (gea-threejs):
150
151
  // captures the next presented frame, the only place the real pixels exist.
151
152
  extern "C" bool geaDisplayCapturePresentedFrame(std::uint16_t *dst, int pixelCapacity, int *width, int *height) __attribute__((weak));
153
+ // The scanout buffer the panel is showing, in native pixels, for a screenshot
154
+ // that cannot get a full-screen copy (a board whose PSRAM is spoken for).
155
+ extern "C" const std::uint16_t *gea_display_presented_framebuffer(int *width, int *height) __attribute__((weak));
152
156
 
153
157
  // Mirrors the engine's default (core/packages/engine/ui/tree_render.cpp): a target
154
158
  // that does not fuse the replay into the flush keeps a persistent framebuffer.
@@ -446,9 +450,40 @@ void writeScreenshot()
446
450
  bool heapCapsAllocated = snapshot != nullptr;
447
451
  if (!snapshot) snapshot = static_cast<std::uint16_t *>(std::malloc(pixelCount * sizeof(std::uint16_t)));
448
452
  if (!snapshot) {
449
- std::printf("GEADEV:ERR SCREENSHOT no-memory bytes=%u\n",
450
- static_cast<unsigned>(pixelCount * sizeof(std::uint16_t)));
453
+ // No room for a copy: encode straight from the buffer on the panel. A
454
+ // frame published mid-capture can tear the picture, nothing worse.
455
+ const std::uint16_t *live = gea_display_presented_framebuffer ? gea_display_presented_framebuffer(&width, &height) : nullptr;
456
+ if (!live || static_cast<std::size_t>(width) * static_cast<std::size_t>(height) != pixelCount) {
457
+ std::printf("GEADEV:ERR SCREENSHOT no-memory bytes=%u\n",
458
+ static_cast<unsigned>(pixelCount * sizeof(std::uint16_t)));
459
+ std::fflush(stdout);
460
+ return;
461
+ }
462
+ gea::framework::services::AppState::lock();
463
+ const char *liveAppId = gea::framework::apps::AppManager::currentId();
464
+ std::snprintf(appIdBuffer, sizeof(appIdBuffer), "%s", liveAppId ? liveAppId : "");
465
+ gea::framework::services::AppState::unlock();
466
+ flockfile(stdout);
467
+ std::printf("GEADEV:SCREENSHOT BEGIN width=%d height=%d encoding=rgb565-rle-v1 app=%s\n", width, height, appIdBuffer);
468
+ Base64Writer writer;
469
+ using gea::framework::graphics::pixel::toRgb565;
470
+ std::uint16_t runValue = toRgb565(live[0]);
471
+ std::uint16_t runCount = 1;
472
+ for (std::size_t i = 1; i < pixelCount; i++) {
473
+ const std::uint16_t value = toRgb565(live[i]);
474
+ if (value == runValue && runCount < 65535) {
475
+ runCount++;
476
+ continue;
477
+ }
478
+ writeRun(writer, runCount, runValue);
479
+ runValue = value;
480
+ runCount = 1;
481
+ }
482
+ writeRun(writer, runCount, runValue);
483
+ writer.finish();
484
+ std::printf("GEADEV:SCREENSHOT END\n");
451
485
  std::fflush(stdout);
486
+ funlockfile(stdout);
452
487
  return;
453
488
  }
454
489
 
@@ -687,10 +722,9 @@ void handleSetTime(char *&cursor)
687
722
  return;
688
723
  }
689
724
  const long long epoch = std::strtoll(tok, nullptr, 10);
690
- struct timeval tv;
691
- tv.tv_sec = static_cast<time_t>(epoch);
692
- tv.tv_usec = 0;
693
- if (settimeofday(&tv, nullptr) == 0) {
725
+ // Through the clock surface, not settimeofday directly, so a board with a
726
+ // battery-backed RTC keeps the time across power cycles too.
727
+ if (gea::platform::clock::setEpochMs(static_cast<double>(epoch) * 1000.0)) {
694
728
  struct timeval back;
695
729
  gettimeofday(&back, nullptr);
696
730
  std::printf("GEADEV:OK SETTIME epoch=%lld readback=%lld\n", epoch, static_cast<long long>(back.tv_sec));
@@ -984,6 +1018,26 @@ void handleTap(char *&cursor)
984
1018
  std::printf("GEADEV:OK TAP x=%d y=%d hold_ms=%d\n", x, y, holdMs);
985
1019
  }
986
1020
 
1021
+ // GEADEV PANEL: the RGB panel's refill-miss counters since the last read
1022
+ // (the weak default answers on displays without them).
1023
+ extern "C" __attribute__((weak)) void gea_display_panel_stats(char *out, int size) { std::snprintf(out, static_cast<std::size_t>(size), "unsupported"); }
1024
+
1025
+ // GEADEV PRESS x y / GEADEV RELEASE x y: one half of a touch, so a host can
1026
+ // inspect the UI while a finger is held down (a pressed highlight, say).
1027
+ void handleTouchEdge(char *&cursor, bool down)
1028
+ {
1029
+ int x = 0;
1030
+ int y = 0;
1031
+ if (!parseInt(nextToken(cursor), &x) || !parseInt(nextToken(cursor), &y)) {
1032
+ std::printf("GEADEV:ERR %s usage=GEADEV_%s_x_y\n", down ? "PRESS" : "RELEASE", down ? "PRESS" : "RELEASE");
1033
+ return;
1034
+ }
1035
+ using gea::platform::touch::Touchscreen;
1036
+ using gea::platform::touch::Phase;
1037
+ Touchscreen::injectEvent(down ? Phase::Down : Phase::Up, down, x, y);
1038
+ std::printf("GEADEV:OK %s x=%d y=%d\n", down ? "PRESS" : "RELEASE", x, y);
1039
+ }
1040
+
987
1041
  void handleDrag(char *&cursor)
988
1042
  {
989
1043
  int x1 = 0;
@@ -2351,6 +2405,8 @@ void handleDiagnosticUpload(char *&cursor)
2351
2405
  // override. Receives the command token plus the remaining argument cursor.
2352
2406
  extern "C" bool geaHandleExtraDevCommand(const char *command, char *args);
2353
2407
 
2408
+ } // namespace
2409
+ namespace {
2354
2410
  void handleCommand(char *line, CommandSource source)
2355
2411
  {
2356
2412
  char *cursor = line;
@@ -2857,6 +2913,14 @@ void handleCommand(char *line, CommandSource source)
2857
2913
  handleTap(cursor);
2858
2914
  } else if (tokenEquals(command, "DRAG")) {
2859
2915
  handleDrag(cursor);
2916
+ } else if (tokenEquals(command, "PRESS")) {
2917
+ handleTouchEdge(cursor, true);
2918
+ } else if (tokenEquals(command, "RELEASE")) {
2919
+ handleTouchEdge(cursor, false);
2920
+ } else if (tokenEquals(command, "PANEL")) {
2921
+ static char stats[768];
2922
+ gea_display_panel_stats(stats, sizeof(stats));
2923
+ std::printf("GEADEV:PANEL %s\n", stats);
2860
2924
  } else if (tokenEquals(command, "ROTARY")) {
2861
2925
  handleRotary(cursor);
2862
2926
  } else if (tokenEquals(command, "KEY")) {
@@ -20,6 +20,11 @@
20
20
 
21
21
  namespace {
22
22
 
23
+ // Set between gea_memory_begin_internal/end on the task that asked: its
24
+ // allocations try internal RAM first. Random-access tables read every pixel
25
+ // cost several times more from PSRAM, whose bus the panel's scanout shares.
26
+ thread_local bool t_preferInternal = false;
27
+
23
28
  #if defined(GEA_HEAP_TRACE)
24
29
  // Diagnosis only: live bytes of C++ heap traffic by allocation size (log2
25
30
  // buckets), printed by the runtime's cycle trace (gea_heap_trace_print), so
@@ -105,7 +110,8 @@ public:
105
110
  {
106
111
  if (size == 0) size = 1;
107
112
 
108
- void *ptr = allocateWithCaps(size, alignment, MALLOC_CAP_SPIRAM | MALLOC_CAP_8BIT);
113
+ void *ptr = t_preferInternal ? allocateWithCaps(size, alignment, MALLOC_CAP_INTERNAL | MALLOC_CAP_8BIT) : nullptr;
114
+ if (!ptr) ptr = allocateWithCaps(size, alignment, MALLOC_CAP_SPIRAM | MALLOC_CAP_8BIT);
109
115
  if (!ptr) ptr = allocateWithCaps(size, alignment, MALLOC_CAP_INTERNAL | MALLOC_CAP_8BIT);
110
116
  if (!ptr) ptr = allocateWithCaps(size, alignment, MALLOC_CAP_8BIT);
111
117
  traceHeap(ptr, true);
@@ -176,6 +182,24 @@ extern "C" void gea_heap_trace_print()
176
182
  }
177
183
  #endif
178
184
 
185
+ // The display's internal staging (the RGB panel's strip buffer) is the one
186
+ // large internal block that can move: it yields before the allocations and
187
+ // takes the tallest strip that still fits after them.
188
+ extern "C" void gea_display_release_internal(std::size_t bytes) __attribute__((weak));
189
+ extern "C" void gea_display_restore_internal() __attribute__((weak));
190
+
191
+ extern "C" void gea_memory_begin_internal(std::size_t bytes)
192
+ {
193
+ if (bytes && gea_display_release_internal) gea_display_release_internal(bytes);
194
+ t_preferInternal = true;
195
+ }
196
+
197
+ extern "C" void gea_memory_end_internal()
198
+ {
199
+ t_preferInternal = false;
200
+ if (gea_display_restore_internal) gea_display_restore_internal();
201
+ }
202
+
179
203
  void *gea::framework::memory::Allocator::allocatePreferSpiram(std::size_t size, std::size_t alignment) {
180
204
  #if defined(GEA_HEAP_TRACE)
181
205
  t_site = reinterpret_cast<std::uintptr_t>(__builtin_return_address(0));
@@ -0,0 +1,182 @@
1
+ {
2
+ "id": "esp32-s3-elecrow-crowpanel-advance-7.0",
3
+ "extends": "esp32-s3",
4
+ "adapter": "esp32-idf",
5
+ "mcu": "esp32s3",
6
+ "_comment": "Elecrow CrowPanel Advance 7.0-HMI (SKU DIS02170A): an ESP32-S3-WROOM-1-N16R8 (16MB quad flash, 8MB octal PSRAM) behind a 7-inch 800x480 IPS parallel RGB panel with a GT911 capacitive touch controller. One firmware serves every board revision: the slow control lines sit behind a PCA9557 on V1.0-V1.2 and an STC8H1K28 board-control MCU on V1.3+, and the binding probes which at boot. Sources: Elecrow's V1.0-V1.5 schematics and V1.5 driver guide (Elecrow-RD/CrowPanel-Advance-7-HMI-ESP32-S3-AI-Powered-IPS-Touch-Screen-800x480) and the factory firmware.",
7
+ "flashSize": "16MB",
8
+ "_flashMode": "The WROOM-1 module routes all four flash data lines, and QIO measured about 2.5 fps faster than DIO on the svg-charts demo.",
9
+ "flashMode": "qio",
10
+ "_console": "The USB-C port goes through a CH340K USB-UART bridge to UART0 (TXD0/RXD0), with the usual DTR/RTS auto-download circuit. The native USB-Serial/JTAG pins are not brought out.",
11
+ "console": {
12
+ "transport": "uart",
13
+ "uart": 0,
14
+ "baud": 115200
15
+ },
16
+ "_psram": "N16R8 is 8MB octal PSRAM; the RGB framebuffer (800x480x2 = 768KB) lives there. 80MHz by default. An app can raise it to 120MHz (ESP-IDF's experimental octal mode) with gea.targets.esp32.psram.speed, plus flashFreq 40 because the two share the MSPI clock: every framebuffer write and every instruction-cache miss (code runs from PSRAM) speeds up -- Neon Drift goes from about 40 to about 50 fps -- but ESP-IDF's live re-tuning from the temperature sensor refuses this module's flash, so the timing is the one tuned at power-up.",
17
+ "_psramXip": "Code and rodata run from PSRAM: flash and PSRAM share the MSPI bus, so instruction-cache misses from flash (cold code on every touch) held off the RGB scanout's PSRAM reads and the image drifted.",
18
+ "psram": {
19
+ "mode": "octal",
20
+ "speed": 80,
21
+ "xip": true
22
+ },
23
+ "_buses": "One I2C bus on GPIO15/16 carries the GT911 (0x5d), the PCA9557 expander (0x18) and the BM8563 RTC (0x51), and is also brought out on the HY2.0 I2C connector.",
24
+ "buses": {
25
+ "i2c": {
26
+ "sda": 15,
27
+ "scl": 16
28
+ }
29
+ },
30
+ "chips": {
31
+ "display": {
32
+ "driver": "rgb_panel",
33
+ "interface": "rgb",
34
+ "width": 800,
35
+ "height": 480,
36
+ "_timing": "Elecrow's current examples drive the panel at 18MHz (their maintenance baseline; older code used 16 and 21) with 8/4/8 porches on both axes, PCLK idle high. Gea runs it at 15MHz (36.6Hz): scanout reads the framebuffer out of PSRAM continuously, and at 18MHz a repaint's PSRAM traffic on top of it starved the bounce-buffer refills -- the picture tore on every touch and scroll.",
37
+ "pclkHz": 15000000,
38
+ "_restartInVsync": "No driver restart at every VSYNC: it runs in the VSYNC interrupt, which waits out a bounce refill in progress, and under scroll load a late one landed inside the next frame and shifted it sideways (the screen shook while scrolling). rgb_panel.cpp restarts the DMA itself, only at a VSYNC that finds it still parked in the blanking, so a slip is realigned on the next on-time frame.",
39
+ "restartInVsync": false,
40
+ "hsyncPulseWidth": 4,
41
+ "hsyncBackPorch": 8,
42
+ "hsyncFrontPorch": 8,
43
+ "vsyncPulseWidth": 4,
44
+ "vsyncBackPorch": 8,
45
+ "vsyncFrontPorch": 8,
46
+ "pclkActiveNeg": true,
47
+ "_scanFramebuffers": "Two scanout buffers, not three: code and rodata run from PSRAM (see _psramXip), which leaves about 4.3MB of heap, and the third 768KB buffer is what the factory demo's full-screen menu backdrop needs.",
48
+ "scanFramebuffers": 2,
49
+ "_bounceRows": "24-row bounce buffers, not the default 30: a refill's time and its window both scale with the rows, so the overrun margin is the same, and the 19KB this frees lets the SRAM staging strip grow from 8 to 16 rows. Large repaints (a tab switch, a page's first scroll) raster through that strip so their PSRAM writes cannot starve the refill, and every strip re-walks the display list, so its height sets their cost.",
50
+ "bounceRows": 24,
51
+ "_pins": "data0-4 = B3-B7, data5-10 = G2-G7, data11-15 = R3-R7 (the panel's low bits are tied off). The backlight is board-control line 1; the panel's RESET is an RC network, not a GPIO.",
52
+ "pins": {
53
+ "de": 42,
54
+ "hsync": 40,
55
+ "vsync": 41,
56
+ "pclk": 39,
57
+ "data0": 21,
58
+ "data1": 47,
59
+ "data2": 48,
60
+ "data3": 45,
61
+ "data4": 38,
62
+ "data5": 9,
63
+ "data6": 10,
64
+ "data7": 11,
65
+ "data8": 12,
66
+ "data9": 13,
67
+ "data10": 14,
68
+ "data11": 7,
69
+ "data12": 17,
70
+ "data13": 18,
71
+ "data14": 3,
72
+ "data15": 46
73
+ }
74
+ },
75
+ "touch": {
76
+ "driver": "gt911",
77
+ "interface": "i2c",
78
+ "_pins": "Reset is board-control line 2 (PCA9557 IO2 on V1.0, the STC's touch-recover command 250 on V1.3+). The schematic routes the GT911's INT to GPIO1, but no edge ever reaches it on a V1.3+ board, so touch is polled, as Elecrow's own firmware does (LovyanGFX pin_int = -1). Without INT the binding cannot pin the address across reset and probes both 0x5d and 0x14.",
79
+ "pins": {}
80
+ },
81
+ "audio": {
82
+ "driver": "ns4168",
83
+ "interface": "i2s",
84
+ "_pins": "Speaker: NS4168 on IO5 BCLK, IO6 LRCLK, IO4 SDIN. Microphone: an INMP441 (I2S: IO19 SCK, IO2 WS, IO20 SD) on V1.0, a PDM part (IO19 CLK, IO20 DATA) on V1.3+; 'auto' picks by the board controller found at boot. IO4-IO6 are shared with the microSD slot and the wireless socket, IO19/IO20 with the socket too; the function-select DIP switch picks which one they reach.",
85
+ "pins": {
86
+ "bclk": 5,
87
+ "ws": 6,
88
+ "dout": 4,
89
+ "micBclk": 19,
90
+ "micWs": 2,
91
+ "micDin": 20
92
+ },
93
+ "_expander": "Amplifier shutdown is board-control line 4 and mute line 3 (high = off). On V1.0 they are PCA9557 IO4/IO3; on V1.3+ pulling shutdown low sends the STC's speaker-enable command 248, and there is no documented command for mute or for turning the amplifier off.",
94
+ "expander": {
95
+ "shutdown": 4,
96
+ "mute": 3
97
+ },
98
+ "microphone": "auto"
99
+ },
100
+ "rtc": {
101
+ "driver": "bm8563",
102
+ "interface": "i2c",
103
+ "_battery": "A BM8563 (PCF8563-compatible; a PCF8563 on V1.5) at 0x51, backed by a CR1220 cell, so the system clock is restored from it at boot."
104
+ },
105
+ "expander": {
106
+ "driver": "elecrow_board_control",
107
+ "interface": "i2c",
108
+ "address": 24,
109
+ "_outputs": "Lines use PCA9557 numbering: 1 backlight, 2 touch reset, 3 amplifier mute, 4 amplifier shutdown. On an STC board each maps to its command (backlight 0-245 with brightness, 250 touch recovery, 248 speaker on). initialOutputs 0x14 / initialDirections 0xe1 apply to the PCA9557: touch out of reset, mute low, shutdown high, backlight off until the panel scans.",
110
+ "initialDirections": 225,
111
+ "initialOutputs": 20,
112
+ "outputs": {
113
+ "backlight": 1,
114
+ "touchReset": 2
115
+ }
116
+ }
117
+ },
118
+ "_storage": "The TF slot is wired for SPI (IO5 SCK, IO6 MOSI, IO4 MISO) with its chip select tied active by a resistor, so it has no CS GPIO and cannot run SD_MMC. It shares IO4-IO6 with the speaker; the function-select DIP switch must be on the SD position for the card to answer.",
119
+ "storage": {
120
+ "microSD": {
121
+ "interface": "spi",
122
+ "pins": {
123
+ "sck": 5,
124
+ "mosi": 6,
125
+ "miso": 4
126
+ }
127
+ }
128
+ },
129
+ "_pinSharing": "The function-select DIP switch routes IO4-IO6 to the speaker or the TF slot (or the wireless socket), never both, so the speaker and the card may name the same GPIOs.",
130
+ "pinSharing": [
131
+ [
132
+ "audio",
133
+ "microSD"
134
+ ]
135
+ ],
136
+ "_buzzer": "The passive buzzer is on GPIO8 on V1.0 but driven by the STC (P2.7) on V1.3+, where Elecrow documents no command for it, so the target does not drive it.",
137
+ "_controls": "BOOT is GPIO0, which is free once the board has booted (the wireless-module socket also uses it as BUSY, only when a module is fitted).",
138
+ "controls": {
139
+ "launcherButton": {
140
+ "pin": 0,
141
+ "activeLevel": 0
142
+ }
143
+ },
144
+ "partitions": {
145
+ "nvs": {
146
+ "type": "data",
147
+ "subtype": "nvs",
148
+ "offset": "0x9000",
149
+ "size": "0x6000"
150
+ },
151
+ "otadata": {
152
+ "type": "data",
153
+ "subtype": "ota",
154
+ "offset": "0xf000",
155
+ "size": "0x2000"
156
+ },
157
+ "phy_init": {
158
+ "type": "data",
159
+ "subtype": "phy",
160
+ "offset": "0x11000",
161
+ "size": "0x1000"
162
+ },
163
+ "ota_0": {
164
+ "type": "app",
165
+ "subtype": "ota_0",
166
+ "offset": "0x20000",
167
+ "size": "0x600000"
168
+ },
169
+ "ota_1": {
170
+ "type": "app",
171
+ "subtype": "ota_1",
172
+ "offset": "0x620000",
173
+ "size": "0x600000"
174
+ },
175
+ "storage": {
176
+ "type": "data",
177
+ "subtype": "spiffs",
178
+ "offset": "0xC20000",
179
+ "size": "0x3E0000"
180
+ }
181
+ }
182
+ }
@@ -746,6 +746,9 @@ target_include_directories(gea_active_app_assets PRIVATE ${GEA_FW_INCLUDE_DIRS})
746
746
  add_dependencies(gea_active_app_assets geatsc_build)
747
747
  target_link_libraries(${COMPONENT_LIB} PRIVATE
748
748
  "-Wl$<COMMA>--whole-archive$<COMMA>$<TARGET_FILE:gea_active_app_assets>$<COMMA>--no-whole-archive")
749
+ # A $<TARGET_FILE> inside a link flag orders nothing: without this the link can
750
+ # run before the archive exists ("cannot find libgea_active_app_assets.a").
751
+ add_dependencies(${COMPONENT_LIB} gea_active_app_assets)
749
752
 
750
753
  gea_framework_inherit_build_settings()
751
754