@mikrojs/firmware 0.14.0 → 0.15.0-next.20260614113448

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.
Files changed (41) hide show
  1. package/components/mikrojs/CMakeLists.txt +8 -3
  2. package/components/mikrojs/mik_ble.cpp +3 -3
  3. package/components/mikrojs/mik_http.cpp +3 -3
  4. package/components/mikrojs/mik_http_server.cpp +4 -4
  5. package/components/mikrojs/mik_i2c.cpp +7 -5
  6. package/components/mikrojs/mik_i2s.cpp +740 -0
  7. package/components/mikrojs/mik_neopixel.cpp +3 -3
  8. package/components/mikrojs/mik_nvs_kv.cpp +3 -3
  9. package/components/mikrojs/mik_pin.cpp +3 -3
  10. package/components/mikrojs/mik_pwm.cpp +3 -3
  11. package/components/mikrojs/mik_rtc.cpp +3 -3
  12. package/components/mikrojs/mik_sleep.cpp +3 -3
  13. package/components/mikrojs/mik_sntp.cpp +3 -3
  14. package/components/mikrojs/mik_spi.cpp +11 -7
  15. package/components/mikrojs/mik_uart.cpp +7 -5
  16. package/components/mikrojs/mik_wifi.cpp +3 -3
  17. package/components/mikrojs/test/CMakeLists.txt +1 -0
  18. package/components/mikrojs/test/ble_test.cpp +21 -21
  19. package/components/mikrojs/test/fs_js_test.cpp +38 -38
  20. package/components/mikrojs/test/http_server_test.cpp +5 -5
  21. package/components/mikrojs/test/http_test.cpp +10 -10
  22. package/components/mikrojs/test/i2s_test.cpp +178 -0
  23. package/components/mikrojs/test/modules_extended_test.cpp +10 -10
  24. package/components/mikrojs/test/rtc_test.cpp +19 -19
  25. package/components/mikrojs/test/sleep_test.cpp +8 -8
  26. package/components/mikrojs/test/sntp_test.cpp +16 -16
  27. package/components/mikrojs/test/stdio_test.cpp +20 -20
  28. package/components/mikrojs/test/sys_test.cpp +12 -12
  29. package/components/mikrojs/test/udp_test.cpp +1 -1
  30. package/components/mikrojs/test/wifi_test.cpp +18 -18
  31. package/package.json +3 -3
  32. package/prebuilds/esp32/bootloader/bootloader.bin +0 -0
  33. package/prebuilds/esp32/mikrojs.bin +0 -0
  34. package/prebuilds/esp32c3/bootloader/bootloader.bin +0 -0
  35. package/prebuilds/esp32c3/mikrojs.bin +0 -0
  36. package/prebuilds/esp32c5/bootloader/bootloader.bin +0 -0
  37. package/prebuilds/esp32c5/mikrojs.bin +0 -0
  38. package/prebuilds/esp32c6/bootloader/bootloader.bin +0 -0
  39. package/prebuilds/esp32c6/mikrojs.bin +0 -0
  40. package/prebuilds/esp32s3/bootloader/bootloader.bin +0 -0
  41. package/prebuilds/esp32s3/mikrojs.bin +0 -0
@@ -43,7 +43,7 @@ endif()
43
43
 
44
44
  idf_component_register(
45
45
  INCLUDE_DIRS "include" "${MIK_INCLUDE_DIR}"
46
- REQUIRES bt littlefs esp_adc esp_app_format esp_driver_gpio esp_driver_i2c esp_driver_ledc esp_driver_rmt esp_driver_spi esp_psram esp_timer esp_http_client esp_http_server esp-tls esp_netif esp_event esp_wifi nvs_flash esp_driver_uart esp_driver_usb_serial_jtag spi_flash
46
+ REQUIRES bt littlefs esp_adc esp_app_format esp_driver_gpio esp_driver_i2c esp_driver_i2s esp_driver_ledc esp_driver_rmt esp_driver_spi esp_psram esp_timer esp_http_client esp_http_server esp-tls esp_netif esp_event esp_wifi nvs_flash esp_driver_uart esp_driver_usb_serial_jtag spi_flash
47
47
  SRCS
48
48
  # QuickJS engine
49
49
  ${QUICKJS_SOURCES}
@@ -84,6 +84,7 @@ idf_component_register(
84
84
  "mik_http.cpp"
85
85
  "mik_http_server.cpp"
86
86
  "mik_i2c.cpp"
87
+ "mik_i2s.cpp"
87
88
  "mik_logfile.cpp"
88
89
  "mik_neopixel.cpp"
89
90
  "mik_pin.cpp"
@@ -116,6 +117,10 @@ execute_process(
116
117
  OUTPUT_STRIP_TRAILING_WHITESPACE
117
118
  )
118
119
  target_compile_definitions(${COMPONENT_LIB} PRIVATE "MIK_FW_VERSION=\"${_MIK_VERSION}\"")
120
+ # Core runtime owns the bare `native:mikro/*` namespace. MIK_PACKAGE_NAME makes
121
+ # MIK_REGISTER_MODULE enforce that every native module here is named
122
+ # "native:mikro/<module>"; driver/board packages set their own package name.
123
+ target_compile_definitions(${COMPONENT_LIB} PRIVATE "MIK_PACKAGE_NAME=\"mikro\"")
119
124
  # The version is read at configure time, so configure must re-run when the
120
125
  # firmware package version changes — otherwise an incremental idf.py build
121
126
  # flashes a binary that still reports the stale MIK_FW_VERSION.
@@ -138,8 +143,8 @@ endif()
138
143
  include("${MIK_BYTECODE_CMAKE}")
139
144
 
140
145
  # Force linker to include self-registering native modules
141
- set(_MIK_MODULES cbor pin i2c spi http http_server wifi rtc nvs_kv sntp sleep neopixel pwm uart)
142
- set(_MIK_BYTECODE_MODULES abort cbor env result schema fs http/helpers http/request http/server i2c kv/nvs kv/rtc kv/shared module neopixel observable observable/lazy observable/operators pin pwm reader sleep spi sntp stdio stream sys test uart udp wifi)
146
+ set(_MIK_MODULES cbor pin i2c i2s spi http http_server wifi rtc nvs_kv sntp sleep neopixel pwm uart)
147
+ set(_MIK_BYTECODE_MODULES abort cbor env result schema fs http/helpers http/request http/server i2c i2s kv/nvs kv/rtc kv/shared module neopixel observable observable/lazy observable/operators pin pwm reader sleep spi sntp stdio stream sys test uart udp wifi)
143
148
  if(CONFIG_BT_ENABLED)
144
149
  list(APPEND _MIK_MODULES ble)
145
150
  list(APPEND _MIK_BYTECODE_MODULES ble)
@@ -57,7 +57,7 @@ static inline MIKBleState*& mik__ble_st(MIKRuntime* rt) {
57
57
  return reinterpret_cast<MIKBleState*&>(rt->module_data[mik__ble_slot]);
58
58
  }
59
59
 
60
- #define MIK_BLE_TAG "native:ble"
60
+ #define MIK_BLE_TAG "native:mikro/ble"
61
61
 
62
62
  /* Max advertising payload (31 bytes) minus mandatory flags overhead (3 bytes). */
63
63
  #define MIK_BLE_NAME_MAX_LEN 29
@@ -1492,7 +1492,7 @@ static JSModuleDef* mik__ble_init(JSContext* ctx) {
1492
1492
  CHECK_NOT_NULL(s_ble_event_queue);
1493
1493
  }
1494
1494
 
1495
- JSModuleDef* m = JS_NewCModule(ctx, "native:ble", mik__ble_module_init);
1495
+ JSModuleDef* m = JS_NewCModule(ctx, "native:mikro/ble", mik__ble_module_init);
1496
1496
  if (!m) return nullptr;
1497
1497
  JS_AddModuleExport(ctx, m, "Ble");
1498
1498
  return m;
@@ -1585,4 +1585,4 @@ void mik__ble_destroy(JSContext* ctx) {
1585
1585
  mik__ble_st(mik_rt) = nullptr;
1586
1586
  }
1587
1587
 
1588
- MIK_REGISTER_MODULE(ble, "native:ble", mik__ble_init, mik__ble_consume, mik__ble_destroy)
1588
+ MIK_REGISTER_MODULE(ble, "native:mikro/ble", mik__ble_init, mik__ble_consume, mik__ble_destroy)
@@ -23,7 +23,7 @@ static inline MIKHttpState*& mik__http_st(MIKRuntime* rt) {
23
23
  return reinterpret_cast<MIKHttpState*&>(rt->module_data[mik__http_slot]);
24
24
  }
25
25
 
26
- #define MIK_HTTP_TAG "native:http"
26
+ #define MIK_HTTP_TAG "native:mikro/http"
27
27
  /* 8 KB was tight for HTTPS — mbedTLS handshake + request header buffer can
28
28
  * spike the task stack; the ESP-HTTP-client header list was corrupted once
29
29
  * the stack overran. 12 KB matches the recommendation for esp-tls users. */
@@ -808,7 +808,7 @@ static JSModuleDef* mik__http_init(JSContext* ctx) {
808
808
  MIKRuntime* mik_rt = MIK_GetRuntime(ctx);
809
809
  mik__http_slot = MIK_AllocModuleSlot(mik_rt);
810
810
 
811
- JSModuleDef* m = JS_NewCModule(ctx, "native:http", mik__http_module_init);
811
+ JSModuleDef* m = JS_NewCModule(ctx, "native:mikro/http", mik__http_module_init);
812
812
  if (!m) return nullptr;
813
813
  JS_AddModuleExport(ctx, m, "request");
814
814
  JS_AddModuleExport(ctx, m, "nextMessage");
@@ -976,4 +976,4 @@ void mik__http_destroy(JSContext* ctx) {
976
976
  mik__http_st(mik_rt) = nullptr;
977
977
  }
978
978
 
979
- MIK_REGISTER_MODULE(http, "native:http", mik__http_init, mik__http_consume, mik__http_destroy)
979
+ MIK_REGISTER_MODULE(http, "native:mikro/http", mik__http_init, mik__http_consume, mik__http_destroy)
@@ -9,7 +9,7 @@
9
9
  #include "private.h"
10
10
  #include "utils.h"
11
11
 
12
- /* native:http_server — an HTTP server backed by ESP-IDF's esp_http_server.
12
+ /* native:mikro/http_server — an HTTP server backed by ESP-IDF's esp_http_server.
13
13
  *
14
14
  * esp_http_server runs request handlers on its own (single) task; QuickJS is
15
15
  * single-threaded, so the JS handler must run on the event-loop task. This is
@@ -32,7 +32,7 @@
32
32
  * lookups via getHeader(), reading the parked request directly. The httpd task
33
33
  * is blocked waiting for the response, so there is no concurrent writer. */
34
34
 
35
- #define MIK_HS_TAG "native:http_server"
35
+ #define MIK_HS_TAG "native:mikro/http_server"
36
36
  #define MIK_HS_DEFAULT_MAX_BODY 16384
37
37
  /* How often the parked handler wakes to check for server shutdown. */
38
38
  #define MIK_HS_ABORT_POLL_MS 250
@@ -674,7 +674,7 @@ static JSModuleDef* mik__http_server_init(JSContext* ctx) {
674
674
  MIKRuntime* rt = MIK_GetRuntime(ctx);
675
675
  mik__http_server_slot = MIK_AllocModuleSlot(rt);
676
676
 
677
- JSModuleDef* m = JS_NewCModule(ctx, "native:http_server", mik__hs_module_init);
677
+ JSModuleDef* m = JS_NewCModule(ctx, "native:mikro/http_server", mik__hs_module_init);
678
678
  if (!m) return nullptr;
679
679
  JS_AddModuleExport(ctx, m, "start");
680
680
  JS_AddModuleExport(ctx, m, "stop");
@@ -786,5 +786,5 @@ void mik__http_server_destroy(JSContext* ctx) {
786
786
  mik__hs_st(rt) = nullptr;
787
787
  }
788
788
 
789
- MIK_REGISTER_MODULE(http_server, "native:http_server", mik__http_server_init,
789
+ MIK_REGISTER_MODULE(http_server, "native:mikro/http_server", mik__http_server_init,
790
790
  mik__http_server_consume, mik__http_server_destroy)
@@ -4,7 +4,7 @@
4
4
  #include "mikrojs/private.h"
5
5
  #include "mikrojs/utils.h"
6
6
 
7
- #define MIK_I2C_TAG "native:i2c"
7
+ #define MIK_I2C_TAG "native:mikro/i2c"
8
8
  #define MIK_I2C_DEFAULT_FREQ 100000
9
9
  #define MIK_I2C_DEFAULT_TIMEOUT_MS 100
10
10
  #define MIK_I2C_SCAN_START 0x08
@@ -198,10 +198,12 @@ static JSValue js_i2c_write(JSContext* ctx, JSValue this_val, int argc, JSValue*
198
198
  uint8_t* data;
199
199
 
200
200
  /* Try typed array (Uint8Array) first, then raw ArrayBuffer */
201
- size_t offset, elem_size;
201
+ size_t offset, elem_size, buf_len;
202
202
  JSValue ab = JS_GetTypedArrayBuffer(ctx, argv[1], &offset, &data_len, &elem_size);
203
203
  if (!JS_IsException(ab)) {
204
- data = JS_GetArrayBuffer(ctx, &data_len, ab);
204
+ /* data_len keeps the view length; the full backing buffer goes to a
205
+ * throwaway so a subarray view isn't over-read. */
206
+ data = JS_GetArrayBuffer(ctx, &buf_len, ab);
205
207
  JS_FreeValue(ctx, ab);
206
208
  if (!data) return JS_ThrowTypeError(ctx, "expected Uint8Array as argument 2");
207
209
  data += offset;
@@ -355,10 +357,10 @@ static JSModuleDef* mik__i2c_init(JSContext* ctx) {
355
357
  JS_SetClassProto(ctx, mik_i2c_class_id, proto); /* consumed */
356
358
 
357
359
  /* Register module */
358
- JSModuleDef* m = JS_NewCModule(ctx, "native:i2c", mik__i2c_module_init);
360
+ JSModuleDef* m = JS_NewCModule(ctx, "native:mikro/i2c", mik__i2c_module_init);
359
361
  if (!m) return nullptr;
360
362
  JS_AddModuleExport(ctx, m, "I2c");
361
363
  return m;
362
364
  }
363
365
 
364
- MIK_REGISTER_MODULE(i2c, "native:i2c", mik__i2c_init, nullptr, nullptr)
366
+ MIK_REGISTER_MODULE(i2c, "native:mikro/i2c", mik__i2c_init, nullptr, nullptr)