@mikrojs/native 0.21.1-next.20260928214050 → 0.23.0
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/CMakeLists.txt +21 -0
- package/dist/runtime/result/native-result.node-shim.d.ts +2 -0
- package/dist/runtime/result/native-result.node-shim.d.ts.map +1 -1
- package/dist/runtime/result/native-result.node-shim.js +57 -0
- package/dist/runtime/result/native-result.node-shim.js.map +1 -1
- package/dist/runtime/result/types.d.ts +33 -0
- package/dist/runtime/result/types.d.ts.map +1 -1
- package/include/mikrojs/app_store.h +16 -0
- package/include/mikrojs/ble_port.h +50 -0
- package/include/mikrojs/build_install.h +36 -0
- package/include/mikrojs/device_store.h +84 -0
- package/include/mikrojs/http_native.h +52 -0
- package/include/mikrojs/mikrojs.h +19 -9
- package/include/mikrojs/ota.h +75 -0
- package/include/mikrojs/ota_env.h +1 -1
- package/include/mikrojs/platform.h +35 -0
- package/include/mikrojs/private.h +13 -3
- package/include/mikrojs/utils.h +17 -7
- package/package.json +4 -4
- package/prebuilds/darwin-arm64/mikrojs.napi.node +0 -0
- package/prebuilds/linux-arm64/mikrojs.napi.node +0 -0
- package/prebuilds/linux-x64/mikrojs.napi.node +0 -0
- package/runtime/http/server-impl.ts +5 -60
- package/runtime/http/server.ts +0 -1
- package/runtime/internal.d.ts +2 -0
- package/runtime/modules.json +1 -1
- package/runtime/result/native-result.node-shim.ts +60 -0
- package/runtime/result/result.ts +1 -1
- package/runtime/result/types.ts +61 -0
- package/runtime/sys/sys.ts +1 -2
- package/runtime/sys/types.ts +5 -2
- package/src/mik_app_store.cpp +32 -0
- package/src/mik_ble.cpp +1573 -0
- package/src/mik_build_install.cpp +785 -0
- package/src/mik_config.cpp +330 -0
- package/src/mik_console.cpp +15 -24
- package/src/mik_deploy.cpp +759 -0
- package/src/mik_ota.cpp +1403 -0
- package/src/mik_ota_client_module.cpp +1142 -0
- package/src/mik_ota_env.cpp +318 -0
- package/src/mik_repl.cpp +15 -6
- package/src/mik_result.cpp +159 -0
- package/src/mik_sys.cpp +57 -52
- package/src/mik_test.cpp +1334 -0
- package/src/mik_test_supervisor.cpp +151 -0
- package/src/mik_udp.cpp +4 -1
- package/src/mik_watchdog.cpp +4 -5
- package/src/mik_wifi_client.cpp +1 -2
- package/src/mikrojs.cpp +15 -6
- package/src/modules.cpp +2 -1
- package/src/utils.cpp +1 -2
- package/runtime/test/test.ts +0 -686
package/src/mik_sys.cpp
CHANGED
|
@@ -4,11 +4,6 @@
|
|
|
4
4
|
|
|
5
5
|
#ifdef CONFIG_IDF_TARGET
|
|
6
6
|
#include <esp_app_desc.h>
|
|
7
|
-
#include <esp_chip_info.h>
|
|
8
|
-
#include <esp_flash.h>
|
|
9
|
-
#ifdef CONFIG_SPIRAM
|
|
10
|
-
#include <esp_psram.h>
|
|
11
|
-
#endif
|
|
12
7
|
#endif
|
|
13
8
|
|
|
14
9
|
#include "mikrojs/platform.h"
|
|
@@ -171,7 +166,7 @@ static JSValue mik__sys_restart(JSContext* ctx, JSValue this_val, int argc, JSVa
|
|
|
171
166
|
return JS_UNDEFINED;
|
|
172
167
|
}
|
|
173
168
|
|
|
174
|
-
const char*
|
|
169
|
+
const char* mik__firmware_name(void) {
|
|
175
170
|
#ifdef MIK_BOARD_NAME
|
|
176
171
|
return MIK_BOARD_NAME;
|
|
177
172
|
#elif defined(CONFIG_IDF_TARGET)
|
|
@@ -181,59 +176,55 @@ const char* mik__board_name(void) {
|
|
|
181
176
|
#endif
|
|
182
177
|
}
|
|
183
178
|
|
|
179
|
+
#ifdef CONFIG_IDF_TARGET
|
|
180
|
+
/* The board name `mikro flash` writes into a copy of the image when it flashes
|
|
181
|
+
* the generic firmware for a board (packages/mikro/src/cli/lib/boardName.ts).
|
|
182
|
+
* ESP-IDF places .rodata_custom_desc right after esp_app_desc_t, at image
|
|
183
|
+
* offset 0x120. Empty in the built image. */
|
|
184
|
+
struct MIKBoardDesc {
|
|
185
|
+
uint32_t magic;
|
|
186
|
+
char board[64];
|
|
187
|
+
};
|
|
188
|
+
static const MIKBoardDesc s_board_desc
|
|
189
|
+
__attribute__((section(".rodata_custom_desc"), used)) = {0x424b494d /* "MIKB" */, {}};
|
|
190
|
+
|
|
191
|
+
/* Copied through volatile reads: the compiler knows the empty initializer and
|
|
192
|
+
* would otherwise fold every read of it. */
|
|
193
|
+
static const char* mik__patched_board_name(void) {
|
|
194
|
+
static char name[sizeof(s_board_desc.board)];
|
|
195
|
+
const volatile char* src = s_board_desc.board;
|
|
196
|
+
for (size_t i = 0; i + 1 < sizeof(name) && src[i] != '\0'; i++) name[i] = src[i];
|
|
197
|
+
return name;
|
|
198
|
+
}
|
|
199
|
+
#endif
|
|
200
|
+
|
|
201
|
+
const char* mik__board_name(void) {
|
|
202
|
+
#ifdef CONFIG_IDF_TARGET
|
|
203
|
+
static const char* patched = mik__patched_board_name();
|
|
204
|
+
if (patched[0] != '\0') return patched;
|
|
205
|
+
#endif
|
|
206
|
+
return mik__firmware_name();
|
|
207
|
+
}
|
|
208
|
+
|
|
184
209
|
static JSValue mik__sys_board(JSContext* ctx) {
|
|
185
210
|
JSValue obj = JS_NewObject(ctx);
|
|
186
211
|
JS_SetPropertyStr(ctx, obj, "name", JS_NewString(ctx, mik__board_name()));
|
|
187
212
|
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
esp_chip_info_t chip_info;
|
|
192
|
-
esp_chip_info(&chip_info);
|
|
193
|
-
JS_SetPropertyStr(ctx, obj, "cores", JS_NewInt32(ctx, chip_info.cores));
|
|
194
|
-
JS_SetPropertyStr(ctx, obj, "revision", JS_NewInt32(ctx, chip_info.revision));
|
|
213
|
+
const MIKPlatform* platform = MIK_GetPlatform();
|
|
214
|
+
const char* chip = platform->get_chip_name ? platform->get_chip_name() : nullptr;
|
|
215
|
+
JS_SetPropertyStr(ctx, obj, "chip", JS_NewString(ctx, chip ? chip : "host"));
|
|
195
216
|
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
217
|
+
MIKChipInfo info = {.cores = 1};
|
|
218
|
+
if (platform->get_chip_info) platform->get_chip_info(&info);
|
|
219
|
+
JS_SetPropertyStr(ctx, obj, "cores", JS_NewInt32(ctx, info.cores));
|
|
220
|
+
JS_SetPropertyStr(ctx, obj, "revision", JS_NewInt32(ctx, info.revision));
|
|
199
221
|
JSValue features = JS_NewArray(ctx);
|
|
200
|
-
uint32_t
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
JS_SetPropertyUint32(ctx, features, fi++, JS_NewString(ctx, "wifi"));
|
|
204
|
-
#endif
|
|
205
|
-
#ifdef CONFIG_BT_ENABLED
|
|
206
|
-
if (chip_info.features & CHIP_FEATURE_BLE)
|
|
207
|
-
JS_SetPropertyUint32(ctx, features, fi++, JS_NewString(ctx, "ble"));
|
|
208
|
-
if (chip_info.features & CHIP_FEATURE_BT)
|
|
209
|
-
JS_SetPropertyUint32(ctx, features, fi++, JS_NewString(ctx, "bt"));
|
|
210
|
-
#endif
|
|
211
|
-
/* No stack to gate on: mikrojs has no 802.15.4 API, so this stays a
|
|
212
|
-
* plain silicon report. */
|
|
213
|
-
if (chip_info.features & CHIP_FEATURE_IEEE802154)
|
|
214
|
-
JS_SetPropertyUint32(ctx, features, fi++, JS_NewString(ctx, "ieee802154"));
|
|
222
|
+
for (uint32_t i = 0; info.features && info.features[i]; i++) {
|
|
223
|
+
JS_SetPropertyUint32(ctx, features, i, JS_NewString(ctx, info.features[i]));
|
|
224
|
+
}
|
|
215
225
|
JS_SetPropertyStr(ctx, obj, "features", features);
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
uint32_t flash_size = 0;
|
|
219
|
-
esp_flash_get_size(NULL, &flash_size);
|
|
220
|
-
JS_SetPropertyStr(ctx, obj, "flash", JS_NewInt64(ctx, flash_size));
|
|
221
|
-
|
|
222
|
-
/* PSRAM size in bytes */
|
|
223
|
-
#ifdef CONFIG_SPIRAM
|
|
224
|
-
JS_SetPropertyStr(ctx, obj, "psram", JS_NewInt64(ctx, esp_psram_get_size()));
|
|
225
|
-
#else
|
|
226
|
-
JS_SetPropertyStr(ctx, obj, "psram", JS_NewInt64(ctx, 0));
|
|
227
|
-
#endif
|
|
228
|
-
|
|
229
|
-
#else
|
|
230
|
-
JS_SetPropertyStr(ctx, obj, "chip", JS_NewString(ctx, "host"));
|
|
231
|
-
JS_SetPropertyStr(ctx, obj, "cores", JS_NewInt32(ctx, 1));
|
|
232
|
-
JS_SetPropertyStr(ctx, obj, "revision", JS_NewInt32(ctx, 0));
|
|
233
|
-
JS_SetPropertyStr(ctx, obj, "features", JS_NewArray(ctx));
|
|
234
|
-
JS_SetPropertyStr(ctx, obj, "flash", JS_NewInt64(ctx, 0));
|
|
235
|
-
JS_SetPropertyStr(ctx, obj, "psram", JS_NewInt64(ctx, 0));
|
|
236
|
-
#endif
|
|
226
|
+
JS_SetPropertyStr(ctx, obj, "flash", JS_NewInt64(ctx, static_cast<int64_t>(info.flash)));
|
|
227
|
+
JS_SetPropertyStr(ctx, obj, "psram", JS_NewInt64(ctx, static_cast<int64_t>(info.psram)));
|
|
237
228
|
return obj;
|
|
238
229
|
}
|
|
239
230
|
|
|
@@ -248,6 +239,7 @@ static JSValue mik__sys_board(JSContext* ctx) {
|
|
|
248
239
|
|
|
249
240
|
static JSValue mik__sys_firmware(JSContext* ctx) {
|
|
250
241
|
JSValue obj = JS_NewObject(ctx);
|
|
242
|
+
JS_SetPropertyStr(ctx, obj, "name", JS_NewString(ctx, mik__firmware_name()));
|
|
251
243
|
#ifdef CONFIG_IDF_TARGET
|
|
252
244
|
const esp_app_desc_t* desc = esp_app_get_description();
|
|
253
245
|
char elf_hash[65];
|
|
@@ -301,6 +293,17 @@ static JSValue mik__sys_set_device_name(JSContext* ctx, JSValue this_val, int ar
|
|
|
301
293
|
return JS_UNDEFINED;
|
|
302
294
|
}
|
|
303
295
|
|
|
296
|
+
/* Read through the platform so `mikro/sys` loads on ports without sleep. */
|
|
297
|
+
static JSValue mik__sys_get_wakeup_cause(JSContext* ctx, JSValue this_val, int argc,
|
|
298
|
+
JSValue* argv) {
|
|
299
|
+
(void)this_val;
|
|
300
|
+
(void)argc;
|
|
301
|
+
(void)argv;
|
|
302
|
+
const MIKPlatform* platform = MIK_GetPlatform();
|
|
303
|
+
const char* cause = platform->get_wakeup_cause ? platform->get_wakeup_cause() : NULL;
|
|
304
|
+
return JS_NewString(ctx, cause ? cause : "undefined");
|
|
305
|
+
}
|
|
306
|
+
|
|
304
307
|
void mik__sys_api_init(JSContext* ctx, JSValue ns) {
|
|
305
308
|
JS_SetPropertyStr(ctx, ns, "evalScript",
|
|
306
309
|
JS_NewCFunction(ctx, mik__sys_eval_script, "evalScript", 1));
|
|
@@ -349,4 +352,6 @@ void mik__sys_api_init(JSContext* ctx, JSValue ns) {
|
|
|
349
352
|
platform->get_reset_reason ? platform->get_reset_reason() : NULL;
|
|
350
353
|
JS_SetPropertyStr(ctx, ns, "resetReason",
|
|
351
354
|
JS_NewString(ctx, reset_reason ? reset_reason : "unknown"));
|
|
355
|
+
JS_SetPropertyStr(ctx, ns, "getWakeupCause",
|
|
356
|
+
JS_NewCFunction(ctx, mik__sys_get_wakeup_cause, "getWakeupCause", 0));
|
|
352
357
|
}
|