@mikrojs/firmware 0.0.7

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 (88) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +30 -0
  3. package/bin/idf.py +7 -0
  4. package/chips.json +3 -0
  5. package/cmake.js +9 -0
  6. package/components/mikrojs/CMakeLists.txt +187 -0
  7. package/components/mikrojs/Kconfig +55 -0
  8. package/components/mikrojs/idf_component.yml +6 -0
  9. package/components/mikrojs/include/mem.h +3 -0
  10. package/components/mikrojs/include/mik_color.h +3 -0
  11. package/components/mikrojs/include/mik_http_internal.h +77 -0
  12. package/components/mikrojs/include/mikrojs.h +5 -0
  13. package/components/mikrojs/include/mikrojs_esp32.h +65 -0
  14. package/components/mikrojs/include/private.h +10 -0
  15. package/components/mikrojs/include/utils.h +3 -0
  16. package/components/mikrojs/mik_ble.cpp +1588 -0
  17. package/components/mikrojs/mik_ble_c_shim.c +61 -0
  18. package/components/mikrojs/mik_ble_c_shim.h +37 -0
  19. package/components/mikrojs/mik_config.cpp +167 -0
  20. package/components/mikrojs/mik_deploy.cpp +584 -0
  21. package/components/mikrojs/mik_http.cpp +916 -0
  22. package/components/mikrojs/mik_i2c.cpp +364 -0
  23. package/components/mikrojs/mik_main.cpp +542 -0
  24. package/components/mikrojs/mik_neopixel.cpp +437 -0
  25. package/components/mikrojs/mik_nvs_kv.cpp +219 -0
  26. package/components/mikrojs/mik_pin.cpp +195 -0
  27. package/components/mikrojs/mik_pwm.cpp +525 -0
  28. package/components/mikrojs/mik_recovery.cpp +86 -0
  29. package/components/mikrojs/mik_rtc.cpp +305 -0
  30. package/components/mikrojs/mik_serial_io.cpp +362 -0
  31. package/components/mikrojs/mik_sleep.cpp +226 -0
  32. package/components/mikrojs/mik_sntp.cpp +275 -0
  33. package/components/mikrojs/mik_spi.cpp +330 -0
  34. package/components/mikrojs/mik_uart.cpp +497 -0
  35. package/components/mikrojs/mik_wifi.cpp +1434 -0
  36. package/components/mikrojs/platform_esp32.cpp +192 -0
  37. package/components/mikrojs/test/CMakeLists.txt +32 -0
  38. package/components/mikrojs/test/abort_test.cpp +254 -0
  39. package/components/mikrojs/test/ble_test.cpp +714 -0
  40. package/components/mikrojs/test/fs_js_test.cpp +458 -0
  41. package/components/mikrojs/test/fs_pub_test.cpp +312 -0
  42. package/components/mikrojs/test/http_test.cpp +475 -0
  43. package/components/mikrojs/test/i2c_test.cpp +138 -0
  44. package/components/mikrojs/test/modules_extended_test.cpp +137 -0
  45. package/components/mikrojs/test/modules_test.cpp +131 -0
  46. package/components/mikrojs/test/pins_test.cpp +47 -0
  47. package/components/mikrojs/test/pwm_test.cpp +166 -0
  48. package/components/mikrojs/test/repl_protocol_test.cpp +405 -0
  49. package/components/mikrojs/test/rtc_test.cpp +331 -0
  50. package/components/mikrojs/test/runtime_test.cpp +89 -0
  51. package/components/mikrojs/test/sleep_test.cpp +222 -0
  52. package/components/mikrojs/test/sntp_test.cpp +249 -0
  53. package/components/mikrojs/test/stdio_test.cpp +449 -0
  54. package/components/mikrojs/test/sys_test.cpp +165 -0
  55. package/components/mikrojs/test/text_encoding_test.cpp +224 -0
  56. package/components/mikrojs/test/timers_js_test.cpp +244 -0
  57. package/components/mikrojs/test/timers_test.cpp +79 -0
  58. package/components/mikrojs/test/wifi_test.cpp +599 -0
  59. package/default-app/main/CMakeLists.txt +3 -0
  60. package/default-app/main/main.cpp +5 -0
  61. package/discover.js +77 -0
  62. package/index.d.ts +7 -0
  63. package/index.js +20 -0
  64. package/package.json +61 -0
  65. package/partitions.csv +5 -0
  66. package/prebuilds/esp32/bootloader/bootloader.bin +0 -0
  67. package/prebuilds/esp32/flasher_args.json +24 -0
  68. package/prebuilds/esp32/mikrojs.bin +0 -0
  69. package/prebuilds/esp32/partition_table/partition-table.bin +0 -0
  70. package/prebuilds/esp32c3/bootloader/bootloader.bin +0 -0
  71. package/prebuilds/esp32c3/flasher_args.json +24 -0
  72. package/prebuilds/esp32c3/mikrojs.bin +0 -0
  73. package/prebuilds/esp32c3/partition_table/partition-table.bin +0 -0
  74. package/prebuilds/esp32c6/bootloader/bootloader.bin +0 -0
  75. package/prebuilds/esp32c6/flasher_args.json +24 -0
  76. package/prebuilds/esp32c6/mikrojs.bin +0 -0
  77. package/prebuilds/esp32c6/partition_table/partition-table.bin +0 -0
  78. package/prebuilds/esp32s3/bootloader/bootloader.bin +0 -0
  79. package/prebuilds/esp32s3/flasher_args.json +24 -0
  80. package/prebuilds/esp32s3/mikrojs.bin +0 -0
  81. package/prebuilds/esp32s3/partition_table/partition-table.bin +0 -0
  82. package/project.cmake +101 -0
  83. package/resolve.js +54 -0
  84. package/sdkconfig.defaults +127 -0
  85. package/sdkconfig.defaults.esp32 +8 -0
  86. package/sdkconfig.defaults.esp32c3 +15 -0
  87. package/sdkconfig.defaults.esp32c6 +26 -0
  88. package/sdkconfig.defaults.esp32s3 +22 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) Bjørge Næss
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,30 @@
1
+ # @mikrojs/firmware
2
+
3
+ ESP32 firmware package for Mikro.js. Provides the ESP-IDF integration, build system, and platform-specific modules (GPIO, WiFi, HTTP, etc.) needed to run Mikro.js on ESP32 chips.
4
+
5
+ ## What's included
6
+
7
+ - **`project.cmake`** - CMake module that integrates with ESP-IDF. Handles component discovery, SDK config merging, and partition table defaults.
8
+ - **`components/mikrojs/`** - ESP-IDF component that compiles the Mikro.js runtime, QuickJS engine, and platform-specific C modules.
9
+ - **`idf.py` wrapper** - Runs `idf.py` through `eim run`, so you don't need to manually activate ESP-IDF.
10
+ - **Default configs** - `sdkconfig.defaults` and `partitions.csv` for common setups.
11
+
12
+ ## Usage
13
+
14
+ A custom firmware project depends on this package and includes `project.cmake`:
15
+
16
+ ```
17
+ my-firmware/
18
+ ├── package.json # depends on @mikrojs/firmware
19
+ ├── CMakeLists.txt # include($ENV{MIKROJS_PROJECT_CMAKE})
20
+ └── main/
21
+ ├── CMakeLists.txt
22
+ └── main.cpp # calls MIK_Main()
23
+ ```
24
+
25
+ See the [Custom Firmware](https://mikrojs.dev/develop/custom-firmware) docs for details.
26
+
27
+ ## Requirements
28
+
29
+ - Node.js >= 24
30
+ - ESP-IDF >= 6.0 (installed via [EIM](https://docs.espressif.com/projects/esp-idf/en/stable/esp32/get-started/index.html))
package/bin/idf.py ADDED
@@ -0,0 +1,7 @@
1
+ #!/bin/sh
2
+ # Thin wrapper: runs idf.py via eim in the activated ESP-IDF environment.
3
+ # Usage: idf.py <args>
4
+ # idf.py build
5
+ # idf.py set-target esp32c6
6
+ # idf.py build flash monitor
7
+ exec eim run "idf.py $*"
package/chips.json ADDED
@@ -0,0 +1,3 @@
1
+ {
2
+ "chips": ["esp32", "esp32c3", "esp32c6", "esp32s3"]
3
+ }
package/cmake.js ADDED
@@ -0,0 +1,9 @@
1
+ import {dirname, join} from 'node:path'
2
+ import {fileURLToPath} from 'node:url'
3
+
4
+ const __dirname = dirname(fileURLToPath(import.meta.url))
5
+
6
+ // EXTRA_COMPONENT_DIRS expects directories containing component subdirectories.
7
+ // ESP-IDF scans this and finds the mikrojs/ subdirectory as a component.
8
+ export const componentDir = join(__dirname, 'components')
9
+ export const projectCmakePath = join(__dirname, 'project.cmake')
@@ -0,0 +1,187 @@
1
+ # ── Resolve package paths via Node.js ────────────────────────────────
2
+ # MIKROJS_PROJECT_DIR is the directory containing package.json and node_modules.
3
+ # Defaults to CMAKE_SOURCE_DIR which works for both:
4
+ # - Monorepo: CMAKE_SOURCE_DIR is esp32/ (has package.json with workspace deps)
5
+ # - External: CMAKE_SOURCE_DIR is the user's project root
6
+ if(NOT DEFINED MIKROJS_PROJECT_DIR)
7
+ set(MIKROJS_PROJECT_DIR "${CMAKE_SOURCE_DIR}")
8
+ endif()
9
+
10
+ # resolve.js lives in the firmware package root, two levels up from this component
11
+ set(_MIK_RESOLVE "${CMAKE_CURRENT_LIST_DIR}/../../resolve.js")
12
+
13
+ execute_process(
14
+ COMMAND node ${_MIK_RESOLVE} quickjs
15
+ OUTPUT_VARIABLE QUICKJS_CMAKE_PATH
16
+ OUTPUT_STRIP_TRAILING_WHITESPACE
17
+ )
18
+ execute_process(
19
+ COMMAND node ${_MIK_RESOLVE} native
20
+ OUTPUT_VARIABLE _NATIVE_JSON
21
+ OUTPUT_STRIP_TRAILING_WHITESPACE
22
+ )
23
+ # Parse JSON output
24
+ string(JSON MIK_INCLUDE_DIR GET "${_NATIVE_JSON}" "include")
25
+ string(JSON MIK_SRC_DIR GET "${_NATIVE_JSON}" "src")
26
+ string(JSON MIK_RUNTIME_DIR GET "${_NATIVE_JSON}" "runtime")
27
+ string(JSON MIK_SCRIPTS_DIR GET "${_NATIVE_JSON}" "scripts")
28
+ string(JSON MIK_BYTECODE_CMAKE GET "${_NATIVE_JSON}" "bytecodeCmake")
29
+
30
+ # Include quickjs.cmake for QUICKJS_SOURCES, QUICKJS_INCLUDE_DIR, etc.
31
+ include("${QUICKJS_CMAKE_PATH}")
32
+
33
+ # nanocbor lives inside the native package
34
+ set(MIK_NANOCBOR_DIR "${MIK_SRC_DIR}/../deps/nanocbor")
35
+
36
+ # BLE sources and the `ble` native module only compile when NimBLE is
37
+ # available. Test builds disable Bluetooth via `CONFIG_BT_ENABLED=n` in
38
+ # their sdkconfig.defaults, so this component has to skip BLE there.
39
+ set(_MIK_BLE_SRCS "")
40
+ if(CONFIG_BT_ENABLED)
41
+ list(APPEND _MIK_BLE_SRCS "mik_ble.cpp" "mik_ble_c_shim.c")
42
+ endif()
43
+
44
+ idf_component_register(
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-tls esp_netif esp_event esp_wifi nvs_flash esp_driver_uart esp_driver_usb_serial_jtag spi_flash
47
+ SRCS
48
+ # QuickJS engine
49
+ ${QUICKJS_SOURCES}
50
+ # Standalone library portable sources
51
+ "${MIK_SRC_DIR}/cutils_compat.c"
52
+ "${MIK_SRC_DIR}/builtins.cpp"
53
+ "${MIK_SRC_DIR}/eval_bytecode.cpp"
54
+ "${MIK_SRC_DIR}/mik_abort.cpp"
55
+ "${MIK_SRC_DIR}/fs.cpp"
56
+ "${MIK_SRC_DIR}/mem.cpp"
57
+ "${MIK_SRC_DIR}/mik_app_config.cpp"
58
+ "${MIK_SRC_DIR}/mik_color.cpp"
59
+ "${MIK_SRC_DIR}/mik_console.cpp"
60
+ "${MIK_SRC_DIR}/mik_inspect.cpp"
61
+ "${MIK_SRC_DIR}/mik_repl.cpp"
62
+ "${MIK_SRC_DIR}/mik_stdio.cpp"
63
+ "${MIK_SRC_DIR}/mik_sys.cpp"
64
+ "${MIK_SRC_DIR}/mik_text_encoding.cpp"
65
+ "${MIK_SRC_DIR}/mik_cbor.cpp"
66
+ "${MIK_SRC_DIR}/mik_result.cpp"
67
+ "${MIK_SRC_DIR}/mikrojs.cpp"
68
+ # nanocbor CBOR codec
69
+ "${MIK_NANOCBOR_DIR}/src/encoder.c"
70
+ "${MIK_NANOCBOR_DIR}/src/decoder.c"
71
+ "${MIK_SRC_DIR}/modules.cpp"
72
+ "${MIK_SRC_DIR}/timers.cpp"
73
+ "${MIK_SRC_DIR}/utils.cpp"
74
+ # ESP32 platform implementation (replaces platform_posix.cpp)
75
+ "platform_esp32.cpp"
76
+ # Default firmware entry point
77
+ "mik_main.cpp"
78
+ # ESP32-specific modules and protocols
79
+ ${_MIK_BLE_SRCS}
80
+ "mik_config.cpp"
81
+ "mik_deploy.cpp"
82
+ "mik_http.cpp"
83
+ "mik_i2c.cpp"
84
+ "mik_neopixel.cpp"
85
+ "mik_pin.cpp"
86
+ "mik_pwm.cpp"
87
+ "mik_nvs_kv.cpp"
88
+ "mik_recovery.cpp"
89
+ "mik_rtc.cpp"
90
+ "mik_serial_io.cpp"
91
+ "mik_sleep.cpp"
92
+ "mik_spi.cpp"
93
+ "mik_sntp.cpp"
94
+ "mik_uart.cpp"
95
+ "mik_wifi.cpp"
96
+ )
97
+
98
+ # QuickJS headers as SYSTEM includes (suppresses warnings)
99
+ target_include_directories(${COMPONENT_LIB} SYSTEM PUBLIC "${QUICKJS_INCLUDE_DIR}")
100
+ # nanocbor headers
101
+ target_include_directories(${COMPONENT_LIB} PRIVATE "${MIK_NANOCBOR_DIR}/include")
102
+ target_compile_options(${COMPONENT_LIB} PUBLIC $<$<COMPILE_LANGUAGE:CXX>:-fpermissive>)
103
+ # -fno-strict-aliasing: see comment in quickjs.cmake. Applied component-wide
104
+ # (same posture as the Linux kernel) so neither QuickJS sources nor our
105
+ # own C/C++ can be bitten by aliasing UB during optimization.
106
+ target_compile_options(${COMPONENT_LIB} PRIVATE -Wno-implicit-fallthrough -Wno-maybe-uninitialized -Wno-missing-field-initializers -fno-strict-aliasing)
107
+
108
+ # ── Board and version metadata ──────────────────────────────────────
109
+ execute_process(
110
+ COMMAND node ${_MIK_RESOLVE} version
111
+ OUTPUT_VARIABLE _MIK_VERSION
112
+ OUTPUT_STRIP_TRAILING_WHITESPACE
113
+ )
114
+ target_compile_definitions(${COMPONENT_LIB} PRIVATE "MIK_FW_VERSION=\"${_MIK_VERSION}\"")
115
+
116
+ # UTC build timestamp. `string(TIMESTAMP ... UTC)` honors SOURCE_DATE_EPOCH
117
+ # when set. Refreshes on re-configure only (idf.py triggers this on each
118
+ # build via its own reconfigure step, so in practice it's close to
119
+ # build-fresh on ESP-IDF).
120
+ string(TIMESTAMP _MIK_BUILD_DATE_UTC "%Y-%m-%dT%H:%M:%SZ" UTC)
121
+ target_compile_definitions(${COMPONENT_LIB} PRIVATE "MIK_BUILD_DATE_UTC=\"${_MIK_BUILD_DATE_UTC}\"")
122
+
123
+ # Board name from MIKROJS_BOARD env var (set by CI or developer)
124
+ if(DEFINED ENV{MIKROJS_BOARD})
125
+ target_compile_definitions(${COMPONENT_LIB} PRIVATE "MIK_BOARD_NAME=\"$ENV{MIKROJS_BOARD}\"")
126
+ endif()
127
+
128
+ # ── Bytecode generation ──────────────────────────────────────────────
129
+ include("${MIK_BYTECODE_CMAKE}")
130
+
131
+ # Force linker to include self-registering native modules
132
+ set(_MIK_MODULES cbor pin i2c spi http wifi rtc nvs_kv sntp sleep neopixel pwm uart)
133
+ set(_MIK_BYTECODE_MODULES cbor env result schema fs http/helpers http/request i2c kv/nvs kv/rtc kv/shared neopixel pin pwm reader sleep spi sntp stdio stream sys test uart wifi)
134
+ if(CONFIG_BT_ENABLED)
135
+ list(APPEND _MIK_MODULES ble)
136
+ list(APPEND _MIK_BYTECODE_MODULES ble)
137
+ endif()
138
+ mikrojs_force_include_modules(${_MIK_MODULES})
139
+ mikrojs_generate_bytecode(
140
+ RUNTIME_DIR "${MIK_RUNTIME_DIR}"
141
+ MODULES ${_MIK_BYTECODE_MODULES}
142
+ MODULE_PREFIX "mikrojs"
143
+ SYMBOL_PREFIX "mikrojs"
144
+ TARGET gen_bytecode
145
+ WORKING_DIRECTORY "${MIKROJS_PROJECT_DIR}"
146
+ )
147
+ add_dependencies(${COMPONENT_LIB} gen_bytecode)
148
+ target_include_directories(${COMPONENT_LIB} PRIVATE "${gen_bytecode_INCLUDE_DIR}")
149
+
150
+ # ── Symbol map for offline panic-trace decoding ──────────────────────
151
+ # Runs after the ELF is linked. Toolchain prefix derived from the C
152
+ # compiler path so this works for any binutils target (xtensa, riscv,
153
+ # arm — anything a future port might add).
154
+ get_filename_component(_MIK_TC_DIR "${CMAKE_C_COMPILER}" DIRECTORY)
155
+ get_filename_component(_MIK_TC_NAME "${CMAKE_C_COMPILER}" NAME)
156
+ string(REGEX REPLACE "gcc(\\.exe)?$" "" _MIK_TC_NAME_PREFIX "${_MIK_TC_NAME}")
157
+ set(_MIK_TC_PREFIX "${_MIK_TC_DIR}/${_MIK_TC_NAME_PREFIX}")
158
+
159
+ # The ${project}.elf target is created by ESP-IDF inside `project()`, in the
160
+ # source-root CMake scope. Component CMakeLists run before that target
161
+ # exists, so defer to end-of-source-dir processing. cmake_language(DEFER)
162
+ # expands ${...} args in the *target* directory's scope at fire time, so
163
+ # component-local variables won't survive — stash them as GLOBAL properties
164
+ # and read them back inside the deferred function.
165
+ set_property(GLOBAL PROPERTY MIKROJS_TOOLCHAIN_PREFIX "${_MIK_TC_PREFIX}")
166
+ set_property(GLOBAL PROPERTY MIKROJS_SCRIPTS_DIR "${MIK_SCRIPTS_DIR}")
167
+
168
+ function(_mik_install_symbol_map_hook)
169
+ get_property(tc_prefix GLOBAL PROPERTY MIKROJS_TOOLCHAIN_PREFIX)
170
+ get_property(scripts_dir GLOBAL PROPERTY MIKROJS_SCRIPTS_DIR)
171
+ idf_build_get_property(project_name PROJECT_NAME)
172
+ idf_build_get_property(target IDF_TARGET)
173
+ add_custom_command(
174
+ TARGET "${project_name}.elf" POST_BUILD
175
+ COMMAND node "${scripts_dir}/generate-symbol-map.js"
176
+ "$<TARGET_FILE:${project_name}.elf>"
177
+ "${CMAKE_BINARY_DIR}/${project_name}.symbols.json"
178
+ "${tc_prefix}"
179
+ "${target}"
180
+ BYPRODUCTS "${CMAKE_BINARY_DIR}/${project_name}.symbols.json"
181
+ COMMENT "Generating symbol map for panic-trace decoding"
182
+ VERBATIM
183
+ )
184
+ endfunction()
185
+
186
+ cmake_language(DEFER DIRECTORY "${CMAKE_SOURCE_DIR}"
187
+ CALL _mik_install_symbol_map_hook)
@@ -0,0 +1,55 @@
1
+ menu "mikrojs console"
2
+
3
+ config MIKROJS_CONSOLE_FALLBACK_UART
4
+ bool "Install UART0 as fallback console on chips with USB-Serial/JTAG"
5
+ default n
6
+ depends on SOC_USB_SERIAL_JTAG_SUPPORTED
7
+ help
8
+ When enabled, mikrojs brings up both USB-Serial/JTAG and UART0
9
+ at boot and latches to whichever receives the first byte.
10
+ Convenient for dev: plug in either cable type and it just
11
+ works. Costs ~4 KB DRAM (UART RX ring buffer), a UART ISR
12
+ in IRAM, and keeps UART0 clocks powered — meaningful on
13
+ RAM-constrained apps (e.g. ones that push large SPI DMA
14
+ frames and already run the system heap close to full).
15
+
16
+ Defaults off to keep RAM available for the application.
17
+ Enable if you want the auto-detect dev experience on a board
18
+ where you sometimes connect a USB-TTL adapter instead of
19
+ (or in addition to) the native USB port. On chips without
20
+ USB-Serial/JTAG hardware (plain ESP32), UART0 is always
21
+ installed regardless of this option.
22
+
23
+ endmenu
24
+
25
+ menu "mikrojs Test Configuration"
26
+
27
+ config MIKROJS_TEST_GPIO_PIN
28
+ int "GPIO pin for output/input tests"
29
+ default 15 if IDF_TARGET_ESP32C6
30
+ default 8 if IDF_TARGET_ESP32C3
31
+ default 2
32
+ help
33
+ GPIO pin used by the hardware test suite for digital write/read tests.
34
+ Should be a safe, general-purpose pin on the target board (ideally an LED).
35
+
36
+ config MIKROJS_TEST_PWM_PIN
37
+ int "GPIO pin for PWM/LEDC tests"
38
+ default 15 if IDF_TARGET_ESP32C6
39
+ default 8 if IDF_TARGET_ESP32C3
40
+ default 2
41
+ help
42
+ GPIO pin used by the hardware test suite for PWM (LEDC) tests.
43
+ Should be a safe, general-purpose pin on the target board (ideally an LED).
44
+
45
+ config MIKROJS_TEST_ADC_PIN
46
+ int "GPIO pin for ADC tests"
47
+ default 0 if IDF_TARGET_ESP32C6
48
+ default 0 if IDF_TARGET_ESP32C3
49
+ default 1 if IDF_TARGET_ESP32S3
50
+ default 34
51
+ help
52
+ GPIO pin used by the hardware test suite for ADC read tests.
53
+ Must be connected to an ADC1 channel on the target chip.
54
+
55
+ endmenu
@@ -0,0 +1,6 @@
1
+ ## IDF Component Manager Manifest File
2
+ dependencies:
3
+ ## Required IDF version
4
+ idf:
5
+ version: '>=5.5.3'
6
+ joltwallet/littlefs: '>=1.19.1'
@@ -0,0 +1,3 @@
1
+ /* Backward-compatible header — forwards to standalone library */
2
+ #pragma once
3
+ #include <mikrojs/mem.h>
@@ -0,0 +1,3 @@
1
+ /* Backward-compatible header — forwards to standalone library */
2
+ #pragma once
3
+ #include <mikrojs/mik_color.h>
@@ -0,0 +1,77 @@
1
+ /* Internal HTTP module layout shared with on-device tests.
2
+ * Included by mik_http.cpp and test/http_test.cpp so struct changes can't
3
+ * drift silently between the implementation and its mirror. */
4
+ #pragma once
5
+
6
+ #include <atomic>
7
+ #include <cstdint>
8
+ #include <cstdlib>
9
+
10
+ #include "freertos/FreeRTOS.h"
11
+ #include "freertos/queue.h"
12
+ #include "freertos/semphr.h"
13
+ #include "utils.h"
14
+
15
+ struct MIKHttpHeader {
16
+ char* key;
17
+ char* value;
18
+ };
19
+
20
+ enum MIKHttpMsgKind : uint8_t {
21
+ MIK_HTTP_MSG_HEADERS,
22
+ MIK_HTTP_MSG_CHUNK,
23
+ MIK_HTTP_MSG_END,
24
+ MIK_HTTP_MSG_ERROR,
25
+ };
26
+
27
+ struct MIKHttpMsg {
28
+ uint32_t id;
29
+ MIKHttpMsgKind kind;
30
+ /* HEADERS */
31
+ int status;
32
+ MIKHttpHeader* headers;
33
+ size_t header_count;
34
+ /* CHUNK */
35
+ uint8_t* chunk_data;
36
+ size_t chunk_len;
37
+ /* ERROR */
38
+ bool is_cancelled;
39
+ char* error_message;
40
+ };
41
+
42
+ struct MIKHttpQueuedMsg {
43
+ MIKHttpMsgKind kind;
44
+ uint8_t* chunk_data;
45
+ size_t chunk_len;
46
+ bool is_cancelled;
47
+ char* error_message;
48
+ MIKHttpQueuedMsg* next;
49
+ };
50
+
51
+ struct MIKHttpPending {
52
+ uint32_t id;
53
+ std::atomic<bool>* cancelled;
54
+ bool js_cancelled;
55
+
56
+ MIKPromise headers_promise;
57
+ bool headers_resolved;
58
+
59
+ MIKPromise next_promise;
60
+ bool next_promise_active;
61
+
62
+ MIKHttpQueuedMsg* queue_head;
63
+ MIKHttpQueuedMsg* queue_tail;
64
+ };
65
+
66
+ /* Ceilings shared with the test harness. Must match the #defines in
67
+ * mik_http.cpp. */
68
+ #define MIK_HTTP_MAX_PENDING 4
69
+ #define MIK_HTTP_MAX_CHUNKS_INFLIGHT 8
70
+
71
+ struct MIKHttpState {
72
+ QueueHandle_t result_queue;
73
+ SemaphoreHandle_t inflight;
74
+ MIKHttpPending pending[MIK_HTTP_MAX_PENDING];
75
+ size_t pending_count = 0;
76
+ uint32_t next_id = 1;
77
+ };
@@ -0,0 +1,5 @@
1
+ /* Backward-compatible header — includes both the standalone library API
2
+ * and ESP32-specific extensions. */
3
+ #pragma once
4
+ #include <mikrojs/mikrojs.h>
5
+ #include "mikrojs_esp32.h"
@@ -0,0 +1,65 @@
1
+ /* ESP32-specific extensions to the mikrojs public API.
2
+ * Include this alongside <mikrojs/mikrojs.h> for deploy, config, and serial I/O. */
3
+ #pragma once
4
+
5
+ #include <stdbool.h>
6
+ #include <stddef.h>
7
+ #include <stdint.h>
8
+
9
+ #ifdef __cplusplus
10
+ extern "C" {
11
+ #endif
12
+
13
+ typedef struct MIKRuntime MIKRuntime;
14
+
15
+ /* Default firmware entry point (mik_main.cpp).
16
+ * Sets up console, NVS, LittleFS, JS runtime, and enters the event loop
17
+ * with REPL, deploy, and config protocol support. */
18
+ void MIK_Main(void);
19
+
20
+ /* Deploy recovery (mik_deploy.cpp) */
21
+ void MIK_DeployRecover(void);
22
+
23
+ /* Safe-mode recovery window (mik_recovery.cpp).
24
+ * Opens a brief window (typ. 500ms) right after console init that watches
25
+ * for two triggers and returns true if either fires:
26
+ * 1) Double-reset: an RTC_NOINIT magic word survives a soft reset that
27
+ * happens while the window is armed.
28
+ * 2) Sync bytes: the host sends "MIKSAFE\n" over the console transport
29
+ * (mikro console --recover toggles RTS to reset and then floods this).
30
+ * When true, the firmware should skip user-app autorun and drop to REPL. */
31
+ bool mik__check_recovery(int timeout_ms);
32
+
33
+ /* Console auto-detection (mik_serial_io.cpp).
34
+ * On chips with USB Serial/JTAG, detects whether USB or UART is connected
35
+ * and sets up the active console accordingly. Must be called early in app_main(). */
36
+ void mik__console_init(void);
37
+
38
+ /* Read from the active console. Returns bytes read, 0 if no data, or -1. */
39
+ int mik__console_read(void* buf, size_t len);
40
+
41
+ /* Write to the active console. Returns bytes written. */
42
+ int mik__console_write(const void* buf, size_t len);
43
+
44
+ /* Serial binary I/O (mik_serial_io.cpp) */
45
+ void mik__serial_binary_begin_no_echo(void);
46
+
47
+ /* Shared NVS helpers (mik_serial_io.cpp) */
48
+ extern const char* MIK__NVS_NS_ENV; /* env var values */
49
+ extern const char* MIK__NVS_NS_SEC; /* secret-flag markers (u8) */
50
+ /* ENV_FLAG_SECRET is defined in mikrojs/private.h as MIK_ENV_FLAG_SECRET */
51
+ void mik__nvs_clear_namespace(const char* ns);
52
+ bool mik__nvs_put_string(const char* ns, const char* key, const char* value);
53
+ bool mik__nvs_put_string_if_diff(const char* ns, const char* key, const char* value,
54
+ bool* out_changed);
55
+ bool mik__nvs_is_secret(const char* key);
56
+ bool mik__nvs_set_secret_flag(const char* key, bool secret);
57
+ bool mik__nvs_env_set(const char* key, const char* value, bool secret, bool* out_changed);
58
+ bool mik__nvs_env_delete(const char* key);
59
+
60
+ /* Read NVS env vars and register them with the runtime via MIK_SetEnvVar() */
61
+ void MIK_LoadEnvFromNVS(MIKRuntime* mik_rt);
62
+
63
+ #ifdef __cplusplus
64
+ }
65
+ #endif
@@ -0,0 +1,10 @@
1
+ /* Backward-compatible header — forwards to standalone library
2
+ * and adds ESP32-specific declarations. */
3
+ #pragma once
4
+ #include <mikrojs/private.h>
5
+ #include "mikrojs_esp32.h"
6
+
7
+ /* Forward declarations for ESP32 module state types (needed by inline accessors
8
+ * that appear before the full struct definitions in their respective .cpp files). */
9
+ struct MIKHttpState;
10
+ struct MIKWifiState;
@@ -0,0 +1,3 @@
1
+ /* Backward-compatible header — forwards to standalone library */
2
+ #pragma once
3
+ #include <mikrojs/utils.h>