stm32f4-emu 0.1.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/LICENSE +674 -0
- package/README.md +273 -0
- package/index.mjs +39 -0
- package/mcp/server.mjs +235 -0
- package/package.json +83 -0
- package/site/app.js +654 -0
- package/site/components.js +146 -0
- package/site/emulator.js +885 -0
- package/site/firmware.js +37 -0
- package/site/index.html +385 -0
- package/site/loaders.js +133 -0
- package/site/netsim.js +212 -0
- package/site/vendor/package.json +15 -0
- package/site/vendor/stm32_periph_wasm.d.ts +400 -0
- package/site/vendor/stm32_periph_wasm.js +944 -0
- package/site/vendor/stm32_periph_wasm_bg.wasm +0 -0
- package/site/vendor/stm32_periph_wasm_bg.wasm.d.ts +68 -0
- package/site/vendor/stm32f407.svd +41374 -0
- package/site/vendor/unicorn_arm.cjs +0 -0
- package/site/vendor/unicorn_arm.js +0 -0
|
@@ -0,0 +1,944 @@
|
|
|
1
|
+
/* @ts-self-types="./stm32_periph_wasm.d.ts" */
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Remove a channel override, reverting it to the synthetic default.
|
|
5
|
+
* @param {string} peripheral
|
|
6
|
+
* @param {number} channel
|
|
7
|
+
*/
|
|
8
|
+
export function adc_clear_channel_value(peripheral, channel) {
|
|
9
|
+
const ptr0 = passStringToWasm0(peripheral, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
10
|
+
const len0 = WASM_VECTOR_LEN;
|
|
11
|
+
wasm.adc_clear_channel_value(ptr0, len0, channel);
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Force an ADC channel's next conversion(s) to return `value` (clamped to
|
|
16
|
+
* 12-bit) instead of the synthetic temp/vref/vbat/random default. Unlike
|
|
17
|
+
* spi_tap/i2c_register_slave this can be called any time, including after
|
|
18
|
+
* init() — it's a global override table, not per-instance device wiring
|
|
19
|
+
* (see docs/components.md).
|
|
20
|
+
* @param {string} peripheral
|
|
21
|
+
* @param {number} channel
|
|
22
|
+
* @param {number} value
|
|
23
|
+
*/
|
|
24
|
+
export function adc_set_channel_value(peripheral, channel, value) {
|
|
25
|
+
const ptr0 = passStringToWasm0(peripheral, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
26
|
+
const len0 = WASM_VECTOR_LEN;
|
|
27
|
+
wasm.adc_set_channel_value(ptr0, len0, channel, value);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* @param {string} peripheral
|
|
32
|
+
* @param {number} address
|
|
33
|
+
* @param {Uint8Array} data
|
|
34
|
+
*/
|
|
35
|
+
export function add_i2c_eeprom(peripheral, address, data) {
|
|
36
|
+
const ptr0 = passStringToWasm0(peripheral, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
37
|
+
const len0 = WASM_VECTOR_LEN;
|
|
38
|
+
const ptr1 = passArray8ToWasm0(data, wasm.__wbindgen_malloc);
|
|
39
|
+
const len1 = WASM_VECTOR_LEN;
|
|
40
|
+
wasm.add_i2c_eeprom(ptr0, len0, address, ptr1, len1);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Register a software SPI device. Must be called before init().
|
|
45
|
+
* @param {string} name
|
|
46
|
+
* @param {string | null | undefined} cs
|
|
47
|
+
* @param {string} clk
|
|
48
|
+
* @param {string} miso
|
|
49
|
+
* @param {string} mosi
|
|
50
|
+
*/
|
|
51
|
+
export function add_software_spi(name, cs, clk, miso, mosi) {
|
|
52
|
+
const ptr0 = passStringToWasm0(name, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
53
|
+
const len0 = WASM_VECTOR_LEN;
|
|
54
|
+
var ptr1 = isLikeNone(cs) ? 0 : passStringToWasm0(cs, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
55
|
+
var len1 = WASM_VECTOR_LEN;
|
|
56
|
+
const ptr2 = passStringToWasm0(clk, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
57
|
+
const len2 = WASM_VECTOR_LEN;
|
|
58
|
+
const ptr3 = passStringToWasm0(miso, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
59
|
+
const len3 = WASM_VECTOR_LEN;
|
|
60
|
+
const ptr4 = passStringToWasm0(mosi, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
61
|
+
const len4 = WASM_VECTOR_LEN;
|
|
62
|
+
wasm.add_software_spi(ptr0, len0, ptr1, len1, ptr2, len2, ptr3, len3, ptr4, len4);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Add an SPI flash device. Must be called before init().
|
|
67
|
+
* @param {string} peripheral
|
|
68
|
+
* @param {number} jedec_id
|
|
69
|
+
* @param {Uint8Array} data
|
|
70
|
+
* @param {string | null} [cs]
|
|
71
|
+
*/
|
|
72
|
+
export function add_spi_flash(peripheral, jedec_id, data, cs) {
|
|
73
|
+
const ptr0 = passStringToWasm0(peripheral, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
74
|
+
const len0 = WASM_VECTOR_LEN;
|
|
75
|
+
const ptr1 = passArray8ToWasm0(data, wasm.__wbindgen_malloc);
|
|
76
|
+
const len1 = WASM_VECTOR_LEN;
|
|
77
|
+
var ptr2 = isLikeNone(cs) ? 0 : passStringToWasm0(cs, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
78
|
+
var len2 = WASM_VECTOR_LEN;
|
|
79
|
+
wasm.add_spi_flash(ptr0, len0, jedec_id, ptr1, len1, ptr2, len2);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* Reset the audio source and capture FIFO.
|
|
84
|
+
*/
|
|
85
|
+
export function audio_clear() {
|
|
86
|
+
wasm.audio_clear();
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* Load a WAV file (PCM 16-bit) as the I2S/SAI sample source. DR reads then
|
|
91
|
+
* consume samples from it. Returns an error string on malformed input.
|
|
92
|
+
* @param {Uint8Array} bytes
|
|
93
|
+
*/
|
|
94
|
+
export function audio_load_wav(bytes) {
|
|
95
|
+
const ptr0 = passArray8ToWasm0(bytes, wasm.__wbindgen_malloc);
|
|
96
|
+
const len0 = WASM_VECTOR_LEN;
|
|
97
|
+
const ret = wasm.audio_load_wav(ptr0, len0);
|
|
98
|
+
if (ret[1]) {
|
|
99
|
+
throw takeFromExternrefTable0(ret[0]);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* Remaining source samples (0 when no WAV is loaded or it is exhausted).
|
|
105
|
+
* @returns {number}
|
|
106
|
+
*/
|
|
107
|
+
export function audio_source_remaining() {
|
|
108
|
+
const ret = wasm.audio_source_remaining();
|
|
109
|
+
return ret >>> 0;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* Drain the I2S/SAI TX capture FIFO (all DR writes since the last call).
|
|
114
|
+
* @returns {Uint16Array}
|
|
115
|
+
*/
|
|
116
|
+
export function audio_take_capture() {
|
|
117
|
+
const ret = wasm.audio_take_capture();
|
|
118
|
+
var v1 = getArrayU16FromWasm0(ret[0], ret[1]).slice();
|
|
119
|
+
wasm.__wbindgen_free(ret[0], ret[1] * 2, 2);
|
|
120
|
+
return v1;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* Forget any fed frame (stop the camera).
|
|
125
|
+
*/
|
|
126
|
+
export function dcmi_clear() {
|
|
127
|
+
wasm.dcmi_clear();
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
/**
|
|
131
|
+
* Provide the next camera frame to the DCMI controller (8-bit pixels,
|
|
132
|
+
* row-major, width x height). The next CAPTURE start consumes it.
|
|
133
|
+
* @param {number} w
|
|
134
|
+
* @param {number} h
|
|
135
|
+
* @param {Uint8Array} pixels
|
|
136
|
+
*/
|
|
137
|
+
export function dcmi_feed_frame(w, h, pixels) {
|
|
138
|
+
const ptr0 = passArray8ToWasm0(pixels, wasm.__wbindgen_malloc);
|
|
139
|
+
const len0 = WASM_VECTOR_LEN;
|
|
140
|
+
wasm.dcmi_feed_frame(w, h, ptr0, len0);
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
/**
|
|
144
|
+
* @param {number} index
|
|
145
|
+
* @returns {Uint32Array}
|
|
146
|
+
*/
|
|
147
|
+
export function dma_get_pending(index) {
|
|
148
|
+
const ret = wasm.dma_get_pending(index);
|
|
149
|
+
var v1 = getArrayU32FromWasm0(ret[0], ret[1]).slice();
|
|
150
|
+
wasm.__wbindgen_free(ret[0], ret[1] * 4, 4);
|
|
151
|
+
return v1;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
/**
|
|
155
|
+
* @returns {number}
|
|
156
|
+
*/
|
|
157
|
+
export function dma_get_pending_count() {
|
|
158
|
+
const ret = wasm.dma_get_pending_count();
|
|
159
|
+
return ret >>> 0;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
/**
|
|
163
|
+
* DMA peripheral-side chunked read: read `size` bytes from peripheral
|
|
164
|
+
* `addr` (4-byte-aligned, tail chunk partial). Replaces the JS per-chunk
|
|
165
|
+
* periph_read loop (one WASM call instead of size/4).
|
|
166
|
+
* @param {number} addr
|
|
167
|
+
* @param {number} size
|
|
168
|
+
* @param {boolean} pinc
|
|
169
|
+
* @param {number} psize
|
|
170
|
+
* @returns {Uint8Array}
|
|
171
|
+
*/
|
|
172
|
+
export function dma_periph_read(addr, size, pinc, psize) {
|
|
173
|
+
const ret = wasm.dma_periph_read(addr, size, pinc, psize);
|
|
174
|
+
var v1 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
|
|
175
|
+
wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
|
|
176
|
+
return v1;
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
/**
|
|
180
|
+
* DMA peripheral-side chunked write: write `bytes` to peripheral `addr` in
|
|
181
|
+
* 4-byte chunks (tail chunk partial). Replaces the JS per-chunk periph_write
|
|
182
|
+
* loop (one WASM call instead of size/4).
|
|
183
|
+
* @param {number} addr
|
|
184
|
+
* @param {Uint8Array} bytes
|
|
185
|
+
*/
|
|
186
|
+
export function dma_periph_write(addr, bytes) {
|
|
187
|
+
const ptr0 = passArray8ToWasm0(bytes, wasm.__wbindgen_malloc);
|
|
188
|
+
const len0 = WASM_VECTOR_LEN;
|
|
189
|
+
wasm.dma_periph_write(addr, ptr0, len0);
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
/**
|
|
193
|
+
* @param {number} stream_idx
|
|
194
|
+
* @param {boolean} success
|
|
195
|
+
*/
|
|
196
|
+
export function dma_set_completed(stream_idx, success) {
|
|
197
|
+
wasm.dma_set_completed(stream_idx, success);
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
/**
|
|
201
|
+
* Clear the RX poll flag (call after processing descriptors).
|
|
202
|
+
*/
|
|
203
|
+
export function eth_clear_rx_poll() {
|
|
204
|
+
wasm.eth_clear_rx_poll();
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
/**
|
|
208
|
+
* Clear the TX poll flag (call after processing descriptors).
|
|
209
|
+
*/
|
|
210
|
+
export function eth_clear_tx_poll() {
|
|
211
|
+
wasm.eth_clear_tx_poll();
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
/**
|
|
215
|
+
* Get the RX descriptor list address for the current poll.
|
|
216
|
+
* @returns {number}
|
|
217
|
+
*/
|
|
218
|
+
export function eth_get_rx_desc_addr() {
|
|
219
|
+
const ret = wasm.eth_get_rx_desc_addr();
|
|
220
|
+
return ret >>> 0;
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
/**
|
|
224
|
+
* Get the TX descriptor list address for the current poll.
|
|
225
|
+
* @returns {number}
|
|
226
|
+
*/
|
|
227
|
+
export function eth_get_tx_desc_addr() {
|
|
228
|
+
const ret = wasm.eth_get_tx_desc_addr();
|
|
229
|
+
return ret >>> 0;
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
/**
|
|
233
|
+
* Check if an Ethernet RX poll is pending (firmware wants to receive a packet).
|
|
234
|
+
* @returns {boolean}
|
|
235
|
+
*/
|
|
236
|
+
export function eth_is_rx_poll() {
|
|
237
|
+
const ret = wasm.eth_is_rx_poll();
|
|
238
|
+
return ret !== 0;
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
/**
|
|
242
|
+
* Check if an Ethernet TX poll is pending (firmware wants to send a packet).
|
|
243
|
+
* @returns {boolean}
|
|
244
|
+
*/
|
|
245
|
+
export function eth_is_tx_poll() {
|
|
246
|
+
const ret = wasm.eth_is_tx_poll();
|
|
247
|
+
return ret !== 0;
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
/**
|
|
251
|
+
* Signal to the peripheral that RX descriptor processing is complete.
|
|
252
|
+
* Call this after writing received data into RX buffers.
|
|
253
|
+
*/
|
|
254
|
+
export function eth_rx_done() {
|
|
255
|
+
wasm.eth_rx_done();
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
/**
|
|
259
|
+
* Re-arm the RX poll flag from JS (used when more packets are pending in gwRxQueue).
|
|
260
|
+
* @param {number} desc_addr
|
|
261
|
+
*/
|
|
262
|
+
export function eth_signal_rx_poll(desc_addr) {
|
|
263
|
+
wasm.eth_signal_rx_poll(desc_addr);
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
/**
|
|
267
|
+
* Re-arm the TX poll flag from JS (used when more TX descriptors are pending).
|
|
268
|
+
* @param {number} desc_addr
|
|
269
|
+
*/
|
|
270
|
+
export function eth_signal_tx_poll(desc_addr) {
|
|
271
|
+
wasm.eth_signal_tx_poll(desc_addr);
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
/**
|
|
275
|
+
* Signal to the peripheral that TX descriptor processing is complete.
|
|
276
|
+
* Call this after walking TX descriptors and sending the packet.
|
|
277
|
+
*/
|
|
278
|
+
export function eth_tx_done() {
|
|
279
|
+
wasm.eth_tx_done();
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
/**
|
|
283
|
+
* Called by the JS driver after it applied the queued erase to guest memory;
|
|
284
|
+
* clears BSY/EOP so the firmware's busy-wait can proceed.
|
|
285
|
+
*/
|
|
286
|
+
export function flash_erase_applied() {
|
|
287
|
+
wasm.flash_erase_applied();
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
/**
|
|
291
|
+
* True when the FLASH peripheral is unlocked with PG set and !BSY — the
|
|
292
|
+
* JS driver applies program writes to guest memory when this is true.
|
|
293
|
+
* @returns {boolean}
|
|
294
|
+
*/
|
|
295
|
+
export function flash_is_programming() {
|
|
296
|
+
const ret = wasm.flash_is_programming();
|
|
297
|
+
return ret !== 0;
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
/**
|
|
301
|
+
* Consume a completed erase request (start, len) the JS driver must apply
|
|
302
|
+
* to guest memory (all bytes 0xFF). Empty vec = nothing pending.
|
|
303
|
+
* @returns {Uint32Array}
|
|
304
|
+
*/
|
|
305
|
+
export function flash_take_erase() {
|
|
306
|
+
const ret = wasm.flash_take_erase();
|
|
307
|
+
var v1 = getArrayU32FromWasm0(ret[0], ret[1]).slice();
|
|
308
|
+
wasm.__wbindgen_free(ret[0], ret[1] * 4, 4);
|
|
309
|
+
return v1;
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
/**
|
|
313
|
+
* Queue values the JS device answers on subsequent bank reads, oldest
|
|
314
|
+
* first. An exhausted queue reads back 0.
|
|
315
|
+
* @param {number} bank
|
|
316
|
+
* @param {Uint32Array} values
|
|
317
|
+
*/
|
|
318
|
+
export function fsmc_push_data(bank, values) {
|
|
319
|
+
const ptr0 = passArray32ToWasm0(values, wasm.__wbindgen_malloc);
|
|
320
|
+
const len0 = WASM_VECTOR_LEN;
|
|
321
|
+
wasm.fsmc_push_data(bank, ptr0, len0);
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
/**
|
|
325
|
+
* Drain all FSMC tap events for a bank since the last call (2 words per
|
|
326
|
+
* access, see `fsmc_tap`).
|
|
327
|
+
* @param {number} bank
|
|
328
|
+
* @returns {Uint32Array}
|
|
329
|
+
*/
|
|
330
|
+
export function fsmc_take_events(bank) {
|
|
331
|
+
const ret = wasm.fsmc_take_events(bank);
|
|
332
|
+
var v1 = getArrayU32FromWasm0(ret[0], ret[1]).slice();
|
|
333
|
+
wasm.__wbindgen_free(ret[0], ret[1] * 4, 4);
|
|
334
|
+
return v1;
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
/**
|
|
338
|
+
* Register a protocol-agnostic tap on an FSMC memory bank (0 = BANK1, the
|
|
339
|
+
* 0x6000_0000 window). Must be called before init(): the Fsmc peripheral
|
|
340
|
+
* binds its banks' devices once at construction and never rescans.
|
|
341
|
+
*
|
|
342
|
+
* Every data-space access to the bank is queued for JS as TWO words —
|
|
343
|
+
* header then value — where the header is `1<<31 | offset` for a write and
|
|
344
|
+
* `offset` for a read. The offset matters: memory-mapped displays in
|
|
345
|
+
* 8080 mode decode an address line as RS/DC, so the address is the only
|
|
346
|
+
* thing separating a command write from a pixel write.
|
|
347
|
+
* @param {number} bank
|
|
348
|
+
*/
|
|
349
|
+
export function fsmc_tap(bank) {
|
|
350
|
+
wasm.fsmc_tap(bank);
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
/**
|
|
354
|
+
* @returns {number}
|
|
355
|
+
*/
|
|
356
|
+
export function get_next_pending_interrupt() {
|
|
357
|
+
const ret = wasm.get_next_pending_interrupt();
|
|
358
|
+
return ret;
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
/**
|
|
362
|
+
* Collect UART output since last call.
|
|
363
|
+
* @returns {string}
|
|
364
|
+
*/
|
|
365
|
+
export function get_uart_output() {
|
|
366
|
+
let deferred1_0;
|
|
367
|
+
let deferred1_1;
|
|
368
|
+
try {
|
|
369
|
+
const ret = wasm.get_uart_output();
|
|
370
|
+
deferred1_0 = ret[0];
|
|
371
|
+
deferred1_1 = ret[1];
|
|
372
|
+
return getStringFromWasm0(ret[0], ret[1]);
|
|
373
|
+
} finally {
|
|
374
|
+
wasm.__wbindgen_free(deferred1_0, deferred1_1, 1);
|
|
375
|
+
}
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
/**
|
|
379
|
+
* @param {number} port
|
|
380
|
+
* @param {number} pin
|
|
381
|
+
* @returns {boolean}
|
|
382
|
+
*/
|
|
383
|
+
export function gpio_read_input(port, pin) {
|
|
384
|
+
const ret = wasm.gpio_read_input(port, pin);
|
|
385
|
+
return ret !== 0;
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
/**
|
|
389
|
+
* @param {number} port
|
|
390
|
+
* @param {number} pin
|
|
391
|
+
* @returns {boolean}
|
|
392
|
+
*/
|
|
393
|
+
export function gpio_read_output(port, pin) {
|
|
394
|
+
const ret = wasm.gpio_read_output(port, pin);
|
|
395
|
+
return ret !== 0;
|
|
396
|
+
}
|
|
397
|
+
|
|
398
|
+
/**
|
|
399
|
+
* @param {number} port
|
|
400
|
+
* @param {number} pin
|
|
401
|
+
* @param {boolean} value
|
|
402
|
+
*/
|
|
403
|
+
export function gpio_set_input(port, pin, value) {
|
|
404
|
+
wasm.gpio_set_input(port, pin, value);
|
|
405
|
+
}
|
|
406
|
+
|
|
407
|
+
/**
|
|
408
|
+
* Check if any interrupt is pending (non-consuming).
|
|
409
|
+
* @returns {boolean}
|
|
410
|
+
*/
|
|
411
|
+
export function has_pending_interrupt() {
|
|
412
|
+
const ret = wasm.has_pending_interrupt();
|
|
413
|
+
return ret !== 0;
|
|
414
|
+
}
|
|
415
|
+
|
|
416
|
+
/**
|
|
417
|
+
* Queue bytes the tapped I2C slave answers on master reads.
|
|
418
|
+
* @param {string} peripheral
|
|
419
|
+
* @param {Uint8Array} bytes
|
|
420
|
+
*/
|
|
421
|
+
export function i2c_push_rx(peripheral, bytes) {
|
|
422
|
+
const ptr0 = passStringToWasm0(peripheral, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
423
|
+
const len0 = WASM_VECTOR_LEN;
|
|
424
|
+
const ptr1 = passArray8ToWasm0(bytes, wasm.__wbindgen_malloc);
|
|
425
|
+
const len1 = WASM_VECTOR_LEN;
|
|
426
|
+
wasm.i2c_push_rx(ptr0, len0, ptr1, len1);
|
|
427
|
+
}
|
|
428
|
+
|
|
429
|
+
/**
|
|
430
|
+
* Read one register of the first matching regfile on a peripheral.
|
|
431
|
+
* @param {string} peripheral
|
|
432
|
+
* @param {number} offset
|
|
433
|
+
* @returns {number}
|
|
434
|
+
*/
|
|
435
|
+
export function i2c_regfile_get(peripheral, offset) {
|
|
436
|
+
const ptr0 = passStringToWasm0(peripheral, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
437
|
+
const len0 = WASM_VECTOR_LEN;
|
|
438
|
+
const ret = wasm.i2c_regfile_get(ptr0, len0, offset);
|
|
439
|
+
return ret;
|
|
440
|
+
}
|
|
441
|
+
|
|
442
|
+
/**
|
|
443
|
+
* Write one register of the first matching regfile on a peripheral
|
|
444
|
+
* (JS-side poke, e.g. temperature coming from outside the guest).
|
|
445
|
+
* @param {string} peripheral
|
|
446
|
+
* @param {number} offset
|
|
447
|
+
* @param {number} value
|
|
448
|
+
*/
|
|
449
|
+
export function i2c_regfile_set(peripheral, offset, value) {
|
|
450
|
+
const ptr0 = passStringToWasm0(peripheral, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
451
|
+
const len0 = WASM_VECTOR_LEN;
|
|
452
|
+
wasm.i2c_regfile_set(ptr0, len0, offset, value);
|
|
453
|
+
}
|
|
454
|
+
|
|
455
|
+
/**
|
|
456
|
+
* Register a pointer-addressed register file (DS3231 RTC style) on an I2C
|
|
457
|
+
* peripheral. Must be called before init(). The first write byte of each
|
|
458
|
+
* transaction is the register pointer, subsequent bytes land at `ptr++`;
|
|
459
|
+
* reads return `regs[ptr++]` (pointer persists across address matches).
|
|
460
|
+
* @param {string} peripheral
|
|
461
|
+
* @param {number} address
|
|
462
|
+
* @param {number} size
|
|
463
|
+
* @param {Uint8Array} init
|
|
464
|
+
*/
|
|
465
|
+
export function i2c_register_regfile(peripheral, address, size, init) {
|
|
466
|
+
const ptr0 = passStringToWasm0(peripheral, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
467
|
+
const len0 = WASM_VECTOR_LEN;
|
|
468
|
+
const ptr1 = passArray8ToWasm0(init, wasm.__wbindgen_malloc);
|
|
469
|
+
const len1 = WASM_VECTOR_LEN;
|
|
470
|
+
wasm.i2c_register_regfile(ptr0, len0, address, size, ptr1, len1);
|
|
471
|
+
}
|
|
472
|
+
|
|
473
|
+
/**
|
|
474
|
+
* Register a protocol-agnostic I2C slave on a peripheral. Must be called
|
|
475
|
+
* before init(). The address is ACKed like any other registered slave;
|
|
476
|
+
* master writes queue for JS (`i2c_take_tx`) and JS-pushed bytes are
|
|
477
|
+
* returned on master reads (`i2c_push_rx`).
|
|
478
|
+
* @param {string} peripheral
|
|
479
|
+
* @param {number} address
|
|
480
|
+
*/
|
|
481
|
+
export function i2c_register_slave(peripheral, address) {
|
|
482
|
+
const ptr0 = passStringToWasm0(peripheral, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
483
|
+
const len0 = WASM_VECTOR_LEN;
|
|
484
|
+
wasm.i2c_register_slave(ptr0, len0, address);
|
|
485
|
+
}
|
|
486
|
+
|
|
487
|
+
/**
|
|
488
|
+
* Drain all events for a tapped I2C slave since the last call. Each entry
|
|
489
|
+
* is a u32: bit31 = START/STOP boundary event (bit30 = 1 START / 0 STOP),
|
|
490
|
+
* otherwise the low byte is one byte the master wrote to the slave.
|
|
491
|
+
* @param {string} peripheral
|
|
492
|
+
* @returns {Uint32Array}
|
|
493
|
+
*/
|
|
494
|
+
export function i2c_take_events(peripheral) {
|
|
495
|
+
const ptr0 = passStringToWasm0(peripheral, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
496
|
+
const len0 = WASM_VECTOR_LEN;
|
|
497
|
+
const ret = wasm.i2c_take_events(ptr0, len0);
|
|
498
|
+
var v2 = getArrayU32FromWasm0(ret[0], ret[1]).slice();
|
|
499
|
+
wasm.__wbindgen_free(ret[0], ret[1] * 4, 4);
|
|
500
|
+
return v2;
|
|
501
|
+
}
|
|
502
|
+
|
|
503
|
+
/**
|
|
504
|
+
* Initialize the emulator with hardcoded peripheral map.
|
|
505
|
+
* Must be called after adding all ext devices (add_spi_flash, add_i2c_eeprom).
|
|
506
|
+
*/
|
|
507
|
+
export function init() {
|
|
508
|
+
wasm.init();
|
|
509
|
+
}
|
|
510
|
+
|
|
511
|
+
/**
|
|
512
|
+
* Initialize the emulator from an SVD XML string (e.g., STM32F407.svd).
|
|
513
|
+
* Must be called after adding all ext devices (add_spi_flash, add_i2c_eeprom).
|
|
514
|
+
* @param {string} svd_xml
|
|
515
|
+
*/
|
|
516
|
+
export function init_svd(svd_xml) {
|
|
517
|
+
const ptr0 = passStringToWasm0(svd_xml, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
518
|
+
const len0 = WASM_VECTOR_LEN;
|
|
519
|
+
wasm.init_svd(ptr0, len0);
|
|
520
|
+
}
|
|
521
|
+
|
|
522
|
+
/**
|
|
523
|
+
* @returns {boolean}
|
|
524
|
+
*/
|
|
525
|
+
export function is_watchdog_reset_requested() {
|
|
526
|
+
const ret = wasm.is_watchdog_reset_requested();
|
|
527
|
+
return ret !== 0;
|
|
528
|
+
}
|
|
529
|
+
|
|
530
|
+
/**
|
|
531
|
+
* Frames completed by the LTDC scanout since enable.
|
|
532
|
+
* @returns {number}
|
|
533
|
+
*/
|
|
534
|
+
export function ltdc_get_frame_count() {
|
|
535
|
+
const ret = wasm.ltdc_get_frame_count();
|
|
536
|
+
return ret >>> 0;
|
|
537
|
+
}
|
|
538
|
+
|
|
539
|
+
/**
|
|
540
|
+
* Current LTDC scanline (0xFFFF when the controller is disabled).
|
|
541
|
+
* @returns {number}
|
|
542
|
+
*/
|
|
543
|
+
export function ltdc_get_scanline() {
|
|
544
|
+
const ret = wasm.ltdc_get_scanline();
|
|
545
|
+
return ret >>> 0;
|
|
546
|
+
}
|
|
547
|
+
|
|
548
|
+
/**
|
|
549
|
+
* @param {number} addr
|
|
550
|
+
* @param {number} width
|
|
551
|
+
* @returns {number}
|
|
552
|
+
*/
|
|
553
|
+
export function periph_read(addr, width) {
|
|
554
|
+
const ret = wasm.periph_read(addr, width);
|
|
555
|
+
return ret >>> 0;
|
|
556
|
+
}
|
|
557
|
+
|
|
558
|
+
/**
|
|
559
|
+
* @param {number} addr
|
|
560
|
+
* @param {number} width
|
|
561
|
+
* @param {number} value
|
|
562
|
+
*/
|
|
563
|
+
export function periph_write(addr, width, value) {
|
|
564
|
+
wasm.periph_write(addr, width, value);
|
|
565
|
+
}
|
|
566
|
+
|
|
567
|
+
/**
|
|
568
|
+
* Clear all process-lifetime globals so a NEW emulator instance starts
|
|
569
|
+
* clean. Must be called before registering that instance's devices.
|
|
570
|
+
* Without it, `ExtDevices` accumulates and a second instance silently binds
|
|
571
|
+
* to the FIRST instance's devices (see system::reset_globals).
|
|
572
|
+
*/
|
|
573
|
+
export function reset_state() {
|
|
574
|
+
wasm.reset_state();
|
|
575
|
+
}
|
|
576
|
+
|
|
577
|
+
/**
|
|
578
|
+
* Debug: flash state summary [wel, status1, cs_state, dummy_pending, pending_program_len]
|
|
579
|
+
* @param {string} peripheral
|
|
580
|
+
* @returns {Uint32Array}
|
|
581
|
+
*/
|
|
582
|
+
export function spi_flash_debug(peripheral) {
|
|
583
|
+
const ptr0 = passStringToWasm0(peripheral, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
584
|
+
const len0 = WASM_VECTOR_LEN;
|
|
585
|
+
const ret = wasm.spi_flash_debug(ptr0, len0);
|
|
586
|
+
var v2 = getArrayU32FromWasm0(ret[0], ret[1]).slice();
|
|
587
|
+
wasm.__wbindgen_free(ret[0], ret[1] * 4, 4);
|
|
588
|
+
return v2;
|
|
589
|
+
}
|
|
590
|
+
|
|
591
|
+
/**
|
|
592
|
+
* Push bytes the JS device answers on the MISO line (read transactions).
|
|
593
|
+
* @param {string} peripheral
|
|
594
|
+
* @param {Uint8Array} bytes
|
|
595
|
+
*/
|
|
596
|
+
export function spi_push_miso(peripheral, bytes) {
|
|
597
|
+
const ptr0 = passStringToWasm0(peripheral, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
598
|
+
const len0 = WASM_VECTOR_LEN;
|
|
599
|
+
const ptr1 = passArray8ToWasm0(bytes, wasm.__wbindgen_malloc);
|
|
600
|
+
const len1 = WASM_VECTOR_LEN;
|
|
601
|
+
wasm.spi_push_miso(ptr0, len0, ptr1, len1);
|
|
602
|
+
}
|
|
603
|
+
|
|
604
|
+
/**
|
|
605
|
+
* Drain all SPI tap events for a peripheral since the last call.
|
|
606
|
+
* @param {string} peripheral
|
|
607
|
+
* @returns {Uint32Array}
|
|
608
|
+
*/
|
|
609
|
+
export function spi_take_events(peripheral) {
|
|
610
|
+
const ptr0 = passStringToWasm0(peripheral, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
611
|
+
const len0 = WASM_VECTOR_LEN;
|
|
612
|
+
const ret = wasm.spi_take_events(ptr0, len0);
|
|
613
|
+
var v2 = getArrayU32FromWasm0(ret[0], ret[1]).slice();
|
|
614
|
+
wasm.__wbindgen_free(ret[0], ret[1] * 4, 4);
|
|
615
|
+
return v2;
|
|
616
|
+
}
|
|
617
|
+
|
|
618
|
+
/**
|
|
619
|
+
* Register a protocol-agnostic tap on an SPI peripheral. Must be called
|
|
620
|
+
* before init(). `cs` optionally names the GPIO pin used as chip select
|
|
621
|
+
* ("PA4"); when given, CS edges are reported in the event stream. `dc`
|
|
622
|
+
* optionally names a data/command pin; its level is reported in bit 29 of
|
|
623
|
+
* each byte event (1 = data) so the JS device can parse TFT-style traffic.
|
|
624
|
+
* @param {string} peripheral
|
|
625
|
+
* @param {string | null} [cs]
|
|
626
|
+
* @param {string | null} [dc]
|
|
627
|
+
*/
|
|
628
|
+
export function spi_tap(peripheral, cs, dc) {
|
|
629
|
+
const ptr0 = passStringToWasm0(peripheral, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
630
|
+
const len0 = WASM_VECTOR_LEN;
|
|
631
|
+
var ptr1 = isLikeNone(cs) ? 0 : passStringToWasm0(cs, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
632
|
+
var len1 = WASM_VECTOR_LEN;
|
|
633
|
+
var ptr2 = isLikeNone(dc) ? 0 : passStringToWasm0(dc, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
634
|
+
var len2 = WASM_VECTOR_LEN;
|
|
635
|
+
wasm.spi_tap(ptr0, len0, ptr1, len1, ptr2, len2);
|
|
636
|
+
}
|
|
637
|
+
|
|
638
|
+
export function tick() {
|
|
639
|
+
wasm.tick();
|
|
640
|
+
}
|
|
641
|
+
|
|
642
|
+
/**
|
|
643
|
+
* Same as tick() but accounts for `delta` instructions at once. Timer
|
|
644
|
+
* peripherals are instruction-count driven, so batching ticks with a
|
|
645
|
+
* delta is semantically identical to one tick per instruction.
|
|
646
|
+
* @param {number} delta
|
|
647
|
+
*/
|
|
648
|
+
export function tick_n(delta) {
|
|
649
|
+
wasm.tick_n(delta);
|
|
650
|
+
}
|
|
651
|
+
|
|
652
|
+
/**
|
|
653
|
+
* Inject a received byte into the UART at the given peripheral base address.
|
|
654
|
+
* Returns true if a peripheral was found at that address.
|
|
655
|
+
* @param {number} addr
|
|
656
|
+
* @param {number} byte
|
|
657
|
+
* @returns {boolean}
|
|
658
|
+
*/
|
|
659
|
+
export function uart_rx_byte(addr, byte) {
|
|
660
|
+
const ret = wasm.uart_rx_byte(addr, byte);
|
|
661
|
+
return ret !== 0;
|
|
662
|
+
}
|
|
663
|
+
function __wbg_get_imports() {
|
|
664
|
+
const import0 = {
|
|
665
|
+
__proto__: null,
|
|
666
|
+
__wbg_error_a6fa202b58aa1cd3: function(arg0, arg1) {
|
|
667
|
+
let deferred0_0;
|
|
668
|
+
let deferred0_1;
|
|
669
|
+
try {
|
|
670
|
+
deferred0_0 = arg0;
|
|
671
|
+
deferred0_1 = arg1;
|
|
672
|
+
console.error(getStringFromWasm0(arg0, arg1));
|
|
673
|
+
} finally {
|
|
674
|
+
wasm.__wbindgen_free(deferred0_0, deferred0_1, 1);
|
|
675
|
+
}
|
|
676
|
+
},
|
|
677
|
+
__wbg_new_227d7c05414eb861: function() {
|
|
678
|
+
const ret = new Error();
|
|
679
|
+
return ret;
|
|
680
|
+
},
|
|
681
|
+
__wbg_stack_3b0d974bbf31e44f: function(arg0, arg1) {
|
|
682
|
+
const ret = arg1.stack;
|
|
683
|
+
const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
684
|
+
const len1 = WASM_VECTOR_LEN;
|
|
685
|
+
getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
|
|
686
|
+
getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
|
|
687
|
+
},
|
|
688
|
+
__wbindgen_cast_0000000000000001: function(arg0, arg1) {
|
|
689
|
+
// Cast intrinsic for `Ref(String) -> Externref`.
|
|
690
|
+
const ret = getStringFromWasm0(arg0, arg1);
|
|
691
|
+
return ret;
|
|
692
|
+
},
|
|
693
|
+
__wbindgen_init_externref_table: function() {
|
|
694
|
+
const table = wasm.__wbindgen_externrefs;
|
|
695
|
+
const offset = table.grow(4);
|
|
696
|
+
table.set(0, undefined);
|
|
697
|
+
table.set(offset + 0, undefined);
|
|
698
|
+
table.set(offset + 1, null);
|
|
699
|
+
table.set(offset + 2, true);
|
|
700
|
+
table.set(offset + 3, false);
|
|
701
|
+
},
|
|
702
|
+
};
|
|
703
|
+
return {
|
|
704
|
+
__proto__: null,
|
|
705
|
+
"./stm32_periph_wasm_bg.js": import0,
|
|
706
|
+
};
|
|
707
|
+
}
|
|
708
|
+
|
|
709
|
+
function getArrayU16FromWasm0(ptr, len) {
|
|
710
|
+
ptr = ptr >>> 0;
|
|
711
|
+
return getUint16ArrayMemory0().subarray(ptr / 2, ptr / 2 + len);
|
|
712
|
+
}
|
|
713
|
+
|
|
714
|
+
function getArrayU32FromWasm0(ptr, len) {
|
|
715
|
+
ptr = ptr >>> 0;
|
|
716
|
+
return getUint32ArrayMemory0().subarray(ptr / 4, ptr / 4 + len);
|
|
717
|
+
}
|
|
718
|
+
|
|
719
|
+
function getArrayU8FromWasm0(ptr, len) {
|
|
720
|
+
ptr = ptr >>> 0;
|
|
721
|
+
return getUint8ArrayMemory0().subarray(ptr / 1, ptr / 1 + len);
|
|
722
|
+
}
|
|
723
|
+
|
|
724
|
+
let cachedDataViewMemory0 = null;
|
|
725
|
+
function getDataViewMemory0() {
|
|
726
|
+
if (cachedDataViewMemory0 === null || cachedDataViewMemory0.buffer.detached === true || (cachedDataViewMemory0.buffer.detached === undefined && cachedDataViewMemory0.buffer !== wasm.memory.buffer)) {
|
|
727
|
+
cachedDataViewMemory0 = new DataView(wasm.memory.buffer);
|
|
728
|
+
}
|
|
729
|
+
return cachedDataViewMemory0;
|
|
730
|
+
}
|
|
731
|
+
|
|
732
|
+
function getStringFromWasm0(ptr, len) {
|
|
733
|
+
return decodeText(ptr >>> 0, len);
|
|
734
|
+
}
|
|
735
|
+
|
|
736
|
+
let cachedUint16ArrayMemory0 = null;
|
|
737
|
+
function getUint16ArrayMemory0() {
|
|
738
|
+
if (cachedUint16ArrayMemory0 === null || cachedUint16ArrayMemory0.byteLength === 0) {
|
|
739
|
+
cachedUint16ArrayMemory0 = new Uint16Array(wasm.memory.buffer);
|
|
740
|
+
}
|
|
741
|
+
return cachedUint16ArrayMemory0;
|
|
742
|
+
}
|
|
743
|
+
|
|
744
|
+
let cachedUint32ArrayMemory0 = null;
|
|
745
|
+
function getUint32ArrayMemory0() {
|
|
746
|
+
if (cachedUint32ArrayMemory0 === null || cachedUint32ArrayMemory0.byteLength === 0) {
|
|
747
|
+
cachedUint32ArrayMemory0 = new Uint32Array(wasm.memory.buffer);
|
|
748
|
+
}
|
|
749
|
+
return cachedUint32ArrayMemory0;
|
|
750
|
+
}
|
|
751
|
+
|
|
752
|
+
let cachedUint8ArrayMemory0 = null;
|
|
753
|
+
function getUint8ArrayMemory0() {
|
|
754
|
+
if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) {
|
|
755
|
+
cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer);
|
|
756
|
+
}
|
|
757
|
+
return cachedUint8ArrayMemory0;
|
|
758
|
+
}
|
|
759
|
+
|
|
760
|
+
function isLikeNone(x) {
|
|
761
|
+
return x === undefined || x === null;
|
|
762
|
+
}
|
|
763
|
+
|
|
764
|
+
function passArray32ToWasm0(arg, malloc) {
|
|
765
|
+
const ptr = malloc(arg.length * 4, 4) >>> 0;
|
|
766
|
+
getUint32ArrayMemory0().set(arg, ptr / 4);
|
|
767
|
+
WASM_VECTOR_LEN = arg.length;
|
|
768
|
+
return ptr;
|
|
769
|
+
}
|
|
770
|
+
|
|
771
|
+
function passArray8ToWasm0(arg, malloc) {
|
|
772
|
+
const ptr = malloc(arg.length * 1, 1) >>> 0;
|
|
773
|
+
getUint8ArrayMemory0().set(arg, ptr / 1);
|
|
774
|
+
WASM_VECTOR_LEN = arg.length;
|
|
775
|
+
return ptr;
|
|
776
|
+
}
|
|
777
|
+
|
|
778
|
+
function passStringToWasm0(arg, malloc, realloc) {
|
|
779
|
+
if (realloc === undefined) {
|
|
780
|
+
const buf = cachedTextEncoder.encode(arg);
|
|
781
|
+
const ptr = malloc(buf.length, 1) >>> 0;
|
|
782
|
+
getUint8ArrayMemory0().subarray(ptr, ptr + buf.length).set(buf);
|
|
783
|
+
WASM_VECTOR_LEN = buf.length;
|
|
784
|
+
return ptr;
|
|
785
|
+
}
|
|
786
|
+
|
|
787
|
+
let len = arg.length;
|
|
788
|
+
let ptr = malloc(len, 1) >>> 0;
|
|
789
|
+
|
|
790
|
+
const mem = getUint8ArrayMemory0();
|
|
791
|
+
|
|
792
|
+
let offset = 0;
|
|
793
|
+
|
|
794
|
+
for (; offset < len; offset++) {
|
|
795
|
+
const code = arg.charCodeAt(offset);
|
|
796
|
+
if (code > 0x7F) break;
|
|
797
|
+
mem[ptr + offset] = code;
|
|
798
|
+
}
|
|
799
|
+
if (offset !== len) {
|
|
800
|
+
if (offset !== 0) {
|
|
801
|
+
arg = arg.slice(offset);
|
|
802
|
+
}
|
|
803
|
+
ptr = realloc(ptr, len, len = offset + arg.length * 3, 1) >>> 0;
|
|
804
|
+
const view = getUint8ArrayMemory0().subarray(ptr + offset, ptr + len);
|
|
805
|
+
const ret = cachedTextEncoder.encodeInto(arg, view);
|
|
806
|
+
|
|
807
|
+
offset += ret.written;
|
|
808
|
+
ptr = realloc(ptr, len, offset, 1) >>> 0;
|
|
809
|
+
}
|
|
810
|
+
|
|
811
|
+
WASM_VECTOR_LEN = offset;
|
|
812
|
+
return ptr;
|
|
813
|
+
}
|
|
814
|
+
|
|
815
|
+
function takeFromExternrefTable0(idx) {
|
|
816
|
+
const value = wasm.__wbindgen_externrefs.get(idx);
|
|
817
|
+
wasm.__externref_table_dealloc(idx);
|
|
818
|
+
return value;
|
|
819
|
+
}
|
|
820
|
+
|
|
821
|
+
let cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
|
|
822
|
+
cachedTextDecoder.decode();
|
|
823
|
+
const MAX_SAFARI_DECODE_BYTES = 2146435072;
|
|
824
|
+
let numBytesDecoded = 0;
|
|
825
|
+
function decodeText(ptr, len) {
|
|
826
|
+
numBytesDecoded += len;
|
|
827
|
+
if (numBytesDecoded >= MAX_SAFARI_DECODE_BYTES) {
|
|
828
|
+
cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
|
|
829
|
+
cachedTextDecoder.decode();
|
|
830
|
+
numBytesDecoded = len;
|
|
831
|
+
}
|
|
832
|
+
return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
|
|
833
|
+
}
|
|
834
|
+
|
|
835
|
+
const cachedTextEncoder = new TextEncoder();
|
|
836
|
+
|
|
837
|
+
if (!('encodeInto' in cachedTextEncoder)) {
|
|
838
|
+
cachedTextEncoder.encodeInto = function (arg, view) {
|
|
839
|
+
const buf = cachedTextEncoder.encode(arg);
|
|
840
|
+
view.set(buf);
|
|
841
|
+
return {
|
|
842
|
+
read: arg.length,
|
|
843
|
+
written: buf.length
|
|
844
|
+
};
|
|
845
|
+
};
|
|
846
|
+
}
|
|
847
|
+
|
|
848
|
+
let WASM_VECTOR_LEN = 0;
|
|
849
|
+
|
|
850
|
+
let wasmModule, wasmInstance, wasm;
|
|
851
|
+
function __wbg_finalize_init(instance, module) {
|
|
852
|
+
wasmInstance = instance;
|
|
853
|
+
wasm = instance.exports;
|
|
854
|
+
wasmModule = module;
|
|
855
|
+
cachedDataViewMemory0 = null;
|
|
856
|
+
cachedUint16ArrayMemory0 = null;
|
|
857
|
+
cachedUint32ArrayMemory0 = null;
|
|
858
|
+
cachedUint8ArrayMemory0 = null;
|
|
859
|
+
wasm.__wbindgen_start();
|
|
860
|
+
return wasm;
|
|
861
|
+
}
|
|
862
|
+
|
|
863
|
+
async function __wbg_load(module, imports) {
|
|
864
|
+
if (typeof Response === 'function' && module instanceof Response) {
|
|
865
|
+
if (typeof WebAssembly.instantiateStreaming === 'function') {
|
|
866
|
+
try {
|
|
867
|
+
return await WebAssembly.instantiateStreaming(module, imports);
|
|
868
|
+
} catch (e) {
|
|
869
|
+
const validResponse = module.ok && expectedResponseType(module.type);
|
|
870
|
+
|
|
871
|
+
if (validResponse && module.headers.get('Content-Type') !== 'application/wasm') {
|
|
872
|
+
console.warn("`WebAssembly.instantiateStreaming` failed because your server does not serve Wasm with `application/wasm` MIME type. Falling back to `WebAssembly.instantiate` which is slower. Original error:\n", e);
|
|
873
|
+
|
|
874
|
+
} else { throw e; }
|
|
875
|
+
}
|
|
876
|
+
}
|
|
877
|
+
|
|
878
|
+
const bytes = await module.arrayBuffer();
|
|
879
|
+
return await WebAssembly.instantiate(bytes, imports);
|
|
880
|
+
} else {
|
|
881
|
+
const instance = await WebAssembly.instantiate(module, imports);
|
|
882
|
+
|
|
883
|
+
if (instance instanceof WebAssembly.Instance) {
|
|
884
|
+
return { instance, module };
|
|
885
|
+
} else {
|
|
886
|
+
return instance;
|
|
887
|
+
}
|
|
888
|
+
}
|
|
889
|
+
|
|
890
|
+
function expectedResponseType(type) {
|
|
891
|
+
switch (type) {
|
|
892
|
+
case 'basic': case 'cors': case 'default': return true;
|
|
893
|
+
}
|
|
894
|
+
return false;
|
|
895
|
+
}
|
|
896
|
+
}
|
|
897
|
+
|
|
898
|
+
function initSync(module) {
|
|
899
|
+
if (wasm !== undefined) return wasm;
|
|
900
|
+
|
|
901
|
+
|
|
902
|
+
if (module !== undefined) {
|
|
903
|
+
if (Object.getPrototypeOf(module) === Object.prototype) {
|
|
904
|
+
({module} = module)
|
|
905
|
+
} else {
|
|
906
|
+
console.warn('using deprecated parameters for `initSync()`; pass a single object instead')
|
|
907
|
+
}
|
|
908
|
+
}
|
|
909
|
+
|
|
910
|
+
const imports = __wbg_get_imports();
|
|
911
|
+
if (!(module instanceof WebAssembly.Module)) {
|
|
912
|
+
module = new WebAssembly.Module(module);
|
|
913
|
+
}
|
|
914
|
+
const instance = new WebAssembly.Instance(module, imports);
|
|
915
|
+
return __wbg_finalize_init(instance, module);
|
|
916
|
+
}
|
|
917
|
+
|
|
918
|
+
async function __wbg_init(module_or_path) {
|
|
919
|
+
if (wasm !== undefined) return wasm;
|
|
920
|
+
|
|
921
|
+
|
|
922
|
+
if (module_or_path !== undefined) {
|
|
923
|
+
if (Object.getPrototypeOf(module_or_path) === Object.prototype) {
|
|
924
|
+
({module_or_path} = module_or_path)
|
|
925
|
+
} else {
|
|
926
|
+
console.warn('using deprecated parameters for the initialization function; pass a single object instead')
|
|
927
|
+
}
|
|
928
|
+
}
|
|
929
|
+
|
|
930
|
+
if (module_or_path === undefined) {
|
|
931
|
+
module_or_path = new URL('stm32_periph_wasm_bg.wasm', import.meta.url);
|
|
932
|
+
}
|
|
933
|
+
const imports = __wbg_get_imports();
|
|
934
|
+
|
|
935
|
+
if (typeof module_or_path === 'string' || (typeof Request === 'function' && module_or_path instanceof Request) || (typeof URL === 'function' && module_or_path instanceof URL)) {
|
|
936
|
+
module_or_path = fetch(module_or_path);
|
|
937
|
+
}
|
|
938
|
+
|
|
939
|
+
const { instance, module } = await __wbg_load(await module_or_path, imports);
|
|
940
|
+
|
|
941
|
+
return __wbg_finalize_init(instance, module);
|
|
942
|
+
}
|
|
943
|
+
|
|
944
|
+
export { initSync, __wbg_init as default };
|