@geastack/targets 0.1.100 → 0.1.102
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/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/.clang-format +10 -0
- 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/CMakeLists.txt +8 -0
- package/targets/esp32-s31-espressif-mosaico/README.md +54 -2
- package/targets/esp32-s31-espressif-mosaico/dependencies.lock +405 -1
- package/targets/esp32-s31-espressif-mosaico/main/CMakeLists.txt +31 -1
- package/targets/esp32-s31-espressif-mosaico/main/board_power.cpp +117 -0
- package/targets/esp32-s31-espressif-mosaico/main/camera.cpp +389 -0
- package/targets/esp32-s31-espressif-mosaico/main/idf_component.yml +17 -3
- 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
|
@@ -0,0 +1,389 @@
|
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
#include "camera.h"
|
|
3
|
+
#include "display.h"
|
|
4
|
+
#include "image.h"
|
|
5
|
+
#include "host/backends.h"
|
|
6
|
+
#include "host/camera_frame.h"
|
|
7
|
+
|
|
8
|
+
#include <algorithm>
|
|
9
|
+
#include <atomic>
|
|
10
|
+
#include <cstdlib>
|
|
11
|
+
#include <cstring>
|
|
12
|
+
#include <mutex>
|
|
13
|
+
#include <vector>
|
|
14
|
+
|
|
15
|
+
#if GEA_MOSAICO_CAMERA_ENABLED
|
|
16
|
+
#include "driver/jpeg_encode.h"
|
|
17
|
+
#include "esp_log.h"
|
|
18
|
+
#include "esp_timer.h"
|
|
19
|
+
#include "freertos/FreeRTOS.h"
|
|
20
|
+
#include "freertos/semphr.h"
|
|
21
|
+
#include "freertos/task.h"
|
|
22
|
+
#include "mosaico_module_camera.h"
|
|
23
|
+
|
|
24
|
+
namespace gea::platform::camera {
|
|
25
|
+
namespace {
|
|
26
|
+
namespace pixel = gea::framework::graphics::pixel;
|
|
27
|
+
namespace frame = gea::host::camera_frame;
|
|
28
|
+
constexpr char kTag[] = "mosaico_camera";
|
|
29
|
+
constexpr std::int64_t kFrameIntervalUs = 2'000'000;
|
|
30
|
+
|
|
31
|
+
class CameraDriver final : public CameraFrameProvider {
|
|
32
|
+
public:
|
|
33
|
+
mosaico_camera_handle_t camera = nullptr;
|
|
34
|
+
jpeg_encoder_handle_t encoder = nullptr;
|
|
35
|
+
std::uint8_t *rgb = nullptr;
|
|
36
|
+
std::uint8_t *jpeg = nullptr;
|
|
37
|
+
std::size_t rgbCapacity = 0, jpegCapacity = 0;
|
|
38
|
+
frame::Size size;
|
|
39
|
+
frame::Size previewSize;
|
|
40
|
+
std::atomic<unsigned> previewCopies{0};
|
|
41
|
+
std::atomic<bool> running{false};
|
|
42
|
+
std::atomic<bool> mirror{false};
|
|
43
|
+
SemaphoreHandle_t exited = nullptr;
|
|
44
|
+
std::mutex operations;
|
|
45
|
+
std::mutex lock;
|
|
46
|
+
std::string latest;
|
|
47
|
+
std::vector<pixel::native_t> pixels;
|
|
48
|
+
|
|
49
|
+
std::string takeFrameDataUrl() override {
|
|
50
|
+
std::unique_lock guard(lock, std::try_to_lock);
|
|
51
|
+
if (!guard.owns_lock()) return {};
|
|
52
|
+
std::string result;
|
|
53
|
+
result.swap(latest);
|
|
54
|
+
return result;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
static void captureTask(void *opaque) {
|
|
58
|
+
auto &self = *static_cast<CameraDriver *>(opaque);
|
|
59
|
+
std::int64_t nextEncode = 0;
|
|
60
|
+
std::int64_t nextPreview = 0;
|
|
61
|
+
std::int64_t previewReportAt = esp_timer_get_time();
|
|
62
|
+
unsigned previewFrames = 0;
|
|
63
|
+
unsigned consecutiveTimeouts = 0;
|
|
64
|
+
while (self.running.load()) {
|
|
65
|
+
mosaico_camera_frame_t source{};
|
|
66
|
+
const auto got = mosaico_camera_get_frame(self.camera, &source);
|
|
67
|
+
if (got != ESP_OK) {
|
|
68
|
+
if (got == ESP_ERR_TIMEOUT && ++consecutiveTimeouts == 3 && self.running.load()) {
|
|
69
|
+
// No frame is borrowed here. Re-arm a stalled DVP queue through the
|
|
70
|
+
// SDK's stream lifecycle instead of leaving the viewer frozen forever.
|
|
71
|
+
const auto restarted = mosaico_camera_restart(self.camera);
|
|
72
|
+
ESP_LOGW(kTag, "Camera timeout recovery: %s", esp_err_to_name(restarted));
|
|
73
|
+
consecutiveTimeouts = 0;
|
|
74
|
+
}
|
|
75
|
+
vTaskDelay(pdMS_TO_TICKS(10));
|
|
76
|
+
continue;
|
|
77
|
+
}
|
|
78
|
+
consecutiveTimeouts = 0;
|
|
79
|
+
const auto now = esp_timer_get_time();
|
|
80
|
+
bool converted = false;
|
|
81
|
+
std::vector<pixel::native_t> preview;
|
|
82
|
+
const std::size_t stride = source.bytes_per_line ? source.bytes_per_line : source.width * 2;
|
|
83
|
+
if (source.pixel_format == V4L2_PIX_FMT_UYVY &&
|
|
84
|
+
now >= nextPreview &&
|
|
85
|
+
source.size / stride >= source.height) {
|
|
86
|
+
// Keep a fixed cadence: scheduling from each received frame would
|
|
87
|
+
// drop every other frame on a 15 Hz sensor and cap preview at 7.5 Hz.
|
|
88
|
+
nextPreview = (now / 100000 + 1) * 100000;
|
|
89
|
+
const int w = self.previewSize.width, h = self.previewSize.height;
|
|
90
|
+
preview.resize(std::size_t(w) * h);
|
|
91
|
+
const auto channel = [](int value) { return std::uint8_t(std::clamp(value, 0, 255)); };
|
|
92
|
+
for (int y = 0; y < h; ++y) for (int x = 0; x < w; ++x) {
|
|
93
|
+
// The left-slot sensor is mounted upside down. Subsample directly
|
|
94
|
+
// from the sensor buffer, correcting its mounting without a resize pass.
|
|
95
|
+
const int sx = source.width - 1 - x * source.width / w;
|
|
96
|
+
const int sy = source.height - 1 - y * source.height / h;
|
|
97
|
+
const auto *pair = static_cast<const std::uint8_t *>(source.data) +
|
|
98
|
+
std::size_t(sy) * stride + std::size_t(sx / 2) * 4;
|
|
99
|
+
const int c = std::max(0, int(pair[sx & 1 ? 3 : 1]) - 16);
|
|
100
|
+
const int u = int(pair[0]) - 128, v = int(pair[2]) - 128;
|
|
101
|
+
preview[y * w + x] = pixel::nativeColor(
|
|
102
|
+
channel((298 * c + 409 * v + 128) >> 8),
|
|
103
|
+
channel((298 * c - 100 * u - 208 * v + 128) >> 8),
|
|
104
|
+
channel((298 * c + 516 * u + 128) >> 8));
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
if (now >= nextEncode && source.pixel_format == V4L2_PIX_FMT_UYVY) {
|
|
108
|
+
nextEncode = now + kFrameIntervalUs;
|
|
109
|
+
converted = frame::uyvyToRgb888Ccw90(
|
|
110
|
+
static_cast<const std::uint8_t *>(source.data), source.size,
|
|
111
|
+
source.width, source.height, stride, self.rgb, self.rgbCapacity,
|
|
112
|
+
self.size.width, self.size.height, self.mirror.load());
|
|
113
|
+
}
|
|
114
|
+
// Return every sensor buffer before codec work; draining continues even
|
|
115
|
+
// while the app is disconnected or its UI never asks for another frame.
|
|
116
|
+
const auto returned = mosaico_camera_return_frame(self.camera, &source);
|
|
117
|
+
if (returned != ESP_OK) {
|
|
118
|
+
ESP_LOGE(kTag, "Return camera buffer failed: %s", esp_err_to_name(returned));
|
|
119
|
+
self.running.store(false);
|
|
120
|
+
break;
|
|
121
|
+
}
|
|
122
|
+
if (!preview.empty()) {
|
|
123
|
+
std::lock_guard guard(self.lock);
|
|
124
|
+
self.pixels.swap(preview);
|
|
125
|
+
++previewFrames;
|
|
126
|
+
}
|
|
127
|
+
if (now - previewReportAt >= 5'000'000) {
|
|
128
|
+
ESP_LOGI(kTag, "Preview: %u sampled frames, %u surface copies in %lld ms",
|
|
129
|
+
previewFrames, self.previewCopies.exchange(0),
|
|
130
|
+
static_cast<long long>((now - previewReportAt) / 1000));
|
|
131
|
+
previewFrames = 0;
|
|
132
|
+
previewReportAt = now;
|
|
133
|
+
}
|
|
134
|
+
if (!converted || !self.running.load()) continue;
|
|
135
|
+
for (std::size_t i = 0; i < std::size_t(self.size.width) * self.size.height; ++i) {
|
|
136
|
+
auto *color = self.rgb + i * 3;
|
|
137
|
+
// ESP-IDF's RGB888 encoder input is explicitly BGR24 (jpeg_types.h).
|
|
138
|
+
std::swap(color[0], color[2]);
|
|
139
|
+
}
|
|
140
|
+
jpeg_encode_cfg_t config{};
|
|
141
|
+
config.width = self.size.width;
|
|
142
|
+
config.height = self.size.height;
|
|
143
|
+
config.src_type = JPEG_ENCODE_IN_FORMAT_RGB888;
|
|
144
|
+
config.sub_sample = JPEG_DOWN_SAMPLING_YUV420;
|
|
145
|
+
config.image_quality = 70;
|
|
146
|
+
std::uint32_t jpegSize = 0;
|
|
147
|
+
const auto encoded = jpeg_encoder_process(self.encoder, &config, self.rgb,
|
|
148
|
+
self.size.width * self.size.height * 3, self.jpeg, self.jpegCapacity, &jpegSize);
|
|
149
|
+
if (encoded != ESP_OK) {
|
|
150
|
+
ESP_LOGW(kTag, "JPEG encode failed: %s", esp_err_to_name(encoded));
|
|
151
|
+
continue;
|
|
152
|
+
}
|
|
153
|
+
auto url = frame::jpegDataUrl(self.jpeg, jpegSize);
|
|
154
|
+
if (url.empty()) continue;
|
|
155
|
+
std::lock_guard guard(self.lock);
|
|
156
|
+
self.latest.swap(url);
|
|
157
|
+
}
|
|
158
|
+
xSemaphoreGive(self.exited);
|
|
159
|
+
vTaskDelete(nullptr);
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
void closeResources() {
|
|
163
|
+
Camera::setFrameProvider(nullptr);
|
|
164
|
+
running.store(false);
|
|
165
|
+
if (exited) {
|
|
166
|
+
// Sensor reads have a 1000ms deadline and JPEG has a 500ms deadline.
|
|
167
|
+
// If a driver nevertheless stalls, preserve its live buffers/handles
|
|
168
|
+
// and let a later close/open retry cleanup instead of hanging the app.
|
|
169
|
+
if (xSemaphoreTake(exited, pdMS_TO_TICKS(2000)) != pdTRUE) {
|
|
170
|
+
ESP_LOGE(kTag, "Camera worker did not stop within 2000ms; resources retained");
|
|
171
|
+
return;
|
|
172
|
+
}
|
|
173
|
+
vSemaphoreDelete(exited);
|
|
174
|
+
exited = nullptr;
|
|
175
|
+
}
|
|
176
|
+
if (camera) {
|
|
177
|
+
const auto result = mosaico_camera_del(camera);
|
|
178
|
+
if (result == ESP_OK) {
|
|
179
|
+
camera = nullptr;
|
|
180
|
+
} else {
|
|
181
|
+
// The SDK retains its context when teardown fails; never erase the
|
|
182
|
+
// sole handle to that still-owned device or its outstanding buffers.
|
|
183
|
+
ESP_LOGE(kTag, "Camera cleanup failed: %s", esp_err_to_name(result));
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
if (!camera) mosaico_module_mgr_deinit();
|
|
187
|
+
if (encoder) { jpeg_del_encoder_engine(encoder); encoder = nullptr; }
|
|
188
|
+
std::free(rgb); rgb = nullptr; rgbCapacity = 0;
|
|
189
|
+
std::free(jpeg); jpeg = nullptr; jpegCapacity = 0;
|
|
190
|
+
std::lock_guard guard(lock);
|
|
191
|
+
std::string().swap(latest);
|
|
192
|
+
std::vector<pixel::native_t>().swap(pixels);
|
|
193
|
+
size = {};
|
|
194
|
+
previewSize = {};
|
|
195
|
+
previewCopies.store(0);
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
void close() {
|
|
199
|
+
std::lock_guard operation(operations);
|
|
200
|
+
closeResources();
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
bool open() {
|
|
204
|
+
std::lock_guard operation(operations);
|
|
205
|
+
if (running.load()) return true;
|
|
206
|
+
closeResources();
|
|
207
|
+
if (camera) return false;
|
|
208
|
+
mosaico_camera_config_t config = MOSAICO_CAMERA_DEFAULT_CONFIG();
|
|
209
|
+
// The two sensors have different supported sizes. Let the SDK detect
|
|
210
|
+
// either sensor's UYVY default, then downsample for upload on this worker.
|
|
211
|
+
// Keep the SDK's 1000ms deadline: stream startup dequeues the first
|
|
212
|
+
// frame too, and the SC101IOT does not reliably deliver it within 100ms.
|
|
213
|
+
auto result = mosaico_camera_new(&config, &camera);
|
|
214
|
+
if (result == ESP_OK) result = mosaico_camera_open(camera);
|
|
215
|
+
mosaico_camera_info_t info{};
|
|
216
|
+
if (result == ESP_OK) result = mosaico_camera_get_info(camera, &info);
|
|
217
|
+
if (result == ESP_OK) {
|
|
218
|
+
std::lock_guard guard(lock);
|
|
219
|
+
size = frame::uploadSize(info.width, info.height);
|
|
220
|
+
previewSize = {160, int(160 * info.height / info.width)};
|
|
221
|
+
if (info.pixel_format != V4L2_PIX_FMT_UYVY || size.width == 0) result = ESP_ERR_NOT_SUPPORTED;
|
|
222
|
+
}
|
|
223
|
+
if (result == ESP_OK) {
|
|
224
|
+
jpeg_encode_memory_alloc_cfg_t memory{};
|
|
225
|
+
memory.buffer_direction = JPEG_ENC_ALLOC_INPUT_BUFFER;
|
|
226
|
+
rgb = static_cast<std::uint8_t *>(jpeg_alloc_encoder_mem(size.width * size.height * 3, &memory, &rgbCapacity));
|
|
227
|
+
memory.buffer_direction = JPEG_ENC_ALLOC_OUTPUT_BUFFER;
|
|
228
|
+
jpeg = static_cast<std::uint8_t *>(jpeg_alloc_encoder_mem(96 * 1024, &memory, &jpegCapacity));
|
|
229
|
+
if (!rgb || !jpeg) result = ESP_ERR_NO_MEM;
|
|
230
|
+
}
|
|
231
|
+
if (result == ESP_OK) {
|
|
232
|
+
jpeg_encode_engine_cfg_t engine{};
|
|
233
|
+
engine.timeout_ms = 500;
|
|
234
|
+
result = jpeg_new_encoder_engine(&engine, &encoder);
|
|
235
|
+
}
|
|
236
|
+
if (result == ESP_OK) result = mosaico_camera_start_stream(camera);
|
|
237
|
+
if (result != ESP_OK) {
|
|
238
|
+
ESP_LOGE(kTag, "Left-slot camera open failed: %s", esp_err_to_name(result));
|
|
239
|
+
closeResources();
|
|
240
|
+
return false;
|
|
241
|
+
}
|
|
242
|
+
exited = xSemaphoreCreateBinary();
|
|
243
|
+
if (!exited) { closeResources(); return false; }
|
|
244
|
+
running.store(true);
|
|
245
|
+
TaskHandle_t worker = nullptr;
|
|
246
|
+
if (xTaskCreatePinnedToCore(captureTask, "gea_camera", 6144, this, 2, &worker, 1) != pdPASS) {
|
|
247
|
+
// No worker exists to signal the completion semaphore.
|
|
248
|
+
vSemaphoreDelete(exited); exited = nullptr;
|
|
249
|
+
closeResources();
|
|
250
|
+
return false;
|
|
251
|
+
}
|
|
252
|
+
Camera::setFrameProvider(this);
|
|
253
|
+
gea::framework::camera::registerCameraSurface();
|
|
254
|
+
ESP_LOGI(kTag, "DVP camera streaming: %ux%u -> upright %dx%d JPEG, one frame per 2s",
|
|
255
|
+
unsigned(info.width), unsigned(info.height), size.width, size.height);
|
|
256
|
+
return true;
|
|
257
|
+
}
|
|
258
|
+
};
|
|
259
|
+
|
|
260
|
+
CameraDriver &driver() { static CameraDriver state; return state; }
|
|
261
|
+
} // namespace
|
|
262
|
+
|
|
263
|
+
bool Camera::isAvailable() { return true; }
|
|
264
|
+
bool Camera::hasPermission() { return true; }
|
|
265
|
+
bool Camera::requestPermission() { return true; }
|
|
266
|
+
bool Camera::open(const std::string &hint, int, int) {
|
|
267
|
+
if (hint != "back" && hint != "front" && hint != "external" && hint != "mosaico-left-dvp") return false;
|
|
268
|
+
return driver().open();
|
|
269
|
+
}
|
|
270
|
+
void Camera::close() { driver().close(); }
|
|
271
|
+
bool Camera::isOpen() { return driver().running.load(); }
|
|
272
|
+
int Camera::width() { auto &state = driver(); std::lock_guard guard(state.lock); return state.previewSize.width; }
|
|
273
|
+
int Camera::height() { auto &state = driver(); std::lock_guard guard(state.lock); return state.previewSize.height; }
|
|
274
|
+
int Camera::orientation() { return 180; }
|
|
275
|
+
Facing Camera::currentFacing() { return Facing::External; }
|
|
276
|
+
std::string Camera::currentFacingString() { return "external"; }
|
|
277
|
+
int Camera::deviceCount() { return 1; }
|
|
278
|
+
DeviceInfo Camera::deviceAt(int index) {
|
|
279
|
+
return index == 0 ? DeviceInfo{"mosaico-left-dvp", Facing::External, width(), height()} : DeviceInfo{};
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
bool Camera::fillPreview(pixel::native_t *dst, int w, int h, int fit, bool mirror) {
|
|
283
|
+
auto &state = driver();
|
|
284
|
+
if (!dst || w <= 0 || h <= 0) return false;
|
|
285
|
+
std::unique_lock guard(state.lock, std::try_to_lock);
|
|
286
|
+
if (!guard.owns_lock() || state.pixels.empty()) return false;
|
|
287
|
+
const int sw = state.previewSize.width, sh = state.previewSize.height;
|
|
288
|
+
++state.previewCopies;
|
|
289
|
+
if (w * sh == h * sw || fit == 2) {
|
|
290
|
+
for (int y = 0; y < h; ++y) {
|
|
291
|
+
const auto *row = state.pixels.data() + (y * sh / h) * sw;
|
|
292
|
+
for (int x = 0; x < w; ++x) {
|
|
293
|
+
const int sx = x * sw / w;
|
|
294
|
+
dst[y * w + x] = row[mirror ? sw - 1 - sx : sx];
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
return true;
|
|
298
|
+
}
|
|
299
|
+
const double scale = fit == 1 ? std::min(double(w) / sw, double(h) / sh) : std::max(double(w) / sw, double(h) / sh);
|
|
300
|
+
const double rw = fit == 2 ? w : sw * scale, rh = fit == 2 ? h : sh * scale;
|
|
301
|
+
for (int y = 0; y < h; ++y) for (int x = 0; x < w; ++x) {
|
|
302
|
+
const double sx = (x - (w - rw) / 2) * sw / rw, sy = (y - (h - rh) / 2) * sh / rh;
|
|
303
|
+
dst[y * w + x] = sx < 0 || sy < 0 || sx >= sw || sy >= sh ? pixel::native_t{} :
|
|
304
|
+
state.pixels[int(sy) * sw + (mirror ? sw - 1 - int(sx) : int(sx))];
|
|
305
|
+
}
|
|
306
|
+
return true;
|
|
307
|
+
}
|
|
308
|
+
void Camera::drawPreview(int x, int y, int w, int h) {
|
|
309
|
+
if (w <= 0) w = width();
|
|
310
|
+
if (h <= 0) h = height();
|
|
311
|
+
if (w <= 0 || h <= 0) return;
|
|
312
|
+
std::vector<pixel::native_t> buffer(std::size_t(w) * h);
|
|
313
|
+
if (!fillPreview(buffer.data(), w, h, 2, false)) return;
|
|
314
|
+
struct Raster { const pixel::native_t *pixels; int width; int x; int y; } raster{buffer.data(), w, x, y};
|
|
315
|
+
gea::platform::display::Display::streamRect(x, y, w, h,
|
|
316
|
+
[](pixel::native_t *dst, int columns, int rows, int column, int row, void *context) {
|
|
317
|
+
auto &image = *static_cast<Raster *>(context);
|
|
318
|
+
for (int i = 0; i < rows; ++i) std::memcpy(dst + i * columns,
|
|
319
|
+
image.pixels + (row - image.y + i) * image.width + column - image.x,
|
|
320
|
+
columns * sizeof(pixel::native_t));
|
|
321
|
+
}, &raster);
|
|
322
|
+
}
|
|
323
|
+
int Camera::previewMode() { return 0; }
|
|
324
|
+
void Camera::positionPreviewLayer(int, int, int, int) {}
|
|
325
|
+
void Camera::hidePreviewLayer() {}
|
|
326
|
+
void Camera::presentNativeOverlay() {}
|
|
327
|
+
int Camera::capture(bool mirror) {
|
|
328
|
+
const int w = width(), h = height();
|
|
329
|
+
if (w <= 0 || h <= 0) return -1;
|
|
330
|
+
auto *pixels = static_cast<pixel::native_t *>(std::malloc(std::size_t(w) * h * sizeof(pixel::native_t)));
|
|
331
|
+
if (!pixels) return -1;
|
|
332
|
+
if (!fillPreview(pixels, w, h, 2, mirror)) { std::free(pixels); return -1; }
|
|
333
|
+
const int image = gea::framework::graphics::ImageStore::instance().registerBuffer(pixels, w, h, -1, true);
|
|
334
|
+
if (image < 0) std::free(pixels);
|
|
335
|
+
return image;
|
|
336
|
+
}
|
|
337
|
+
bool Camera::startRecording(const std::string &, double) { return false; }
|
|
338
|
+
double Camera::stopRecording() { return -1; }
|
|
339
|
+
bool Camera::isRecording() { return false; }
|
|
340
|
+
void Camera::setFlash(const std::string &mode) {
|
|
341
|
+
auto &state = driver();
|
|
342
|
+
std::lock_guard operation(state.operations);
|
|
343
|
+
if (!state.camera) return;
|
|
344
|
+
if (mode == "on" || mode == "torch") mosaico_camera_flash_trigger(state.camera);
|
|
345
|
+
else mosaico_camera_flash_stop(state.camera);
|
|
346
|
+
}
|
|
347
|
+
void Camera::setMirror(bool mirror) { driver().mirror.store(mirror); }
|
|
348
|
+
void Camera::setZoom(double) {}
|
|
349
|
+
void Camera::setExposure(const std::string &, double, double, double) {}
|
|
350
|
+
void Camera::setWhiteBalance(const std::string &, double, double) {}
|
|
351
|
+
void Camera::setFocus(const std::string &, double, double) {}
|
|
352
|
+
void Camera::setTorch(const std::string &mode, double) { setFlash(mode); }
|
|
353
|
+
} // namespace gea::platform::camera
|
|
354
|
+
|
|
355
|
+
#else
|
|
356
|
+
// Apps without the camera binding do not download or link DVP/BSP components.
|
|
357
|
+
namespace gea::platform::camera {
|
|
358
|
+
bool Camera::isAvailable() { return false; }
|
|
359
|
+
bool Camera::hasPermission() { return false; }
|
|
360
|
+
bool Camera::requestPermission() { return false; }
|
|
361
|
+
bool Camera::open(const std::string &, int, int) { return false; }
|
|
362
|
+
void Camera::close() {}
|
|
363
|
+
bool Camera::isOpen() { return false; }
|
|
364
|
+
int Camera::width() { return 0; }
|
|
365
|
+
int Camera::height() { return 0; }
|
|
366
|
+
int Camera::orientation() { return 0; }
|
|
367
|
+
Facing Camera::currentFacing() { return Facing::External; }
|
|
368
|
+
std::string Camera::currentFacingString() { return "external"; }
|
|
369
|
+
int Camera::deviceCount() { return 0; }
|
|
370
|
+
DeviceInfo Camera::deviceAt(int) { return {}; }
|
|
371
|
+
void Camera::drawPreview(int, int, int, int) {}
|
|
372
|
+
int Camera::previewMode() { return 0; }
|
|
373
|
+
bool Camera::fillPreview(gea::framework::graphics::pixel::native_t *, int, int, int, bool) { return false; }
|
|
374
|
+
void Camera::positionPreviewLayer(int, int, int, int) {}
|
|
375
|
+
void Camera::hidePreviewLayer() {}
|
|
376
|
+
void Camera::presentNativeOverlay() {}
|
|
377
|
+
int Camera::capture(bool) { return -1; }
|
|
378
|
+
bool Camera::startRecording(const std::string &, double) { return false; }
|
|
379
|
+
double Camera::stopRecording() { return -1; }
|
|
380
|
+
bool Camera::isRecording() { return false; }
|
|
381
|
+
void Camera::setFlash(const std::string &) {}
|
|
382
|
+
void Camera::setZoom(double) {}
|
|
383
|
+
void Camera::setMirror(bool) {}
|
|
384
|
+
void Camera::setExposure(const std::string &, double, double, double) {}
|
|
385
|
+
void Camera::setWhiteBalance(const std::string &, double, double) {}
|
|
386
|
+
void Camera::setFocus(const std::string &, double, double) {}
|
|
387
|
+
void Camera::setTorch(const std::string &, double) {}
|
|
388
|
+
} // namespace gea::platform::camera
|
|
389
|
+
#endif
|
|
@@ -2,10 +2,21 @@
|
|
|
2
2
|
# so each network-only component carries the same capability rule the other
|
|
3
3
|
# targets use (GEA_EMBEDDED_CAPABILITY_* comes from the gea CLI's app analysis).
|
|
4
4
|
#
|
|
5
|
-
#
|
|
6
|
-
#
|
|
7
|
-
# former, and an app that asks for echo cancellation is not supported yet.
|
|
5
|
+
# ESP-SR now ships S31 libraries. Keep them optional for voice apps using AEC;
|
|
6
|
+
# the portable Opus build below still replaces the unsupported audio codec.
|
|
8
7
|
dependencies:
|
|
8
|
+
espressif/esp-sr:
|
|
9
|
+
version: '==2.6.0'
|
|
10
|
+
rules:
|
|
11
|
+
- if: '$GEA_EMBEDDED_CAPABILITY_AEC == 1'
|
|
12
|
+
# Official module ownership, sensor autodetection and DVP stability patches.
|
|
13
|
+
# The pinned Git checkout also supplies its relative BSP/manager components.
|
|
14
|
+
mosaico_module_camera:
|
|
15
|
+
git: https://github.com/esp-mosaico/esp-mosaico-bsp.git
|
|
16
|
+
version: a4bfb426afcf2911c01fdd9b6d6f024019f00f8f
|
|
17
|
+
path: components/mosaico_module_camera
|
|
18
|
+
rules:
|
|
19
|
+
- if: '$GEA_EMBEDDED_CAPABILITY_CAMERA == 1'
|
|
9
20
|
espressif/esp_lcd_co5300: '^2.0.3'
|
|
10
21
|
# The board's touch controller is a CST9220 (Espressif's board definition,
|
|
11
22
|
# esp-brookesia esp_mosaico_v1_2). It may run the HYN212 protocol, which the
|
|
@@ -16,6 +27,9 @@ dependencies:
|
|
|
16
27
|
# board_power.cpp: the USB-C port is the S31's high-speed OTG controller, so
|
|
17
28
|
# the console is a TinyUSB CDC interface.
|
|
18
29
|
espressif/esp_tinyusb: '^2.2.1'
|
|
30
|
+
# nand_mount.cpp: the board's SPI NAND as FAT storage at /nand.
|
|
31
|
+
espressif/spi_nand_flash: '^1.4.4'
|
|
32
|
+
espressif/spi_nand_flash_fatfs: '^1.1.2'
|
|
19
33
|
espressif/esp_h264:
|
|
20
34
|
version: '^1.4.1'
|
|
21
35
|
rules:
|
|
@@ -66,6 +66,18 @@ struct PowerConfig {
|
|
|
66
66
|
gpio_num_t powerOffRequest;
|
|
67
67
|
};
|
|
68
68
|
|
|
69
|
+
// The 1 Gbit SPI NAND (GD5F1GM7UEYIGR) on SPI3, pins per the esp-dev-kits V1.2
|
|
70
|
+
// user guide. main/nand_mount.cpp mounts it as the board's file storage.
|
|
71
|
+
struct NandConfig {
|
|
72
|
+
spi_host_device_t spiHost;
|
|
73
|
+
gpio_num_t clk;
|
|
74
|
+
gpio_num_t mosi;
|
|
75
|
+
gpio_num_t miso;
|
|
76
|
+
gpio_num_t cs;
|
|
77
|
+
gpio_num_t wp;
|
|
78
|
+
gpio_num_t hold;
|
|
79
|
+
};
|
|
80
|
+
|
|
69
81
|
struct LauncherButtonConfig {
|
|
70
82
|
gpio_num_t pin;
|
|
71
83
|
int activeLevel;
|
|
@@ -119,6 +131,16 @@ public:
|
|
|
119
131
|
.powerAmplifier = GPIO_NUM_45,
|
|
120
132
|
};
|
|
121
133
|
|
|
134
|
+
static constexpr NandConfig nand{
|
|
135
|
+
.spiHost = SPI3_HOST,
|
|
136
|
+
.clk = GPIO_NUM_20,
|
|
137
|
+
.mosi = GPIO_NUM_21,
|
|
138
|
+
.miso = GPIO_NUM_22,
|
|
139
|
+
.cs = GPIO_NUM_23,
|
|
140
|
+
.wp = GPIO_NUM_25,
|
|
141
|
+
.hold = GPIO_NUM_24,
|
|
142
|
+
};
|
|
143
|
+
|
|
122
144
|
static constexpr PowerConfig power{
|
|
123
145
|
.vcc3v3Enable = GPIO_NUM_60,
|
|
124
146
|
.powerOffRequest = GPIO_NUM_57,
|
|
@@ -132,6 +154,7 @@ inline constexpr auto display = Board::display;
|
|
|
132
154
|
inline constexpr auto touch = Board::touch;
|
|
133
155
|
inline constexpr auto audio = Board::audio;
|
|
134
156
|
inline constexpr auto power = Board::power;
|
|
157
|
+
inline constexpr auto nand = Board::nand;
|
|
135
158
|
|
|
136
159
|
// The "AI" button on the side, active low. BOOT (GPIO61) stays the ROM's
|
|
137
160
|
// download strap and is left alone.
|
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
// The board's 1 Gbit SPI NAND as its file storage, FAT on Espressif's
|
|
2
|
+
// spi_nand_flash driver (Dhara wear levelling), mounted at /nand.
|
|
3
|
+
//
|
|
4
|
+
// It is where an app keeps what is too large for its app slot: the NOR holds
|
|
5
|
+
// the firmware and the slot caps an image near 8 MB, while assets pushed here
|
|
6
|
+
// (`gea devctl push <file> /nand/...`) are read back at run time through
|
|
7
|
+
// readCacheFile. It is the storage provider gea::platform::storage::
|
|
8
|
+
// ensureMounted() answers from, so every file op mounts it first.
|
|
9
|
+
//
|
|
10
|
+
// The chip is on SPI3 (SPI2 is the panel's) behind VCC_3V3, which the mount
|
|
11
|
+
// opens first. A blank chip has no filesystem: the first mount formats it.
|
|
12
|
+
#include "platform/file_cache.h"
|
|
13
|
+
#include "board.h"
|
|
14
|
+
|
|
15
|
+
#include <cinttypes>
|
|
16
|
+
#include <cstring>
|
|
17
|
+
#include <initializer_list>
|
|
18
|
+
|
|
19
|
+
#include "driver/gpio.h"
|
|
20
|
+
#include "driver/spi_master.h"
|
|
21
|
+
#include "esp_log.h"
|
|
22
|
+
#include "esp_vfs_fat_nand.h"
|
|
23
|
+
#include "freertos/FreeRTOS.h"
|
|
24
|
+
#include "freertos/semphr.h"
|
|
25
|
+
|
|
26
|
+
namespace gea::platform::board {
|
|
27
|
+
void powerOnRails();
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
namespace gea::platform::storage {
|
|
31
|
+
|
|
32
|
+
namespace {
|
|
33
|
+
|
|
34
|
+
constexpr char kTag[] = "nand";
|
|
35
|
+
constexpr char kMountPoint[] = "/nand";
|
|
36
|
+
// The GD5F1GM7 reads at up to 133 MHz; 40 MHz single-line is what the
|
|
37
|
+
// driver's own examples run and is ample for loading assets once.
|
|
38
|
+
constexpr int kClockHz = 40 * 1000 * 1000;
|
|
39
|
+
|
|
40
|
+
StaticSemaphore_t g_lockStorage;
|
|
41
|
+
SemaphoreHandle_t g_lock = nullptr;
|
|
42
|
+
bool g_busReady = false;
|
|
43
|
+
spi_device_handle_t g_spi = nullptr;
|
|
44
|
+
spi_nand_flash_device_t *g_flash = nullptr;
|
|
45
|
+
bool g_mounted = false;
|
|
46
|
+
|
|
47
|
+
// Each step is kept once it succeeds, and a failed mount is retried on the
|
|
48
|
+
// next file op: the first attempt runs at boot, before the USB console is up,
|
|
49
|
+
// so its log line is lost -- a retry while a host is attached says why.
|
|
50
|
+
bool mountNand()
|
|
51
|
+
{
|
|
52
|
+
gea::platform::board::powerOnRails();
|
|
53
|
+
const auto &pins = gea::platform::board::nand;
|
|
54
|
+
esp_err_t err = ESP_OK;
|
|
55
|
+
if (!g_busReady) {
|
|
56
|
+
// WP# and HOLD# are active low and stay plain GPIOs held high. Handed to
|
|
57
|
+
// the SPI bus as IO2/IO3 they float to levels the chip reads as HOLD#
|
|
58
|
+
// asserted, and READ ID answers zeros (seen on the board; Espressif's
|
|
59
|
+
// own Mosaico bring-up does the same). Single-line needs neither.
|
|
60
|
+
for (gpio_num_t pin : {pins.hold, pins.wp}) {
|
|
61
|
+
gpio_set_level(pin, 1);
|
|
62
|
+
gpio_config_t control = {};
|
|
63
|
+
control.pin_bit_mask = 1ULL << pin;
|
|
64
|
+
control.mode = GPIO_MODE_OUTPUT;
|
|
65
|
+
control.pull_up_en = GPIO_PULLUP_ENABLE;
|
|
66
|
+
gpio_config(&control);
|
|
67
|
+
gpio_set_level(pin, 1);
|
|
68
|
+
}
|
|
69
|
+
spi_bus_config_t bus = {};
|
|
70
|
+
bus.mosi_io_num = pins.mosi;
|
|
71
|
+
bus.miso_io_num = pins.miso;
|
|
72
|
+
bus.sclk_io_num = pins.clk;
|
|
73
|
+
bus.quadwp_io_num = GPIO_NUM_NC;
|
|
74
|
+
bus.quadhd_io_num = GPIO_NUM_NC;
|
|
75
|
+
bus.max_transfer_sz = 4096 * 2;
|
|
76
|
+
err = spi_bus_initialize(pins.spiHost, &bus, SPI_DMA_CH_AUTO);
|
|
77
|
+
if (err != ESP_OK) {
|
|
78
|
+
ESP_LOGE(kTag, "SPI bus init failed: %s", esp_err_to_name(err));
|
|
79
|
+
return false;
|
|
80
|
+
}
|
|
81
|
+
g_busReady = true;
|
|
82
|
+
}
|
|
83
|
+
if (g_spi == nullptr) {
|
|
84
|
+
spi_device_interface_config_t device = {};
|
|
85
|
+
device.clock_speed_hz = kClockHz;
|
|
86
|
+
device.mode = 0;
|
|
87
|
+
device.spics_io_num = pins.cs;
|
|
88
|
+
device.queue_size = 10;
|
|
89
|
+
device.flags = SPI_DEVICE_HALFDUPLEX;
|
|
90
|
+
err = spi_bus_add_device(pins.spiHost, &device, &g_spi);
|
|
91
|
+
if (err != ESP_OK) {
|
|
92
|
+
g_spi = nullptr;
|
|
93
|
+
ESP_LOGE(kTag, "SPI device add failed: %s", esp_err_to_name(err));
|
|
94
|
+
return false;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
if (g_flash == nullptr) {
|
|
98
|
+
spi_nand_flash_config_t config = {};
|
|
99
|
+
config.device_handle = g_spi;
|
|
100
|
+
config.io_mode = SPI_NAND_IO_MODE_SIO;
|
|
101
|
+
config.flags = SPI_DEVICE_HALFDUPLEX;
|
|
102
|
+
err = spi_nand_flash_init_device(&config, &g_flash);
|
|
103
|
+
if (err != ESP_OK) {
|
|
104
|
+
g_flash = nullptr;
|
|
105
|
+
ESP_LOGE(kTag, "NAND init failed: %s", esp_err_to_name(err));
|
|
106
|
+
return false;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
esp_vfs_fat_mount_config_t mount = {};
|
|
111
|
+
mount.max_files = 4;
|
|
112
|
+
mount.format_if_mount_failed = true;
|
|
113
|
+
mount.allocation_unit_size = 16 * 1024;
|
|
114
|
+
err = esp_vfs_fat_nand_mount(kMountPoint, g_flash, &mount);
|
|
115
|
+
if (err != ESP_OK) {
|
|
116
|
+
ESP_LOGE(kTag, "mount %s failed: %s", kMountPoint, esp_err_to_name(err));
|
|
117
|
+
return false;
|
|
118
|
+
}
|
|
119
|
+
std::uint64_t total = 0;
|
|
120
|
+
std::uint64_t free = 0;
|
|
121
|
+
esp_vfs_fat_info(kMountPoint, &total, &free);
|
|
122
|
+
ESP_LOGI(kTag, "mounted %s: %" PRIu64 " KB, %" PRIu64 " KB free", kMountPoint, total / 1024, free / 1024);
|
|
123
|
+
return true;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
// Serialized: the board start task mounts eagerly (GEADEV PUSH writes /nand
|
|
127
|
+
// without asking) while the app's first file read may ask at the same moment.
|
|
128
|
+
bool ensureNandMounted()
|
|
129
|
+
{
|
|
130
|
+
xSemaphoreTake(g_lock, portMAX_DELAY);
|
|
131
|
+
if (!g_mounted) g_mounted = mountNand();
|
|
132
|
+
const bool mounted = g_mounted;
|
|
133
|
+
xSemaphoreGive(g_lock);
|
|
134
|
+
return mounted;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
} // namespace
|
|
138
|
+
|
|
139
|
+
} // namespace gea::platform::storage
|
|
140
|
+
|
|
141
|
+
// GEADEV FORMAT /nand (device_control.cpp): unmount, erase the whole chip,
|
|
142
|
+
// and mount again, which formats the blank chip.
|
|
143
|
+
extern "C" int gea_board_storage_format(const char *mount)
|
|
144
|
+
{
|
|
145
|
+
using namespace gea::platform::storage;
|
|
146
|
+
if (std::strcmp(mount, kMountPoint) != 0) return -2;
|
|
147
|
+
if (g_lock == nullptr) return -3;
|
|
148
|
+
xSemaphoreTake(g_lock, portMAX_DELAY);
|
|
149
|
+
if (!g_mounted && g_flash == nullptr) g_mounted = mountNand();
|
|
150
|
+
if (g_flash == nullptr) {
|
|
151
|
+
xSemaphoreGive(g_lock);
|
|
152
|
+
return -4;
|
|
153
|
+
}
|
|
154
|
+
if (g_mounted) esp_vfs_fat_nand_unmount(kMountPoint, g_flash);
|
|
155
|
+
g_mounted = false;
|
|
156
|
+
const esp_err_t err = spi_nand_erase_chip(g_flash);
|
|
157
|
+
if (err != ESP_OK) ESP_LOGE(kTag, "erase failed: %s", esp_err_to_name(err));
|
|
158
|
+
g_mounted = mountNand();
|
|
159
|
+
const bool mounted = g_mounted;
|
|
160
|
+
xSemaphoreGive(g_lock);
|
|
161
|
+
return err != ESP_OK ? -5 : (mounted ? 0 : -6);
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
namespace gea::platform::storage {
|
|
165
|
+
|
|
166
|
+
void installNandFileStorage()
|
|
167
|
+
{
|
|
168
|
+
if (g_lock == nullptr) g_lock = xSemaphoreCreateMutexStatic(&g_lockStorage);
|
|
169
|
+
setMountProvider(&ensureNandMounted);
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
} // namespace gea::platform::storage
|
|
@@ -1,10 +1,14 @@
|
|
|
1
1
|
# Espressif ESP-Mosaico V1.2, 16 MB quad NOR flash (GD25Q128E).
|
|
2
2
|
# The S31 bootloader sits at 0x2000 (the first two sectors are reserved), which
|
|
3
3
|
# leaves it 24 KB below the partition table at 0x8000.
|
|
4
|
+
# The app slots take all but 256 KB of storage: an app is installed over USB
|
|
5
|
+
# into a slot, so the slot is the largest app the board can run, and three.js
|
|
6
|
+
# games (skytail) outgrew 7 MB. A board still on the old 7 MB layout rewrites
|
|
7
|
+
# its table to this one on boot (board_power.cpp, migratePartitionTable).
|
|
4
8
|
# Name, Type, SubType, Offset, Size
|
|
5
9
|
nvs, data, nvs, 0x9000, 0x6000
|
|
6
10
|
otadata, data, ota, 0xf000, 0x2000
|
|
7
11
|
phy_init, data, phy, 0x11000, 0x1000
|
|
8
|
-
ota_0, app, ota_0, 0x20000,
|
|
9
|
-
ota_1, app, ota_1,
|
|
10
|
-
storage, data, spiffs,
|
|
12
|
+
ota_0, app, ota_0, 0x20000, 0x7d0000
|
|
13
|
+
ota_1, app, ota_1, 0x7f0000, 0x7d0000
|
|
14
|
+
storage, data, spiffs, 0xfc0000, 0x40000
|