@geastack/targets 0.1.103 → 0.1.104
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/README.md +7 -0
- package/package.json +6 -6
- package/targets/cmake/geatsc-generated-archive-build.mjs +41 -12
- package/targets/esp32/app_project.cmake +23 -27
- package/targets/esp32/chip_bindings/magnetometer/bmm150.cpp +140 -0
- package/targets/esp32/chip_bindings/touch/cst9217.cpp +27 -3
- package/targets/esp32/chip_bindings/touch/cst9217_controller.h +11 -2
- package/targets/esp32/components/gea_framework/CMakeLists.txt +9 -5
- package/targets/esp32/components/gea_framework/project_include.cmake +22 -0
- package/targets/esp32/esp_now.cpp +298 -0
- package/targets/esp32/esp_now_power.h +17 -0
- package/targets/esp32/esp_now_rate.h +57 -0
- package/targets/esp32/esp_now_tx_header.h +46 -0
- package/targets/esp32/gea_framework.cmake +1 -0
- package/targets/esp32/ldfragments/gea_ui_state_external.lf +11 -0
- package/targets/esp32/services/device_control.cpp +29 -11
- package/targets/esp32/services/frame_scheduler.cpp +7 -0
- package/targets/esp32/uart.cpp +7 -1
- package/targets/esp32-m5stack-m5paper/CMakeLists.txt +1 -0
- package/targets/esp32-m5stack-m5paper/main/idf_component.yml +7 -4
- package/targets/esp32-p4-m5stack-tab5/CMakeLists.txt +1 -0
- package/targets/esp32-p4-m5stack-tab5/main/CMakeLists.txt +4 -0
- package/targets/esp32-p4-m5stack-tab5/main/idf_component.yml +9 -6
- package/targets/esp32-p4-waveshare-touch-lcd-3.5/CMakeLists.txt +1 -0
- package/targets/esp32-p4-waveshare-touch-lcd-3.5/main/CMakeLists.txt +4 -0
- package/targets/esp32-p4-waveshare-touch-lcd-3.5/main/display.cpp +21 -5
- package/targets/esp32-p4-waveshare-touch-lcd-3.5/main/idf_component.yml +8 -5
- package/targets/esp32-p4-waveshare-touch-lcd-7/CMakeLists.txt +1 -0
- package/targets/esp32-p4-waveshare-touch-lcd-7/main/CMakeLists.txt +4 -0
- package/targets/esp32-p4-waveshare-touch-lcd-7/main/display.cpp +16 -5
- package/targets/esp32-p4-waveshare-touch-lcd-7/main/idf_component.yml +8 -5
- package/targets/esp32-s3-elecrow-rotary-2.1/CMakeLists.txt +1 -0
- package/targets/esp32-s3-elecrow-rotary-2.1/main/CMakeLists.txt +3 -3
- package/targets/esp32-s3-elecrow-rotary-2.1/main/idf_component.yml +5 -2
- package/targets/esp32-s3-epaper-1.54/CMakeLists.txt +1 -0
- package/targets/esp32-s3-epaper-1.54/main/CMakeLists.txt +9 -9
- package/targets/esp32-s3-epaper-1.54/main/idf_component.yml +7 -4
- package/targets/esp32-s3-lilygo-t-display-s3-long/CMakeLists.txt +1 -0
- package/targets/esp32-s3-lilygo-t-display-s3-long/main/idf_component.yml +7 -4
- package/targets/esp32-s3-lilygo-t5-epaper-4.7/CMakeLists.txt +1 -0
- package/targets/esp32-s3-lilygo-t5-epaper-4.7/main/idf_component.yml +4 -1
- package/targets/esp32-s3-m5stack-papers3/CMakeLists.txt +1 -0
- package/targets/esp32-s3-m5stack-papers3/main/idf_component.yml +7 -4
- package/targets/esp32-s3-m5stack-sticks3/CMakeLists.txt +1 -0
- package/targets/esp32-s3-m5stack-sticks3/main/CMakeLists.txt +2 -1
- package/targets/esp32-s3-m5stack-sticks3/main/idf_component.yml +6 -3
- package/targets/esp32-s3-m5stack-stopwatch/CMakeLists.txt +1 -0
- package/targets/esp32-s3-m5stack-stopwatch/main/gea-dependencies.json +42 -0
- package/targets/esp32-s3-m5stack-stopwatch/main/idf_component.yml +4 -18
- package/targets/esp32-s3-touch-amoled-1.75/CMakeLists.txt +1 -0
- package/targets/esp32-s3-touch-amoled-1.75/main/idf_component.yml +8 -5
- package/targets/esp32-s3-touch-amoled-1.8/CMakeLists.txt +1 -0
- package/targets/esp32-s3-touch-amoled-1.8/main/CMakeLists.txt +9 -4
- package/targets/esp32-s3-touch-amoled-1.8/main/gea-dependencies.json +26 -0
- package/targets/esp32-s3-touch-amoled-1.8/main/idf_component.yml +6 -18
- package/targets/esp32-s3-touch-amoled-2.06/CMakeLists.txt +1 -0
- package/targets/esp32-s3-touch-amoled-2.06/main/CMakeLists.txt +11 -10
- package/targets/esp32-s3-touch-amoled-2.06/main/gea-dependencies.json +58 -0
- package/targets/esp32-s3-touch-amoled-2.06/main/idf_component.yml +4 -42
- package/targets/esp32-s3-touch-amoled-2.41/CMakeLists.txt +1 -0
- package/targets/esp32-s3-touch-amoled-2.41/main/gea-dependencies.json +42 -0
- package/targets/esp32-s3-touch-amoled-2.41/main/idf_component.yml +5 -30
- package/targets/esp32-s3-touch-lcd-1.54/CMakeLists.txt +1 -0
- package/targets/esp32-s3-touch-lcd-1.54/main/idf_component.yml +8 -5
- package/targets/esp32-s3-touch-lcd-3.5b/CMakeLists.txt +1 -0
- package/targets/esp32-s3-touch-lcd-3.5b/main/gea-dependencies.json +26 -0
- package/targets/esp32-s3-touch-lcd-3.5b/main/idf_component.yml +4 -20
- package/targets/esp32-s31-espressif-mosaico/CMakeLists.txt +1 -0
- package/targets/esp32-s31-espressif-mosaico/README.md +10 -2
- package/targets/esp32-s31-espressif-mosaico/dependencies.lock +7 -334
- package/targets/esp32-s31-espressif-mosaico/main/CMakeLists.txt +9 -1
- package/targets/esp32-s31-espressif-mosaico/main/board_power.cpp +13 -1
- package/targets/esp32-s31-espressif-mosaico/main/gea-dependencies.json +52 -0
- package/targets/esp32-s31-espressif-mosaico/main/idf_component.yml +13 -40
- package/targets/esp32-s31-espressif-mosaico/main/include/board.h +6 -0
- package/targets/esp32-s31-espressif-mosaico/main/include/mosaico_peer_uart_pins.h +2 -2
- package/targets/esp32-s31-espressif-mosaico/partitions.csv +1 -1
- package/targets/esp32-s3-m5stack-stopwatch/.clang-format +0 -10
|
@@ -0,0 +1,298 @@
|
|
|
1
|
+
#include "sdkconfig.h"
|
|
2
|
+
#if CONFIG_ESP_WIFI_ENABLED && !CONFIG_ESP_HOST_WIFI_ENABLED && \
|
|
3
|
+
__has_include("esp_now.h")
|
|
4
|
+
#include "connectivity/wifi_task_stack.h"
|
|
5
|
+
#include "esp_event.h"
|
|
6
|
+
#include "esp_heap_caps.h"
|
|
7
|
+
#include "esp_idf_version.h"
|
|
8
|
+
#include "esp_log.h"
|
|
9
|
+
#include "esp_now.h"
|
|
10
|
+
#include "esp_now_power.h"
|
|
11
|
+
#include "esp_now_rate.h"
|
|
12
|
+
#include "esp_now_tx_header.h"
|
|
13
|
+
#include "esp_timer.h"
|
|
14
|
+
#include "esp_wifi.h"
|
|
15
|
+
#include "freertos/FreeRTOS.h"
|
|
16
|
+
#include "freertos/semphr.h"
|
|
17
|
+
#include "platform/esp_now.h"
|
|
18
|
+
#include <atomic>
|
|
19
|
+
#include <cstring>
|
|
20
|
+
#include <new>
|
|
21
|
+
|
|
22
|
+
namespace {
|
|
23
|
+
using namespace gea::platform::espnow;
|
|
24
|
+
constexpr unsigned kQueue = 64;
|
|
25
|
+
struct State {
|
|
26
|
+
Datagram rx[kQueue];
|
|
27
|
+
std::atomic<unsigned> write{0}, read{0}, sent{0}, failed{0}, dropped{0},
|
|
28
|
+
received{0}, maxSend{0};
|
|
29
|
+
std::atomic<bool> busy{false}, open{false}, captureTxHeader{false};
|
|
30
|
+
std::int64_t sentAt = 0;
|
|
31
|
+
std::atomic<std::uint64_t> completedStart{0}, completedAt{0};
|
|
32
|
+
std::atomic<unsigned> completedRate{0}, completedStatus{0};
|
|
33
|
+
std::atomic<std::uint32_t> completedMacControl{0}, completedMacSequence{0};
|
|
34
|
+
SemaphoreHandle_t event = nullptr;
|
|
35
|
+
bool ownsRadio = false;
|
|
36
|
+
wifi_ps_type_t previousPs = WIFI_PS_NONE;
|
|
37
|
+
int rate = 54, channel = 0;
|
|
38
|
+
};
|
|
39
|
+
State *state = nullptr;
|
|
40
|
+
void received(const esp_now_recv_info_t *info, const std::uint8_t *bytes,
|
|
41
|
+
int size) {
|
|
42
|
+
auto *s = state;
|
|
43
|
+
if (!s || !s->open.load(std::memory_order_acquire) || !info ||
|
|
44
|
+
!info->src_addr || !bytes || size <= 0 || size > 1470)
|
|
45
|
+
return;
|
|
46
|
+
const unsigned w = s->write.load(std::memory_order_relaxed);
|
|
47
|
+
if (w - s->read.load(std::memory_order_acquire) >= kQueue) {
|
|
48
|
+
++s->dropped;
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
auto &p = s->rx[w % kQueue];
|
|
52
|
+
std::memcpy(p.source.data(), info->src_addr, 6);
|
|
53
|
+
std::memcpy(p.bytes.data(), bytes, size);
|
|
54
|
+
p.size = size;
|
|
55
|
+
p.receivedUs = esp_timer_get_time();
|
|
56
|
+
p.rssi = info->rx_ctrl ? info->rx_ctrl->rssi : 0;
|
|
57
|
+
p.radioTimestampUs = info->rx_ctrl ? info->rx_ctrl->timestamp : 0;
|
|
58
|
+
p.radioTimestampValid = info->rx_ctrl != nullptr;
|
|
59
|
+
s->write.store(w + 1, std::memory_order_release);
|
|
60
|
+
++s->received;
|
|
61
|
+
xSemaphoreGive(s->event);
|
|
62
|
+
}
|
|
63
|
+
#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 5, 0)
|
|
64
|
+
void sent(const esp_now_send_info_t *info, esp_now_send_status_t status) {
|
|
65
|
+
#else
|
|
66
|
+
void sent(const std::uint8_t *, esp_now_send_status_t status) {
|
|
67
|
+
#endif
|
|
68
|
+
auto *s = state;
|
|
69
|
+
if (!s)
|
|
70
|
+
return;
|
|
71
|
+
const auto completed = esp_timer_get_time();
|
|
72
|
+
const auto elapsed = static_cast<unsigned>(completed - s->sentAt);
|
|
73
|
+
if (elapsed > s->maxSend.load())
|
|
74
|
+
s->maxSend.store(elapsed);
|
|
75
|
+
if (status == ESP_NOW_SEND_SUCCESS)
|
|
76
|
+
++s->sent;
|
|
77
|
+
else
|
|
78
|
+
++s->failed;
|
|
79
|
+
s->completedStart.store(s->sentAt, std::memory_order_relaxed);
|
|
80
|
+
s->completedAt.store(completed, std::memory_order_relaxed);
|
|
81
|
+
#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 5, 0)
|
|
82
|
+
s->completedRate.store(info ? static_cast<unsigned>(info->rate) : 0,
|
|
83
|
+
std::memory_order_relaxed);
|
|
84
|
+
#endif
|
|
85
|
+
gea::targets::esp32::espnow::TxMacHeader mac{};
|
|
86
|
+
#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 5, 0)
|
|
87
|
+
if (s->captureTxHeader.load(std::memory_order_acquire))
|
|
88
|
+
mac = gea::targets::esp32::espnow::callbackTxMacHeader(info);
|
|
89
|
+
#endif
|
|
90
|
+
s->completedMacControl.store(mac.control, std::memory_order_relaxed);
|
|
91
|
+
s->completedMacSequence.store(mac.sequence, std::memory_order_relaxed);
|
|
92
|
+
s->completedStatus.store(static_cast<unsigned>(status),
|
|
93
|
+
std::memory_order_relaxed);
|
|
94
|
+
// The sole sender's canSend acquire observes this complete metadata before
|
|
95
|
+
// it admits another datagram. Other statistics readers remain data-race free.
|
|
96
|
+
s->busy.store(false, std::memory_order_release);
|
|
97
|
+
xSemaphoreGive(s->event);
|
|
98
|
+
}
|
|
99
|
+
bool configure_rate(const std::uint8_t *mac) {
|
|
100
|
+
return gea::targets::esp32::espnow::configureRate(mac, state->rate);
|
|
101
|
+
}
|
|
102
|
+
} // namespace
|
|
103
|
+
extern "C" bool gea_espnow_open(int channel, int rate) {
|
|
104
|
+
esp_now_rate_config_t requested{};
|
|
105
|
+
if (channel < 0 || channel > 13 ||
|
|
106
|
+
!gea::targets::esp32::espnow::rateConfig(rate, requested))
|
|
107
|
+
return false;
|
|
108
|
+
if (state && state->open.load())
|
|
109
|
+
return state->channel == channel && state->rate == rate;
|
|
110
|
+
if (!state) {
|
|
111
|
+
auto *memory =
|
|
112
|
+
heap_caps_malloc(sizeof(State), MALLOC_CAP_SPIRAM | MALLOC_CAP_8BIT);
|
|
113
|
+
if (!memory)
|
|
114
|
+
memory = heap_caps_malloc(sizeof(State), MALLOC_CAP_8BIT);
|
|
115
|
+
if (!memory)
|
|
116
|
+
return false;
|
|
117
|
+
state = new (memory) State;
|
|
118
|
+
state->event = xSemaphoreCreateBinary();
|
|
119
|
+
if (!state->event) {
|
|
120
|
+
state->~State();
|
|
121
|
+
heap_caps_free(state);
|
|
122
|
+
state = nullptr;
|
|
123
|
+
return false;
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
auto *s = state;
|
|
127
|
+
s->rate = rate;
|
|
128
|
+
s->channel = channel;
|
|
129
|
+
wifi_mode_t mode{};
|
|
130
|
+
const bool existing = esp_wifi_get_mode(&mode) == ESP_OK;
|
|
131
|
+
if (existing && channel != 0)
|
|
132
|
+
return false; // Do not commandeer an AP/station owner.
|
|
133
|
+
if (!existing) {
|
|
134
|
+
if (!channel)
|
|
135
|
+
return false;
|
|
136
|
+
const auto loop = esp_event_loop_create_default();
|
|
137
|
+
if (loop != ESP_OK && loop != ESP_ERR_INVALID_STATE)
|
|
138
|
+
return false;
|
|
139
|
+
wifi_init_config_t config = WIFI_INIT_CONFIG_DEFAULT();
|
|
140
|
+
config.wifi_task_core_id = 0;
|
|
141
|
+
gea::targets::esp32::wifi::applyTaskStackOverride(&config);
|
|
142
|
+
if (esp_wifi_init(&config) != ESP_OK)
|
|
143
|
+
return false;
|
|
144
|
+
s->ownsRadio = true;
|
|
145
|
+
if (esp_wifi_set_storage(WIFI_STORAGE_RAM) != ESP_OK ||
|
|
146
|
+
esp_wifi_set_mode(WIFI_MODE_STA) != ESP_OK ||
|
|
147
|
+
esp_wifi_start() != ESP_OK ||
|
|
148
|
+
esp_wifi_set_channel(channel, WIFI_SECOND_CHAN_NONE) != ESP_OK) {
|
|
149
|
+
gea_espnow_close();
|
|
150
|
+
return false;
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
if (!gea::targets::esp32::espnow::rateProtocolReady(rate)) {
|
|
154
|
+
if (s->ownsRadio)
|
|
155
|
+
gea_espnow_close();
|
|
156
|
+
return false;
|
|
157
|
+
}
|
|
158
|
+
esp_wifi_get_ps(&s->previousPs);
|
|
159
|
+
if (esp_wifi_set_ps(WIFI_PS_NONE) != ESP_OK || esp_now_init() != ESP_OK) {
|
|
160
|
+
gea_espnow_close();
|
|
161
|
+
return false;
|
|
162
|
+
}
|
|
163
|
+
std::uint32_t version = 0;
|
|
164
|
+
if (esp_now_get_version(&version) != ESP_OK || version < 2 ||
|
|
165
|
+
esp_now_register_recv_cb(received) != ESP_OK ||
|
|
166
|
+
esp_now_register_send_cb(sent) != ESP_OK) {
|
|
167
|
+
gea_espnow_close();
|
|
168
|
+
return false;
|
|
169
|
+
}
|
|
170
|
+
s->read.store(0);
|
|
171
|
+
s->write.store(0);
|
|
172
|
+
s->busy.store(false);
|
|
173
|
+
s->sent.store(0);
|
|
174
|
+
s->failed.store(0);
|
|
175
|
+
s->received.store(0);
|
|
176
|
+
s->dropped.store(0);
|
|
177
|
+
s->maxSend.store(0);
|
|
178
|
+
s->completedStart.store(0);
|
|
179
|
+
s->completedAt.store(0);
|
|
180
|
+
s->completedRate.store(0);
|
|
181
|
+
s->completedStatus.store(0);
|
|
182
|
+
s->completedMacControl.store(0);
|
|
183
|
+
s->completedMacSequence.store(0);
|
|
184
|
+
s->captureTxHeader.store(false);
|
|
185
|
+
s->open.store(true, std::memory_order_release);
|
|
186
|
+
ESP_LOGI("espnow", "v%lu channel=%d rate=%d Mbps RX capacity=%u",
|
|
187
|
+
(unsigned long)version, channel, rate, kQueue);
|
|
188
|
+
return true;
|
|
189
|
+
}
|
|
190
|
+
extern "C" void gea_espnow_close() {
|
|
191
|
+
auto *s = state;
|
|
192
|
+
if (!s)
|
|
193
|
+
return;
|
|
194
|
+
s->captureTxHeader.store(false, std::memory_order_release);
|
|
195
|
+
s->open.store(false, std::memory_order_release);
|
|
196
|
+
esp_now_unregister_recv_cb();
|
|
197
|
+
esp_now_unregister_send_cb();
|
|
198
|
+
esp_now_deinit();
|
|
199
|
+
// Keep the bounded storage for subsequent opens. A callback already running
|
|
200
|
+
// on another core cannot encounter freed memory.
|
|
201
|
+
if (s->ownsRadio) {
|
|
202
|
+
esp_wifi_stop();
|
|
203
|
+
esp_wifi_deinit();
|
|
204
|
+
s->ownsRadio = false;
|
|
205
|
+
} else
|
|
206
|
+
esp_wifi_set_ps(s->previousPs);
|
|
207
|
+
s->busy.store(false);
|
|
208
|
+
}
|
|
209
|
+
extern "C" bool gea_espnow_is_open() {
|
|
210
|
+
return state && state->open.load(std::memory_order_acquire);
|
|
211
|
+
}
|
|
212
|
+
extern "C" bool gea_espnow_can_send() {
|
|
213
|
+
return gea_espnow_is_open() && !state->busy.load(std::memory_order_acquire);
|
|
214
|
+
}
|
|
215
|
+
extern "C" bool gea_espnow_capture_tx_header(bool enabled) {
|
|
216
|
+
if (enabled && (!gea_espnow_is_open() || !state->ownsRadio))
|
|
217
|
+
return false;
|
|
218
|
+
if (state)
|
|
219
|
+
state->captureTxHeader.store(enabled, std::memory_order_release);
|
|
220
|
+
return true;
|
|
221
|
+
}
|
|
222
|
+
extern "C" bool gea_espnow_set_max_tx_power(int quarterDbm) {
|
|
223
|
+
return gea::targets::esp32::espnow::setMaxTxPower(
|
|
224
|
+
gea_espnow_is_open(), state && state->ownsRadio, quarterDbm);
|
|
225
|
+
}
|
|
226
|
+
extern "C" int gea_espnow_get_max_tx_power() {
|
|
227
|
+
return gea::targets::esp32::espnow::getMaxTxPower(gea_espnow_is_open());
|
|
228
|
+
}
|
|
229
|
+
extern "C" bool gea_espnow_peer(const std::uint8_t *mac,
|
|
230
|
+
const std::uint8_t *key) {
|
|
231
|
+
if (!gea_espnow_is_open() || !mac)
|
|
232
|
+
return false;
|
|
233
|
+
esp_now_peer_info_t peer{};
|
|
234
|
+
std::memcpy(peer.peer_addr, mac, 6);
|
|
235
|
+
peer.ifidx = WIFI_IF_STA;
|
|
236
|
+
if (key) {
|
|
237
|
+
std::memcpy(peer.lmk, key, 16);
|
|
238
|
+
peer.encrypt = true;
|
|
239
|
+
}
|
|
240
|
+
const auto result = esp_now_is_peer_exist(mac) ? esp_now_mod_peer(&peer)
|
|
241
|
+
: esp_now_add_peer(&peer);
|
|
242
|
+
return result == ESP_OK && configure_rate(mac);
|
|
243
|
+
}
|
|
244
|
+
extern "C" int gea_espnow_send(const std::uint8_t *mac, const void *bytes,
|
|
245
|
+
std::size_t size) {
|
|
246
|
+
if (!gea_espnow_is_open() || !mac || !bytes || !size || size > 1470)
|
|
247
|
+
return -1;
|
|
248
|
+
auto *s = state;
|
|
249
|
+
bool idle = false;
|
|
250
|
+
if (!s->busy.compare_exchange_strong(idle, true, std::memory_order_acq_rel))
|
|
251
|
+
return 0;
|
|
252
|
+
s->sentAt = esp_timer_get_time();
|
|
253
|
+
const auto result =
|
|
254
|
+
esp_now_send(mac, static_cast<const std::uint8_t *>(bytes), size);
|
|
255
|
+
if (result != ESP_OK) {
|
|
256
|
+
s->busy.store(false, std::memory_order_release);
|
|
257
|
+
if (result == ESP_ERR_ESPNOW_NO_MEM)
|
|
258
|
+
return 0;
|
|
259
|
+
++s->failed;
|
|
260
|
+
return -1;
|
|
261
|
+
}
|
|
262
|
+
return static_cast<int>(size);
|
|
263
|
+
}
|
|
264
|
+
extern "C" bool gea_espnow_receive(gea::platform::espnow::Datagram *packet) {
|
|
265
|
+
if (!gea_espnow_is_open() || !packet)
|
|
266
|
+
return false;
|
|
267
|
+
auto *s = state;
|
|
268
|
+
const auto r = s->read.load(std::memory_order_relaxed);
|
|
269
|
+
if (r == s->write.load(std::memory_order_acquire))
|
|
270
|
+
return false;
|
|
271
|
+
*packet = s->rx[r % kQueue];
|
|
272
|
+
s->read.store(r + 1, std::memory_order_release);
|
|
273
|
+
return true;
|
|
274
|
+
}
|
|
275
|
+
extern "C" void gea_espnow_wake() {
|
|
276
|
+
if (state)
|
|
277
|
+
xSemaphoreGive(state->event);
|
|
278
|
+
}
|
|
279
|
+
extern "C" void gea_espnow_wait(unsigned ms) {
|
|
280
|
+
if (state)
|
|
281
|
+
xSemaphoreTake(state->event, pdMS_TO_TICKS(ms));
|
|
282
|
+
}
|
|
283
|
+
extern "C" void gea_espnow_statistics(gea::platform::espnow::Statistics *out) {
|
|
284
|
+
if (!out || !state)
|
|
285
|
+
return;
|
|
286
|
+
const auto macControl = state->completedMacControl.load();
|
|
287
|
+
const auto macSequence = state->completedMacSequence.load();
|
|
288
|
+
*out = {state->sent.load(), state->failed.load(),
|
|
289
|
+
state->received.load(), state->dropped.load(),
|
|
290
|
+
state->maxSend.load(), state->completedStart.load(),
|
|
291
|
+
state->completedAt.load(), state->completedRate.load(),
|
|
292
|
+
state->completedStatus.load(),
|
|
293
|
+
static_cast<std::uint16_t>(macControl),
|
|
294
|
+
static_cast<std::uint16_t>(macControl >> 16),
|
|
295
|
+
static_cast<std::uint16_t>(macSequence),
|
|
296
|
+
(macSequence & 0x10000U) != 0};
|
|
297
|
+
}
|
|
298
|
+
#endif
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
#pragma once
|
|
2
|
+
#include "esp_wifi.h"
|
|
3
|
+
#include <cstdint>
|
|
4
|
+
|
|
5
|
+
namespace gea::targets::esp32::espnow {
|
|
6
|
+
// Radio-wide setting: a borrowed ESP-NOW session must not change its owner's
|
|
7
|
+
// Wi-Fi power. Leave the SDK default untouched until explicitly requested.
|
|
8
|
+
inline bool setMaxTxPower(bool open, bool owned, int quarterDbm) {
|
|
9
|
+
return open && owned && quarterDbm >= 8 && quarterDbm <= 84 &&
|
|
10
|
+
esp_wifi_set_max_tx_power(static_cast<std::int8_t>(quarterDbm)) ==
|
|
11
|
+
ESP_OK;
|
|
12
|
+
}
|
|
13
|
+
inline int getMaxTxPower(bool open) {
|
|
14
|
+
std::int8_t power = 0;
|
|
15
|
+
return open && esp_wifi_get_max_tx_power(&power) == ESP_OK ? power : -1;
|
|
16
|
+
}
|
|
17
|
+
} // namespace gea::targets::esp32::espnow
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
#pragma once
|
|
2
|
+
#include "esp_now.h"
|
|
3
|
+
#include "esp_wifi.h"
|
|
4
|
+
#include <cstdint>
|
|
5
|
+
|
|
6
|
+
namespace gea::targets::esp32::espnow {
|
|
7
|
+
// 115 is the integer API selector for HE20 MCS9 short GI (114.7 Mbps),
|
|
8
|
+
// supported here only by ESP32-S31. Existing selectors retain their PHY mode.
|
|
9
|
+
inline bool rateConfig(int selector, esp_now_rate_config_t &out) {
|
|
10
|
+
esp_now_rate_config_t rate{};
|
|
11
|
+
rate.phymode = WIFI_PHY_MODE_11G;
|
|
12
|
+
switch (selector) {
|
|
13
|
+
case 24:
|
|
14
|
+
rate.rate = WIFI_PHY_RATE_24M;
|
|
15
|
+
break;
|
|
16
|
+
case 36:
|
|
17
|
+
rate.rate = WIFI_PHY_RATE_36M;
|
|
18
|
+
break;
|
|
19
|
+
case 54:
|
|
20
|
+
rate.rate = WIFI_PHY_RATE_54M;
|
|
21
|
+
break;
|
|
22
|
+
case 65:
|
|
23
|
+
rate.phymode = WIFI_PHY_MODE_HT20;
|
|
24
|
+
rate.rate = WIFI_PHY_RATE_MCS7_LGI;
|
|
25
|
+
break;
|
|
26
|
+
#if CONFIG_IDF_TARGET_ESP32S31 && CONFIG_SOC_WIFI_HE_SUPPORT
|
|
27
|
+
case 115:
|
|
28
|
+
rate.phymode = WIFI_PHY_MODE_HE20;
|
|
29
|
+
rate.rate = WIFI_PHY_RATE_MCS9_SGI;
|
|
30
|
+
break;
|
|
31
|
+
#endif
|
|
32
|
+
default:
|
|
33
|
+
return false;
|
|
34
|
+
}
|
|
35
|
+
out = rate;
|
|
36
|
+
return true;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
// Never change a borrowed radio's interface protocols. The owned S31 default
|
|
40
|
+
// includes 11AX; fail closed if the current owner has disabled that capability.
|
|
41
|
+
inline bool rateProtocolReady(int selector) {
|
|
42
|
+
if (selector != 115)
|
|
43
|
+
return true;
|
|
44
|
+
#if CONFIG_IDF_TARGET_ESP32S31 && CONFIG_SOC_WIFI_HE_SUPPORT
|
|
45
|
+
std::uint8_t protocols = 0;
|
|
46
|
+
return esp_wifi_get_protocol(WIFI_IF_STA, &protocols) == ESP_OK &&
|
|
47
|
+
(protocols & WIFI_PROTOCOL_11AX) != 0;
|
|
48
|
+
#else
|
|
49
|
+
return false;
|
|
50
|
+
#endif
|
|
51
|
+
}
|
|
52
|
+
inline bool configureRate(const std::uint8_t *mac, int selector) {
|
|
53
|
+
esp_now_rate_config_t rate{};
|
|
54
|
+
return rateConfig(selector, rate) && rateProtocolReady(selector) &&
|
|
55
|
+
esp_now_set_peer_rate_config(mac, &rate) == ESP_OK;
|
|
56
|
+
}
|
|
57
|
+
} // namespace gea::targets::esp32::espnow
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
#pragma once
|
|
2
|
+
#include <cstddef>
|
|
3
|
+
#include <cstdint>
|
|
4
|
+
#include <cstring>
|
|
5
|
+
|
|
6
|
+
namespace gea::targets::esp32::espnow {
|
|
7
|
+
struct TxMacHeader {
|
|
8
|
+
std::uint32_t control = 0; // Frame Control low16, Duration high16.
|
|
9
|
+
std::uint32_t sequence = 0; // Sequence Control low16, valid bit16.
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
inline TxMacHeader actionTxMacHeader(const std::uint8_t *bytes,
|
|
13
|
+
std::size_t headerBytes,
|
|
14
|
+
const std::uint8_t *source,
|
|
15
|
+
const std::uint8_t *destination) noexcept {
|
|
16
|
+
if (!bytes || headerBytes < 24 || !source || !destination)
|
|
17
|
+
return {};
|
|
18
|
+
const auto read16 = [&](unsigned at) {
|
|
19
|
+
return std::uint16_t(bytes[at]) | (std::uint16_t(bytes[at + 1]) << 8);
|
|
20
|
+
};
|
|
21
|
+
const auto control = read16(0);
|
|
22
|
+
// Version zero, management Action, neither ToDS nor FromDS. Remaining
|
|
23
|
+
// flags (including Retry and Protected) are retained without interpretation.
|
|
24
|
+
if ((control & 0x03ffU) != 0x00d0U ||
|
|
25
|
+
std::memcmp(bytes + 4, destination, 6) ||
|
|
26
|
+
std::memcmp(bytes + 10, source, 6))
|
|
27
|
+
return {};
|
|
28
|
+
return {std::uint32_t(control) | (std::uint32_t(read16(2)) << 16),
|
|
29
|
+
std::uint32_t(read16(22)) | 0x10000U};
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
template <class Info>
|
|
33
|
+
inline auto callbackTxMacHeader(const Info *info) noexcept
|
|
34
|
+
-> decltype(info->data, info->src_addr, info->des_addr, TxMacHeader{}) {
|
|
35
|
+
if (!info || !info->data)
|
|
36
|
+
return {};
|
|
37
|
+
// IDF promises data starts at the MAC header. Its data_len is an 8-bit
|
|
38
|
+
// BODY length excluding that header, not an available-buffer length. It
|
|
39
|
+
// cannot bound the complete ESP-NOW v2 frame (up to1470 payload bytes).
|
|
40
|
+
// Read only the fixed24-byte header in this callback; never retain pointers,
|
|
41
|
+
// read the body, mutate SDK memory, or infer retries from a zero Retry bit.
|
|
42
|
+
return actionTxMacHeader(info->data, 24, info->src_addr, info->des_addr);
|
|
43
|
+
}
|
|
44
|
+
// Older public SDK callback shapes do not expose the MAC header.
|
|
45
|
+
inline TxMacHeader callbackTxMacHeader(...) noexcept { return {}; }
|
|
46
|
+
} // namespace gea::targets::esp32::espnow
|
|
@@ -249,6 +249,7 @@ list(APPEND GEA_FW_CXX_SOURCES
|
|
|
249
249
|
"${GEA_HOST}/host/gpio.cpp"
|
|
250
250
|
"${GEA_EMBEDDED_ROOT}/targets/esp32/gpio.cpp"
|
|
251
251
|
"${GEA_EMBEDDED_ROOT}/targets/esp32/uart.cpp"
|
|
252
|
+
"${GEA_EMBEDDED_ROOT}/targets/esp32/esp_now.cpp"
|
|
252
253
|
)
|
|
253
254
|
|
|
254
255
|
function(gea_framework_compile_definitions)
|
|
@@ -16,6 +16,9 @@
|
|
|
16
16
|
entries:
|
|
17
17
|
bss -> extern_ram
|
|
18
18
|
common -> extern_ram
|
|
19
|
+
# IDF groups RISC-V .sbss/.scommon and link-once BSS here. Reuse that
|
|
20
|
+
# group so ldgen excludes these owners from its default DRAM catch-all.
|
|
21
|
+
legacy_bss -> extern_ram
|
|
19
22
|
|
|
20
23
|
# The shared framework component: the engine's caches and task-only tables.
|
|
21
24
|
[mapping:gea_ui_state_external_framework]
|
|
@@ -33,3 +36,11 @@ entries:
|
|
|
33
36
|
runtime (gea_ui_state_external)
|
|
34
37
|
display (gea_ui_state_external)
|
|
35
38
|
tree_render (gea_ui_state_external)
|
|
39
|
+
|
|
40
|
+
# The compiler archive holds the application's JS/TS globals, closures and
|
|
41
|
+
# runtime tables. They share the UI event-loop lifetime and run with caches on.
|
|
42
|
+
# Native board/ISR/DMA sources live in other archives and are not included.
|
|
43
|
+
[mapping:gea_ui_state_external_app]
|
|
44
|
+
archive: libgea_active_geatsc.a
|
|
45
|
+
entries:
|
|
46
|
+
* (gea_ui_state_external)
|
|
@@ -1475,9 +1475,16 @@ void handlePush(char *args)
|
|
|
1475
1475
|
// console -- the ESP32-S31's OTG port -- is flashed without the BOOT button.
|
|
1476
1476
|
// Compiled only for boards that ask for it (GEA_DEVICE_CONTROL_USB_OTA).
|
|
1477
1477
|
#if GEA_DEVICE_CONTROL_USB_OTA
|
|
1478
|
+
// How long a transfer waits for its next byte before giving up. The host streams
|
|
1479
|
+
// continuously once READY is out, so a silence this long means it is gone
|
|
1480
|
+
// (killed, unplugged). Keep it short: until the receive loop gives up, every
|
|
1481
|
+
// byte the next host sends -- its PING, its own OTA line -- is swallowed as
|
|
1482
|
+
// payload of the dead transfer.
|
|
1483
|
+
constexpr std::int64_t kOtaIdleTimeoutUs = 3000000;
|
|
1484
|
+
|
|
1478
1485
|
// The fallback when the image cannot be staged: a firmware that runs from
|
|
1479
1486
|
// PSRAM (XIP) of about its own size leaves no room for the next image, so
|
|
1480
|
-
//
|
|
1487
|
+
// a large game could only be updated from a smaller app. Each 64 KB read goes
|
|
1481
1488
|
// straight to flash, erased sector by sector as it is written: a whole-slot
|
|
1482
1489
|
// erase up front would hold READY past the host's 15 s wait. stdin reads the TinyUSB CDC FIFO, which leaves
|
|
1483
1490
|
// the OUT endpoint un-armed while it is full, so the host waits out a write
|
|
@@ -1503,19 +1510,21 @@ static void handleOtaStreamed(const esp_partition_t *slot, long size, std::uint3
|
|
|
1503
1510
|
|
|
1504
1511
|
std::uint32_t crc = 0xFFFFFFFFu;
|
|
1505
1512
|
long got = 0;
|
|
1506
|
-
|
|
1513
|
+
std::int64_t lastByteAt = esp_timer_get_time();
|
|
1507
1514
|
while (got < size && err == ESP_OK) {
|
|
1508
1515
|
const std::size_t want = std::min(kChunk, static_cast<std::size_t>(size - got));
|
|
1509
1516
|
std::size_t filled = 0;
|
|
1517
|
+
// The flash write below holds the read for a while; that is not host silence.
|
|
1518
|
+
lastByteAt = esp_timer_get_time();
|
|
1510
1519
|
while (filled < want) {
|
|
1511
1520
|
const std::size_t n = std::fread(buffer + filled, 1, want - filled, stdin);
|
|
1512
1521
|
if (n == 0) {
|
|
1513
1522
|
std::clearerr(stdin);
|
|
1514
|
-
if (
|
|
1523
|
+
if (esp_timer_get_time() - lastByteAt > kOtaIdleTimeoutUs) break;
|
|
1515
1524
|
vTaskDelay(pdMS_TO_TICKS(2));
|
|
1516
1525
|
continue;
|
|
1517
1526
|
}
|
|
1518
|
-
|
|
1527
|
+
lastByteAt = esp_timer_get_time();
|
|
1519
1528
|
filled += n;
|
|
1520
1529
|
}
|
|
1521
1530
|
if (filled < want) break;
|
|
@@ -1528,7 +1537,7 @@ static void handleOtaStreamed(const esp_partition_t *slot, long size, std::uint3
|
|
|
1528
1537
|
if (got != size || err != ESP_OK) {
|
|
1529
1538
|
esp_ota_abort(handle);
|
|
1530
1539
|
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);
|
|
1540
|
+
else std::printf("GEADEV:OTA ERR transfer-failed got=%ld want=%ld\n", got, size);
|
|
1532
1541
|
return;
|
|
1533
1542
|
}
|
|
1534
1543
|
if (crc != expectCrc) {
|
|
@@ -1575,7 +1584,7 @@ void handleOta(char *args)
|
|
|
1575
1584
|
}
|
|
1576
1585
|
// Staged in 1 MB pieces, not one image-sized block: a board that runs its
|
|
1577
1586
|
// firmware from PSRAM (XIP) never has a free block as large as its own
|
|
1578
|
-
// image -- an 8 MB
|
|
1587
|
+
// image -- an 8 MB game image met a 6.8 MB largest block on a fresh boot.
|
|
1579
1588
|
constexpr std::size_t kStage = 1024 * 1024;
|
|
1580
1589
|
const std::size_t pieces = (static_cast<std::size_t>(size) + kStage - 1) / kStage;
|
|
1581
1590
|
std::vector<std::uint8_t *> stage(pieces, nullptr);
|
|
@@ -1595,7 +1604,7 @@ void handleOta(char *args)
|
|
|
1595
1604
|
std::fflush(stdout);
|
|
1596
1605
|
|
|
1597
1606
|
long got = 0;
|
|
1598
|
-
|
|
1607
|
+
std::int64_t lastByteAt = esp_timer_get_time();
|
|
1599
1608
|
while (got < size) {
|
|
1600
1609
|
const std::size_t piece = static_cast<std::size_t>(got) / kStage;
|
|
1601
1610
|
const std::size_t at = static_cast<std::size_t>(got) % kStage;
|
|
@@ -1603,16 +1612,19 @@ void handleOta(char *args)
|
|
|
1603
1612
|
const std::size_t n = std::fread(stage[piece] + at, 1, want, stdin);
|
|
1604
1613
|
if (n == 0) {
|
|
1605
1614
|
std::clearerr(stdin); // an idle read sets the sticky EOF flag
|
|
1606
|
-
if (
|
|
1615
|
+
if (esp_timer_get_time() - lastByteAt > kOtaIdleTimeoutUs) break;
|
|
1607
1616
|
vTaskDelay(pdMS_TO_TICKS(2));
|
|
1608
1617
|
continue;
|
|
1609
1618
|
}
|
|
1610
|
-
|
|
1619
|
+
lastByteAt = esp_timer_get_time();
|
|
1611
1620
|
got += static_cast<long>(n);
|
|
1612
1621
|
}
|
|
1613
1622
|
if (got != size) {
|
|
1614
1623
|
freeStage();
|
|
1615
|
-
|
|
1624
|
+
// want= tags the line with this transfer: a host that opens the port
|
|
1625
|
+
// later can be handed it from the TX FIFO, and must not take it for
|
|
1626
|
+
// the reply to its own OTA.
|
|
1627
|
+
std::printf("GEADEV:OTA ERR transfer-failed got=%ld want=%ld\n", got, size);
|
|
1616
1628
|
return;
|
|
1617
1629
|
}
|
|
1618
1630
|
std::uint32_t crc = 0xFFFFFFFFu;
|
|
@@ -2343,7 +2355,13 @@ void handleCommand(char *line, CommandSource source)
|
|
|
2343
2355
|
const char *appId = gea::framework::apps::AppManager::currentId();
|
|
2344
2356
|
const std::string ip = gea::framework::network::wifi().ip();
|
|
2345
2357
|
const std::string mac = gea::framework::network::wifi().mac();
|
|
2346
|
-
|
|
2358
|
+
// `GEADEV PING <nonce>` echoes the nonce, so a host resynchronising the
|
|
2359
|
+
// console can tell this reply from one queued before it opened the port.
|
|
2360
|
+
const char *nonce = nextToken(cursor);
|
|
2361
|
+
if (nonce && std::strlen(nonce) <= 32)
|
|
2362
|
+
std::printf("GEADEV:PONG app=%s ip=%s mac=%s nonce=%s\n", appId ? appId : "", ip.c_str(), mac.c_str(), nonce);
|
|
2363
|
+
else
|
|
2364
|
+
std::printf("GEADEV:PONG app=%s ip=%s mac=%s\n", appId ? appId : "", ip.c_str(), mac.c_str());
|
|
2347
2365
|
} else if (tokenEquals(command, "NETDIAG")) {
|
|
2348
2366
|
printNetworkDiagnostics();
|
|
2349
2367
|
} else if (tokenEquals(command, "IPCSTACK")) {
|
|
@@ -11,6 +11,7 @@
|
|
|
11
11
|
#include "host/worker.h"
|
|
12
12
|
#include "ui/refresh_trace.h"
|
|
13
13
|
#include "ui/refresh_perf.h"
|
|
14
|
+
#include "ui/state_init.h"
|
|
14
15
|
#include "ui/document.h"
|
|
15
16
|
#include "memory_config.h"
|
|
16
17
|
#include "services/comparison_benchmark.h"
|
|
@@ -1121,7 +1122,13 @@ private:
|
|
|
1121
1122
|
}
|
|
1122
1123
|
};
|
|
1123
1124
|
|
|
1125
|
+
#if GEA_EMBEDDED_UI_STATE_DYNAMIC_INIT
|
|
1126
|
+
// Keep the singleton relocatable without changing its member initializers.
|
|
1127
|
+
// Its TCB and queue still require internal memory; this does not opt it into PSRAM.
|
|
1128
|
+
__attribute__((noinline)) FrameSchedulerEngine() {}
|
|
1129
|
+
#else
|
|
1124
1130
|
FrameSchedulerEngine() = default;
|
|
1131
|
+
#endif
|
|
1125
1132
|
|
|
1126
1133
|
static const char *stageName(FrameStage stage)
|
|
1127
1134
|
{
|
package/targets/esp32/uart.cpp
CHANGED
|
@@ -70,10 +70,16 @@ extern "C" bool gea_uart_open(int port, int tx, int rx, int baud, int rxBytes,
|
|
|
70
70
|
config.flow_ctrl = UART_HW_FLOWCTRL_DISABLE;
|
|
71
71
|
config.source_clk = UART_SCLK_DEFAULT;
|
|
72
72
|
// Allocate before routing pins: a failed allocation cannot disturb the
|
|
73
|
-
//
|
|
73
|
+
// pins.
|
|
74
74
|
if (uart_driver_install(uart, rxBytes, txBytes, 0, nullptr, 0) != ESP_OK)
|
|
75
75
|
return false;
|
|
76
|
+
// IDF's matrix RX route enables input but deliberately preserves output
|
|
77
|
+
// (it also supports shared TX/RX pads). Gea requires distinct pins, so clear
|
|
78
|
+
// stale routes first, including a previous firmware's TX on our new RX pad.
|
|
79
|
+
// Software restart can leave the pad configured after driver state is lost.
|
|
76
80
|
if (uart_param_config(uart, &config) != ESP_OK ||
|
|
81
|
+
gpio_reset_pin(static_cast<gpio_num_t>(tx)) != ESP_OK ||
|
|
82
|
+
gpio_reset_pin(static_cast<gpio_num_t>(rx)) != ESP_OK ||
|
|
77
83
|
uart_set_pin(uart, tx, rx, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE) !=
|
|
78
84
|
ESP_OK ||
|
|
79
85
|
uart_set_rx_full_threshold(uart, 96) != ESP_OK ||
|
|
@@ -1,9 +1,12 @@
|
|
|
1
|
+
# Registry versions are pinned to the ones dependencies.lock records. The build
|
|
2
|
+
# solves into its build directory (esp32/app_project.cmake), so a range would let
|
|
3
|
+
# a re-solve for another app's capabilities move them.
|
|
1
4
|
dependencies:
|
|
2
5
|
# PCM <-> Opus at the WebRTC media-track boundary.
|
|
3
6
|
78/esp-opus: '^1.0.5'
|
|
4
|
-
espressif/esp_lcd_touch_gt911: '
|
|
5
|
-
espressif/esp_codec_dev: '
|
|
6
|
-
espressif/esp_websocket_client: '
|
|
7
|
-
espressif/esp_peer: '
|
|
7
|
+
espressif/esp_lcd_touch_gt911: '==1.2.0~2'
|
|
8
|
+
espressif/esp_codec_dev: '==1.5.11'
|
|
9
|
+
espressif/esp_websocket_client: '==1.7.0'
|
|
10
|
+
espressif/esp_peer: '==1.5.0'
|
|
8
11
|
idf:
|
|
9
12
|
version: '>=5.3'
|
|
@@ -332,6 +332,8 @@ idf_component_register(
|
|
|
332
332
|
"${GEA_EMBEDDED_ROOT}/targets/esp32/services/frame_scheduler.cpp"
|
|
333
333
|
"${GEA_EMBEDDED_ROOT}/targets/esp32/services/memory.cpp"
|
|
334
334
|
"${GEA_EMBEDDED_ROOT}/targets/esp32/services/ota.cpp"
|
|
335
|
+
# ota.cpp stages the image through ota_image.cpp (and its debug hooks).
|
|
336
|
+
"${GEA_EMBEDDED_ROOT}/targets/esp32/services/ota_image.cpp"
|
|
335
337
|
"${GEA_EMBEDDED_ROOT}/targets/esp32/services/storage_service.cpp"
|
|
336
338
|
"${GEA_EMBEDDED_ROOT}/targets/esp32/services/heap.cpp"
|
|
337
339
|
${APP_GENERATED_SOURCES}
|
|
@@ -353,6 +355,8 @@ idf_component_register(
|
|
|
353
355
|
esp_http_client
|
|
354
356
|
${GEA_EMBEDDED_HTTPS_REQUIRES}
|
|
355
357
|
app_update
|
|
358
|
+
# esp32/services/ota.cpp reads the flash through esp_flash.h.
|
|
359
|
+
spi_flash
|
|
356
360
|
esp_mm
|
|
357
361
|
esp_netif
|
|
358
362
|
esp_event
|